Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- name: Test hardware_compat.inc
run: |
rgbasm -P hardware.inc hardware_compat.inc
- name: Test sgb.inc
run: |
rgbasm sgb.inc

windows-testing:
runs-on: windows-latest
Expand Down
257 changes: 257 additions & 0 deletions sgb.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
;******************************************************************************
; Super Game Boy command constant definitions
; https://github.com/gbdev/hardware.inc
;******************************************************************************

; To the extent possible under law, the authors of this work have
; waived all copyright and related or neighboring rights to the work.
; See https://creativecommons.org/publicdomain/zero/1.0/ for details.
; SPDX-License-Identifier: CC0-1.0

; If this file was already included, don't do it again
if !def(SGB_INC)

; Define the include guard
def SGB_INC equ 1


;******************************************************************************
; SGB packet constants
;******************************************************************************

def SGB_PACKET_SIZE equ 16


;******************************************************************************
; SGB command prefixes
;******************************************************************************

def SGB_HEADER_COMMAND equ %11111000
def SGB_HEADER_LENGTH equ %00000111

def S_SGB_COMMAND equ 3

def SGB_PAL01 equ $00 << S_SGB_COMMAND
def SGB_PAL23 equ $01 << S_SGB_COMMAND
def SGB_PAL03 equ $02 << S_SGB_COMMAND
def SGB_PAL12 equ $03 << S_SGB_COMMAND
def SGB_ATTR_BLK equ $04 << S_SGB_COMMAND
def SGB_ATTR_LIN equ $05 << S_SGB_COMMAND
def SGB_ATTR_DIV equ $06 << S_SGB_COMMAND
def SGB_ATTR_CHR equ $07 << S_SGB_COMMAND
def SGB_SOUND equ $08 << S_SGB_COMMAND
def SGB_SOU_TRN equ $09 << S_SGB_COMMAND
def SGB_PAL_SET equ $0A << S_SGB_COMMAND
def SGB_PAL_TRN equ $0B << S_SGB_COMMAND
def SGB_ATRC_EN equ $0C << S_SGB_COMMAND
def SGB_TEST_EN equ $0D << S_SGB_COMMAND
def SGB_ICON_EN equ $0E << S_SGB_COMMAND
def SGB_DATA_SND equ $0F << S_SGB_COMMAND
def SGB_DATA_TRN equ $10 << S_SGB_COMMAND
def SGB_MLT_REQ equ $11 << S_SGB_COMMAND
def SGB_JUMP equ $12 << S_SGB_COMMAND
def SGB_CHR_TRN equ $13 << S_SGB_COMMAND
def SGB_PCT_TRN equ $14 << S_SGB_COMMAND
def SGB_ATTR_TRN equ $15 << S_SGB_COMMAND
def SGB_ATTR_SET equ $16 << S_SGB_COMMAND
def SGB_MASK_EN equ $17 << S_SGB_COMMAND
def SGB_OBJ_TRN equ $18 << S_SGB_COMMAND
def SGB_PAL_PRI equ $19 << S_SGB_COMMAND
def SGB_STUB1 equ $1A << S_SGB_COMMAND
def SGB_STUB2 equ $1B << S_SGB_COMMAND
def SGB_STUB3 equ $1C << S_SGB_COMMAND
def SGB_STUB4 equ $1D << S_SGB_COMMAND
def SGB_STUB5 equ $1E << S_SGB_COMMAND
def SGB_STUB6 equ $1F << S_SGB_COMMAND


;******************************************************************************
; SGB command-related values
;******************************************************************************

; -- SGB_PAL01 ($00) ----------------------------------------------------------

def A_SGB_PAL01_COLOR_0 equ $01 ; $01-$02
def A_SGB_PAL01_PAL_0_COLOR_1 equ $03 ; $03-$04
def A_SGB_PAL01_PAL_0_COLOR_2 equ $05 ; $05-$06
def A_SGB_PAL01_PAL_0_COLOR_3 equ $07 ; $07-$08
def A_SGB_PAL01_PAL_1_COLOR_1 equ $09 ; $09-$0A
def A_SGB_PAL01_PAL_1_COLOR_2 equ $0B ; $0B-$0C
def A_SGB_PAL01_PAL_1_COLOR_3 equ $0D ; $0D-$0E


