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 ++++++++++++++++++++++++++++--------- constants/palette_constants.asm | 11 ----------- 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'constants') 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 ;****************************************************************************** diff --git a/constants/palette_constants.asm b/constants/palette_constants.asm index 6d2d49de..1cb51452 100644 --- a/constants/palette_constants.asm +++ b/constants/palette_constants.asm @@ -1,14 +1,3 @@ -; monochrome palette color ids - const_def - const SHADE_WHITE ; %00 - const SHADE_LIGHT ; %01 - const SHADE_DARK ; %10 - const SHADE_BLACK ; %11 -DEF NUM_PAL_COLORS EQU const_value - -DEF PAL_COLOR_SIZE EQU 2 -DEF PALETTE_SIZE EQU NUM_PAL_COLORS * PAL_COLOR_SIZE - ; pal/blk packets ; SetPalFunctions indexes (see engine/gfx/palettes.asm) const_def -- 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') 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 From 1eb6f61d62133922ac15c61792be8ea901d6baba Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 11 Aug 2025 16:31:18 -0400 Subject: Identify `JOYP_SGB_MLT_REQ` constant --- constants/misc_constants.asm | 3 +++ engine/gfx/palettes.asm | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'constants') diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index a542b4a7..8bd6f223 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -10,3 +10,6 @@ DEF TRUE EQU 1 ; input DEF NO_INPUT EQU 0 + +; SGB command MLT_REQ can be used to detect SGB hardware +DEF JOYP_SGB_MLT_REQ EQU %00000011 diff --git a/engine/gfx/palettes.asm b/engine/gfx/palettes.asm index fe69144c..429d8123 100644 --- a/engine/gfx/palettes.asm +++ b/engine/gfx/palettes.asm @@ -462,8 +462,8 @@ CheckSGB: ei call Wait7000 ldh a, [rJOYP] - and $3 - cp $3 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .isSGB ld a, JOYP_SGB_ZERO ldh [rJOYP], a @@ -494,8 +494,8 @@ CheckSGB: call Wait7000 call Wait7000 ldh a, [rJOYP] - and $3 - cp $3 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .isSGB call SendMltReq1Packet and a -- cgit v1.3.1-sl0p From d98b5e6f022b37ace47e7b59e7d4c7e8839b4ca4 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 28 Aug 2025 19:22:16 -0400 Subject: Document where badge and elevator floor "items" are used --- constants/item_constants.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'constants') diff --git a/constants/item_constants.asm b/constants/item_constants.asm index 4e09da0c..8f623d55 100644 --- a/constants/item_constants.asm +++ b/constants/item_constants.asm @@ -27,6 +27,7 @@ const HYPER_POTION ; $12 const SUPER_POTION ; $13 const POTION ; $14 +; badges use item IDs (see scripts/CeruleanBadgeHouse.asm) const BOULDERBADGE ; $15 DEF SAFARI_BAIT EQU BOULDERBADGE ; overload const CASCADEBADGE ; $16 @@ -94,7 +95,7 @@ DEF SAFARI_ROCK EQU CASCADEBADGE ; overload const MAX_ELIXER ; $53 DEF NUM_ITEMS EQU const_value - 1 -; elevator floors use item IDs +; elevator floors use item IDs (see scripts/CeladonMartElevator.asm and scripts/SilphCoElevator.asm) const FLOOR_B2F ; $54 const FLOOR_B1F ; $55 const FLOOR_1F ; $56 -- cgit v1.3.1-sl0p From 4d2594cb24b7e67cde4e1373c9a2b5e0ae7ff473 Mon Sep 17 00:00:00 2001 From: Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> Date: Wed, 3 Sep 2025 17:56:09 +0200 Subject: Label and constant cleanup (#528) * Label cleanup, add some constants instead of raw numbers * Rename load/save game functions to be more explicit --- constants/ram_constants.asm | 4 + data/maps/objects/Route2Gate.asm | 4 +- data/predef_pointers.asm | 12 +- engine/battle/core.asm | 48 ++++---- engine/battle/effects.asm | 12 +- engine/events/give_pokemon.asm | 2 +- engine/events/prize_menu.asm | 12 +- engine/gfx/palettes.asm | 10 +- engine/link/cable_club.asm | 2 +- engine/link/cable_club_npc.asm | 2 +- engine/menus/display_text_id_init.asm | 2 +- engine/menus/main_menu.asm | 5 +- engine/menus/save.asm | 201 ++++++++++++++++++--------------- engine/menus/start_sub_menus.asm | 36 +++--- engine/movie/hall_of_fame.asm | 2 +- engine/movie/oak_speech/clear_save.asm | 2 +- engine/movie/title.asm | 2 +- engine/movie/trade.asm | 12 +- engine/overworld/missable_objects.asm | 3 - engine/pokemon/bills_pc.asm | 5 +- engine/pokemon/status_screen.asm | 2 +- home/init.asm | 13 +-- home/map_objects.asm | 10 +- home/overworld.asm | 2 +- home/text_script.asm | 4 +- home/vcopy.asm | 4 +- scripts/HallOfFame.asm | 2 +- scripts/PokemonMansionB1F.asm | 16 +-- scripts/SeafoamIslandsB4F.asm | 2 +- scripts/VermilionDock.asm | 2 +- 30 files changed, 221 insertions(+), 214 deletions(-) (limited to 'constants') diff --git a/constants/ram_constants.asm b/constants/ram_constants.asm index 756aaa68..cc794133 100644 --- a/constants/ram_constants.asm +++ b/constants/ram_constants.asm @@ -49,6 +49,7 @@ DEF BIT_NO_PREVIOUS_MAP EQU 7 ; wCurrentBoxNum DEF BIT_HAS_CHANGED_BOXES EQU 7 +DEF BOX_NUM_MASK EQU %01111111 ; wObtainedBadges, wBeatGymFlags const_def @@ -153,3 +154,6 @@ DEF NUM_BADGES EQU const_value const_def const BIT_PLAYER_LOWER_Y ; 0 const BIT_PLAYER_LOWER_X ; 1 + +; rLCDC +DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9800 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON diff --git a/data/maps/objects/Route2Gate.asm b/data/maps/objects/Route2Gate.asm index 6c46736d..44e4aa67 100644 --- a/data/maps/objects/Route2Gate.asm +++ b/data/maps/objects/Route2Gate.asm @@ -1,6 +1,6 @@ object_const_def - const_export ROUTE2_OAKS_AIDE - const_export ROUTE2_YOUNGSTER + const_export ROUTE2GATE_OAKS_AIDE + const_export ROUTE2GATE_YOUNGSTER Route2Gate_Object: db $a ; border block diff --git a/data/predef_pointers.asm b/data/predef_pointers.asm index ebf81847..e6968c46 100644 --- a/data/predef_pointers.asm +++ b/data/predef_pointers.asm @@ -53,7 +53,7 @@ PredefPointers:: add_predef DoubleOrHalveSelectedStats add_predef ShowPokedexMenu add_predef EvolutionAfterBattle - add_predef SaveSAVtoSRAM0 + add_predef SaveMainData add_predef InitOpponent add_predef CableClub_Run add_predef DrawBadges @@ -73,7 +73,7 @@ PredefPointers:: add_predef UsedCut add_predef ShowPokedexData add_predef WriteMonMoves - add_predef SaveSAV + add_predef SaveMenu add_predef LoadSGB add_predef MarkTownVisitedAndLoadMissableObjects add_predef SetPartyMonTypes @@ -90,10 +90,10 @@ PredefPointers:: add_predef EmptyFunc ; return immediately add_predef AskName add_predef PewterGuys - add_predef SaveSAVtoSRAM2 - add_predef LoadSAV2 - add_predef LoadSAV - add_predef SaveSAVtoSRAM1 + add_predef SavePartyAndDexData + add_predef LoadPartyAndDexData + add_predef TryLoadSaveFile + add_predef SaveCurrentBoxData add_predef DoInGameTradeDialogue add_predef HallOfFamePC add_predef DisplayDexRating diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 28c164e5..296f9019 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -3137,30 +3137,30 @@ PlayerCalcMoveDamage: jp c, .moveHitTest ; SetDamageEffects moves (e.g. Seismic Toss and Super Fang) skip damage calculation call CriticalHitTest call HandleCounterMove - jr z, handleIfPlayerMoveMissed + jr z, HandleIfPlayerMoveMissed call GetDamageVarsForPlayerAttack call CalculateDamage - jp z, playerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest + jp z, PlayerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest ; for these moves, accuracy tests will only occur if they are called as part of the effect itself call AdjustDamageForMoveType call RandomizeDamage .moveHitTest call MoveHitTest -handleIfPlayerMoveMissed: +HandleIfPlayerMoveMissed: ld a, [wMoveMissed] and a - jr z, getPlayerAnimationType + jr z, GetPlayerAnimationType ld a, [wPlayerMoveEffect] sub EXPLODE_EFFECT - jr z, playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT - jr playerCheckIfFlyOrChargeEffect -getPlayerAnimationType: + jr z, PlayPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT + jr PlayerCheckIfFlyOrChargeEffect +GetPlayerAnimationType: ld a, [wPlayerMoveEffect] and a ld a, ANIMATIONTYPE_BLINK_ENEMY_MON_SPRITE ; move has no effect other than dealing damage - jr z, playPlayerMoveAnimation + jr z, PlayPlayerMoveAnimation ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_LIGHT ; move has effect -playPlayerMoveAnimation: +PlayPlayerMoveAnimation: push af ld a, [wPlayerBattleStatus2] bit HAS_SUBSTITUTE_UP, a @@ -3179,7 +3179,7 @@ playPlayerMoveAnimation: ld b, BANK(ReshowSubstituteAnim) call nz, Bankswitch jr MirrorMoveCheck -playerCheckIfFlyOrChargeEffect: +PlayerCheckIfFlyOrChargeEffect: ld c, 30 call DelayFrames ld a, [wPlayerMoveEffect] @@ -3246,7 +3246,7 @@ MirrorMoveCheck: ld a, [wPlayerNumAttacksLeft] dec a ld [wPlayerNumAttacksLeft], a - jp nz, getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. + jp nz, GetPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. ; damage calculation and accuracy tests only happen for the first hit res ATTACKING_MULTIPLE_TIMES, [hl] ; clear attacking multiple times status when all attacks are over ld hl, MultiHitText @@ -3523,7 +3523,7 @@ CheckPlayerStatusConditions: ld [hl], a ld a, BIDE ld [wPlayerMoveNum], a - ld hl, handleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest + ld hl, HandleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest jp .returnToHL .ThrashingAboutCheck @@ -3557,7 +3557,7 @@ CheckPlayerStatusConditions: ld a, [wPlayerNumAttacksLeft] dec a ; did multi-turn move end? ld [wPlayerNumAttacksLeft], a - ld hl, getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + ld hl, GetPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest jp nz, .returnToHL jp .returnToHL @@ -5567,7 +5567,7 @@ RandomizeDamage: .loop call BattleRandom rrca - cp 217 + cp 85 percent + 1 jr c, .loop ldh [hMultiplier], a call Multiply ; multiply damage by the random number, which is in the range [217, 255] @@ -5660,7 +5660,7 @@ EnemyCalcMoveDamage: jp c, EnemyMoveHitTest call CriticalHitTest call HandleCounterMove - jr z, handleIfEnemyMoveMissed + jr z, HandleIfEnemyMoveMissed call SwapPlayerAndEnemyLevels call GetDamageVarsForEnemyAttack call SwapPlayerAndEnemyLevels @@ -5671,13 +5671,13 @@ EnemyCalcMoveDamage: EnemyMoveHitTest: call MoveHitTest -handleIfEnemyMoveMissed: +HandleIfEnemyMoveMissed: ld a, [wMoveMissed] and a jr z, .moveDidNotMiss ld a, [wEnemyMoveEffect] cp EXPLODE_EFFECT - jr z, handleExplosionMiss + jr z, HandleExplosionMiss jr EnemyCheckIfFlyOrChargeEffect .moveDidNotMiss call SwapPlayerAndEnemyLevels @@ -5686,13 +5686,13 @@ GetEnemyAnimationType: ld a, [wEnemyMoveEffect] and a ld a, ANIMATIONTYPE_SHAKE_SCREEN_VERTICALLY - jr z, playEnemyMoveAnimation + jr z, PlayEnemyMoveAnimation ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_HEAVY - jr playEnemyMoveAnimation -handleExplosionMiss: + jr PlayEnemyMoveAnimation +HandleExplosionMiss: call SwapPlayerAndEnemyLevels xor a -playEnemyMoveAnimation: +PlayEnemyMoveAnimation: push af ld a, [wEnemyBattleStatus2] bit HAS_SUBSTITUTE_UP, a ; does mon have a substitute? @@ -6031,7 +6031,7 @@ CheckEnemyStatusConditions: ld a, BIDE ld [wEnemyMoveNum], a call SwapPlayerAndEnemyLevels - ld hl, handleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest + ld hl, HandleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest jp .enemyReturnToHL .checkIfThrashingAbout bit THRASHING_ABOUT, [hl] ; is mon using thrash or petal dance? @@ -6881,12 +6881,12 @@ _InitBattleCommon: call PrintText call SaveScreenTilesToBuffer1 call ClearScreen - ld a, $98 + ld a, HIGH(vBGMap0) ldh [hAutoBGTransferDest + 1], a ld a, $1 ldh [hAutoBGTransferEnabled], a call Delay3 - ld a, $9c + ld a, HIGH(vBGMap1) ldh [hAutoBGTransferDest + 1], a call LoadScreenTilesFromBuffer1 hlcoord 9, 7 diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index a3a552e7..e111f783 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -7,9 +7,9 @@ _JumpMoveEffect: ldh a, [hWhoseTurn] and a ld a, [wPlayerMoveEffect] - jr z, .next1 + jr z, .next ld a, [wEnemyMoveEffect] -.next1 +.next dec a ; subtract 1, there is no special effect for 00 add a ; x2, 16bit pointers ld hl, MoveEffectPointerTable @@ -680,14 +680,14 @@ UpdateLoweredStatDone: call PrintStatText pop de ld a, [de] - cp $44 + cp ATTACK_DOWN_SIDE_EFFECT ; for all side effects, move animation has already played, skip it jr nc, .ApplyBadgeBoostsAndStatusPenalties call PlayCurrentMoveAnimation2 .ApplyBadgeBoostsAndStatusPenalties ldh a, [hWhoseTurn] and a call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat, - ; even to those not affected by the stat-up move (will be boosted further) + ; even to those not affected by the stat-down move (will be boosted further) ld hl, MonsStatsFellText call PrintText @@ -1438,9 +1438,9 @@ CheckTargetSubstitute: ld hl, wEnemyBattleStatus2 ldh a, [hWhoseTurn] and a - jr z, .next1 + jr z, .next ld hl, wPlayerBattleStatus2 -.next1 +.next bit HAS_SUBSTITUTE_UP, [hl] pop hl ret diff --git a/engine/events/give_pokemon.asm b/engine/events/give_pokemon.asm index 9e80bdfc..640a3dba 100644 --- a/engine/events/give_pokemon.asm +++ b/engine/events/give_pokemon.asm @@ -20,7 +20,7 @@ _GivePokemon:: callfar SendNewMonToBox ld hl, wStringBuffer ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum sub 9 diff --git a/engine/events/prize_menu.asm b/engine/events/prize_menu.asm index c73d7ab8..15b991ed 100644 --- a/engine/events/prize_menu.asm +++ b/engine/events/prize_menu.asm @@ -2,12 +2,12 @@ CeladonPrizeMenu:: ld b, COIN_CASE call IsItemInBag jr nz, .havingCoinCase - ld hl, RequireCoinCaseTextPtr + ld hl, RequireCoinCaseText jp PrintText .havingCoinCase ld hl, wStatusFlags5 set BIT_NO_TEXT_DELAY, [hl] - ld hl, ExchangeCoinsForPrizesTextPtr + ld hl, ExchangeCoinsForPrizesText call PrintText ; the following are the menu settings xor a @@ -28,7 +28,7 @@ CeladonPrizeMenu:: call TextBoxBorder call GetPrizeMenuId call UpdateSprites - ld hl, WhichPrizeTextPtr + ld hl, WhichPrizeText call PrintText call HandleMenuInput ; menu choice handler bit B_PAD_B, a @@ -42,16 +42,16 @@ CeladonPrizeMenu:: res BIT_NO_TEXT_DELAY, [hl] ret -RequireCoinCaseTextPtr: +RequireCoinCaseText: text_far _RequireCoinCaseText text_waitbutton text_end -ExchangeCoinsForPrizesTextPtr: +ExchangeCoinsForPrizesText: text_far _ExchangeCoinsForPrizesText text_end -WhichPrizeTextPtr: +WhichPrizeText: text_far _WhichPrizeText text_end diff --git a/engine/gfx/palettes.asm b/engine/gfx/palettes.asm index 429d8123..0497f74a 100644 --- a/engine/gfx/palettes.asm +++ b/engine/gfx/palettes.asm @@ -523,15 +523,15 @@ CopyGfxToSuperNintendoVRAM: call CopySGBBorderTiles jr .next .notCopyingTileData - ld bc, $1000 + ld bc, 256 tiles call CopyData .next ld hl, vBGMap0 - ld de, $c + ld de, TILEMAP_WIDTH - SCREEN_WIDTH ld a, $80 - ld c, $d + ld c, (256 + SCREEN_WIDTH - 1) / SCREEN_WIDTH ; enough rows to fit 256 tiles .loop - ld b, $14 + ld b, SCREEN_WIDTH .innerLoop ld [hli], a inc a @@ -540,7 +540,7 @@ CopyGfxToSuperNintendoVRAM: add hl, de dec c jr nz, .loop - ld a, $e3 + ld a, LCDC_DEFAULT ldh [rLCDC], a pop hl call SendSGBPacket diff --git a/engine/link/cable_club.asm b/engine/link/cable_club.asm index 872e9b9c..a4307532 100644 --- a/engine/link/cable_club.asm +++ b/engine/link/cable_club.asm @@ -861,7 +861,7 @@ TradeCenter_Trade: hlcoord 1, 14 ld de, TradeCompleted call PlaceString - predef SaveSAVtoSRAM2 + predef SavePartyAndDexData ; this allows reset into Pokecenter vc_hook Trade_save_game_end ld c, 50 call DelayFrames diff --git a/engine/link/cable_club_npc.asm b/engine/link/cable_club_npc.asm index 19e59eca..2c458b59 100644 --- a/engine/link/cable_club_npc.asm +++ b/engine/link/cable_club_npc.asm @@ -64,7 +64,7 @@ CableClubNPC:: and a jr nz, .choseNo vc_hook Wireless_TryQuickSave_block_input - callfar SaveSAVtoSRAM + callfar SaveGameData call WaitForSoundToFinish ld a, SFX_SAVE call PlaySoundWaitForCurrent diff --git a/engine/menus/display_text_id_init.asm b/engine/menus/display_text_id_init.asm index 2ef1cfb1..f8bd6512 100644 --- a/engine/menus/display_text_id_init.asm +++ b/engine/menus/display_text_id_init.asm @@ -69,7 +69,7 @@ DisplayTextIDInit:: add hl, de dec c jr nz, .spriteStandStillLoop - ld b, $9c ; window background address + ld b, HIGH(vBGMap1) call CopyScreenTileBufferToVRAM ; transfer background in WRAM to VRAM xor a ldh [hWY], a ; put the window on the screen diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index a3fe6587..c6f8547b 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -8,7 +8,7 @@ MainMenu: call CheckForPlayerNameInSRAM jr nc, .mainMenuLoop - predef LoadSAV + predef TryLoadSaveFile .mainMenuLoop ld c, 20 @@ -701,8 +701,9 @@ CheckForPlayerNameInSRAM: ; in carry. ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK(sPlayerName) == BMODE_ADVANCED ld [rRAMB], a ld b, NAME_LENGTH ld hl, sPlayerName diff --git a/engine/menus/save.asm b/engine/menus/save.asm index fba1dc53..7112207f 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -1,16 +1,15 @@ -LoadSAV: -; if carry, write "the file data is destroyed" +TryLoadSaveFile: call ClearScreen call LoadFontTilePatterns call LoadTextBoxTilePatterns - call LoadSAV0 + call LoadMainData jr c, .badsum - call LoadSAV1 + call LoadCurrentBoxData jr c, .badsum - call LoadSAV2 + call LoadPartyAndDexData jr c, .badsum ld a, $2 ; good checksum - jr .goodsum + jr .done .badsum ld hl, wStatusFlags5 push hl @@ -22,7 +21,7 @@ LoadSAV: pop hl res BIT_NO_TEXT_DELAY, [hl] ld a, $1 ; bad checksum -.goodsum +.done ld [wSaveFileStatus], a ret @@ -30,33 +29,34 @@ FileDataDestroyedText: text_far _FileDataDestroyedText text_end -LoadSAV0: +LoadMainData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ; This vc_hook does not have to be in any particular location. ; It is defined here because it refers to the same labels as the two lines below. vc_hook Unknown_save_limit ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld c, a ld a, [sMainDataCheckSum] cp c - jp z, .checkSumsMatched + jp z, .checkSumMatched ; If the computed checksum didn't match the saved on, try again. ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld c, a ld a, [sMainDataCheckSum] cp c - jp nz, SAVBadCheckSum + jp nz, CheckSumFailed -.checkSumsMatched +.checkSumMatched ld hl, sPlayerName ld de, wPlayerName ld bc, NAME_LENGTH @@ -73,46 +73,51 @@ LoadSAV0: call CopyData ld a, [sTileAnimations] ldh [hTileAnimations], a + +; this part is redundant, LoadCurrentBoxData is always called next ld hl, sCurBoxData ld de, wBoxDataStart ld bc, wBoxDataEnd - wBoxDataStart call CopyData + and a - jp SAVGoodChecksum + jp GoodCheckSum -LoadSAV1: +LoadCurrentBoxData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld c, a ld a, [sMainDataCheckSum] cp c - jr nz, SAVBadCheckSum + jr nz, CheckSumFailed ld hl, sCurBoxData ld de, wBoxDataStart ld bc, wBoxDataEnd - wBoxDataStart call CopyData and a - jp SAVGoodChecksum + jp GoodCheckSum -LoadSAV2: +LoadPartyAndDexData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld c, a ld a, [sMainDataCheckSum] cp c - jp nz, SAVBadCheckSum + jp nz, CheckSumFailed ld hl, sPartyData ld de, wPartyDataStart ld bc, wPartyDataEnd - wPartyDataStart @@ -122,40 +127,43 @@ LoadSAV2: ld bc, wPokedexSeenEnd - wPokedexOwned call CopyData and a - jp SAVGoodChecksum + jp GoodCheckSum -SAVBadCheckSum: +CheckSumFailed: scf + ; fallthrough -SAVGoodChecksum: - ld a, $0 +GoodCheckSum: + ld a, BMODE_SIMPLE ; preserve flags ld [rBMODE], a + ASSERT RAMG_SRAM_DISABLE == BMODE_SIMPLE ld [rRAMG], a ret -LoadSAVIgnoreBadCheckSum: -; unused function that loads save data and ignores bad checksums - call LoadSAV0 - call LoadSAV1 - jp LoadSAV2 +TryLoadSaveFileIgnoreChecksum: ; unreferenced +; don't update wSaveFileStatus upon success or failure +; don't display warning in case of failed checksum + call LoadMainData + call LoadCurrentBoxData + jp LoadPartyAndDexData -SaveSAV: +SaveMenu: farcall PrintSaveScreenText ld hl, WouldYouLikeToSaveText - call SaveSAVConfirm + call SaveTheGame_YesOrNo and a ;|0 = Yes|1 = No| ret nz ld a, [wSaveFileStatus] dec a jr z, .save - call SAVCheckRandomID + call CheckPreviousSaveFile jr z, .save ld hl, OlderFileWillBeErasedText - call SaveSAVConfirm + call SaveTheGame_YesOrNo and a ret nz .save - call SaveSAVtoSRAM + call SaveGameData hlcoord 1, 13 lb bc, 4, 18 call ClearScreenArea @@ -175,13 +183,13 @@ SaveSAV: NowSavingString: db "Now saving...@" -SaveSAVConfirm: +SaveTheGame_YesOrNo: call PrintText hlcoord 0, 7 lb bc, 8, 1 ld a, TWO_OPTION_MENU ld [wTextBoxID], a - call DisplayTextBoxID ; yes/no menu + call DisplayTextBoxID ld a, [wCurrentMenuItem] ret @@ -197,12 +205,14 @@ OlderFileWillBeErasedText: text_far _OlderFileWillBeErasedText text_end -SaveSAVtoSRAM0: +SaveMainData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a + ld hl, wPlayerName ld de, sPlayerName ld bc, NAME_LENGTH @@ -216,26 +226,29 @@ SaveSAVtoSRAM0: ld bc, wSpriteDataEnd - wSpriteDataStart call CopyData ld hl, wBoxDataStart + +; this part is redundant, SaveCurrentBoxData is always called next ld de, sCurBoxData ld bc, wBoxDataEnd - wBoxDataStart call CopyData ldh a, [hTileAnimations] ld [sTileAnimations], a + ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld [sMainDataCheckSum], a xor a ld [rBMODE], a ld [rRAMG], a ret -SaveSAVtoSRAM1: -; stored pokémon +SaveCurrentBoxData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ld hl, wBoxDataStart ld de, sCurBoxData @@ -243,18 +256,19 @@ SaveSAVtoSRAM1: call CopyData ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld [sMainDataCheckSum], a xor a ld [rBMODE], a ld [rRAMG], a ret -SaveSAVtoSRAM2: +SavePartyAndDexData: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ld hl, wPartyDataStart ld de, sPartyData @@ -266,21 +280,21 @@ SaveSAVtoSRAM2: call CopyData ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld [sMainDataCheckSum], a xor a ld [rBMODE], a ld [rRAMG], a ret -SaveSAVtoSRAM:: +SaveGameData:: ld a, $2 ld [wSaveFileStatus], a - call SaveSAVtoSRAM0 - call SaveSAVtoSRAM1 - jp SaveSAVtoSRAM2 + call SaveMainData + call SaveCurrentBoxData + jp SavePartyAndDexData -SAVCheckSum: +CalcCheckSum: ;Check Sum (result[1 byte] is complemented) ld d, 0 .loop @@ -303,7 +317,7 @@ CalcIndividualBoxCheckSums: push bc push de ld bc, wBoxDataEnd - wBoxDataStart - call SAVCheckSum + call CalcCheckSum pop de ld [de], a inc de @@ -317,7 +331,7 @@ GetBoxSRAMLocation: ; out: b = box SRAM bank, hl = pointer to start of box ld hl, BoxSRAMPointerTable ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp NUM_BOXES / 2 ld b, 2 jr c, .next @@ -379,7 +393,7 @@ ChangeBox:: ld a, [hl] ld [de], a call RestoreMapTextPointer - call SaveSAVtoSRAM + call SaveGameData ld hl, wChangeBoxSavedMapTextPointer call SetMapTextPointer ld a, SFX_SAVE @@ -396,7 +410,7 @@ CopyBoxToOrFromSRAM: push hl ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a ld a, b ld [rRAMB], a @@ -404,7 +418,7 @@ CopyBoxToOrFromSRAM: call CopyData pop hl -; mark the memory that the box was copied from as am empty box +; mark the source box as an empty box xor a ld [hli], a dec a @@ -412,7 +426,7 @@ CopyBoxToOrFromSRAM: ld hl, sBox1 ; sBox7 ld bc, sBank2AllBoxesChecksum - sBox1 - call SAVCheckSum + call CalcCheckSum ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum call CalcIndividualBoxCheckSums xor a @@ -434,7 +448,7 @@ DisplayChangeBoxMenu: xor a ld [wMenuWatchMovingOutOfBounds], a ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK ld [wCurrentMenuItem], a ld [wLastMenuItem], a hlcoord 0, 0 @@ -455,7 +469,7 @@ DisplayChangeBoxMenu: ld hl, hUILayoutFlags res BIT_SINGLE_SPACED_LINES, [hl] ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum sub 9 @@ -474,7 +488,7 @@ DisplayChangeBoxMenu: hlcoord 18, 1 ld de, wBoxMonCounts ld bc, SCREEN_WIDTH - ld a, $c + ld a, NUM_BOXES .loop push af ld a, [de] @@ -517,12 +531,12 @@ EmptyAllSRAMBoxes: ; player changes the box) ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a - ld a, 2 + ld a, BANK("Saved Boxes 1") ld [rRAMB], a call EmptySRAMBoxesInBank - ld a, 3 + ld a, BANK("Saved Boxes 2") ld [rRAMB], a call EmptySRAMBoxesInBank xor a @@ -546,7 +560,7 @@ EmptySRAMBoxesInBank: call EmptySRAMBox ld hl, sBox1 ; sBox7 ld bc, sBank2AllBoxesChecksum - sBox1 - call SAVCheckSum + call CalcCheckSum ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum call CalcIndividualBoxCheckSums ret @@ -563,12 +577,12 @@ GetMonCountsForAllBoxes: push hl ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a - ld a, $2 + ld a, BANK("Saved Boxes 1") ld [rRAMB], a call GetMonCountsForBoxesInBank - ld a, $3 + ld a, BANK("Saved Boxes 2") ld [rRAMB], a call GetMonCountsForBoxesInBank xor a @@ -578,7 +592,7 @@ GetMonCountsForAllBoxes: ; copy the count for the current box from WRAM ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK ld c, a ld b, 0 add hl, bc @@ -602,25 +616,26 @@ GetMonCountsForBoxesInBank: ld [hli], a ret -SAVCheckRandomID: -; checks if Sav file is the same by checking player's name 1st letter -; and the two random numbers generated at game beginning -; (which are stored at wPlayerID)s - ld a, $0a +; check if we're trying to save over a different playthrough +; return result in zero flag +; z set: a valid save file was found, and saved PlayerID is different from wPlayerID +CheckPreviousSaveFile: + ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $01 + ld a, BMODE_ADVANCED ld [rBMODE], a + ASSERT BANK("Save Data") == BMODE_ADVANCED ld [rRAMB], a ld a, [sPlayerName] and a jr z, .next ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld c, a ld a, [sMainDataCheckSum] cp c - jr nz, .next + jr nz, .next ; return z set if save data is corrupted ld hl, sMainData + (wPlayerID - wMainDataStart) ; player ID ld a, [hli] ld h, [hl] @@ -631,8 +646,9 @@ SAVCheckRandomID: ld a, [wPlayerID + 1] cp h .next - ld a, $00 + ld a, BMODE_SIMPLE ld [rBMODE], a + ASSERT RAMG_SRAM_DISABLE == BMODE_SIMPLE ld [rRAMG], a ret @@ -674,7 +690,7 @@ LoadHallOfFameTeams: HallOfFame_Copy: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a xor a ld [rRAMB], a @@ -684,25 +700,26 @@ HallOfFame_Copy: ld [rRAMG], a ret -ClearSAV: +; Fill SRAM with $ff, erasing save data. Used by DoClearSaveDialogue +ClearAllSRAMBanks: ld a, RAMG_SRAM_ENABLE ld [rRAMG], a - ld a, $1 + ld a, BMODE_ADVANCED ld [rBMODE], a xor a - call PadSRAM_FF - ld a, $1 - call PadSRAM_FF - ld a, $2 - call PadSRAM_FF - ld a, $3 - call PadSRAM_FF + call .PadSRAM_FF + ld a, 1 + call .PadSRAM_FF + ld a, 2 + call .PadSRAM_FF + ld a, 3 + call .PadSRAM_FF xor a ld [rBMODE], a ld [rRAMG], a ret -PadSRAM_FF: +.PadSRAM_FF ld [rRAMB], a ld hl, STARTOF(SRAM) ld bc, SIZEOF(SRAM) diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index 65f0b26e..e845941f 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -1,6 +1,6 @@ StartMenu_Pokedex:: predef ShowPokedexMenu - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call Delay3 call LoadGBPal call UpdateSprites @@ -63,7 +63,7 @@ StartMenu_Pokemon:: ld [hl], a call HandleMenuInput push af - call LoadScreenTilesFromBuffer1 ; restore saved screen + call LoadScreenTilesFromBuffer1 pop af bit B_PAD_B, a jp nz, .loop @@ -117,7 +117,7 @@ StartMenu_Pokemon:: ld a, [hli] ld h, [hl] ld l, a - ld a, [wObtainedBadges] ; badges obtained + ld a, [wObtainedBadges] jp hl .outOfBattleMovePointers dw .cut @@ -286,7 +286,7 @@ StartMenu_Pokemon:: ; writes a blank tile to all possible menu cursor positions on the party menu ErasePartyMenuCursors:: hlcoord 0, 1 - ld bc, 2 * 20 ; menu cursor positions are 2 rows apart + ld bc, 2 * SCREEN_WIDTH ; menu cursor positions are 2 rows apart ld a, 6 ; 6 menu cursor positions .loop ld [hl], " " @@ -296,7 +296,7 @@ ErasePartyMenuCursors:: ret ItemMenuLoop: - call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen + call LoadScreenTilesFromBuffer2DisableBGTransfer call RunDefaultPaletteCommand StartMenu_Item:: @@ -323,7 +323,7 @@ StartMenu_Item:: ld [wBagSavedMenuItem], a jr nc, .choseItem .exitMenu - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call LoadTextBoxTilePatterns call UpdateSprites jp RedisplayStartMenu @@ -363,7 +363,7 @@ StartMenu_Item:: bit B_PAD_B, a jr z, .useOrTossItem jp ItemMenuLoop -.useOrTossItem ; if the player made the choice to use or toss the item +.useOrTossItem ld a, [wCurItem] ld [wNamedObjectIndex], a call GetItemName @@ -459,14 +459,14 @@ StartMenu_TrainerInfo:: xor a ldh [hTileAnimations], a call DrawTrainerInfo - predef DrawBadges ; draw badges + predef DrawBadges ld b, SET_PAL_TRAINER_CARD call RunPaletteCommand call GBPalNormal - call WaitForTextScrollButtonPress ; wait for button press + call WaitForTextScrollButtonPress call GBPalWhiteOut call LoadFontTilePatterns - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call RunDefaultPaletteCommand call ReloadMapData call LoadGBPal @@ -489,7 +489,7 @@ DrawTrainerInfo: ld de, vChars2 tile $00 ld bc, $1c tiles call CopyData - ld hl, TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns + ld hl, TrainerInfoTextBoxTileGraphics ld de, vChars2 tile $77 ld bc, 8 tiles push bc @@ -499,10 +499,10 @@ DrawTrainerInfo: ld bc, $17 tiles call TrainerInfo_FarCopyData pop bc - ld hl, BadgeNumbersTileGraphics ; badge number tile patterns + ld hl, BadgeNumbersTileGraphics ld de, vChars1 tile $58 call TrainerInfo_FarCopyData - ld hl, GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns + ld hl, GymLeaderFaceAndBadgeTileGraphics ld de, vChars2 tile $20 ld bc, 8 * 8 tiles ld a, BANK(GymLeaderFaceAndBadgeTileGraphics) @@ -555,12 +555,12 @@ DrawTrainerInfo: ld c, 3 | LEADING_ZEROES | LEFT_ALIGN | MONEY_SIGN call PrintBCDNumber hlcoord 9, 6 - ld de, wPlayTimeHours ; hours + ld de, wPlayTimeHours lb bc, LEFT_ALIGN | 1, 3 call PrintNumber ld [hl], $d6 ; colon tile ID inc hl - ld de, wPlayTimeMinutes ; minutes + ld de, wPlayTimeMinutes lb bc, LEADING_ZEROES | 1, 2 jp PrintNumber @@ -642,8 +642,8 @@ StartMenu_SaveReset:: ld a, [wStatusFlags4] bit BIT_LINK_CONNECTED, a jp nz, Init - predef SaveSAV ; save the game - call LoadScreenTilesFromBuffer2 ; restore saved screen + predef SaveMenu + call LoadScreenTilesFromBuffer2 jp HoldTextDisplayOpen StartMenu_Option:: @@ -652,7 +652,7 @@ StartMenu_Option:: call ClearScreen call UpdateSprites callfar DisplayOptionMenu - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call LoadTextBoxTilePatterns call UpdateSprites jp RedisplayStartMenu diff --git a/engine/movie/hall_of_fame.asm b/engine/movie/hall_of_fame.asm index 236cf516..7653b4bc 100644 --- a/engine/movie/hall_of_fame.asm +++ b/engine/movie/hall_of_fame.asm @@ -7,7 +7,7 @@ AnimateHallOfFame: call LoadTextBoxTilePatterns call DisableLCD ld hl, vBGMap0 - ld bc, $800 + ld bc, 2 * TILEMAP_AREA ld a, " " call FillMemory call EnableLCD diff --git a/engine/movie/oak_speech/clear_save.asm b/engine/movie/oak_speech/clear_save.asm index d5c04e6e..f4a278b3 100644 --- a/engine/movie/oak_speech/clear_save.asm +++ b/engine/movie/oak_speech/clear_save.asm @@ -15,7 +15,7 @@ DoClearSaveDialogue: ld a, [wCurrentMenuItem] and a jp z, Init - farcall ClearSAV + farcall ClearAllSRAMBanks jp Init ClearSaveDataText: diff --git a/engine/movie/title.asm b/engine/movie/title.asm index 83fb32e8..bcd01f33 100644 --- a/engine/movie/title.asm +++ b/engine/movie/title.asm @@ -356,7 +356,7 @@ DrawPlayerCharacter: ClearBothBGMaps: ld hl, vBGMap0 - ld bc, $400 * 2 + ld bc, 2 * TILEMAP_AREA ld a, " " jp FillMemory diff --git a/engine/movie/trade.asm b/engine/movie/trade.asm index 4d7bd54a..4cb9d394 100644 --- a/engine/movie/trade.asm +++ b/engine/movie/trade.asm @@ -167,7 +167,7 @@ LoadTradingGFXAndMonNames: ld a, BANK(TradingAnimationGraphics2) call FarCopyData2 ld hl, vBGMap0 - ld bc, $800 + ld bc, 2 * TILEMAP_AREA ld a, " " call FillMemory call ClearSprites @@ -223,7 +223,7 @@ Trade_Cleanup: ret Trade_ShowPlayerMon: - ld a, %10101011 + ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON ldh [rLCDC], a ld a, $50 ldh [hWY], a @@ -279,7 +279,7 @@ Trade_DrawOpenEndOfLinkCable: ld a, $a0 ldh [hSCX], a call DelayFrame - ld a, %10001011 + ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_OFF | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON ldh [rLCDC], a hlcoord 6, 2 ld b, TILEMAP_LINK_CABLE @@ -338,7 +338,7 @@ Trade_AnimateBallEnteringLinkCable: ld a, $1 ldh [hAutoBGTransferEnabled], a call ClearScreen - ld b, $98 + ld b, HIGH(vBGMap0) call CopyScreenTileBufferToVRAM call Delay3 xor a @@ -452,7 +452,7 @@ Trade_InitGameboyTransferGfx: ldh [hAutoBGTransferEnabled], a call Trade_LoadMonPartySpriteGfx call DelayFrame - ld a, %10101011 + ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON ldh [rLCDC], a xor a ldh [hSCX], a @@ -757,7 +757,7 @@ Trade_ShowClearedWindow: ld a, $1 ldh [hAutoBGTransferEnabled], a call ClearScreen - ld a, %11100011 + ld a, LCDC_DEFAULT ldh [rLCDC], a ld a, $7 ldh [rWX], a diff --git a/engine/overworld/missable_objects.asm b/engine/overworld/missable_objects.asm index 8f88b138..1660a894 100644 --- a/engine/overworld/missable_objects.asm +++ b/engine/overworld/missable_objects.asm @@ -15,9 +15,6 @@ MarkTownVisitedAndLoadMissableObjects:: add hl, bc ld a, [hli] ; load missable objects pointer in hl ld h, [hl] - ; fall through - -LoadMissableObjects: ld l, a push hl ld de, MissableObjects ; calculate difference between out pointer and the base pointer diff --git a/engine/pokemon/bills_pc.asm b/engine/pokemon/bills_pc.asm index ea21e8e2..6d522377 100644 --- a/engine/pokemon/bills_pc.asm +++ b/engine/pokemon/bills_pc.asm @@ -151,7 +151,7 @@ BillsPCMenu: ld c, 9 call TextBoxBorder ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum ; two digit box num @@ -236,7 +236,7 @@ BillsPCDeposit: call WaitForSoundToFinish ld hl, wBoxNumString ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum sub 9 @@ -538,6 +538,7 @@ JustAMomentText:: text_far _JustAMomentText text_end +UnusedOpenBillsPC: ; unreferenced ld a, [wSpritePlayerStateData1FacingDirection] cp SPRITE_FACING_UP ret nz diff --git a/engine/pokemon/status_screen.asm b/engine/pokemon/status_screen.asm index a68f9b38..344e7802 100644 --- a/engine/pokemon/status_screen.asm +++ b/engine/pokemon/status_screen.asm @@ -427,7 +427,7 @@ StatusScreen2: ld a, $1 ldh [hAutoBGTransferEnabled], a call Delay3 - call WaitForTextScrollButtonPress ; wait for button + call WaitForTextScrollButtonPress pop af ldh [hTileAnimations], a ld hl, wStatusFlags2 diff --git a/home/init.asm b/home/init.asm index 67fa3ab1..2ed200b4 100644 --- a/home/init.asm +++ b/home/init.asm @@ -7,17 +7,6 @@ SoftReset:: Init:: ; Program init. - -; * LCD enabled -; * Window tile map at $9C00 -; * Window display enabled -; * BG and window tile data at $8800 -; * BG tile map at $9800 -; * 8x8 OBJ size -; * OBJ display enabled -; * BG display enabled -DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9800 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON - di xor a @@ -100,7 +89,7 @@ DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC ld a, BANK(SFX_Shooting_Star) ld [wAudioROMBank], a ld [wAudioSavedROMBank], a - ld a, $9c + ld a, HIGH(vBGMap1) ldh [hAutoBGTransferDest + 1], a xor a ldh [hAutoBGTransferDest], a diff --git a/home/map_objects.asm b/home/map_objects.asm index e0d9b6a5..44b012e6 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -30,27 +30,25 @@ TextScript_ItemStoragePC:: call SaveScreenTilesToBuffer2 ld b, BANK(PlayerPC) ld hl, PlayerPC - jr bankswitchAndContinue + jr BankswitchAndContinue TextScript_BillsPC:: call SaveScreenTilesToBuffer2 ld b, BANK(BillsPC_) ld hl, BillsPC_ - jr bankswitchAndContinue + jr BankswitchAndContinue TextScript_GameCornerPrizeMenu:: -; XXX find a better name for this function -; special_F7 ld b, BANK(CeladonPrizeMenu) ld hl, CeladonPrizeMenu -bankswitchAndContinue:: +BankswitchAndContinue:: call Bankswitch jp HoldTextDisplayOpen ; continue to main text-engine function TextScript_PokemonCenterPC:: ld b, BANK(ActivatePC) ld hl, ActivatePC - jr bankswitchAndContinue + jr BankswitchAndContinue StartSimulatingJoypadStates:: xor a diff --git a/home/overworld.asm b/home/overworld.asm index 8c79d6e7..5af527c0 100644 --- a/home/overworld.asm +++ b/home/overworld.asm @@ -114,7 +114,7 @@ OverworldLoopLessDelay:: ld [wEnteringCableClub], a jr z, .changeMap ; XXX can this code be reached? - predef LoadSAV + predef TryLoadSaveFile ld a, [wCurMap] ld [wDestinationMap], a call PrepareForSpecialWarp diff --git a/home/text_script.asm b/home/text_script.asm index 35dd955b..389f2499 100644 --- a/home/text_script.asm +++ b/home/text_script.asm @@ -84,7 +84,7 @@ ENDM dict TX_SCRIPT_PRIZE_VENDOR, TextScript_GameCornerPrizeMenu dict2 TX_SCRIPT_CABLE_CLUB_RECEPTIONIST, callfar CableClubNPC - call PrintText_NoCreatingTextBox ; display the text + call PrintText_NoCreatingTextBox ld a, [wDoNotWaitForButtonPressAfterDisplayingText] and a jr nz, HoldTextDisplayOpen @@ -93,7 +93,7 @@ AfterDisplayingTextID:: ld a, [wEnteringCableClub] and a jr nz, HoldTextDisplayOpen - call WaitForTextScrollButtonPress ; wait for a button press after displaying all the text + call WaitForTextScrollButtonPress ; loop to hold the dialogue box open as long as the player keeps holding down the A button HoldTextDisplayOpen:: diff --git a/home/vcopy.asm b/home/vcopy.asm index 92c78a88..e4ba2cdb 100644 --- a/home/vcopy.asm +++ b/home/vcopy.asm @@ -140,7 +140,7 @@ AutoBgMapTransfer:: ld h, a ldh a, [hAutoBGTransferDest] ld l, a - ld de, 12 * 32 + ld de, 12 * TILEMAP_WIDTH add hl, de xor a ; TRANSFERTOP jr .doTransfer @@ -160,7 +160,7 @@ AutoBgMapTransfer:: ld h, a ldh a, [hAutoBGTransferDest] ld l, a - ld de, 6 * 32 + ld de, 6 * TILEMAP_WIDTH add hl, de ld a, TRANSFERBOTTOM .doTransfer diff --git a/scripts/HallOfFame.asm b/scripts/HallOfFame.asm index eb26afaf..31d56022 100644 --- a/scripts/HallOfFame.asm +++ b/scripts/HallOfFame.asm @@ -47,7 +47,7 @@ HallOfFameResetEventsAndSaveScript: ld [wHallOfFameCurScript], a ld a, PALLET_TOWN ld [wLastBlackoutMap], a - farcall SaveSAVtoSRAM + farcall SaveGameData ld b, 5 .delayLoop ld c, 600 / 5 diff --git a/scripts/PokemonMansionB1F.asm b/scripts/PokemonMansionB1F.asm index e31bbd3e..176c243a 100644 --- a/scripts/PokemonMansionB1F.asm +++ b/scripts/PokemonMansionB1F.asm @@ -16,30 +16,30 @@ MansionB1FCheckReplaceSwitchDoorBlocks: CheckEvent EVENT_MANSION_SWITCH_ON jr nz, .switchTurnedOn ld a, $e - ld bc, $80d + lb bc, 8, 13 call Mansion2ReplaceBlock ld a, $e - ld bc, $b06 + lb bc, 11, 6 call Mansion2ReplaceBlock ld a, $5f - ld bc, $304 + lb bc, 3, 4 call Mansion2ReplaceBlock ld a, $54 - ld bc, $808 + lb bc, 8, 8 call Mansion2ReplaceBlock ret .switchTurnedOn ld a, $2d - ld bc, $80d + lb bc, 8, 13 call Mansion2ReplaceBlock ld a, $5f - ld bc, $b06 + lb bc, 11, 6 call Mansion2ReplaceBlock ld a, $e - ld bc, $304 + lb bc, 3, 4 call Mansion2ReplaceBlock ld a, $e - ld bc, $808 + lb bc, 8, 8 call Mansion2ReplaceBlock ret diff --git a/scripts/SeafoamIslandsB4F.asm b/scripts/SeafoamIslandsB4F.asm index 314a8d50..40ecee0a 100644 --- a/scripts/SeafoamIslandsB4F.asm +++ b/scripts/SeafoamIslandsB4F.asm @@ -37,7 +37,7 @@ SeafoamIslandsB4FDefaultScript: ld a, [wCoordIndex] cp $3 jr nc, .only1UpInputNeeded - ld a, NPC_MOVEMENT_UP + ld a, PAD_UP ld [wSimulatedJoypadStatesEnd + 1], a ld a, 2 jr .forcePlayerUpFromSurfExit diff --git a/scripts/VermilionDock.asm b/scripts/VermilionDock.asm index 608d2b7e..237b4175 100644 --- a/scripts/VermilionDock.asm +++ b/scripts/VermilionDock.asm @@ -50,7 +50,7 @@ VermilionDockSSAnneLeavesScript: ld [wSpritePlayerStateData1ImageIndex], a ld c, 120 call DelayFrames - ld b, $9c + ld b, HIGH(vBGMap1) call CopyScreenTileBufferToVRAM hlcoord 0, 10 ld bc, SCREEN_WIDTH * 6 -- cgit v1.3.1-sl0p