⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gfxdrawtext.pas

📁 一个不出名的GBA模拟器
💻 PAS
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// gfxDrawText.pas: Render metacode for text backgrounds            //
//                                                                  //
// The contents of this file are subject to the Bottled Light       //
// Public License Version 1.0 (the "License"); you may not use this //
// file except in compliance with the License. You may obtain a     //
// copy of the License at http://www.bottledlight.com/BLPL/         //
//                                                                  //
// Software distributed under the License is distributed on an      //
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   //
// implied. See the License for the specific language governing     //
// rights and limitations under the License.                        //
//                                                                  //
// The Original Code is the Mappy VM Core, released April 1st, 2003 //
// The Initial Developer of the Original Code is Bottled Light,     //
// Inc. Portions created by Bottled Light, Inc. are Copyright       //
// (C) 2001 - 2003 Bottled Light, Inc. All Rights Reserved.         //
//                                                                  //
// Author(s):                                                       //
//   Michael Noland (joat), michael@bottledlight.com                //
//                                                                  //
// Changelog:                                                       //
//   1.0: First public release (April 1st, 2003)                    //
//                                                                  //
//////////////////////////////////////////////////////////////////////

var
  pdy, w, dx: uint32;
  base, charbase: uint32;
  x: integer;
  j, pal, pix: uint32;
  h, dy: uint32;
{$INCLUDE gfxDrawPixelInc.pas}

  // Calculate the beginning tile and pixel position
  dx := scrollX and $1FF;
  dy := (scrollY + y) and $1FF;

  // Calculate the size of the screen (either 32 or 64 tiles
  // but w&h are either 64 or 128, since each entry is 2 bytes
  if CR and TEXT_BG_XSIZE = 0 then w := 64 else w := 128;
  if CR and TEXT_BG_YSIZE = 0 then h := 64 else h := 128;

  // Wrap the y coordinate
  dy := dy and (h shl 2 - 1);

  // Calculate the map base address (including a Y offset)
  base := ((CR shr 8) and $1F) * $800;
  base := base + ((dy shr 8)*(w shr 6)) shl 11 + ((dy shr 3) and $1F) shl 6;

  // Calculate the tile base address and an offset (seperate for flipping)
  charbase := ((CR shr 2) and $3) * $4000;
  pdy := (dy and 7) shl 3;

  x := 0;
  if CR and TEXT_BG_256COLORS = 0 then begin
    // Render a 16 color background
    while x < gfxScreenWidth do begin
      // Wrap the x coordinate
      dx := dx and (w shl 2 - 1);

      // Look up the appropiate tile (icky)
      pix := (Puint16(@(VRAM[base + (dx shr 8) shl 11 + ((dx shr 3) and $1F) shl 1]))^);
      j := (pix shr 10) and $3;
      pal := pix shr 12;
      pix := pix and $3FF;

      // Look up the appropriate pixel (icky)
           if j = 0 then pix := VRAM[charbase + pix shl 5 + (pdy + dx and 7) shr 1]
      else if j = 1 then pix := VRAM[charbase + pix shl 5 + (7 + pdy - dx and 7) shr 1]
      else if j = 2 then pix := VRAM[charbase + pix shl 5 + (56 - pdy + dx and 7) shr 1]
      else               pix := VRAM[charbase + pix shl 5 + (63 - pdy - dx and 7) shr 1];

      // Draw a pixel
      if Odd(dx) xor (j and 1 <> 0) then pix := pix shr 4 else pix := pix and $F;
      if (pix <> 0) and (wins^ and mask <> 0) or ((pix = 0) and (not latchXparent) and (mclock > 0)) then begin
        pix := Puint16(@(palette[pix shl 1 + pal shl 5]))^;
      {$INCLUDE gfxDrawPixel.pas}

      Inc(x);
      Inc(dx);
    end;
  end else begin
    // Render a 256 color background
    while x < gfxScreenWidth do begin
      // Wrap the x coordinate
      dx := dx and (w shl 2 - 1);

      // Look up the appropiate tile (icky)
      pix := (Puint16(@(VRAM[base + (dx shr 8) shl 11 + ((dx shr 3) and $1F) shl 1]))^);
      j := (pix shr 10) and $3;
      pix := pix and $3FF;

      // Look up the appropriate pixel (icky)
           if j = 0 then pix := VRAM[charbase + pdy + pix shl 6 + dx and 7]
      else if j = 1 then pix := VRAM[charbase + 7 + pdy + pix shl 6 - dx and 7]
      else if j = 2 then pix := VRAM[charbase + 56 - pdy + pix shl 6 + dx and 7]
      else               pix := VRAM[charbase + 63 - pdy + pix shl 6 - dx and 7];

      // Draw a pixel
      if (pix <> 0) and (wins^ and mask <> 0) or ((pix = 0) and (not latchXparent) and (mclock > 0)) then begin
        pix := Puint16(@(palette[pix shl 1]))^;
      {$INCLUDE gfxDrawPixel.pas}

      Inc(x);
      Inc(dx);
    end;
  end;
end; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -