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

📄 addressspace.pas

📁 一个不出名的GBA模拟器
💻 PAS
📖 第 1 页 / 共 3 页
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// AddressSpace.pas: Common constants and types.                    //
//   This contains register addresses, types, and masks common to   //
//   both the Mappy VM core and the Mappy VM user interface.        //
//                                                                  //
// 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 User Interface/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. //
//                                                                  //
// This file is common to both the Mappy VM user interface and the  //
// Mappy VM core projects, and is considered Original Code for both //
//                                                                  //
// Author(s):                                                       //
//   Michael Noland (joat), michael@bottledlight.com                //
//                                                                  //
// Changelog:                                                       //
//   1.0: First public release (April 1st, 2003)                    //
//                                                                  //
// Notes:                                                           //
//   Todo: Add networking registers.                                //
//                                                                  //
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
unit AddressSpace; ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
interface ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

type
  uint8 = byte;
  int8 = shortint;
  Puint8 = ^uint8;
  Pint8 = ^int8;

  int16 = smallint;
  uint16 = word;
  Puint16 = ^uint16;
  Pint16 = ^int16;

  int32 = integer;
  uint32 = longword;
  Puint32 = ^uint32;
  Pint32 = ^int32;

  float = single;
  float32 = single;
  float64 = double;

  Pfloat32 = ^float32;
  Pfloat64 = ^float64;

  Pboolean = ^boolean;

  Puint8Array = ^Tuint8Array;
  Tuint8Array = array[0..MaxInt - 1] of uint8;

  Puint16Array = ^Tuint16Array;
  Tuint16Array = array[0..MaxInt shr 1 - 1] of uint16;

//////////////////////////////////////////////////////////////////////

