diff --git a/projects.md b/projects.md index e00f79b..76fb2db 100644 --- a/projects.md +++ b/projects.md @@ -3,6 +3,7 @@ title: Projects ---
Pan Docs |
About the Pan Docs |
================================================================= + Everything You Always Wanted To Know About GAMEBOY * + ================================================================= + |
* but were afraid to ask + |
Pan of -ATX- Document Updated by contributions from: + Marat Fayzullin, Pascal Felber, Paul Robson, Martin Korth + CPU, SGB, CGB, AUX specs by Martin Korth + |
Last updated 10/2001 by nocash + Previously updated 4-Mar-98 by kOOPa + |
http://www.work.de/nocash/pandocs.txt + http://www.work.de/nocash/pandocs.htm + |
Game Boy Technical Data |
CPU - 8-bit (Similar to the Z80 processor) + Clock Speed - 4.194304MHz (4.295454MHz for SGB, max. 8.4MHz for CGB) + Work RAM - 8K Byte (32K Byte for CGB) + Video RAM - 8K Byte (16K Byte for CGB) + Screen Size - 2.6" + Resolution - 160x144 (20x18 tiles) + Max sprites - Max 40 per screen, 10 per line + Sprite sizes - 8x8 or 8x16 + Palettes - 1x4 BG, 2x3 OBJ (for CGB: 8x4 BG, 8x3 OBJ) + Colors - 4 grayshades (32768 colors for CGB) + Horiz Sync - 9198 KHz (9420 KHz for SGB) + Vert Sync - 59.73 Hz (61.17 Hz for SGB) + Sound - 4 channels with stereo sound + Power - DC6V 0.7W (DC3V 0.7W for GB Pocket, DC3V 0.6W for CGB) + |
Memory Map |
0000-3FFF 16KB ROM Bank 00 (in cartridge, fixed at bank 00) + 4000-7FFF 16KB ROM Bank 01..NN (in cartridge, switchable bank number) + 8000-9FFF 8KB Video RAM (VRAM) (switchable bank 0-1 in CGB Mode) + A000-BFFF 8KB External RAM (in cartridge, switchable bank, if any) + C000-CFFF 4KB Work RAM Bank 0 (WRAM) + D000-DFFF 4KB Work RAM Bank 1 (WRAM) (switchable bank 1-7 in CGB Mode) + E000-FDFF Same as C000-DDFF (ECHO) (typically not used) + FE00-FE9F Sprite Attribute Table (OAM) + FEA0-FEFF Not Usable + FF00-FF7F I/O Ports + FF80-FFFE High RAM (HRAM) + FFFF Interrupt Enable Register + |
0000,0008,0010,0018,0020,0028,0030,0038 for RST commands + 0040,0048,0050,0058,0060 for Interrupts + |
Video Display |
LCD Control Register |
Bit 7 - LCD Display Enable (0=Off, 1=On) + Bit 6 - Window Tile Map Display Select (0=9800-9BFF, 1=9C00-9FFF) + Bit 5 - Window Display Enable (0=Off, 1=On) + Bit 4 - BG & Window Tile Data Select (0=8800-97FF, 1=8000-8FFF) + Bit 3 - BG Tile Map Display Select (0=9800-9BFF, 1=9C00-9FFF) + Bit 2 - OBJ (Sprite) Size (0=8x8, 1=8x16) + Bit 1 - OBJ (Sprite) Display Enable (0=Off, 1=On) + Bit 0 - BG Display (for CGB see below) (0=Off, 1=On) + |
LCD Status Register |
Bit 6 - LYC=LY Coincidence Interrupt (1=Enable) (Read/Write) + Bit 5 - Mode 2 OAM Interrupt (1=Enable) (Read/Write) + Bit 4 - Mode 1 V-Blank Interrupt (1=Enable) (Read/Write) + Bit 3 - Mode 0 H-Blank Interrupt (1=Enable) (Read/Write) + Bit 2 - Coincidence Flag (0:LYC<>LY, 1:LYC=LY) (Read Only) + Bit 1-0 - Mode Flag (Mode 0-3, see below) (Read Only) + 0: During H-Blank + 1: During V-Blank + 2: During Searching OAM-RAM + 3: During Transfering Data to LCD Driver + |
Mode 0: The LCD controller is in the H-Blank period and + the CPU can access both the display RAM (8000h-9FFFh) + and OAM (FE00h-FE9Fh) + |
Mode 1: The LCD contoller is in the V-Blank period (or the + display is disabled) and the CPU can access both the + display RAM (8000h-9FFFh) and OAM (FE00h-FE9Fh) + |
Mode 2: The LCD controller is reading from OAM memory. + The CPU <cannot> access OAM memory (FE00h-FE9Fh) + during this period. + |
Mode 3: The LCD controller is reading from both OAM and VRAM, + The CPU <cannot> access OAM and VRAM during this period. + CGB Mode: Cannot access Palette Data (FF69,FF6B) either. + |
Mode 2 2_____2_____2_____2_____2_____2___________________2____ + Mode 3 _33____33____33____33____33____33__________________3___ + Mode 0 ___000___000___000___000___000___000________________000 + Mode 1 ____________________________________11111111111111_____ + |
LCD Interrupts |
LCD Position and Scrolling |
LCD Monochrome Palettes |
Bit 7-6 - Shade for Color Number 3 + Bit 5-4 - Shade for Color Number 2 + Bit 3-2 - Shade for Color Number 1 + Bit 1-0 - Shade for Color Number 0 + |
0 White + 1 Light gray + 2 Dark gray + 3 Black + |
LCD Color Palettes (CGB only) |
Bit 0-5 Index (00-3F) + Bit 7 Auto Increment (0=Disabled, 1=Increment after Writing) + |
Bit 0-4 Red Intensity (00-1F) + Bit 5-9 Green Intensity (00-1F) + Bit 10-14 Blue Intensity (00-1F) + |
LCD VRAM Bank (CGB only) |
Bit 0 - VRAM Bank (0-1) + |
LCD OAM DMA Transfers |
Source: XX00-XX9F ;XX in range from 00-F1h + Destination: FE00-FE9F + |
ld (0FF46h),a ;start DMA transfer, a=start address/100h + ld a,28h ;delay... + wait: ;total 5x40 cycles, approx 200ms + dec a ;1 cycle + jr nz,wait ;4 cycles + |
LCD VRAM DMA Transfers (CGB only) |
VRAM Tile Data |
Byte 0-1 First Line (Upper 8 pixels) + Byte 2-3 Next Line + etc. + |
VRAM Background Maps |
Bit 0-2 Background Palette number (BGP0-7) + Bit 3 Tile VRAM Bank number (0=Bank 0, 1=Bank 1) + Bit 4 Not used + Bit 5 Horizontal Flip (0=Normal, 1=Mirror horizontally) + Bit 6 Vertical Flip (0=Normal, 1=Mirror vertically) + Bit 7 BG-to-OAM Priority (0=Use OAM priority bit, 1=BG Priority) + |
VRAM Sprite Attribute Table (OAM) |
Bit7 OBJ-to-BG Priority (0=OBJ Above BG, 1=OBJ Behind BG color 1-3) + (Used for both BG and Window. BG color 0 is always behind OBJ) + Bit6 Y flip (0=Normal, 1=Vertically mirrored) + Bit5 X flip (0=Normal, 1=Horizontally mirrored) + Bit4 Palette number **Non CGB Mode Only** (0=OBP0, 1=OBP1) + Bit3 Tile VRAM-Bank **CGB Mode Only** (0=Bank 0, 1=Bank 1) + Bit2-0 Palette number **CGB Mode Only** (OBP0-7) + |
Accessing VRAM and OAM |
Mode 0 - H-Blank Period, + Mode 1 - V-Blank Period, and + Mode 2 - Searching OAM Period + |
ld hl,0FF41h ;-STAT Register + @@wait: ;\ + bit 1,(hl) ; Wait until Mode is 0 or 1 + jr nz,@@wait ;/ + |
Mode 0 - H-Blank Period, and + Mode 1 - V-Blank Period + |
ld hl,0FF41h ;-STAT Register + @@wait1: ;\ + bit 1,(hl) ; Wait until Mode is -NOT- 0 or 1 + jr z,@@wait1 ;/ + @@wait2: ;\ + bit 1,(hl) ; Wait until Mode 0 or 1 -BEGINS- + jr nz,@@wait2 ;/ + |
Sound Controller |
Sound Overview |
Quadrangular wave patterns with sweep and envelope functions. + Quadrangular wave patterns with envelope functions. + Voluntary wave patterns from wave RAM. + White noise with an envelope function. + |
Sound Channel 1 - Tone & Sweep |
Bit 6-4 - Sweep Time + Bit 3 - Sweep Increase/Decrease + 0: Addition (frequency increases) + 1: Subtraction (frequency decreases) + Bit 2-0 - Number of sweep shift (n: 0-7) + |
000: sweep off - no freq change + 001: 7.8 ms (1/128Hz) + 010: 15.6 ms (2/128Hz) + 011: 23.4 ms (3/128Hz) + 100: 31.3 ms (4/128Hz) + 101: 39.1 ms (5/128Hz) + 110: 46.9 ms (6/128Hz) + 111: 54.7 ms (7/128Hz) + |
X(t) = X(t-1) +/- X(t-1)/2^n + |
Bit 7-6 - Wave Pattern Duty (Read/Write) + Bit 5-0 - Sound length data (Write Only) (t1: 0-63) + |
00: 12.5% ( _-------_-------_------- ) + 01: 25% ( __------__------__------ ) + 10: 50% ( ____----____----____---- ) (normal) + 11: 75% ( ______--______--______-- ) + |
Bit 7-4 - Initial Volume of envelope (0-0Fh) (0=No Sound) + Bit 3 - Envelope Direction (0=Decrease, 1=Increase) + Bit 2-0 - Number of envelope sweep (n: 0-7) + (If zero, stop envelope operation.) + |
Bit 7 - Initial (1=Restart Sound) (Write Only) + Bit 6 - Counter/consecutive selection (Read/Write) + (1=Stop output when length in NR11 expires) + Bit 2-0 - Frequency's higher 3 bits (x) (Write Only) + |
Sound Channel 2 - Tone |
Bit 7-6 - Wave Pattern Duty (Read/Write) + Bit 5-0 - Sound length data (Write Only) (t1: 0-63) + |
00: 12.5% ( _-------_-------_------- ) + 01: 25% ( __------__------__------ ) + 10: 50% ( ____----____----____---- ) (normal) + 11: 75% ( ______--______--______-- ) + |
Bit 7-4 - Initial Volume of envelope (0-0Fh) (0=No Sound) + Bit 3 - Envelope Direction (0=Decrease, 1=Increase) + Bit 2-0 - Number of envelope sweep (n: 0-7) + (If zero, stop envelope operation.) + |
Bit 7 - Initial (1=Restart Sound) (Write Only) + Bit 6 - Counter/consecutive selection (Read/Write) + (1=Stop output when length in NR21 expires) + Bit 2-0 - Frequency's higher 3 bits (x) (Write Only) + |
Sound Channel 3 - Wave Output |
Bit 7 - Sound Channel 3 Off (0=Stop, 1=Playback) (Read/Write) + |
Bit 7-0 - Sound length (t1: 0 - 255) + |
Bit 6-5 - Select output level (Read/Write) + |
0: Mute (No sound) + 1: 100% Volume (Produce Wave Pattern RAM Data as it is) + 2: 50% Volume (Produce Wave Pattern RAM data shifted once to the right) + 3: 25% Volume (Produce Wave Pattern RAM data shifted twice to the right) + |
Bit 7 - Initial (1=Restart Sound) (Write Only) + Bit 6 - Counter/consecutive selection (Read/Write) + (1=Stop output when length in NR31 expires) + Bit 2-0 - Frequency's higher 3 bits (x) (Write Only) + |
Sound Channel 4 - Noise |
Bit 5-0 - Sound length data (t1: 0-63) + |
Bit 7-4 - Initial Volume of envelope (0-0Fh) (0=No Sound) + Bit 3 - Envelope Direction (0=Decrease, 1=Increase) + Bit 2-0 - Number of envelope sweep (n: 0-7) + (If zero, stop envelope operation.) + |
Bit 7-4 - Shift Clock Frequency (s) + Bit 3 - Counter Step/Width (0=15 bits, 1=7 bits) + Bit 2-0 - Dividing Ratio of Frequencies (r) + |
Bit 7 - Initial (1=Restart Sound) (Write Only) + Bit 6 - Counter/consecutive selection (Read/Write) + (1=Stop output when length in NR41 expires) + |
Sound Control Registers |
Bit 7 - Output Vin to SO2 terminal (1=Enable) + Bit 6-4 - SO2 output level (volume) (0-7) + Bit 3 - Output Vin to SO1 terminal (1=Enable) + Bit 2-0 - SO1 output level (volume) (0-7) + |
Bit 7 - Output sound 4 to SO2 terminal + Bit 6 - Output sound 3 to SO2 terminal + Bit 5 - Output sound 2 to SO2 terminal + Bit 4 - Output sound 1 to SO2 terminal + Bit 3 - Output sound 4 to SO1 terminal + Bit 2 - Output sound 3 to SO1 terminal + Bit 1 - Output sound 2 to SO1 terminal + Bit 0 - Output sound 1 to SO1 terminal + |
Bit 7 - All sound on/off (0: stop all sound circuits) (Read/Write) + Bit 3 - Sound 4 ON flag (Read Only) + Bit 2 - Sound 3 ON flag (Read Only) + Bit 1 - Sound 2 ON flag (Read Only) + Bit 0 - Sound 1 ON flag (Read Only) + |
Joypad Input |
Bit 7 - Not used + Bit 6 - Not used + Bit 5 - P15 Select Button Keys (0=Select) + Bit 4 - P14 Select Direction Keys (0=Select) + Bit 3 - P13 Input Down or Start (0=Pressed) (Read Only) + Bit 2 - P12 Input Up or Select (0=Pressed) (Read Only) + Bit 1 - P11 Input Left or Button B (0=Pressed) (Read Only) + Bit 0 - P10 Input Right or Button A (0=Pressed) (Read Only) + |
Serial Data Transfer (Link Cable) |
Bit 7 - Transfer Start Flag (0=No Transfer, 1=Start) + Bit 1 - Clock Speed (0=Normal, 1=Fast) ** CGB Mode Only ** + Bit 0 - Shift Clock (0=External Clock, 1=Internal Clock) + |
8192Hz - 1KB/s - Bit 1 cleared, Normal + 16384Hz - 2KB/s - Bit 1 cleared, Double Speed Mode + 262144Hz - 32KB/s - Bit 1 set, Normal + 524288Hz - 64KB/s - Bit 1 set, Double Speed Mode + |
ld a,$75 + ld ($FF01),a + ld a,$81 + ld ($FF02),a + |
Timer and Divider Registers |
Bit 2 - Timer Stop (0=Stop, 1=Start) + Bits 1-0 - Input Clock Select + 00: 4096 Hz (~4194 Hz SGB) + 01: 262144 Hz (~268400 Hz SGB) + 10: 65536 Hz (~67110 Hz SGB) + 11: 16384 Hz (~16780 Hz SGB) + |
Interrupts |
0 - Disable all Interrupts + 1 - Enable all Interrupts that are enabled in IE Register (FFFF) + |
EI ;Enable Interrupts (ie. IME=1) + DI ;Disable Interrupts (ie. IME=0) + RETI ;Enable Ints & Return (same as the opcode combination EI, RET) + <INT> ;Disable Ints & Call to Interrupt Vector + |
Bit 0: V-Blank Interrupt Enable (INT 40h) (1=Enable) + Bit 1: LCD STAT Interrupt Enable (INT 48h) (1=Enable) + Bit 2: Timer Interrupt Enable (INT 50h) (1=Enable) + Bit 3: Serial Interrupt Enable (INT 58h) (1=Enable) + Bit 4: Joypad Interrupt Enable (INT 60h) (1=Enable) + |
Bit 0: V-Blank Interrupt Request (INT 40h) (1=Request) + Bit 1: LCD STAT Interrupt Request (INT 48h) (1=Request) + Bit 2: Timer Interrupt Request (INT 50h) (1=Request) + Bit 3: Serial Interrupt Request (INT 58h) (1=Request) + Bit 4: Joypad Interrupt Request (INT 60h) (1=Request) + |
1) More than one interrupt signal changed from Low + to High at the same time. + 2) Several interrupts have been requested during a + time in which IME/IE didn't allow these interrupts + to be executed directly. + 3) The user has written a value with several "1" bits + (for example 1Fh) to the IF register. + |
CGB Registers |
Bit 7: Current Speed (0=Normal, 1=Double) (Read Only) + Bit 0: Prepare Speed Switch (0=No, 1=Prepare) (Read/Write) + |
IF KEY1_BIT7 <> DESIRED_SPEED THEN + IE=00H ;(FFFF)=00h + JOYP=30H ;(FF00)=30h + KEY1=01H ;(FF4D)=01h + STOP ;STOP + ENDIF + |
The CPU (2.10 MHz, 1 Cycle = approx. 0.5us) + Timer and Divider Registers + Serial Port (Link Cable) + DMA Transfer to OAM + |
LCD Video Controller + HDMA Transfer to VRAM + All Sound Timings and Frequencies + |
Bit 0: Write Data (0=LED Off, 1=LED On) (Read/Write) + Bit 1: Read Data (0=Receiving IR Signal, 1=Normal) (Read Only) + Bit 6-7: Data Read Enable (0=Disable, 3=Enable) (Read/Write) + |
Bit 0-2 Select WRAM Bank (Read/Write) + |
SGB Functions |
SGB Description |
SGB Unlocking and Detecting SGB Functions |
146h - SGB Flag - Must be set to 03h for SGB games + 14Bh - Old Licensee Code - Must be set 33h for SGB games + |
01h SGB or Normal Gameboy (DMG) + FFh SGB2 or Pocket Gameboy + 11h CGB or GBA + |
SGB Command Packet Transfers |
RESET 0 0 1 1 0 1 0 + P14 --_---_---_-----------_-------_--... + P15 --_-----------_---_-------_------... + |
1 PULSE Reset + 1 BYTE Command Code*8+Length + 15 BYTES Parameter Data + 1 BIT Stop Bit (0) + |
1 PULSE Reset + 16 BYTES Parameter Data + 1 BIT Stop Bit (0) + |
SGB VRAM Transfers |
SGB Command Summary |
Code Name Expl. + 00 PAL01 Set SGB Palette 0,1 Data + 01 PAL23 Set SGB Palette 2,3 Data + 02 PAL03 Set SGB Palette 0,3 Data + 03 PAL12 Set SGB Palette 1,2 Data + 04 ATTR_BLK "Block" Area Designation Mode + 05 ATTR_LIN "Line" Area Designation Mode + 06 ATTR_DIV "Divide" Area Designation Mode + 07 ATTR_CHR "1CHR" Area Designation Mode + 08 SOUND Sound On/Off + 09 SOU_TRN Transfer Sound PRG/DATA + 0A PAL_SET Set SGB Palette Indirect + 0B PAL_TRN Set System Color Palette Data + 0C ATRC_EN Enable/disable Attraction Mode + 0D TEST_EN Speed Function + 0E ICON_EN SGB Function + 0F DATA_SND SUPER NES WRAM Transfer 1 + 10 DATA_TRN SUPER NES WRAM Transfer 2 + 11 MLT_REG Controller 2 Request + 12 JUMP Set SNES Program Counter + 13 CHR_TRN Transfer Character Font Data + 14 PCT_TRN Set Screen Data Color Data + 15 ATTR_TRN Set Attribute from ATF + 16 ATTR_SET Set Data to ATF + 17 MASK_EN Game Boy Window Mask + 18 OBJ_TRN Super NES OBJ Mode + |
SGB Color Palettes Overview |
White --> Color 0 + Light Gray --> Color 1 + Dark Gray --> Color 2 + Black --> Color 3 + |
SGB Palette Commands |
Byte Content + 0 Command*8+Length (fixed length=01h) + 1-E Color Data for 7 colors of 2 bytes (16bit) each: + Bit 0-4 - Red Intensity (0-31) + Bit 5-9 - Green Intensity (0-31) + Bit 10-14 - Blue Intensity (0-31) + Bit 15 - Not used (zero) + F Not used (00h) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1-2 System Palette number for SGB Color Palette 0 (0-511) + 3-4 System Palette number for SGB Color Palette 1 (0-511) + 5-6 System Palette number for SGB Color Palette 2 (0-511) + 7-8 System Palette number for SGB Color Palette 3 (0-511) + 9 Attribute File + Bit 0-5 - Attribute File Number (00h-2Ch) (Used only if Bit7=1) + Bit 6 - Cancel Mask (0=No change, 1=Yes) + Bit 7 - Use Attribute File (0=No, 1=Apply above ATF Number) + A-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1-F Not used (zero) + |
000-FFF Data for System Color Palette 0-511 + |
SGB Color Attribute Commands |
Byte Content + 0 Command*8+Length (length=1..7) + 1 Number of Data Sets (01h..12h) + 2-7 Data Set #1 + Byte 0 - Control Code (0-7) + Bit 0 - Change Colors inside of surrounded area (1=Yes) + Bit 1 - Change Colors of surrounding character line (1=Yes) + Bit 2 - Change Colors outside of surrounded area (1=Yes) + Bit 3-7 - Not used (zero) + Exception: When changing only the Inside or Outside, then the + Surrounding line becomes automatically changed to same color. + Byte 1 - Color Palette Designation + Bit 0-1 - Palette Number for inside of surrounded area + Bit 2-3 - Palette Number for surrounding character line + Bit 4-5 - Palette Number for outside of surrounded area + Bit 6-7 - Not used (zero) + Data Set Byte 2 - Coordinate X1 (left) + Data Set Byte 3 - Coordinate Y1 (upper) + Data Set Byte 4 - Coordinate X2 (right) + Data Set Byte 5 - Coordinate Y2 (lower) + Specifies the coordinates of the surrounding rectangle. + 8-D Data Set #2 (if any) + E-F Data Set #3 (continued at 0-3 in next packet) (if any) + |
Byte Content + 0 Command*8+Length (length=1..7) + 1 Number of Data Sets (01h..6Eh) (one byte each) + 2 Data Set #1 + Bit 0-4 - Line Number (X- or Y-coordinate, depending on bit 7) + Bit 5-6 - Palette Number (0-3) + Bit 7 - H/V Mode Bit (0=Vertical line, 1=Horizontal Line) + 3 Data Set #2 (if any) + 4 Data Set #3 (if any) + etc. + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Color Palette Numbers and H/V Mode Bit + Bit 0-1 Palette Number below/right of division line + Bit 2-3 Palette Number above/left of division line + Bit 4-5 Palette Number for division line + Bit 6 H/V Mode Bit (0=split left/right, 1=split above/below) + 2 X- or Y-Coordinate (depending on H/V bit) + 3-F Not used (zero) + |
Byte Content + 0 Command*8+Length (length=1..6) + 1 Beginning X-Coordinate + 2 Beginning Y-Coordinate + 3-4 Number of Data Sets (1-360) + 5 Writing Style (0=Left to Right, 1=Top to Bottom) + 6 Data Sets 1-4 (Set 1 in MSBs, Set 4 in LSBs) + 7 Data Sets 5-8 (if any) + 8 Data Sets 9-12 (if any) + etc. + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1-F Not used (zero) + |
000-FD1 Data for ATF0 through ATF44 (4050 bytes) + FD2-FFF Not used + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Attribute File Number (00-2Ch), Bit 6=Cancel Mask + 2-F Not used (zero) + |
SGB Sound Functions |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Sound Effect A (Port 1) Decrescendo 8bit Sound Code + 2 Sound Effect B (Port 2) Sustain 8bit Sound Code + 3 Sound Effect Attributes + Bit 0-1 - Sound Effect A Pitch (0..3=Low..High) + Bit 2-3 - Sound Effect A Volume (0..2=High..Low, 3=Mute on) + Bit 4-5 - Sound Effect B Pitch (0..3=Low..High) + Bit 6-7 - Sound Effect B Volume (0..2=High..Low, 3=Not used) + 4 Music Score Code (must be zero if not used) + 5-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1-F Not used (zero) + |
000 One (or two ???) 16bit expression(s ???) indicating the + transfer destination address and transfer length. + ...-... Transfer Data + ...-FFF Remaining bytes not used + |
0400h-2AFFh APU-RAM Program Area (9.75KBytes) + 2B00h-4AFFh APU-RAM Sound Score Area (8Kbytes) + 4DB0h-EEFFh APU-RAM Sampling Data Area (40.25 Kbytes) + |
Code Description P V Code Description P V + 00 Dummy flag, re-trigger - 2 18 Fast Jump 3 1 + 80 Effect A, stop/silent - 2 19 Jet (rocket) takeoff 0 1 + 01 Nintendo 3 1 1A Jet (rocket) landing 0 1 + 02 Game Over 3 2 1B Cup breaking 2 2 + 03 Drop 3 1 1C Glass breaking 1 2 + 04 OK ... A 3 2 1D Level UP 2 2 + 05 OK ... B 3 2 1E Insert air 1 1 + 06 Select...A 3 2 1F Sword swing 1 1 + 07 Select...B 3 1 20 Water falling 2 1 + 08 Select...C 2 2 21 Fire 1 1 + 09 Mistake...Buzzer 2 1 22 Wall collapsing 1 2 + 0A Catch Item 2 2 23 Cancel 1 2 + 0B Gate squeaks 1 time 2 2 24 Walking 1 2 + 0C Explosion...small 1 2 25 Blocking strike 1 2 + 0D Explosion...medium 1 2 26 Picture floats on & off 3 2 + 0E Explosion...large 1 2 27 Fade in 0 2 + 0F Attacked...A 3 1 28 Fade out 0 2 + 10 Attacked...B 3 2 29 Window being opened 1 2 + 11 Hit (punch)...A 0 2 2A Window being closed 0 2 + 12 Hit (punch)...B 0 2 2B Big Laser 3 2 + 13 Breath in air 3 2 2C Stone gate closes/opens 0 2 + 14 Rocket Projectile...A 3 2 2D Teleportation 3 1 + 15 Rocket Projectile...B 3 2 2E Lightning 0 2 + 16 Escaping Bubble 2 1 2F Earthquake 0 2 + 17 Jump 3 1 30 Small Laser 2 2 + |
Code Description P V Code Description P V + 00 Dummy flag, re-trigger - 4 0D Waterfall 2 2 + 80 Effect B, stop/silent - 4 0E Small character running 3 1 + 01 Applause...small group 2 1 0F Horse running 3 1 + 02 Applause...medium group 2 2 10 Warning sound 1 1 + 03 Applause...large group 2 4 11 Approaching car 0 1 + 04 Wind 1 2 12 Jet flying 1 1 + 05 Rain 1 1 13 UFO flying 2 1 + 06 Storm 1 3 14 Electromagnetic waves 0 1 + 07 Storm with wind/thunder 2 4 15 Score UP 3 1 + 08 Lightning 0 2 16 Fire 2 1 + 09 Earthquake 0 2 17 Camera shutter, formanto 3 4 + 0A Avalanche 0 2 18 Write, formanto 0 1 + 0B Wave 0 1 19 Show up title, formanto 0 1 + 0C River 3 2 + |
SGB System Control Commands |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Gameboy Screen Mask (0-3) + 0 Cancel Mask (Display activated) + 1 Freeze Screen (Keep displaying current picture) + 2 Blank Screen (Black) + 3 Blank Screen (Color 0) + 2-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Attraction Disable (0=Enable, 1=Disable) + 2-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Test Mode Enable (0=Disable, 1=Enable) + 2-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Disable Bits + Bit 0 - Use of SGB-Built-in Color Palettes (1=Disable) + Bit 1 - Controller Set-up Screen (0=Enable, 1=Disable) + Bit 2 - SGB Register File Transfer (0=Receive, 1=Disable) + Bit 3-6 - Not used (zero) + 2-F Not used (zero) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 SNES Destination Address, low + 2 SNES Destination Address, high + 3 SNES Destination Address, bank number + 4 Number of bytes to write (01h-0Bh) + 5 Data Byte #1 + 6 Data Byte #2 (if any) + 7 Data Byte #3 (if any) + etc. + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 SNES Destination Address, low + 2 SNES Destination Address, high + 3 SNES Destination Address, bank number + 4-F Not used (zero) + |
000-FFF Data + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 SNES Program Counter, low + 2 SNES Program Counter, high + 3 SNES Program Counter, bank number + 4 SNES NMI Handler, low + 5 SNES NMI Handler, high + 6 SNES NMI Handler, bank number + 7-F Not used, zero + |
SGB Multiplayer Command |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Multiplayer Control (0-3) (Bit0=Enable, Bit1=Two/Four Players) + 0 = One player + 1 = Two players + 3 = Four players + 2-F Not used (zero) + |
0Fh Joypad 1 + 0Eh Joypad 2 + 0Dh Joypad 3 + 0Ch Joypad 4 + |
SGB Border and OBJ Commands |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Tile Transfer Destination + Bit 0 - Tile Numbers (0=Tiles 00h-7Fh, 1=Tiles 80h-FFh) + Bit 1 - Tile Type (0=BG Tiles, 1=OBJ Tiles) + Bit 2-7 - Not used (zero) + 2-F Not used (zero) + |
000-FFF Bitmap data for 128 Tiles + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1-F Not used (zero) + |
000-7FF BG Map 32x32 Entries of 16bit each (2048 bytes) + 800-87F BG Palette Data (Palettes 4-7, each 16 colors of 16bits each) + 880-FFF Not used, don't care + |
Bit 0-9 - Character Number (use only 00h-FFh, upper 2 bits zero) + Bit 10-12 - Palette Number (use only 4-7, officially use only 4-6) + Bit 13 - BG Priority (use only 0) + Bit 14 - X-Flip (0=Normal, 1=Mirror horizontally) + Bit 15 - Y-Flip (0=Normal, 1=Mirror vertically) + |
Byte Content + 0 Command*8+Length (fixed length=1) + 1 Control Bits + Bit 0 - SNES OBJ Mode enable (0=Cancel, 1=Enable) + Bit 1 - Change OBJ Color (0=No, 1=Use definitions below) + Bit 2-7 - Not used (zero) + 2-3 System Color Palette Number for OBJ Palette 4 (0-511) + 4-5 System Color Palette Number for OBJ Palette 5 (0-511) + 6-7 System Color Palette Number for OBJ Palette 6 (0-511) + 8-9 System Color Palette Number for OBJ Palette 7 (0-511) + These color entries are ignored if above Control Bit 1 is zero. + Because each OBJ palette consists of 16 colors, four system + palette entries (of 4 colors each) are transferred into each + OBJ palette. The system palette numbers are not required to be + aligned to a multiple of four, and will wrap to palette number + 0 when exceeding 511. For example, a value of 511 would copy + system palettes 511, 0, 1, 2 to the SNES OBJ palette. + A-F Not used (zero) + |
8F90-8FEF SNES OAM, 24 Entries of 4 bytes each (96 bytes) + 8FF0-8FF5 SNES OAM MSBs, 24 Entries of 2 bits each (6 bytes) + 8FF6-8FFF Not used, don't care (10 bytes) + |
Byte 0 OBJ X-Position (0-511, MSB is separately stored, see below) + Byte 1 OBJ Y-Position (0-255) + Byte 2-3 Attributes (16bit) + Bit 0-8 Tile Number (use only 00h-FFh, upper bit zero) + Bit 9-11 Palette Number (use only 4-7) + Bit 12-13 OBJ Priority (use only 3) + Bit 14 X-Flip (0=Normal, 1=Mirror horizontally) + Bit 15 Y-Flip (0=Normal, 1=Mirror vertically) + |
Actually, the format is unknown ??? However, 2 bits are used per entry: + One bit is the most significant bit of the OBJ X-Position. + The other bit specifies the OBJ size (8x8 or 16x16 pixels). + |
CPU Registers and Flags |
16bit Hi Lo Name/Function + AF A - Accumulator & Flags + BC B C BC + DE D E DE + HL H L HL + SP - - Stack Pointer + PC - - Program Counter/Pointer + |
Bit Name Set Clr Expl. + 7 zf Z NZ Zero Flag + 6 n - - Add/Sub-Flag (BCD) + 5 h - - Half Carry Flag (BCD) + 4 cy C NC Carry Flag + 3-0 - - - Not used (always zero) + |
CPU Instruction Set |
ld r,r xx 4 ---- r=r + ld r,n xx nn 8 ---- r=n + ld r,(HL) xx 8 ---- r=(HL) + ld (HL),r 7x 8 ---- (HL)=r + ld (HL),n 36 nn 12 ---- + ld A,(BC) 0A 8 ---- + ld A,(DE) 1A 8 ---- + ld A,(nn) FA 16 ---- + ld (BC),A 02 8 ---- + ld (DE),A 12 8 ---- + ld (nn),A EA 16 ---- + ld A,(FF00+n) F0 nn 12 ---- read from io-port n (memory FF00+n) + ld (FF00+n),A E0 nn 12 ---- write to io-port n (memory FF00+n) + ld A,(FF00+C) F2 8 ---- read from io-port C (memory FF00+C) + ld (FF00+C),A E2 8 ---- write to io-port C (memory FF00+C) + ldi (HL),A 22 8 ---- (HL)=A, HL=HL+1 + ldi A,(HL) 2A 8 ---- A=(HL), HL=HL+1 + ldd (HL),A 32 8 ---- (HL)=A, HL=HL-1 + ldd A,(HL) 3A 8 ---- A=(HL), HL=HL-1 + |
ld rr,nn x1 nn nn 12 ---- rr=nn (rr may be BC,DE,HL or SP) + ld SP,HL F9 8 ---- SP=HL + push rr x5 16 ---- SP=SP-2 (SP)=rr (rr may be BC,DE,HL,AF) + pop rr x1 12 (AF) rr=(SP) SP=SP+2 (rr may be BC,DE,HL,AF) + |
add A,r 8x 4 z0hc A=A+r + add A,n C6 nn 8 z0hc A=A+n + add A,(HL) 86 8 z0hc A=A+(HL) + adc A,r 8x 4 z0hc A=A+r+cy + adc A,n CE nn 8 z0hc A=A+n+cy + adc A,(HL) 8E 8 z0hc A=A+(HL)+cy + sub r 9x 4 z1hc A=A-r + sub n D6 nn 8 z1hc A=A-n + sub (HL) 96 8 z1hc A=A-(HL) + sbc A,r 9x 4 z1hc A=A-r-cy + sbc A,n DE nn 8 z1hc A=A-n-cy + sbc A,(HL) 9E 8 z1hc A=A-(HL)-cy + and r Ax 4 z010 A=A & r + and n E6 nn 8 z010 A=A & n + and (HL) A6 8 z010 A=A & (HL) + xor r Ax 4 z000 + xor n EE nn 8 z000 + xor (HL) AE 8 z000 + or r Bx 4 z000 A=A | r + or n F6 nn 8 z000 A=A | n + or (HL) B6 8 z000 A=A | (HL) + cp r Bx 4 z1hc compare A-r + cp n FE nn 8 z1hc compare A-n + cp (HL) BE 8 z1hc compare A-(HL) + inc r xx 4 z0h- r=r+1 + inc (HL) 34 12 z0h- (HL)=(HL)+1 + dec r xx 4 z1h- r=r-1 + dec (HL) 35 12 z1h- (HL)=(HL)-1 + daa 27 4 z-0x decimal adjust akku + cpl 2F 4 -11- A = A xor FF + |
add HL,rr x9 8 -0hc HL = HL+rr ;rr may be BC,DE,HL,SP + inc rr x3 8 ---- rr = rr+1 ;rr may be BC,DE,HL,SP + dec rr xB 8 ---- rr = rr-1 ;rr may be BC,DE,HL,SP + add SP,dd E8 16 00hc SP = SP +/- dd ;dd is 8bit signed number + ld HL,SP+dd F8 12 00hc HL = SP +/- dd ;dd is 8bit signed number + |
rlca 07 4 000c rotate akku left + rla 17 4 000c rotate akku left through carry + rrca 0F 4 000c rotate akku right + rra 1F 4 000c rotate akku right through carry + rlc r CB 0x 8 z00c rotate left + rlc (HL) CB 06 16 z00c rotate left + rl r CB 1x 8 z00c rotate left through carry + rl (HL) CB 16 16 z00c rotate left through carry + rrc r CB 0x 8 z00c rotate right + rrc (HL) CB 0E 16 z00c rotate right + rr r CB 1x 8 z00c rotate right through carry + rr (HL) CB 1E 16 z00c rotate right through carry + sla r CB 2x 8 z00c shift left arithmetic (b0=0) + sla (HL) CB 26 16 z00c shift left arithmetic (b0=0) + swap r CB 3x 8 z000 exchange low/hi-nibble + swap (HL) CB 36 16 z000 exchange low/hi-nibble + sra r CB 2x 8 z00c shift right arithmetic (b7=b7) + sra (HL) CB 2E 16 z00c shift right arithmetic (b7=b7) + srl r CB 3x 8 z00c shift right logical (b7=0) + srl (HL) CB 3E 16 z00c shift right logical (b7=0) + |
bit n,r CB xx 8 z01- test bit n + bit n,(HL) CB xx 12 z01- test bit n + set n,r CB xx 8 ---- set bit n + set n,(HL) CB xx 16 ---- set bit n + res n,r CB xx 8 ---- reset bit n + res n,(HL) CB xx 16 ---- reset bit n + |
ccf 3F 4 -00c cy=cy xor 1 + scf 37 4 -001 cy=1 + nop 00 4 ---- no operation + halt 76 N*4 ---- halt until interrupt occurs (low power) + stop 10 00 ? ---- low power standby mode (VERY low power) + di F3 4 ---- disable interrupts, IME=0 + ei FB 4 ---- enable interrupts, IME=1 + |
jp nn C3 nn nn 16 ---- jump to nn, PC=nn + jp HL E9 4 ---- jump to HL, PC=HL + jp f,nn xx nn nn 16;12 ---- conditional jump if nz,z,nc,c + jr PC+dd 18 dd 12 ---- relative jump to nn (PC=PC+/-7bit) + jr f,PC+dd xx dd 12;8 ---- conditional relative jump if nz,z,nc,c + call nn CD nn nn 24 ---- call to nn, SP=SP-2, (SP)=PC, PC=nn + call f,nn xx nn nn 24;12 ---- conditional call if nz,z,nc,c + ret C9 16 ---- return, PC=(SP), SP=SP+2 + ret f xx 20;8 ---- conditional return if nz,z,nc,c + reti D9 16 ---- return and enable interrupts (IME=1) + rst n xx 16 ---- call to 00,08,10,18,20,28,30,38 + |
CPU Comparision with Z80 |
Opcode Z80 GMB + --------------------------------------- + 08 EX AF,AF LD (nn),SP + 10 DJNZ PC+dd STOP + 22 LD (nn),HL LDI (HL),A + 2A LD HL,(nn) LDI A,(HL) + 32 LD (nn),A LDD (HL),A + 3A LD A,(nn) LDD A,(HL) + D3 OUT (n),A - + D9 EXX RETI + DB IN A,(n) - + DD <IX> - + E0 RET PO LD (FF00+n),A + E2 JP PO,nn LD (FF00+C),A + E3 EX (SP),HL - + E4 CALL P0,nn - + E8 RET PE ADD SP,dd + EA JP PE,nn LD (nn),A + EB EX DE,HL - + EC CALL PE,nn - + ED <pref> - + F0 RET P LD A,(FF00+n) + F2 JP P,nn LD A,(FF00+C) + F4 CALL P,nn - + F8 RET M LD HL,SP+dd + FA JP M,nn LD A,(nn) + FC CALL M,nn - + FD <IY> - + CB3X SLL r/(HL) SWAP r/(HL) + |
The Cartridge Header |
CE ED 66 66 CC 0D 00 0B 03 73 00 83 00 0C 00 0D + 00 08 11 1F 88 89 00 0E DC CC 6E E6 DD DD D9 99 + BB BB 67 63 6E 0E EC CC DD DC 99 9F BB B9 33 3E + |
80h - Game supports CGB functions, but works on old gameboys also. + C0h - Game works on CGB only (physically the same as 80h). + |
00h = No SGB functions (Normal Gameboy or CGB only game) + 03h = Game supports SGB functions + |
00h ROM ONLY 13h MBC3+RAM+BATTERY + 01h MBC1 15h MBC4 + 02h MBC1+RAM 16h MBC4+RAM + 03h MBC1+RAM+BATTERY 17h MBC4+RAM+BATTERY + 05h MBC2 19h MBC5 + 06h MBC2+BATTERY 1Ah MBC5+RAM + 08h ROM+RAM 1Bh MBC5+RAM+BATTERY + 09h ROM+RAM+BATTERY 1Ch MBC5+RUMBLE + 0Bh MMM01 1Dh MBC5+RUMBLE+RAM + 0Ch MMM01+RAM 1Eh MBC5+RUMBLE+RAM+BATTERY + 0Dh MMM01+RAM+BATTERY FCh POCKET CAMERA + 0Fh MBC3+TIMER+BATTERY FDh BANDAI TAMA5 + 10h MBC3+TIMER+RAM+BATTERY FEh HuC3 + 11h MBC3 FFh HuC1+RAM+BATTERY + 12h MBC3+RAM + |
00h - 32KByte (no ROM banking) + 01h - 64KByte (4 banks) + 02h - 128KByte (8 banks) + 03h - 256KByte (16 banks) + 04h - 512KByte (32 banks) + 05h - 1MByte (64 banks) - only 63 banks used by MBC1 + 06h - 2MByte (128 banks) - only 125 banks used by MBC1 + 07h - 4MByte (256 banks) + 52h - 1.1MByte (72 banks) + 53h - 1.2MByte (80 banks) + 54h - 1.5MByte (96 banks) + |
00h - None + 01h - 2 KBytes + 02h - 8 Kbytes + 03h - 32 KBytes (4 banks of 8KBytes each) + |
00h - Japanese + 01h - Non-Japanese + |
x=0:FOR i=0134h TO 014Ch:x=x-MEM[i]-1:NEXT + |
Memory Bank Controllers |
None (32KByte ROM only) |
MBC1 (max 2MByte ROM and/or 32KByte RAM) |
00h Disable RAM (default) + 0Ah Enable RAM + |
00h = ROM Banking Mode (up to 8KByte RAM, 2MByte ROM) (default) + 01h = RAM Banking Mode (up to 32KByte RAM, 512KByte ROM) + |
MBC2 (max 256KByte ROM and 512x4 bits RAM) |
MBC3 (max 2MByte ROM and/or 32KByte RAM and Timer) |
08h RTC S Seconds 0-59 (0-3Bh) + 09h RTC M Minutes 0-59 (0-3Bh) + 0Ah RTC H Hours 0-23 (0-17h) + 0Bh RTC DL Lower 8 bits of Day Counter (0-FFh) + 0Ch RTC DH Upper 1 bit of Day Counter, Carry Bit, Halt Flag + Bit 0 Most significant bit of Day Counter (Bit 8) + Bit 6 Halt (0=Active, 1=Stop Timer) + Bit 7 Day Counter Carry Bit (1=Counter Overflow) + |
HuC1 (MBC with Infrared Controller) |
MBC Timing Issues |
Gamegenie/Shark Cheats |
AB New data + FCDE Memory address, XORed by 0F000h + GI Old data, XORed by 0BAh and rotated left by two + H Don't know, maybe checksum and/or else + |
AB External RAM bank number + CD New Data + GHEF Memory Address (internal or external RAM, A000-DFFF) + |
Power Up Sequence |
AF=$01B0 + BC=$0013 + DE=$00D8 + HL=$014D + Stack Pointer=$FFFE + [$FF05] = $00 ; TIMA + [$FF06] = $00 ; TMA + [$FF07] = $00 ; TAC + [$FF10] = $80 ; NR10 + [$FF11] = $BF ; NR11 + [$FF12] = $F3 ; NR12 + [$FF14] = $BF ; NR14 + [$FF16] = $3F ; NR21 + [$FF17] = $00 ; NR22 + [$FF19] = $BF ; NR24 + [$FF1A] = $7F ; NR30 + [$FF1B] = $FF ; NR31 + [$FF1C] = $9F ; NR32 + [$FF1E] = $BF ; NR33 + [$FF20] = $FF ; NR41 + [$FF21] = $00 ; NR42 + [$FF22] = $00 ; NR43 + [$FF23] = $BF ; NR30 + [$FF24] = $77 ; NR50 + [$FF25] = $F3 ; NR51 + [$FF26] = $F1-GB, $F0-SGB ; NR52 + [$FF40] = $91 ; LCDC + [$FF42] = $00 ; SCY + [$FF43] = $00 ; SCX + [$FF45] = $00 ; LYC + [$FF47] = $FC ; BGP + [$FF48] = $FF ; OBP0 + [$FF49] = $FF ; OBP1 + [$FF4A] = $00 ; WY + [$FF4B] = $00 ; WX + [$FFFF] = $00 ; IE + |
Reducing Power Consumption |
PWR Using the HALT Instruction |
@@wait: + ld a,(0FF44h) ;LY + cp a,144 + jr nz,@@wait + |
ld hl,vblank_flag ;hl=pointer to vblank_flag + xor a ;a=0 + @@wait: ;wait... + halt ;suspend CPU - wait for ANY interrupt + cp a,(hl) ;vblank flag still zero? + jr z,@@wait ;wait more if zero + ld (hl),a ;set vblank_flag back to zero + |
PWR Using the STOP Instruction |
PWR Disabeling the Sound Controller |
PWR Not using CGB Double Speed Mode |
PWR Using the Skills |
Sprite RAM Bug |
inc rr dec rr ;rr = bc,de, or hl + ldi a,(hl) ldd a,(hl) + ldi (hl),a ldd (hl),a + |
External Connectors |
Pin Name Expl. + 1 VDD Power Supply +5V DC + 2 PHI System Clock + 3 /WR Write + 4 /RD Read + 5 /CS Chip Select + 6-21 A0-A15 Address Lines + 22-29 D0-D7 Data Lines + 30 /RES Reset signal + 31 VIN External Sound Input + 32 GND Ground + |
Pin Name Color Expl. + 1 VCC - +5V DC + 2 SOUT red Data Out + 3 SIN orange Data In + 4 P14 - Not used + 5 SCK green Shift Clock + 6 GND blue Ground + |
Pin Expl. + Tip Sound Left + Middle Sound Right + Base Ground + |
END |