Skip to content

Commit 98729d0

Browse files
authored
Add MBC3-specific registers and values (#27)
Also some minor cleanup nearby required modifications
1 parent 8124cf4 commit 98729d0

File tree

1 file changed

+92
-24
lines changed

1 file changed

+92
-24
lines changed

hardware.inc

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
;* Rev 4.3 - 07-Nov-21 : Deprecate VRAM address constants (Eievui)
3232
;* Rev 4.4 - 11-Jan-22 : Deprecate VRAM CART_SRAM_2KB constant (avivace)
3333
;* Rev 4.5 - 03-Mar-22 : Added bit number definitions for OCPS, BCPS and LCDC (sukus)
34+
;* Rev 4.6 - 15-Jun-22 : Added MBC3 registers and special values
3435

3536
IF __RGBDS_MAJOR__ == 0 && __RGBDS_MINOR__ < 5
3637
FAIL "This version of 'hardware.inc' requires RGBDS version 0.5.0 or later."
@@ -44,11 +45,18 @@ DEF HARDWARE_INC EQU 1
4445
MACRO rev_Check_hardware_inc
4546
;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
4647
;TO SECOND PARAMETER IN FOLLOWING LINE.
47-
IF \1 > 4.5 ;PUT REVISION NUMBER HERE
48+
IF \1 > 4.6 ;PUT REVISION NUMBER HERE
4849
WARN "Version \1 or later of 'hardware.inc' is required."
4950
ENDC
5051
ENDM
5152

53+
54+
;***************************************************************************
55+
;*
56+
;* General memory region constants
57+
;*
58+
;***************************************************************************
59+
5260
DEF _VRAM EQU $8000 ; $8000->$9FFF
5361
DEF _SCRN0 EQU $9800 ; $9800->$9BFF
5462
DEF _SCRN1 EQU $9C00 ; $9C00->$9FFF
@@ -60,17 +68,80 @@ DEF _IO EQU $FF00 ; $FF00->$FF7F,$FFFF
6068
DEF _AUD3WAVERAM EQU $FF30 ; $FF30->$FF3F
6169
DEF _HRAM EQU $FF80 ; $FF80->$FFFE
6270

63-
; *** MBC5 Equates ***
6471

65-
DEF rRAMG EQU $0000 ; $0000->$1fff
66-
DEF rROMB0 EQU $2000 ; $2000->$2fff
67-
DEF rROMB1 EQU $3000 ; $3000->$3fff - If more than 256 ROM banks are present.
68-
DEF rRAMB EQU $4000 ; $4000->$5fff - Bit 3 enables rumble (if present)
72+
;***************************************************************************
73+
;*
74+
;* MBC registers
75+
;*
76+
;***************************************************************************
77+
78+
; *** Common ***
79+
80+
; --
81+
; -- RAMG ($0000-$1FFF)
82+
; -- Controls whether access to SRAM (and the MBC3 RTC registers) is allowed (W)
83+
; --
84+
DEF rRAMG EQU $0000
85+
86+
DEF CART_SRAM_ENABLE EQU $0A
87+
DEF CART_SRAM_DISABLE EQU $00
88+
89+
90+
; --
91+
; -- ROMB0 ($2000-$3FFF)
92+
; -- Selects which ROM bank is mapped to the ROMX space ($4000-$7FFF) (W)
93+
; --
94+
; -- The range of accepted values, as well as the behavior of writing $00,
95+
; -- varies depending on the MBC.
96+
; --
97+
DEF rROMB0 EQU $2000
98+
99+
; --
100+
; -- RAMB ($4000-$5FFF)
101+
; -- Selects which SRAM bank is mapped to the SRAM space ($A000-$BFFF) (W)
102+
; --
103+
; -- The range of accepted values varies depending on the cartridge configuration.
104+
; --
105+
DEF rRAMB EQU $4000
106+
107+
108+
; *** MBC3-specific registers ***
109+
110+
; Write one of these to rRAMG to map the corresponding RTC register to all SRAM space
111+
DEF RTC_S EQU $08 ; Seconds (0-59)
112+
DEF RTC_M EQU $09 ; Minutes (0-59)
113+
DEF RTC_H EQU $0A ; Hours (0-23)
114+
DEF RTC_DL EQU $0B ; Lower 8 bits of Day Counter ($00-$FF)
115+
DEF RTC_DH EQU $0C ; Bit 7 - Day Counter Carry Bit (1=Counter Overflow)
116+
; Bit 6 - Halt (0=Active, 1=Stop Timer)
117+
; Bit 0 - Most significant bit of Day Counter (Bit 8)
118+
119+
120+
; --
121+
; -- RTCLATCH ($6000-$7FFF)
122+
; -- Write $00 then $01 to latch the current time into the RTC registers (W)
123+
; --
124+
DEF rRTCLATCH EQU $6000
125+
126+
127+
; *** MBC5-specific register ***
128+
129+
; --
130+
; -- ROMB1 ($3000-$3FFF)
131+
; -- A 9th bit that "extends" ROMB0 if more than 256 banks are present (W)
132+
; --
133+
; -- Also note that rROMB0 thus only spans $2000-$2FFF.
134+
; --
135+
DEF rROMB1 EQU $3000
136+
137+
138+
; Bit 3 of RAMB enables the rumble motor (if any)
139+
DEF CART_RUMBLE_ON EQU 1 << 3
69140

70141

71142
;***************************************************************************
72143
;*
73-
;* Custom registers
144+
;* Memory-mapped registers
74145
;*
75146
;***************************************************************************
76147

@@ -105,9 +176,9 @@ DEF rSB EQU $FF01
105176
; --
106177
DEF rSC EQU $FF02
107178

108-
DEF SCF_START EQU %10000000 ;Transfer Start Flag (1=Transfer in progress, or requested)
109-
DEF SCF_SPEED EQU %00000010 ;Clock Speed (0=Normal, 1=Fast) ** CGB Mode Only **
110-
DEF SCF_SOURCE EQU %00000001 ;Shift Clock (0=External Clock, 1=Internal Clock)
179+
DEF SCF_START EQU %10000000 ; Transfer Start Flag (1=Transfer in progress, or requested)
180+
DEF SCF_SPEED EQU %00000010 ; Clock Speed (0=Normal, 1=Fast) ** CGB Mode Only **
181+
DEF SCF_SOURCE EQU %00000001 ; Shift Clock (0=External Clock, 1=Internal Clock)
111182

112183
DEF SCB_START EQU 7
113184
DEF SCB_SPEED EQU 1
@@ -803,10 +874,20 @@ DEF BOOTUP_B_AGB EQU %00000001 ; GBA, GBA SP, Game Boy Player, or New GBA S
803874

804875
;***************************************************************************
805876
;*
806-
;* Cart related
877+
;* Header
807878
;*
808879
;***************************************************************************
809880

881+
;*
882+
;* Nintendo scrolling logo
883+
;* (Code won't work on a real GameBoy)
884+
;* (if next lines are altered.)
885+
MACRO NINTENDO_LOGO
886+
DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
887+
DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
888+
DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
889+
ENDM
890+
810891
; $0143 Color GameBoy compatibility code
811892
DEF CART_COMPATIBLE_DMG EQU $00
812893
DEF CART_COMPATIBLE_DMG_GBC EQU $80
@@ -867,9 +948,6 @@ DEF CART_SRAM_8KB EQU 2 ; 1 bank
867948
DEF CART_SRAM_32KB EQU 3 ; 4 banks
868949
DEF CART_SRAM_128KB EQU 4 ; 16 banks
869950

870-
DEF CART_SRAM_ENABLE EQU $0A
871-
DEF CART_SRAM_DISABLE EQU $00
872-
873951
; $014A Destination code
874952
DEF CART_DEST_JAPANESE EQU $00
875953
DEF CART_DEST_NON_JAPANESE EQU $01
@@ -955,16 +1033,6 @@ DEF OAMB_PAL1 EQU 4 ; Palette number; 0,1 (DMG)
9551033
DEF OAMB_BANK1 EQU 3 ; Bank number; 0,1 (GBC)
9561034

9571035

958-
;*
959-
;* Nintendo scrolling logo
960-
;* (Code won't work on a real GameBoy)
961-
;* (if next lines are altered.)
962-
MACRO NINTENDO_LOGO
963-
DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
964-
DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
965-
DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
966-
ENDM
967-
9681036
; Deprecated constants. Please avoid using.
9691037

9701038
DEF IEF_LCDC EQU %00000010 ; LCDC (see STAT)

0 commit comments

Comments
 (0)