const
  // Display Control Register (RW)
  //  [0..2]: Video mode (0-5)
  //  [3]: CGB mode?  fixme: is this the cart switch?
  //  [4]: Display 2nd framebuffer (modes 4-5)
  //  [5]: Enable access of OAM during H-Blank
  //  [6]: Use 1D sprite mapping
  //  [7]: Enable forced blank (disable rendering)
  //  [8]: Enable BG0
  //  [9]: Enable BG1
  //  [10]: Enable BG2
  //  [11]: Enable BG3
  //  [12]: Enable sprites
  //  [13]: Mask with window 0
  //  [14]: Mask with window 1
  //  [15]: Mask with sprite windows
  DISPLAY_CR = $00;
   DISPLAY_CR_MODEMASK = $7;
   DISPLAY_CR_FB = $10;
   DISPLAY_CR_NOHBLOBJS = $20;
   DISPLAY_CR_OBJ_1D = $40;
   DISPLAY_CR_NO_DISP = $80;
  DISPLAY_ACTIVE = $01;
   DISPLAY_ACTIVE_BG0 = $01;
   DISPLAY_ACTIVE_BG1 = $02;
   DISPLAY_ACTIVE_BG2 = $04;
   DISPLAY_ACTIVE_BG3 = $08;
   DISPLAY_ACTIVE_OBJ = $10;
   DISPLAY_ACTIVE_WIN0 = $20;
   DISPLAY_ACTIVE_WIN1 = $40;
   DISPLAY_ACTIVE_OBJW = $80;

  // Display Status Register (R/W)
  //  [0]: In V-Blank
  //  [1]: In H-Blank
  //  [2]: Y trigger equals current scanline
  //  [3]: V-Blank IRQ enable
  //  [4]: H-Blank IRQ enable
  //  [5]: Y trigger IRQ enable
  //  [6..7]: Unknown
  //  [8..15]: Scanline Y-trigger value
  DISPLAY_SR = $04;
   DISPLAY_SR_IN_VBL = 1 shl 0;
   DISPLAY_SR_IN_HBL = 1 shl 1;
   DISPLAY_SR_TRIGGERED = 1 shl 2;
   DISPLAY_SR_VBL_IRQ = 1 shl 3;
   DISPLAY_SR_HBL_IRQ = 1 shl 4;
   DISPLAY_SR_Y_TRIGGER_IRQ = 1 shl 5;
  DISPLAY_YTRIG = $05;

  // Current scanline (R)
  //  [0..7]: Current scanline
  DISPLAY_Y =  $06;

  BG0_CR = $08;
  BG1_CR = $0A;
  BG2_CR = $0C;
  BG3_CR = $0E;

  // Tiled BG Control Register
  //  [0..1]: Priority (0 is highest)
  //  [2..3]: Tile base (16 KB steps)
  //  [4..5]: Always 0
  //  [6]: Enable mosaic
  //  [7]: Single palette mode (256 colors)
  //  [8..12]: Screen base (2 KB steps)
  //  [13]: Enable map wrapping (rot/scale only)
  //  [14..15]: Map size
   TEXT_BG_MOSAIC = 1 shl 6;     // If set, apply mosaic to the background
   TEXT_BG_256COLORS = 1 shl 7;  // If set, tiles are 8-bit, otherwise 4-bit
   RS_BG_WRAP = 1 shl 13;        // If set, wrap the bg around, otherwise just go xparent
   TEXT_BG_XSIZE = 1 shl 14;     // If set, X size is 512 rather than 256
   TEXT_BG_YSIZE = 1 shl 15;     // If set, Y size is 512 rather than 256

  BG2_A = $20;   // Horizontal dx for BG2 (8.8 fixed point, 16 bits)
  BG2_B = $22;   // Vertical dx for BG2 (8.8 fixed point, 16 bits)
  BG2_C = $24;   // Horizontal dy for BG2 (8.8 fixed point, 16 bits)
  BG2_D = $26;   // Vertical dy for BG2 (8.8 fixed point, 16 bits)
  BG2_X = $28;   // Horizontal offset of BG2 (20.8 fixed point, 28 bits)
  BG2_Y = $2C;   // Vertical offset of BG2 (20.8 fixed point, 28 bits)

  BG0_X0 = $10;  // Text mode BG0 horizontal scroll (9 bits)
  BG0_Y0 = $12;  // Text mode BG0 vertical scroll (9 bits)
  BG1_X0 = $14;  // Text mode BG1 horizontal scroll (9 bits)
  BG1_Y0 = $16;  // Text mode BG1 vertical scroll (9 bits)
  BG2_X0 = $18;  // Text mode BG2 horizontal scroll (9 bits)
  BG2_Y0 = $1A;  // Text mode BG2 vertical scroll (9 bits)
  BG3_X0 = $1C;  // Text mode BG3 horizontal scroll (9 bits)
  BG3_Y0 = $1E;  // Text mode BG3 vertical scroll (9 bits)

  // scr[x,y] = framebuffer[bg_x + bg_a*x + bg_b*y, bg_y + bg_c*x + bg_d*y]
  BG3_A = $30;  // Horizontal dx for BG3 (8.8 fixed point, 16 bits)
  BG3_B = $32;  // Vertical dx for BG3 (8.8 fixed point, 16 bits)
  BG3_C = $34;  // Horizontal dy for BG3 (8.8 fixed point, 16 bits)
  BG3_D = $36;  // Vertical dy for BG3 (8.8 fixed point, 16 bits)
  BG3_X = $38;  // Horizontal offset of BG3 (20.8 fixed point, 28 bits)
  BG3_Y = $3C;  // Vertical offset of BG3 (20.8 fixed point, 28 bits)

  BG2_X_DIRTY = $420;
  BG2_Y_DIRTY = $421;
  BG3_X_DIRTY = $422;
  BG3_Y_DIRTY = $423;
  BG2_X_LATCH = $428;
  BG2_Y_LATCH = $42C;
  BG3_X_LATCH = $438;
  BG3_Y_LATCH = $43C;

