From fd86bcaa06fd81911e88eb6d0253715ad79866a8 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 22 Jul 2025 08:59:51 -0400 Subject: Update hardware.inc to 5.2.0 --- constants/hardware.inc | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'constants/hardware.inc') diff --git a/constants/hardware.inc b/constants/hardware.inc index 628b6820..e77034fe 100644 --- a/constants/hardware.inc +++ b/constants/hardware.inc @@ -22,7 +22,7 @@ endc ; Define the include guard and the current hardware.inc version ; (do this after the RGBDS version check since the `def` syntax depends on it) def HARDWARE_INC equ 1 -def HARDWARE_INC_VERSION equs "5.1.0" +def HARDWARE_INC_VERSION equs "5.2.0" ; Usage: rev_Check_hardware_inc ; Examples: @@ -66,7 +66,7 @@ def B_JOYP_DOWN equ 3 ; 0 = Down is pressed (if reading Control Pad) [ro] def B_JOYP_UP equ 2 ; 0 = Up is pressed (if reading Control Pad) [ro] def B_JOYP_LEFT equ 1 ; 0 = Left is pressed (if reading Control Pad) [ro] def B_JOYP_RIGHT equ 0 ; 0 = Right is pressed (if reading Control Pad) [ro] - def JOYP_INPUTS equ %0000_1111 + def JOYP_INPUTS equ %0000_1111 ; bits equal to 0 indicate pressed (when reading inputs) def JOYP_START equ 1 << B_JOYP_START def JOYP_SELECT equ 1 << B_JOYP_SELECT def JOYP_B equ 1 << B_JOYP_B @@ -422,8 +422,6 @@ def B_AUDENA_ENABLE_CH1 equ 0 ; 1 = channel 1 is running [ro] ; -- AUD3WAVE ($FF30-$FF3F) --------------------------------------------------- ; Audio channel 3 wave pattern RAM [r/w] -def _AUD3WAVERAM equ $FF30 ; $FF30-$FF3F - def rAUD3WAVE_0 equ $FF30 def rAUD3WAVE_1 equ $FF31 def rAUD3WAVE_2 equ $FF32 @@ -441,8 +439,6 @@ def rAUD3WAVE_D equ $FF3D def rAUD3WAVE_E equ $FF3E def rAUD3WAVE_F equ $FF3F -def AUD3WAVE_SIZE equ 16 - ; -- LCDC ($FF40) ------------------------------------------------------------- ; PPU graphics control def rLCDC equ $FF40 @@ -551,7 +547,7 @@ def rWY equ $FF4A ; X coordinate of the Window's top-left pixel, plus 7 (7-166) [r/w] def rWX equ $FF4B -def WX_OFS equ 7 ; subtract this to get the actual Window Y coordinate +def WX_OFS equ 7 ; subtract this to get the actual Window X coordinate ; -- SYS / KEY0 ($FF4C) ------------------------------------------------------- ; (CGB boot ROM only) CPU mode select @@ -606,7 +602,7 @@ def rVDMA_SRC_LOW equ $FF52 ; (CGB only) VRAM DMA destination address (high 8 bits) [wo] def rVDMA_DEST_HIGH equ $FF53 -; -- VDMA_DEST_LOW / HDMA3 ($FF54) -------------------------------------------- +; -- VDMA_DEST_LOW / HDMA4 ($FF54) -------------------------------------------- ; (CGB only) VRAM DMA destination address (low 8 bits) [wo] def rVDMA_DEST_LOW equ $FF54 @@ -812,7 +808,7 @@ def rRTCREG equ $A000 ; ** MBC5 only **************************************************************** -; -- ROMB0 ($2000-$3FFF) ------------------------------------------------------ +; -- ROMB0 ($2000-$2FFF) ------------------------------------------------------ ; ROM bank number low byte (bits 0-7) [wo] def rROMB0 equ $2000 @@ -868,12 +864,14 @@ def RAMREG_ENABLE equ $40 ; Latch accelerometer start [wo] def rACCLATCH0 equ $A000 +; Write $55 to ACCLATCH0 to erase the latched data def ACCLATCH0_START equ $55 ; -- ACCLATCH1 ($Ax1x) -------------------------------------------------------- ; Latch accelerometer finish [wo] def rACCLATCH1 equ $A010 +; Write $AA to ACCLATCH1 to latch the accelerometer and update ACCEL* def ACCLATCH1_FINISH equ $AA ; -- ACCELX0 ($Ax2x) ---------------------------------------------------------- @@ -903,6 +901,7 @@ def rEEPROM equ $A080 ; IR register [r/w] def rIRREG equ $A000 +; whether the IR transmitter sees light def IR_LED_OFF equ $C0 def IR_LED_ON equ $C1 @@ -938,6 +937,12 @@ def COLOR_SIZE equ 2 ; size of color in bytes (little-endian BGR555) def PAL_COLORS equ 4 ; colors per palette def PAL_SIZE equ COLOR_SIZE * PAL_COLORS ; size of palette in bytes +; (DMG only) grayscale shade indexes for BGP, OBP0, and OBP1 +def SHADE_WHITE equ %00 +def SHADE_LIGHT equ %01 +def SHADE_DARK equ %10 +def SHADE_BLACK equ %11 + ; Tilemaps the BG or Window can read from (controlled by LCDC) def TILEMAP0 equ $9800 ; $9800-$9BFF def TILEMAP1 equ $9C00 ; $9C00-$9FFF @@ -986,6 +991,20 @@ def OAM_COUNT equ 40 ; how many OBJs there are room for in OAM def OAM_SIZE equ OBJ_SIZE * OAM_COUNT +;****************************************************************************** +; Audio channel RAM addresses +;****************************************************************************** + +def AUD1RAM equ $FF10 ; $FF10-$FF14 +def AUD2RAM equ $FF15 ; $FF15-$FF19 +def AUD3RAM equ $FF1A ; $FF1A-$FF1E +def AUD4RAM equ $FF1F ; $FF1F-$FF23 +def AUDRAM_SIZE equ 5 ; size of each audio channel RAM in bytes + +def _AUD3WAVERAM equ $FF30 ; $FF30-$FF3F +def AUD3WAVE_SIZE equ 16 ; size of wave pattern RAM in bytes + + ;****************************************************************************** ; Interrupt vector addresses ;****************************************************************************** -- cgit v1.3.1-sl0p From bdbc8cbd48765cf287a524bea5ae2323772cc1c8 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 11 Aug 2025 15:43:27 -0400 Subject: Update hardware.inc to 5.3.0 and use its `JOYP_SGB_*` constants --- constants/hardware.inc | 46 ++++++++++++++++++++++++++++++++++++---------- engine/gfx/palettes.asm | 28 ++++++++++++++-------------- 2 files changed, 50 insertions(+), 24 deletions(-) (limited to 'constants/hardware.inc') diff --git a/constants/hardware.inc b/constants/hardware.inc index e77034fe..e1e3b2cc 100644 --- a/constants/hardware.inc +++ b/constants/hardware.inc @@ -22,7 +22,7 @@ endc ; Define the include guard and the current hardware.inc version ; (do this after the RGBDS version check since the `def` syntax depends on it) def HARDWARE_INC equ 1 -def HARDWARE_INC_VERSION equs "5.2.0" +def HARDWARE_INC_VERSION equs "5.3.0" ; Usage: rev_Check_hardware_inc ; Examples: @@ -76,6 +76,14 @@ def B_JOYP_RIGHT equ 0 ; 0 = Right is pressed (if reading Control Pad) [ro] def JOYP_LEFT equ 1 << B_JOYP_LEFT def JOYP_RIGHT equ 1 << B_JOYP_RIGHT +; SGB command packet transfer uses for JOYP bits +def B_JOYP_SGB_ONE equ 5 ; 0 = sending 1 bit +def B_JOYP_SGB_ZERO equ 4 ; 0 = sending 0 bit + def JOYP_SGB_START equ %00_00_0000 ; start SGB packet transfer + def JOYP_SGB_ONE equ %00_01_0000 ; send 1 bit + def JOYP_SGB_ZERO equ %00_10_0000 ; send 0 bit + def JOYP_SGB_FINISH equ %00_11_0000 ; finish SGB packet transfer + ; Combined input byte, with Control Pad in high nybble (conventional order) def B_PAD_DOWN equ 7 def B_PAD_UP equ 6 @@ -96,7 +104,6 @@ def B_PAD_A equ 0 def PAD_B equ 1 << B_PAD_B def PAD_A equ 1 << B_PAD_A - ; Combined input byte, with Control Pad in low nybble (swapped order) def B_PAD_SWAP_START equ 7 def B_PAD_SWAP_SELECT equ 6 @@ -222,7 +229,7 @@ def AUD1ENV_PACE equ %00000_111 ; how long between envelope iterations ; (in 64 Hz ticks, ~15.6 ms apart) [r/w] ; -- AUD1LOW / NR13 ($FF13) --------------------------------------------------- -; Audio channel 1 period (low 8 bits) [r/w] +; Audio channel 1 period (low 8 bits) [wo] def rAUD1LOW equ $FF13 ; -- AUD1HIGH / NR14 ($FF14) -------------------------------------------------- @@ -266,7 +273,7 @@ def AUD2ENV_PACE equ %00000_111 ; how long between envelope iterations ; (in 64 Hz ticks, ~15.6 ms apart) [r/w] ; -- AUD2LOW / NR23 ($FF18) --------------------------------------------------- -; Audio channel 2 period (low 8 bits) [r/w] +; Audio channel 2 period (low 8 bits) [wo] def rAUD2LOW equ $FF18 ; -- AUD2HIGH / NR24 ($FF19) -------------------------------------------------- @@ -304,7 +311,7 @@ def AUD3LEVEL_VOLUME equ %0_11_00000 ; volume level [r/w] def AUD3LEVEL_25 equ %0_11_00000 ; 25% ; -- AUD3LOW / NR33 ($FF1D) --------------------------------------------------- -; Audio channel 3 period (low 8 bits) [r/w] +; Audio channel 3 period (low 8 bits) [wo] def rAUD3LOW equ $FF1D ; -- AUD3HIGH / NR34 ($FF1E) -------------------------------------------------- @@ -927,15 +934,18 @@ def TILE_HEIGHT equ 8 ; height of tile in pixels def TILE_SIZE equ 16 ; size of tile in bytes (2 bits/pixel) def COLOR_SIZE equ 2 ; size of color in bytes (little-endian BGR555) - def B_COLOR_RED equ 0 ; bits 4-0 - def B_COLOR_GREEN equ 5 ; bits 9-5 - def B_COLOR_BLUE equ 10 ; bits 14-10 +def PAL_COLORS equ 4 ; colors per palette +def PAL_SIZE equ COLOR_SIZE * PAL_COLORS ; size of palette in bytes + +def COLOR_CH_WIDTH equ 5 ; bits per RGB color channel +def COLOR_CH_MAX equ (1 << COLOR_CH_WIDTH) - 1 + def B_COLOR_RED equ COLOR_CH_WIDTH * 0 ; bits 4-0 + def B_COLOR_GREEN equ COLOR_CH_WIDTH * 1 ; bits 9-5 + def B_COLOR_BLUE equ COLOR_CH_WIDTH * 2 ; bits 14-10 def COLOR_RED equ %000_11111 ; for the low byte def COLOR_GREEN_LOW equ %111_00000 ; for the low byte def COLOR_GREEN_HIGH equ %0_00000_11 ; for the high byte def COLOR_BLUE equ %0_11111_00 ; for the high byte -def PAL_COLORS equ 4 ; colors per palette -def PAL_SIZE equ COLOR_SIZE * PAL_COLORS ; size of palette in bytes ; (DMG only) grayscale shade indexes for BGP, OBP0, and OBP1 def SHADE_WHITE equ %00 @@ -1032,6 +1042,22 @@ def B_BOOTUP_B_AGB equ 0 def BOOTUP_B_CGB equ 0 << B_BOOTUP_B_AGB def BOOTUP_B_AGB equ 1 << B_BOOTUP_B_AGB +; Register C = CPU qualifier +def BOOTUP_C_DMG equ $13 +def BOOTUP_C_SGB equ $14 +def BOOTUP_C_CGB equ $00 ; CGB or AGB + +; Register D = color qualifier +def BOOTUP_D_MONO equ $00 ; DMG, MGB, SGB, or CGB or AGB in DMG mode +def BOOTUP_D_COLOR equ $FF ; CGB or AGB + +; Register E = CPU qualifier (distinguishes DMG variants) +def BOOTUP_E_DMG0 equ $C1 +def BOOTUP_E_DMG equ $C8 +def BOOTUP_E_SGB equ $00 +def BOOTUP_E_CGB_DMGMODE equ $08 ; CGB or AGB in DMG mode +def BOOTUP_E_CGB equ $56 ; CGB or AGB + ;****************************************************************************** ; Aliases diff --git a/engine/gfx/palettes.asm b/engine/gfx/palettes.asm index ef532c66..fe69144c 100644 --- a/engine/gfx/palettes.asm +++ b/engine/gfx/palettes.asm @@ -338,30 +338,30 @@ SendSGBPacket: ld a, 1 ldh [hDisableJoypadPolling], a ; send RESET signal (P14=LOW, P15=LOW) - xor a + xor a ; JOYP_SGB_START ldh [rJOYP], a ; set P14=HIGH, P15=HIGH - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ;load length of packets (16 bytes) - ld b, $10 + ld b, 16 .nextByte ;set bit counter (8 bits per byte) - ld e, $08 + ld e, 8 ; get next byte in the packet ld a, [hli] ld d, a .nextBit0 bit 0, d ; if 0th bit is not zero set P14=HIGH, P15=LOW (send bit 1) - ld a, $10 + ld a, JOYP_SGB_ONE jr nz, .next0 ; else (if 0th bit is zero) set P14=LOW, P15=HIGH (send bit 0) - ld a, $20 + ld a, JOYP_SGB_ZERO .next0 ldh [rJOYP], a ; must set P14=HIGH,P15=HIGH between each "pulse" - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ; rotation will put next bit in 0th position (so we can always use command ; "bit 0, d" to fetch the bit that has to be sent) @@ -371,11 +371,11 @@ SendSGBPacket: jr nz, .nextBit0 dec b jr nz, .nextByte -; send bit 1 as a "stop bit" (end of parameter data) - ld a, $20 +; send bit 0 as a "stop bit" (end of parameter data) + ld a, JOYP_SGB_ZERO ldh [rJOYP], a ; set P14=HIGH,P15=HIGH - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a xor a ldh [hDisableJoypadPolling], a @@ -465,17 +465,17 @@ CheckSGB: and $3 cp $3 jr nz, .isSGB - ld a, $20 + ld a, JOYP_SGB_ZERO ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] call Wait7000 call Wait7000 - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a call Wait7000 call Wait7000 - ld a, $10 + ld a, JOYP_SGB_ONE ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] @@ -486,7 +486,7 @@ CheckSGB: call Wait7000 vc_hook Unknown_network_reset call Wait7000 - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] -- cgit v1.3.1-sl0p