diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index a0cc1d0a..5eecb38f 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -20,9 +20,14 @@ D_LEFT EQU %00100000 D_UP EQU %01000000 D_DOWN EQU %10000000 +PIXELS_PER_TILE EQU 8 + SCREEN_WIDTH EQU 20 SCREEN_HEIGHT EQU 18 +SCREEN_WIDTH_PIXELS EQU SCREEN_WIDTH * PIXELS_PER_TILE +SCREEN_HEIGHT_PIXELS EQU SCREEN_HEIGHT * PIXELS_PER_TILE + NPC_MOVEMENT_DOWN EQU $00 NPC_MOVEMENT_UP EQU $40 NPC_MOVEMENT_LEFT EQU $80 diff --git a/engine/gamefreak.asm b/engine/gamefreak.asm index 32dda60e..38c66793 100755 --- a/engine/gamefreak.asm +++ b/engine/gamefreak.asm @@ -28,67 +28,78 @@ AnimateShootingStar: ; 70044 (1c:4044) call LoadShootingStarGraphics ld a, (SFX_1f_67 - SFX_Headers_1f) / 3 call PlaySound + +; Move the big star down and left across the screen. ld hl, wOAMBuffer ld bc, $a004 -.asm_70052 +.bigStarLoop push hl push bc -.asm_70054 - ld a, [hl] - add $4 +.bigStarInnerLoop + ld a, [hl] ; Y + add 4 ld [hli], a - ld a, [hl] - add $fc + ld a, [hl] ; X + add -4 ld [hli], a inc hl inc hl dec c - jr nz, .asm_70054 - ld c, $1 + jr nz, .bigStarInnerLoop + ld c, 1 call CheckForUserInterruption pop bc pop hl ret c ld a, [hl] - cp $50 - jr nz, .asm_70070 - jr .asm_70052 -.asm_70070 + cp 80 + jr nz, .next + jr .bigStarLoop +.next cp b - jr nz, .asm_70052 + jr nz, .bigStarLoop + +; Clear big star OAM. ld hl, wOAMBuffer - ld c, $4 - ld de, $4 -.asm_7007b - ld [hl], $a0 + ld c, 4 + ld de, 4 +.clearOAMLoop + ld [hl], 160 add hl, de dec c - jr nz, .asm_7007b - ld b, $3 -.asm_70083 + jr nz, .clearOAMLoop + +; Make Gamefreak logo flash. + ld b, 3 +.flashLogoLoop ld hl, rOBP0 rrc [hl] rrc [hl] - ld c, $a + ld c, 10 call CheckForUserInterruption ret c dec b - jr nz, .asm_70083 + jr nz, .flashLogoLoop + +; Copy 24 instances of the small stars OAM data. +; Note that their coordinates put them off-screen. ld de, wOAMBuffer - ld a, $18 -.asm_70098 + ld a, 24 +.initSmallStarsOAMLoop push af - ld hl, OAMData_700ee - ld bc, $4 + ld hl, SmallStarsOAM + ld bc, 4 call CopyData pop af dec a - jr nz, .asm_70098 + jr nz, .initSmallStarsOAMLoop + +; Animate the small stars falling from the Gamefreak logo. xor a - ld [wWhichTrade], a - ld hl, PointerTable_700f2 - ld c, $6 -.asm_700af + ld [wMoveDownSmallStarsOAMCount], a + ld hl, SmallStarsWaveCoordsPointerTable + ld c, 6 +.smallStarsLoop ld a, [hli] ld e, a ld a, [hli] @@ -96,100 +107,109 @@ AnimateShootingStar: ; 70044 (1c:4044) push bc push hl ld hl, wOAMBuffer + $50 - ld c, $4 -.asm_700ba + ld c, 4 +.smallStarsInnerLoop ; introduce new wave of 4 small stars OAM entries ld a, [de] cp $ff - jr z, .asm_700d5 - ld [hli], a + jr z, .next2 + ld [hli], a ; Y inc de ld a, [de] - ld [hli], a + ld [hli], a ; X inc de inc hl inc hl dec c - jr nz, .asm_700ba - ld a, [wWhichTrade] - cp $18 - jr z, .asm_700d5 - add $6 - ld [wWhichTrade], a -.asm_700d5 - call Func_7011f + jr nz, .smallStarsInnerLoop + ld a, [wMoveDownSmallStarsOAMCount] + cp 24 + jr z, .next2 + add 6 ; should be 4, but the extra 2 aren't visible on screen + ld [wMoveDownSmallStarsOAMCount], a +.next2 + call MoveDownSmallStars push af + +; shift the existing OAM entries down to make room for the next wave ld hl, wOAMBuffer + $10 ld de, wOAMBuffer ld bc, $50 call CopyData + pop af pop hl pop bc ret c dec c - jr nz, .asm_700af + jr nz, .smallStarsLoop and a ret -OAMData_700ee: ; 700ee (1c:40ee) +SmallStarsOAM: ; 700ee (1c:40ee) db $00,$00,$A2,$90 -PointerTable_700f2: ; 700f2 (1c:40f2) - dw OAMData_700fe - dw OAMData_70106 - dw OAMData_7010e - dw OAMData_70116 - dw OAMData_7011e - dw OAMData_7011e +SmallStarsWaveCoordsPointerTable: ; 700f2 (1c:40f2) + dw SmallStarsWave1Coords + dw SmallStarsWave2Coords + dw SmallStarsWave3Coords + dw SmallStarsWave4Coords + dw SmallStarsEmptyWave + dw SmallStarsEmptyWave -; each entry is only half of an OAM tile -OAMData_700fe: ; 700fe (1c:40fe) +; The stars that fall from the Gamefreak logo come in 4 waves of 4 OAM entries. +; These arrays contain the Y and X coordinates of each OAM entry. + +SmallStarsWave1Coords: ; 700fe (1c:40fe) db $68,$30 db $68,$40 db $68,$58 db $68,$78 -OAMData_70106: ; 70106 (1c:4106) +SmallStarsWave2Coords: ; 70106 (1c:4106) db $68,$38 db $68,$48 db $68,$60 db $68,$70 -OAMData_7010e: ; 7010e (1c:410e) +SmallStarsWave3Coords: ; 7010e (1c:410e) db $68,$34 db $68,$4C db $68,$54 db $68,$64 -OAMData_70116: ; 70116 (1c:4116) +SmallStarsWave4Coords: ; 70116 (1c:4116) db $68,$3C db $68,$5C db $68,$6C db $68,$74 -OAMData_7011e: ; 7011e (1c:411e) +SmallStarsEmptyWave: ; 7011e (1c:411e) db $FF -Func_7011f: ; 7011f (1c:411f) - ld b, $8 -.asm_70121 +MoveDownSmallStars: ; 7011f (1c:411f) + ld b, 8 +.loop ld hl, wOAMBuffer + $5c - ld a, [wWhichTrade] - ld de, $fffc + ld a, [wMoveDownSmallStarsOAMCount] + ld de, -4 ld c, a -.asm_7012b - inc [hl] +.innerLoop + inc [hl] ; Y add hl, de dec c - jr nz, .asm_7012b + jr nz, .innerLoop + +; Toggle the palette so that the lower star in the small stars tile blinks in +; and out. ld a, [rOBP1] - xor $a0 + xor %10100000 ld [rOBP1], a - ld c, $3 + + ld c, 3 call CheckForUserInterruption ret c dec b - jr nz, .asm_70121 + jr nz, .loop ret GameFreakLogoOAMData: ; 70140 (1c:4140) diff --git a/engine/intro.asm b/engine/intro.asm index c306555d..bbe47cdb 100755 --- a/engine/intro.asm +++ b/engine/intro.asm @@ -22,16 +22,16 @@ PlayIntroScene: ; 4169d (10:569d) ld [rOBP1], a xor a ld [hSCX], a - ld b, $3 - call Func_4183f + ld b, $3 ; Gengar tiles + call IntroCopyTiles ld a, 0 ld [W_BASECOORDX], a ld a, 80 ld [W_BASECOORDY], a ld bc, $606 - call Func_417c7 - ld de, $28ff - call Func_4180e + call InitIntroNidorinoOAM + ld de, $28ff ; move Nidorino right by 80 pixels + call IntroMoveMon ret c ; hip @@ -66,22 +66,22 @@ PlayIntroScene: ; 4169d (10:569d) ; raise ld b, $4 - call Func_4183f + call IntroCopyTiles ld a, (SFX_1f_61 - SFX_Headers_1f) / 3 call PlaySound - ld de, $401 - call Func_4180e + ld de, $401 ; move Gengar left by 8 pixels + call IntroMoveMon ld c, $1e call CheckForUserInterruption ret c ; slash ld b, $5 - call Func_4183f + call IntroCopyTiles ld a, (SFX_1f_62 - SFX_Headers_1f) / 3 call PlaySound - ld de, $800 - call Func_4180e + ld de, $800 ; move Gengar right by 16 pixels + call IntroMoveMon ; hip ld a, (SFX_1f_5f - SFX_Headers_1f) / 3 call PlaySound @@ -93,10 +93,10 @@ PlayIntroScene: ; 4169d (10:569d) call CheckForUserInterruption ret c - ld de, $401 - call Func_4180e + ld de, $401 ; move Gengar left by 8 pixels + call IntroMoveMon ld b, $3 - call Func_4183f + call IntroCopyTiles ld c, $3c call CheckForUserInterruption ret c @@ -142,19 +142,19 @@ AnimateIntroNidorino: ; 41793 (10:5793) ld a, [de] ld [W_BASECOORDX], a push de - ld c, $24 - call Func_417ae + ld c, 6 * 6 + call UpdateIntroNidorinoOAM ld c, 5 call DelayFrames pop de inc de jr AnimateIntroNidorino -Func_417ae: ; 417ae (10:57ae) +UpdateIntroNidorinoOAM: ; 417ae (10:57ae) ld hl, wOAMBuffer ld a, [wd09f] ld d, a -.asm_417b5 +.loop ld a, [W_BASECOORDY] add [hl] ld [hli], a @@ -166,105 +166,111 @@ Func_417ae: ; 417ae (10:57ae) inc hl inc d dec c - jr nz, .asm_417b5 + jr nz, .loop ret -Func_417c7: ; 417c7 (10:57c7) +InitIntroNidorinoOAM: ; 417c7 (10:57c7) ld hl, wOAMBuffer - ld d, $0 -.asm_417cc + ld d, 0 +.loop push bc ld a, [W_BASECOORDY] ld e, a -.asm_417d1 +.innerLoop ld a, e - add $8 + add 8 ld e, a - ld [hli], a + ld [hli], a ; Y ld a, [W_BASECOORDX] - ld [hli], a + ld [hli], a ; X ld a, d - ld [hli], a + ld [hli], a ; tile ld a, $80 - ld [hli], a + ld [hli], a ; attributes inc d dec c - jr nz, .asm_417d1 + jr nz, .innerLoop ld a, [W_BASECOORDX] - add $8 + add 8 ld [W_BASECOORDX], a pop bc dec b - jr nz, .asm_417cc + jr nz, .loop ret -Func_417f0: ; 417f0 (10:57f0) +IntroClearScreen: ; 417f0 (10:57f0) ld hl, vBGMap1 ld bc, $240 - jr asm_417fe + jr IntroClearCommon -Func_417f8: ; 417f8 (10:57f8) +IntroClearMiddleOfScreen: ; 417f8 (10:57f8) +; clear the area of the tile map between the black bars on the top and bottom hlCoord 0, 4 - ld bc, $c8 -asm_417fe: ; 417fe (10:57fe) + ld bc, SCREEN_WIDTH * 10 + +IntroClearCommon: ; 417fe (10:57fe) ld [hl], $0 inc hl dec bc ld a, b or c - jr nz, asm_417fe + jr nz, IntroClearCommon ret -Func_41807: ; 41807 (10:5807) +IntroPlaceBlackTiles: ; 41807 (10:5807) ld a, $1 -.asm_41809 +.loop ld [hli], a dec c - jr nz, .asm_41809 + jr nz, .loop ret -Func_4180e: ; 4180e (10:580e) +IntroMoveMon: ; 4180e (10:580e) +; d = number of times to move the mon (2 pixels each time) +; e: $00 = move Gengar right, $01 = move Gengar left, $ff = move Nidorino right ld a, e cp $ff - jr z, .asm_4181d + jr z, .moveNidorinoRight cp $1 - jr z, .asm_4182d + jr z, .moveGengarLeft +; move Gengar right ld a, [hSCX] dec a dec a - jr .asm_41831 -.asm_4181d + jr .next +.moveNidorinoRight push de - ld a, $2 + ld a, 2 ld [W_BASECOORDX], a xor a ld [W_BASECOORDY], a - ld c, $24 - call Func_417ae + ld c, 6 * 6 + call UpdateIntroNidorinoOAM pop de -.asm_4182d +.moveGengarLeft ld a, [hSCX] inc a inc a -.asm_41831 +.next ld [hSCX], a push de - ld c, $2 + ld c, 2 call CheckForUserInterruption pop de ret c dec d - jr nz, Func_4180e + jr nz, IntroMoveMon ret -Func_4183f: ; 4183f (10:583f) +IntroCopyTiles: ; 4183f (10:583f) hlCoord 13, 7 CopyTileIDsFromList_ZeroBaseTileID: ; 41842 (10:5842) - ld c, $0 + ld c, 0 predef_jump CopyTileIDsFromList -Func_41849: ; 41849 (10:5849) +PlayMoveSoundB: ; 41849 (10:5849) +; unused predef GetMoveSoundB ld a, b jp PlaySound @@ -303,7 +309,7 @@ PlayShootingStar: ; 4188a (10:588a) call DisableLCD xor a ld [W_CUROPPONENT], a - call Func_418e9 + call IntroDrawBlackBars call LoadIntroGraphics call EnableLCD ld hl, rLCDC @@ -314,36 +320,37 @@ PlayShootingStar: ; 4188a (10:588a) callba AnimateShootingStar push af pop af - jr c, .asm_418d0 + jr c, .next ; skip the delay if the user interrupted the animation ld c, 40 call DelayFrames -.asm_418d0 +.next ld a, BANK(Music_IntroBattle) ld [wc0ef], a ld [wc0f0], a ld a, MUSIC_INTRO_BATTLE ld [wc0ee], a call PlaySound - call Func_417f8 + call IntroClearMiddleOfScreen call ClearSprites jp Delay3 -Func_418e9: ; 418e9 (10:58e9) - call Func_417f0 +IntroDrawBlackBars: ; 418e9 (10:58e9) +; clear the screen and draw black bars on the top and bottom + call IntroClearScreen hlCoord 0, 0 - ld c, $50 - call Func_41807 + ld c, SCREEN_WIDTH * 4 + call IntroPlaceBlackTiles hlCoord 0, 14 - ld c, $50 - call Func_41807 + ld c, SCREEN_WIDTH * 4 + call IntroPlaceBlackTiles ld hl, vBGMap1 ld c, $80 - call Func_41807 + call IntroPlaceBlackTiles ld hl, vBGMap1 + $1c0 ld c, $80 - jp Func_41807 + jp IntroPlaceBlackTiles -Func_4190c: ; 4190c (10:590c) +EmptyFunc4: ; 4190c (10:590c) ret IntroNidorinoAnimation0: ; 4190d (10:590d) diff --git a/engine/menu/diploma.asm b/engine/menu/diploma.asm index a90abdb5..33453a53 100755 --- a/engine/menu/diploma.asm +++ b/engine/menu/diploma.asm @@ -36,19 +36,23 @@ DisplayDiploma: ; 566e2 (15:66e2) hlCoord 10, 4 ld de, wPlayerName call PlaceString - callba Func_44dd + callba DrawPlayerCharacter + +; Move the player 33 pixels right and set the priority bit so he appears +; behind the background layer. ld hl, wOAMBuffer + $01 ld bc, $8028 -.asm_5673e - ld a, [hl] - add $21 +.adjustPlayerGfxLoop + ld a, [hl] ; X + add 33 ld [hli], a inc hl ld a, b - ld [hli], a + ld [hli], a ; attributes inc hl dec c - jr nz, .asm_5673e + jr nz, .adjustPlayerGfxLoop + call EnableLCD callba LoadTrainerInfoTextBoxTiles ld b, $8 @@ -65,15 +69,17 @@ DisplayDiploma: ; 566e2 (15:66e2) call Delay3 jp GBPalNormal -Func_56777: ; 56777 (15:6777) +UnusedPlayerNameLengthFunc: ; 56777 (15:6777) +; Unused function that does a calculation involving the length of the player's +; name. ld hl, wPlayerName ld bc, $ff00 -.asm_5677d +.loop ld a, [hli] - cp $50 + cp "@" ret z dec c - jr .asm_5677d + jr .loop DiplomaTextPointersAndCoords: ; 56784 (15:6784) dw DiplomaText diff --git a/engine/menu/prize_menu.asm b/engine/menu/prize_menu.asm index acc18633..fff8e4c4 100755 --- a/engine/menu/prize_menu.asm +++ b/engine/menu/prize_menu.asm @@ -179,11 +179,11 @@ LoadCoinsToSubtract: ; 528b1 (14:68b1) ld hl,wd141 ; first prize's price add hl,de ; get selected prize's price xor a - ld [$FF9F],a + ld [hCoins - 1],a ld a,[hli] - ld [$FFA0],a + ld [hCoins],a ld a,[hl] - ld [$FFA1],a + ld [hCoins + 1],a ret HandlePrizeChoice: ; 528c6 (14:68c6) @@ -239,7 +239,7 @@ HandlePrizeChoice: ; 528c6 (14:68c6) ret nc .SubtractCoins call LoadCoinsToSubtract - ld hl,$FFA1 + ld hl,hCoins + 1 ld de,wPlayerCoins + 1 ld c,$02 ; how many bytes predef SubBCDPredef ; subtract coins (BCD daa operations) diff --git a/engine/menu/vending_machine.asm b/engine/menu/vending_machine.asm index d5209440..07cf8854 100755 --- a/engine/menu/vending_machine.asm +++ b/engine/menu/vending_machine.asm @@ -7,19 +7,19 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) xor a ld [wCurrentMenuItem], a ld [wLastMenuItem], a - ld a, $3 + ld a, A_BUTTON | B_BUTTON ld [wMenuWatchedKeys], a - ld a, $3 + ld a, 3 ld [wMaxMenuItem], a - ld a, $5 + ld a, 5 ld [wTopMenuItemY], a - ld a, $1 + ld a, 1 ld [wTopMenuItemX], a ld hl, wd730 set 6, [hl] hlCoord 0, 3 - ld b, $8 - ld c, $c + ld b, 8 + ld c, 12 call TextBoxBorder call UpdateSprites hlCoord 2, 5 @@ -31,27 +31,28 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) ld hl, wd730 res 6, [hl] call HandleMenuInput - bit 1, a - jr nz, .asm_74f93 + bit 1, a ; pressed B? + jr nz, .notThirsty ld a, [wCurrentMenuItem] - cp $3 - jr z, .asm_74f93 + cp 3 ; chose Cancel? + jr z, .notThirsty xor a - ld [$ff9f], a - ld [$ffa1], a + ld [hMoney], a + ld [hMoney + 2], a ld a, $2 - ld [$ffa0], a + ld [hMoney + 1], a call HasEnoughMoney jr nc, .enoughMoney ld hl, VendingMachineText4 jp PrintText .enoughMoney - call Func_74fe7 - ld a, [$ffdb] + call LoadVendingMachineItem + ld a, [hVendingMachineItem] ld b, a ld c, 1 call GiveItem jr nc, .BagFull + ld b, 60 ; number of times to play the "brrrrr" sound .playDeliverySound ld c, 2 @@ -62,10 +63,10 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) pop bc dec b jr nz, .playDeliverySound -.asm_74f72 + ld hl, VendingMachineText5 call PrintText - ld hl, $ffde + ld hl, hVendingMachinePrice + 2 ld de, wPlayerMoney + 2 ld c, $3 predef SubBCDPredef @@ -75,7 +76,7 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0) .BagFull ld hl, VendingMachineText6 jp PrintText -.asm_74f93 +.notThirsty ld hl, VendingMachineText7 jp PrintText @@ -110,22 +111,22 @@ VendingMachineText7: ; 74fe2 (1d:4fe2) TX_FAR _VendingMachineText7 db "@" -Func_74fe7: ; 74fe7 (1d:4fe7) +LoadVendingMachineItem: ; 74fe7 (1d:4fe7) ld hl, VendingPrices ld a, [wCurrentMenuItem] add a add a - ld d, $0 + ld d, 0 ld e, a add hl, de ld a, [hli] - ld [$ffdb], a + ld [hVendingMachineItem], a ld a, [hli] - ld [$ffdc], a + ld [hVendingMachinePrice], a ld a, [hli] - ld [$ffdd], a + ld [hVendingMachinePrice + 1], a ld a, [hl] - ld [$ffde], a + ld [hVendingMachinePrice + 2], a ret VendingPrices: ; 75000 (1d:5000) diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm index 868f118f..910fcf04 100755 --- a/engine/overworld/hidden_items.asm +++ b/engine/overworld/hidden_items.asm @@ -67,9 +67,9 @@ HiddenCoins: ; 76799 (1d:6799) and a ret nz xor a - ld [$ff9f], a - ld [$ffa0], a - ld [$ffa1], a + ld [hCoins - 1], a + ld [hCoins], a + ld [hCoins + 1], a ld a, [wWhichTrade] sub COIN cp 10 @@ -81,22 +81,22 @@ HiddenCoins: ; 76799 (1d:6799) jr .bcd100 .bcd10 ld a, $10 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd20 ld a, $20 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd40 ; due to a typo, this is never used ld a, $40 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd100 ld a, $1 - ld [$ffa0], a + ld [hCoins], a .bcddone ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef ld hl, wd6fe diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm index aabc2de8..fcef55e0 100755 --- a/engine/overworld/npc_movement.asm +++ b/engine/overworld/npc_movement.asm @@ -74,7 +74,7 @@ PalletMovementScript_OakMoveLeft: ; 1a44c (6:644c) jr .done ; The player is on the left tile of the northern path out of Pallet Town and ; Prof. Oak is below. -; Prof. Oak is already on the right tile. +; Prof. Oak is already where he needs to be. .playerOnLeftTile ld a, $3 ld [wNPCMovementScriptFunctionNum], a diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm index 2caada1d..e6fdfc92 100755 --- a/engine/overworld/pokemart.asm +++ b/engine/overworld/pokemart.asm @@ -206,7 +206,7 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) jp .loop .isThereEnoughMoney ld de,wPlayerMoney - ld hl,$ff9f ; item price + ld hl,hMoney ld c,3 ; length of money in bytes jp StringCmp .notEnoughMoney diff --git a/engine/titlescreen.asm b/engine/titlescreen.asm index 7230f08f..74f7ad61 100755 --- a/engine/titlescreen.asm +++ b/engine/titlescreen.asm @@ -67,50 +67,60 @@ ENDC ld a, BANK(Version_GFX) call FarCopyDataDouble - call Func_4519 + call ClearBothBGMaps + +; place tiles for pokemon logo (except for the last row) hlCoord 2, 1 ld a, $80 ld de, SCREEN_WIDTH - ld c, $6 -.asm_434d + ld c, 6 +.pokemonLogoTileLoop ld b, $10 push hl -.asm_4350 +.pokemonLogoTileRowLoop ; place tiles for one row ld [hli], a inc a dec b - jr nz, .asm_4350 + jr nz, .pokemonLogoTileRowLoop pop hl add hl, de dec c - jr nz, .asm_434d + jr nz, .pokemonLogoTileLoop + +; place tiles for the last row of the pokemon logo hlCoord 2, 7 ld a, $31 ld b, $10 -.asm_4361 +.pokemonLogoLastTileRowLoop ld [hli], a inc a dec b - jr nz, .asm_4361 - call Func_44dd + jr nz, .pokemonLogoLastTileRowLoop + + call DrawPlayerCharacter + +; put a pokeball in the player's hand ld hl, wOAMBuffer + $28 ld a, $74 ld [hl], a + +; place tiles for title screen copyright hlCoord 2, 17 - ld de, .titlescreenTilemap + ld de, .tileScreenCopyrightTiles ld b, $10 -.asm_4377 +.tileScreenCopyrightTilesLoop ld a, [de] ld [hli], a inc de dec b - jr nz, .asm_4377 - jr .asm_438f + jr nz, .tileScreenCopyrightTilesLoop -.titlescreenTilemap ; 437f (1:437f) + jr .next + +.tileScreenCopyrightTiles ; 437f (1:437f) db $41,$42,$43,$42,$44,$42,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E ; ©'95.'96.'98 GAME FREAK inc. -.asm_438f +.next call SaveScreenTilesToBuffer2 call LoadScreenTilesFromBuffer2 call EnableLCD @@ -121,37 +131,39 @@ IF DEF(_BLUE) ld a,SQUIRTLE ; which Pokemon to show first on the title screen ENDC - ld [wWhichTrade], a - call Func_4524 - ld a, $9b - call Func_4533 + ld [wTitleMonSpecies], a + call LoadTitleMonSprite + ld a, (vBGMap0 + $300) / $100 + call TitleScreenCopyTileMapToVRAM call SaveScreenTilesToBuffer1 ld a, $40 ld [hWY], a call LoadScreenTilesFromBuffer2 - ld a, $98 - call Func_4533 + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM ld b, $6 call GoPAL_SET call GBPalNormal - ld a, $e4 + ld a, %11100100 ld [rOBP0], a - ld bc, $ffaf ; background scroll Y + +; make pokemon logo bounce up and down + ld bc, hSCY ; background scroll Y ld hl, .TitleScreenPokemonLogoYScrolls -.asm_43c6 +.bouncePokemonLogoLoop ld a, [hli] and a - jr z, .asm_43f4 + jr z, .finishedBouncingPokemonLogo ld d, a - cp $fd - jr nz, .asm_43d4 + cp -3 + jr nz, .skipPlayingSound ld a, (SFX_1f_62 - SFX_Headers_1f) / 3 call PlaySound -.asm_43d4 +.skipPlayingSound ld a, [hli] ld e, a call .ScrollTitleScreenPokemonLogo - jr .asm_43c6 + jr .bouncePokemonLogoLoop .TitleScreenPokemonLogoYScrolls: ; 43db (1:43db) ; Controls the bouncing effect of the Pokemon logo on the title screen @@ -168,36 +180,40 @@ ENDC ; Scrolls the Pokemon logo on the title screen to create the bouncing effect ; Scrolls d pixels e times call DelayFrame - ld a, [bc] + ld a, [bc] ; background scroll Y add d ld [bc], a dec e jr nz, .ScrollTitleScreenPokemonLogo ret -.asm_43f4 + +.finishedBouncingPokemonLogo call LoadScreenTilesFromBuffer1 ld c, 36 call DelayFrames ld a, (SFX_1f_63 - SFX_Headers_1f) / 3 call PlaySound + +; scroll game version in from the right call PrintGameVersionOnTitleScreen - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a - ld d, $90 -.asm_440a + ld d, 144 +.scrollTitleScreenGameVersionLoop ld h, d - ld l, $40 - call Func_44cf - ld h, $0 - ld l, $50 - call Func_44cf + ld l, 64 + call ScrollTitleScreenGameVersion + ld h, 0 + ld l, 80 + call ScrollTitleScreenGameVersion ld a, d - add $4 + add 4 ld d, a and a - jr nz, .asm_440a - ld a, $9c - call Func_4533 + jr nz, .scrollTitleScreenGameVersionLoop + + ld a, vBGMap1 / $100 + call TitleScreenCopyTileMapToVRAM call LoadScreenTilesFromBuffer2 call PrintGameVersionOnTitleScreen call Delay3 @@ -207,19 +223,22 @@ ENDC call PlaySound xor a ld [wcc5b], a -.asm_443b - ld c, $c8 + +; Keep scrolling in new mons indefinitely until the user performs input. +.awaitUserInterruptionLoop + ld c, 200 call CheckForUserInterruption - jr c, .asm_4459 - call Func_44c1 - ld c, $1 + jr c, .finishedWaiting + call TitleScreenScrollInMon + ld c, 1 call CheckForUserInterruption - jr c, .asm_4459 - callba Func_372ac - call Func_4496 - jr .asm_443b -.asm_4459 - ld a, [wWhichTrade] + jr c, .finishedWaiting + callba TitleScreenAnimateBallIfStarterOut + call TitleScreenPickNewMon + jr .awaitUserInterruptionLoop + +.finishedWaiting + ld a, [wTitleMonSpecies] call PlayCry call WaitForSoundToFinish call GBPalWhiteOutWithDelay3 @@ -229,10 +248,10 @@ ENDC inc a ld [H_AUTOBGTRANSFERENABLED], a call ClearScreen - ld a, $98 - call Func_4533 - ld a, $9c - call Func_4533 + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM + ld a, vBGMap1 / $100 + call TitleScreenCopyTileMapToVRAM call Delay3 call LoadGBPal ld a, [hJoyHeld] @@ -247,12 +266,12 @@ ENDC ld hl, DoClearSaveDialogue jp Bankswitch -Func_4496: ; 4496 (1:4496) - ld a, $98 - call Func_4533 +TitleScreenPickNewMon: ; 4496 (1:4496) + ld a, vBGMap0 / $100 + call TitleScreenCopyTileMapToVRAM -.new -; Generate a new TitleMon. +.loop +; Keep looping until a mon different from the current one is picked. call Random and $f ld c, a @@ -260,14 +279,14 @@ Func_4496: ; 4496 (1:4496) ld hl, TitleMons add hl, bc ld a, [hl] - ld hl, wWhichTrade + ld hl, wTitleMonSpecies ; Can't be the same as before. cp [hl] - jr z, .new + jr z, .loop ld [hl], a - call Func_4524 + call LoadTitleMonSprite ld a, $90 ld [hWY], a @@ -275,14 +294,14 @@ Func_4496: ; 4496 (1:4496) callba TitleScroll ret -Func_44c1: ; 44c1 (1:44c1) +TitleScreenScrollInMon: ; 44c1 (1:44c1) ld d, 0 ; scroll in callba TitleScroll xor a ld [hWY], a ret -Func_44cf: ; 44cf (1:44cf) +ScrollTitleScreenGameVersion: ; 44cf (1:44cf) .wait ld a, [rLY] cp l @@ -297,7 +316,7 @@ Func_44cf: ; 44cf (1:44cf) jr z, .wait2 ret -Func_44dd: ; 44dd (1:44dd) +DrawPlayerCharacter: ; 44dd (1:44dd) ld hl, PlayerCharacterTitleGraphics ld de, vSprites ld bc, $230 @@ -305,49 +324,49 @@ Func_44dd: ; 44dd (1:44dd) call FarCopyData2 call ClearSprites xor a - ld [wWhichTrade], a + ld [wPlayerCharacterOAMTile], a ld hl, wOAMBuffer ld de, $605a - ld b, $7 -.asm_44fa + ld b, 7 +.loop push de - ld c, $5 -.asm_44fd + ld c, 5 +.innerLoop ld a, d - ld [hli], a + ld [hli], a ; Y ld a, e - ld [hli], a - add $8 + ld [hli], a ; X + add 8 ld e, a - ld a, [wWhichTrade] - ld [hli], a + ld a, [wPlayerCharacterOAMTile] + ld [hli], a ; tile inc a - ld [wWhichTrade], a + ld [wPlayerCharacterOAMTile], a inc hl dec c - jr nz, .asm_44fd + jr nz, .innerLoop pop de - ld a, $8 + ld a, 8 add d ld d, a dec b - jr nz, .asm_44fa + jr nz, .loop ret -Func_4519: ; 4519 (1:4519) +ClearBothBGMaps: ; 4519 (1:4519) ld hl, vBGMap0 - ld bc, $800 - ld a, $7f + ld bc, $400 * 2 + ld a, " " jp FillMemory -Func_4524: ; 4524 (1:4524) +LoadTitleMonSprite: ; 4524 (1:4524) ld [wcf91], a ld [wd0b5], a hlCoord 5, 10 call GetMonHeader jp LoadFrontSpriteByMonIndex -Func_4533: ; 4533 (1:4533) +TitleScreenCopyTileMapToVRAM: ; 4533 (1:4533) ld [H_AUTOBGTRANSFERDEST + 1], a jp Delay3 diff --git a/engine/titlescreen2.asm b/engine/titlescreen2.asm index 61b97edc..c0853a0d 100755 --- a/engine/titlescreen2.asm +++ b/engine/titlescreen2.asm @@ -87,9 +87,9 @@ TitleBallYTable: ; 372a0 (d:72a0) ; This is really two 0-terminated lists. Initiated with an index of 1. db 0, $71, $6f, $6e, $6d, $6c, $6d, $6e, $6f, $71, $74, 0 -Func_372ac: ; 372ac (d:72ac) +TitleScreenAnimateBallIfStarterOut: ; 372ac (d:72ac) ; Animate the TitleBall if a starter just got scrolled out. - ld a, [wWhichTrade] + ld a, [wTitleMonSpecies] cp STARTER1 jr z, .ok cp STARTER2 diff --git a/home.asm b/home.asm index 430be975..38a95742 100644 --- a/home.asm +++ b/home.asm @@ -1630,15 +1630,15 @@ DisplayChooseQuantityMenu:: ; 2d57 (0:2d57) ld c,$03 ld a,[wItemQuantity] ld b,a - ld hl,$ff9f ; total price + ld hl,hMoney ; total price ; initialize total price to 0 xor a ld [hli],a ld [hli],a ld [hl],a .addLoop ; loop to multiply the individual price by the quantity to get the total price - ld de,$ffa1 - ld hl,$ff8d + ld de,hMoney + 2 + ld hl,hItemPrice + 2 push bc predef AddBCDPredef ; add the individual price to the current sum pop bc @@ -1648,23 +1648,23 @@ DisplayChooseQuantityMenu:: ; 2d57 (0:2d57) and a ; should the price be halved (for selling items)? jr z,.skipHalvingPrice xor a - ld [$ffa2],a - ld [$ffa3],a + ld [hDivideBCDDivisor],a + ld [hDivideBCDDivisor + 1],a ld a,$02 - ld [$ffa4],a + ld [hDivideBCDDivisor + 2],a predef DivideBCDPredef3 ; halves the price ; store the halved price - ld a,[$ffa2] - ld [$ff9f],a - ld a,[$ffa3] - ld [$ffa0],a - ld a,[$ffa4] - ld [$ffa1],a + ld a,[hDivideBCDQuotient] + ld [hMoney],a + ld a,[hDivideBCDQuotient + 1] + ld [hMoney + 1],a + ld a,[hDivideBCDQuotient + 2] + ld [hMoney + 2],a .skipHalvingPrice hlCoord 12, 10 ld de,SpacesBetweenQuantityAndPriceText call PlaceString - ld de,$ff9f ; total price + ld de,hMoney ; total price ld c,$a3 call PrintBCDNumber hlCoord 9, 10 @@ -2942,17 +2942,17 @@ GetTrainerName:: ; 359e (0:359e) HasEnoughMoney:: ; Check if the player has at least as much -; money as the 3-byte BCD value at $ff9f. +; money as the 3-byte BCD value at hMoney. ld de, wPlayerMoney - ld hl, $ff9f + ld hl, hMoney ld c, 3 jp StringCmp HasEnoughCoins:: ; Check if the player has at least as many -; coins as the 2-byte BCD value at $ffa0. +; coins as the 2-byte BCD value at hCoins. ld de, wPlayerCoins - ld hl, $ffa0 + ld hl, hCoins ld c, 2 jp StringCmp diff --git a/hram.asm b/hram.asm index acc66a65..b0d5a942 100644 --- a/hram.asm +++ b/hram.asm @@ -92,6 +92,12 @@ hNPCPlayerRelativePosPerspective EQU $FF9B ; 1 = target is to the west hNPCPlayerRelativePosFlags EQU $FF9D +hMoney EQU $FF9F ; 3-byte BCD number +hCoins EQU $FFA0 ; 2-byte BCD number + +hDivideBCDDivisor EQU $FFA2 ; 3-byte BCD number +hDivideBCDQuotient EQU $FFA2 ; 3-byte BCD number + hSerialReceivedNewData EQU $FFA9 ; $01 = using external clock @@ -201,6 +207,9 @@ hTilesetType EQU $FFD7 H_CURRENTSPRITEOFFSET EQU $FFDA ; multiple of $10 +hVendingMachineItem EQU $FFDB +hVendingMachinePrice EQU $FFDC ; 3-byte BCD number + hNewPartyLength EQU $FFE4 hDividend2 EQU $FFE5 diff --git a/main.asm b/main.asm index 1bff6a4e..3bc5989a 100755 --- a/main.asm +++ b/main.asm @@ -31,30 +31,30 @@ ResetStatusAndHalveMoneyOnBlackout:: ld [wNPCMovementScriptPointerTableNum], a ld [wFlags_0xcd60], a - ld [$ff9f], a - ld [$ff9f + 1], a - ld [$ff9f + 2], a + ld [hMoney], a + ld [hMoney + 1], a + ld [hMoney + 2], a call HasEnoughMoney jr c, .lostmoney ; never happens ; Halve the player's money. ld a, [wPlayerMoney] - ld [$ff9f], a + ld [hMoney], a ld a, [wPlayerMoney + 1] - ld [$ff9f + 1], a + ld [hMoney + 1], a ld a, [wPlayerMoney + 2] - ld [$ff9f + 2], a + ld [hMoney + 2], a xor a - ld [$ffa2], a - ld [$ffa3], a + ld [hDivideBCDDivisor], a + ld [hDivideBCDDivisor + 1], a ld a, 2 - ld [$ffa4], a + ld [hDivideBCDDivisor + 2], a predef DivideBCDPredef3 - ld a, [$ffa2] + ld a, [hDivideBCDQuotient] ld [wPlayerMoney], a - ld a, [$ffa2 + 1] + ld a, [hDivideBCDQuotient + 1] ld [wPlayerMoney + 1], a - ld a, [$ffa2 + 2] + ld a, [hDivideBCDQuotient + 2] ld [wPlayerMoney + 2], a .lostmoney @@ -789,12 +789,12 @@ INCLUDE "engine/oak_speech2.asm" ; sets carry flag if there is enough money and unsets carry flag if not SubtractAmountPaidFromMoney_: ; 6b21 (1:6b21) ld de,wPlayerMoney - ld hl,$ff9f ; total price of items + ld hl,hMoney ; total price of items ld c,3 ; length of money in bytes call StringCmp ret c ld de,wPlayerMoney + 2 - ld hl,$ffa1 ; total price of items + ld hl,hMoney + 2 ; total price of items ld c,3 ; length of money in bytes predef SubBCDPredef ; subtract total price from money ld a,MONEY_BOX diff --git a/scripts/celadongamecorner.asm b/scripts/celadongamecorner.asm index 9c6c4408..3bcdf3a3 100755 --- a/scripts/celadongamecorner.asm +++ b/scripts/celadongamecorner.asm @@ -151,31 +151,31 @@ CeladonGameCornerText2: ; 48ca9 (12:4ca9) call Has9990Coins jr nc, .asm_48d14 xor a - ld [$ff9f], a - ld [$ffa1], a + ld [hMoney], a + ld [hMoney + 2], a ld a, $10 - ld [$ffa0], a + ld [hMoney + 1], a call HasEnoughMoney jr nc, .asm_48cdb ld hl, CeladonGameCornerText_48d31 jr .asm_48d1c .asm_48cdb xor a - ld [$ff9f], a - ld [$ffa1], a + ld [hMoney], a + ld [hMoney + 2], a ld a, $10 - ld [$ffa0], a - ld hl, $ffa1 + ld [hMoney + 1], a + ld hl, hMoney + 2 ld de, wPlayerMoney + 2 ld c, $3 predef SubBCDPredef xor a - ld [$ff9f], a - ld [$ffa0], a + ld [hCoins - 1], a + ld [hCoins], a ld a, $50 - ld [$ffa1], a + ld [hCoins + 1], a ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef call CeladonGameCornerScript_48f1e @@ -238,12 +238,12 @@ CeladonGameCornerText5: ; 48d4a (12:4d4a) call Has9990Coins jr nc, .asm_48d8e xor a - ld [$ff9f], a - ld [$ffa0], a + ld [hCoins - 1], a + ld [hCoins], a ld a, $10 - ld [$ffa1], a + ld [hCoins + 1], a ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef ld hl, wd77e @@ -320,12 +320,12 @@ CeladonGameCornerText9: ; 48dd9 (12:4dd9) call Has9990Coins jr nc, .asm_48e18 xor a - ld [$ff9f], a - ld [$ffa0], a + ld [hCoins - 1], a + ld [hCoins], a ld a, $20 - ld [$ffa1], a + ld [hCoins + 1], a ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef ld hl, wd77e @@ -373,12 +373,12 @@ CeladonGameCornerText10: ; 48e3b (12:4e3b) call Has9990Coins jr z, .asm_48e7a xor a - ld [$ff9f], a - ld [$ffa0], a + ld [hCoins - 1], a + ld [hCoins], a ld a, $20 - ld [$ffa1], a + ld [hCoins + 1], a ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef ld hl, wd77e @@ -527,7 +527,7 @@ GameCornerBlankText2: ; 48f8d (12:4f8d) Has9990Coins: ; 48f95 (12:4f95) ld a, $99 - ld [$ffa0], a + ld [hCoins], a ld a, $90 - ld [$ffa1], a + ld [hCoins + 1], a jp HasEnoughCoins diff --git a/scripts/daycarem.asm b/scripts/daycarem.asm index 2196e021..330f2234 100755 --- a/scripts/daycarem.asm +++ b/scripts/daycarem.asm @@ -137,11 +137,11 @@ DayCareMScript_562e1: ; 562e1 (15:62e1) and a jp nz, .asm_56403 ld hl, wTrainerFacingDirection - ld [$ff9f], a + ld [hMoney], a ld a, [hli] - ld [$ffa0], a + ld [hMoney + 1], a ld a, [hl] - ld [$ffa1], a + ld [hMoney + 2], a call HasEnoughMoney jr nc, .asm_56396 ld hl, DayCareMText_56454 diff --git a/scripts/mtmoonpokecenter.asm b/scripts/mtmoonpokecenter.asm index b06c4df0..bba73dbd 100755 --- a/scripts/mtmoonpokecenter.asm +++ b/scripts/mtmoonpokecenter.asm @@ -35,10 +35,10 @@ MtMoonPokecenterText4: ; 492ec (12:52ec) ld a, [wCurrentMenuItem] and a jp nz, .asm_4934e - ld [$ff9f], a - ld [$ffa1], a + ld [hMoney], a + ld [hMoney + 2], a ld a, $5 - ld [$ffa0], a + ld [hMoney + 1], a call HasEnoughMoney jr nc, .asm_faa09 ld hl, MtMoonPokecenterText_49366 diff --git a/scripts/museum1f.asm b/scripts/museum1f.asm index 38fddb26..26c7f02d 100755 --- a/scripts/museum1f.asm +++ b/scripts/museum1f.asm @@ -81,10 +81,10 @@ Museum1FText1: ; 5c135 (17:4135) and a jr nz, .asm_de133 xor a - ld [$ff9f], a - ld [$ffa0], a + ld [hMoney], a + ld [hMoney + 1], a ld a, $50 - ld [$ffa1], a + ld [hMoney + 2], a call HasEnoughMoney jr nc, .asm_0f3e3 ld hl, Museum1FText_5c229 diff --git a/scripts/safarizoneentrance.asm b/scripts/safarizoneentrance.asm index 6cbb0925..2edbe61b 100755 --- a/scripts/safarizoneentrance.asm +++ b/scripts/safarizoneentrance.asm @@ -155,11 +155,11 @@ SafariZoneEntranceTextPointers: ; 752b9 (1d:52b9) and a jp nz,.PleaseComeAgain xor a - ld [$ff9f],a + ld [hMoney],a ld a,$05 - ld [$ffa0],a + ld [hMoney + 1],a ld a,$00 - ld [$ffa1],a + ld [hMoney + 2],a call HasEnoughMoney jr nc,.success ld hl,.NotEnoughMoneyText diff --git a/text.asm b/text.asm index ac53f65f..ecc3beea 100644 --- a/text.asm +++ b/text.asm @@ -15,7 +15,7 @@ POKEDEX_TEXT EQU $2b MOVE_NAMES EQU $2c INCLUDE "macros.asm" - +INCLUDE "hram.asm" SECTION "Text 1", ROMX, BANK[TEXT_1] @@ -1015,13 +1015,13 @@ _HiddenItemBagFullText:: ; 894e1 (22:54e1) _FoundHiddenCoinsText:: ; 8950b (22:550b) text $52, " found" line "@" - TX_BCD $ffa0, $c2 + TX_BCD hCoins, $c2 text " coins!@@" _FoundHiddenCoins2Text:: ; 89523 (22:5523) text $52, " found" line "@" - TX_BCD $ffa0, $c2 + TX_BCD hCoins, $c2 text " coins!@@" _DroppedHiddenCoinsText:: ; 8953b (22:553b) @@ -2635,7 +2635,7 @@ _PokemartTellBuyPriceText:: ; a2619 (28:6619) text "?" line "That will be" cont "¥@" - TX_BCD $ff9f, $c3 + TX_BCD hMoney, $c3 text ". OK?" done @@ -2662,7 +2662,7 @@ _PokemonSellingGreetingText:: ; a2690 (28:6690) _PokemartTellSellPriceText:: ; a26ae (28:66ae) text "I can pay you" line "¥@" - TX_BCD $ff9f, $c3 + TX_BCD hMoney, $c3 text " for that." done diff --git a/wram.asm b/wram.asm index fe632e20..6eef4ea8 100755 --- a/wram.asm +++ b/wram.asm @@ -634,6 +634,13 @@ wOverrideSimulatedJoypadStatesMask:: ; cd3b ds 1 +wTitleMonSpecies:: ; cd3d + +wPlayerCharacterOAMTile:: ; cd3d + +wMoveDownSmallStarsOAMCount:: ; cd3d +; the number of small stars OAM entries to move down + wChargeMoveNum:: ; cd3d wCoordIndex:: ; cd3d