GameBoy Programming Manual
GameBoy Programming Manual
GameBoy Programming Manual
Version 1.0
DMG-06-4216-001-A
Released 11/09/1999
“Confidential”
INTRODUCTION
This manual is a combination and reorganization of the information presented in the Game Boy Development
Manual, revision G, and the Game Boy Color User's Guide, version 1.3. In addition, it incorporates all information
related to Game Boy programming, including programming for Super Game Boy and the Game Boy Pocket
Printer.
Note: SGB is used to denote both SGB and SGB2 when no distinction is necessary.
SGB2 is used only in cases where distinction is necessary.
3
Game Boy Programming Manual
4
Preface: To Publishers
PREFACE: TO PUBLISHERS
* Please do not send original artwork or materials, as they will not be returned.
CGB software and/or product proposals are evaluated based on the following criteria:
• Use of Color
To ensure that the expectations of the Game Boy Color consumer are met, Mario Club will evaluate the
use of color in all CGB games (dual or dedicated) using the following criteria:
Please detail or demonstrate how your game will utilize color capabilities of the CGB. Use whatever
means will best allow you to do so, such as artists renderings, programmed demos, ROM images, written
descriptions, and so on.
5
Game Boy Programming Manual
Please submit a written proposal of the enhancements to us for pre-approval. Use whatever additional
means that will best allow you to communicate the game-play enhancements, such as storyboards,
treatments, videotapes, programmed demos, and so on.
If you wish to arrange electronic transfer of the ROM image, please contact Sharon Pfeifle in our Testing
and Engineering department at (425) 861-2768 or by e-mail at “sharpf01@noa.nintendo.com”. Please
notify me when you have made an electronic submission for our review.
• Proposed Developer
Please supply us with the name, address and phone number of the proposed developer. If the developer
is not an Authorized Nintendo CGB Developer, please contact Lief Thompson at
“liefth@noa.nintendo.com” or 425-861-2823, and he will provide you with the application information.
• Schedule Information
Please provide us with an estimated product schedule, including interim ROM submission(s), final Mario
Club submission, submission of the master ROM to Lot Check, and the release date.
You will be contacted with the evaluation results when the Licensee Product Support Group has completed its
evaluation of your ROM or concept submission.
6
Table of Contents
Table of Contents
Page Number
Introduction............................................................................................... 3
Preface: To Publishers ....................................................................... 5
Chapter 1 System ................................................................................10
Chapter 2 Display Functions............................................................. 46
Chapter 3 Sound Functions .............................................................. 70
Chapter 4 CPU Instruction Set.......................................................... 84
Chapter 5 Miscellaneous General Information ............................. 114
Chapter 6 The Super Game Boy System ....................................... 124
Chapter 7 Super Game Boy Sound ................................................ 182
Chapter 8 Game Boy Memory Controllers(MBC).......................... 212
Chapter 9 Pocket Printer ................................................................. 233
Appendix 1 Programming Cautions .................................................. 248
Appendix 2 Register and Instruction Set Summaries ..................... 260
Appendix 3 Software Submission Requirements............................ 276
7
Game Boy Programming Manual
8
Chapter 1: System
9
Game Boy Programming Manual
CHAPTER 1: SYSTEM
1. GENERAL SYSTEM INFORMATION
1.1 System Overview
Structure
At the heart of the DMG/CGB system is a CPU with a built-in LCD controller designed for
DMG/CGB use.
System
[DMG] [CGB]
Ø Dot-matrix LCD unit capable of Ø Color dot-matrix LCD unit capable of
grayscale display RGB with 32 grayscale shades
Ø 64 Kbit – SRAM (for LCD display) Ø 128 Kbit – SRAM (for LCD display)
Ø 64 Kbit – SRAM (working memory) Ø 256 Kbit – SRAM (working memory)
Ø Infrared communication link (photo
transistor, photo LED)
10
Chapter 1: System
Note To operate in CGB mode, specific code must first be placed in the ROM
data area of the user program. For more information, see Chapter 5,
Section 2, Recognition of CGB support (CGB only) in ROM Data.
Power Source
Ø Battery/AC adapter/Battery charger
The 6-pin serial communication subconnector and the AC adapter input connector of the DMG hardware
that preceded MGB are shaped differently than those of MGB and CGB. Thus, two types of accessories
are available — those exclusively for DMG and those exclusively for MGB/CGB. In addition, a
conversion connector is necessary for communication between DMG and MGB/CGB.
11
Game Boy Programming Manual
LCD Panel
Power Switch
DC-DC Power to
LCD Driver Converter System
Headphone
Terminal Volume
Amp
Speaker
Display RAM
DMG: 64 Kbit
CGB: 128 Kbit
8-bit
Infrared Microprocessor
Communication
(CGB only)
Work RAM
DMG: 64 Kbit
6-pin CGB: 256 Kbit
Subconnector
Operating
Keys Game Boy
Hardware Unit
Mask ROM
Program
SRAM
(Backup)
Game Pak
12
Chapter 1: System
0x000-0x0FF: Allocated as the destination address for RST instructions and the starting address for
interrupts.
0x100-0x14F: Allocated as the ROM area for storing data such as the name of the game.
0x150: Allocated as the starting address of the user program.
The 8 KB from 0x8000 to 0x9FFF is used as RAM for the LCD display. In CGB, the amount of RAM
allocated for this purpose is 16 KB (8 KB x 2), twice the amount allocated for the LCD display in DMG,
and this RAM can be used in 8 KB units using bank switching. The 8 KB RAM areas are divided into the
following 2 areas.
1 An area for character data
2 An area for BG (background) display data (Character code and attribute)
The 8 KB from 0xA000 to 0xBFFF is the area allocated for external expansion RAM.
The 8 KB from 0xC000 to 0xDFFF is the work RAM area.
In DMG, the 8 KB of working RAM is implemented without change. In CGB, bank switching is used to
provide 32 KB of working RAM. This 32 KB area is divided into 8 areas of 4 KB each.
1 The 4 KB from 0xC000 to 0xCFFF is fixed as Bank 0.
2 The 4 KB from 0xD000 to 0xDFFF can be switched between banks 1 though 7.
13
Game Boy Programming Manual
0x000
Interrupt Address
RST Address
0x100
ROM Data
Area
0x150 Program Start Address
0x8000
Bank 1
Bank 0
Character Data
Character Data
(CGB only)
0x9800
BG Display Data 1 (CGB only)
Character Codes Attributes
0x9C00
BG Display Data 2 (CGB only)
Character Codes Attributes
0xA000
External Expansion
Working RAM
8 KB
(CGB Only)
0xC000
(DMG)
Bank 0 (Fixed)
Unit Working RAM
0xD000
8 KB
Banks 1-7 (Switchable)
0xE000
Use of area 0xE000 - 0xFDFF prohibited
0xFE00
OAM (40 OBJs) 7 6 5 4 3 2 1 0 0xFE00
(40 x 32 bits) (OBJ 0)
0xFEA0 Y0
X0
0xFF00
Port/Mode Registers Character Code
Control Register Color Palette (CGB)
Sound Register Character Bank (CGB)
Palette (DMG)
0xFF80 Left/Right
Up/Down
Working & Stack RAM Priority
127 bytes Y39
0xFFFE X39
0xFFFF Character Code
0xFE9F
(OBJ 39)
14
Chapter 1: System
15
Game Boy Programming Manual
OAM FE00~FE9F ← ←
Sound Registers NR x x FF10~FF26 ← ←
Waveform RAM FF30~FF3F ← ←
16
Chapter 1: System
2. CPU
2.1 OVERVIEW OF CPU FEATURES
The CPUs of DMG and CGB are ICs customized for DMG/CGB use, and have the following features.
CPU Features
Central to the 8-bit CPU are the following features, including an I/O port and timer.
Ø 127 x 8 bits of built-in RAM (working and stack)
Ø RAM for LCD Display: <DMG> 8 KB/<CGB>16 KB ( )
Ø Working RAM: <DMG> 8KB/<CGB> 32 KB
Ø Built-in 16-stage Frequency Divider
Ø Built-in 8-bit Timer
Ø 4 types of Internal Interrupts (maskable)
Ø 1 type of External Interrupt (maskable)
Ø Built-in DMA Controller
Ø Input Ports P10 ~ P13
Ø Output Ports P14 and P15
Ø Serial I/O Ports SIN, SCK, SOUT
Ø Infrared I/O Port <CGB only>
Sound Functions
Each system is equipped with 4 types of sound synthesis circuitry.
Ø Sound 1: Quadrangular waveform, sweep and envelope functions
Ø Sound 2: Quadrangular waveform, envelope functions
Ø Sound 3: Arbitrary waveform, generated
Ø Sound 4: White noise, generated
Ø 2 output channels (output can be allocated to a channel)
Ø Synthesized output with external sound input <CGB only>
17
Game Boy Programming Manual
Miscellaneous
Ø An internal monitor program is built into DMG/CGB CPUs. When power is
turned on or the Game Boy is reset, the internal monitor program first
initializes components such as the ports, then passes control to the user
program.
Ø Instruction cycles
<DMG> 0.954 µs (source oscillation: 4.1943 MHz)
<CGB> 0.954 µs/0.477 µs, switchable (source oscillation: 8.3886 MHz)
18
Chapter 1: System
....
/RD DMA
Timing
Data Buffer Controller
/WR Control
/CS
Synthesizer
Circuit
•@•@•@•@•@•@•@•@•@ Sound 2
Ø Divider NR20-NR23
•@•@
DIV SO2
Sound 3
NR30-NR33
Timer
TIMA TMA TAC
Sound 4
NR40-NR42
....
/MRD Keyport
Timing
Data Buffer
/MWR Control
/CS1
RAM
Interrupt
127 bytes
Controller
CPU Core
A0-A15
ROM
PC 2 Kbytes
SP Sound 1
NR10-NR14
Address Buffer
Synthesizer Circuit
A F SO1
Sound 2
MA0-MA12 NR20-NR23 SO2
B C
Sound 3
NR30-NR33
RA0,RA1 D E VIN
Sound 4
H L NR40-NR42
Waveform Sound
PHI Divider RAM Control
32x4 NR50-NR52
DIV
CK1
C. G Timer
CK2 TIMA TMA TAC Palette RAM
LDR0-LDR5
LDG0-LDG5
SCK
LCD Drive Signal Buffer LDB0-LDB5
LCD Controller DCK
SI SIO OAM RAM
40x28 bit (DMA Controller) SPL
SO LP
PS
SPS
Infrared CLS
R0-R4 Comm Port/ MOD
LCD Display RAM Interface REVC
General
Purpose
Port
VDD3 M1
VDD5
/RESET
GND
MD8-MD15 TEST0-TEST2 /MCS0,/MCS1 PSMO1 PSMO0
20
Chapter 1: System
DMA Transfers
DMA transfers are controlled by the DMA registers.
<DMG>
DMG allows 40 x 32-bit DMA transfers from 0x8000-0xDFFF to OAM (0xFE00-0xFE9F). The transfer
start address can be specified in increments of 0x100 for 0x8000-0xDFFF.
<CGB>
In addition to the DMA transfers method for DMG (from 0x0000-0xDFFF in CGB), CGB enables two new
types of DMA transfer — horizontal blanking and general-purpose DMA transfers.
Note, however, that when performing a DMG-type DMA transfer on CGB, some consideration must be
given to specifying the destination RAM area.
For more information, see the DMA Functions section in Chapter 2.
Timer
The timer is composed of the following:
Ø TIMA (timer counter)
Ø TMA (timer modulo register)
Ø TAC (timer control register)
Controller Connections
Ø P10-P13: Input ports
Ø P14-P15: The key matrix structure is composed of the output ports.
21
Game Boy Programming Manual
At user program startup, the status of the CPU port registers and mode registers are as follows.
Register Status
P1 0
SC 0
TIMA 0
TAC 0
IE 0
LCDC $83 BG/OBJ ON, LCDC OPERATION
SCY 0
SCX 0
LYC 0
WY 0
W 0
Stack: 0xFFFE
Interrupt Enable (IE) DI
Standby Modes
The standby functions are HALT mode, which halts the system clock, and STOP mode, which halts
oscillation (source oscillation).
HALT Mode
Game Boy switches to HALT mode when a HALT instruction is executed.
The system clock and CPU operation halt in this mode. However, operation of source oscillation
circuitry between terminals CK1 and CK2 continues. Thus, the functions that do not require the
system clock (e.g,, DIV, SIO, timer, LCD controller, and sound circuit) continue to operate in this
mode.
HALT mode is canceled by the following events, which have the starting addresses indicated.
1) A LOW signal to the /RESET terminal
Starting address: 0x0000
2) The interrupt-enable flag and its corresponding interrupt request flag are set
IME = 0 (Interrupt Master Enable flag disabled)
Starting address: address following that of the HALT instruction
IME = 1 (Interrupt Master Enable flag enabled)
Starting address: each interrupt starting address
STOP Mode
Game Boy switches to STOP mode when a STOP instruction is executed.
The system clock and oscillation circuitry between the CK1 and CK2 terminals are halted in this
mode. Thus, all operation is halted except that of the SI0 external clock. STOP mode is canceled by
the following events, and started from the starting address.
3) A LOW signal to the /RESET terminal
Starting address: 0x0000
4) A LOW signal to terminal P10, P11, P12, or P13
Starting address: address following that of STOP instruction
When STOP mode is canceled, the system clock is restored after 217 times the oscillation clock
(DMG: 4 MHz, CGB: 4 MHz/8 MHz), and the CPU resumes operation.
When STOP mode is entered, the STOP instruction should be executed after all interrupt-enable
flags are reset, and meanwhile, terminals P10-P13 are all in a HIGH period.
22
Chapter 1: System
À)
2.4 CPU FUNCTIONS (COMMON TO DMG/CGBÀ
The CPU functions described here are those that are identical in DMG and CGB. CPU functions that are
enhanced in CGB are described in Section 2.5, CPU Functions (Common to DMG/CGBÁ). CPU
functions that cannot be used for DMG are described in Section 2.6, CPU Function (CGB only).
The P1 ports are connected with a matrix for reading key operations.
Res. x4
RIGHT A
P10
LEFT B
P11
All inputs are
UP SELECT pulled High
P12
DOWN START
P13
23
Game Boy Programming Manual
When key input is read, a brief interval is interposed between P14 and P15 output
and reading of the input, as shown below.
Example: KEY LD A, $20 ; Read U, D, L, R keys
LD ($FF00), A ; Port P14 ← LOW output
LD A, ($FF00) ; Register A ← Port P10-P13
LD A, ($FF00) ; Perform this operation twice
.
.
LD A, ($10) ; Reads keys A, B, SE, ST
LD ($FF00), A ; Port P15 ← LOW output
The interrupt request flag (IF: 4) is set by negative edge input at one of the
P13-P10 terminals. Negative edge input requires a LOW period of 24
times source oscillation (DMG = 4 MHz, CGB = 4 MHz/8 MHz).
The interrupt request flag (IF: 4) also is set when a reset signal is input to
the /RESET terminal with a P13~P10 terminal in the LOW state.
The upper 8 bits of the 16-bit counter that counts the basic clock frequency (f) can be referenced. If an
LD instruction is executed, these bits are cleared to 0 regardless of the value being written. f =
(4.194304 MHz).
24
Chapter 1: System
Example
If a TMA write is executed with the same timing as that with which the contents of the modula register
TMA are transferred to TIMA as the result of a timer overflow, the same data is transferred to TIMA.
25
Game Boy Programming Manual
Interrupt starting
Cause of Interrupt Priority
address The LCDC interrupt mode
can be selected (see STAT register).
Vertical blanking 1 0x0040
Mode 00
Mode 01
LCDC status interrupt 2 0x0048 Mode 10
LYC=LY consist
Timer overflow 3 0x0050
When multiple interrupts occur simultaneously, the IE flag of each is set, but only that with the highest
priority is started. Those with lower priorities are suspended.
26
Chapter 1: System
When using an interrupt, set the IF register to 0 before setting the IE register.
The resetting of the IF register that initiates the interrupt is a hardware reset.
The interrupt processing routine should push the registers during interrupt processing.
When an interrupt begins, all other interrupts are prohibited, but processing of the highest level interrupt
is enabled by controlling the IME and IE flags with instructions.
Return from the interrupt routine is performed by the RET1 and RET instructions.
If the RETI instruction is used for the return, the IME flag is automatically set even if a DI instruction is
executed in the interrupt processing routine.
IF the RET instruction is used for the return, the IME flag remains reset unless an EI instruction is
executed in the interrupt routine.
Each interrupt request flag of the IF register can be individually tested using instructions.
Interrupts are accepted during the op code fetch cycle of each instruction.
27
Game Boy Programming Manual
Á)
2.5 CPU FUNCTIONS (COMMON TO DMG/CGBÁ
This section describes the CPU functions that have been enhanced in CGB. Functions that are identical
in DMG and CGB are described in Section 2.4, CPU Functions (Common to DMG/CGBÀ). CPU
functions not available in DMG are described in Section 2.6, CPU Functions (CGB only).
Note In DMG mode, bit 1 of the SC register is set to 1 and cannot be changed,
but the transfer speed is fixed at 8 KHz.
28
Chapter 1: System
When the shift clock goes low, the contents of the SB register are shifted leftward and the data is output
from the highest bit. When the shift clock goes high, input data from the SIN terminal are output to the
lowest bit of the SB register.
If the highest bit of the SC register (SC7) is set, reading and writing to the SB register is prohibited.
An SIO serial transfer should be started (highest SC bit set) after the external or internal shift clock is
selected. Excessive shifting may result if the transfer is started before or at the same time as the shift
clock is selected.
If a transfer is performed using the external clock, the data is first set in the SB register, then the SC
register start flag is set and input from the external clock is awaited. The transfer start flag must be set
each time data is transferred.
Serial communication (SIO) specifications are essentially the same for DMG and CGB. In CGB,
however, the operating speed of the internal shift clock can be set to high by specifying a speed in bit
1.
29
Game Boy Programming Manual
1 2 3 4 5 6 7 8
SCK
SIN
7 6 5 4 3 2 1 0
Read Timing
Output Timing SB
SIN
7 6 5 4 3 2 1 0
VDD
3-Bit Counter
Resistance
OUT
OR
Gate
SCK 3-State Buffer
IN1 IN2
CTRL
Inverter
IN1
Serial Control (SC)
Switch
OUT
IN2 1 2 3 4 5 6
SC0 SC7
CTRL
30
Chapter 1: System
Start
RD Clear
-Select code other than $00 and $FF. (For both slave and
master code).
Transfer
Y
RD = Master Code?
Slave Start -Game first notified that it is slave by master code
N sent from master. Subsequently moves to game flow.
Y
RD = Slave Code?
Master Start -Data sent when this side becomes master is the slave
N
code. Game subsequently moves to game flow.
N
V_BLANK?
SIO Interrupt
Y
RD (SB)
RD = Slave Code?
Transfer
TD: Transfer
(SB) TD Data Buffer
(SB) Slave Code
Timing of
1ms WAIT receive
(SC) $81 synchronized
with Power Up.
(SC) $80
RET
RETI
31
Game Boy Programming Manual
If Master If Slave
Game Processing
N
SIO Finished?
N
V_BLANK Slave waits for
Y finish of SIO to
Y Transfer synchronize with
master. (This is an
example; not
necessary to
(SC) $81 implement this
way.)
RD (SB)
RD (SB)
(SB) TD
(SB) TD
RETI
Data subsequently sent by the master is placed in (SB) and then sent to the slave at the
same time as the (SC) is set to $81. At exactly that same time, the master receives the
slave data. An SIO interrupt is then set in the slave and, as the flowchart indicates, the
slave sets the data to be sent to the master (current data).
Because the data sent from the slave are those loaded at the time of the previous
interrupt, the data sent to the master are one step (one pass through the main program)
behind the current slave data. Exactly the converse is true when this process is viewed
32
Chapter 1: System
from the perspective of the slave. An SIO interrupt is set in the master, and the master
sets the data to be sent to the slave (current data). In this case, because the data sent
from the master are those loaded at the time of the previous interrupt, the data sent to
slave are one step (one pass through main program) behind the current master data.
(*The data of the master and slave can be synchronized by setting the data for each
back 1 pass.)
In the example, 1 byte is sent per frame. (This is not required.) If several bytes are sent
continuously, a transmission interval longer than the processing time of other interrupts
(e.g. V_BLANK) should be used (usually around 1 mS). The reason is that if an attempt
is made to communicate with the slave during another interrupt, the slave cannot receive
the data until after the interrupt is finished. If the next data is transmitted before the
other interrupt is finished, the slave will be unable to receive the initial data of the
transmission.
33
Game Boy Programming Manual
The 32 KB of Game Boy working RAM is divided into 8 banks of 4 KB each. The CPU memory space
0xC000-0xCFFF is set to Bank 0, and the space 0xD000-0xDFFF is switched between banks 1-7.
Switching is performed using the lowest 3 bits of the bank register, SVBK. (If 0 is specified, Bank 1 is
selected.)
The speed of the CGB CPU can be changed to suit different purposes. In normal mode, each block
operates at the same speed as with the DMG CPU. In double-speed mode, all blocks except the liquid
crystal control circuit and the sound circuit operate at twice normal speed.
Immediately after the CGB CPU is reset (immediately after reset cancellation), it operates in normal
mode. The CPU mode is switched by executing a STOP instruction with bit 0 of register Key 1 set to a
value of 1. If this is done in normal mode, the CPU is switched to double-speed mode; otherwise it is
switched to normal mode. Bit 0 of register Key 1 is automatically reset after the operating speed is
switched. In addition, bit 7 of register Key 1 serves as the CPU speed flag, indicating the current CPU
speed.
34
Chapter 1: System
Note When bit 0 of register Key 1 is set to 1, the standby function cannot be
used. When using the standby function, always confirm that bit 0 of
register Key 1 is set to 0. When switching the CPU speed, all interrupt-
enable flags should be reset and a STOP instruction executed with bits 4
and 5 of the P1 port register set to 1, as with the standby function (STOP
mode). When the CPU speed is switched, a return from STOP mode is
automatic, so it is not necessary to generate a STOP mode cancellation.
However, until the CPU speed has been changed and the system clock
returns, bits 4 and 5 of the P1 port register should be made to hold the
value 1.
35
Game Boy Programming Manual
In case the CPU operating speed needed to be switched, the current speed should always be checked
first using the speed flag (bit 7 of the KEY 1 register). This ensures that the speed will be switched to the
intended speed.
No
Speed flag = 0?
Yes
36
Chapter 1: System
The CGB system is equipped with an infrared communication function. An infrared signal can be output
by writing data to bit 0 of register RP. A received infrared signal is latched internally in the CPU by
positive edge of the system clock. (System clock goes to HIGH from LOW.) The latched data can be
read beginning from bit 1 of register RP by setting bits 6 and 7 to 1.
Note When data is not sent or received, always set the values of register RP to
0x00. This register cannot be written to in DMG mode.
Sender:
Setting bit 0 of the CPU register RP to 1 causes the LED to emit light; setting it to 0 turns off the LED.
Receiver:
If the photo transistor detects infrared light, bit 1 of register RP is set to 0; if no infrared light is detected,
this bit is set to 1.
When the receiver recognizes the unmodified signal from the sender as a logical value of 1 or 0, the
receiver actually cannot distinguish between the continuous transmission of 1s and the absence of
received infrared light. The status of the receiver is identical under these conditions. Consequently, to
ensure proper data transmission from sender to receiver in Game Boy Color infrared communication,
signals are distinguished by the size of the interval between the rising edge of the pulse of one received
signal to the rising edge of the subsequent received signal.
37
Game Boy Programming Manual
Double-speed 36 66
Normal speed
“1” signal sent 40 93 1
0
Double speed 50 65
Normal speed
Synchronous pulses 99 132 1
0
Double-speed 57 56 57
Normal speed
Connected pulses
Scatter in the source oscillation of Game Boy Color produces slight individual
differences.
To use infrared communication, data reception must be enabled by setting bits 6 and 7 of Game Boy
Color register RP to 1. However, even with both of these bits set to 1, data cannot immediately be
received. After setting bits 6 and 7 to 1, at least 50 ms should be allowed to pass before using the
infrared port.
38
Chapter 1: System
When data is transmitted and received, it is transmitted in packets. Each packet comprises the 4 parts
shown below, and each part is sandwiched between synchronous pulses. For more information, see
Section 2.6.3.7, Details of Data Transmission and Reception.
The data that comprises a packet is transmitted 1 bit at a time beginning from the MSB.
Transmission Packet
Connector:
Signal that implements an infrared communication connection between 2 Game Boy Colors. This is
always required in the initial packet. When the receiver receives the connector and recognizes it as a
connecting pulse, the receiver returns the same pulse to the sender. The sender then determines
whether this signal is a normal connecting pulse. If it is not recognized as a normal pulse, transmission
is interrupted at this stage. With continuous communication that is not halted before completion, this part
of the packet is unnecessary from the second packet onward.
Header:
Data indicating the type of data being sent and the total number of bytes.
Data:
The transmitted data itself. Maximum of 255 bytes.
There are no data if completion of communication is indicated to the receiver.
(The data portion of the packet consists only of a synchronous pulse.)
Checksum:
2 bytes of data consisting of the sum of the header and all data in the data portion of the packet.
Following this, the communication status is returned from receiver to sender.
When data is transmitted and received, both Game Boy Colors are first placed in receive status. The
one with the send indicator is then designated as the sender, and the other one is designated as the
receiver. The flow of data transmission is shown below.
39
Game Boy Programming Manual
Light emission
Sender
Light detection
Light emission
Receiver
Light detection
The two Game Boy Colors perform initial data reception, then the one designated as the sender (e.g., by
operations such as pressing button A) begins transmission. The connecting portion of the packet is
unnecessary from the second packet onward.
40
Chapter 1: System
Start of infrared
communication
N
o
Read bit 1 of register Y
RP Transmission e
Signal received?
N
o
Value read=0?
Y
e
Pulse-width measurement Transmission of
(software measurement of connecting pulse
H and L periods)
N
Received signal a o
proper connecting Start of reception,
pulse? measurement of width of
received pulse
Y
e
Y
Communication Error e
Connection established Connection established
(receiver) (sender)
Header
Light emission by sender
Synchronous pulse OOH Number of data transmitted Synchronous pulse
Data
Light emission by sender
Synchronous pulse Transmitted data Synchronous pulse
41
Game Boy Programming Manual
A 2-byte checksum consisting of the sum of the header and transmitted data is sandwiched between
synchronous pulses. The receiver uses the checksum to determine whether the transmission was
performed properly and notifies the sender of the results of communication status.
0x00: Communication OK
0x01: Checksum error
The results of the checksum calculated by the receiver do not agree with the checksum sent by the
sender.
In the following cases, the communication status cannot be returned to the sender even if an error is
generated during communication (no response from receiver).
If an error described above in Communication Status is generated, the following error codes are returned
by subroutine.
42
Chapter 1: System
The following figure shows the flow of processing when errors occur during communication. This should
be used as a reference when implementing data communication.
Hardware Unit 1 Hardware Unit 2
Send status Receive status
Connector
NG
If connector not returned by receiver.
Connector
OK
Data(1)
NG If status not returned from receiver.
Data (1) are re-sent, so caution is required.1
Data(1)
NG
If status is NG.
Data(1)
OK
OK, so data (1) are received.
Data(2)
OK
OK, so data (2) are received.
END
NG If status not returned from receiver.
Note that it is easy for sender to enter an
endless loop. 2
END
NG
If completion indicator is NG.
END
OK
OK, so both units end communication.
Finish Finish
43
Game Boy Programming Manual
1) Data(1) and Data(2) each represent 1 packet for transmission, not including the connector.
2) END signifies the packet used to indicate the completion of transmission (not including the
connector).
When programming use of the infrared port, please note the following.
♦ When transmitting more than 256 bytes of data, ensure that the receiver keeps track of
which packet number is being received. When a communication error (status not returned
even though data was received) is generated, the sender will re-send the data, and the
receiver may lose track of the packet number (see note 1 of previous section).
♦ The sender is prone to entering an endless loop when the packet signifying transmission
completion is received. Therefore, the receiver should remain in receive status for
approximately 300 µs after returning the status (see note 2 of previous section).
♦ Depending on the power reserve of the battery, infrared communication may cause a
sudden drop in battery voltage and a complete loss of power.
♦ Ensure that the speed of the two communicating Game Boy Colors is the same (both
double-speed or both normal speed during communication).
♦ Noise can be heard from the speaker and headphones during communication, but this does
not indicate a problem with the hardware.
♦ Ensure that faulty or uncontrolled operation does not occur when infrared communication
signals are input from other game software and devices. Use particular care when using the
same subroutine to communicate between various types of games, because fault y or
uncontrolled operation is especially likely to occur in such cases. (Before performing data
communication, confirm that the other hardware participating in the transmission is using the
same game. This can be accomplished by means such as exchanging a unique key code.)
The following are items to note when using an infrared communication subroutine other than that
provided by Nintendo.
2.6.3.12 Specifications
1) Communication Speed
Normal-speed mode: approximately 7.5 Kbps
Double-speed mode: approximately 10.5 Kbps
2) Communication distances: Minimum, 10 cm, Typical, 15 cm
º
3) Recommended directional angle: approximately ± 15
44
Chapter 2: Display Functions
45
Game Boy Programming Manual
♦ The basic character size can be switched to an 8 x 16-dot composition for OBJ characters only. In this
case, however, only even-numbered character codes can be specified.
Even if an odd-numbered character code is specified, the display will be the same as that seen with an
even-numbered code.
♦ Up to 40 OBJ characters can be displayed in a single screen, and up to 10 characters can be displayed on
each horizontal line. (Stored in OAM (Display RAM: 0xFE00-0xFE9F))
♦ The display data for OBJ characters is stored in OAM (Display RAM: 0xFE00~0xFE9F) in the following
order:
y-axis coordinate
x-axis coordinate
Character code
attribute data
♦ OBJ characters are automatically displayed to the screen using the data written to OAM.
46
Chapter 2: Display Functions
The DMG CPU has 8 KB (64 Kbits) of built-in LCD display RAM.
The CGB CPU has 16 KB (128 Kbits) of built-in LCD display RAM.
In CGB, 16 KB of memory can be joined in the 8 KB (64-Kbit) memory area (0x8000-0x9FFF) by bank
switching using the register VBK (0xFF4F). Bank switching is used exclusively in CGB and cannot be used in
DMG mode.
♦ Character data can be written to the 6144 bytes from 0x8000 to 0x97FF.
♦ By default, the area from 0x8000 to 0x8FFF is allocated for OBJ character data storage.
♦ The register LCDC can be used to select either 0x8000-0x8FFF or 0x8800-0x97FF as the area for storing
BG and window character data.
♦ If the BG character data is allocated to 0x8000-0x8FFF, this data shares an area with OBJ data, and the
character dot data that corresponds to the CHR codes is also the same.
♦ By means of bank switching, CGB can store twice the amount of character data in LCD display RAM that
DMG can store. In this case, both Bank 1 and Bank 0 have the same mapping as the area in DMG.
47
Game Boy Programming Manual
CHR Codes:
<DMG> <CGB>
OBJ: 256 x 1 OBJ: 256 x 2
BG: 256 x 1 BG: 256 x 2
Note Because bank switching is not available in DMG mode, Bank 1 on the right side of
the figure is not available in this mode.
48
Chapter 2: Display Functions
X00 0x8000
0x801F
X02 0x8020
OBJ Code "002" OBJ Code
0x802F Dot Data "102" Dot
X03 0x8030 Data
0x803F
X80 0x8800
OBJ Code "080" BJ Code "180" &
& BG Code "080" BG Code "180"
0x880F Dot Data Dot Data
X81 0x8810 OBJ Code "080" OBJ Code "180"
& BG Code "081" & BG Code "181"
0x881F Dot Data Dot Data
CHR Codes:
<DMG> <CGB>
OBJ: 128 x 1 OBJ: 128 x 2
BG: 256 x 1 BG: 256 x 2
2) If BG character data is allocated to 0x8000-0x8FFF, these data share an area with OBJ data, and
the dot data that correspond to the CHR codes also are the same.
Note Because bank switching is not available in DMG mode, Bank 1 on the right side of
the figure is not available in this mode.
49
Game Boy Programming Manual
1.4 BG Display
Because bank switching is not available in DMG mode, Bank 1 on the right side of the figure is not present in
this mode.
Bank 0 Bank 1 (CGB only)
0x9800 BG Display Data 1
0x9C00
BG Display Data 2
0x9FFF
Data for 32 x 32 character codes (256 x 256 dots) can be specified from 0x9800 or 0x9C00 as BG
display data. Of these, data for 20 x 18 character codes (160 x 144 dots) are displayed to the LCD
screen.
The screen can be scrolled vertically or horizontally one dot at a time by changing the values of scroll
registers SCX and SCY.
50
Chapter 2: Display Functions
ATRB: Attribute
51
Game Boy Programming Manual
♦ Window Display
Specifying a position on the LCD screen using registers WX and WY causes the window to open
downward and to the right beginning from that position.
Window display data also can be specified as character codes, beginning from 0x9800 or 0x9C00 in
external SRAM.
OBJ character data is displayed in the window in the same way as the BG screen.
WX
O 159
O
LCD Screen Area
WY
143
52
Chapter 2: Display Functions
u Screen Timing
160 Segments
10 lines
1.09ms
Vertical Blanking Period
108.7µs/1 line
Frame frequency: 59.7Hz
53
Game Boy Programming Manual
54
Chapter 2: Display Functions
Mode 00: A flag value of 1 represents a horizontal blanking period and means that the CPU
has access to display RAM (0x8000-0x9FFF).
When the value of the flag is 0, display RAM is in use by the LCD controller.
Mode 01: A flag value of 1 indicates a vertical blanking period and means that the CPU has
access (approximately 1 ms) to display RAM (0x8000-0x9FFF).
Mode 10: A flag value of 1 means that OAM (0xFE00-0xFE90) is being used by the LCD
controller and is inaccessible by the CPU.
Mode 11: A flag value of 1 means that the LCD controller is using OAM (0xFE00-0xFE90)
and display RAM (0x8000-0x9FFF). The CPU cannot access either of these areas.
In addition, the register allows selection of 1 of the 4 types of interrupts from the LCD
controller. Executing a write instruction for the match flag resets that flag but does not change
the mode flag.
Changing the values of SCY and SCX scrolls the BG screen vertically and horizontally one dot (or pixel) at a
time.
55
Game Boy Programming Manual
LY indicates which line of data is currently being transferred to the LCD driver. LY takes a value of 0-153, with
144-153 representing the vertical blanking period.
When the value of bit 7 of the LCDC register is 1, writing 1 to this again does not change the value of register
LY.
Writing a value of 0 to bit 7 of the LCDC register when its value is 1 stops the LCD controller, and the value of
register LY immediately becomes 0. (Note: Values should not be written to the register during screen display.)
Register LYC is a register compared with register LY. If they match, the Matchflag of the STAT register is set.
NOTE The following 3 registers (BGP, OBP0, and OBP1) are valid in DMG and DMG
mode of CGB. For information on CGB color palette settings, see Section 3, LCD
Color Display.
56
Chapter 2: Display Functions
The grayscales (2 bit) for the character dot data is converted by the palette data (BG: register BGP; OBJ:
OBP0 or OBP1) and output to the LCD driver as data representing 4 shades (including transparent).
0 ≤ WY ≤ 143
With WY = 0, the window is displayed from the top edge of the LCD screen.
7 ≤ WX ≤ 166
With WX = 7, the window is displayed from the left edge of the LCD screen.
57
Game Boy Programming Manual
WX
0 159
0
LCD screen area
WY
143
OBJ characters are displayed in the same manner in the window as on BG.
OBJ (Object)
♦ Data for 40 objects (OBJ) can be loaded into internal OAM RAM in the CPU (0xFE00-OxFE9F), and 40
objects can be displayed to the LCD. Up to 10 objects can be displayed on the same Y line.
♦ Each object consists of a y-coordinate (8 bits), x-coordinate (8 bits), and CHR code (8 bits) and
specifications for BG and OBJ display priority (1 bit), vertical flip (1bit), horizontal flip (1 bit), DMG-mode
palette, (1 bit), character bank (1bit), and color palette (3 bits), for a total of 32 bits.
♦ An 8 x 8- or 8 x 16-dot block composition can be specified for an OBJ using bit 2 of the LCDC register.
With an 8 x 16-dot composition, the CHR code is specifed as an even number, as in DMG.
58
Chapter 2: Display Functions
OAM Register
Note In DMG mode, the lower 4 bits of the attribute flag are invalid; only the flags in
the upper 4 bits including the palette flag are valid.
59
Game Boy Programming Manual
DMA transfers of 40 x 32 bits of data can be performed from the RAM area (0x8000-0xDFFF) to OAM
(OxFE00-0xFE9F). The transfer time is 160 µs.
Note that in DMG, data cannot be transferred by DMA from ROM area 0x0000-0x7FFF.
The starting address of a DMA transfer can be specified as 0x8000-0xDFFF in increments of 0x100.
Note that the method used for transfers from 0x8000-0x9FFF (display RAM) is different from that used for
transfers from other addresses.
Example 1
The following example shows how to perform a DMA transfer of 40 x 32 bits from the expansion RAM area
(0xC000-0xC09F) to OAM (0xFE00-0xFE9F).
During DMA, the CPU is run using the internal RAM area (0xFF80-0xFFFE) to prevent external bus conflicts.
FF80 3E C0 LD A, 0C0H
E0 46 LD (DMA) , A ;C000-C09F→OAM
3E 28 LD A, 40 ;160-cycle wait
3D L1: DEC A
20 FD JR NZ, L1
C9 RET
2. Example of program that writes the above instructions to internal RAM starting from 0xFF80:
Label Instruction
LD C, 80H
LD B, 10
LD HL, DMADATA
L2: LD A, (HLI)
LD (C), A
INC C
DEC B
JR NZ, L2
•
•
•
60
Chapter 2: Display Functions
3. When the DMA transfer is performed, the subroutine written to internal RAM shown in Step 1 above is
executed:
•
CALL 0FF80H :DMA transfer
•
Note The preceding program is used for DMA transfers performed within routines for
processing interrupts implemented by vertical blanking. In all other cases,
however, the program written to internal RAM should be as shown below to
prevent interrupts during a transfer.
Example 2
The example below shows a DMA transfer of 40 x 32 bits of data from the display RAM area (0x9F00-0x9F9F)
to OAM (0xFE00-0xFE9H).
3E 9F LD A, 9FH
E0 46 LD (DMA), A :9F00~9F9F→0AM
Data can be transferred by DMA from 0x8000-0x9F9F to OAM either by the method shown in Example 1 or by
using only the above instructions.
This DMA method transfers only 40 x 32 bits of data from 0-0xDFFF to OAM (0xFE00-0xFE9F). The transfer
starting address can be specified as 0-0xDFFF in increments of 0x100. The transfer method is the same as
that used in DMG, but when data is transferred from 0x8000-0x9FFF (LCD display RAM area), the data
transferred are those in the bank specified by bit 0 of register VBK. When transferring data from 0xD000-
0xDFFF (unit working RAM area), the data transferred are those in the bank specified by the lower 3 bits of
register SVBK.
Note When the CPU is operating at double-speed, the transfer rate is also doubled.
61
Game Boy Programming Manual
Sixteen bytes of data can be automatically transferred from the user program area (0-0x7FFF) or external and
unit working RAM area (0xA000-0xDFFF) to the LCD display RAM area (0x8000-0x9FFF) during each
horizontal blanking period. The number of lines transferred by DMA in a horizontal blanking period can be
specified as 1-128 by setting register HDMA5. CPU processing is halted during a DMA transfer period.
The unit working RAM area (0xD000-0xDFFF) selected as the transfer source is the bank specified by register
SVBK.
The LCD display RAM area (0x8000-0x9FFF) selected as the transfer destination is the bank specified by
register VBK.
Special Notes
♦ The number of bytes transferred by the new DMA method must be specified in 16-byte increments; byte
counts that are not a multiple of 16 cannot be transferred.
♦ With the new DMA transfer method, transfers are performed at a fixed rate regardless of whether the
CPU is set to operate at normal or double-speed.
♦ Horizontal blanking DMA transfer should always be started with the LCDC on and the STAT mode set to
a value other than 00.
♦ General-purpose DMA transfer should be performed with the LCDC off or during a vertical blanking
period.
♦ When the new DMA transfer method is used to transfer data from the user program area (0-0x7FFF),
mask ROM and MBC for double-speed mode are required.
62
Chapter 2: Display Functions
63
Game Boy Programming Manual
1) The case with the same x-coordinate: For both DMG and CGB
B a = No. of OBJ A
b = No. of OBJ B
A c = No. of OBJ C
When a < b < c, objects are displayed as indicated in the figure at left.
A
A
B C
C C A
In DMB mode and with objects with different x-coordinates, the object with the smallest x-coordinate is given priority.
A B
a = No. of OBJ A
B b = No. of OBJ B
64
Chapter 2: Display Functions
1. BG Color Palettes
Color Palette No. Palette Data No.
OBJ color palettes have the same composition as shown in the figure above.
65
Game Boy Programming Manual
Data is written to color palettes using the write-specification and write-data registers. The lower 6 bits of the
write-specification register specifies the write address. When data is written to the write-data register, the data
will be written to the address specified by the write-specification register. If the highest bit of the write-
specification register is set to 1, the write address is then automatically incremented to specify the next
address. (The next address is read from the lower 6 bits of the write-specification register.)
The write-specification and write-data registers also are used to read data from color palettes. When the write-
data register is read, the data at the address specified by the write-specification register is read. When data is
read, the specified address is not incremented even if the most-significant bit of the write-specification register
is set to 1.
66
Chapter 2: Display Functions
When objects are displayed, overlapping objects and background are displayed according to the display
priority flags for OBJ and BG, as indicated below. The BG display priority flag can be used to assign BG
display priority to individual characters.
* obj and bg represent dot data (01, 10, 11) for OBJ and BG, respectively.
When earlier DMG software is used, coloring is performed automatically by the system using registers BGP,
OBP0, and OBP1. However, the display uses 3 palettes, 1 for BG, with 4 colors, and 2 for OBJ, each with 3
colors (excluding transparent; maximum of 10 colors in 1 screen).
1. BG Display
Colors specified in BG color palette No. 0 are displayed by the dot data (2 bits)
whose grayscales are specified by register BGP.
2. OBJ Display
Colors specified in OBJ color palettes No. 0 and No. 1 are displayed by the dot
data (2 bits) whose grayscales are specified by registers OBP0 and OBP1.
The CGB unit automatically selects the display color according to the color palette pre-registered in the CGB
(cannot be changed by a program). However, when turning on power to the CGB, the player can select from a
combination of the 12 colors registered in the unit. This function is available only in DMB mode.
67
Game Boy Programming Manual
68
Chapter 3: Sound Functions
69
Game Boy Programming Manual
♦ ON Mode
Sounds are output according to data in the mode register for each sound.
The mode register data can be specified as needed while outputting sound.
♦ Initialization Flag
When the default envelope values are set and the length counter is restarted,
the initialization flag is set to 1 and the data is initialized.
♦ Mute
In the following instances, the synthesizer will enter mute status. No sound
will be output regardless of the ON flag setting.
Sounds 1, 2, and 4:
- When the output level is 0 with the default envelope value set to a value
other than 0000 and in DOWN mode
- When the step is 0 with the default envelope value set to a value of 0000
and in UP mode (NR12, NR22, and NR42 set to 0x08 and the initialization
flag set)
Sound 3:
With the output level set to mute
(bits 5 and 6 of NR32 set to 0)
♦ Stop Status
In the following cases, the ON flag is reset and sound output is halted.
-Sound output is halted by the length counter.
-With Sound 1, during a sweep operation, an overflow occurs in addition
mode.
♦ OFF Mode
Stops operation of the frequency counter and D/A converter and halts sound output.
♦ Sounds 1, 2, and 4:
-When the default level is set to 0000 with the envelope in DOWN mode
(initialization not required)
♦ Sound 3:
-When the Sound OFF flag (bit 7 of NR30) is set to 0.
Setting the Sound OFF flag to 1 cancels OFF mode.
70
Chapter 3: Sound Functions
Note The sound mode registers should always be set after All Sound OFF mode is
canceled. The sound mode registers cannot be set in All Sound OFF mode.
1) Use NR51.
2) Set NR12, NR22, and NR42 to 0x08.
3) Set NR14, NR24, and NR44 to 0x80.
71
Game Boy Programming Manual
Sound 1 is a circuit that generates a rectangle waveform with sweep and envelope functions. It is set by registers
NR10, NR11, NR12, NR13, and NR14.
If the result of this formula is a value consisting of more than 11 bits, sound output is stopped and the Sound
1 ON flag of NR52 (bit 0) is reset.
In a subtraction operation, if the subtrahend is less than 0, the result is the pre-calculation value X (t ) = X ( t -
1 ). However, if n = 0, shifting does not occur and the frequency is unchanged.
Example: When NR10 = 0x79 and the default frequency = 0x400, the sweep waveform appears as follows.
Note When the sweep function is not used, the increase/decrease flag should be set
to 1 (subtraction mode).
72
Chapter 3: Sound Functions
01 : 25%
10 : 50%
11 : 75%
Amp. Gain
4/64 sec
73
Game Boy Programming Manual
Counter/Continous Selection
0: Outputs continuous sound regardless of length data in register NR11.
1: Outputs sound for the duration specified by the length data in register NR11.
When sound output is finished, bit 0 of register NR52, the Sound 1 ON flag, is reset.
Initialize
Setting this bit to 1 restarts Sound 1.
With the 11-bit frequency data specified in NR13 and NR14 represented by x, the frequency, f, is determined
by the following formula.
f = 4194304 / (4 x 2 x (2048 - X)) Hz
3
When no sweep function is used with Sound 1, the sweep time should be set to 0 (sweep OFF). In addition,
either the sweep increase/decrease flag should be set to 1 or the sweep shift number set to 0 (set to 0x08-
0x0F or 0x00 in NR10).
Sound may not be produced if the sweep increase/decrease flag of NR10 is set to 0 (addition mode), the
sweep shift number set to a value other than 0, and the mode set to sweep OFF (e.g. NR10 = 0x01)
If the contents of the envelope register (NR12) needs to be changed during sound operation (ON flag set to
1), the initialize flag should be set after the value in the envelope register is set.
74
Chapter 3: Sound Functions
Sound 2 is a circuit that generates a rectangle waveform with an envelope function. It is set by registers NR21,
NR22, NR23, and NR24.
Counter/Continous Selection
0: Outputs continuous sound regardless of length data in register NR21.
1: Outputs sound for the duration specified by the length data in register NR21.
When sound output is finished, bit 1 of register NR52, the Sound 2 ON flag, is reset.
Initialize
Setting this bit to 1 restarts Sound 2.
If the contents of the envelope register (NR22) needs to be changed during sound operation (ON flag set to
1), the initialize flag should be set after the value in the envelope register is set.
75
Game Boy Programming Manual
Sound 3 is a circuit that generates user-defined waveforms. It automatically reads a waveform pattern (1 cycle)
written to waveform RAM at 0xFF30-0xFF3F, and it can output a sound while changing its length, frequency, and
level by registers NR30, NR31, NR32, NR33, and NR34.
The settings of the sound length and frequency functions and data are the same as for the Sound 1 circuit.
Output Level:
00: Mute
01: Output waveform RAM data (4-bit length) unmodified.
10: Output waveform RAM data (4-bit length) shifted 1 bit to the right (1/2).
11: Output waveform RAM data (4-bit length) shifted 2 bits to the right (1/4).
Counter/Continous Selection
0: Outputs continuous sound regardless of length data in register NR31.
1: Outputs sound for the duration specified by the length data in register NR31.
When sound output is finished, bit 2 of register NR52, the Sound 3 ON flag, is reset.
76
Chapter 3: Sound Functions
Initialization Flag
When the Sound OFF flag (bit 7, NR30) is set to 1, setting this bit to 1 restarts Sound 3.
• The initialization flag should not be set when the frequency is changed during Sound 3 output.
• Setting the initialization flag during Sound 3 operation (Sound 3 ON flag = 1) may destroy the contents
of waveform RAM.
• Setting the initialization flags for Sound 1, Sound 2, or Sound 4 does not cause a problem.
Address D7 D6 D5 D4 D3 D2 D1 D0
Data
OH Step
OH 1FH
77
Game Boy Programming Manual
Sound 4 is a white-noise generating circuit. It can output sound while switching the number of steps of the
polynomial counter for random number generation and changing the frequency dividing ratio and envelope data
by registers NR41, NR42, NR43, and NR44.
78
Chapter 3: Sound Functions
Counter/Continuous Selection:
0: Outputs continuous sound regardless of length data in register NR41.
1: Outputs sound for the duration specified by the length data in register NR41.
When sound output is finished, bit 3 of register NR52, the Sound 4 ON flag, is reset.
Initialize:
Setting this bit to 1 restarts Sound 4.
If the contents of the envelope register (NR22) needs to be changed during sound operation (ON flag set to
1), the initialize flag should be set after the value in the envelope register is set.
79
Game Boy Programming Manual
Output Level:
000: Minimum level (Maximum level ÷ 8)
111: Maximum level
0: No output
1: Output
80
Chapter 3: Sound Functions
• The design prevents the maximum amplitude from exceeding 3V when only sounds 1-4 are used, even
when the output level for each sound is set to the maximum.
When the output level is set to 0x0F, each sound is output at 0.75V.
0.75V x 4 = 3V
• The maximum amplitude of the synthesized sound output also must be limited to 3V or less when the VIN
terminal is used to input external sound.
Use software to adjust the output levels of sounds 1-4 so that they do not exceed 0.6V (3V ÷).
Also limit the output level of the VIN terminal to 0.6V or less (input range of 1.9 - 2.5V).
+1.5V
+0.3
2.2V
-0.3
-1.5V
• The input voltage from the VIN terminal also can be increased if the levels of the internal sounds are low or
if not all 4 sounds are used (total output level of 3V or less).
81
Game Boy Programming Manual
82
Game Boy Programming Manual
84
Chapter 4: CPU Instruction Set
85
Game Boy Programming Manual
86
Chapter 4: CPU Instruction Set
87
Game Boy Programming Manual
88
Chapter 4: CPU Instruction Set
89
Game Boy Programming Manual
90
Chapter 4: CPU Instruction Set
91
Game Boy Programming Manual
92
Chapter 4: CPU Instruction Set
93
Game Boy Programming Manual
94
Chapter 4: CPU Instruction Set
95
Game Boy Programming Manual
96
Chapter 4: CPU Instruction Set
97
Game Boy Programming Manual
98
Chapter 4: CPU Instruction Set
99
Game Boy Programming Manual
100
Chapter 4: CPU Instruction Set
101
Game Boy Programming Manual
102
Chapter 4: CPU Instruction Set
103
Game Boy Programming Manual
104
Chapter 4: CPU Instruction Set
105
Game Boy Programming Manual
106
Chapter 4: CPU Instruction Set
107
Game Boy Programming Manual
108
Chapter 4: CPU Instruction Set
109
Game Boy Programming Manual
110
Chapter 4: CPU Instruction Set
111
Game Boy Programming Manual
112
Chapter 5: Miscellaneous General Information
113
Game Boy Programming Manual
1. MONITOR ROM
The DMG and CGB CPU includes internal monitor ROM.
When power on the hardware is turned on, the monitor ROM checks for errors in the ‘Nintendo’ logo character
data within the game software.
If the data is correct, the Nintendo logo is displayed and the program is then started. If there is an error in the
data, the screen flashes repeatedly.
For information on registering the Nintendo logo character data, refer to Appendix 3 of this manual, Submission
Requirements.
The conditions required for starting the user program are as follows.
Starting Address 0x150 (default value) The starting address can be freely set by writing a
jump destination address at 0x102 and 0x103.
114
Chapter 5: Miscellaneous General Information
Note For an overall description of the ROM area shown below, please refer to
Appendix 3, Submission Requirements.
Setting a value of 0x80 or 0xC0 at this address causes the system to recognize the software as being for CGB.
If 0x00 or any value less than 0x7F (existing DMG software) is set at this address, the software is recognized as
non-CGB software and CGB functions (registers) are not available.
Starting
Address
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
0x0100 00 C3 Lo Hi
0x0120
0x0130 Game
Game Title (0x134 - 0x13E) Code
0x0140 Game Code 33
(0x13F-0x142)
CGB/CGB Only: When operating on CGB, up to 56 colors can be displayed on a single screen.
Non-CGB: When operating on CGB, up to 10 colors can be displayed on a single screen.
Note Regardless of the type of game, the following fixed values should be stored at
the following addresses.
• Address 0x100=0x00
• Address 0x101=0xC3
• Address 0x14B=0x33
• Addresses 0x104 – 0x133=‘Nintendo’ character data
115
Game Boy Programming Manual
During waiting for vertical blanking, halt the CPU system clock to reduce power consumption by the CPU and
ROM.
;****** ******
;****** Main Routine ******
;****** ******
MAIN
CALL CONT : Keypad input.
CALL GAME : Game or other processing.
VBLK_WT
HALT : Halt the system clock.
: Return from HALT mode if an interrupt is generated.
: Wait for a vertical blanking interrupt.
NOP : Used to avoid bugs in the rare case that the instruction.
after the HALT instruction is not executed.
LD A, (VBLK_F)
AND A : Generate a V-blank interrupt?
JR Z, VBLK_WT : Jump if a non-V-blank interrupt.
XOR A
LD (VBLK_F), A
JR MAIN
;****** ******
;****** Vertical Blanking Routine ******
;****** ******
VBLK
PUSH AF
PUSH BC
PUSH DE
PUSH HL
CALL DMA
POP HL
POP DE
POP BC
POP AF
RETI
HALT instructions should not be executed while CGB horizontal blanking DMA is executed. (See Appendix 1,
Programming Cautions.)
116
Chapter 5: Miscellaneous General Information
If the title is similar to that of other software (e.g., series software), a subtitle should also be displayed to
distinguish the programs from one another.
For information on software methods of distinguishing game units, see Section 6 of this chapter, Software
Created for CGB: Example.
[Game Title]
117
Game Boy Programming Manual
CGB DMG
118
Chapter 5: Miscellaneous General Information
The following example describes how to create a program that operates on both CGB and DMG and allows
display of 56 colors when running on CGB . Such means can be used to maintain compatibility with earlier
hardware (DMG) while using CGB functions.
0x9800 BG attribute
BG CHR Code
0x9C00
BG CHR Code BG attribute
0x9FFF
7 6 5 4 3 2 1 0
0 0 0 0
• Both the color palette and DMG-mode palette are set as attribute flags in the OAM register.
7 6 5 4 3 2 1 0
Color Palette
DMG-Mode Palette
119
Game Boy Programming Manual
Immediately after program startup, the initial value of the accumulator (register A) is read to determine
whether the hardware on which the program is operating is a DMG (SGB), MGB/MGL (SGB2) , or CGB.
120
Chapter 5: Miscellaneous General Information
6.3 Flowcharts
1) Branched Processing for CGB and DMG/MGB/MGL
Start
Supplemental processing for
CGB support
0x11 CGB
Unit Discrimination:
Value of register A is
read
CGB flag 1
0x01 (DMG)
0xFF (MGB/MGL)
Initialization
OAM Transfer
= 1 (CGB)
CGB?
CGB Flag Check
LCDC ON
Color display in CGB
Monochrome display in DMG/MGB/MGL
LCDC OFF
or blanking
121
Game Boy Programming Manual
Initialization
OAM Transfer
LCDC ON
Color display in CGB
Monochrome display in DMG/MGB/MGL
LCDC OFF
or blanking
Note The BG attributes should always be transferred before the BG character code.
Even if only the BG attributes are changed, always transfer the character code
from that same address.
122
Chapter 6: The Super Game Boy System
123
Game Boy Programming Manual
1. OVERVIEW
1.1 What is Super Game Boy (SGB)?
SGB is a device that enables Game Boy software to be enjoyed on a TV screen. Game Boy software can be
plugged into the SGB, which operates on the Super Nintendo Entertainment System (Super NES).
SGB consists of the basic Game Boy circuitry, and components such as an Intercommunication Device (ICD, with
built-in SGB RAM), the system program, and a CIC.
Basic SGB operation involves conversion by the ICD of 2-bit, 4 grayscale image signals generated by the SGB
CPU to SUPER NES character data and storage of these data in SGB RAM. The system program subsequently
transfers this data by DMA to SUPER NES WRAM and then to VRAM. The above operations are performed
repeatedly to display the Game Boy screen on a TV screen.
Unmodified sound output from the SGB CPU is linked to the SUPER NES sound mixing circuit and is output from
the speaker on the TV.
These operations are controlled by the SGB system program and therefore require no special consideration when
programming for Game Boy.
Game Boy software not specifically created for SGB provides 4 colors in 4 grayscales. These colors are selected
from several color patterns provided in the system program. Programming using the system commands
described later allows a game to be represented using 4 palettes of 4 colors each per screen and SUPER NES
functions such as SUPER NES sound.
Super Game Boy comes in 2 models: the 1994 model, which has no communication connector, and the 1998
model, which is equipped with a communication connector.
This manual uses the term SGB2 when discussing points that concern only the 1998 model. Descriptions that
use the term Super Game Boy or SGB refer to both Super Game Boy models. SGB2 allows game
representations that use SHVC functions for communication play. (SGB2 has not been released in the U.S.
market.)
124
Chapter 6: The Super Game Boy System
VISUAL DATA
Address
KEY DATA
System
Address
Program
Data
SGBRA
ROM
M
Register
file
Data
ICD
SGB-CPU
SOUND L, R CIC
W-RAM V-RAM
64Kbit 64Kbit
32P Card Connector
DMG Game SNES62P Card Edge
Pak
125
Game Boy Programming Manual
1.3 Functions
The types of representations indicated below can be implemented using SUPER NES
functions invoked by sending system commands.
For more information, please see Section 3 in this chapter, System Commands.
Image Functions
• Multiple areas can be specified for each screen, and separate color palette attributes can be specified for
each area.
• Color palette attributes can be specified separately for each character (8 x 8 bits).
Sound Functions
• The rich variety of sound effects included the system program can be generated by the SUPER NES
audio processing unit (APU).
• The sound generator included in the system program can be used by transferring music data.
Controller Functions
• Data from multiple SUPER NES controllers data can be read, providing for multiplayer games that can
accommodate between 2 and 4 players.
Miscellaneous
• On the T.V. screen, the system program displays the space outside the game screen (picture frame).
A mode is available that allows the user to arrange the colors on a palette.
126
Chapter 6: The Super Game Boy System
• If the commands described in Section 3.2 in this chapter, System Command Details, are sent to the register
file, Super NES functions, such as those described in Section 1.3, Functions, can be used by having the
system program read these commands.
Send data to the register file using P14 and P15. The size of the register file is 128 bits;
this is referred to as 1 packet.
NOTE Data transfers from the register file and SGB RAM to SUPER NES are performed
by the system program.
Using the register file to transmit system commands allows the various SUPER NES functions described below to
be used in games.
The system program receives the commands and performs the specified processing.
Using 2 bits in SGB (P14 and P15 of SGB CPU), data is sent to the register file by serial transmission.
127
Game Boy Programming Manual
The system program reads the contents written to the register file.
1. Start write
P14 H
A LOW pulse is output to both P14 and P15.
L This is required for transmission of each packet (128 bits) .
P15 H
2. Write 0
P14 H
P15 is fixed at HIGH, and a
L LOW pulse is output to P14.
P15 H
3. Write 1
P14 H
P14 is fixed at HIGH, and
L a LOW pulse is output to P15.
P15 H
P14
or P15
Pulse Width
P15 a, c, e 5 µ s (min)
or P14
b, d 15 µ s (min)
a b c d e
128
Chapter 6: The Super Game Boy System
2) Write Example
d0 d1 d2 d3 d4 d5 d6
P14
P15
Start 1 1 0 0 1 0 1
00h
d7 d6 d5 d4 d3 d2 d1 d0
01h
02h
Transmitted Data
: : : :
0Fh
129
Game Boy Programming Manual
Transmission Procedure
1. Start of write
Transmitted Data
d0, d1, d2, d3, d4, d5, d6, d7
00h : 0 1 0 1 0 0 0 0
0x01: data
0x02: data
: :
: :
0xF: data
Bit 129: 0
4. Start of write
0x00: data
0x01: data
: :
: :
0xF: data
Bit 129: 0
4) Transmission Interval
The interval between completion of transmission of one packet (128 bits + 1 bit) and
transmission of the next packet is set at approximately 60 msec (4 frames).
• • •
The data in bit 129 marks the end of one packet, so it should always be transmitted.
130
Chapter 6: The Super Game Boy System
Data and programs stored in a cartridge can be transferred using the image signal transmission path (LD0, LD1).
Character data stored in DMG VRAM and displayed are then stored in SGB RAM. The system program usually
transfers these data to SUPER NES VRAM as character data. However, when a specific command is received,
the data is handled as data for command processing.
The displayed image signal is handled directly as data, so be careful to ensure that the OBJ display and window
are set to OFF, the correct values are set for the DMB color palette, and the BG to be displayed is correctly
transferred.
When data is transferred they are displayed to the screen, so the system command MASK_EN must be used to
mask the screen.
For more information, see Section 3.2 in this chapter, System Command Details.
Note Commands that transfer data using image signals are indicated by the heading,
Data Transfer Using VRAM.
131
Game Boy Programming Manual
3. SYSTEM COMMANDS
3.1 System Command Summary
PALO1 00 DATA_TRN 10
PAL23 01 MLT_REQ 11
PAL03 02 JUMP 12
PAL12 03 CHR_TRN 13
ATTR_BLK 04 PCT_TRN 14
ATTR_LIN 05 ATTR_TRN 15
ATTR_DIV 06 ATTR_SET 16
ATTR_CHR 07 MASK_EN 17
SOUND 08 PAL_PRI 19
SOU_TRN 09
Use prohibited 0D
PAL_SET 0A
Use prohibited 18
PAL_TRN 0B
ATRC_EN 0C
ICON_EN 0E
DATA_SND 0F
132
Chapter 6: The Super Game Boy System
Please refer to the following map in the discussion of coordinate settings and color palette area specifications in
the description of the system command functions.
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
00
01
02
03
04
05
06
07
144 dots
[18
characters] 08
09
0A
0B
0C
0D
0E
0F
10
11
DMG Window
133
Game Boy Programming Manual
DMG Window
.....................
Command PAL-SET/Option
System Color Palette510
SGB
Color data setting of Game Pak Attribute file
system color palette transfer
(Command PAL- (Command ATTR-TRN)
TRN)
Note Bit 00 of SGB color palettes 0 – 3 have the same color. The color setting in effect
for this bit is the most recent setting.
134
Chapter 6: The Super Game Boy System
00 01 10 11
Red Green Gray Black
SGB palette Bit m layer
Table 2
10 00
However, if bit 11 of the DMG palette is
set to grayscale 00, the portion of 00 01
the DMG character image is displayed
with a 00 grayscale, and the portion 00 11
of the SGB character image is displayed
as red rather than black. 00-11: grayscale data
135
Game Boy Programming Manual
When representing DMG grayscale on SGB, the image can be faithfully represented if 00 of the SGB palette is set to a
light color and 11 to a dark color.
d7 d0
0x00 0 0 0 0 0 0 0 1
d7 d0 d7 d0
0x01 Palette0 Color00 Data LOW 8bit 0x02 -- Palette0 Color00 Data HIGH 7bit
0x03 Palette0 Color01 Data LOW 8bit 0x04 -- Palette0 Color01 Data HIGH 7bit
0x05 Palette0 Color10 Data LOW 8bit 0x06 -- Palette0 Color10 Data HIGH 7bit
0x07 Palette0 Color11 Data LOW 8bit 0x08 -- Palette0 Color11 Data HIGH 7bit
d7 d0 d7 d0
0x09 Palette1 Color01 Data LOW 8bit 0x0A -- Palette1 Color01 Data HIGH 7bit
0x0B Palette1 Color10 Data LOW 8bit 0x0C -- Palette1 Color10 Data HIGH 7bit
0x0D Palette1 Color11 Data LOW 8bit 0x0E -- Palette1 Color11 Data HIGH 7bit
0x0F
0 0 0 0 0 0 0 0
136
Chapter 6: The Super Game Boy System
Function: Sets the color data for SGB color palettes 2 and 3.
d7 d0
0x00 0 0 0 0 0 0 0 0
d7 d0 d7 d0
0x01 Palette2 Color00 Data LOW 8bit 0x02 -- Palette2 Color00 Data HIGH 7bit
0x03 Palette2 Color01 Data LOW 8bit 0x04 -- Palette2 Color01 Data HIGH 7bit
0x05 Palette2 Color10 Data LOW 8bit 0x06 -- Palette2 Color10 Data HIGH 7bit
0x07 Palette2 Color11 Data LOW 8bit 0x08 -- Palette2 Color11 Data HIGH 7bit
d7 d0 d7 d0
0x09 Palette3 Color01 Data LOW 8bit 0x0A -- Palette3 Color01 Data HIGH 7bit
0x0B Palette3 Color10 Data LOW 8bit 0x0C -- Palette3 Color10 Data HIGH 7bit
0x0D Palette3 Color11 Data LOW 8bit 0x0E -- Palette3 Color11 Data HIGH 7bit
0x0F 0 0 0 0 0 0 0 0
137
Game Boy Programming Manual
Function: Sets the color data for SGB color palettes 0 and 3.
d7 d0
0x00 0 0 0 0 1 0 0 1
d7 d0 d7 d0
0x01 Palette0 Color00 Data LOW 8bit 0x02 -- Palette0 Color00 Data HIGH 7bit
0x03 Palette0 Color01 Data LOW 8bit 0x04 -- Palette0 Color01 Data HIGH 7bit
0x05 Palette0 Color10 Data LOW 8bit 0x06 -- Palette0 Color10 Data HIGH 7bit
0x07 Palette0 Color11 Data LOW 8bit 0x08 -- Palette0 Color11 Data HIGH 7bit
d7 d0 d7 d0
0x09 Palette3 Color01 Data LOW 8bit 0x0A -- Palette3 Color01 Data HIGH 7bit
0x0B Palette3 Color10 Data LOW 8bit 0x0C -- Palette3 Color10 Data HIGH 7bit
0x0D Palette3 Color11 Data LOW 8bit 0x0E -- Palette3 Color11 Data HIGH 7bit
0x0F 0 0 0 0 0 0 0 0
138
Chapter 6: The Super Game Boy System
Function: Sets the color data for SGB color palettes 1 and 2.
d7 d0
0x00 0 0 0 1 1 0 0 1
d7 d0 d7 d0
0x01 Palette1 Color00 Data LOW 8bit 0x02 -- Palette1 Color00 Data HIGH 7bit
0x03 Palette1 Color01 Data LOW 8bit 0x04 -- Palette1 Color01 Data HIGH 7bit
0x05 Palette1 Color10 Data LOW 8bit 0x06 -- Palette1 Color10 Data HIGH 7bit
0x07 Palette1 Color11 Data LOW 8bit 0x08 -- Palette1 Color11 Data HIGH 7bit
d7 d0 d7 d0
0x09 Palette2 Color01 Data LOW 8bit 0x0A -- Palette2 Color01 Data HIGH 7bit
0x0B Palette2 Color10 Data LOW 8bit 0x0C -- Palette2 Color10 Data HIGH 7bit
0x0D Palette2 Color11 Data LOW 8bit 0x0E -- Palette2 Color11 Data HIGH 7bit
0x0F 0 0 0 0 0 0 0 0
139
Game Boy Programming Manual
Function: Applies the specified color palette attributes to areas inside and outside the square.
d7 d0
0x00 0 0 1 0 0
0x01 -- -- --
Control Codes
Applies the attributes specified by d1 and d0 of 0x03 only to the area within the
001
square (including the CHR border).
Applies the color palette attributes specified by d3 and d2 of 0x03 only on the
010
square CHR border.
Applies the color palette attributes specified by d1 and d0 of 0x03 only to the
011 area within the square, and applies the color palette attributes specified by d3
and d2 of 0x03 only to the border of the square.
Applies the attributes specified by d5 and d4 of 0x03 only to the area outside the
100
square (including the CHR border).
Applies the color palette attributes specified by d1 and d0 of 0x03 to the area
101 within the square, and applies the color palette attributes specified by d5 and d4
of 0x03 to the area outside of the CHR border. (CHR border is unchanged.)
Applies the color palette attributes specified by d5 and d4 of 0x03 only to the
110 area outside of the square, and applies the color palette attributes specified by
d3 and d2 of 0x03 to the CHR border .
Applies the specified color palette attributes to the area inside the square, to the
111
CHR border line, and to the area outside the CHR border .
The color palette attributes of areas not specified are not changed.
140
Chapter 6: The Super Game Boy System
d7 d0
d7 d0
0x04 -- -- -- Starting point H1 Starting (upper left) and ending (lower right) points of
the square.
0x05 -- -- -- Starting point V1
Coordinate data
0x06 -- -- -- Ending point h1 (H1,V1) H
V
(h1,v1)
d7 d0
Ending point v2
0x0D -- -- --
0x0E 0 0 0 0 0 0 0 0
0x0F 0 0 0 0 0 0 0 0
Note If the number of packets is 1, 0x00 is written to 0x0E and 0x0F. If the number of
packets exceeds 1, the control code and color palette specification code of the
next data item are written to 0x0E and 0x0F, respectively.
141
Game Boy Programming Manual
d7 d0
d7 d0
0x02 *
*
* The empty area of the packet is filled with 0x00.
Note When there is no area inside the square border (e.g., h1 = H1 + 1), a control code
such as one that sets the color attribute for the area inside the border cannot be
used.
142
Chapter 6: The Super Game Boy System
Please note that when ATTR_BLK, ATTR_LIN, ATTR_DIV, or ATTR_CHR are used, the data that is sent are valid
even if MASK_EN (freezes screen immediately before masking) is selected.
When using MASK_EN before these commands, use 0x10 or 0x11 as the argument. If 0x01 is used as the
MASK_EN argument, ATTR_TRN and ATTR_SET should be used.
143
Game Boy Programming Manual
d7 d0
0x00 0 0 1 0 1
d7 d0
0x01
d7 d0
Palette number
H/V mode bit
0: Specifies the H coordinate character line number (vertical line)
1: Specifies the V coordinate character line number (horizontal line)
d7 d0
0x03 Character Line
2nd data item
nth Packet
0x00 Character Line
: : : :
0x0F Character Line
144
Chapter 6: The Super Game Boy System
Example
d7 d0
0x00 0 0 1 0 1 0 0 1
d7 d0
0x02 1 0 1 0 1 1 1 1
0x03 0 0 0 0 0 0 1 0
* The color of intersection of the two lines is decided by the last line color.
145
Game Boy Programming Manual
Function: Divides the color palette attributes of the screen by the specified coordinates.
d7 d0
0x00 0 0 1 1 0 0 0 1
d7 d0
0x01 --
d7 d0
146
Chapter 6: The Super Game Boy System
Example
d7 d0
0x00 0 0 1 1 0 0 0 1
d7 d0
0x01 -- 0 1 0 0 1 1 1
Palette: 3
Palette: 1
Palette: 2
Coordinate setting: H
0x02 -- -- -- 0 0 1 1 0
147
Game Boy Programming Manual
d7 d0
0x00 0 0 1 1 1
d7 d0
0x01 -- -- --
0x02 -- -- --
0x03
0x04 -- -- -- -- -- -- --
0x05 -- -- -- -- -- -- --
148
Chapter 6: The Super Game Boy System
START
Horizontal write (H direction)
Pal.No. Pal.No Pal.No Pal.No
0x06
START
Pal.No Pal.No Pal.No Pal.No
0x07
: : : :
Vertical write (V direction)
: : : : START
: : : :
: : : :
: : : :
6th Packet
0x0F Pal.No. Pal.No. Pal.No. Pal.No. Data items nos. 357, 358, 359, and 360.
149
Game Boy Programming Manual
Function: Generates and halts internal sound effects and sounds that use internal tone data.
d7 d0
0x00 0 1 0 0 0 0 0 1
Sound code
Sound code
0x03
d7 d0
0x04
BGM code
When not used, 0x00 always written.
150
Chapter 6: The Super Game Boy System
d7 d0
0x00 0 1 0 0 1 0 0 1
* The 4 Kbytes of SGB RAM data immediately following the command is sent to APU RAM.
The data to be transferred must be prepared prior to the frame preceding issuance of the command.
The transfer ends 6 frames after the command is issued (not counting the frame in which the command is
issued).
The beginning of the data for transfer contains a 16-bit representation of the number of data items and the
transfer destination address, and the end contains an ending code and the starting address of the program.
For more information, see Chapter 7: Super Game Boy Sound.
151
Game Boy Programming Manual
d7 d0
0x00 0 1 0 1 0 0 0 1
0x01
d7 d0
0x02 -- -- -- -- -- -- --
d7 d0
0x03 LOW
0x04 -- -- -- -- -- -- -- HIGH
d7 d0
0x05 LOW
0x06 -- -- -- -- -- -- -- HIGH
d7 d0
0x07 LOW
0x08 -- -- -- -- -- -- -- HIGH
152
Chapter 6: The Super Game Boy System
d7 d0
0x09
0: No change
1: Cancels masking after the data is set.
0: Not specified.
1: The specified attribute file number.
153
Game Boy Programming Manual
d7 d0
0x00 0 1 0 1 1 0 0 1
* The 4 Kbytes of SGB RAM data immediate following the command is handled as system color palette data and
stored in SUPER NES WRAM as data for system color palettes 000 – 511.
d7 d0
: : : :
154
Chapter 6: The Super Game Boy System
d7 d0
0x00 0 1 1 0 0 0 0 1
d7 d0
0x01 -- -- -- -- -- -- --
0: Enables attraction
1: Disables attraction
Example: Attraction start duration for a model (type without communication connector).
The time required for attraction to start for each picture frame is as follows.
(Times shown in parentheses are times required to start attraction a second time.)
Cinema 3 mins.
Cats 3 mins.
155
Game Boy Programming Manual
d7 d0
0x00 0 1 1 1 0 0 0 1
0x01 -- -- -- -- --
Color palette
0: Enable settings
1: Disable settings
0: Receive
1: Do not receive
156
Chapter 6: The Super Game Boy System
d7 d0
0x00 0 1 1 1 1 0 0 1
0x01
d7 d0
0x02
0x03
Bank number
d7 d0
0x04
d7 d0
157
Game Boy Programming Manual
d7 d0
0x00 1 0 0 0 0 0 0 1
d7 d0
0x01
d7 d0
0x02
d7 d0
0x03
Bank number
* Free Addresses
Note When an SHVC program is tranferred to WRAM and executed, 0x00 should be
written to 0x1700 of bank 00. This can be written either by using DATA_SND or
DATA_TRN or by using the transferred program.
158
Chapter 6: The Super Game Boy System
d7 d0
0x00 1 0 0 0 1 0 0 1
d7 d0
0x01 -- -- -- -- -- --
0: No request
1: Request
The game program can use a connector for 2
controllers.
(e.g., standard Controllers and Multiplayer 5)
0: 2 players
1: 4 players
(Multiplayer 5 required)
159
Game Boy Programming Manual
Function: Sets the SUPER NES program counter to the specified address.
d7 d0
0x00 1 0 0 1 0 0 0 1
d7 d0
0x01
Address (LOW)
d7 d0
0x02
Address (HIGH)
d7 d0
0x03
Bank number
d7 d0
0x04
0x05
0x06
Bank number
Note If all addresses from 0x04 to 0x06 are set to 0, the NMI jumps to the original
vector. NMI is disabled in the system program, so it must be enabled to be used.
160
Chapter 6: The Super Game Boy System
d7 d0
0x00 1 0 0 1 1 0 0 1
0x01 -- -- -- -- -- -- 0
Note The 4 Kbytes of SGB RAM data immediately following this command is handled
as SUPER NES character data and transferred to SUPER NES VRAM.
The format of the tranferred data is based on the SUPER NES character data
format.
When character data is used for the picture frame, characters with a character
name setting of 0x00 should consist of null bits, and all dots of characters with
a name setting of 0x01 should be represented by non-null bits.
161
Game Boy Programming Manual
Function: Transfers screen data and color data for picture frames created by the software developer.
d7 d0
1 0 1 0 0 0 0 1
0x00
* The 4 Kbytes of SGB RAM immediately following this command are handled as screen data and transferred to
SUPER NES VRAM.
START
DMG Window
The format of the transferred data is based on that of SUPER NES screen and color data. However, the BG
priority bit is set to 0, the color palettes to palette numbers 4-6, the higher-order 2 bits of the character name to
00b, and the characters to 8 x 8-bit mode.
162
Chapter 6: The Super Game Boy System
d7 d0
0x00 1 0 1 0 1 0 0 1
* The 4 Kbytes of SGB RAM immediately following this command are transferred to WRAM as attribute files.
(The capacity of each attribute file is 2 x 20 x 18/8 = 90 bytes. Thus, 45 attribute files occupy 4,050 bytes,
0xATF0-0xATF44.
The ATF data format (90 bytes total) -- written horizontally from the left edge of the DMG window.
..
Byte 1 Byte 2 ..
d7,d6 d5,d4 d3,d2 d1,d0 d7,d6 d5,d4 d3,d2 d1,d0 ..
..
Byte 6 Byte 7 ..
d5,d4 d3,d2 d5,d4 d3,d2 ..
d7,d6 d1,d0 d7,d6 d1,d0
..
: : : : : : : :
..
Byte 81 Byte 82 ..
d7,d6 d5,d4 d3,d2 d1,d0 d7,d6 d5,d4 d3,d2 d1,d0 ..
..
Byte 86 Byte 87 ..
..
d7,d6 d5,d4 d3,d2 d1,d0 d7,d6 d5,d4 d3,d2 d1,d0
..
163
Game Boy Programming Manual
d7 d0
0x00 1 0 1 1 0 0 0 1
d7 d0
0x01 --
0: Not changed
1: Cancel masking after attribute file transfer
164
Chapter 6: The Super Game Boy System
d7 d0
0x00 1 0 1 1 1 0 0 1
d7 d0
0x01 -- -- -- -- -- --
Note When masking is performed at the start of the game, it should be performed after
the DMG reset is canceled and around the time that the DMG screen is displayed
on SGB. (The timing of the command should be adjusted so that it is issued after
a wait of several frames.) Without this timing, the screen may be momentarily
be displayed in monochrome.
Note Masking with an argument (0X01) of 0x10 or 0x11 is prohibited during a game.
165
Game Boy Programming Manual
Function: Specifies the priority of the color palette for the application and the color palette selected by the player.
d7 d0
0x00 1 1 0 0 1 0 0 1
d7 d0
0x01 -- -- -- -- -- -- -- --
00, 01, 02, 03, 04, 05, 06, 07, 0A, 16 (Code value)
166
Chapter 6: The Super Game Boy System
• After each packet (128 bits) is sent, 0 must always be sent in bit 129.
• If a data sequence covers more than 1 packet, byte 1 of each packet after the first is a continuation of the
data of the previous packet.
• Note that there are two modes of data transfer: register-file mode and a mode in which 4 Kbytes are
tranferred using SGB RAM.
• Controller key input should not be read while a command is being sent.
• Pre-loaded sound effects A and B can be played simultaneously using system commands.
• The A sound effects are formants, primarily action sounds, and the B sound effects are looping sounds,
primarily ambient sounds.
• The interval (frequency) for these sound effects can be set to 4 levels.
• Changing the interval A allows a completely different sound effect to be obtained with the same sound source.
In addition, the volume can be set to 3 levels.
167
Game Boy Programming Manual
SOUND Command
0x01 Nintendo d1 = 1 • d0 = 1 • • • 7
168
Chapter 6: The Super Game Boy System
SOUND Command
0x17 Jump d1 = 1 • d0 = 1 • • • 7
0x1D Level up d1 = 1 • d0 = 0 • • 6 • 7
0x21 Fire d1 = 1 • d0 = 1 • • • 7
0x24 Stepping d1 = 1 • d0 = 1 • • 6 • 7
0x2D Teleportation d1 = 1 • d0 = 1 • • • 7
0x2E Thunder d1 = 1 • d0 = 0 • • 6 • 7
0x2F Earthquake d1 = 1 • d0 = 0 • • 6 • 7
169
Game Boy Programming Manual
SOUND Command
0x04 Wind d5 = 0 • d4 = 1 • • 4 • 5
0x05 Rain d5 = 0 • d4 = 1 • • • 5
0x06 Storm d5 = 0 • d4 = 1 • 1 • 4 • 5
0x07 Hurricane d5 = 1 • d4 = 0 0• 1 • 4 • 5
0x08 Thunder d5 = 0 • d4 = 0 • • 4 • 5
0x09 Earthquake d5 = 0 • d4 = 0 • • 4 • 5
0x0B Wave d5 = 0 • d4 = 0 • • • 5
0x0C River d5 = 1 • d4 = 1 • • 4 • 5
0x0D Waterfall d5 = 1 • d4 = 0 • • 4 • 5
170
Chapter 6: The Super Game Boy System
SOUND Command
0x16 Fire d5 = 1 • d4 = 0 • • • 5
171
Game Boy Programming Manual
SOUND Command
0x03
d7 d6 d5 d4 d3 d2 d1 d0
× × 0 0 Interval (short)
× × 0 1 Interval (med-short)
A × × 1 0 Interval (med-long)
Sound
Effects × × 1 1 Interval (long)
0 0 × × Volume (high)
0 1 × × Volume (med)
1 0 × × Volume (low)
× × 0 0 Interval (short)
× × 0 1 Interval (med-short)
B
Sound
× × 1 0 Interval (med-long)
Effects
× × 1 1 Interval (long)
0 0 × × Volume (high)
0 1 × × Volume (med)
1 0 × × Volume (low)
1 1 Mute ON
• Mute takes effect only when both bits d2 and d3 are set to 1. If the volume is set for either the A or B sound
effect, mute is turned off.
• Fade-out and fade-in take effect with mute-on and mute-off, respectively. Mute-on and mute-off are
implemented for BGM played by A and B sound effects and by the APU.
• When the mute flag is set, the volume and interval data for the A (Port 1) and B (Port 2) sound effects also
should be set.
172
Chapter 6: The Super Game Boy System
4. MISCELLANEOUS
4.1 Reading Input from Multiple Controllers
After a multiplayer request (Command MLT_REQ) is sent, data from controllers 1, 2, 3, and 4 automatically
become readable.
In 2-player mode, data from controller 1 is read first, followed by data from controller 2, then data from controller 1
again, and so on. In 4-player mode, the order is controller 1, controller 2, controller 3, controller 4, controller 1
again, and so on.
In these cases, the next controller for which data is to be read must be determined beforehand by reading P10-
P13 with P14 and P15 high.
0xF Controller 1
0xE Controller 2
0xD Controller 3
0xC Controller 4
Note Controller data cannot be read if Multiplayer 5 and SUPER NES Mouse are
connected at the same time.
173
Game Boy Programming Manual
The program uses the following methods to determine which of the 4 types is operating.
• Checks the initial value of the internal accumulator of the CPU. (distinguishes between previous/new versions
of CPU).
01 → DMG or SGB
FF → MGB/MGL or SGB2
• Sends a muliplayer request (Command MLT_REQ) and determines whether there is a switch to multiplayer
mode.
174
Chapter 6: The Super Game Boy System
START
DMG
MGB/MGL SGB SGB2
Main Routine
175
Game Boy Programming Manual
The following registers can be used to perform functions such resetting the SGB CPU from a program transferred
to SUPER NES WRAM and receiving and passing data to a DMG program.
1:Ready
0: mid-transfer or read finished
DMG Reset Register Resets the SGB CPU
[DRR] 0x6003 (WR)
-- 0 0 -- -- 0 1
0: Reset
1: Cancel
ST SE B A D U L R
Using RF0 - RFF and RFS allows data sent to the register file by the DMG program to be received by the SUPER
NES program.
CR1 is a register used by the original SGB system program for writing keypad data from controller 1. The SUPER
NES program can use the controller-reading routine of the DMG program to receive data written to this register.
176
Chapter 6: The Super Game Boy System
177
Game Boy Programming Manual
5. PROGRAMMING CAUTIONS
5.1 ROM Registration Data
To use SGB functions (system commands), the following values must be stored at the ROM addresses indicated.
When writing programs that use the system commands of SGB and SGB2, use the initialization routine of the
game program to send the following 8 packets of default data to the register file.
178
Chapter 6: The Super Game Boy System
When using the SOU_TRN system command, send the following 5 packets of SOU_TRN default data to the
register file before SOU_TRN is used.
STI
DB $79, $00, $09, $00, $0B
DB $AD, $C2, $02, $C9, $09, $D0, $1A, $A9, $01, $8D, $00
ST2
DB $79, $0B, $09, $00, $0B
DB $42, $AF, $DB, $FF, $00, $F0, $05, $20, $73, $C5, $80
ST3
DB $79, $16, $09, $00, $0B
DB $03, $20, $76, $C5, $A9, $31, $8D, $00, $42, $68, $68
ST4
DB $79, $21, $09, $00, $01
DB $60, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
ST5
DB $79, $00, $08, $00, $03
DB $4C, $00, $09, $00, $00, $00, $00, $00, $00, $00, $00
179
Game Boy Programming Manual
180
Chapter 7: Super Game Boy Sound
181
Game Boy Programming Manual
Using the SGB system commands, pre-loaded sound effects in the sound program can be used in Game Boy
application programs that support SGB (SGB software).
These commands can be used to set each of the 73 types of pre-loaded sound effects to 4 intervals (playback
frequencies) and 3 volume levels.
Also preloaded are music data for BGM (instruments sound sampling data). This easily allows play of score data
created with Kankichi-kun, the tool for creating SNES scores, and score data for KAN.ASM, the standard driver
that is a software tool for IS-SOUND.
In addition, information on the SGB score data format has been made openly available, allowing those using
tools other than the NEWS system or IS-SOUND to create score data in this format.
182
Chapter 7: Super Game Boy Sound
[ APU Addresses ]
183
Game Boy Programming Manual
BGM can be played with the APU by using the SOU_TRN command to transfer original score data to the
prescribed area of APU RAM. The user area is the 8 Kbytes from 0x2B00 to 0x4AFF.
SOUND Command
0x10
0xF
Note If 0x01-0x0F are set without score data being transferred, the BGM built into the
system is played.
This BGM is exclusively for use by the system, so 0x01-0x0F should not be
written as a BGM flag without original score data being transferred.
Even if original score data is transferred, there is risk that the sound program
will run uncontrolled if a non-designated code is written.
Muting is in effect when the system is initialized, so the BGM playback settings
must be made after muting is canceled.
184
Chapter 7: Super Game Boy Sound
Original BGM can be played with the SGB sound program by transferring score data to the APU using system
commands.
Fifty-seven sounds can be used in BGM, and the score data can be up to just under 8 Kbytes in size.
The method used to create a musical piece is nearly identical to that of the standard SNES.
When the NEWS system is used, score data is created using Kankichi-kun. When IS-SOUND is used, score
data created by an external sequencer are processed through MIDI and converted to create score data
supported by the standard sound driver KAN.ASM.
In addition the SGB score data format has been made openly available, allowing those using original tools to
create score data in this format.
In creating musical pieces, please refer to Section 4, SGB Sound Program Source List, when selecting sounds.
Please do not change the order of these source data.
185
Game Boy Programming Manual
% mv sobox xxxxx
% mkdir sobox
* SGB can use only specific sound objects. Thus, special SGB source data must be installed. A sobox directory
for SGB use must be created to prevent loss of previously installed source data files with the same names as the
data files to be installed.
% soread
Executing the above command causes the sampling data to be automatically installed.
% mkdir #####
186
Chapter 7: Super Game Boy Sound
8. From the installation disk, install the following files in the working directory: sgbt.asm, sample.kan,
check.kan, kankichib.hex, and kan.equ.
Item Setting
Kan.equ 0x4c30
Kan.tan 0x04c10
9. Make the following changes in the file .cshrc in the home directory.
10. In the home directory, execute the following command: source .cshrc.
187
Game Boy Programming Manual
% cp sample.kan xxx.kan
* This avoids the task of creating a source list in source-list order when using mapu.
2. Start mapu.
% mapu -k
* When starting mapu for the first time, press the NICE reset button.
3. The usable sounds (sources) can be checked with mapu. Selecting check.kan allows the sounds to be
checked in source-list order.
* If data in files such as check.kan are changed, the sounds cannot be checked.
* Source data (sampling data) that SGB can use have been set in xxx.kan. The source list is shown in Section
4, SGB Sound Program Source List. Note that changing the order of the source list will result in sounds different
from the intended sounds when BGM is played.
5. When producing a musical piece, see Section 3.7, Cautions Regarding Production of Musical Pieces. Refer
to the Kankichi-kun Manual.
6. Finally, convert to the file format described in Section 3.8, Format for Transferred Files.
188
Chapter 7: Super Game Boy Sound
Environment Required
Revisions
1. Portions of the IS-SOUND software tool KAN.EQU were revised as indicated below (older versions only).
1. Set Gate Table data to 050 · 101 · 127 · 152 · 178 · 203 · 229 · 252.
2. Set Velocity Table data to 025 · 050 · 076 · 101 · 114 · 127 · 140 · 152 · 165 · 178 · 191 · 203
· 216· 229 · 242 · 252.
Note Sound data (sampling data) are required to check music data using IS-SOUND.
Consequently, a program equivalent to the sound program built into the SGB
hardware (including sound-effect data) and sampling data (sound data) have
been provided in a hex file for MS-DOS. The following briefly describes how to
set up this program and data.
1. Create an SGB working directory at any location, and move to that directory.
8. Execute s2140 to write 01 (from the main program, writes 01 to 0 of the sound port).
189
Game Boy Programming Manual
With this procedure, the pre-loaded source data (sampling data) are played in the order shown in Section 4 of
this chapter, SGB Sound Program Source List.
After the data is transferred once, only the score data needs to be transferred to allow music to be checked
again.
Cautions
1. Score data is the data defined in KAN.ASM Version 1.21 as being located from GFT onward. For
information on all items related to converting data from other sequencers to score data, formats, and tool
usage, see the IS-SOUND manual.
4. When producing a musical piece, do so in accordance with Section 3.7, Cautions Regarding Production of
Musical Pieces.
5. Convert to the file format described in Section 3.8, Format for Transferred Files.
The score data format has been made openly available for the benefit of those using original development tools.
Score Data
Glossary of Terms
Block A unit several bars long that each tune is divided into.
190
Chapter 7: Super Game Boy Sound
Example 1
191
Game Boy Programming Manual
192
Chapter 7: Super Game Boy Sound
Description of Example 1
(a) The score data map to memory addresses 0x2B00-0x4AFF in the APU.
If this area is exceeded, a portion of the sound program will be destroyed.
(e) 0x01-0x7F (01-127) is the number of loops (repetitions); 0x82-0xFF (130-255) is an endless loop.
If repetition is not needed, set the end code (0x00) instead of a loop code.
(g) Location where the parts of each block are indicated and the part labels are defined.
Defines the part labels for parts 0, 1, 2, . . . 7 in ascending order from top to bottom. 0x00 should be written for
unused parts. Even if some parts are unused, always define 8 parts.
Parameters such as temp, volume, pan, source number, echo, velocity, interval, and sound length are set here.
First set are the effects parameters – such as main volume, ramp, and echo – for Part 0 of the first block. Once
these are set, they need not be set again (for other blocks or parts) as long as they are not changed.
Next the parameters such as part volume, pan, source number, and tuning are set for each part.
Then the sound length, velocity + gate time, and interval are set in that order. Be careful to ensure that sound
length is always set first, followed by velocity + gate item, then the interval.
If the next sound is the same as the previous sound, the sound length, velocity, and gate time need not be set
again.
The lower parts and blocks are set in the same manner.
193
Game Boy Programming Manual
Code Summaries
6 18 48
Sixteenth note Dotted eighth Half note
note
9 24 72
Dotted Quarter note Dotted half note
sixteenth note
12 36 96
Eighth note Dotted quarter Whole note
note
Note For triplets and thirty-second notes, convert using the above values.
194
Chapter 7: Super Game Boy Sound
*When setting score data using symbols, assemble after defining the equal statement according to the table
above.
195
Game Boy Programming Manual
c) Interval Data
Intervals for 6 octaves can be set here.
Depending on the sound, however, high sounds may not be heard.
The following table shows the correspondence between code settings and intervals. Please refer to this
table when setting an interval.
*When score data is set using symbols, assemble after defining the equals statement.
196
Chapter 7: Super Game Boy Sound
Note 2: When specifying a tie, first set the step time (length) and velocity + gate time. (This can be skipped if
unchanged from the previous sound.)
Note 3: When specifying KYU (a rest), first set the step time (length). (This can be skipped if unchanged from
the previous sound.)
Settings Example:
Length Gt & Vel Interval Code
db 024, P99+V99, C30 ;(0x0A4) for specifying an interval
Length Gt & Vel Tie Code
db 048, P90+V95, TIE ;(0x0C8) for specifying a tie
Length Rest Code
db 096 KYU ;(0x0C9) for specifying a rest
197
Game Boy Programming Manual
d) Special Symbols
The special symbols represent special data for implementing a variety of special effects. These include
sound change, crescendo, panpot change, vibrato, tremolo, and echo. Each symbol has its own parameters.
The following table lists these special symbols, their parameters, and the valid values for these
parameters.
vib No. of hold steps Rate Depth Vibrato (no. of hold steps is the time
($E3) 0 ≤ X ≤ 255 1 ≤ Y ≤ 255 1 ≤ Z ≤ 255 till vibrato takes effect)
198
Chapter 7: Super Game Boy Sound
tre No. of hold steps Rate Depth Tremelo (no. of hold steps is the
($EB) 0 ≤ X ≤ 255 1 ≤ Y ≤ 255 1 ≤ Z ≤ 255 time till tremelo takes effect)
pat PAT ADRS(L) PAT ADRS(H) REPEAT PAT Pattern data subroutine
($EF) $00 ≤ X ≤ $FF $00 ≤ Y ≤ $FF 1 ≤ Z ≤ 255 Seen Note 2.
swk No. of hold steps No. of steps Amount of change Start sweep from next sound
($F1) 0 ≤ X ≤ 255 1 ≤ Y ≤ 255 $DC ≤ Z ≤ $FF(– value)
– is the two’s complement
$00 ≤ Z ≤ $24
sws No. of hold steps No. of steps Amount of change Start sweep heading into next sound
($F2) 0 ≤ X ≤ 255 1 ≤ Y ≤ 255 $DC ≤ Z ≤ $FF(– value– is the two’s complement
$00 ≤ Z ≤ $24
199
Game Boy Programming Manual
Note 1: The tempo values set by the program data and the actual (musical piece) tempos that correspond to
those values are as follows.
Note 2: Used when the same performance data is repeated (for data compression). Following the pat code, the
L and H addresses and the repetition frequency for the performance data is set. The performance data at the
addresses specified by pat are then read. The data is played the number of times specified by the repetition
frequency. The performance data at the locations specified by pat require an end code of 0x00.
Note 3: When applying echo, ecv and edl are required. The value entered for the echo channel is 1 for echo
used in Part 0, 2 for Part 1, 4 for Part 2, 8 for Part 3, 16 for Part 4, 32 for Part 5, 64 for Part 6, and 128 for Part
7. When echo is used for multiple parts, enter the sum of the channel number values.
Examples
Note 4: Echo time is the delay duration. It uses RAM area equal to twice the echo time value, expressed in
Kbytes. The echo area in SGB is 4 Kbytes, so a value of 2 or less should be entered. Feedback indicates the
amount of delay returned. Filter No. indicates the type of filter applied to the delayed sound.
*The symbols marked with a I in the Special Symbols table are applied to all parts. These should be set in the
first part.
*When using a symbol to set a special symbol for score data, assemble after defining the equals statement
according to the Special Symbols table.
*The special symbols and the arguments that follow should be set in the order shown in the tables.
*If using IS-SOUND, load sgbsound.hex according to the steps in Section 3.5, Setting the Working Environment
for IS-SOUND. Transferring the subsequently created score data allows the tunes and sounds to be checked.
200
Chapter 7: Super Game Boy Sound
Cautions
3. Musical pieces should be produced according to the instructions in Section 3.7, Cautions Regarding
Production of Musical Pieces.
4. Convert to the file format described in Section 3.8, Format for Transferred Files.
201
Game Boy Programming Manual
The echo parameters set in BGM are applied in the same manner for the A and B sound effects.
This is because echo is applied equally to all 8 channels. The parameters have been tuned so
that they can also be used with BGM, so please note this when resetting the parameters.
If a value greater than 2 is specified for Echo Time, the sampling data will be destroyed. Up to 15
tunes can be registered (0x01-0x0F). Channels 2 and 3 are allocated for BGM, so these channels
should be used for regular playback of BGM parts.
Microtuning of source data used for notes should be specified using the tun code with the score
data. For tuning values, refer to the recommended tunings in Section 4 of this chapter, SGB
Sound Program Source List (except for percussion instruments).
The recommended tuning values for this source list are based on an interval of C30 (See Section
3.6.4, Interval Data).
Also indicated for each source data item is the score data setting (interval code) for producing
sounds with a C30 interval. Please refer to these settings in inputting score data.
In high and low areas, the tuning of some source data may be somewhat off. Whenever this
occurs, the tuning value must be modified.
For SGB, all tunings are set 50 cents higher than the standard value (A = 440 Hz).
202
Chapter 7: Super Game Boy Sound
% cp sgbt.asm yyy.asm
* When adding multiple tunes, add them beginning from line 113. Also increase the number of ‘include
ΟΟΟ.dat’ statements after line 115 by the number of tunes.
4. Convert the yyy.hex file completed in Step 3 to the format used by the SNES sound generator.
The score data file to be transferred is converted to the format used by the sound boot program.
Example:
dw $0030 ; Number of data items to transfer
dw $2b00 ; Transfer destination address
db $00,$01,$02,$03,$04,$05,$06,$07 ; Score data
db $08,$09,$0a,$0b,$0c,$0d,$0e,$0f ; Score data
db $00,$01,$02,$03,$04,$05,$06,$07 ; Score data
db $08,$09,$0a,$0b,$0c,$0d,$0e,$0f ; Score data
db $00,$01,$02,$03,$04,$05,$06,$07 ; Score data
db $00,$01,$02,$03,$04,$05,$06,$07 ; Score data
dw $0000 ; Transfer end code
dw $0400 ; Program start address
203
Game Boy Programming Manual
The number of data items to transfer (2 bytes) and the transfer destination address (2 bytes) are placed at the
starting address of the score data. (Be careful to ensure that the data in this order.)
Finally, the transfer end code (2 bytes) and the program starting address are added. (Be careful to ensure that
the data is in this order.) The transfer end code is $0000.
In SGB, the transfer destination address is $2b00, and the program starting address is $0400. Please be sure to
use the correct addresses, or program control will be lost.
The area used for the transferred score data is approximately 8 Kbytes. A data overflow will destroy the directory.
204
Chapter 7: Super Game Boy Sound
205
Game Boy Programming Manual
206
Chapter 7: Super Game Boy Sound
Settings for source data numbers 0x39-0x3E cannot be specified on Kankichi-kun. These source data can be
used only with sound effects. However, they can be set using tools other than Kankichi-kun.
The shaded portions are the basic source data. The other source data items are the basic source data with
modified envelopes.
The contents of the source list are also listed in the README file located in the sobox directory installed for
NEWS.
The recommended tuning values in the source list are based on an interval of C30. (See Section 3.6.4, Interval
Data.) With high- and low-pass filtering, the tuning of some source data may be somewhat off. Whenever this
occurs, the tuning value must be modified.
The interval value is the score data setting (interval code) for producing sounds with a C30 interval. For SGB,
all tunings are set 50 cents higher than the standard value (A = 440 Hz). The source data items in the empty
areas do not require tuning. (In addition, they can be used without changing the interval).
207
Game Boy Programming Manual
• The data is not transferred to areas other than the score area (except for the Directory and sod
data).
If the data is transferred to other areas, the sound effects used by the system may no longer play or may be
altered (strange sounds). Transferring data to other areas may also lead to a loss of program control. Therefore,
please be certain to ensure that the above two conditions are met.
* The sound numbers ( so No.) corresponding to the sampling data should be from among one of
the following.
Note All numbers other than the above are used for system sound effects or music.
Therefore, be careful to use only the above numbers.
* Directory and sod data are provided for each sound (so No.).
No. of
Start Address Data Structure
Bytes
When the sound number is 0x000, the directory data comprise 4 bytes beginning at 0x4B00, and the sod data
comprise 6 bytes beginning at 0x4C30 (0x000 cannot be used).
Please substitute the directory data and sod data values corresponding to the given sound number.
Note For the sound number, however, be careful not to use any number other those
shown in 2. Use of an incorrect number will cause a loss of program control.
Transferring all of these data and issuing a BGB request will result in audio playback.
208
Chapter 7: Super Game Boy Sound
With sampling data consisting of a single sound with a sound number of 0x002, the Directory data would be the
4 bytes beginning at 0x4B08, and the sod data would occupy the 6 bytes beginning at 0x4C3C. In this case,
ensure that the score data begin at 0x2B00. Starting these data at any location other than 0x2B00 would cause
a loss of program control. The sampling data (audio data) should be transferred to the area between 0x2B00 and
0x3AFF.
When using multiple sampling data items, also transfer the Directory and sod data specified for each item in Step 2.
Note Be careful not to rewrite the Directory and sod data used by the system.
209
Game Boy Programming Manual
210
Chapter 8: Game Boy Memory Controllers (MBC)
211
Game Boy Programming Manual
♦ Register 2: Upper ROM bank code when using 8 Mbits or more of ROM (and register 3 is 0)
Write addresses: 0x4000-0x5FFF Write data: 0-3
The upper ROM banks can be selected in 512-Kbyte increments.
Write value of 0 selects banks 0x01-0x1F
Write value of 1 selects banks 0x21-0x3F
Write value of 2 selects banks 0x41-0x5F
Write value of 3 selects banks 0x61-0x7F
: RAM bank code when using 256 Kbits of RAM (and register 3 is 1)
212
Chapter 8: Game Boy Memory Controllers (MBC)
213
Game Boy Programming Manual
: :
Program
Residence
Area Bank 2
0x008000
Bank 1
0000 0x004000
Bank 0
000000
214
Chapter 8: Game Boy Memory Controllers (MBC)
2. MBC2
2.1 Overview
Controller for up to 2 Mbits (256 Kbytes) of ROM with built-in backup RAM (512 x 4 bits).
Display
Bank 6
0x8000 0x18000
Bank 5
Program 0x14000
Switching Bank 4
Area 0x10000
Bank 3
0x4000 0x0C000
Bank 2
Program 0x08000
Residence Bank 1
Area 0x04000
Bank 0
0000 00000
215
Game Boy Programming Manual
3. MBC3
3.1 Overview
MBC3 is the memory bank controller that allows use of between 512 Kbits (64 Kbytes) and 16 Mbits (2 MB)
of ROM and 256 Kbits (32 Kbytes) of RAM.
Built into the controller are clock counters that operate by means of an external crystal oscillator (32.768
KHz). The clock counters are accessed by RAM bank switching.
RAM and clock counter data can be backed up by an external lithium battery.
216
Chapter 8: Game Boy Memory Controllers (MBC)
The clock counter registers are assigned to the external expansion RAM area of the CPU address space.
To access the clock counters, RAM bank switching must first be performed.
3.3.1 Reading
The clock counters are accessed by first writing 0x0A to register 0. This opens the gate used to access
the counters. To read clock counter values, write 1 to register 3 to latch the values of all the registers. If
the value of register 3 is already 1, first set it to 0 and then to 1. While this register is set to 1, the clock
counters will operate but the latched values of all of the clock counters will not change. This allows the
clock counters to be read.
For example, the seconds counter register can be accessed and read by first setting the RAM bank to 8,
then reading from any CPU address between 0xA000 and 0xBFFF.
3.3.2 Writing
Writing 0x0A to register 0 opens the access gate, allowing each clock counter register to be written to.
217
Game Boy Programming Manual
• ROM bank 0 is assigned to the program residence area (0x0000-0x3FFF) of the CPU memory space
(unchangeable).
• One bank from among ROM banks 0x01-0x7F can be assigned to the program switching area (0x4000-
0x7FFF) of the CPU memory space.
• One bank from among RAM banks 0-3 and the clock counter registers (RAM banks 0x08-0x0C) can be
assigned to the external expansion working RAM area (0xA000-0xBFFF) of the CPU memory space.
218
Chapter 8: Game Boy Memory Controllers (MBC)
Although counting up of the clock counters themselves and accessing the clock counters from the CPU are
performed asynchronously, clock counter failure may result if both operations are performed at the same
time. To prevent this, MBC3 provides an interface circuit for WR signals from the CPU. Use of this circuit
necessitates a delay when accessing control register 3 and the clock counter registers (RTC_S, RTC_M,
RTC_H, RTC_DL, and RTC_DH). Thus, whenever accessing these registers consecutively, interpose a
delay of 4 cycles between accesses.
219
Game Boy Programming Manual
3.5.2 Condensation
MBC3 uses a crystal oscillator for its clock counter operation, and condensation on the oscillator may halt
its oscillation, preventing the clocks from counting up. Once the condensation disappears, the clocks will
resume counting up from where they stopped. However, please ensure that the counter stoppage does not
result in a loss of program control.
Although control registers 0-3 are initialized (see Section 3.2, Description of Registers) when Game Boy
power is turned on, they are not initialized by a hard reset of SNES when Super Game Boy is used.
Therefore, please be sure to implement a software reset of these registers.
When commercial Game Boy software that uses MBC3 is shipped from the factory, the values of the clock
counter registers are undefined. Therefore, please ensure that these registers are initialized.
220
Chapter 8: Game Boy Memory Controllers (MBC)
4. MBC5
4.1 Overview
Supports CGB double-speed mode.
MBC5 can use up to 64 Mbits of ROM (512 banks of 128 bits each) and
1 Mbit of RAM (16 banks of 64 Kbits each).
4.2 Registers
CPU Address
RAM 0xFFFF ROM
Unit
Highest bank, Registers Highest bank,
0x0F 0x1FF
Maximum of 1 0xE000
Mbit Internal
: : Working
Set by RAMB register. : : 0xC000 RAM
Accessible only External
when RAMG register
: :
Bank 0x01 Expansion
is 0x0A. Working RAM
0xA000
Bank 0x00 : :
Display Up to 64 Mbits
RAM Set by the
: : ROMB0,
0x8000 ROMB1
registers
Empty Bank Switching : :
(no image) Area
Bank 0x00 - Bank
0x6000 0x1FF : :
0x5000 RAMB (Default bank 0x01)
: :
0x4000
ROMB1
0x3000
Program Residence
ROMB0
Area
0x2000 Fixed at
Bank 1
Bank 0x00
RAMG
Bank 0
0x0000
Writing Reading
During a write, data is written to the bank control registers at
CPU addresses 0x0000-0x7FFF. During a read, the contents of
ROM are read from these addresses.
221
Game Boy Programming Manual
Note Although the bits marked with are ignored by MBC5, they should
be used after being set to 0. The default values are set automatically when
power is turned on.
222
Chapter 8: Game Boy Memory Controllers (MBC)
♦ Use of Register 1
If an MBC1 program uses register 1 (ROM bank control register) addresses 0x3000-0x3FFF, the bank
intended for selection by ROMB1 in MBC5 will not be selected.
♦ Use of Register 2
Note that in MBC1, programs that use 8 Mbits or more use register 2 (ROM or RAM bank control
register) for the high ROM bank. Consequently, in MBC5 the RAM bank is different while the ROM
bank is unchanged.
ROM banks 0x20, 0x40, and 0x60 cannot be used in MBC1, but they can be used in MBC5.
Because the addresses of ROM and RAM are independent of each other in MBC5, ROM/RAM
switching is unnecessary.
Any write instructions to register3 left in a program that uses MBC1 are ignored by MBC5 and have no
effect.
♦ Memory Image
If a memory device is used that uses less than the maximum amount of memory available (ROM: 64
Mbits; RAM: 1 Mbit) , a memory image is generated for the empty bank area. Therefore, please do not
develop software that uses an image, because it may cause failures.
To protect RAM data, it is recommended that RAM access be disabled when RAM is not being
accessed (RAMG ← 0x00) .
Always use the sound control register (NR50) with bits 7 and 3 (VIN function OFF) set to 0. Because
the VIN terminal is used in development flash ROM cartridges, using the register with VIN set to ON
will produce sound abnormalities.
223
Game Boy Programming Manual
LD A,$FF
LD ($2000),A ;ROMB0 setting
LD A,$01
LD ($3000),A ;ROMB1 setting
|
|
|
LD A,$0F
LD ($4000),A ; RAMB setting
LD A,$0A
LD ($0000),A ; Enable access to RAM
|
| RAM Access Processing
|
LD A,$00
LD ($0000), A ; Disable access to RAM
224
Chapter 8: Game Boy Memory Controllers (MBC)
Up to 64 Mbits (512 banks of 128 Kbits each) of ROM and 256 Kbits of RAM (4 banks of 64 Kbits each) can
be used.
5.2 Registers
225
Game Boy Programming Manual
CPU Address
RAM 0xFFFF
ROM
Unit
Bank 3 Registers Highest bank, 0x1FF
0xE000
Maximum of 256 Internal
Kbits (Banks 0-3) Bank 2 Working
RAM : :
Set by register RAMB Bank 1 0xC000 External
Accessible only when Expansion
RAMG is 0x0A Working RAM : :
Bank 0
0xA000 Display Maximum 64
RAM : : Mbits
Set by registers
0x8000 ROMB0 and
ROMB1
Empty
(no image) Bank Switching : :
Area
0x6000 Bank 0x00 - Bank
0x1FF
0x5000 RAMB (Default bank 0x01) : :
0x4000
ROMB1
0x3000
ROMB0 Program Residence
0x2000 Area Bank 1
Fixed at Bank 0
RAMG
Bank 0
0x0000
Write Read
* During a write, data is written to the bank control registers at
CPU addresses 0x0000-0x7FFF. During a read, the contents of
ROM are read from these addresses.
226
Chapter 8: Game Boy Memory Controllers (MBC)
Note Be sure to set the bits marked with to 0 before using them. The
default values are set automatically when power is turned on.
227
Game Boy Programming Manual
(1) Set the frame rate to 1 frame per 1/60 second and control vibration frame by frame.
(2) At the start of vibration control, send a startup pulse (at least 2 ON frames).
A startup pulse also should be sent if the width of an OFF pulse is 3 or more consecutive
frames. This is necessary because startup from a complete stop requires a certain amount of
time.
(see Ex. 5)
ON
Example 1:
Strong
OFF
2Frames 1 2
ON Startup
Example 2:
Pulse
Slightly strong
OFF
2Frames 1 1
Example 3: ON Startup
Pulse
Slightly weak
OFF
2Frames 2 1
ON Startup
Example 4: Pulse
Strong
OFF
2Frames 3 2
Example 5: ON Startup Startup
3 consecutive Pulse Pulse
OFF frames
OFF
228
Chapter 8: Game Boy Memory Controllers (MBC)
IMPORTANT
The above points are guidelines that should be followed in most cases. However, if adhering to
these guidelines is made difficult by factors such as the game content, take appropriate
measures while keeping in mind the points noted in Section 6.7, Effects of Vibration on the
Body.
229
Game Boy Programming Manual
Users have occasionally experienced numbness for some time after continuous vibration lasting several
tens of seconds to several minutes. This may occur regardless of the strength of the vibration (see
Section 5.5.2, Vibration Pulse Examples).
Unfortunately, the effects of continuous vibration on the body are not yet clear. Thus, the guidelines
presented in Section 5.6.5, Limiting the Period of Continuous Vibration, are intended to give priority to
user safety. However, software development requires free thinking and original ideas, and there may
well be cases in which the use of continuous vibration in a game is desirable.
Because each game is different, the limitations presented in Section 5.6.5 are by their nature not
restrictions that should be enforced digitally. It is instead preferable for the developer to adequately
consider user safety when determining the game’s content.
For example, even supposing that continuous vibration does last for more than 1 minute, it may not pose
a safety problem if it is used infrequently, such as only when special events occur. Conversely, if
vibrations lasting several seconds to several tens of seconds are repeated at short intervals, the effects
on the user may be the same as with continuous, long-term vibration.
Thus, the guidelines presented in Section 5.6.5 are not absolute restrictions. However, even if a
program varies from these guidelines, the following points should be considered minimum requirements
and strictly observed.
• Because the effects of continous vibration vary from person to person, the strength of these effects
on the user should not be determined independently by the developer. Rather, this determination
should be arrived at after considering the opinions of many others during debugging and other
phases of development.
230
Chapter 9: Pocket Printer
232
Chapter 9: Pocket Printer
1. OVERVIEW
These specifications define the serial protocol used to send print and control data from Game Boy
to the Pocket Printer (abbreviated to printer). Game Boy sends data to the printer in packets, and
the printer responds by returning 2 bytes of status information.
2. COMMUNICATION SPECIFICATIONS
2.1 Bidirectional Communication
Serial transfers between Game Boy and the printer are performed in the Game Boy specification
communication format (bidirectional).
The shift clock is furnished by the Game Boy. Both Game Boy and the printer start transmission
from the most significant bit (MSB).
For more information , see Chapter 1, Section 2.5.1, Serial Cable Communication.
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
An interval of 270 µs to 5 ms must be interposed between each byte sent. Thus, care should be
exercised regarding factors like interrupts when programming.
Each type of data sent by the Game Boy is sent in a packet. An interval of 270 µs to 117 ms
must be allowed between the transfer of each packet. Thus, care should be exercised regarding
factors like interrupts when programming.
After the connection between the Game Boy and printer is confirmed, the Game Boy sends a
NUL packet every 100 msec for a synchronism check of the connection. If the Game Boy
determines that a connection is unnecessary and does not send a NUL packet in the prescribed
time, the printer will determine that the connection is abnormal and will wait in an initialized state
for a signal from the Game Boy.
233
Game Boy Programming Manual
This section defines the following data items (packet types and data) by function.
234
Chapter 9: Pocket Printer
The value of the MSB is always 1. The lower-order 7 bits represent the device number.
The Pocket Printer is device no. 1.
Byte 2: Status
LowBat ER2 ER1 ER0 Untran Full Busy Sum
Status information is sent in reply to each 2 bytes of dummy data sent by the Game Boy.
* The status returned by the printer is FF FF when the printer is not connected to the Game Boy
or not powered on.
Either an error number listed below or the error number plus a description of the error would be
sent to the display screen in response to an error flag in byte 2. (This information is also
presented in the user’s manual of the Pocket Printer. That information must be used together with
the information given here.)
235
Game Boy Programming Manual
A value other than 0x81for the first status byte means that a device other than the Pocket Printer
is connected. This should be conveyed to the user as an error message.
236
Chapter 9: Pocket Printer
4. PACKET DETAILS
This packet is used to initialize the printer and check the connection. If the Game Boy sends a packet for
checking the printer connection and a printer is connected, it returns a 2-byte status code and initializes for the
start of print processing. This packet must always be sent when the Game Boy starts to access the printer. It
allows transferred data to be invalidated (reset).
Actual Data
88 33 01 00 00 00 01 00 00 00
Example
88 33 02 00 04 00 01 13 E4 40 3D 01 00 00
PA Header Data Checksum Dummy
Data: Byte 1 specifies the number of sheets. 0-255 (1 in the example). 0 means line feed only.
Data: Byte 2 indicates the number of line feeds. Higher-order 4 bits represents the number of feeds before
printing.
Lower-order 4 bits represents the number after printing. Each
value is 0x00-0x0F.
* 1 feed = 2.64 mm
Data: Byte 3 holds the palette values. Default is 00. Palettes are defined by every 2 bits beginning
from high bit. (See Chapter 2, Section 2.3, Character RAM.)
Data: Byte 4 is the print density adjustment. 0x00-0x7F. Default values are 0x40 and 0x80 or greater.
00 < 0x40 < 0x7F
-25% 0% +25%
When printing continuous images from multiple screens, setting the number of line feeds to 0 after one screen’s
worth of data is printed (9 data packets and a data-end packet) enables printing to be continued from one
image to the next without a break.
Cautions Regarding Print Instructions (Caution Required)
• Although applications can print 2-255 pages continuously, this may take a long time. Thus, the user should
be provided with a means of halting a print job in progress. (See Section 4.5, Break Packet.)
• Whenever possible, the print density data should be backed up to avoid the inconvenience of adjusting the
density at each startup.
237
Game Boy Programming Manual
• If a print instruction packet is set within 100 msec of when the motor is stopped, the position where printing
resumes may be incorrect. Always send print instruction packets at least 100 msec after the motor has been
stopped.
• Always set the number of line feeds before printing to 1 or greater and the number after printing to 3 or
greater, except in the case of the previously mentioned continuous printing , when both values are 0. Other
values for these parameters may in result in faulty operation, such as double printing on the same line or
failure of the last printed line to reach the paper cutter.
Sends print data that are in character data format. The print data is sent in 1-byte increments for the specified
number of bytes.
Example
88 33 04 00 80 02 Data0 ~ DataN-1 C1 C2 00 00
Transmission of compressed data is accomplished by compressing one line at a time -- each line consisting of
20 characters horizontally and 2 characters vertically -- and sending the number of compressed bytes in order,
beginning from the first line.
If the compressed lines exceed 0x280 bytes, the non-compressed data is sent as is (mixture of compressed
and non-compressed packets). If the extended data do not fill an entire line when the packets are processed,
the printer returns a packet error.
If an instruction to stop printing is received while print data is being sent, an initialization packet can be sent
instead of the next data packet.
One Game Boy screen of data is represented by 9 data packets. However, a data-end packet can be sent even
if the number of data packets sent is less than 9. In this case, the printer will print only the number of lines
received. Line feeds can be performed by sending a data-end packet with no data packet and issuing a print
instruction. The printer will then feed the number of lines indicated by the instruction.
Sending the following print instruction packet with a data-end packet but no data packet would specify that 5
sheets be printed, with 1 line feed before printing and 3 line feeds after printing, and that the pre-printing line
feeds be ignored. The number of line feeds performed would therefore equal the product of number of sheets to
be printed and the number of post-printing line feeds specified. Thus, in this example, the number of line feeds
would be 15.
Example
88 33 02 00 04 00 05 13 E4 40 42 01 00 00
238
Chapter 9: Pocket Printer
Actual Data
88 33 04 00 00 00 04 00 00 00
A data length of 0 for the data packet header represents the end of the print data. This must always be sent to
end print data transmission.
Used to discontinue printing. The break packet is sent by means of the user’s instructions and forcibly stops
printing. (Printing is halted after 1 line is printed.)
Actual Data
88 33 08 00 00 00 08 00 00 00
A functionless packet for requesting the current status of the printer. The printer may occasionally be halted
unintentionally while printing (e.g., paper jam, low battery), so a NUL packet should always first be sent to check
the printer’s status.
Actual Data
88 33 0F 00 00 00 0F 00 00 00
Except in the case of a checksum error, if a packet of one of these types is sent but does not match the
specification described, the printer will return a packet error.
Packets other than the types mentioned above are ignored by the printer.
239
Game Boy Programming Manual
The following table shows the packets that can and cannot be sent from the Game Boy to the printer while the
printer is in various states.
Data packet ? Ο x s s
Data-end packet ? Ο x s s
Break packet ? s s Ο s
NUL packet ? Ο Ο Ο Ο
* The user could push the feed button while data is being transferred. In this case, the entire data packet would
be ignored, so the same packet would need to be re-sent.
240
Chapter 9: Pocket Printer
241
Game Boy Programming Manual
Printer normal
Printer status normal ↓
↓ Wait to receive data
Start communication ↓
↓ Data reception
Cable disconnects during data transfer ↓
↓ Preamble detection failure
Printer status = 0xFF ↓
↓ Set status to 0xFF
Confirm reset of printer connection ↓
↓ 80 msec delay
Check connection after 100 msec ↓
Printer initialization
242
Chapter 9: Pocket Printer
8. PRINT DATA
Printing Example
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
X00 X01 X02 X03 .... X09 X0A X0B X0C ... X13
Y0
Y1
Transfer Order
Y0.X00 --> Y0.X01 --> Y0.X02 --> ··· Y0.X13: 2 x 8 x 20 = 0x140 bytes
Y1.X00 (2 x 8) --> Y1.X01 --> ··· Y1.X13: 2 x 8 x 20 = 0x140 bytes
Total 0x280 bytes
1 CHAR =
2 bytes (higher grayscale, then lower grayscale) x 8 dots
vertically
243
Game Boy Programming Manual
9. COMPRESSION ALGORITHM
Compressed data essentially consist of control codes specifying the data type and length and the
actual data.
Control Code Control Code Control Code Control Code Control Code
0x7F ... 0x7E ... 0xFF ... 0x80 ... 0xFE ... ...
RAW Data RAW Data Loop Data Loop Data Loop Data
Example
0x09 0xA0 0xA1 0xA2 0xA3 ... 0xAA 0x7F 0x80 0x81 0x82 ... 0xFF 0xFF 0x55 0x80 0xAA
0x10 bytes of raw data 0x80 bytes of raw data 0x81 items of 0x55, 0x02 items of 0xAA
244
Chapter 9: Pocket Printer
11. MISCELLANEOUS
The printer comes in two types, each made a different manufacturer (Seiko Systems and Hosiden). During
final game debugging, the game should be checked with at least 1 printer of each type. The manufacturer
can be determined from the serial number on the back of the unit (Printers with PS serial numbers are made
by Seiko; those with PH serial numbers are made by Hosiden.) Many of the Seiko printers obtained on the
market are the normal Pocket Printer, while many of the printers made by Hosiden are manufactured
according to the special Pocket Printer Pikachu Yellow specification. However, depending on the needs of
the manufacturers, there is no guarantee that this distinction will hold true in the future. If obtaining a printer
proves difficult, please contact Nintendo for a special consultation.
Modifying a program to suit the intended use is permitted. However, in creating the original program, values
for timing and other parameters were calculated to allow normal operation. These parameters must
therefore be carefully considered when modifying a program.
245
Game Boy Programming Manual
246
Appendix 1: Programming Cautions
247
Game Boy Programming Manual
These programming notes provide information on how to avoid easily made mistakes during program
development, information on unique Game Boy programming issues that require special attention, and special
issues regarding peripheral devices.
Many of the topics covered in this appendix also are covered elsewhere in different chapters of this manual.
This appendix consolidates the discussion of these topics. Topics that would be more easily comprehensible to
the reader when presented separately will also be discussed in another chapter, even though this may
duplicate the discussion in this appendix.
Note: Although these notes were created to make every effort to eliminate potential sources of trouble at
market, they do not represent a guarantee that various potential problems on the market can be absolutely
avoided.
248
Appendix 1: Programming Cautions
2.1 LCDC/VRAM
Covers: CGB
Multiple windows that divide the screen horizontally into upper and lower areas can be displayed by setting the window
x-coordinate register (WX) to a value of 167 or greater during a horizontal blanking period. Attempting to display
multiple windows by switching the window ON and OFF during H-blanking may result in the lower window not being
displayed.
BG (Background) 167<WX<255
Window WX=7
BG (Background) OFF
Window ON
249
Game Boy Programming Manual
Reference Notes:
1. Accessing VRAM Outside of a V-blanking period
In early DMGs, accessing VRAM outside of a V-blanking period would corrupt the screen.
2. Length of H-blanking
The length of the H-blanking period changes depending on the conditions of OBJ use, so caution is
recommended when using H-blanking.
2.2 Communication
Covers: CGB
Adequate care should be taken to ensure against faulty operation and loss of program control even when infrared
communication signal input is received from other game software and devices. Note that such problems may
particularly occur in communication between multiple games that use the same subroutines. (Before performing data
communication, use means such exchanging a unique key code to check whether the same game is on the other
hardware.)
2.3 Sound
Covers: CGB
With continuous operation mode selected (bit 6 of NR*4 set to 0) for sounds 1, 2, and 3, if the higher-order frequency
data (lower-order 3 bits of NR*4) are changed, the sound length (bits 0-5 of NR*1) must to set to 0 after the frequency
data is set. If the sound length is not set to 0, the sound may stop during playback.
250
Appendix 1: Programming Cautions
Covers: DMG
An interval of approximately 18 cycles should be used between output from P14 and P15 and reading of input. Without
this interval, normal key input cannot be read.
Example:
LD A,3 ;Selects f/256 as the count-up pulse.
LD (07),A ;Sets TAC ← 3
LD A,7 ;Starts the timer
LD (07),A
If a write instruction is executed for the modulo register TMA with the same timing as the contents of that register are
transferred to TIMA as a result of a timer overflow, the same write data also will be transferred to TIMA..
251
Game Boy Programming Manual
Covers: CGB
When switching the CPU operating speed, first confirm the current speed by checking the speed flag (bit 7 of register
KEY1). In double-speed mode, both the divider (DIV) and timer (TIMA) registers will also be set for double-speed
operation.
Horizontal blanking DMA should always be started (bit 7 of HDMA5 set to 1) when the STAT mode is not set to 00. If
horizontal blanking DMA is started when STAT mode is 00, depending on the timing, the data in LCD display RAM may
be destroyed. In addition, execution of a HALT instruction during horizontal blanking DMA may prevent normal
cancellation of the HALT mode or DMA. Therefore, HALT instructions should not be used while horizontal blanking
DMA is being started.
General-purpose DMA should be started (bit 7 of HDMA5 set to 0) with the LCDC off or during V-blanking. However,
when transferring data during V-blanking, ensure that the transfer period does not overlap with STAT modes 10 or 11.
In DMG and in CGB in DMG mode, when transferring data to OAM by DMA, the user program area (0x00-0x7FFF)
should not be used as the starting address of the transfer. In some cases, data cannot be transferred from the user
program area normally. CGB mode, however, does enable DMA transfers from the user program area.
252
Appendix 1: Programming Cautions
To protect RAM data, access to RAM should be disabled (RAMG←0x00) when it is not being accessed.
3.2 MBC3
If the clock counters themselves are counted up, accessing of the clock counters by the CPU is performed
asynchronously. However, if these operations are performed simultaneously, the clock counters may fail. To prevent
this, MBC3 provides an interface circuit for WR signals from the CPR. Use of this circuit necessitates a delay when
accessing control register 3 and the clock counter registers (RTC_S, RTC_M, RTC_H, RTC_DL, and RTC_DH). Thus,
whenever accessing these registers consecutively, interpose a delay of 4 cycles between accesses.
MBC3 uses a crystal oscillator for its clock counter operation, and condensation on the oscillator may halt its oscillation,
preventing the clocks from counting up. Once the condensation disappears, the clocks will resume counting up from
where they stopped. However, please ensure that the counter stoppage does not result in a loss of program control.
253
Game Boy Programming Manual
Although control registers 0-3 are initialized (see Section 3.2, Description of Registers) when the Game Boy power is
turned on, they are not initialized by a hard reset of SNES when Super Game Boy is used. Therefore, please be sure to
implement a software reset of these registers.
When commercial GB software that use MBC3 are shipped from the factory, the values of the clock counter registers
are undefined. Therefore, please ensure that these registers are initialized.
3.3 MBC5
If a memory device is used that uses less than the maximum amount of memory available (ROM: 64 Mbits; RAM: 1
Mbit) , a memory image is generated for the empty bank area. Therefore, please do not develop software that uses an
image, because it may cause failures.
Always use the sound control register (NR50) with bits 7 and 3 (VIN function OFF) set to 0. Because the VIN terminal is
used in development flash ROM cartridges, using the register with VIN set to ON will produce sound abnormalities.
3.3.3 Disabling Vibration Using the SGB, SGB2, or 64GB Pak (Recommended)
When MBC5 with rumble feature is used by SGB, SGB2, or the 64GB Pak, vibration should be turned off by the
program to prevent failures caused by a faulty connection. For methods of recognizing SGB and SGB2, see Chapter 6,
section 4.2, Recognizing SGB. With the 64GB Pak, vibration is controlled by the N64 software. Therefore, N64
software programs that support MBC5 should not write data to bit 3 of the RAM bank register.
254
Appendix 1: Programming Cautions
To prevent physical effects in the user such as numbness as a result of continuous vibration, limit the duration of
continuous vibration as indicated below, regardless of the vibration strength.
The user should be allowed to set the rumble feature to ON or OFF or to select strong, mild, or OFF by means such as
an initial-settings screen at the start of the game. In addition, the program should allow the user to easily change these
settings even during a game if, for example, they are uncomfortable with the vibration. Such changes also should be
allowed a pause.
If the battery that powers the motor (size AAA alkaline battery) wears out, the perceived vibration level will be reduced
even if the requested vibration level remains the same. Therefore, rumble operation should be checked both when the
battery is new (1.6 V) and when it is at the end of its life (1.1 V).
255
Game Boy Programming Manual
To use the functions of SGB (system commands), the following values must be stored in ROM at the locations indicated.
0x146 ← 0x03, 0x14B ← 0x33
When writing programs that use the functions of SGB, use the initialization routine of the game program to send default
data (see Chapter 6) to the register file.
When using the SOU_TRN system command, send the SOU_TRN default data (see Chapter 6) to the register file before
SOU_TRN is used.
256
Appendix 1: Programming Cautions
Transfer time intervals vary depending on the manufacturer. The timings indicated in Chapter 9 should be used to avoid
faulty operation with a printer from a particular manufacturer.
Between 2 and 255 sheets can be printed continuously by an application. However, because this may take a long time,
the user should be given a means of halting a print job in progress.
Because it is very inconvenient to adjust the density each time the program is started, the print density data should be
backed up whenever possible.
If a print instruction packet is sent within 100 msec of when the motor is stopped, the print starting position may be
incorrect. Therefore, print instruction packets should always be sent at least 100 msec after the motor is stopped.
In setting the number of line feeds to be inserted before and after printing (byte 2 of the data portion of the print
instruction packet), always specify a value of 1 or greater for the number of feeds before printing and 3 or greater for the
number after printing. Otherwise, problems can arise, such as double printing twice on a single line or failure of the last
line of print to reach the paper cutter.
There are two types printers, each made by a different manufacturer (Seiko Instruments and Hosiden). As part of final
debugging, the program should be checked with at least one printer of each type.
Modifying the program to suit the intended use is permitted. However, in creating the original program, values for timing
and other parameters were calculated to allow normal operation. These parameters must therefore be carefully
considered when modifying the program.
257
Game Boy Programming Manual
If your game is Super Game Boy (SGB) enhanced, then you just need to use the MLT_REQ function. Otherwise, you
must use the SGB libraries to verify if the game is in an SGB. (These libraries are located in the CGB files section of
Wario World under SGBlib.zip.) You will need to call the SGBCHK function from these libraries right after the Soft Reset
label. To use this function, you must set the ROM Registration area for SGB ($146h) to $03, which allows access to the
SGB REgisters. (Don't forget to readjust the Complement Check.)
Also, on the Software Submission sheet, make sure you note that the game has a $03 in address $146, but in the
remarks section, explain that the game doesn't use any of the SGB features.
258
Game Boy Programming Manual
260
Appendix 2: Register and Instruction Set Summaries
261
Game Boy Programming Manual
262
Appendix 2: Register and Instruction Set Summaries
263
Game Boy Programming Manual
264
Appendix 2: Register and Instruction Set Summaries
265
Game Boy Programming Manual
266
Appendix 2: Register and Instruction Set Summaries
267
Game Boy Programming Manual
268
Appendix 2: Register and Instruction Set Summaries
269
Game Boy Programming Manual
270
Appendix 2: Register and Instruction Set Summaries
271
Game Boy Programming Manual
272
Appendix 2: Register and Instruction Set Summaries
273
Game Boy Programming Manual
274
Appendix 3: Software Submission Requirements
275
Game Boy Programming Manual
ROM Data
A copy of the ROM data must be submitted in binary format on MS-DOS® 3.5 inch disk(s). The size of
the file must be equal to the size of the EP-ROM (i.e., one 4 Meg EP- ROM = one 4 Meg file). Please
label each disk and include a description of its contents. (See “Storing Data to the Floppy Disk” below.)
276
Appendix 3: Software Submission Requirements
Screen Text
A printed copy of the complete screen text must be submitted.
Instruction Manual
One copy of the instruction manual must be included with your game submission. If, at the time of
submission the manual is not complete, (submitted as an intermediate version) then you must submit a
list of known bugs.
Note If any of these items are not satisfied, the program will be rejected and will
not be submitted into the approval process until all criteria are met.
3. SOFTWARE VERIFICATION
The following verification process will significantly improve the probability of approval of your software.
1. The licensing screen on all submissions should state “LICENSED BY NINTENDO”.
2. Confirm the Licensing Screen information is correct.
3. Check the spelling on the Licensing Screen and Title Screen, as well as the spelling and
grammar on the screen text.
4. Confirm the use of a TM (™), circle R (), or circle C () where applicable.
5. Run a “Bypass” Test to assure that when the game is powered up, the Licensing Screen is
visible for at least one second, even if any combination of controller buttons are pressed
repeatedly. Also “Power-up” the software repeatedly to assure it does so without
programming failures.
6. Game characters should be moved in all possible directions or positions, regardless of
whether it is required to play the game properly. For instance, if the game does not require
going to a particular area to complete the game, go there anyway to assure there are no
programming problems in going to that location.
7. The software should be paused many times during the test, as this often causes
programming problems to surface.
8. All testing should be recorded onto a videotape, making it easier to review programming
problems.
9. The entire attract mode (demo) should be viewed to assure there are no programming
problems.
10. Routines designed to assist the programmer or developer in “debugging” the software
should be removed from the game prior to submission. This includes routines to determine
hardware type.
277
Game Boy Programming Manual
11. A Game Boy Color dedicated game must include a hardware check upon power-up, which
will display the following message when it is connected to a device other than Game Boy
Color. The official game title must also be displayed in the upper portion of the display
screen.
--<Game Title>--
"This game can only be played on Game Boy Color"
Example
Tom’s Golf or
1992 ABC Corporation
LICENSED BY NINTENDO
If a blank screen appears for more than two seconds when powered up, Nintendo suggests placing a
message or graphic on the screen so that consumers do not think their game is inoperable (e.g., --
“Please Wait”--). If a blank screen appears for more than five seconds during game play, a message or
graphic should also be placed on the screen.
278
Appendix 3: Software Submission Requirements
6. COMMON PROBLEMS
Some possible problems that may prevent approval of your software include, but are not limited to the
following:
1. Software locks up.
2. Scrambled blocks or characters appear on the screen.
3. The software won’t pause.
4. Your character can get stuck somewhere with no possible way to get out.
5. Scrambled graphics at the edges of the screen when the screen scrolls in any direction.
6. Vowels in the passwords or password entry-system.
7. Colored lines at the top or bottom of the screen.
8. Shifting of the screen in any direction.
9. Inconsistent scoring methods.
10. Flashes on screen.
11. Small flickering lines on the screen.
12. Hit or be hit by an enemy but no damage is incurred.
13. Three (3) or four (4) player game can be started without using a four player adapter.
14. Incorrect Licensing Screen; “Licensed by Nintendo” should appear for all formats.
15. Violation of any Programming Cautions in the product programming manual.
16. Communication problems on two-player linkable DMG games.
17. Horizontal or vertical black lines when switching between screens on DMG games.
18. Use of the Nintendo logo or representations of Nintendo products in software without
license agreement.
19. The use of the term Super Nintendo or Nintendo when the Super Nintendo Entertainment
System or Nintendo Entertainment System is the intended reference, respectively. Use of
any term other than Nintendo 64 or N64 when the Nintendo 64 Entertainment System is the
intended reference.
20. Character actions are inconsistent (for instance, a character that cannot fly, being able to
walk off the edge of a platform and stand in midair).
21. Referring to the Nintendo Control Pad or Control Stick by an unacceptable term, such as;
“joypad”, “directional control”, etc.
22. Referring to the Nintendo Controller by an unacceptable term, such as; “joystick”, etc.
23. Referring to the Nintendo Game Pak by an unacceptable term, such as; “Game Cassette”,
etc.
24. Referring to the Game Boy Game Link by an unacceptable term, such as; “Video Link”, etc.
Note If Licensor approval is required, please assure that this has been finalized
before the software submission has been made.
279
Game Boy Programming Manual
280
Appendix 3: Software Submission Requirements
Note This checklist must be included with the software submission. If any of the
items are not satisfied, the program will be promptly returned and will not
be submitted into the approval process until all criteria are met.
281
Game Boy Programming Manual
c. IR Communications
If the software has CGB infrared communications capabilities, please
indicate whether the function involves communications with the same
game or with a different game. If you select “different game,” include the
game title in the parentheses.
7. Overseas Version
If the game has been, or will be, sold in another country; indicate the product title and
product code.
8. Contact
Provide the company name, department, address, phone number, fax number, and the
name of a representative that Nintendo should contact with all questions or comments
about the product.
282
Appendix 3: Software Submission Requirements
9. Submission Date
Provide the submission date and select the method used for submission.
10. Scheduled Release Date
Provide the scheduled release date for the game.
11. ROM Registration Data
Provide the contents registered in the indicated addresses of the master ROM. Refer to
“ROM Registration Data Specification” for details. Enter the ASCII code for the charac-
ters in areas marked with parenthesis “( )”.
12. Game Title Registration
Enter the game title registered in the master ROM using ASCII characters and their
ASCII codes. Also enter the Game Code assigned by Nintendo. Refer to “Character
Code List for Game Title Registration” for these entries.
13. Memory Controller
Indicate the type of memory controller used for this game. If no Memory Controller is
used, mark None.
14. Memory Configuration
Indicate the memory configuration of the game, as follows.
♦ ROM: Indicate the ROM size.
♦ RAM: Indicate whether or not work RAM is installed in the
Game Pak. If work RAM is installed, indicate whether it is
used as an expansion device or contained inside an
MBC. If it is used as an expansion device, indicate the
size of the RAM in the location provided. Also indicate if
work RAM
requires data back-up (battery). When the MBC-3 Clock
Counter function is used, check "Yes" for "Data Back-up",
regardless of which box is checked for "RAM".
283
Game Boy Programming Manual
284
Appendix 3: Software Submission Requirements
Example:
If the Initial code is 3 digits (prior to 1994), include an under bar (“_”) after the Initial code to bring it to 4
digits. The file name would appear as follows: “AAJ_10-0.GB”
Enter the check sum of each ROM submitted. To calculate the check sum, add each byte in the ROM
data. The lower 2 bytes of the resulting value is the check sum. Enter the check sum for each ROM
submitted for the master program and the total of their individual check sums. The total is calculated by
adding the individual check sums. This method of calculation is different from the check sum on the
ROM Registration Specification.
285
Game Boy Programming Manual
286
Appendix 3: Software Submission Requirements
287
Game Boy Programming Manual
Note The following data will be stored in Game Boy Memory for all Game Boy
software.
0100H = 00H
0101H = C3H
014BH = 33H
0104H~0133H = “Nintendo” character data
288
Appendix 3: Software Submission Requirements
289
Game Boy Programming Manual
CGB Incompatible: A program which does not use CGB functions, but
operates with both CGB and DMG (Monochrome).
CGB Compatible: A program which uses CGB functions, and operates with
both CGB and DMG.
CGB Exclusive: A program which uses CGB functions, but will only operate
on a Game Boy Color unit (not on DMG/MGB). If a user
attempts to play this software on Game Boy, a screen must
be displayed telling the user that the game must be played
on Game Boy Color.
6. Maker Code (0144H, 0145H)
Enter the 2-digit ASCII code assigned by Nintendo. Contact Product Testing, if in doubt.
All letters must be in upper case. For example;
If Maker Code is 01, the ASCII code for 0 (30H) is stored at 0144H and the
ASCII code for 1 (31H) is stored at 0145H.
If Maker Code is FF, the ASCII code for F (46H) is stored at 0144H and
0145H.
Note In order to use Super Game Boy functions, the following data must be
registered.
290
Appendix 3: Software Submission Requirements
Parts Configuration
Address MBC-3 MBC5 Backup
0147H Battery
ROM MBC-1 MBC-2 SRAM
W/ No No W/
RTC RTC Rumble Rumble
00H X
01H X X
02H X X X
03H X X X X
04H
05H X X
06H X X X
07H
08H X X
09H X X X
0FH X X X
10H X X X X
11H X X
12H X X X
13H X X X X
19H X X
1AH X X X
1BH X X X X
19H X X
1AH X X X
1BH X X X X
291
Game Boy Programming Manual
292
Appendix 3: Software Submission Requirements
293
Game Boy Programming Manual
None None
: Board Available
If a price quote is necessary, please submit a "Game Boy Price Quote Request Form" to NOA Licensing Dept.
: Board Not Available
If required, please submit a "Game Boy Price Quote Request Form" to NOA Licensing Dept., approximately 5 months
before scheduled software submission.
( ) : At the present time, a mask ROM cannot be prepared. If necessary, please contact NOA Licensing Dept.
[Notes] MBC-1, 2, and 3 do not support Game Boy Color double-speed mode (including H-DMA and General Purpose DMA. Please refer to your Programming Manual.
*1 There are some restrictions in memory mapping when MBC-1 ROM Size is 8M or larger. Please refer to "Memory Controllers" in your Programming Manual.
*2 For MBC-5 with ROM of 1M or less, a mask ROM supporting CGB double-speed mode can not be prepared. Double-speed mode is supported by ROM of 2M or larger.
294
Appendix 3: Software Submission Requirements
None None 1
None 2 3
MBC-1 4 • Built-in 64K SRAM
With or without backup battery
64K/None 5 6
256K/64K/None • Built-in 256K SRAM
7 With or without backup battery
MBC-2 None 8
MBC-3 256K/64K/None • RTC Function
9 • Built-in 256K SRAM
With or without backup battery
3 MBC1-1M to 2M-EPROM E200233 EPROM : 27C101/27C2001 (Can use 301 type) (*3)
8 MBC2-1M to 2M-EPROM E200258 EPROM : 27C101/27C2001 (Can use 301 type) (*3)
295
Game Boy Programming Manual
[Notes] MBC-1, 2, and 3 do not support Game Boy Color double-speed mode (including H-DMA and General Purpose DMA. Please refer to your Programming Manual.
There are some restrictions in memory mapping when MBC-1 ROM size is 1M or larger. Please refer to "Memory Controllers" in your Programming Manual.
*1 : When ordering, please indicate both the board name and product code to NOA Licensing Dept.
*2 : For the EPROM specification, please use the described specification, above, or something with the same pin configuration.
*3 : Can support both types for land switching on the board.
296
Appendix 3: Software Submission Requirements
297
Game Boy Programming Manual
298