diff options
author | Rangi <35663410+Rangi42@users.noreply.github.com> | 2020-02-23 14:16:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 14:16:26 -0500 |
commit | ef1c4c5a813595841a2c81105ca0c06e5ea85db0 (patch) | |
tree | e5d59ac8f5a649ba4add7f7a3fa64c09ecfbc6b5 | |
parent | 9a927c1b3efa2eca886f346a4fcca0eb57278faf (diff) | |
parent | 813d0aa73a16ababcf257d4df57ff3b69879b011 (diff) |
Merge pull request #687 from mid-kid/master
Small home/ reorganization
-rw-r--r-- | home.asm | 174 | ||||
-rw-r--r-- | home/array.asm | 44 | ||||
-rw-r--r-- | home/battle.asm | 54 | ||||
-rw-r--r-- | home/call_regs.asm | 8 | ||||
-rw-r--r-- | home/copy.asm | 430 | ||||
-rw-r--r-- | home/copy2.asm | 131 | ||||
-rw-r--r-- | home/cry.asm | 101 | ||||
-rw-r--r-- | home/flag.asm | 27 | ||||
-rw-r--r-- | home/gfx.asm | 391 | ||||
-rw-r--r-- | home/header.asm | 66 | ||||
-rw-r--r-- | home/hp_pals.asm | 17 | ||||
-rw-r--r-- | home/interrupts.asm | 16 | ||||
-rw-r--r-- | home/joypad.asm | 4 | ||||
-rw-r--r-- | home/map.asm | 9 | ||||
-rw-r--r-- | home/math.asm | 10 | ||||
-rw-r--r-- | home/menu.asm | 781 | ||||
-rw-r--r-- | home/menu2.asm | 539 | ||||
-rw-r--r-- | home/menu_window.asm | 242 | ||||
-rw-r--r-- | home/mon_data.asm | 87 | ||||
-rw-r--r-- | home/mon_data_2.asm | 34 | ||||
-rw-r--r-- | home/mon_stats.asm | 104 | ||||
-rw-r--r-- | home/pokedex_flags.asm | 32 | ||||
-rw-r--r-- | home/pokemon.asm | 323 | ||||
-rw-r--r-- | home/print_level.asm | 28 | ||||
-rw-r--r-- | home/print_text.asm | 17 | ||||
-rw-r--r-- | home/printer.asm (renamed from home/handshake.asm) | 0 | ||||
-rw-r--r-- | home/region.asm | 3 | ||||
-rw-r--r-- | home/rst.asm | 35 | ||||
-rw-r--r-- | home/sprite_anims.asm | 19 | ||||
-rw-r--r-- | home/tilemap.asm | 18 | ||||
-rw-r--r-- | home/time_palettes.asm (renamed from home/rtc.asm) | 0 | ||||
-rw-r--r-- | home/vblank.asm | 6 |
32 files changed, 1871 insertions, 1879 deletions
@@ -1,30 +1,16 @@ INCLUDE "constants.asm" - SECTION "NULL", ROM0 - NULL:: - -INCLUDE "home/rst.asm" - - -INCLUDE "home/interrupts.asm" - - -SECTION "Header", ROM0 - -Start:: - nop - jp _Start - +INCLUDE "home/header.asm" SECTION "Home", ROM0 INCLUDE "home/init.asm" INCLUDE "home/vblank.asm" INCLUDE "home/delay.asm" -INCLUDE "home/rtc.asm" +INCLUDE "home/time_palettes.asm" INCLUDE "home/fade.asm" INCLUDE "home/lcd.asm" INCLUDE "home/time.asm" @@ -32,189 +18,45 @@ INCLUDE "home/serial.asm" INCLUDE "home/joypad.asm" INCLUDE "home/decompress.asm" INCLUDE "home/palettes.asm" -INCLUDE "home/copy.asm" +INCLUDE "home/gfx.asm" INCLUDE "home/text.asm" INCLUDE "home/video.asm" INCLUDE "home/map_objects.asm" INCLUDE "home/sine.asm" INCLUDE "home/movement.asm" INCLUDE "home/menu.asm" -INCLUDE "home/menu_window.asm" -INCLUDE "home/menu2.asm" -INCLUDE "home/handshake.asm" +INCLUDE "home/printer.asm" INCLUDE "home/game_time.asm" INCLUDE "home/map.asm" - -InexplicablyEmptyFunction:: -; unused -; Inexplicably empty. -; Seen in PredefPointers. -rept 16 - nop -endr - ret - INCLUDE "home/farcall.asm" INCLUDE "home/predef.asm" INCLUDE "home/window.asm" INCLUDE "home/flag.asm" - -Unreferenced_CheckBPressedDebug:: -; Used in debug ROMs to walk through walls and avoid encounters. - - ld a, [wDebugFlags] - bit DEBUG_FIELD_F, a - ret z - - ldh a, [hJoyDown] - bit B_BUTTON_F, a - ret - -xor_a:: - xor a - ret - -xor_a_dec_a:: - xor a - dec a - ret - -Unreferenced_CheckFieldDebug:: - push hl - ld hl, wDebugFlags - bit DEBUG_FIELD_F, [hl] - pop hl - ret - INCLUDE "home/sprite_updates.asm" INCLUDE "home/string.asm" INCLUDE "home/region.asm" - -ret_2f3e:: - ret - INCLUDE "home/item.asm" INCLUDE "home/random.asm" INCLUDE "home/sram.asm" - -; Register aliases - -_hl_:: - jp hl - -_de_:: - push de - ret - +INCLUDE "home/call_regs.asm" INCLUDE "home/double_speed.asm" INCLUDE "home/clear_sprites.asm" -INCLUDE "home/copy2.asm" +INCLUDE "home/copy.asm" INCLUDE "home/copy_tilemap.asm" INCLUDE "home/copy_name.asm" - -IsInArray:: -; Find value a for every de bytes in array hl. -; Return index in b and carry if found. - - ld b, 0 - ld c, a -.loop - ld a, [hl] - cp -1 - jr z, .NotInArray - cp c - jr z, .InArray - inc b - add hl, de - jr .loop - -.NotInArray: - and a - ret - -.InArray: - scf - ret - -SkipNames:: -; Skip a names. - ld bc, NAME_LENGTH - and a - ret z -.loop - add hl, bc - dec a - jr nz, .loop - ret - +INCLUDE "home/array.asm" INCLUDE "home/math.asm" INCLUDE "home/print_text.asm" - -CallPointerAt:: - ldh a, [hROMBank] - push af - ld a, [hli] - rst Bankswitch - - ld a, [hli] - ld h, [hl] - ld l, a - - call _hl_ - - pop hl - ld a, h - rst Bankswitch - ret - INCLUDE "home/queue_script.asm" INCLUDE "home/compare.asm" INCLUDE "home/tilemap.asm" -INCLUDE "home/hp_pals.asm" - -CountSetBits:: -; Count the number of set bits in b bytes starting from hl. -; Return in a, c and [wNumSetBits]. - ld c, 0 -.next - ld a, [hli] - ld e, a - ld d, 8 - -.count - srl e - ld a, 0 - adc c - ld c, a - dec d - jr nz, .count - - dec b - jr nz, .next - - ld a, c - ld [wNumSetBits], a - ret - -GetWeekday:: - ld a, [wCurDay] -.mod - sub 7 - jr nc, .mod - add 7 - ret - INCLUDE "home/pokedex_flags.asm" INCLUDE "home/names.asm" INCLUDE "home/scrolling_menu.asm" INCLUDE "home/stone_queue.asm" INCLUDE "home/trainers.asm" -INCLUDE "home/mon_stats.asm" -INCLUDE "home/cry.asm" -INCLUDE "home/print_level.asm" -INCLUDE "home/mon_data.asm" +INCLUDE "home/pokemon.asm" INCLUDE "home/print_bcd.asm" -INCLUDE "home/mon_data_2.asm" INCLUDE "home/battle.asm" INCLUDE "home/sprite_anims.asm" INCLUDE "home/audio.asm" diff --git a/home/array.asm b/home/array.asm new file mode 100644 index 000000000..0abf9b7d3 --- /dev/null +++ b/home/array.asm @@ -0,0 +1,44 @@ +IsInArray:: +; Find value a for every de bytes in array hl. +; Return index in b and carry if found. + + ld b, 0 + ld c, a +.loop + ld a, [hl] + cp -1 + jr z, .NotInArray + cp c + jr z, .InArray + inc b + add hl, de + jr .loop + +.NotInArray: + and a + ret + +.InArray: + scf + ret + +SkipNames:: +; Skip a names. + ld bc, NAME_LENGTH + and a + ret z +.loop + add hl, bc + dec a + jr nz, .loop + ret + +AddNTimes:: +; Add bc * a to hl. + and a + ret z +.loop + add hl, bc + dec a + jr nz, .loop + ret diff --git a/home/battle.asm b/home/battle.asm index 7f2e8bfdd..77ec0b026 100644 --- a/home/battle.asm +++ b/home/battle.asm @@ -1,3 +1,38 @@ +GetPartyParamLocation:: +; Get the location of parameter a from wCurPartyMon in hl + push bc + ld hl, wPartyMons + ld c, a + ld b, 0 + add hl, bc + ld a, [wCurPartyMon] + call GetPartyLocation + pop bc + ret + +GetPartyLocation:: +; Add the length of a PartyMon struct to hl a times. + ld bc, PARTYMON_STRUCT_LENGTH + jp AddNTimes + +Unreferenced_GetDexNumber:: +; Probably used in gen 1 to convert index number to dex number +; Not required in gen 2 because index number == dex number + push hl + ld a, b + dec a + ld b, 0 + add hl, bc + ld hl, BaseData + BASE_DEX_NO + ld bc, BASE_DATA_SIZE + call AddNTimes + ld a, BANK(BaseData) + call GetFarHalfword + ld b, l + ld c, h + pop hl + ret + UserPartyAttr:: push af ldh a, [hBattleTurn] @@ -224,3 +259,22 @@ GetBattleAnimByte:: ld a, [wBattleAnimByte] ret + +PushLYOverrides:: + ldh a, [hLCDCPointer] + and a + ret z + + ld a, LOW(wLYOverridesBackup) + ld [wRequested2bppSource], a + ld a, HIGH(wLYOverridesBackup) + ld [wRequested2bppSource + 1], a + + ld a, LOW(wLYOverrides) + ld [wRequested2bppDest], a + ld a, HIGH(wLYOverrides) + ld [wRequested2bppDest + 1], a + + ld a, (wLYOverridesEnd - wLYOverrides) / 16 + ld [wRequested2bpp], a + ret diff --git a/home/call_regs.asm b/home/call_regs.asm new file mode 100644 index 000000000..d0a4be1b9 --- /dev/null +++ b/home/call_regs.asm @@ -0,0 +1,8 @@ +; Register aliases + +_hl_:: + jp hl + +_de_:: + push de + ret diff --git a/home/copy.asm b/home/copy.asm index 5780beb95..018986cf2 100644 --- a/home/copy.asm +++ b/home/copy.asm @@ -1,391 +1,131 @@ -; Functions to copy data from ROM. - -Get2bpp_2:: - ldh a, [rLCDC] - bit rLCDC_ENABLE, a - jp z, Copy2bpp - - homecall _Get2bpp - - ret - -Get1bpp_2:: - ldh a, [rLCDC] - bit rLCDC_ENABLE, a - jp z, Copy1bpp - - homecall _Get1bpp - +CopyBytes:: +; copy bc bytes from hl to de + inc b ; we bail the moment b hits 0, so include the last run + inc c ; same thing; include last byte + jr .HandleLoop +.CopyByte: + ld a, [hli] + ld [de], a + inc de +.HandleLoop: + dec c + jr nz, .CopyByte + dec b + jr nz, .CopyByte ret -FarCopyBytesDouble_DoubleBankSwitch:: - ldh [hBuffer], a - ldh a, [hROMBank] +SwapBytes:: +; swap bc bytes between hl and de +.Loop: + ; stash [hl] away on the stack + ld a, [hl] push af - ldh a, [hBuffer] - rst Bankswitch - call FarCopyBytesDouble + ; copy a byte from [de] to [hl] + ld a, [de] + ld [hli], a + ; retrieve the previous value of [hl]; put it in [de] pop af - rst Bankswitch - ret + ld [de], a + inc de -OldDMATransfer:: - dec c - ldh a, [hBGMapMode] - push af - xor a - ldh [hBGMapMode], a - ldh a, [hROMBank] - push af + ; handle loop stuff + dec bc ld a, b - rst Bankswitch - -.loop -; load the source and target MSB and LSB - ld a, d - ldh [rHDMA1], a ; source MSB - ld a, e - and $f0 - ldh [rHDMA2], a ; source LSB - ld a, h - and $1f - ldh [rHDMA3], a ; target MSB - ld a, l - and $f0 - ldh [rHDMA4], a ; target LSB -; stop when c < 8 - ld a, c - cp $8 - jr c, .done -; decrease c by 8 - sub $8 - ld c, a -; DMA transfer state - ld a, $f - ldh [hDMATransfer], a - call DelayFrame -; add $100 to hl and de - ld a, l - add LOW($100) - ld l, a - ld a, h - adc HIGH($100) - ld h, a - ld a, e - add LOW($100) - ld e, a - ld a, d - adc HIGH($100) - ld d, a - jr .loop - -.done - ld a, c - and $7f ; pretty silly, considering at most bits 0-2 would be set - ldh [hDMATransfer], a - call DelayFrame - pop af - rst Bankswitch - - pop af - ldh [hBGMapMode], a + or c + jr nz, .Loop ret -ReplaceKrisSprite:: - farcall _ReplaceKrisSprite - ret - -LoadStandardFont:: - farcall _LoadStandardFont - ret - -LoadFontsBattleExtra:: - farcall _LoadFontsBattleExtra - ret - -LoadFontsExtra:: - farcall _LoadFontsExtra1 - farcall _LoadFontsExtra2 - ret - -LoadFontsExtra2:: - farcall _LoadFontsExtra2 - ret - -DecompressRequest2bpp:: - push de - ld a, BANK(sScratch) - call GetSRAMBank - push bc - - ld de, sScratch - ld a, b - call FarDecompress - - pop bc - pop hl - - ld de, sScratch - call Request2bpp - call CloseSRAM +ByteFill:: +; fill bc bytes with the value of a, starting at hl + inc b ; we bail the moment b hits 0, so include the last run + inc c ; same thing; include last byte + jr .HandleLoop +.PutByte: + ld [hli], a +.HandleLoop: + dec c + jr nz, .PutByte + dec b + jr nz, .PutByte ret -FarCopyBytes:: -; copy bc bytes from a:hl to de - +GetFarByte:: +; retrieve a single byte from a:hl, and return it in a. + ; bankswitch to new bank ldh [hBuffer], a ldh a, [hROMBank] push af ldh a, [hBuffer] rst Bankswitch - call CopyBytes + ; get byte from new bank + ld a, [hl] + ldh [hBuffer], a + ; bankswitch to previous bank pop af rst Bankswitch - ret -FarCopyBytesDouble:: -; Copy bc bytes from a:hl to bc*2 bytes at de, -; doubling each byte in the process. + ; return retrieved value in a + ldh a, [hBuffer] + ret +GetFarHalfword:: +; retrieve a halfword from a:hl, and return it in hl. + ; bankswitch to new bank ldh [hBuffer], a ldh a, [hROMBank] push af ldh a, [hBuffer] rst Bankswitch -; switcheroo, de <> hl - ld a, h - ld h, d - ld d, a - ld a, l - ld l, e - ld e, a - - inc b - inc c - jr .dec - -.loop - ld a, [de] - inc de - ld [hli], a - ld [hli], a -.dec - dec c - jr nz, .loop - dec b - jr nz, .loop + ; get halfword from new bank, put it in hl + ld a, [hli] + ld h, [hl] + ld l, a + ; bankswitch to previous bank and return pop af rst Bankswitch ret -Request2bpp:: -; Load 2bpp at b:de to occupy c tiles of hl. - ldh a, [hBGMapMode] - push af - xor a - ldh [hBGMapMode], a - - ldh a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ldh a, [hTilesPerCycle] +FarCopyWRAM:: + ldh [hBuffer], a + ldh a, [rSVBK] push af - ld a, $8 - ldh [hTilesPerCycle], a - - ld a, [wLinkMode] - cp LINK_MOBILE - jr nz, .NotMobile - ldh a, [hMobile] - and a - jr nz, .NotMobile - ld a, $6 - ldh [hTilesPerCycle], a - -.NotMobile: - ld a, e - ld [wRequested2bppSource], a - ld a, d - ld [wRequested2bppSource + 1], a - ld a, l - ld [wRequested2bppDest], a - ld a, h - ld [wRequested2bppDest + 1], a -.loop - ld a, c - ld hl, hTilesPerCycle - cp [hl] - jr nc, .iterate - - ld [wRequested2bpp], a -.wait - call DelayFrame - ld a, [wRequested2bpp] - and a - jr nz, .wait - - pop af - ldh [hTilesPerCycle], a + ldh a, [hBuffer] + ldh [rSVBK], a - pop af - rst Bankswitch + call CopyBytes pop af - ldh [hBGMapMode], a + ldh [rSVBK], a ret -.iterate - ldh a, [hTilesPerCycle] - ld [wRequested2bpp], a - -.wait2 - call DelayFrame - ld a, [wRequested2bpp] - and a - jr nz, .wait2 - - ld a, c - ld hl, hTilesPerCycle - sub [hl] - ld c, a - jr .loop - -Request1bpp:: -; Load 1bpp at b:de to occupy c tiles of hl. - ldh a, [hBGMapMode] - push af - xor a - ldh [hBGMapMode], a - - ldh a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ldh a, [hTilesPerCycle] +GetFarWRAMByte:: + ldh [hBuffer], a + ldh a, [rSVBK] push af - ld a, $8 - ldh [hTilesPerCycle], a - - ld a, [wLinkMode] - cp LINK_MOBILE - jr nz, .NotMobile - ldh a, [hMobile] - and a - jr nz, .NotMobile - ld a, $6 - ldh [hTilesPerCycle], a - -.NotMobile: - ld a, e - ld [wRequested1bppSource], a - ld a, d - ld [wRequested1bppSource + 1], a - ld a, l - ld [wRequested1bppDest], a - ld a, h - ld [wRequested1bppDest + 1], a -.loop - ld a, c - ld hl, hTilesPerCycle - cp [hl] - jr nc, .iterate - - ld [wRequested1bpp], a -.wait - call DelayFrame - ld a, [wRequested1bpp] - and a - jr nz, .wait - - pop af - ldh [hTilesPerCycle], a - - pop af - rst Bankswitch - + ldh a, [hBuffer] + ldh [rSVBK], a + ld a, [hl] + ldh [hBuffer], a pop af - ldh [hBGMapMode], a + ldh [rSVBK], a + ldh a, [hBuffer] ret -.iterate - ldh a, [hTilesPerCycle] - ld [wRequested1bpp], a - -.wait2 - call DelayFrame - ld a, [wRequested1bpp] - and a - jr nz, .wait2 - - ld a, c - ld hl, hTilesPerCycle - sub [hl] - ld c, a - jr .loop - -Get2bpp:: - ldh a, [rLCDC] - bit rLCDC_ENABLE, a - jp nz, Request2bpp - -Copy2bpp:: -; copy c 2bpp tiles from b:de to hl - - push hl - ld h, d - ld l, e - pop de - -; bank - ld a, b - -; bc = c * $10 - push af - swap c - ld a, $f - and c - ld b, a - ld a, $f0 - and c - ld c, a - pop af - - jp FarCopyBytes - -Get1bpp:: - ldh a, [rLCDC] - bit rLCDC_ENABLE, a - jp nz, Request1bpp - -Copy1bpp:: -; copy c 1bpp tiles from b:de to hl - - push de - ld d, h - ld e, l - -; bank - ld a, b - -; bc = c * $10 / 2 +GetFarWRAMWord:: + ldh [hBuffer], a + ldh a, [rSVBK] push af - ld h, 0 - ld l, c - add hl, hl - add hl, hl - add hl, hl - ld b, h - ld c, l + ldh a, [hBuffer] + ldh [rSVBK], a + ld a, [hli] + ld h, [hl] + ld l, a pop af - - pop hl - jp FarCopyBytesDouble + ldh [rSVBK], a + ret diff --git a/home/copy2.asm b/home/copy2.asm deleted file mode 100644 index 018986cf2..000000000 --- a/home/copy2.asm +++ /dev/null @@ -1,131 +0,0 @@ -CopyBytes:: -; copy bc bytes from hl to de - inc b ; we bail the moment b hits 0, so include the last run - inc c ; same thing; include last byte - jr .HandleLoop -.CopyByte: - ld a, [hli] - ld [de], a - inc de -.HandleLoop: - dec c - jr nz, .CopyByte - dec b - jr nz, .CopyByte - ret - -SwapBytes:: -; swap bc bytes between hl and de -.Loop: - ; stash [hl] away on the stack - ld a, [hl] - push af - - ; copy a byte from [de] to [hl] - ld a, [de] - ld [hli], a - - ; retrieve the previous value of [hl]; put it in [de] - pop af - ld [de], a - inc de - - ; handle loop stuff - dec bc - ld a, b - or c - jr nz, .Loop - ret - -ByteFill:: -; fill bc bytes with the value of a, starting at hl - inc b ; we bail the moment b hits 0, so include the last run - inc c ; same thing; include last byte - jr .HandleLoop -.PutByte: - ld [hli], a -.HandleLoop: - dec c - jr nz, .PutByte - dec b - jr nz, .PutByte - ret - -GetFarByte:: -; retrieve a single byte from a:hl, and return it in a. - ; bankswitch to new bank - ldh [hBuffer], a - ldh a, [hROMBank] - push af - ldh a, [hBuffer] - rst Bankswitch - - ; get byte from new bank - ld a, [hl] - ldh [hBuffer], a - - ; bankswitch to previous bank - pop af - rst Bankswitch - - ; return retrieved value in a - ldh a, [hBuffer] - ret - -GetFarHalfword:: -; retrieve a halfword from a:hl, and return it in hl. - ; bankswitch to new bank - ldh [hBuffer], a - ldh a, [hROMBank] - push af - ldh a, [hBuffer] - rst Bankswitch - - ; get halfword from new bank, put it in hl - ld a, [hli] - ld h, [hl] - ld l, a - - ; bankswitch to previous bank and return - pop af - rst Bankswitch - ret - -FarCopyWRAM:: - ldh [hBuffer], a - ldh a, [rSVBK] - push af - ldh a, [hBuffer] - ldh [rSVBK], a - - call CopyBytes - - pop af - ldh [rSVBK], a - ret - -GetFarWRAMByte:: - ldh [hBuffer], a - ldh a, [rSVBK] - push af - ldh a, [hBuffer] - ldh [rSVBK], a - ld a, [hl] - ldh [hBuffer], a - pop af - ldh [rSVBK], a - ldh a, [hBuffer] - ret - -GetFarWRAMWord:: - ldh [hBuffer], a - ldh a, [rSVBK] - push af - ldh a, [hBuffer] - ldh [rSVBK], a - ld a, [hli] - ld h, [hl] - ld l, a - pop af - ldh [rSVBK], a - ret diff --git a/home/cry.asm b/home/cry.asm deleted file mode 100644 index 856134b3e..000000000 --- a/home/cry.asm +++ /dev/null @@ -1,101 +0,0 @@ -PlayStereoCry:: - push af - ld a, 1 - ld [wStereoPanningMask], a - pop af - call _PlayMonCry - call WaitSFX - ret - -PlayStereoCry2:: -; Don't wait for the cry to end. -; Used during pic animations. - push af - ld a, 1 - ld [wStereoPanningMask], a - pop af - jp _PlayMonCry - -PlayMonCry:: - call PlayMonCry2 - call WaitSFX - ret - -PlayMonCry2:: -; Don't wait for the cry to end. - push af - xor a - ld [wStereoPanningMask], a - ld [wCryTracks], a - pop af - call _PlayMonCry - ret - -_PlayMonCry:: - push hl - push de - push bc - - call GetCryIndex - jr c, .done - - ld e, c - ld d, b - call PlayCry - -.done - pop bc - pop de - pop hl - ret - -LoadCry:: -; Load cry bc. - - call GetCryIndex - ret c - - ldh a, [hROMBank] - push af - ld a, BANK(PokemonCries) - rst Bankswitch - - ld hl, PokemonCries -rept 6 ; sizeof(mon_cry) - add hl, bc -endr - - ld e, [hl] - inc hl - ld d, [hl] - inc hl - - ld a, [hli] - ld [wCryPitch], a - ld a, [hli] - ld [wCryPitch + 1], a - ld a, [hli] - ld [wCryLength], a - ld a, [hl] - ld [wCryLength + 1], a - - pop af - rst Bankswitch - and a - ret - -GetCryIndex:: - and a - jr z, .no - cp NUM_POKEMON + 1 - jr nc, .no - - dec a - ld c, a - ld b, 0 - and a - ret - -.no - scf - ret diff --git a/home/flag.asm b/home/flag.asm index 372d8107f..125c2a434 100644 --- a/home/flag.asm +++ b/home/flag.asm @@ -101,3 +101,30 @@ CheckReceivedDex:: ld a, c and a ret + +Unreferenced_CheckBPressedDebug:: +; Used in debug ROMs to walk through walls and avoid encounters. + + ld a, [wDebugFlags] + bit DEBUG_FIELD_F, a + ret z + + ldh a, [hJoyDown] + bit B_BUTTON_F, a + ret + +xor_a:: + xor a + ret + +xor_a_dec_a:: + xor a + dec a + ret + +Unreferenced_CheckFieldDebug:: + push hl + ld hl, wDebugFlags + bit DEBUG_FIELD_F, [hl] + pop hl + ret diff --git a/home/gfx.asm b/home/gfx.asm new file mode 100644 index 000000000..4655f204f --- /dev/null +++ b/home/gfx.asm @@ -0,0 +1,391 @@ +; Functions to copy data from ROM. + +Get2bpp_2:: + ldh a, [rLCDC] + bit rLCDC_ENABLE, a + jp z, Copy2bpp + + homecall _Get2bpp + + ret + +Get1bpp_2:: + ldh a, [rLCDC] + bit rLCDC_ENABLE, a + jp z, Copy1bpp + + homecall _Get1bpp + + ret + +FarCopyBytesDouble_DoubleBankSwitch:: + ldh [hBuffer], a + ldh a, [hROMBank] + push af + ldh a, [hBuffer] + rst Bankswitch + + call FarCopyBytesDouble + + pop af + rst Bankswitch + ret + +OldDMATransfer: + dec c + ldh a, [hBGMapMode] + push af + xor a + ldh [hBGMapMode], a + ldh a, [hROMBank] + push af + ld a, b + rst Bankswitch + +.loop +; load the source and target MSB and LSB + ld a, d + ldh [rHDMA1], a ; source MSB + ld a, e + and $f0 + ldh [rHDMA2], a ; source LSB + ld a, h + and $1f + ldh [rHDMA3], a ; target MSB + ld a, l + and $f0 + ldh [rHDMA4], a ; target LSB +; stop when c < 8 + ld a, c + cp $8 + jr c, .done +; decrease c by 8 + sub $8 + ld c, a +; DMA transfer state + ld a, $f + ldh [hDMATransfer], a + call DelayFrame +; add $100 to hl and de + ld a, l + add LOW($100) + ld l, a + ld a, h + adc HIGH($100) + ld h, a + ld a, e + add LOW($100) + ld e, a + ld a, d + adc HIGH($100) + ld d, a + jr .loop + +.done + ld a, c + and $7f ; pretty silly, considering at most bits 0-2 would be set + ldh [hDMATransfer], a + call DelayFrame + pop af + rst Bankswitch + + pop af + ldh [hBGMapMode], a + ret + +ReplaceKrisSprite:: + farcall _ReplaceKrisSprite + ret + +LoadStandardFont:: + farcall _LoadStandardFont + ret + +LoadFontsBattleExtra:: + farcall _LoadFontsBattleExtra + ret + +LoadFontsExtra:: + farcall _LoadFontsExtra1 + farcall _LoadFontsExtra2 + ret + +LoadFontsExtra2: + farcall _LoadFontsExtra2 + ret + +DecompressRequest2bpp:: + push de + ld a, BANK(sScratch) + call GetSRAMBank + push bc + + ld de, sScratch + ld a, b + call FarDecompress + + pop bc + pop hl + + ld de, sScratch + call Request2bpp + call CloseSRAM + ret + +FarCopyBytes:: +; copy bc bytes from a:hl to de + + ldh [hBuffer], a + ldh a, [hROMBank] + push af + ldh a, [hBuffer] + rst Bankswitch + + call CopyBytes + + pop af + rst Bankswitch + ret + +FarCopyBytesDouble: +; Copy bc bytes from a:hl to bc*2 bytes at de, +; doubling each byte in the process. + + ldh [hBuffer], a + ldh a, [hROMBank] + push af + ldh a, [hBuffer] + rst Bankswitch + +; switcheroo, de <> hl + ld a, h + ld h, d + ld d, a + ld a, l + ld l, e + ld e, a + + inc b + inc c + jr .dec + +.loop + ld a, [de] + inc de + ld [hli], a + ld [hli], a +.dec + dec c + jr nz, .loop + dec b + jr nz, .loop + + pop af + rst Bankswitch + ret + +Request2bpp:: +; Load 2bpp at b:de to occupy c tiles of hl. + ldh a, [hBGMapMode] + push af + xor a + ldh [hBGMapMode], a + + ldh a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ldh a, [hTilesPerCycle] + push af + ld a, $8 + ldh [hTilesPerCycle], a + + ld a, [wLinkMode] + cp LINK_MOBILE + jr nz, .NotMobile + ldh a, [hMobile] + and a + jr nz, .NotMobile + ld a, $6 + ldh [hTilesPerCycle], a + +.NotMobile: + ld a, e + ld [wRequested2bppSource], a + ld a, d + ld [wRequested2bppSource + 1], a + ld a, l + ld [wRequested2bppDest], a + ld a, h + ld [wRequested2bppDest + 1], a +.loop + ld a, c + ld hl, hTilesPerCycle + cp [hl] + jr nc, .iterate + + ld [wRequested2bpp], a +.wait + call DelayFrame + ld a, [wRequested2bpp] + and a + jr nz, .wait + + pop af + ldh [hTilesPerCycle], a + + pop af + rst Bankswitch + + pop af + ldh [hBGMapMode], a + ret + +.iterate + ldh a, [hTilesPerCycle] + ld [wRequested2bpp], a + +.wait2 + call DelayFrame + ld a, [wRequested2bpp] + and a + jr nz, .wait2 + + ld a, c + ld hl, hTilesPerCycle + sub [hl] + ld c, a + jr .loop + +Request1bpp:: +; Load 1bpp at b:de to occupy c tiles of hl. + ldh a, [hBGMapMode] + push af + xor a + ldh [hBGMapMode], a + + ldh a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ldh a, [hTilesPerCycle] + push af + ld a, $8 + ldh [hTilesPerCycle], a + + ld a, [wLinkMode] + cp LINK_MOBILE + jr nz, .NotMobile + ldh a, [hMobile] + and a + jr nz, .NotMobile + ld a, $6 + ldh [hTilesPerCycle], a + +.NotMobile: + ld a, e + ld [wRequested1bppSource], a + ld a, d + ld [wRequested1bppSource + 1], a + ld a, l + ld [wRequested1bppDest], a + ld a, h + ld [wRequested1bppDest + 1], a +.loop + ld a, c + ld hl, hTilesPerCycle + cp [hl] + jr nc, .iterate + + ld [wRequested1bpp], a +.wait + call DelayFrame + ld a, [wRequested1bpp] + and a + jr nz, .wait + + pop af + ldh [hTilesPerCycle], a + + pop af + rst Bankswitch + + pop af + ldh [hBGMapMode], a + ret + +.iterate + ldh a, [hTilesPerCycle] + ld [wRequested1bpp], a + +.wait2 + call DelayFrame + ld a, [wRequested1bpp] + and a + jr nz, .wait2 + + ld a, c + ld hl, hTilesPerCycle + sub [hl] + ld c, a + jr .loop + +Get2bpp:: + ldh a, [rLCDC] + bit rLCDC_ENABLE, a + jp nz, Request2bpp + +Copy2bpp: +; copy c 2bpp tiles from b:de to hl + + push hl + ld h, d + ld l, e + pop de + +; bank + ld a, b + +; bc = c * $10 + push af + swap c + ld a, $f + and c + ld b, a + ld a, $f0 + and c + ld c, a + pop af + + jp FarCopyBytes + +Get1bpp:: + ldh a, [rLCDC] + bit rLCDC_ENABLE, a + jp nz, Request1bpp + +Copy1bpp:: +; copy c 1bpp tiles from b:de to hl + + push de + ld d, h + ld e, l + +; bank + ld a, b + +; bc = c * $10 / 2 + push af + ld h, 0 + ld l, c + add hl, hl + add hl, hl + add hl, hl + ld b, h + ld c, l + pop af + + pop hl + jp FarCopyBytesDouble diff --git a/home/header.asm b/home/header.asm new file mode 100644 index 000000000..4ecc49bfb --- /dev/null +++ b/home/header.asm @@ -0,0 +1,66 @@ +; rst vectors (called through the rst instruction) + +SECTION "rst0", ROM0[$0000] + di + jp Start + +SECTION "rst8", ROM0[$0008] ; rst FarCall + jp FarCall_hl + +SECTION "rst10", ROM0[$0010] ; rst Bankswitch + ldh [hROMBank], a + ld [MBC3RomBank], a + ret + +SECTION "rst18", ROM0[$0018] + rst $38 + +SECTION "rst20", ROM0[$0020] + rst $38 + +SECTION "rst28", ROM0[$0028] ; rst JumpTable + push de + ld e, a + ld d, 0 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] +; SECTION "rst30", ROM0[$0030] + ld l, a + pop de + jp hl + +SECTION "rst38", ROM0[$0038] + rst $38 + + +; Game Boy hardware interrupts + +SECTION "vblank", ROM0[$0040] + jp VBlank + +SECTION "lcd", ROM0[$0048] + jp LCD + +SECTION "timer", ROM0[$0050] + jp Timer + +SECTION "serial", ROM0[$0058] + jp Serial + +SECTION "joypad", ROM0[$0060] + jp Joypad + + +; Game Boy cartridge header + +SECTION "Header", ROM0[$0100] + +Start:: + nop + jp _Start + +; The cartridge header data is filled in by rgbfix. +; This makes sure it doesn't get used. + ds $0150 - @ diff --git a/home/hp_pals.asm b/home/hp_pals.asm deleted file mode 100644 index 9400d341f..000000000 --- a/home/hp_pals.asm +++ /dev/null @@ -1,17 +0,0 @@ -SetHPPal:: -; Set palette for hp bar pixel length e at hl. - call GetHPPal - ld [hl], d - ret - -GetHPPal:: -; Get palette for hp bar pixel length e in d. - ld d, HP_GREEN - ld a, e - cp (HP_BAR_LENGTH_PX * 50 / 100) ; 24 - ret nc - inc d ; HP_YELLOW - cp (HP_BAR_LENGTH_PX * 21 / 100) ; 10 - ret nc - inc d ; HP_RED - ret diff --git a/home/interrupts.asm b/home/interrupts.asm deleted file mode 100644 index 0cae6441c..000000000 --- a/home/interrupts.asm +++ /dev/null @@ -1,16 +0,0 @@ -; Game Boy hardware interrupts - -SECTION "vblank", ROM0 - jp VBlank - -SECTION "lcd", ROM0 - jp LCD - -SECTION "timer", ROM0 - jp Timer - -SECTION "serial", ROM0 - jp Serial - -SECTION "joypad", ROM0 - jp JoypadInt diff --git a/home/joypad.asm b/home/joypad.asm index cfc94a4be..2ffd8343c 100644 --- a/home/joypad.asm +++ b/home/joypad.asm @@ -1,4 +1,4 @@ -JoypadInt:: +Joypad:: ; Replaced by Joypad, called from VBlank instead of the useless ; joypad interrupt. @@ -13,7 +13,7 @@ ClearJoypad:: ldh [hJoyDown], a ret -Joypad:: +UpdateJoypad:: ; This is called automatically every frame in VBlank. ; Read the joypad register and translate it to something more ; workable for use in-game. There are 8 buttons, so we can use diff --git a/home/map.asm b/home/map.asm index bccc2ae1c..0b7bb6eac 100644 --- a/home/map.asm +++ b/home/map.asm @@ -2277,3 +2277,12 @@ LoadMapTileset:: pop bc pop hl ret + +InexplicablyEmptyFunction:: +; unused +; Inexplicably empty. +; Seen in PredefPointers. +rept 16 + nop +endr + ret diff --git a/home/math.asm b/home/math.asm index f385ccbf8..3042cc61d 100644 --- a/home/math.asm +++ b/home/math.asm @@ -1,13 +1,3 @@ -AddNTimes:: -; Add bc * a to hl. - and a - ret z -.loop - add hl, bc - dec a - jr nz, .loop - ret - SimpleMultiply:: ; Return a * c. and a diff --git a/home/menu.asm b/home/menu.asm index 412955b28..ae9696815 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -60,3 +60,784 @@ HideCursor:: ld l, a ld [hl], " " ret + +PushWindow:: + callfar _PushWindow + ret + +ExitMenu:: + push af + callfar _ExitMenu + pop af + ret + +InitVerticalMenuCursor:: + callfar _InitVerticalMenuCursor + ret + +CloseWindow:: + push af + call ExitMenu + call ApplyTilemap + call UpdateSprites + pop af + ret + +RestoreTileBackup:: + call MenuBoxCoord2Tile + call .copy + call MenuBoxCoord2Attr + call .copy + ret + +.copy + call GetMenuBoxDims + inc b + inc c + +.row + push bc + push hl + +.col + ld a, [de] + ld [hli], a + dec de + dec c + jr nz, .col + + pop hl + ld bc, SCREEN_WIDTH + add hl, bc + pop bc + dec b + jr nz, .row + + ret + +PopWindow:: + ld b, $10 + ld de, wMenuFlags +.loop + ld a, [hld] + ld [de], a + inc de + dec b + jr nz, .loop + ret + +GetMenuBoxDims:: + ld a, [wMenuBorderTopCoord] ; top + ld b, a + ld a, [wMenuBorderBottomCoord] ; bottom + sub b + ld b, a + ld a, [wMenuBorderLeftCoord] ; left + ld c, a + ld a, [wMenuBorderRightCoord] ; right + sub c + ld c, a + ret + +CopyMenuData:: + push hl + push de + push bc + push af + ld hl, wMenuDataPointer + ld a, [hli] + ld h, [hl] + ld l, a + ld de, wMenuDataFlags + ld bc, wMenuDataEnd - wMenuDataFlags + call CopyBytes + pop af + pop bc + pop de + pop hl + ret + +GetWindowStackTop:: + ld hl, wWindowStackPointer + ld a, [hli] + ld h, [hl] + ld l, a + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + ret + +PlaceVerticalMenuItems:: + call CopyMenuData + ld hl, wMenuDataPointer + ld e, [hl] + inc hl + ld d, [hl] + call GetMenuTextStartCoord + call Coord2Tile ; hl now contains the tilemap address where we will start printing text. + inc de + ld a, [de] ; Number of items + inc de + ld b, a +.loop + push bc + call PlaceString + inc de + ld bc, 2 * SCREEN_WIDTH + add hl, bc + pop bc + dec b + jr nz, .loop + + ld a, [wMenuDataFlags] + bit 4, a + ret z + + call MenuBoxCoord2Tile + ld a, [de] + ld c, a + inc de + ld b, $0 + add hl, bc + jp PlaceString + +MenuBox:: + call MenuBoxCoord2Tile + call GetMenuBoxDims + dec b + dec c + jp Textbox + +GetMenuTextStartCoord:: + ld a, [wMenuBorderTopCoord] + ld b, a + inc b + ld a, [wMenuBorderLeftCoord] + ld c, a + inc c +; bit 6: if not set, leave extra room on top + ld a, [wMenuDataFlags] + bit 6, a + jr nz, .bit_6_set + inc b + +.bit_6_set +; bit 7: if set, leave extra room on the left + ld a, [wMenuDataFlags] + bit 7, a + jr z, .bit_7_clear + inc c + +.bit_7_clear + ret + +ClearMenuBoxInterior:: + call MenuBoxCoord2Tile + ld bc, SCREEN_WIDTH + 1 + add hl, bc + call GetMenuBoxDims + dec b + dec c + call ClearBox + ret + +ClearWholeMenuBox:: + call MenuBoxCoord2Tile + call GetMenuBoxDims + inc c + inc b + call ClearBox + ret + +MenuBoxCoord2Tile:: + ld a, [wMenuBorderLeftCoord] + ld c, a + ld a, [wMenuBorderTopCoord] + ld b, a + +Coord2Tile:: +; Return the address of wTilemap(c, b) in hl. + xor a + ld h, a + ld l, b + ld a, c + ld b, h + ld c, l + add hl, hl + add hl, hl + add hl, bc + add hl, hl + add hl, hl + ld c, a + xor a + ld b, a + add hl, bc + bccoord 0, 0 + add hl, bc + ret + +MenuBoxCoord2Attr:: + ld a, [wMenuBorderLeftCoord] + ld c, a + ld a, [wMenuBorderTopCoord] + ld b, a + +Coord2Attr:: +; Return the address of wAttrmap(c, b) in hl. + xor a + ld h, a + ld l, b + ld a, c + ld b, h + ld c, l + add hl, hl + add hl, hl + add hl, bc + add hl, hl + add hl, hl + ld c, a + xor a + ld b, a + add hl, bc + bccoord 0, 0, wAttrmap + add hl, bc + ret + +LoadMenuHeader:: + call CopyMenuHeader + call PushWindow + ret + +CopyMenuHeader:: + ld de, wMenuHeader + ld bc, wMenuHeaderEnd - wMenuHeader + call CopyBytes + ldh a, [hROMBank] + ld [wMenuDataBank], a + ret + +StoreTo_wMenuCursorBuffer:: + ld [wMenuCursorBuffer], a + ret + +MenuTextbox:: + push hl + call LoadMenuTextbox + pop hl + jp PrintText + +; unused + ret + +LoadMenuTextbox:: + ld hl, .MenuHeader + call LoadMenuHeader + ret + +.MenuHeader: + db MENU_BACKUP_TILES ; flags + menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 + dw vTiles0 + db 0 ; default option + +MenuTextboxBackup:: + call MenuTextbox + call CloseWindow + ret + +LoadStandardMenuHeader:: + ld hl, .MenuHeader + call LoadMenuHeader + ret + +.MenuHeader: + db MENU_BACKUP_TILES ; flags + menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 + dw 0 + db 1 ; default option + +Call_ExitMenu:: + call ExitMenu + ret + +VerticalMenu:: + xor a + ldh [hBGMapMode], a + call MenuBox + call UpdateSprites + call PlaceVerticalMenuItems + call ApplyTilemap + call CopyMenuData + ld a, [wMenuDataFlags] + bit 7, a + jr z, .cancel + call InitVerticalMenuCursor + call StaticMenuJoypad + call MenuClickSound + bit 1, a + jr z, .okay +.cancel + scf + ret + +.okay + and a + ret + +GetMenu2:: + call LoadMenuHeader + call VerticalMenu + call CloseWindow + ld a, [wMenuCursorY] + ret + +CopyNameFromMenu:: + push hl + push bc + push af + ld hl, wMenuDataPointer + ld a, [hli] + ld h, [hl] + ld l, a + inc hl + inc hl + pop af + call GetNthString + ld d, h + ld e, l + call CopyName1 + pop bc + pop hl + ret + +YesNoBox:: + lb bc, SCREEN_WIDTH - 6, 7 + +PlaceYesNoBox:: + jr _YesNoBox + +PlaceGenericTwoOptionBox:: + call LoadMenuHeader + jr InterpretTwoOptionMenu + +_YesNoBox:: +; Return nc (yes) or c (no). + push bc + ld hl, YesNoMenuHeader + call CopyMenuHeader + pop bc +; This seems to be an overflow prevention, but +; it was coded wrong. + ld a, b + cp SCREEN_WIDTH - 6 + jr nz, .okay ; should this be "jr nc"? + ld a, SCREEN_WIDTH - 6 + ld b, a + +.okay + ld a, b + ld [wMenuBorderLeftCoord], a + add 5 + ld [wMenuBorderRightCoord], a + ld a, c + ld [wMenuBorderTopCoord], a + add 4 + ld [wMenuBorderBottomCoord], a + call PushWindow + +InterpretTwoOptionMenu:: + call VerticalMenu + push af + ld c, $f + call DelayFrames + call CloseWindow + pop af + jr c, .no + ld a, [wMenuCursorY] + cp 2 ; no + jr z, .no + and a + ret + +.no + ld a, 2 + ld [wMenuCursorY], a + scf + ret + +YesNoMenuHeader:: + db MENU_BACKUP_TILES ; flags + menu_coords 10, 5, 15, 9 + dw .MenuData + db 1 ; default option + +.MenuData: + db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags + db 2 + db "YES@" + db "NO@" + +OffsetMenuHeader:: + call _OffsetMenuHeader + call PushWindow + ret + +_OffsetMenuHeader:: + push de + call CopyMenuHeader + pop de + ld a, [wMenuBorderLeftCoord] + ld h, a + ld a, [wMenuBorderRightCoord] + sub h + ld h, a + ld a, d + ld [wMenuBorderLeftCoord], a + add h + ld [wMenuBorderRightCoord], a + ld a, [wMenuBorderTopCoord] + ld l, a + ld a, [wMenuBorderBottomCoord] + sub l + ld l, a + ld a, e + ld [wMenuBorderTopCoord], a + add l + ld [wMenuBorderBottomCoord], a + ret + +DoNthMenu:: + call DrawVariableLengthMenuBox + call MenuWriteText + call InitMenuCursorAndButtonPermissions + call GetStaticMenuJoypad + call GetMenuJoypad + call MenuClickSound + ret + +SetUpMenu:: + call DrawVariableLengthMenuBox ; ??? + call MenuWriteText + call InitMenuCursorAndButtonPermissions ; set up selection pointer + ld hl, w2DMenuFlags1 + set 7, [hl] + ret + +DrawVariableLengthMenuBox:: + call CopyMenuData + call GetMenuIndexSet + call AutomaticGetMenuBottomCoord + call MenuBox + ret + +MenuWriteText:: + xor a + ldh [hBGMapMode], a + call GetMenuIndexSet ; sort out the text + call RunMenuItemPrintingFunction ; actually write it + call SafeUpdateSprites + ldh a, [hOAMUpdate] + push af + ld a, $1 + ldh [hOAMUpdate], a + call ApplyTilemap + pop af + ldh [hOAMUpdate], a + ret + +AutomaticGetMenuBottomCoord:: + ld a, [wMenuBorderLeftCoord] + ld c, a + ld a, [wMenuBorderRightCoord] + sub c + ld c, a + ld a, [wMenuDataItems] + add a + inc a + ld b, a + ld a, [wMenuBorderTopCoord] + add b + ld [wMenuBorderBottomCoord], a + ret + +GetMenuIndexSet:: + ld hl, wMenuDataIndicesPointer + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wWhichIndexSet] + and a + jr z, .skip + ld b, a + ld c, -1 +.loop + ld a, [hli] + cp c + jr nz, .loop + dec b + jr nz, .loop + +.skip + ld d, h + ld e, l + ld a, [hl] + ld [wMenuDataItems], a + ret + +RunMenuItemPrintingFunction:: + call MenuBoxCoord2Tile + ld bc, 2 * SCREEN_WIDTH + 2 + add hl, bc +.loop + inc de + ld a, [de] + cp -1 + ret z + ld [wMenuSelection], a + push de + push hl + ld d, h + ld e, l + ld hl, wMenuDataDisplayFunctionPointer + call ._hl_ + pop hl + ld de, 2 * SCREEN_WIDTH + add hl, de + pop de + jr .loop + +._hl_ + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +InitMenuCursorAndButtonPermissions:: + call InitVerticalMenuCursor + ld hl, wMenuJoypadFilter + ld a, [wMenuDataFlags] + bit 3, a + jr z, .disallow_select + set START_F, [hl] + +.disallow_select + ld a, [wMenuDataFlags] + bit 2, a + jr z, .disallow_left_right + set D_LEFT_F, [hl] + set D_RIGHT_F, [hl] + +.disallow_left_right + ret + +GetScrollingMenuJoypad:: + call ScrollingMenuJoypad + ld hl, wMenuJoypadFilter + and [hl] + jr ContinueGettingMenuJoypad + +GetStaticMenuJoypad:: + xor a + ld [wMenuJoypad], a + call StaticMenuJoypad + +ContinueGettingMenuJoypad: + bit A_BUTTON_F, a + jr nz, .a_button + bit B_BUTTON_F, a + jr nz, .b_start + bit START_F, a + jr nz, .b_start + bit D_RIGHT_F, a + jr nz, .d_right + bit D_LEFT_F, a + jr nz, .d_left + xor a + ld [wMenuJoypad], a + jr .done + +.d_right + ld a, D_RIGHT + ld [wMenuJoypad], a + jr .done + +.d_left + ld a, D_LEFT + ld [wMenuJoypad], a + jr .done + +.a_button + ld a, A_BUTTON + ld [wMenuJoypad], a + +.done + call GetMenuIndexSet + ld a, [wMenuCursorY] + ld l, a + ld h, $0 + add hl, de + ld a, [hl] + ld [wMenuSelection], a + ld a, [wMenuCursorY] + ld [wMenuCursorBuffer], a + and a + ret + +.b_start + ld a, B_BUTTON + ld [wMenuJoypad], a + ld a, -1 + ld [wMenuSelection], a + scf + ret + +PlaceMenuStrings:: + push de + ld hl, wMenuDataPointerTableAddr + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wMenuSelection] + call GetNthString + ld d, h + ld e, l + pop hl + call PlaceString + ret + +PlaceNthMenuStrings:: + push de + ld a, [wMenuSelection] + call GetMenuDataPointerTableEntry + inc hl + inc hl + ld a, [hli] + ld d, [hl] + ld e, a + pop hl + call PlaceString + ret + +Unreferenced_Function1f9e:: + call GetMenuDataPointerTableEntry + inc hl + inc hl + ld a, [hli] + ld d, [hl] + ld e, a + ret + +MenuJumptable:: + ld a, [wMenuSelection] + call GetMenuDataPointerTableEntry + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +GetMenuDataPointerTableEntry:: + ld e, a + ld d, $0 + ld hl, wMenuDataPointerTableAddr + ld a, [hli] + ld h, [hl] + ld l, a + add hl, de + add hl, de + add hl, de + add hl, de + ret + +ClearWindowData:: + ld hl, wWindowStackPointer + call .bytefill + ld hl, wMenuHeader + call .bytefill + ld hl, wMenuDataFlags + call .bytefill + ld hl, w2DMenuCursorInitY + call .bytefill + + ldh a, [rSVBK] + push af + ld a, BANK(wWindowStack) + ldh [rSVBK], a + + xor a + ld hl, wWindowStackBottom + ld [hld], a + ld [hld], a + ld a, l + ld [wWindowStackPointer], a + ld a, h + ld [wWindowStackPointer + 1], a + + pop af + ldh [rSVBK], a + ret + +.bytefill + ld bc, $10 + xor a + call ByteFill + ret + +MenuClickSound:: + push af + and A_BUTTON | B_BUTTON + jr z, .nosound + ld hl, wMenuFlags + bit 3, [hl] + jr nz, .nosound + call PlayClickSFX +.nosound + pop af + ret + +PlayClickSFX:: + push de + ld de, SFX_READ_TEXT_2 + call PlaySFX + pop de + ret + +MenuTextboxWaitButton:: + call MenuTextbox + call WaitButton + call ExitMenu + ret + +Place2DMenuItemName:: + ldh [hBuffer], a + ldh a, [hROMBank] + push af + ldh a, [hBuffer] + rst Bankswitch + + call PlaceString + pop af + rst Bankswitch + + ret + +_2DMenu:: + ldh a, [hROMBank] + ld [wMenuData_2DMenuItemStringsBank], a + farcall _2DMenu_ + ld a, [wMenuCursorBuffer] + ret + +InterpretBattleMenu:: + ldh a, [hROMBank] + ld [wMenuData_2DMenuItemStringsBank], a + farcall _InterpretBattleMenu + ld a, [wMenuCursorBuffer] + ret + +InterpretMobileMenu:: + ldh a, [hROMBank] + ld [wMenuData_2DMenuItemStringsBank], a + farcall _InterpretMobileMenu + ld a, [wMenuCursorBuffer] + ret diff --git a/home/menu2.asm b/home/menu2.asm deleted file mode 100644 index 4debb11ad..000000000 --- a/home/menu2.asm +++ /dev/null @@ -1,539 +0,0 @@ -; Functions used in displaying and handling menus. - -LoadMenuHeader:: - call CopyMenuHeader - call PushWindow - ret - -CopyMenuHeader:: - ld de, wMenuHeader - ld bc, wMenuHeaderEnd - wMenuHeader - call CopyBytes - ldh a, [hROMBank] - ld [wMenuDataBank], a - ret - -StoreTo_wMenuCursorBuffer:: - ld [wMenuCursorBuffer], a - ret - -MenuTextbox:: - push hl - call LoadMenuTextbox - pop hl - jp PrintText - -; unused - ret - -LoadMenuTextbox:: - ld hl, .MenuHeader - call LoadMenuHeader - ret - -.MenuHeader: - db MENU_BACKUP_TILES ; flags - menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 - dw vTiles0 - db 0 ; default option - -MenuTextboxBackup:: - call MenuTextbox - call CloseWindow - ret - -LoadStandardMenuHeader:: - ld hl, .MenuHeader - call LoadMenuHeader - ret - -.MenuHeader: - db MENU_BACKUP_TILES ; flags - menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 - dw 0 - db 1 ; default option - -Call_ExitMenu:: - call ExitMenu - ret - -VerticalMenu:: - xor a - ldh [hBGMapMode], a - call MenuBox - call UpdateSprites - call PlaceVerticalMenuItems - call ApplyTilemap - call CopyMenuData - ld a, [wMenuDataFlags] - bit 7, a - jr z, .cancel - call InitVerticalMenuCursor - call StaticMenuJoypad - call MenuClickSound - bit 1, a - jr z, .okay -.cancel - scf - ret - -.okay - and a - ret - -GetMenu2:: - call LoadMenuHeader - call VerticalMenu - call CloseWindow - ld a, [wMenuCursorY] - ret - -CopyNameFromMenu:: - push hl - push bc - push af - ld hl, wMenuDataPointer - ld a, [hli] - ld h, [hl] - ld l, a - inc hl - inc hl - pop af - call GetNthString - ld d, h - ld e, l - call CopyName1 - pop bc - pop hl - ret - -YesNoBox:: - lb bc, SCREEN_WIDTH - 6, 7 - -PlaceYesNoBox:: - jr _YesNoBox - -PlaceGenericTwoOptionBox:: - call LoadMenuHeader - jr InterpretTwoOptionMenu - -_YesNoBox:: -; Return nc (yes) or c (no). - push bc - ld hl, YesNoMenuHeader - call CopyMenuHeader - pop bc -; This seems to be an overflow prevention, but -; it was coded wrong. - ld a, b - cp SCREEN_WIDTH - 6 - jr nz, .okay ; should this be "jr nc"? - ld a, SCREEN_WIDTH - 6 - ld b, a - -.okay - ld a, b - ld [wMenuBorderLeftCoord], a - add 5 - ld [wMenuBorderRightCoord], a - ld a, c - ld [wMenuBorderTopCoord], a - add 4 - ld [wMenuBorderBottomCoord], a - call PushWindow - -InterpretTwoOptionMenu:: - call VerticalMenu - push af - ld c, $f - call DelayFrames - call CloseWindow - pop af - jr c, .no - ld a, [wMenuCursorY] - cp 2 ; no - jr z, .no - and a - ret - -.no - ld a, 2 - ld [wMenuCursorY], a - scf - ret - -YesNoMenuHeader:: - db MENU_BACKUP_TILES ; flags - menu_coords 10, 5, 15, 9 - dw .MenuData - db 1 ; default option - -.MenuData: - db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags - db 2 - db "YES@" - db "NO@" - -OffsetMenuHeader:: - call _OffsetMenuHeader - call PushWindow - ret - -_OffsetMenuHeader:: - push de - call CopyMenuHeader - pop de - ld a, [wMenuBorderLeftCoord] - ld h, a - ld a, [wMenuBorderRightCoord] - sub h - ld h, a - ld a, d - ld [wMenuBorderLeftCoord], a - add h - ld [wMenuBorderRightCoord], a - ld a, [wMenuBorderTopCoord] - ld l, a - ld a, [wMenuBorderBottomCoord] - sub l - ld l, a - ld a, e - ld [wMenuBorderTopCoord], a - add l - ld [wMenuBorderBottomCoord], a - ret - -DoNthMenu:: - call DrawVariableLengthMenuBox - call MenuWriteText - call InitMenuCursorAndButtonPermissions - call GetStaticMenuJoypad - call GetMenuJoypad - call MenuClickSound - ret - -SetUpMenu:: - call DrawVariableLengthMenuBox ; ??? - call MenuWriteText - call InitMenuCursorAndButtonPermissions ; set up selection pointer - ld hl, w2DMenuFlags1 - set 7, [hl] - ret - -DrawVariableLengthMenuBox:: - call CopyMenuData - call GetMenuIndexSet - call AutomaticGetMenuBottomCoord - call MenuBox - ret - -MenuWriteText:: - xor a - ldh [hBGMapMode], a - call GetMenuIndexSet ; sort out the text - call RunMenuItemPrintingFunction ; actually write it - call SafeUpdateSprites - ldh a, [hOAMUpdate] - push af - ld a, $1 - ldh [hOAMUpdate], a - call ApplyTilemap - pop af - ldh [hOAMUpdate], a - ret - -AutomaticGetMenuBottomCoord:: - ld a, [wMenuBorderLeftCoord] - ld c, a - ld a, [wMenuBorderRightCoord] - sub c - ld c, a - ld a, [wMenuDataItems] - add a - inc a - ld b, a - ld a, [wMenuBorderTopCoord] - add b - ld [wMenuBorderBottomCoord], a - ret - -GetMenuIndexSet:: - ld hl, wMenuDataIndicesPointer - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [wWhichIndexSet] - and a - jr z, .skip - ld b, a - ld c, -1 -.loop - ld a, [hli] - cp c - jr nz, .loop - dec b - jr nz, .loop - -.skip - ld d, h - ld e, l - ld a, [hl] - ld [wMenuDataItems], a - ret - -RunMenuItemPrintingFunction:: - call MenuBoxCoord2Tile - ld bc, 2 * SCREEN_WIDTH + 2 - add hl, bc -.loop - inc de - ld a, [de] - cp -1 - ret z - ld [wMenuSelection], a - push de - push hl - ld d, h - ld e, l - ld hl, wMenuDataDisplayFunctionPointer - call ._hl_ - pop hl - ld de, 2 * SCREEN_WIDTH - add hl, de - pop de - jr .loop - -._hl_ - ld a, [hli] - ld h, [hl] - ld l, a - jp hl - -InitMenuCursorAndButtonPermissions:: - call InitVerticalMenuCursor - ld hl, wMenuJoypadFilter - ld a, [wMenuDataFlags] - bit 3, a - jr z, .disallow_select - set START_F, [hl] - -.disallow_select - ld a, [wMenuDataFlags] - bit 2, a - jr z, .disallow_left_right - set D_LEFT_F, [hl] - set D_RIGHT_F, [hl] - -.disallow_left_right - ret - -GetScrollingMenuJoypad:: - call ScrollingMenuJoypad - ld hl, wMenuJoypadFilter - and [hl] - jr ContinueGettingMenuJoypad - -GetStaticMenuJoypad:: - xor a - ld [wMenuJoypad], a - call StaticMenuJoypad - -ContinueGettingMenuJoypad: - bit A_BUTTON_F, a - jr nz, .a_button - bit B_BUTTON_F, a - jr nz, .b_start - bit START_F, a - jr nz, .b_start - bit D_RIGHT_F, a - jr nz, .d_right - bit D_LEFT_F, a - jr nz, .d_left - xor a - ld [wMenuJoypad], a - jr .done - -.d_right - ld a, D_RIGHT - ld [wMenuJoypad], a - jr .done - -.d_left - ld a, D_LEFT - ld [wMenuJoypad], a - jr .done - -.a_button - ld a, A_BUTTON - ld [wMenuJoypad], a - -.done - call GetMenuIndexSet - ld a, [wMenuCursorY] - ld l, a - ld h, $0 - add hl, de - ld a, [hl] - ld [wMenuSelection], a - ld a, [wMenuCursorY] - ld [wMenuCursorBuffer], a - and a - ret - -.b_start - ld a, B_BUTTON - ld [wMenuJoypad], a - ld a, -1 - ld [wMenuSelection], a - scf - ret - -PlaceMenuStrings:: - push de - ld hl, wMenuDataPointerTableAddr - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [wMenuSelection] - call GetNthString - ld d, h - ld e, l - pop hl - call PlaceString - ret - -PlaceNthMenuStrings:: - push de - ld a, [wMenuSelection] - call GetMenuDataPointerTableEntry - inc hl - inc hl - ld a, [hli] - ld d, [hl] - ld e, a - pop hl - call PlaceString - ret - -Unreferenced_Function1f9e:: - call GetMenuDataPointerTableEntry - inc hl - inc hl - ld a, [hli] - ld d, [hl] - ld e, a - ret - -MenuJumptable:: - ld a, [wMenuSelection] - call GetMenuDataPointerTableEntry - ld a, [hli] - ld h, [hl] - ld l, a - jp hl - -GetMenuDataPointerTableEntry:: - ld e, a - ld d, $0 - ld hl, wMenuDataPointerTableAddr - ld a, [hli] - ld h, [hl] - ld l, a - add hl, de - add hl, de - add hl, de - add hl, de - ret - -ClearWindowData:: - ld hl, wWindowStackPointer - call .bytefill - ld hl, wMenuHeader - call .bytefill - ld hl, wMenuDataFlags - call .bytefill - ld hl, w2DMenuCursorInitY - call .bytefill - - ldh a, [rSVBK] - push af - ld a, BANK(wWindowStack) - ldh [rSVBK], a - - xor a - ld hl, wWindowStackBottom - ld [hld], a - ld [hld], a - ld a, l - ld [wWindowStackPointer], a - ld a, h - ld [wWindowStackPointer + 1], a - - pop af - ldh [rSVBK], a - ret - -.bytefill - ld bc, $10 - xor a - call ByteFill - ret - -MenuClickSound:: - push af - and A_BUTTON | B_BUTTON - jr z, .nosound - ld hl, wMenuFlags - bit 3, [hl] - jr nz, .nosound - call PlayClickSFX -.nosound - pop af - ret - -PlayClickSFX:: - push de - ld de, SFX_READ_TEXT_2 - call PlaySFX - pop de - ret - -MenuTextboxWaitButton:: - call MenuTextbox - call WaitButton - call ExitMenu - ret - -Place2DMenuItemName:: - ldh [hBuffer], a - ldh a, [hROMBank] - push af - ldh a, [hBuffer] - rst Bankswitch - - call PlaceString - pop af - rst Bankswitch - - ret - -_2DMenu:: - ldh a, [hROMBank] - ld [wMenuData_2DMenuItemStringsBank], a - farcall _2DMenu_ - ld a, [wMenuCursorBuffer] - ret - -InterpretBattleMenu:: - ldh a, [hROMBank] - ld [wMenuData_2DMenuItemStringsBank], a - farcall _InterpretBattleMenu - ld a, [wMenuCursorBuffer] - ret - -InterpretMobileMenu:: - ldh a, [hROMBank] - ld [wMenuData_2DMenuItemStringsBank], a - farcall _InterpretMobileMenu - ld a, [wMenuCursorBuffer] - ret diff --git a/home/menu_window.asm b/home/menu_window.asm deleted file mode 100644 index d66485041..000000000 --- a/home/menu_window.asm +++ /dev/null @@ -1,242 +0,0 @@ -PushWindow:: - callfar _PushWindow - ret - -ExitMenu:: - push af - callfar _ExitMenu - pop af - ret - -InitVerticalMenuCursor:: - callfar _InitVerticalMenuCursor - ret - -CloseWindow:: - push af - call ExitMenu - call ApplyTilemap - call UpdateSprites - pop af - ret - -RestoreTileBackup:: - call MenuBoxCoord2Tile - call .copy - call MenuBoxCoord2Attr - call .copy - ret - -.copy - call GetMenuBoxDims - inc b - inc c - -.row - push bc - push hl - -.col - ld a, [de] - ld [hli], a - dec de - dec c - jr nz, .col - - pop hl - ld bc, SCREEN_WIDTH - add hl, bc - pop bc - dec b - jr nz, .row - - ret - -PopWindow:: - ld b, $10 - ld de, wMenuFlags -.loop - ld a, [hld] - ld [de], a - inc de - dec b - jr nz, .loop - ret - -GetMenuBoxDims:: - ld a, [wMenuBorderTopCoord] ; top - ld b, a - ld a, [wMenuBorderBottomCoord] ; bottom - sub b - ld b, a - ld a, [wMenuBorderLeftCoord] ; left - ld c, a - ld a, [wMenuBorderRightCoord] ; right - sub c - ld c, a - ret - -CopyMenuData:: - push hl - push de - push bc - push af - ld hl, wMenuDataPointer - ld a, [hli] - ld h, [hl] - ld l, a - ld de, wMenuDataFlags - ld bc, wMenuDataEnd - wMenuDataFlags - call CopyBytes - pop af - pop bc - pop de - pop hl - ret - -GetWindowStackTop:: - ld hl, wWindowStackPointer - ld a, [hli] - ld h, [hl] - ld l, a - inc hl - ld a, [hli] - ld h, [hl] - ld l, a - ret - -PlaceVerticalMenuItems:: - call CopyMenuData - ld hl, wMenuDataPointer - ld e, [hl] - inc hl - ld d, [hl] - call GetMenuTextStartCoord - call Coord2Tile ; hl now contains the tilemap address where we will start printing text. - inc de - ld a, [de] ; Number of items - inc de - ld b, a -.loop - push bc - call PlaceString - inc de - ld bc, 2 * SCREEN_WIDTH - add hl, bc - pop bc - dec b - jr nz, .loop - - ld a, [wMenuDataFlags] - bit 4, a - ret z - - call MenuBoxCoord2Tile - ld a, [de] - ld c, a - inc de - ld b, $0 - add hl, bc - jp PlaceString - -MenuBox:: - call MenuBoxCoord2Tile - call GetMenuBoxDims - dec b - dec c - jp Textbox - -GetMenuTextStartCoord:: - ld a, [wMenuBorderTopCoord] - ld b, a - inc b - ld a, [wMenuBorderLeftCoord] - ld c, a - inc c -; bit 6: if not set, leave extra room on top - ld a, [wMenuDataFlags] - bit 6, a - jr nz, .bit_6_set - inc b - -.bit_6_set -; bit 7: if set, leave extra room on the left - ld a, [wMenuDataFlags] - bit 7, a - jr z, .bit_7_clear - inc c - -.bit_7_clear - ret - -ClearMenuBoxInterior:: - call MenuBoxCoord2Tile - ld bc, SCREEN_WIDTH + 1 - add hl, bc - call GetMenuBoxDims - dec b - dec c - call ClearBox - ret - -ClearWholeMenuBox:: - call MenuBoxCoord2Tile - call GetMenuBoxDims - inc c - inc b - call ClearBox - ret - -MenuBoxCoord2Tile:: - ld a, [wMenuBorderLeftCoord] - ld c, a - ld a, [wMenuBorderTopCoord] - ld b, a - -Coord2Tile:: -; Return the address of wTilemap(c, b) in hl. - xor a - ld h, a - ld l, b - ld a, c - ld b, h - ld c, l - add hl, hl - add hl, hl - add hl, bc - add hl, hl - add hl, hl - ld c, a - xor a - ld b, a - add hl, bc - bccoord 0, 0 - add hl, bc - ret - -MenuBoxCoord2Attr:: - ld a, [wMenuBorderLeftCoord] - ld c, a - ld a, [wMenuBorderTopCoord] - ld b, a - -Coord2Attr:: -; Return the address of wAttrmap(c, b) in hl. - xor a - ld h, a - ld l, b - ld a, c - ld b, h - ld c, l - add hl, hl - add hl, hl - add hl, bc - add hl, hl - add hl, hl - ld c, a - xor a - ld b, a - add hl, bc - bccoord 0, 0, wAttrmap - add hl, bc - ret diff --git a/home/mon_data.asm b/home/mon_data.asm deleted file mode 100644 index f365f019c..000000000 --- a/home/mon_data.asm +++ /dev/null @@ -1,87 +0,0 @@ -Unreferenced_GetNthMove:: - ld hl, wListMoves_MoveIndicesBuffer - ld c, a - ld b, 0 - add hl, bc - ld a, [hl] - ret - -GetBaseData:: - push bc - push de - push hl - ldh a, [hROMBank] - push af - ld a, BANK(BaseData) - rst Bankswitch - -; Egg doesn't have BaseData - ld a, [wCurSpecies] - cp EGG - jr z, .egg - -; Get BaseData - dec a - ld bc, BASE_DATA_SIZE - ld hl, BaseData - call AddNTimes - ld de, wCurBaseData - ld bc, BASE_DATA_SIZE - call CopyBytes - jr .end - -.egg - ld de, UnknownEggPic - -; Sprite dimensions - ld b, $55 ; 5x5 - ld hl, wBasePicSize - ld [hl], b - -; Beta front and back sprites -; (see pokegold-spaceworld's data/pokemon/base_stats/*) - ld hl, wBaseUnusedFrontpic - ld [hl], e - inc hl - ld [hl], d - inc hl - ld [hl], e - inc hl - ld [hl], d - jr .end ; useless - -.end -; Replace Pokedex # with species - ld a, [wCurSpecies] - ld [wBaseDexNo], a - - pop af - rst Bankswitch - pop hl - pop de - pop bc - ret - -GetCurNick:: - ld a, [wCurPartyMon] - ld hl, wPartyMonNicknames - -GetNick:: -; Get nickname a from list hl. - - push hl - push bc - - call SkipNames - ld de, wStringBuffer1 - - push de - ld bc, MON_NAME_LENGTH - call CopyBytes - pop de - - callfar CorrectNickErrors - - pop bc - pop hl - ret diff --git a/home/mon_data_2.asm b/home/mon_data_2.asm deleted file mode 100644 index 99169eaa8..000000000 --- a/home/mon_data_2.asm +++ /dev/null @@ -1,34 +0,0 @@ -GetPartyParamLocation:: -; Get the location of parameter a from wCurPartyMon in hl - push bc - ld hl, wPartyMons - ld c, a - ld b, 0 - add hl, bc - ld a, [wCurPartyMon] - call GetPartyLocation - pop bc - ret - -GetPartyLocation:: -; Add the length of a PartyMon struct to hl a times. - ld bc, PARTYMON_STRUCT_LENGTH - jp AddNTimes - -Unreferenced_GetDexNumber:: -; Probably used in gen 1 to convert index number to dex number -; Not required in gen 2 because index number == dex number - push hl - ld a, b - dec a - ld b, 0 - add hl, bc - ld hl, BaseData + BASE_DEX_NO - ld bc, BASE_DATA_SIZE - call AddNTimes - ld a, BANK(BaseData) - call GetFarHalfword - ld b, l - ld c, h - pop hl - ret diff --git a/home/mon_stats.asm b/home/mon_stats.asm deleted file mode 100644 index d064d4798..000000000 --- a/home/mon_stats.asm +++ /dev/null @@ -1,104 +0,0 @@ -IsAPokemon:: -; Return carry if species a is not a Pokemon. - and a - jr z, .NotAPokemon - cp EGG - jr z, .Pokemon - cp NUM_POKEMON + 1 - jr c, .Pokemon - -.NotAPokemon: - scf - ret - -.Pokemon: - and a - ret - -DrawBattleHPBar:: -; Draw an HP bar d tiles long at hl -; Fill it up to e pixels - - push hl - push de - push bc - -; Place 'HP:' - ld a, $60 - ld [hli], a - ld a, $61 - ld [hli], a - -; Draw a template - push hl - ld a, $62 ; empty bar -.template - ld [hli], a - dec d - jr nz, .template - ld a, $6b ; bar end - add b - ld [hl], a - pop hl - -; Safety check # pixels - ld a, e - and a - jr nz, .fill - ld a, c - and a - jr z, .done - ld e, 1 - -.fill -; Keep drawing tiles until pixel length is reached - ld a, e - sub TILE_WIDTH - jr c, .lastbar - - ld e, a - ld a, $6a ; full bar - ld [hli], a - ld a, e - and a - jr z, .done - jr .fill - -.lastbar - ld a, $62 ; empty bar - add e ; + e - ld [hl], a - -.done - pop bc - pop de - pop hl - ret - -PrepMonFrontpic:: - ld a, $1 - ld [wBoxAlignment], a - -_PrepMonFrontpic:: - ld a, [wCurPartySpecies] - call IsAPokemon - jr c, .not_pokemon - - push hl - ld de, vTiles2 - predef GetMonFrontpic - pop hl - xor a - ldh [hGraphicStartTile], a - lb bc, 7, 7 - predef PlaceGraphic - xor a - ld [wBoxAlignment], a - ret - -.not_pokemon - xor a - ld [wBoxAlignment], a - inc a - ld [wCurPartySpecies], a - ret diff --git a/home/pokedex_flags.asm b/home/pokedex_flags.asm index 809341509..5c12da511 100644 --- a/home/pokedex_flags.asm +++ b/home/pokedex_flags.asm @@ -1,3 +1,35 @@ +CountSetBits:: +; Count the number of set bits in b bytes starting from hl. +; Return in a, c and [wNumSetBits]. + ld c, 0 +.next + ld a, [hli] + ld e, a + ld d, 8 + +.count + srl e + ld a, 0 + adc c + ld c, a + dec d + jr nz, .count + + dec b + jr nz, .next + + ld a, c + ld [wNumSetBits], a + ret + +GetWeekday:: + ld a, [wCurDay] +.mod + sub 7 + jr nc, .mod + add 7 + ret + SetSeenAndCaughtMon:: push af ld c, a diff --git a/home/pokemon.asm b/home/pokemon.asm new file mode 100644 index 000000000..e1d39bb9d --- /dev/null +++ b/home/pokemon.asm @@ -0,0 +1,323 @@ +IsAPokemon:: +; Return carry if species a is not a Pokemon. + and a + jr z, .NotAPokemon + cp EGG + jr z, .Pokemon + cp NUM_POKEMON + 1 + jr c, .Pokemon + +.NotAPokemon: + scf + ret + +.Pokemon: + and a + ret + +DrawBattleHPBar:: +; Draw an HP bar d tiles long at hl +; Fill it up to e pixels + + push hl + push de + push bc + +; Place 'HP:' + ld a, $60 + ld [hli], a + ld a, $61 + ld [hli], a + +; Draw a template + push hl + ld a, $62 ; empty bar +.template + ld [hli], a + dec d + jr nz, .template + ld a, $6b ; bar end + add b + ld [hl], a + pop hl + +; Safety check # pixels + ld a, e + and a + jr nz, .fill + ld a, c + and a + jr z, .done + ld e, 1 + +.fill +; Keep drawing tiles until pixel length is reached + ld a, e + sub TILE_WIDTH + jr c, .lastbar + + ld e, a + ld a, $6a ; full bar + ld [hli], a + ld a, e + and a + jr z, .done + jr .fill + +.lastbar + ld a, $62 ; empty bar + add e ; + e + ld [hl], a + +.done + pop bc + pop de + pop hl + ret + +PrepMonFrontpic:: + ld a, $1 + ld [wBoxAlignment], a + +_PrepMonFrontpic:: + ld a, [wCurPartySpecies] + call IsAPokemon + jr c, .not_pokemon + + push hl + ld de, vTiles2 + predef GetMonFrontpic + pop hl + xor a + ldh [hGraphicStartTile], a + lb bc, 7, 7 + predef PlaceGraphic + xor a + ld [wBoxAlignment], a + ret + +.not_pokemon + xor a + ld [wBoxAlignment], a + inc a + ld [wCurPartySpecies], a + ret + +PlayStereoCry:: + push af + ld a, 1 + ld [wStereoPanningMask], a + pop af + call _PlayMonCry + call WaitSFX + ret + +PlayStereoCry2:: +; Don't wait for the cry to end. +; Used during pic animations. + push af + ld a, 1 + ld [wStereoPanningMask], a + pop af + jp _PlayMonCry + +PlayMonCry:: + call PlayMonCry2 + call WaitSFX + ret + +PlayMonCry2:: +; Don't wait for the cry to end. + push af + xor a + ld [wStereoPanningMask], a + ld [wCryTracks], a + pop af + call _PlayMonCry + ret + +_PlayMonCry:: + push hl + push de + push bc + + call GetCryIndex + jr c, .done + + ld e, c + ld d, b + call PlayCry + +.done + pop bc + pop de + pop hl + ret + +LoadCry:: +; Load cry bc. + + call GetCryIndex + ret c + + ldh a, [hROMBank] + push af + ld a, BANK(PokemonCries) + rst Bankswitch + + ld hl, PokemonCries +rept 6 ; sizeof(mon_cry) + add hl, bc +endr + + ld e, [hl] + inc hl + ld d, [hl] + inc hl + + ld a, [hli] + ld [wCryPitch], a + ld a, [hli] + ld [wCryPitch + 1], a + ld a, [hli] + ld [wCryLength], a + ld a, [hl] + ld [wCryLength + 1], a + + pop af + rst Bankswitch + and a + ret + +GetCryIndex:: + and a + jr z, .no + cp NUM_POKEMON + 1 + jr nc, .no + + dec a + ld c, a + ld b, 0 + and a + ret + +.no + scf + ret + +PrintLevel:: +; Print wTempMonLevel at hl + + ld a, [wTempMonLevel] + ld [hl], "<LV>" + inc hl + +; How many digits? + ld c, 2 + cp 100 ; This is distinct from MAX_LEVEL. + jr c, Print8BitNumLeftAlign + +; 3-digit numbers overwrite the :L. + dec hl + inc c + jr Print8BitNumLeftAlign + +PrintLevel_Force3Digits:: +; Print :L and all 3 digits + ld [hl], "<LV>" + inc hl + ld c, 3 + +Print8BitNumLeftAlign:: + ld [wDeciramBuffer], a + ld de, wDeciramBuffer + ld b, PRINTNUM_LEFTALIGN | 1 + jp PrintNum + +Unreferenced_GetNthMove:: + ld hl, wListMoves_MoveIndicesBuffer + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + ret + +GetBaseData:: + push bc + push de + push hl + ldh a, [hROMBank] + push af + ld a, BANK(BaseData) + rst Bankswitch + +; Egg doesn't have BaseData + ld a, [wCurSpecies] + cp EGG + jr z, .egg + +; Get BaseData + dec a + ld bc, BASE_DATA_SIZE + ld hl, BaseData + call AddNTimes + ld de, wCurBaseData + ld bc, BASE_DATA_SIZE + call CopyBytes + jr .end + +.egg + ld de, UnknownEggPic + +; Sprite dimensions + ld b, $55 ; 5x5 + ld hl, wBasePicSize + ld [hl], b + +; Beta front and back sprites +; (see pokegold-spaceworld's data/pokemon/base_stats/*) + ld hl, wBaseUnusedFrontpic + ld [hl], e + inc hl + ld [hl], d + inc hl + ld [hl], e + inc hl + ld [hl], d + jr .end ; useless + +.end +; Replace Pokedex # with species + ld a, [wCurSpecies] + ld [wBaseDexNo], a + + pop af + rst Bankswitch + pop hl + pop de + pop bc + ret + +GetCurNick:: + ld a, [wCurPartyMon] + ld hl, wPartyMonNicknames + +GetNick:: +; Get nickname a from list hl. + + push hl + push bc + + call SkipNames + ld de, wStringBuffer1 + + push de + ld bc, MON_NAME_LENGTH + call CopyBytes + pop de + + callfar CorrectNickErrors + + pop bc + pop hl + ret diff --git a/home/print_level.asm b/home/print_level.asm deleted file mode 100644 index bdd11aabb..000000000 --- a/home/print_level.asm +++ /dev/null @@ -1,28 +0,0 @@ -PrintLevel:: -; Print wTempMonLevel at hl - - ld a, [wTempMonLevel] - ld [hl], "<LV>" - inc hl - -; How many digits? - ld c, 2 - cp 100 ; This is distinct from MAX_LEVEL. - jr c, Print8BitNumLeftAlign - -; 3-digit numbers overwrite the :L. - dec hl - inc c - jr Print8BitNumLeftAlign - -PrintLevel_Force3Digits:: -; Print :L and all 3 digits - ld [hl], "<LV>" - inc hl - ld c, 3 - -Print8BitNumLeftAlign:: - ld [wDeciramBuffer], a - ld de, wDeciramBuffer - ld b, PRINTNUM_LEFTALIGN | 1 - jp PrintNum diff --git a/home/print_text.asm b/home/print_text.asm index b7f76ce64..51f23edb2 100644 --- a/home/print_text.asm +++ b/home/print_text.asm @@ -118,3 +118,20 @@ FarPrintText:: pop af rst Bankswitch ret + +CallPointerAt:: + ldh a, [hROMBank] + push af + ld a, [hli] + rst Bankswitch + + ld a, [hli] + ld h, [hl] + ld l, a + + call _hl_ + + pop hl + ld a, h + rst Bankswitch + ret diff --git a/home/handshake.asm b/home/printer.asm index 9747713c7..9747713c7 100644 --- a/home/handshake.asm +++ b/home/printer.asm diff --git a/home/region.asm b/home/region.asm index 4cb3d4768..eedcbbee4 100644 --- a/home/region.asm +++ b/home/region.asm @@ -30,3 +30,6 @@ IsInJohto:: .Kanto: ld a, 1 ret + +ret_2f3e:: + ret diff --git a/home/rst.asm b/home/rst.asm deleted file mode 100644 index 6fe5bd572..000000000 --- a/home/rst.asm +++ /dev/null @@ -1,35 +0,0 @@ -; rst vectors - -SECTION "rst0", ROM0 - di - jp Start - -SECTION "rst8", ROM0 ; rst FarCall - jp FarCall_hl - -SECTION "rst10", ROM0 ; rst Bankswitch - ldh [hROMBank], a - ld [MBC3RomBank], a - ret - -SECTION "rst18", ROM0 - rst $38 - -SECTION "rst20", ROM0 - rst $38 - -SECTION "rst28", ROM0 ; rst JumpTable - push de - ld e, a - ld d, 0 - add hl, de - add hl, de - ld a, [hli] - ld h, [hl] -; SECTION "rst30", ROM0 - ld l, a - pop de - jp hl - -SECTION "rst38", ROM0 - rst $38 diff --git a/home/sprite_anims.asm b/home/sprite_anims.asm index 816849981..e20c63ac5 100644 --- a/home/sprite_anims.asm +++ b/home/sprite_anims.asm @@ -1,22 +1,3 @@ -PushLYOverrides:: - ldh a, [hLCDCPointer] - and a - ret z - - ld a, LOW(wLYOverridesBackup) - ld [wRequested2bppSource], a - ld a, HIGH(wLYOverridesBackup) - ld [wRequested2bppSource + 1], a - - ld a, LOW(wLYOverrides) - ld [wRequested2bppDest], a - ld a, HIGH(wLYOverrides) - ld [wRequested2bppDest + 1], a - - ld a, (wLYOverridesEnd - wLYOverrides) / 16 - ld [wRequested2bpp], a - ret - InitSpriteAnimStruct:: ld [wSpriteAnimIDBuffer], a ldh a, [hROMBank] diff --git a/home/tilemap.asm b/home/tilemap.asm index 914027845..379b1464a 100644 --- a/home/tilemap.asm +++ b/home/tilemap.asm @@ -216,3 +216,21 @@ GetSGBLayout:: .sgb predef_jump LoadSGBLayout + +SetHPPal:: +; Set palette for hp bar pixel length e at hl. + call GetHPPal + ld [hl], d + ret + +GetHPPal:: +; Get palette for hp bar pixel length e in d. + ld d, HP_GREEN + ld a, e + cp (HP_BAR_LENGTH_PX * 50 / 100) ; 24 + ret nc + inc d ; HP_YELLOW + cp (HP_BAR_LENGTH_PX * 21 / 100) ; 10 + ret nc + inc d ; HP_RED + ret diff --git a/home/rtc.asm b/home/time_palettes.asm index 7dc4e776a..7dc4e776a 100644 --- a/home/rtc.asm +++ b/home/time_palettes.asm diff --git a/home/vblank.asm b/home/vblank.asm index e86ee00b7..4fea80c50 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -131,7 +131,7 @@ VBlank0:: ld [wTextDelayFrames], a .ok2 - call Joypad + call UpdateJoypad ld a, BANK(_UpdateSound) rst Bankswitch @@ -325,7 +325,7 @@ VBlank4:: call hTransferVirtualOAM - call Joypad + call UpdateJoypad xor a ld [wVBlankOccurred], a @@ -364,7 +364,7 @@ VBlank5:: xor a ld [wVBlankOccurred], a - call Joypad + call UpdateJoypad xor a ldh [rIF], a |