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

📄 gfxdrawrs2d16sprite.pas

📁 一个不出名的GBA模拟器
💻 PAS
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// gfxDrawRS2D16Sprite.pas: Render metacode for rot/scale 16        //
// color sprites with 2D mapping                                    //
//                                                                  //
// 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
  hsize, vsize: byte;
  dw, dh: byte;
  pix, pal: uint16;
  sx, sy: integer;
  x, base, rbase: integer;

  dx, dy: integer;
  cx, cy: integer;
  offset: uint32;
{$INCLUDE gfxDrawPixelInc.pas}
  sx := entry^.x;
  sy := entry^.y;

  // Check for the double size flag being set
  hsize := entry^.width;
  vsize := entry^.height;
  dw := hsize;
  dh := vsize;
  if entry^.doublesize then begin
    dw := dw shl 1;
    dh := dh shl 1;
  end;

  // Calculate the palette base
  pal := (entry^.c shr 12) shl 5 + 512;

  // Read the rot/scale parameters
  offset := ((entry^.b shr 9) and $1F) shl 5 + 6;
  dx := Pint16(@(OAM[offset]))^;
  dy := Pint16(@(OAM[offset+16]))^;
  cx := Pint16(@(OAM[offset+8]))^;
  cy := Pint16(@(OAM[offset+24]))^;

  // Fidget with the coordinates
  cx := cx*(y - dh shr 1) + hsize shl 7;
  cy := cy*(y - dh shr 1) + vsize shl 7;
  cx := cx - dx*(dw shr 1);
  cy := cy - dy*(dw shr 1);

  rbase := (entry^.c and $3FF) shl 5 + $10000;

  // Do some clipping
  if sx < 0 then begin
    cx := cx - dx * sx;
    cy := cy - dy * sx;
    sx := 0;
  end;
  if sx+entry^.run > 240 then Exit;
  ids := @(Puint8Array(ids)^[sx]);
  wins := @(Puint8Array(wins)^[sx]);
  line := @(Puint16Array(line)^[sx]);

  // Draw the sprite
  dw := dw shl 8;
  dh := dh shl 8;
  for x := 0 to entry^.run-1 do begin
    if (cx shr 8 < hsize) and (cy shr 8 < vsize) then begin
      base := rbase + ((cy shr 8) shr 3) shl 10 + ((cy shr 8) and 7) shl 2;
      base := base + ((cx shr 8) and 7) shr 1 + ((cx shr 8) shr 3) shl 5;
      pix := VRAM[base];
      if Odd(cx shr 8) then pix := pix shr 4 else pix := pix and $F;
    end else
      pix := 0;

    if (pix <> 0) {$IFNDEF OBJWIN}and (wins^ and mask <> 0){$ENDIF} or
       ((pix = 0) and (not latchXparent) and (mclock > 0)) then begin
      pix := Puint16(@(palette[pix shl 1 + pal]))^;
    {$INCLUDE gfxDrawPixel.pas}

    Inc(cx, dx);
    Inc(cy, dy);
  end;
end; 

⌨️ 快捷键说明

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