; -- SGB_PAL23 ($01) ----------------------------------------------------------

def A_SGB_PAL23_COLOR_0 equ $01 ; $01-$02
def A_SGB_PAL23_PAL_2_COLOR_1 equ $03 ; $03-$04
def A_SGB_PAL23_PAL_2_COLOR_2 equ $05 ; $05-$06
def A_SGB_PAL23_PAL_2_COLOR_3 equ $07 ; $07-$08
def A_SGB_PAL23_PAL_3_COLOR_1 equ $09 ; $09-$0A
def A_SGB_PAL23_PAL_3_COLOR_2 equ $0B ; $0B-$0C
def A_SGB_PAL23_PAL_3_COLOR_3 equ $0D ; $0D-$0E


; -- SGB_PAL03 ($02) ----------------------------------------------------------

def A_SGB_PAL03_COLOR_0 equ $01 ; $01-$02
def A_SGB_PAL03_PAL_0_COLOR_1 equ $03 ; $03-$04
def A_SGB_PAL03_PAL_0_COLOR_2 equ $05 ; $05-$06
def A_SGB_PAL03_PAL_0_COLOR_3 equ $07 ; $07-$08
def A_SGB_PAL03_PAL_3_COLOR_1 equ $09 ; $09-$0A
def A_SGB_PAL03_PAL_3_COLOR_2 equ $0B ; $0B-$0C
def A_SGB_PAL03_PAL_3_COLOR_3 equ $0D ; $0D-$0E


; -- SGB_PAL12 ($03) ----------------------------------------------------------

def A_SGB_PAL12_COLOR_0 equ $01 ; $01-$02
def A_SGB_PAL12_PAL_1_COLOR_1 equ $03 ; $03-$04
def A_SGB_PAL12_PAL_1_COLOR_2 equ $05 ; $05-$06
def A_SGB_PAL12_PAL_1_COLOR_3 equ $07 ; $07-$08
def A_SGB_PAL12_PAL_2_COLOR_1 equ $09 ; $09-$0A
def A_SGB_PAL12_PAL_2_COLOR_2 equ $0B ; $0B-$0C
def A_SGB_PAL12_PAL_2_COLOR_3 equ $0D ; $0D-$0E