//////////////////////////////////////////////////////////////////////
// Sprites ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

  // Sprite attribute 0
  //  [0-7]: y-coordinate
  //  [8]: when set, rot/scale the object
  //  [9]: when set, use doublesize mode
  //  [10-11]: Sprite mode
  //    00: normal
  //    01: apply blending to it
  //    10: window
  //    11: invalid
  //  [12]: when set, apply a mosaic to it
  //  [13]: when set, 256 color mode, otherwise 16x16 mode
  //  [14-15]: Shape
  //    00: Square
  //    01: Horizontal
  //    10: Vertical
  //    11: Invalid
  const
  SPRITE_A_ROTSCALE = 1 shl 8;
  SPRITE_A_DOUBLESIZE = 1 shl 9;
  SPRITE_A_MOSAIC = 1 shl 12;
  SPRITE_A_256MODE = 1 shl 13;

  // Sprite attribute 1
  //  [0-8]: x-coordinate
  //  [9-13]: rot/scale quad selection
  //  [12]: horizontal flip
  //  [13]: vertical flip
  //  [14,15]: Object size
  SPRITE_B_FLIP_X = 1 shl 12;
  SPRITE_B_FLIP_Y = 1 shl 13;

  // Sprite attribute 2
  //  [0-9]: Tile number   (in bitmap mode, numbers 0-511 are invalid)
  // (fixme: should we enforce this, or does it just render framebuffer junk when used?)
  //  [10-11]: Priority
  //  [12-15]: Palette (in 256 color mode, it's irrelevant)

  // Actual size of a sprite: (sh=shape, si=size)
  //  sh si
  //  00 00  8x8
  //  00 01  16x16
  //  00 10  32x32
  //  00 11  64x64
  //  01 00  16x8
  //  01 01  32x8
  //  01 10  32x16
  //  01 11  64x32
  //  10 00  8x16
  //  10 01  8x32
  //  10 10  16x32
  //  10 11  32x64
  //  11 xx  Invalid
  SpriteSizes: array[0..23] of byte =
   (8,8,   16,16,  32,32,  64,64,
    16,8,  32,8,   32,16,  64,32,
    8,16,  8,32,   16,32,  32,64);

type
  TRotScaleSet = packed record
    a, b, c, d: int16;
    cx, cy: uint32;
  end;
  PRotScaleSet = ^TRotScaleSet;

//////////////////////////////////////////////////////////////////////
// Display related registers and constants ///////////////////////////
//////////////////////////////////////////////////////////////////////

type
  // The format of a sprite in OAM
  TSprite = packed record
    a, b, c, rs: uint16;
  end;
  PSprite = ^TSprite;         

//////////////////////////////////////////////////////////////////////

const
  // Framebuffer offsets
  DISP_FB0_START = $00000;
  DISP_FB1_START = $0A000;

//////////////////////////////////////////////////////////////////////
// Window control registers //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

    WIN0_X0 = $41;
    WIN0_X1 = $40;
    WIN0_Y0 = $45;
    WIN0_Y1 = $44;

    WIN1_X0 = $43;
    WIN1_X1 = $42;
    WIN1_Y0 = $47;
    WIN1_Y1 = $46;

    WIN0_IN = $48;
    WIN1_IN = $49;

    WIN_OUT = $4A;
    SPR_WIN_IN = $4B;

//////////////////////////////////////////////////////////////////////
// Mosaic registers //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

  // Mosaic Control Register
  //  [0..3]: BG mosaic x repeat
  //  [4..7]: BG mosaic y repeat
  //  [8..11]: Sprite mosaic x repeat
  //  [12..15]: Sprite mosaic y repeat
  BG_MOSAIC = $4C;
  SPR_MOSAIC = $4D;

  // BG tile format
  // [0..9]: Tile base (32 byte steps)
  // [10]: Horizontal flip
  // [11]: Vertical flip
  // [12..15]: Palette index

//////////////////////////////////////////////////////////////////////
// Blend Registers ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

  // bit 0-5 controls the 1st target selection, 4=oam, 5=background
  // bit 6-7 controls the blend mode
  BLEND_S1 =   $50;

  // bit 0-5 controls the 2nd target selection ...
  BLEND_S2 =   $51;

  // bit 0-4 control blend registers, if > 16 then = 16
  COEFF_A =    $52;
  COEFF_B =    $53;
  COEFF_Y =    $54;

⌨️ 快捷键说明

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