Skip to content

Commit 590a515

Browse files
pinobatchISSOtm
andauthored
Correct SGB packet delay durations (#460)
Co-authored-by: Eldred Habert <[email protected]>
1 parent 3dbab00 commit 590a515

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/SGB_Command_Packet.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,37 @@ Game Boy keyboard matrix (which still works).
88
## Transferring Bits
99

1010
A command packet transfer must be initiated by setting both P14 and P15
11-
to LOW, this will reset and start the SNES packet receiving program.
11+
to LOW; this will reset and start the ICD2 packet receiving circuit.
1212
Data is then transferred (LSB first), setting P14=LOW will indicate a
1313
"0" bit, and setting P15=LOW will indicate a "1" bit. For example:
1414

1515
```
1616
RESET 0 0 1 1 0 1 0
1717
P14 --_---_---_-----------_-------_--...
1818
P15 --_-----------_---_-------_------...
19+
↑ ↑ ↑ ↑
20+
Time 0 50 100 150
1921
```
2022

21-
Data and reset pulses must be kept LOW for at least 5us. P14 and P15
22-
must be kept both HIGH for at least 15us between any pulses. Obviously,
23-
it'd be no good idea to access the JOYPAD register during the transfer,
23+
[The boot ROM](<#Super Game Boy (SGB, SGB2)>) and licensed software keep data and reset pulses LOW for at least 5 μs and leave P14 and P15 HIGH for at least 15 μs after each pulse.
24+
Though the hardware is capable of receiving pulses and spaces as short as 2 μs (as tested using [sgb-speedtest]),
25+
following the common practice of 5-cycle pulses and 15-cycle spaces may improve reliability in some corner case that the community has not yet discovered.
26+
Obviously, it'd be no good idea to access [the joypad register](<#FF00 — P1/JOYP: Joypad>) during the transfer,
2427
for example, in case that your VBlank interrupt procedure reads-out
25-
joypad states each frame, be sure to disable that interrupt during the
28+
joypad states each frame, so be sure to disable that interrupt during the
2629
transfer (or disable only the joypad procedure by using a software
2730
flag).
2831

32+
[sgb-speedtest]: https://github.com/zlago/sgb-speedtest/
33+
2934
## Transferring Packets
3035

3136
Each packet is invoked by a RESET pulse, then 128 bits of data are
3237
transferred (16 bytes, LSB of first byte first), and finally, a
33-
"0" bit must be transferred as stop bit. The structure of normal
34-
packets thus is:
38+
"0" bit must be transferred as a stop bit.
39+
These 130 bit periods correspond to at least 2600 cycles at the recommended rate.
40+
41+
The structure of the first packet in a transmission is:
3542

3643
1. 1 pulse: Start signal
3744
2. 1 byte: Header byte (Command Code \* 8 + Length)
@@ -47,5 +54,6 @@ parameter bytes are used, then further packet(s) will follow, as such:
4754
3. 1 bit: Stop Bit (0)
4855

4956
By using all 7 packets, up to 111 data bytes (15+16\*6) may be sent.
50-
Unused bytes at the end of the last packet don't matter. A 60ms (4
51-
frames) delay should be invoked between each packet transfer.
57+
Unused bytes at the end of the last packet don't matter.
58+
The GB program should wait 60 ms (4 frames) between each packet transfer and the next,
59+
as the "bomb" tool to erase a user-drawn border can cause the SGB system software not to check for packets for 4 frames.

0 commit comments

Comments
 (0)