Comment on lines +114 to +115

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATTR_BLK ($04), ATTR_LIN ($05), ATTR_DIV ($06), and ATTR_CHR ($07) all go in-between here, and have A_* byte offsets (and significant bit/mask values for some of those bytes' meanings) which could be defined here. Same goes for the other command types which aren't yet addressed.

; -- SGB_SOUND ($08) ----------------------------------------------------------

def A_SGB_SOUND_A equ $01
def A_SGB_SOUND_B equ $02
def A_SGB_SOUND_FLAGS equ $03
def A_SGB_SOUND_SCORE equ $04

; A_SGB_SOUND_FLAGS values
def S_SGB_SOUND_A_PITCH equ 0
def SGB_SOUND_A_PITCH_0 equ 0 << S_SGB_SOUND_A_PITCH
def SGB_SOUND_A_PITCH_1 equ 1 << S_SGB_SOUND_A_PITCH
def SGB_SOUND_A_PITCH_2 equ 2 << S_SGB_SOUND_A_PITCH
def SGB_SOUND_A_PITCH_3 equ 3 << S_SGB_SOUND_A_PITCH
def S_SGB_SOUND_A_VOLUME equ 2
def SGB_SOUND_A_VOLUME_HIGH equ 0 << S_SGB_SOUND_A_VOLUME
def SGB_SOUND_A_VOLUME_MED equ 1 << S_SGB_SOUND_A_VOLUME
def SGB_SOUND_A_VOLUME_LOW equ 2 << S_SGB_SOUND_A_VOLUME
def SGB_SOUND_A_VOLUME_OFF equ 3 << S_SGB_SOUND_A_VOLUME
def S_SGB_SOUND_B_PITCH equ 4
def SGB_SOUND_B_PITCH_0 equ 0 << S_SGB_SOUND_B_PITCH
def SGB_SOUND_B_PITCH_1 equ 1 << S_SGB_SOUND_B_PITCH
def SGB_SOUND_B_PITCH_2 equ 2 << S_SGB_SOUND_B_PITCH
def SGB_SOUND_B_PITCH_3 equ 3 << S_SGB_SOUND_B_PITCH
def S_SGB_SOUND_B_VOLUME equ 6
def SGB_SOUND_B_VOLUME_HIGH equ 0 << S_SGB_SOUND_B_VOLUME
def SGB_SOUND_B_VOLUME_MED equ 1 << S_SGB_SOUND_B_VOLUME
def SGB_SOUND_B_VOLUME_LOW equ 2 << S_SGB_SOUND_B_VOLUME

; A_SGB_SOUND_A values
def SGB_SOUND_A_RETRIGGER equ $00
def SGB_SOUND_A_NINTENDO equ $01
def SGB_SOUND_A_GAME_OVER equ $02
def SGB_SOUND_A_DROP equ $03
def SGB_SOUND_A_OK_A equ $04
def SGB_SOUND_A_OK_B equ $05
def SGB_SOUND_A_SELECT_A equ $06
def SGB_SOUND_A_SELECT_B equ $07
def SGB_SOUND_A_SELECT_C equ $08
def SGB_SOUND_A_ERROR equ $09
def SGB_SOUND_A_CATCH equ $0A
def SGB_SOUND_A_KNOCK equ $0B
def SGB_SOUND_EXPLOSION_SMALL equ $0C
def SGB_SOUND_EXPLOSION_MEDIUM equ $0D
def SGB_SOUND_EXPLOSION_LARGE equ $0E
def SGB_SOUND_DEFEAT_A equ $0F
def SGB_SOUND_DEFEAT_B equ $10
def SGB_SOUND_HIT_A equ $11
def SGB_SOUND_HIT_B equ $12
def SGB_SOUND_A_BREATH_IN equ $13
def SGB_SOUND_A_ROCKET_A equ $14
def SGB_SOUND_A_ROCKET_B equ $15
def SGB_SOUND_A_ESCAPING_BUBBLE equ $16
def SGB_SOUND_A_JUMP equ $17
def SGB_SOUND_A_JUMP_FAST equ $18
def SGB_SOUND_A_JET_TAKEOFF equ $19
def SGB_SOUND_A_JET_LANDING equ $1A
def SGB_SOUND_A_CUP_BREAKING equ $1B
def SGB_SOUND_A_GLASS_BREAKING equ $1C
def SGB_SOUND_A_LEVEL_UP equ $1D
def SGB_SOUND_A_INSERT_AIR equ $1E
def SGB_SOUND_A_SWORD_SWING equ $1F
def SGB_SOUND_A_WATER_FALLING equ $20
def SGB_SOUND_A_FIRE equ $21
def SGB_SOUND_A_WALL_COLLAPSING equ $22
def SGB_SOUND_A_CANCEL equ $23
def SGB_SOUND_A_WALKING equ $24
def SGB_SOUND_A_BLOCKING_STRIKE equ $25
def SGB_SOUND_A_PICTURE_FLOATS equ $26
def SGB_SOUND_A_FADE_IN equ $27
def SGB_SOUND_A_FADE_OUT equ $28
def SGB_SOUND_A_WINDOW_OPENING equ $29
def SGB_SOUND_A_WINDOW_CLOSING equ $2A
def SGB_SOUND_A_LASER_BIG equ $2B
def SGB_SOUND_A_STONE_GATE equ $2C
def SGB_SOUND_A_TELEPORTATION equ $2D
def SGB_SOUND_A_LIGHTNING equ $2E
def SGB_SOUND_A_EARTHQUAKE equ $2F
def SGB_SOUND_A_LASER_SMALL equ $30
def SGB_SOUND_A_STOP equ $80

; A_SGB_SOUND_B values
def SGB_SOUND_B_RETRIGGER equ $00
def SGB_SOUND_B_APPLAUSE_SMALL equ $01
def SGB_SOUND_B_APPLAUSE_MED equ $02
def SGB_SOUND_B_APPLAUSE_LARGE equ $03
def SGB_SOUND_B_WIND equ $04
def SGB_SOUND_B_RAIN equ $05
def SGB_SOUND_B_STORM equ $06
def SGB_SOUND_B_STORM_W_THUNDER equ $07
def SGB_SOUND_B_LIGHTNING equ $08
def SGB_SOUND_B_EARTHQUAKE equ $09
def SGB_SOUND_B_AVALANCHE equ $0A
def SGB_SOUND_B_WAVE equ $0B
def SGB_SOUND_B_RIVER equ $0C
def SGB_SOUND_B_WATERFALL equ $0D
def SGB_SOUND_B_RUNNING_SMALL equ $0E
def SGB_SOUND_B_RUNNING_HORSE equ $0F
def SGB_SOUND_B_WARNING equ $10
def SGB_SOUND_B_CAR_APPROACHING equ $11
def SGB_SOUND_B_JET_FLYING equ $12
def SGB_SOUND_B_UFO_FLYING equ $13
def SGB_SOUND_B_ELECTOMAGNETIC equ $14
def SGB_SOUND_B_SCORE_UP equ $15
def SGB_SOUND_B_FIRE equ $16
def SGB_SOUND_B_CAMERA_SHUTTER equ $17
def SGB_SOUND_B_WRITE equ $18
def SGB_SOUND_B_SHOW_UP equ $19
def SGB_SOUND_B_STOP equ $80


; -- SGB_MLT_REQ ($11) --------------------------------------------------------

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not add constants for the original hardware.inc request in #76, covering the MLT_REQ data which can be read from the P1/JOYP register.

We already define some SGB-related constants in hardware.inc itself -- including the B_JOYP_SGB_ONE/ZERO and JOYP_SGB_START/FINISH bits essential to all SGB commands -- so that may be the correct place for them after all?

On the other hand, if multiple SGB command types all reuse the P1 register for reading certain command-specific values (I don't know, haven't read about every single one) then sgb.inc would IMO be the correct place, to avoid bloating hardware.inc's JOYP section with mostly SGB-related content.

@Narishma-gb Narishma-gb Aug 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any command expects to read a return via rJOYP. In case of MLT_REQ, joypad reads are now "signed" with the controller number being polled, but as it is permanent, it's a side effect of the command.
I'd suggest relocating B_JOYP_SGB_ONE, JOYP_SGB_START, ... here, because in order to transfer a packet to the SGB, this file will likely be included since it conveniently has the command definition. Besides, it would be very surprising to check for SGB hardware, and do nothing else with it.


def A_SGB_MLT_REQ_PLAYERS equ $01

; A_SGB_MLT_REQ_PLAYERS values
def SGB_MLT_REQ_PLAYERS_ONE equ $00
def SGB_MLT_REQ_PLAYERS_TWO equ $01
def SGB_MLT_REQ_PLAYERS_FOUR equ $11
Comment on lines +231 to +233

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand https://gbdev.io/pandocs/SGB_Command_Multiplayer.html#sgb-command-11--mlt_req correctly, should these be binary %00, %01, and %11?



; -- SGB_CHR_TRN ($13) --------------------------------------------------------

def A_SGB_CHR_TRN_DEST equ $01

; A_SGB_CHR_TRN_DEST values
def SGB_CHR_TRN_DEST_BG_0 equ $00
def SGB_CHR_TRN_DEST_BG_1 equ $01
def SGB_CHR_TRN_DEST_OBJ_0 equ $02
def SGB_CHR_TRN_DEST_OBJ_1 equ $03


; -- SGB_MASK_EN ($17) --------------------------------------------------------

def A_SGB_MASK_EN_MASK equ $01

; A_SGB_MASK_EN_MASK values
def SGB_MASK_EN_MASK_CANCEL equ $00
def SGB_MASK_EN_MASK_FREEZE equ $01
def SGB_MASK_EN_MASK_BLACK equ $02
def SGB_MASK_EN_MASK_COLOR_0 equ $03

endc ; SGB_INC
Loading