Manual
Page 1
Note: Game BoyTM, Game Boy PocketTM, Super Game BoyTM and Game Boy ColorTM are registered trademarks of Anthrox, GABY, Marat Fayzullin, Pascal Felber, Paul Robson, Martin Korth, kOOPa, Bowser Contents: Assembly Language Commands, Timings and Opcodes, and everything you always wanted to know about GB but were afraid to 1999 by DP Game BoyTM CPU Manual Sources by: Pan of Nintendo CO., LTD. © 1989 to ask. THIS DOCUMENT IS PRINTED ON DIN A5 SIZE PAPER (148mm x 210mm)! Version: 1.01 by Nintendo CO., LTD.
Note: Game BoyTM, Game Boy PocketTM, Super Game BoyTM and Game Boy ColorTM are registered trademarks of Anthrox, GABY, Marat Fayzullin, Pascal Felber, Paul Robson, Martin Korth, kOOPa, Bowser Contents: Assembly Language Commands, Timings and Opcodes, and everything you always wanted to know about GB but were afraid to 1999 by DP Game BoyTM CPU Manual Sources by: Pan of Nintendo CO., LTD. © 1989 to ask. THIS DOCUMENT IS PRINTED ON DIN A5 SIZE PAPER (148mm x 210mm)! Version: 1.01 by Nintendo CO., LTD.
Manual
Page 2
... 2.12.2. Interrupt Descriptions 34 2.13. Hardware specifications 5 2.1. Stop Mode 19 2.7.3. Low-Power Mode 19 2.8. Sprite RAM Bug 27 2.9. Special Registers 35 2.13.1. Terms 5 2.3. Sprites 25 2.8.3. 1. Foreword Game BoyTM CPU Manual Table of 8kB Internal RAM 9 2.5.3. Foreword 4 2. Game Boy Specs 6 2.4. Processor 6 2.5. General memory map 8 2.5.2. Echo of Contents 1. User I /O Registers 35 Page 2 V 1.01 Reserved Memory Locations 10 2.6. Power Up Sequence 17 2.7.2. Serial I/O 31 2.12...
... 2.12.2. Interrupt Descriptions 34 2.13. Hardware specifications 5 2.1. Stop Mode 19 2.7.3. Low-Power Mode 19 2.8. Sprite RAM Bug 27 2.9. Special Registers 35 2.13.1. Terms 5 2.3. Sprites 25 2.8.3. 1. Foreword Game BoyTM CPU Manual Table of 8kB Internal RAM 9 2.5.3. Foreword 4 2. Game Boy Specs 6 2.4. Processor 6 2.5. General memory map 8 2.5.2. Echo of Contents 1. User I /O Registers 35 Page 2 V 1.01 Reserved Memory Locations 10 2.6. Power Up Sequence 17 2.7.2. Serial I/O 31 2.12...
Manual
Page 4
... to help you will be found in the Appendix (thanks to get your emulator proved programs run on a real Game Boy can be found in paragraph 2. The first is the 'GBSpec.txt' (also known as the Pan Document) by Pan of three major parts. The...Also, a timing diagram of specifications and commands for Nintendo Super Game Boy speciffic programming by GABY (GAmeBoY). It was designed to Philippe Pouliquen). This can be found in paragraph 1. 1. Foreword This Document was ment to start right off coding for GBC specific programming). Foreword Game BoyTM CPU Manual 1. The third is...
... to help you will be found in the Appendix (thanks to get your emulator proved programs run on a real Game Boy can be found in paragraph 2. The first is the 'GBSpec.txt' (also known as the Pan Document) by Pan of three major parts. The...Also, a timing diagram of specifications and commands for Nintendo Super Game Boy speciffic programming by GABY (GAmeBoY). It was designed to Philippe Pouliquen). This can be found in paragraph 1. 1. Foreword This Document was ment to start right off coding for GBC specific programming). Foreword Game BoyTM CPU Manual 1. The third is...
Manual
Page 5
... informational purposes regarding the inner workings on how their Game Boy works and what makes it "tick". Game BoyTM CPU Manual 2. Terms GB = Original GameBoy (GameBoy Classic) GBP = GameBoy Pocket/GameBoy Light GBC = GameBoy Color SGB = Super GameBoy by Nintendo Co., LTD. Any reference to inform a user on the hand-held game machine known as Game Boy, manufactured and designed by...
... informational purposes regarding the inner workings on how their Game Boy works and what makes it "tick". Game BoyTM CPU Manual 2. Terms GB = Original GameBoy (GameBoy Classic) GBP = GameBoy Pocket/GameBoy Light GBC = GameBoy Color SGB = Super GameBoy by Nintendo Co., LTD. Any reference to inform a user on the hand-held game machine known as Game Boy, manufactured and designed by...
Manual
Page 6
...01 Game Boy Specs Game BoyTM CPU Manual 2.3. Game Boy Specs • CPU: 8-bit (Similar to an Intel 8080. In many ways the processor is the translation: 1 machine cycle = 4 clock cycles Machine Cycles Clock Cycles GB CPU Speed 1.05MHz 4.19MHz NOP Instruction 1 cycle 4 cycles 2.4. Processor The GameBoy uses a computer chip similar to the Z80 processor.) • Main RAM: 8K Byte • Video...4 channels with stereo sound • Power: DC6V 0.7W (DC3V 0.7W for GB Pocket) Nintendo documents describe the CPU & instructions speed in machine cycles while this document describes them in ...
...01 Game Boy Specs Game BoyTM CPU Manual 2.3. Game Boy Specs • CPU: 8-bit (Similar to an Intel 8080. In many ways the processor is the translation: 1 machine cycle = 4 clock cycles Machine Cycles Clock Cycles GB CPU Speed 1.05MHz 4.19MHz NOP Instruction 1 cycle 4 cycles 2.4. Processor The GameBoy uses a computer chip similar to the Z80 processor.) • Main RAM: 8K Byte • Video...4 channels with stereo sound • Power: DC6V 0.7W (DC3V 0.7W for GB Pocket) Nintendo documents describe the CPU & instructions speed in machine cycles while this document describes them in ...
Manual
Page 8
Memory Map 2.5.1. Memory Map Game BoyTM CPU Manual 2.5. General memory map Interrupt Enable Register FFFF Internal RAM FF80 Empty but unusable for I/O FF4C I/O ports FF00 Empty but unusable for I/O FEA0 Sprite Attrib Memory (OAM) FE00 Echo of 8kB Internal RAM E000 8kB Internal RAM C000 8kB switchable RAM bank A000 8kB Video RAM 8000 -- 16kB switchable ROM bank | 4000 |= 32kB Cartrigbe 16kB ROM bank #0 | 0000 -- * NOTE: b = bit, B = byte Page 8 V 1.01 2.5.
Memory Map 2.5.1. Memory Map Game BoyTM CPU Manual 2.5. General memory map Interrupt Enable Register FFFF Internal RAM FF80 Empty but unusable for I/O FF4C I/O ports FF00 Empty but unusable for I/O FEA0 Sprite Attrib Memory (OAM) FE00 Echo of 8kB Internal RAM E000 8kB Internal RAM C000 8kB switchable RAM bank A000 8kB Video RAM 8000 -- 16kB switchable ROM bank | 4000 |= 32kB Cartrigbe 16kB ROM bank #0 | 0000 -- * NOTE: b = bit, B = byte Page 8 V 1.01 2.5.
Manual
Page 10
Reserved Memory Locations Game BoyTM CPU Manual 2.5.4. It contains the following values: 0100-0103 This is the begin code execution point in each cartridge. Usually there is located at 0100-014F in a cart. Reserved Memory Locations 0000 0008 0010 0018 0020 0028 0030 0038 0040 Restart $00 Address (RST $00 calls this address.) Restart $08 Address... 0058 0060 Serial Transfer Completion Interrupt Start Address High-to-Low of P10-P13 Interrupt Start Address An internal information area is a NOP and a JP instruction here but not always. Page 10...
Reserved Memory Locations Game BoyTM CPU Manual 2.5.4. It contains the following values: 0100-0103 This is the begin code execution point in each cartridge. Usually there is located at 0100-014F in a cart. Reserved Memory Locations 0000 0008 0010 0018 0020 0028 0030 0038 0040 Restart $00 Address (RST $00 calls this address.) Restart $08 Address... 0058 0060 Serial Transfer Completion Interrupt Start Address High-to-Low of P10-P13 Interrupt Start Address An internal information area is a NOP and a JP instruction here but not always. Page 10...
Manual
Page 12
Accolade A4 - Konami (Super GameBoy function won't work if $33.) 014C Mask ROM Version number (Usually $00) Page 12 V 1.01 Non-Japanese 014B Licensee code (old): 33 - Hudson HuC-1 10-ROM+MBC3+TIMER+RAM+BATT 11-ROM+MBC3 0148 ROM size: 0 - 256Kbit = 32KByte = 2 banks 1 - 512Kbit = 64KByte = 4 banks ... 0149 RAM size: 0 - None 1 - 16kBit = 2kB = 1 bank 2 - 64kBit = 8kB = 1 bank 3 - 256kBit = 32kB = 4 banks 4 - 1MBit =128kB =16 banks 014A Destination code: 0 - 2.5.4. Reserved Memory Locations Game BoyTM CPU Manual F-ROM+MBC3+TIMER+BATT FF - Check 0144/0145 for Licensee...
Accolade A4 - Konami (Super GameBoy function won't work if $33.) 014C Mask ROM Version number (Usually $00) Page 12 V 1.01 Non-Japanese 014B Licensee code (old): 33 - Hudson HuC-1 10-ROM+MBC3+TIMER+RAM+BATT 11-ROM+MBC3 0148 ROM size: 0 - 256Kbit = 32KByte = 2 banks 1 - 512Kbit = 64KByte = 4 banks ... 0149 RAM size: 0 - None 1 - 16kBit = 2kB = 1 bank 2 - 64kBit = 8kB = 1 bank 3 - 256kBit = 32kB = 4 banks 4 - 1MBit =128kB =16 banks 014A Destination code: 0 - 2.5.4. Reserved Memory Locations Game BoyTM CPU Manual F-ROM+MBC3+TIMER+BATT FF - Check 0144/0145 for Licensee...
Manual
Page 14
... which uses external RAM, MBC2 has 512 x 4 bits of the GameBoy. (NOTE: Nintendo suggests values $0A to enable and $00 to 16/8 mode: Writing a value (XXXXXXBB - X = Don't care, B = bank select bits) into 4000-5FFF area will work with both. • MBC2 (Memory Bank Controller 2): This memory controller works much like the MBC1 controller with the following exceptions: MBC2 will set...
... which uses external RAM, MBC2 has 512 x 4 bits of the GameBoy. (NOTE: Nintendo suggests values $0A to enable and $00 to 16/8 mode: Writing a value (XXXXXXBB - X = Don't care, B = bank select bits) into 4000-5FFF area will work with both. • MBC2 (Memory Bank Controller 2): This memory controller works much like the MBC1 controller with the following exceptions: MBC2 will set...
Manual
Page 19
...instruction be used whenever possible to reduce power consumption & extend the life of both the CPU and ROM. Stop Mode The STOP command halts the GameBoy processor and screen until an interrupt occurs at reset. Low-Power... Always set all RAM to assume the above values will only contain known data if the GameBoy code initializes it is pressed. Power Up Sequence It is serviced and then the instruction immediately following.... Cart RAM the first time it to set these at which point the interrupt is not a good idea to value $00 on power up contains random data. The GB and ...
...instruction be used whenever possible to reduce power consumption & extend the life of both the CPU and ROM. Stop Mode The STOP command halts the GameBoy processor and screen until an interrupt occurs at reset. Low-Power... Always set all RAM to assume the above values will only contain known data if the GameBoy code initializes it is pressed. Power Up Sequence It is serviced and then the instruction immediately following.... Cart RAM the first time it to set these at which point the interrupt is not a good idea to value $00 on power up contains random data. The GB and ...
Manual
Page 21
... CPU Manual 2.7.3. The first HALT causes the second HALT to be repeated, which therefore causes the following command (=itself) to be repeated - No, some other ; button inputs ; game operation jr Main by DP Page 21 again and again. jr z,Main ; return from halt when ; Clear V-Blank flag call call Controls Game ; Below is suggested code for Game Boy...
... CPU Manual 2.7.3. The first HALT causes the second HALT to be repeated, which therefore causes the following command (=itself) to be repeated - No, some other ; button inputs ; game operation jr Main by DP Page 21 again and again. jr z,Main ; return from halt when ; Clear V-Blank flag call call Controls Game ; Below is suggested code for Game Boy...
Manual
Page 22
... around the screen (i.e. Each byte contains a Page 22 V 1.01 Low-Power Mode Game BoyTM CPU Manual ; **** V-Blank Interrupt Routine **** Vblnk: push af push bc push de push hl call SpriteDma ; Video 2.8.1. Do sprite updates ld a,1 ld (VblnkFlag),a pop hl pop de pop bc pop af reti 2.8. when part of it goes off the screen, it appears on...
... around the screen (i.e. Each byte contains a Page 22 V 1.01 Low-Power Mode Game BoyTM CPU Manual ; **** V-Blank Interrupt Routine **** Vblnk: push af push bc push de push hl call SpriteDma ; Video 2.8.1. Do sprite updates ld a,1 ld (VblnkFlag),a pop hl pop de pop bc pop af reti 2.8. when part of it goes off the screen, it appears on...
Manual
Page 25
... hides a sprite. Sprites GameBoy video controller can be displayed per scan line. Sprite patterns have unsigned numbering. highest, $FE04 - Because of... Object Attribute Memory) at $8000-8FFF and have the same format as 0. To display a sprite use the following formulas...: SpriteScreenPositionX (Upper left corner of sprite) = SpriteY - 16 by DP Page 25 When sprites with different x coordinate values overlap, the one with the same x coordinate values overlap, they are taken from the Sprite Pattern Table located at $FE00-FE9F. Game BoyTM CPU Manual...
... hides a sprite. Sprites GameBoy video controller can be displayed per scan line. Sprite patterns have unsigned numbering. highest, $FE04 - Because of... Object Attribute Memory) at $8000-8FFF and have the same format as 0. To display a sprite use the following formulas...: SpriteScreenPositionX (Upper left corner of sprite) = SpriteY - 16 by DP Page 25 When sprites with different x coordinate values overlap, the one with the same x coordinate values overlap, they are taken from the Sprite Pattern Table located at $FE00-FE9F. Game BoyTM CPU Manual...
Manual
Page 34
...reason is to indicate to the user when the video hardware is not using the EI instruction. 1. This can be freely accessed. Page 34 V 1.01 This period lasts approximately 1.1 ms. 2. 2.12.2. Interrupt Descriptions Game BoyTM CPU Manual 2.12.2. Timer Overflow This ...controlling the SCX/SCY registers ($FF43/$FF42) to occur as described by the STAT register ($FF40). Interrupt Descriptions The following interrupts only occur if they have been enabled in the Interrupt Enable register ($FFFF) and if the interrupts have actually been enabled using video ram so it may be useful...
...reason is to indicate to the user when the video hardware is not using the EI instruction. 1. This can be freely accessed. Page 34 V 1.01 This period lasts approximately 1.1 ms. 2. 2.12.2. Interrupt Descriptions Game BoyTM CPU Manual 2.12.2. Timer Overflow This ...controlling the SCX/SCY registers ($FF43/$FF42) to occur as described by the STAT register ($FF40). Interrupt Descriptions The following interrupts only occur if they have been enabled in the Interrupt Enable register ($FFFF) and if the interrupts have actually been enabled using video ram so it may be useful...
Manual
Page 82
C - Set if result is zero. H - 3.3.3. 8-Bit ALU Game BoyTM CPU Manual 3. SUB n Description: Subtract n from bit 4. N - Set. Opcodes: Instruction SUB SUB SUB SUB SUB SUB SUB SUB SUB Parameters A B C D E H L (HL) # Opcode 97 90 91 92 93 94 95 96 D6 Cycles 4 4 4 4 4 4 4 8 8 Page 82 V 1.01 Use with: n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set if no borrow. Set if no borrow from A.
C - Set if result is zero. H - 3.3.3. 8-Bit ALU Game BoyTM CPU Manual 3. SUB n Description: Subtract n from bit 4. N - Set. Opcodes: Instruction SUB SUB SUB SUB SUB SUB SUB SUB SUB Parameters A B C D E H L (HL) # Opcode 97 90 91 92 93 94 95 96 D6 Cycles 4 4 4 4 4 4 4 8 8 Page 82 V 1.01 Use with: n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set if no borrow. Set if no borrow from A.
Manual
Page 83
H - C - Use with: n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set if no borrow. Set if no borrow from A. by DP Page 83 Set if result is zero. Set. N - Game BoyTM CPU Manual 3.3.3. 8-Bit ALU 4. Opcodes: Instruction SBC SBC SBC SBC SBC SBC SBC SBC SBC Parameters A,A A,B A,C A,D A,E A,H A,L A,(HL) A,# Opcode 9F 98 99 9A 9B 9C 9D 9E ?? Cycles 4 4 4 4 4 4 4 8 ? SBC A,n Description: Subtract n + Carry flag from bit 4.
H - C - Use with: n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set if no borrow. Set if no borrow from A. by DP Page 83 Set if result is zero. Set. N - Game BoyTM CPU Manual 3.3.3. 8-Bit ALU 4. Opcodes: Instruction SBC SBC SBC SBC SBC SBC SBC SBC SBC Parameters A,A A,B A,C A,D A,E A,H A,L A,(HL) A,# Opcode 9F 98 99 9A 9B 9C 9D 9E ?? Cycles 4 4 4 4 4 4 4 8 ? SBC A,n Description: Subtract n + Carry flag from bit 4.
Manual
Page 87
CP n Description: Compare A with : n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set for no borrow from bit 4. This is zero. (Set if A = n.) N - H - Set. Game BoyTM CPU Manual 3.3.3. 8-Bit ALU 8. C - Use with n. Set if result is basically an A - n subtraction instruction but the results are thrown away. Set if no borrow. (Set if A < n.) Opcodes: Instruction CP CP CP CP CP CP CP CP CP Parameters A B C D E H L (HL) # Opcode BF B8 B9 BA BB BC BD BE FE Cycles 4 4 4 4 4 4 4 8 8 by DP Page 87
CP n Description: Compare A with : n = A,B,C,D,E,H,L,(HL),# Flags affected: Z - Set for no borrow from bit 4. This is zero. (Set if A = n.) N - H - Set. Game BoyTM CPU Manual 3.3.3. 8-Bit ALU 8. C - Use with n. Set if result is basically an A - n subtraction instruction but the results are thrown away. Set if no borrow. (Set if A < n.) Opcodes: Instruction CP CP CP CP CP CP CP CP CP Parameters A B C D E H L (HL) # Opcode BF B8 B9 BA BB BC BD BE FE Cycles 4 4 4 4 4 4 4 8 8 by DP Page 87
Manual
Page 95
Game BoyTM CPU Manual 3.3.5. H - CPL Description: Complement A register. (Flip all bits.) Flags affected: Z - Set or reset according to operation. Not affected. Reset. Set. Miscellaneous 2. C - N - This instruction adjusts register A so that the correct representation of Binary Coded Decimal (BCD) is zero. Opcodes: Instruction Parameters DAA -/- C - Not affected. Opcodes: Instruction Parameters CPL -/- Flags affected: Z - Set if register A is obtained. Opcode Cycles 2F 4 by DP Page...
Game BoyTM CPU Manual 3.3.5. H - CPL Description: Complement A register. (Flip all bits.) Flags affected: Z - Set or reset according to operation. Not affected. Reset. Set. Miscellaneous 2. C - N - This instruction adjusts register A so that the correct representation of Binary Coded Decimal (BCD) is zero. Opcodes: Instruction Parameters DAA -/- C - Not affected. Opcodes: Instruction Parameters CPL -/- Flags affected: Z - Set if register A is obtained. Opcode Cycles 2F 4 by DP Page...
Manual
Page 108
3.3.7. Reset. Use with: b = 0 - 7, r = A,B,C,D,E,H,L,(HL) Flags affected: Z - Not affected. Set. N - C - Bit Opcodes Game BoyTM CPU Manual 3.3.7. H - Opcodes: Instruction BIT BIT BIT BIT BIT BIT BIT BIT Parameters b,A b,B b,C b,D b,E b,H b,L b,(HL) Opcode CB 47 CB 40 CB 41 CB 42 CB 43 CB 44 CB 45 CB 46 Cycles 8 8 8 8 8 8 8 16 Page 108 V 1.01 Bit Opcodes 1. BIT b,r Description: Test bit b in register r. Set if bit b of register r is 0.
3.3.7. Reset. Use with: b = 0 - 7, r = A,B,C,D,E,H,L,(HL) Flags affected: Z - Not affected. Set. N - C - Bit Opcodes Game BoyTM CPU Manual 3.3.7. H - Opcodes: Instruction BIT BIT BIT BIT BIT BIT BIT BIT Parameters b,A b,B b,C b,D b,E b,H b,L b,(HL) Opcode CB 47 CB 40 CB 41 CB 42 CB 43 CB 44 CB 45 CB 46 Cycles 8 8 8 8 8 8 8 16 Page 108 V 1.01 Bit Opcodes 1. BIT b,r Description: Test bit b in register r. Set if bit b of register r is 0.
Manual
Page 119
... # character to remind you that they have to 0. It is the System color palette. Game BoyTM CPU Manual 4. Foreword Super GameBoy Commands, Extracted by kOOPa, 15-Feb-98 Last updated by DP Page 119 The hardware color palette is 128 bits + a zero bit. The...Game Boy commands 4. Palettes There are only really two palette types: SGB color palettes and by : Bowser, 13-June-98 Updates: Block Area mode ($04) control codes updated Line mode ($05) written Divide mode ($06) written 1CHR mode ($07) written A SGB command transfer is shown at the bottom of 128 bit packages to be set...
... # character to remind you that they have to 0. It is the System color palette. Game BoyTM CPU Manual 4. Foreword Super GameBoy Commands, Extracted by kOOPa, 15-Feb-98 Last updated by DP Page 119 The hardware color palette is 128 bits + a zero bit. The...Game Boy commands 4. Palettes There are only really two palette types: SGB color palettes and by : Bowser, 13-June-98 Updates: Block Area mode ($04) control codes updated Line mode ($05) written Divide mode ($06) written 1CHR mode ($07) written A SGB command transfer is shown at the bottom of 128 bit packages to be set...