Skip to content

Commit db8a1c0

Browse files
authored
Add MBC registers, combined PAD masks, and color bits (#63)
* Added registers and constants for more MBCs * Added `PAD_*` constants for combined button and Control Pad masks * Added `B_COLOR_*` red/green/blue bit numbers * Corrected comments on `B_BG_PRIO` and `B_OAM_PRIO`
1 parent 8d4432e commit db8a1c0

File tree

2 files changed

+176
-35
lines changed

2 files changed

+176
-35
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@
9999
- Added `BG_*` constants for CGB-only BG tile attributes
100100
- Added hardware_compat.inc for backwards-compatibility aliases
101101
- Deprecated `rSMBK` alias for `rWBK`/`rSVBK`
102+
- **Rev 5.1.0** - 2025-06-29 *(Rangi42)*
103+
- Added registers and constants for more MBCs
104+
- Added `PAD_*` constants for combined button and Control Pad masks
105+
- Added `B_COLOR_*` red/green/blue bit numbers
106+
- Corrected comments on `B_BG_PRIO` and `B_OAM_PRIO`

hardware.inc

Lines changed: 171 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endc
2222
; Define the include guard and the current hardware.inc version
2323
; (do this after the RGBDS version check since the `def` syntax depends on it)
2424
def HARDWARE_INC equ 1
25-
def HARDWARE_INC_VERSION equs "5.0.0"
25+
def HARDWARE_INC_VERSION equs "5.1.0"
2626

2727
; Usage: rev_Check_hardware_inc <min_ver>
2828
; Examples:
@@ -85,14 +85,17 @@ def B_PAD_START equ 3
8585
def B_PAD_SELECT equ 2
8686
def B_PAD_B equ 1
8787
def B_PAD_A equ 0
88-
def PAD_DOWN equ 1 << B_PAD_DOWN
89-
def PAD_UP equ 1 << B_PAD_UP
90-
def PAD_LEFT equ 1 << B_PAD_LEFT
91-
def PAD_RIGHT equ 1 << B_PAD_RIGHT
92-
def PAD_START equ 1 << B_PAD_START
93-
def PAD_SELECT equ 1 << B_PAD_SELECT
94-
def PAD_B equ 1 << B_PAD_B
95-
def PAD_A equ 1 << B_PAD_A
88+
def PAD_CTRL_PAD equ %1111_0000
89+
def PAD_BUTTONS equ %0000_1111
90+
def PAD_DOWN equ 1 << B_PAD_DOWN
91+
def PAD_UP equ 1 << B_PAD_UP
92+
def PAD_LEFT equ 1 << B_PAD_LEFT
93+
def PAD_RIGHT equ 1 << B_PAD_RIGHT
94+
def PAD_START equ 1 << B_PAD_START
95+
def PAD_SELECT equ 1 << B_PAD_SELECT
96+
def PAD_B equ 1 << B_PAD_B
97+
def PAD_A equ 1 << B_PAD_A
98+
9699

97100
; Combined input byte, with Control Pad in low nybble (swapped order)
98101
def B_PAD_SWAP_START equ 7
@@ -103,14 +106,16 @@ def B_PAD_SWAP_DOWN equ 3
103106
def B_PAD_SWAP_UP equ 2
104107
def B_PAD_SWAP_LEFT equ 1
105108
def B_PAD_SWAP_RIGHT equ 0
106-
def PAD_SWAP_START equ 1 << B_PAD_SWAP_START
107-
def PAD_SWAP_SELECT equ 1 << B_PAD_SWAP_SELECT
108-
def PAD_SWAP_B equ 1 << B_PAD_SWAP_B
109-
def PAD_SWAP_A equ 1 << B_PAD_SWAP_A
110-
def PAD_SWAP_DOWN equ 1 << B_PAD_SWAP_DOWN
111-
def PAD_SWAP_UP equ 1 << B_PAD_SWAP_UP
112-
def PAD_SWAP_LEFT equ 1 << B_PAD_SWAP_LEFT
113-
def PAD_SWAP_RIGHT equ 1 << B_PAD_SWAP_RIGHT
109+
def PAD_SWAP_CTRL_PAD equ %0000_1111
110+
def PAD_SWAP_BUTTONS equ %1111_0000
111+
def PAD_SWAP_START equ 1 << B_PAD_SWAP_START
112+
def PAD_SWAP_SELECT equ 1 << B_PAD_SWAP_SELECT
113+
def PAD_SWAP_B equ 1 << B_PAD_SWAP_B
114+
def PAD_SWAP_A equ 1 << B_PAD_SWAP_A
115+
def PAD_SWAP_DOWN equ 1 << B_PAD_SWAP_DOWN
116+
def PAD_SWAP_UP equ 1 << B_PAD_SWAP_UP
117+
def PAD_SWAP_LEFT equ 1 << B_PAD_SWAP_LEFT
118+
def PAD_SWAP_RIGHT equ 1 << B_PAD_SWAP_RIGHT
114119

115120
; -- SB ($FF01) ---------------------------------------------------------------
116121
; Serial transfer data [r/w]
@@ -723,27 +728,38 @@ def B_IE_VBLANK equ 0 ; 1 = VBlank interrupt is enabled [r/w]
723728
; however, one address for each of these ranges is considered the "canonical" one, and
724729
; these addresses are what's provided here.
725730

731+
732+
; ** Common to most MBCs ******************************************************
733+
726734
; -- RAMG ($0000-$1FFF) -------------------------------------------------------
727735
; Whether SRAM can be accessed [wo]
728736
def rRAMG equ $0000
729737

730-
; Common values
738+
; Common values (not for HuC1 or HuC-3)
731739
def RAMG_SRAM_DISABLE equ $00
732740
def RAMG_SRAM_ENABLE equ $0A ; some MBCs accept any value whose low nybble is $A
733741

734-
; -- ROMB0 ($2000-$3FFF) ------------------------------------------------------
735-
; ROM bank number (low 8 bits when applicable) [wo]
736-
def rROMB0 equ $2000
737-
738-
; -- ROMB1 ($3000-$3FFF) ------------------------------------------------------
739-
; (MBC5 only) ROM bank number high bit (bit 8) [wo]
740-
def rROMB1 equ $3000
742+
; (HuC-3 only) switch SRAM to map cartridge RAM, RTC, or IR
743+
def RAMG_CART_RAM_RO equ $00 ; select cartridge RAM [ro]
744+
def RAMG_CART_RAM equ $0A ; select cartridge RAM [r/w]
745+
def RAMG_RTC_IN equ $0B ; select RTC command/argument [wo]
746+
def RAMG_RTC_IN_CMD equ %0_111_0000 ; command
747+
def RAMG_RTC_IN_ARG equ %0_000_1111 ; argument
748+
def RAMG_RTC_OUT equ $0C ; select RTC command/response [ro]
749+
def RAMG_RTC_OUT_CMD equ %0_111_0000 ; command
750+
def RAMG_RTC_OUT_RESULT equ %0_000_1111 ; result
751+
def RAMG_RTC_SEMAPHORE equ $0D ; select RTC semaphore [r/w]
752+
def RAMG_IR equ $0E ; (HuC1 and HuC-3 only) select IR [r/w]
753+
754+
; -- ROMB ($2000-$3FFF) -------------------------------------------------------
755+
; ROM bank number (not for MBC5 or MBC6) [wo]
756+
def rROMB equ $2000
741757

742758
; -- RAMB ($4000-$5FFF) -------------------------------------------------------
743-
; SRAM bank number [wo]
759+
; SRAM bank number (not for MBC2, MBC6, or MBC7) [wo]
744760
def rRAMB equ $4000
745761

746-
; (MBC3-only) Special RAM bank numbers that actually map values into RTCREG
762+
; (MBC3 only) Special RAM bank numbers that actually map values into RTCREG
747763
def RAMB_RTC_S equ $08 ; seconds counter (0-59)
748764
def RAMB_RTC_M equ $09 ; minutes counter (0-59)
749765
def RAMB_RTC_H equ $0A ; hours counter (0-23)
@@ -761,19 +777,136 @@ def B_RAMB_RUMBLE equ 3 ; (MBC5 and MBC7 only) enable the rumble motor (if any)
761777
def RAMB_RUMBLE_OFF equ 0 << B_RAMB_RUMBLE
762778
def RAMB_RUMBLE_ON equ 1 << B_RAMB_RUMBLE
763779

780+
781+
; ** MBC1 and MMM01 only ******************************************************
782+
783+
; -- BMODE ($6000-$7FFF) ------------------------------------------------------
784+
; Banking mode select [wo]
785+
def rBMODE equ $6000
786+
787+
def BMODE_SIMPLE equ $00 ; locks ROMB and RAMB to bank 0
788+
def BMODE_ADVANCED equ $01 ; allows bank-switching with RAMB
789+
790+
791+
; ** MBC2 only ****************************************************************
792+
793+
; -- ROM2B ($0000-$3FFF with bit 8 set) ---------------------------------------
794+
; ROM bank number [wo]
795+
def rROM2B equ $2100
796+
797+
798+
; ** MBC3 only ****************************************************************
799+
764800
; -- RTCLATCH ($6000-$7FFF) ---------------------------------------------------
765-
; (MBC3 only) RTC latch clock data [wo]
801+
; RTC latch clock data [wo]
766802
def rRTCLATCH equ $6000
767803

768804
; Write $00 then $01 to latch the current time into RTCREG
769805
def RTCLATCH_START equ $00
770806
def RTCLATCH_FINISH equ $01
771807

772808
; -- RTCREG ($A000-$BFFF) -----------------------------------------------------
773-
; (MBC3 only) RTC register [r/w]
809+
; RTC register [r/w]
774810
def rRTCREG equ $A000
775811

776812

813+
; ** MBC5 only ****************************************************************
814+
815+
; -- ROMB0 ($2000-$3FFF) ------------------------------------------------------
816+
; ROM bank number low byte (bits 0-7) [wo]
817+
def rROMB0 equ $2000
818+
819+
; -- ROMB1 ($3000-$3FFF) ------------------------------------------------------
820+
; ROM bank number high bit (bit 8) [wo]
821+
def rROMB1 equ $3000
822+
823+
824+
; ** MBC6 only ****************************************************************
825+
826+
; -- RAMBA ($0400-$07FF) ------------------------------------------------------
827+
; RAM bank A number [wo]
828+
def rRAMBA equ $0400
829+
830+
; -- RAMBB ($0800-$0BFF) ------------------------------------------------------
831+
; RAM bank B number [wo]
832+
def rRAMBB equ $0800
833+
834+
; -- FLASH ($0C00-$0FFF) ------------------------------------------------------
835+
; Whether the flash chip can be accessed [wo]
836+
def rFLASH equ $0C00
837+
838+
; -- FMODE ($1000) ------------------------------------------------------------
839+
; Write mode select for the flash chip
840+
def rFMODE equ $1000
841+
842+
; -- ROMBA ($2000-$27FF) ------------------------------------------------------
843+
; ROM/Flash bank A number [wo]
844+
def rROMBA equ $2000
845+
846+
; -- FLASHA ($2800-$2FFF) -----------------------------------------------------
847+
; ROM/Flash bank A select [wo]
848+
def rFLASHA equ $2800
849+
850+
; -- ROMBB ($3000-$37FF) ------------------------------------------------------
851+
; ROM/Flash bank B number [wo]
852+
def rROMBB equ $3000
853+
854+
; -- FLASHB ($3800-$3FFF) -----------------------------------------------------
855+
; ROM/Flash bank B select [wo]
856+
def rFLASHB equ $3800
857+
858+
859+
; ** MBC7 only ****************************************************************
860+
861+
; -- RAMREG ($4000-$5FFF) -----------------------------------------------------
862+
; Enable RAM register access [wo]
863+
def rRAMREG equ $4000
864+
865+
def RAMREG_ENABLE equ $40
866+
867+
; -- ACCLATCH0 ($Ax0x) --------------------------------------------------------
868+
; Latch accelerometer start [wo]
869+
def rACCLATCH0 equ $A000
870+
871+
def ACCLATCH0_START equ $55
872+
873+
; -- ACCLATCH1 ($Ax1x) --------------------------------------------------------
874+
; Latch accelerometer finish [wo]
875+
def rACCLATCH1 equ $A010
876+
877+
def ACCLATCH1_FINISH equ $AA
878+
879+
; -- ACCELX0 ($Ax2x) ----------------------------------------------------------
880+
; Accelerometer X value low byte [ro]
881+
def rACCELX0 equ $A020
882+
883+
; -- ACCELX1 ($Ax3x) ----------------------------------------------------------
884+
; Accelerometer X value high byte [ro]
885+
def rACCELX1 equ $A030
886+
887+
; -- ACCELY0 ($Ax4x) ----------------------------------------------------------
888+
; Accelerometer Y value low byte [ro]
889+
def rACCELY0 equ $A040
890+
891+
; -- ACCELY1 ($Ax5x) ----------------------------------------------------------
892+
; Accelerometer Y value high byte [ro]
893+
def rACCELY1 equ $A050
894+
895+
; -- EEPROM ($Ax8x) -----------------------------------------------------------
896+
; EEPROM access [r/w]
897+
def rEEPROM equ $A080
898+
899+
900+
; ** HuC1 only ****************************************************************
901+
902+
; -- IRREG ($A000-$BFFF) ------------------------------------------------------
903+
; IR register [r/w]
904+
def rIRREG equ $A000
905+
906+
def IR_LED_OFF equ $C0
907+
def IR_LED_ON equ $C1
908+
909+
777910
;******************************************************************************
778911
; Screen-related constants
779912
;******************************************************************************
@@ -795,10 +928,13 @@ def TILE_HEIGHT equ 8 ; height of tile in pixels
795928
def TILE_SIZE equ 16 ; size of tile in bytes (2 bits/pixel)
796929

797930
def COLOR_SIZE equ 2 ; size of color in bytes (little-endian BGR555)
798-
def COLOR_GREEN_LOW equ %111_00000 ; for the low byte
799-
def COLOR_RED equ %000_11111 ; for the low byte
800-
def COLOR_BLUE equ %0_11111_00 ; for the high byte
801-
def COLOR_GREEN_HIGH equ %000000_11 ; for the high byte
931+
def B_COLOR_RED equ 0 ; bits 4-0
932+
def B_COLOR_GREEN equ 5 ; bits 9-5
933+
def B_COLOR_BLUE equ 10 ; bits 14-10
934+
def COLOR_RED equ %000_11111 ; for the low byte
935+
def COLOR_GREEN_LOW equ %111_00000 ; for the low byte
936+
def COLOR_GREEN_HIGH equ %0_00000_11 ; for the high byte
937+
def COLOR_BLUE equ %0_11111_00 ; for the high byte
802938
def PAL_COLORS equ 4 ; colors per palette
803939
def PAL_SIZE equ COLOR_SIZE * PAL_COLORS ; size of palette in bytes
804940

@@ -807,7 +943,7 @@ def TILEMAP0 equ $9800 ; $9800-$9BFF
807943
def TILEMAP1 equ $9C00 ; $9C00-$9FFF
808944

809945
; (CGB only) BG tile attribute fields
810-
def B_BG_PRIO equ 7 ; whether the BG tile colors 1-3 are drawn below OBJs
946+
def B_BG_PRIO equ 7 ; whether the BG tile colors 1-3 are drawn above OBJs
811947
def B_BG_YFLIP equ 6 ; whether the whole BG tile is flipped vertically
812948
def B_BG_XFLIP equ 5 ; whether the whole BG tile is flipped horizontally
813949
def B_BG_BANK1 equ 3 ; which VRAM bank the BG tile is taken from
@@ -831,7 +967,7 @@ def OAMA_X rb ; 1
831967
def OAM_X_OFS equ 8 ; subtract 8 from what's written to OAM to get the real X position
832968
def OAMA_TILEID rb ; 2
833969
def OAMA_FLAGS rb ; 3
834-
def B_OAM_PRIO equ 7 ; whether the OBJ is drawn above BG colors 1-3
970+
def B_OAM_PRIO equ 7 ; whether the OBJ is drawn below BG colors 1-3
835971
def B_OAM_YFLIP equ 6 ; whether the whole OBJ is flipped vertically
836972
def B_OAM_XFLIP equ 5 ; whether the whole OBJ is flipped horizontally
837973
def B_OAM_PAL1 equ 4 ; (DMG only) which of the two palettes the OBJ uses

0 commit comments

Comments
 (0)