Skip to content

Commit

Permalink
Correct bits of JOYP involved in sending SGB packets (#547)
Browse files Browse the repository at this point in the history
Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
  • Loading branch information
Zarithya and ISSOtm committed Mar 20, 2024
1 parent 97593b5 commit 5dbce5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/SGB_Command_Packet.md
@@ -1,16 +1,17 @@
# Command Packet Transfers

Command packets are transferred from the Game Boy to the SNES by using bits 6 and 7 of of [the `JOYP` register][JOYP].
Command packets are transferred from the Game Boy to the SNES by using bits 4 and 5 of of [the `JOYP` register][JOYP].
These lines are normally used to select one of the two button groups (which [still works as usual][JOYP]).

## Transferring Bits

A command packet transfer must be initiated by setting [`JOYP`][JOYP] bits 6 and 7 both to 0; this will reset and start the ICD2 packet receiving circuit.
Data is then transferred (LSB first), setting bit 6 to 0 will indicate a `0` bit, and setting bit 7 to 0 will indicate a `1` bit.
A command packet transfer must be initiated by setting [`JOYP`][JOYP] bits 4 and 5 both to 0; this will reset and start the ICD2 packet receiving circuit.
Data is then transferred (LSB first), setting bit 4 to 0 will indicate a `0` bit, and setting bit 5 to 0 will indicate a `1` bit.
For example:

{{#include imgs/sgb_bits.svg}}

[The boot ROM](<#Super Game Boy (SGB, SGB2)>) and licensed software keep data and reset pulses LOW for at least 5 M-cycles and leave bit 6 and 7 both to 1 for at least 15 M-cycles after each pulse.
[The boot ROM](<#Super Game Boy (SGB, SGB2)>) and licensed software keep data and reset pulses LOW for at least 5 M-cycles and leave bit 4 and 5 both to 1 for at least 15 M-cycles after each pulse.
Though the hardware is capable of receiving pulses and spaces as short as 2 M-cycles (as tested using [sgb-speedtest]), following the common practice of 5 M-cycle pulses and 15 M-cycle spaces may improve reliability in some corner case that the community has not yet discovered.

:::tip
Expand Down
4 changes: 2 additions & 2 deletions src/imgs/sgb_bits.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5dbce5b

Please sign in to comment.