diff --git a/src/constants/gfx_constants.asm b/src/constants/gfx_constants.asm index 0d98459..200f53d 100644 --- a/src/constants/gfx_constants.asm +++ b/src/constants/gfx_constants.asm @@ -4,7 +4,7 @@ DEF palettes EQUS "* PAL_SIZE" DEF NUM_BACKGROUND_PALETTES EQU 8 DEF NUM_OBJECT_PALETTES EQU 8 -DEF PALRGB_WHITE EQU (31 << B_COLOR_BLUE) | (31 << B_COLOR_GREEN) | (31 << B_COLOR_RED) +DEF PALRGB_WHITE EQU (COLOR_CH_MAX << B_COLOR_BLUE) | (COLOR_CH_MAX << B_COLOR_GREEN) | (COLOR_CH_MAX << B_COLOR_RED) ; tile size DEF tiles EQUS "* TILE_SIZE" diff --git a/src/constants/hardware.inc b/src/constants/hardware.inc index e77034f..e1e3b2c 100644 --- a/src/constants/hardware.inc +++ b/src/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/src/constants/misc_constants.asm b/src/constants/misc_constants.asm index 748dd90..071cdec 100644 --- a/src/constants/misc_constants.asm +++ b/src/constants/misc_constants.asm @@ -5,7 +5,7 @@ DEF CONSOLE_CGB EQU $02 ; wReentrancyFlag bits DEF IN_VBLANK EQU 0 -DEF IN_TIMER EQU 1 +DEF IN_TIMER EQU 1 ; wFlushPaletteFlags constants DEF FLUSH_ONE_PAL EQU %10000000 @@ -40,17 +40,13 @@ DEF CARDPOP_NAME_LIST_SIZE EQUS "CARDPOP_NAME_LIST_MAX_ELEMS * NAME_BUFFER_LENGT DEF NUM_CHALLENGE_MACHINE_OPPONENTS EQU 5 -; rJOYP constants to read IR signals or SNES input -DEF P15 EQU %00100000 -DEF P14 EQU %00010000 -DEF P13 EQU %00001000 -DEF P12 EQU %00000100 -DEF P11 EQU %00000010 -DEF P10 EQU %00000001 -DEF SNES_JOYPAD1 EQU $3 ; lower two bits -DEF SNES_JOYPAD2 EQU $2 ; lower two bits -DEF SNES_JOYPAD3 EQU $1 ; lower two bits -DEF SNES_JOYPAD4 EQU $0 ; lower two bits +; rJOYP constants to read SNES input +DEF JOYP_SGB_MLT_REQ EQU %00000011 + +; rJOYP constants to read IR signals +DEF P14 EQU %00010000 +DEF P11 EQU %00000010 +DEF P10 EQU %00000001 ; commands transmitted through IR to be ; executed by the other device diff --git a/src/engine/link/ir_core.asm b/src/engine/link/ir_core.asm index 8ee6f67..fc49bbc 100644 --- a/src/engine/link/ir_core.asm +++ b/src/engine/link/ir_core.asm @@ -145,7 +145,7 @@ Func_19705: ld hl, rRP .loop ldh a, [rJOYP] - bit 1, a + bit 1, a ; P11 jr z, ReturnZFlagUnsetAndCarryFlagSet ld a, $aa ; request call TransmitByteThroughIR @@ -162,7 +162,7 @@ Func_1971e: ld hl, rRP .asm_19721 ldh a, [rJOYP] - bit 1, a + bit 1, a ; P11 jr z, ReturnZFlagUnsetAndCarryFlagSet call ReceiveByteThroughIR_ZeroIfUnsuccessful cp $aa ; request diff --git a/src/home/double_speed.asm b/src/home/double_speed.asm index 9db6e34..f18f1ad 100644 --- a/src/home/double_speed.asm +++ b/src/home/double_speed.asm @@ -26,7 +26,7 @@ CGBSpeedSwitch:: xor a ldh [rIF], a ldh [rIE], a - ld a, $30 + ld a, JOYP_GET_NONE ldh [rJOYP], a stop call SetupTimer diff --git a/src/home/input.asm b/src/home/input.asm index 8b41ea9..4471fa2 100644 --- a/src/home/input.asm +++ b/src/home/input.asm @@ -48,7 +48,7 @@ Reset:: SaveButtonsHeld:: ld a, c ldh [hKeysHeld], a - ld a, JOYP_GET_CTRL_PAD | JOYP_GET_BUTTONS + ld a, JOYP_GET_NONE ldh [rJOYP], a ret diff --git a/src/home/sgb.asm b/src/home/sgb.asm index 62046be..adfe7e8 100644 --- a/src/home/sgb.asm +++ b/src/home/sgb.asm @@ -121,32 +121,32 @@ SendSGB:: ld c, LOW(rJOYP) .send_packets_loop push bc - ld a, $0 + ld a, JOYP_SGB_START ld [$ff00+c], a - ld a, P15 | P14 + ld a, JOYP_SGB_FINISH ld [$ff00+c], a ld b, SGB_PACKET_SIZE .send_packet_loop - ld e, $8 + ld e, 8 ld a, [hli] ld d, a .read_byte_loop bit 0, d - ld a, P14 ; '1' bit + ld a, JOYP_SGB_ONE jr nz, .transfer_bit - ld a, P15 ; '0' bit + ld a, JOYP_SGB_ZERO .transfer_bit ld [$ff00+c], a - ld a, P15 | P14 + ld a, JOYP_SGB_FINISH ld [$ff00+c], a rr d dec e jr nz, .read_byte_loop dec b jr nz, .send_packet_loop - ld a, P15 ; stop bit + ld a, JOYP_SGB_ZERO ld [$ff00+c], a - ld a, P15 | P14 + ld a, JOYP_SGB_FINISH ld [$ff00+c], a pop bc dec b @@ -163,16 +163,16 @@ DetectSGB:: ld hl, MltReq2Packet call SendSGB ldh a, [rJOYP] - and %11 - cp SNES_JOYPAD1 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .sgb - ld a, P15 + ld a, JOYP_SGB_ZERO ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] - ld a, P15 | P14 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a - ld a, P14 + ld a, JOYP_SGB_ONE ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] @@ -180,14 +180,14 @@ DetectSGB:: ldh a, [rJOYP] ldh a, [rJOYP] ldh a, [rJOYP] - ld a, P15 | P14 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] ldh a, [rJOYP] ldh a, [rJOYP] - and %11 - cp SNES_JOYPAD1 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .sgb ld hl, MltReq1Packet call SendSGB