From 1cf79b6f15761ec95ba1b0f9d6d83781c4240612 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 7 Aug 2014 21:17:44 -0700 Subject: Fix static banks passed into GetName. This appears to be the only other use of wPredefBank. Chances are there are more uncaught banks. Known cases are marked as "hardcoded" or similar. --- home.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index dc0b0889..8c8f5c35 100644 --- a/home.asm +++ b/home.asm @@ -2044,7 +2044,7 @@ DisplayListMenuIDLoop:: ; 2c53 (0:2c53) .skipGettingQuantity ld a,[wcf91] ld [wd0b5],a - ld a,$01 + ld a,BANK(ItemNames) ld [wPredefBank],a call GetName jr .storeChosenEntry @@ -3782,7 +3782,7 @@ GetName:: ; 376b (0:376b) ; returns pointer to name in de ld a,[wd0b5] ld [wd11e],a - cp a,$C4 ;it's TM/HM + cp HM_01 jp nc,GetMachineName ld a,[H_LOADEDROMBANK] push af @@ -3858,8 +3858,8 @@ GetItemPrice:: ; 37df (0:37df) ld a, [H_LOADEDROMBANK] push af ld a, [wListMenuID] ; wListMenuID - cp $1 - ld a, $1 ; hardcoded Bank + cp MOVESLISTMENU + ld a, BANK(ItemPrices) jr nz, .asm_37ed ld a, $f ; hardcoded Bank .asm_37ed -- cgit v1.2.3 From cf399a8c86a7340a8c3162400657dca1c5d3ba0a Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 12 Aug 2014 00:01:04 -0700 Subject: Split copy and serial functions out of home.asm. --- home.asm | 573 +-------------------------------------------------------------- 1 file changed, 4 insertions(+), 569 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index 8c8f5c35..ad010cde 100644 --- a/home.asm +++ b/home.asm @@ -79,30 +79,7 @@ HideSprites:: jr nz, .loop ret -FarCopyData:: -; Copy bc bytes from a:hl to de. - ld [wBuffer], a - ld a, [H_LOADEDROMBANK] - push af - ld a, [wBuffer] - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - call CopyData - pop af - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - ret - -CopyData:: -; Copy bc bytes from hl to de. - ld a, [hli] - ld [de], a - inc de - dec bc - ld a, c - or b - jr nz, CopyData - ret +INCLUDE "home/copy.asm" SECTION "Entry", ROM0[$100] @@ -908,556 +885,14 @@ InterlaceMergeSpriteBuffers:: ; 16ea (0:16ea) INCLUDE "data/collision.asm" - - -FarCopyData2:: -; Identical to FarCopyData, but uses $ff8b -; as temp space instead of wBuffer. - ld [$ff8b],a - ld a,[H_LOADEDROMBANK] - push af - ld a,[$ff8b] - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a - call CopyData - pop af - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a - ret - -FarCopyData3:: -; Copy bc bytes from a:de to hl. - ld [$ff8b],a - ld a,[H_LOADEDROMBANK] - push af - ld a,[$ff8b] - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a - push hl - push de - push de - ld d,h - ld e,l - pop hl - call CopyData - pop de - pop hl - pop af - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a - ret - -FarCopyDataDouble:: -; Expand bc bytes of 1bpp image data -; from a:hl to 2bpp data at de. - ld [$ff8b],a - ld a,[H_LOADEDROMBANK] - push af - ld a,[$ff8b] - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a -.loop - ld a,[hli] - ld [de],a - inc de - ld [de],a - inc de - dec bc - ld a,c - or b - jr nz,.loop - pop af - ld [H_LOADEDROMBANK],a - ld [MBC3RomBank],a - ret - -CopyVideoData:: -; Wait for the next VBlank, then copy c 2bpp -; tiles from b:de to hl, 8 tiles at a time. -; This takes c/8 frames. - - ld a, [H_AUTOBGTRANSFERENABLED] - push af - xor a ; disable auto-transfer while copying - ld [H_AUTOBGTRANSFERENABLED], a - - ld a, [H_LOADEDROMBANK] - ld [$ff8b], a - - ld a, b - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - - ld a, e - ld [H_VBCOPYSRC], a - ld a, d - ld [H_VBCOPYSRC + 1], a - - ld a, l - ld [H_VBCOPYDEST], a - ld a, h - ld [H_VBCOPYDEST + 1], a - -.loop - ld a, c - cp 8 - jr nc, .keepgoing - -.done - ld [H_VBCOPYSIZE], a - call DelayFrame - ld a, [$ff8b] - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - pop af - ld [H_AUTOBGTRANSFERENABLED], a - ret - -.keepgoing - ld a, 8 - ld [H_VBCOPYSIZE], a - call DelayFrame - ld a, c - sub 8 - ld c, a - jr .loop - -CopyVideoDataDouble:: -; Wait for the next VBlank, then copy c 1bpp -; tiles from b:de to hl, 8 tiles at a time. -; This takes c/8 frames. - ld a, [H_AUTOBGTRANSFERENABLED] - push af - xor a ; disable auto-transfer while copying - ld [H_AUTOBGTRANSFERENABLED], a - ld a, [H_LOADEDROMBANK] - ld [$ff8b], a - - ld a, b - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - - ld a, e - ld [H_VBCOPYDOUBLESRC], a - ld a, d - ld [H_VBCOPYDOUBLESRC + 1], a - - ld a, l - ld [H_VBCOPYDOUBLEDEST], a - ld a, h - ld [H_VBCOPYDOUBLEDEST + 1], a - -.loop - ld a, c - cp 8 - jr nc, .keepgoing - -.done - ld [H_VBCOPYDOUBLESIZE], a - call DelayFrame - ld a, [$ff8b] - ld [H_LOADEDROMBANK], a - ld [MBC3RomBank], a - pop af - ld [H_AUTOBGTRANSFERENABLED], a - ret - -.keepgoing - ld a, 8 - ld [H_VBCOPYDOUBLESIZE], a - call DelayFrame - ld a, c - sub 8 - ld c, a - jr .loop - -ClearScreenArea:: -; Clear tilemap area cxb at hl. - ld a, $7f ; blank tile - ld de, 20 ; screen width -.y - push hl - push bc -.x - ld [hli], a - dec c - jr nz, .x - pop bc - pop hl - add hl, de - dec b - jr nz, .y - ret - -CopyScreenTileBufferToVRAM:: -; Copy wTileMap to the BG Map starting at b * $100. -; This is done in thirds of 6 rows, so it takes 3 frames. - - ld c, 6 - - ld hl, $600 * 0 - ld de, wTileMap + 20 * 6 * 0 - call .setup - call DelayFrame - - ld hl, $600 * 1 - ld de, wTileMap + 20 * 6 * 1 - call .setup - call DelayFrame - - ld hl, $600 * 2 - ld de, wTileMap + 20 * 6 * 2 - call .setup - jp DelayFrame - -.setup - ld a, d - ld [H_VBCOPYBGSRC+1], a - call GetRowColAddressBgMap - ld a, l - ld [H_VBCOPYBGDEST], a - ld a, h - ld [H_VBCOPYBGDEST+1], a - ld a, c - ld [H_VBCOPYBGNUMROWS], a - ld a, e - ld [H_VBCOPYBGSRC], a - ret - -ClearScreen:: -; Clear wTileMap, then wait -; for the bg map to update. - ld bc, 20 * 18 - inc b - ld hl, wTileMap - ld a, $7f -.loop - ld [hli], a - dec c - jr nz, .loop - dec b - jr nz, .loop - jp Delay3 - - +INCLUDE "home/copy2.asm" INCLUDE "home/text.asm" INCLUDE "home/vcopy.asm" INCLUDE "home/init.asm" INCLUDE "home/vblank.asm" INCLUDE "home/fade.asm" - - -Serial:: ; 2125 (0:2125) - push af - push bc - push de - push hl - ld a, [$ffaa] - inc a - jr z, .asm_2142 - ld a, [$ff01] - ld [$ffad], a - ld a, [$ffac] - ld [$ff01], a - ld a, [$ffaa] - cp $2 - jr z, .asm_2162 - ld a, $80 - ld [$ff02], a - jr .asm_2162 -.asm_2142 - ld a, [$ff01] - ld [$ffad], a - ld [$ffaa], a - cp $2 - jr z, .asm_215f - xor a - ld [$ff01], a - ld a, $3 - ld [rDIV], a ; $ff04 -.asm_2153 - ld a, [rDIV] ; $ff04 - bit 7, a - jr nz, .asm_2153 - ld a, $80 - ld [$ff02], a - jr .asm_2162 -.asm_215f - xor a - ld [$ff01], a -.asm_2162 - ld a, $1 - ld [$ffa9], a - ld a, $fe - ld [$ffac], a - pop hl - pop de - pop bc - pop af - reti - -Func_216f:: ; 216f (0:216f) - ld a, $1 - ld [$ffab], a -.asm_2173 - ld a, [hl] - ld [$ffac], a - call Func_219a - push bc - ld b, a - inc hl - ld a, $30 -.asm_217e - dec a - jr nz, .asm_217e - ld a, [$ffab] - and a - ld a, b - pop bc - jr z, .asm_2192 - dec hl - cp $fd - jr nz, .asm_2173 - xor a - ld [$ffab], a - jr .asm_2173 -.asm_2192 - ld [de], a - inc de - dec bc - ld a, b - or c - jr nz, .asm_2173 - ret - -Func_219a:: ; 219a (0:219a) - xor a - ld [$ffa9], a - ld a, [$ffaa] - cp $2 - jr nz, .asm_21a7 - ld a, $81 - ld [$ff02], a -.asm_21a7 - ld a, [$ffa9] - and a - jr nz, .asm_21f1 - ld a, [$ffaa] - cp $1 - jr nz, .asm_21cc - call Func_2237 - jr z, .asm_21cc - call Func_2231 - push hl - ld hl, wcc48 - inc [hl] - jr nz, .asm_21c3 - dec hl - inc [hl] -.asm_21c3 - pop hl - call Func_2237 - jr nz, .asm_21a7 - jp Func_223f -.asm_21cc - ld a, [rIE] ; $ffff - and $f - cp $8 - jr nz, .asm_21a7 - ld a, [W_NUMHITS] ; wd074 - dec a - ld [W_NUMHITS], a ; wd074 - jr nz, .asm_21a7 - ld a, [wd075] - dec a - ld [wd075], a - jr nz, .asm_21a7 - ld a, [$ffaa] - cp $1 - jr z, .asm_21f1 - ld a, $ff -.asm_21ee - dec a - jr nz, .asm_21ee -.asm_21f1 - xor a - ld [$ffa9], a - ld a, [rIE] ; $ffff - and $f - sub $8 - jr nz, .asm_2204 - ld [W_NUMHITS], a ; wd074 - ld a, $50 - ld [wd075], a -.asm_2204 - ld a, [$ffad] - cp $fe - ret nz - call Func_2237 - jr z, .asm_221f - push hl - ld hl, wcc48 - ld a, [hl] - dec a - ld [hld], a - inc a - jr nz, .asm_2219 - dec [hl] -.asm_2219 - pop hl - call Func_2237 - jr z, Func_223f -.asm_221f - ld a, [rIE] ; $ffff - and $f - cp $8 - ld a, $fe - ret z - ld a, [hl] - ld [$ffac], a - call DelayFrame - jp Func_219a - -Func_2231:: ; 2231 (0:2231) - ld a, $f -.asm_2233 - dec a - jr nz, .asm_2233 - ret - -Func_2237:: ; 2237 (0:2237) - push hl - ld hl, wcc47 - ld a, [hli] - or [hl] - pop hl - ret - -Func_223f:: ; 223f (0:223f) - dec a - ld [wcc47], a - ld [wcc48], a - ret - -Func_2247:: ; 2247 (0:2247) - ld hl, wcc42 - ld de, wcc3d - ld c, $2 - ld a, $1 - ld [$ffab], a -.asm_2253 - call DelayFrame - ld a, [hl] - ld [$ffac], a - call Func_219a - ld b, a - inc hl - ld a, [$ffab] - and a - ld a, $0 - ld [$ffab], a - jr nz, .asm_2253 - ld a, b - ld [de], a - inc de - dec c - jr nz, .asm_2253 - ret - -Func_226e:: ; 226e (0:226e) - call SaveScreenTilesToBuffer1 - callab PrintWaitingText - call Func_227f - jp LoadScreenTilesFromBuffer1 - -Func_227f:: ; 227f (0:227f) - ld a, $ff - ld [wcc3e], a -.asm_2284 - call Func_22c3 - call DelayFrame - call Func_2237 - jr z, .asm_22a0 - push hl - ld hl, wcc48 - dec [hl] - jr nz, .asm_229f - dec hl - dec [hl] - jr nz, .asm_229f - pop hl - xor a - jp Func_223f -.asm_229f - pop hl -.asm_22a0 - ld a, [wcc3e] - inc a - jr z, .asm_2284 - ld b, $a -.asm_22a8 - call DelayFrame - call Func_22c3 - dec b - jr nz, .asm_22a8 - ld b, $a -.asm_22b3 - call DelayFrame - call Func_22ed - dec b - jr nz, .asm_22b3 - ld a, [wcc3e] - ld [wcc3d], a - ret - -Func_22c3:: ; 22c3 (0:22c3) - call asm_22d7 - ld a, [wcc42] - add $60 - ld [$ffac], a - ld a, [$ffaa] - cp $2 - jr nz, asm_22d7 - ld a, $81 - ld [$ff02], a -asm_22d7:: ; 22d7 (0:22d7) - ld a, [$ffad] - ld [wcc3d], a - and $f0 - cp $60 - ret nz - xor a - ld [$ffad], a - ld a, [wcc3d] - and $f - ld [wcc3e], a - ret - -Func_22ed:: ; 22ed (0:22ed) - xor a - ld [$ffac], a - ld a, [$ffaa] - cp $2 - ret nz - ld a, $81 - ld [$ff02], a - ret - -Func_22fa:: ; 22fa (0:22fa) - ld a, $2 - ld [$ff01], a - xor a - ld [$ffad], a - ld a, $80 - ld [$ff02], a - ret - - -; timer interrupt is apparently not invoked anyway -Timer:: ; 2306 (0:2306) - reti - - +INCLUDE "home/serial.asm" +INCLUDE "home/timer.asm" INCLUDE "home/audio.asm" -- cgit v1.2.3 From 8f49e37b82a90bbef8c7133c4adea8f82abf00e7 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 30 Aug 2014 19:48:49 -0700 Subject: Use hram constants for remaining joypad variables. --- home.asm | 74 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index ad010cde..f83662ca 100644 --- a/home.asm +++ b/home.asm @@ -102,34 +102,34 @@ Start:: INCLUDE "home/joypad.asm" - INCLUDE "data/map_header_pointers.asm" - INCLUDE "home/overworld.asm" -; this is used to check if the player wants to interrupt the opening sequence at several points -; XXX is this used anywhere else? -; INPUT: -; c = number of frames to wait -; sets carry if Up+Select+B, Start, or A is pressed within c frames -; unsets carry otherwise + CheckForUserInterruption:: ; 12f8 (0:12f8) +; Return carry if Up+Select+B, Start or A are pressed in c frames. +; Used only in the intro and title screen. call DelayFrame + push bc call JoypadLowSensitivity pop bc - ld a,[hJoyHeld] ; currently pressed buttons - cp a,%01000110 ; Up, Select button, B button - jr z,.setCarry ; if all three keys are pressed - ld a,[$ffb5] ; either newly pressed buttons or currently pressed buttons at low sampling rate - and a,%00001001 ; Start button, A button - jr nz,.setCarry ; if either key is pressed + + ld a, [hJoyHeld] + cp D_UP + SELECT + B_BUTTON + jr z, .input + + ld a, [hJoy5] + and START | A_BUTTON + jr nz, .input + dec c - jr nz,CheckForUserInterruption -.unsetCarry + jr nz, CheckForUserInterruption + and a ret -.setCarry + +.input scf ret @@ -1347,7 +1347,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6) xor a ld [H_AUTOBGTRANSFERENABLED],a ; disable auto-transfer ld a,1 - ld [$ffb7],a ; joypad state update flag + ld [hJoy7],a ; joypad state update flag ld a,[W_BATTLETYPE] and a ; is it the Old Man battle? jr nz,.specialBattleType @@ -1501,7 +1501,7 @@ DisplayListMenuIDLoop:: ; 2c53 (0:2c53) ld a,[wCurrentMenuItem] ld [wd12d],a xor a - ld [$ffb7],a ; joypad state update flag + ld [hJoy7],a ; joypad state update flag ld hl,wd730 res 6,[hl] ; turn on letter printing delay jp BankswitchBack @@ -1662,7 +1662,7 @@ ExitListMenu:: ; 2e3b (0:2e3b) ld [wd12e],a ld [wcc37],a xor a - ld [$ffb7],a + ld [hJoy7],a ld hl,wd730 res 6,[hl] call BankswitchBack @@ -3347,29 +3347,29 @@ CopyString:: ; 3829 (0:3829) ret ; this function is used when lower button sensitivity is wanted (e.g. menus) -; OUTPUT: [$ffb5] = pressed buttons in usual format -; there are two flags that control its functionality, [$ffb6] and [$ffb7] +; OUTPUT: [hJoy5] = pressed buttons in usual format +; there are two flags that control its functionality, [hJoy6] and [hJoy7] ; there are esentially three modes of operation ; 1. Get newly pressed buttons only -; ([$ffb7] == 0, [$ffb6] == any) -; Just copies [hJoyPressed] to [$ffb5]. +; ([hJoy7] == 0, [hJoy6] == any) +; Just copies [hJoyPressed] to [hJoy5]. ; 2. Get currently pressed buttons at low sample rate with delay -; ([$ffb7] == 1, [$ffb6] != 0) +; ([hJoy7] == 1, [hJoy6] != 0) ; If the user holds down buttons for more than half a second, ; report buttons as being pressed up to 12 times per second thereafter. ; If the user holds down buttons for less than half a second, ; report only one button press. ; 3. Same as 2, but report no buttons as pressed if A or B is held down. -; ([$ffb7] == 1, [$ffb6] == 0) +; ([hJoy7] == 1, [hJoy6] == 0) JoypadLowSensitivity:: ; 3831 (0:3831) call Joypad - ld a,[$ffb7] ; flag + ld a,[hJoy7] ; flag and a ; get all currently pressed buttons or only newly pressed buttons? ld a,[hJoyPressed] ; newly pressed buttons jr z,.storeButtonState ld a,[hJoyHeld] ; all currently pressed buttons .storeButtonState - ld [$ffb5],a + ld [hJoy5],a ld a,[hJoyPressed] ; newly pressed buttons and a ; have any buttons been newly pressed since last check? jr z,.noNewlyPressedButtons @@ -3383,18 +3383,18 @@ JoypadLowSensitivity:: ; 3831 (0:3831) jr z,.delayOver .delayNotOver xor a - ld [$ffb5],a ; report no buttons as pressed + ld [hJoy5],a ; report no buttons as pressed ret .delayOver -; if [$ffb6] = 0 and A or B is pressed, report no buttons as pressed +; if [hJoy6] = 0 and A or B is pressed, report no buttons as pressed ld a,[hJoyHeld] and a,%00000011 ; A and B buttons jr z,.setShortDelay - ld a,[$ffb6] ; flag + ld a,[hJoy6] ; flag and a jr nz,.setShortDelay xor a - ld [$ffb5],a + ld [hJoy5],a .setShortDelay ld a,5 ; 1/12 of a second delay ld [H_FRAMECOUNTER],a @@ -3421,7 +3421,7 @@ WaitForTextScrollButtonPress:: ; 3865 (0:3865) pop hl call JoypadLowSensitivity predef Func_5a5f - ld a, [$ffb5] + ld a, [hJoy5] and A_BUTTON | B_BUTTON jr z, .asm_3872 pop af @@ -3888,7 +3888,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2) .getJoypadState pop hl call JoypadLowSensitivity - ld a,[$ffb5] + ld a,[hJoy5] and a ; was a key pressed? jr nz,.keyPressed push hl @@ -3911,7 +3911,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2) .keyPressed xor a ld [wcc4b],a - ld a,[$ffb5] + ld a,[hJoy5] ld b,a bit 6,a ; pressed Up key? jr z,.checkIfDownPressed @@ -3953,7 +3953,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2) and b ; does the menu care about any of the pressed keys? jp z,.loop1 .checkIfAButtonOrBButtonPressed - ld a,[$ffb5] + ld a,[hJoy5] and a,%00000011 ; pressed A button or B button? jr z,.skipPlayingSound .AButtonOrBButtonPressed @@ -3971,7 +3971,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2) ld [H_DOWNARROWBLINKCNT1],a ; restore previous values xor a ld [wMenuWrappingEnabled],a ; disable menu wrapping - ld a,[$ffb5] + ld a,[hJoy5] ret .noWrappingAround ld a,[wcc37] -- cgit v1.2.3 From fcfed136c6a0c094314bf75441af4d4b43cfc999 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Sep 2014 13:16:34 -0700 Subject: Don't define addresses for ROM0 sections in home.asm. Instead, occupy the space reserved for the rom header so there is no collision. --- home.asm | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index f83662ca..112bf265 100644 --- a/home.asm +++ b/home.asm @@ -1,35 +1,36 @@ + ; The rst vectors are unused. -SECTION "rst00", ROM0[$00] +SECTION "rst 00", ROM0 [$00] rst $38 -SECTION "rst08", ROM0[$08] +SECTION "rst 08", ROM0 [$08] rst $38 -SECTION "rst10", ROM0[$10] +SECTION "rst 10", ROM0 [$10] rst $38 -SECTION "rst18", ROM0[$18] +SECTION "rst 18", ROM0 [$18] rst $38 -SECTION "rst20", ROM0[$20] +SECTION "rst 20", ROM0 [$20] rst $38 -SECTION "rst28", ROM0[$28] +SECTION "rst 28", ROM0 [$28] rst $38 -SECTION "rst30", ROM0[$30] +SECTION "rst 30", ROM0 [$30] rst $38 -SECTION "rst38", ROM0[$38] +SECTION "rst 38", ROM0 [$38] rst $38 -; interrupts -SECTION "vblank", ROM0[$40] +; Hardware interrupts +SECTION "vblank", ROM0 [$40] jp VBlank -SECTION "lcdc", ROM0[$48] +SECTION "hblank", ROM0 [$48] rst $38 -SECTION "timer", ROM0[$50] +SECTION "timer", ROM0 [$50] jp Timer -SECTION "serial", ROM0[$58] +SECTION "serial", ROM0 [$58] jp Serial -SECTION "joypad", ROM0[$60] +SECTION "joypad", ROM0 [$60] reti -SECTION "bank0",ROM0[$61] +SECTION "Home", ROM0 DisableLCD:: xor a @@ -82,12 +83,23 @@ HideSprites:: INCLUDE "home/copy.asm" -SECTION "Entry", ROM0[$100] + +SECTION "Entry", ROM0 [$100] + nop jp Start -SECTION "Start", ROM0[$150] +SECTION "Header", ROM0 [$104] + + ; The header is generated by rgbfix. + ; The space here is allocated to prevent code from being overwritten. + + ds $150 - $104 + + + +SECTION "Main", ROM0 Start:: cp GBC -- cgit v1.2.3 From 3de9d14d3e1ed14b880c0064a6141d9d9ca9b828 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Sep 2014 21:02:59 -0700 Subject: Recomment misc functions in home.asm. --- home.asm | 861 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 434 insertions(+), 427 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index 112bf265..7b5c8c6b 100644 --- a/home.asm +++ b/home.asm @@ -169,63 +169,76 @@ LoadDestinationWarpPosition:: ; 1313 (0:1313) ld [$2000],a ret -; INPUT: -; c: if nonzero, show at least a sliver of health -; d = number of HP bar sections (normally 6) -; e = health (in eighths of bar sections) (normally out of 48) + DrawHPBar:: ; 1336 (0:1336) +; Draw an HP bar d tiles long, and fill it to e pixels. +; If c is nonzero, show at least a sliver regardless. +; The right end of the bar changes with [wListMenuID]. + push hl push de push bc - ld a,$71 ; left of HP bar tile 1 - ld [hli],a - ld a,$62 ; left of HP bar tile 2 - ld [hli],a + + ; Left + ld a, $71 ; "HP:" + ld [hli], a + ld a, $62 + ld [hli], a + push hl - ld a,$63 ; empty bar section tile -.drawEmptyBarLoop + + ; Middle + ld a, $63 ; empty +.draw ld [hli],a dec d - jr nz,.drawEmptyBarLoop + jr nz, .draw + + ; Right ld a,[wListMenuID] - dec a ; what should the right of HP bar tile be? - ld a,$6d ; right of HP bar tile, in status screen and battles - jr z,.writeTile - dec a ; right of HP bar tile, in pokemon menu -.writeTile + dec a + ld a, $6d ; status screen and battle + jr z, .ok + dec a ; pokemon menu +.ok ld [hl],a + pop hl - ld a,e - and a ; is there enough health to show up on the HP bar? - jr nz,.loop ; if so, draw the HP bar - ld a,c - and a ; should a sliver of health be shown no matter what? - jr z,.done - ld e,1 ; if so, fill one eighth of a bar section -; loop to draw every full bar section -.loop - ld a,e - sub a,8 - jr c,.drawPartialBarSection - ld e,a - ld a,$6b ; filled bar section tile - ld [hli],a - ld a,e + + ld a, e and a - jr z,.done - jr .loop -; draws a partial bar section at the end (if necessary) -; there are 7 possible partial bar sections from 1/8 to 7/8 full -.drawPartialBarSection - ld a,$63 ; empty bar section tile - add e ; add e to get the appropriate partial bar section tile - ld [hl],a ; write the tile + jr nz, .fill + + ; If c iz nonzero, draw a pixel anyway. + ld a, c + and a + jr z, .done + ld e, 1 + +.fill + ld a, e + sub 8 + jr c, .partial + ld e, a + ld a, $6b ; full + ld [hli], a + ld a, e + and a + jr z, .done + jr .fill + +.partial + ; Fill remaining pixels at the end if necessary. + ld a, $63 ; empty + add e + ld [hl], a .done pop bc pop de pop hl ret + ; loads pokemon data from one of multiple sources to wcf98 ; loads base stats to W_MONHDEXNUM ; INPUT: @@ -240,22 +253,22 @@ DrawHPBar:: ; 1336 (0:1336) ; wcf98 = base address of pokemon data ; W_MONHDEXNUM = base address of base stats LoadMonData:: ; 1372 (0:1372) - ld hl,LoadMonData_ - ld b,BANK(LoadMonData_) + ld hl, LoadMonData_ + ld b, BANK(LoadMonData_) jp Bankswitch ; writes c to wd0dc+b Func_137a:: ; 137a (0:137a) ld hl, wd0dc ld e, b - ld d, $0 + ld d, 0 add hl, de ld a, c ld [hl], a ret LoadFlippedFrontSpriteByMonIndex:: ; 1384 (0:1384) - ld a, $1 + ld a, 1 ld [W_SPRITEFLIPPED], a LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) @@ -271,9 +284,9 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) ld [hl], b and a pop hl - jr z, .invalidDexNumber ; dex #0 invalid + jr z, .invalidDexNumber ; dex #0 invalid cp NUM_POKEMON + 1 - jr c, .validDexNumber ; dex >#151 invalid + jr c, .validDexNumber ; dex >#151 invalid .invalidDexNumber ld a, RHYDON ; $1 ld [wcf91], a @@ -298,41 +311,44 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) ld [$2000], a ret -; plays the cry of a pokemon -; INPUT: -; a = pokemon ID + PlayCry:: ; 13d0 (0:13d0) +; Play monster a's cry. call GetCryData - call PlaySound ; play cry - jp WaitForSoundToFinish ; wait for sound to be done playing + call PlaySound + jp WaitForSoundToFinish -; gets a pokemon's cry data -; INPUT: -; a = pokemon ID GetCryData:: ; 13d9 (0:13d9) +; Load cry data for monster a. dec a - ld c,a - ld b,0 - ld hl,CryData - add hl,bc - add hl,bc - add hl,bc - ld a,Bank(CryData) + ld c, a + ld b, 0 + ld hl, CryData + add hl, bc + add hl, bc + add hl, bc + + ld a, Bank(CryData) call BankswitchHome - ld a,[hli] - ld b,a - ld a,[hli] - ld [wc0f1],a - ld a,[hl] - ld [wc0f2],a + ld a, [hli] + ld b, a ; cry id + ld a, [hli] + ld [wc0f1], a + ld a, [hl] + ld [wc0f2], a call BankswitchBack - ld a,b ; a = cryID - ld c,$14 ; base sound ID for pokemon cries - rlca - add b ; a = cryID * 3 - add c ; a = $14 + cryID * 3 + + ; Cry headers have 3 channels, + ; and start from index $14, + ; so add 3 times the cry id. + ld a, b + ld c, $14 + rlca ; * 2 + add b + add c ret + DisplayPartyMenu:: ; 13fc (0:13fc) ld a,[$ffd7] push af @@ -354,42 +370,42 @@ GoBackToPartyMenu:: ; 1411 (0:1411) jp HandlePartyMenuInput PartyMenuInit:: ; 1420 (0:1420) - ld a,$01 + ld a, 1 ; hardcoded bank call BankswitchHome call LoadHpBarAndStatusTilePatterns - ld hl,wd730 - set 6,[hl] ; turn off letter printing delay + ld hl, wd730 + set 6, [hl] ; turn off letter printing delay xor a - ld [wcc49],a - ld [wcc37],a - ld hl,wTopMenuItemY + ld [wcc49], a + ld [wcc37], a + ld hl, wTopMenuItemY inc a - ld [hli],a ; top menu item Y + ld [hli], a ; top menu item Y xor a - ld [hli],a ; top menu item X - ld a,[wcc2b] + ld [hli], a ; top menu item X + ld a, [wcc2b] push af - ld [hli],a ; current menu item ID + ld [hli], a ; current menu item ID inc hl - ld a,[wPartyCount] + ld a, [wPartyCount] and a ; are there more than 0 pokemon in the party? - jr z,.storeMaxMenuItemID + jr z, .storeMaxMenuItemID dec a ; if party is not empty, the max menu item ID is ([wPartyCount] - 1) ; otherwise, it is 0 .storeMaxMenuItemID - ld [hli],a ; max menu item ID - ld a,[wd11f] + ld [hli], a ; max menu item ID + ld a, [wd11f] and a - ld a,%00000011 ; A button and B button - jr z,.next + ld a, A_BUTTON + B_BUTTON + jr z, .next xor a - ld [wd11f],a + ld [wd11f], a inc a .next - ld [hli],a ; menu watched keys + ld [hli], a ; menu watched keys pop af - ld [hl],a ; old menu item ID + ld [hl], a ; old menu item ID ret HandlePartyMenuInput:: ; 145a (0:145a) @@ -672,7 +688,7 @@ PrintBCDNumber:: ; 15cd (0:15cd) ret PrintBCDDigit:: ; 1604 (0:1604) - and a,%00001111 + and $f and a jr z,.zeroDigit .nonzeroDigit @@ -1403,7 +1419,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6) ld [wTopMenuItemY],a ld a,5 ld [wTopMenuItemX],a - ld a,%00000111 ; A button, B button, Select button + ld a,A_BUTTON | B_BUTTON | SELECT ld [wMenuWatchedKeys],a ld c,10 call DelayFrames @@ -1827,7 +1843,7 @@ PrintListMenuEntries:: ; 2e5a (0:2e5a) ld bc,20 + 8 ; 1 row down and 8 columns right add hl,bc ld a,"×" - ldi [hl],a + ld [hli],a ld a,[wd11e] push af ld a,[de] @@ -2653,8 +2669,8 @@ FuncTX_ItemStoragePC:: ; 3460 (0:3460) FuncTX_BillsPC:: ; 346a (0:346a) call SaveScreenTilesToBuffer2 - ld b, BANK(Func_214c2) - ld hl, Func_214c2 + ld b, BANK(BillsPC_) + ld hl, BillsPC_ jr bankswitchAndContinue FuncTX_SlotMachine:: ; 3474 (0:3474) @@ -3064,65 +3080,63 @@ Func_366b:: ; 366b (0:366b) pop hl ret -; copies the tile patterns for letters and numbers into VRAM -LoadFontTilePatterns:: ; 3680 (0:3680) - ld a,[rLCDC] - bit 7,a ; is the LCD enabled? - jr nz,.lcdEnabled -.lcdDisabled - ld hl,FontGraphics - ld de,vFont - ld bc,$400 - ld a,BANK(FontGraphics) + +LoadFontTilePatterns:: + ld a, [rLCDC] + bit 7, a ; is the LCD enabled? + jr nz, .on +.off + ld hl, FontGraphics + ld de, vFont + ld bc, $400 + ld a, BANK(FontGraphics) jp FarCopyDataDouble ; if LCD is off, transfer all at once -.lcdEnabled - ld de,FontGraphics - ld hl,vFont - ld bc,(BANK(FontGraphics) << 8 | $80) +.on + ld de, FontGraphics + ld hl, vFont + ld bc, BANK(FontGraphics) << 8 | $80 jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank -; copies the text box tile patterns into VRAM -LoadTextBoxTilePatterns:: ; 36a0 (0:36a0) - ld a,[rLCDC] - bit 7,a ; is the LCD enabled? - jr nz,.lcdEnabled -.lcdDisabled - ld hl,TextBoxGraphics - ld de,vChars2 + $600 - ld bc,$200 - ld a,BANK(TextBoxGraphics) +LoadTextBoxTilePatterns:: + ld a, [rLCDC] + bit 7, a ; is the LCD enabled? + jr nz, .on +.off + ld hl, TextBoxGraphics + ld de, vChars2 + $600 + ld bc, $200 + ld a, BANK(TextBoxGraphics) jp FarCopyData2 ; if LCD is off, transfer all at once -.lcdEnabled - ld de,TextBoxGraphics - ld hl,vChars2 + $600 - ld bc,(BANK(TextBoxGraphics) << 8 | $20) +.on + ld de, TextBoxGraphics + ld hl, vChars2 + $600 + ld bc, BANK(TextBoxGraphics) << 8 | $20 jp CopyVideoData ; if LCD is on, transfer during V-blank -; copies HP bar and status display tile patterns into VRAM -LoadHpBarAndStatusTilePatterns:: ; 36c0 (0:36c0) - ld a,[rLCDC] - bit 7,a ; is the LCD enabled? - jr nz,.lcdEnabled -.lcdDisabled - ld hl,HpBarAndStatusGraphics - ld de,vChars2 + $620 - ld bc,$1e0 - ld a,BANK(HpBarAndStatusGraphics) +LoadHpBarAndStatusTilePatterns:: + ld a, [rLCDC] + bit 7, a ; is the LCD enabled? + jr nz, .on +.off + ld hl, HpBarAndStatusGraphics + ld de, vChars2 + $620 + ld bc, $1e0 + ld a, BANK(HpBarAndStatusGraphics) jp FarCopyData2 ; if LCD is off, transfer all at once -.lcdEnabled - ld de,HpBarAndStatusGraphics - ld hl,vChars2 + $620 - ld bc,(BANK(HpBarAndStatusGraphics) << 8 | $1e) +.on + ld de, HpBarAndStatusGraphics + ld hl, vChars2 + $620 + ld bc, BANK(HpBarAndStatusGraphics) << 8 | $1e jp CopyVideoData ; if LCD is on, transfer during V-blank -;Fills memory range with the specified byte. -;input registers a = fill_byte, bc = length, hl = address -FillMemory:: ; 36e0 (0:36e0) + +FillMemory:: +; Fill bc bytes at hl with a. push de ld d, a .loop ld a, d - ldi [hl], a + ld [hli], a dec bc ld a, b or c @@ -3130,15 +3144,16 @@ FillMemory:: ; 36e0 (0:36e0) pop de ret -; loads sprite that de points to -; bank of sprite is given in a + UncompressSpriteFromDE:: ; 36eb (0:36eb) +; Decompress pic at a:de. ld hl, W_SPRITEINPUTPTR ld [hl], e inc hl ld [hl], d jp UncompressSpriteData + SaveScreenTilesToBuffer2:: ; 36f4 (0:36f4) ld hl, wTileMap ld de, wTileMapBackup2 @@ -3229,8 +3244,12 @@ GetName:: ; 376b (0:376b) ; returns pointer to name in de ld a,[wd0b5] ld [wd11e],a + + ; TM names are separate from item names. + ; BUG: This applies to all names instead of just items. cp HM_01 - jp nc,GetMachineName + jp nc, GetMachineName + ld a,[H_LOADEDROMBANK] push af push hl @@ -3400,7 +3419,7 @@ JoypadLowSensitivity:: ; 3831 (0:3831) .delayOver ; if [hJoy6] = 0 and A or B is pressed, report no buttons as pressed ld a,[hJoyHeld] - and a,%00000011 ; A and B buttons + and A_BUTTON | B_BUTTON jr z,.setShortDelay ld a,[hJoy6] ; flag and a @@ -3513,7 +3532,7 @@ PrintLetterDelay:: ; 38d3 (0:38d3) bit 0,a jr z,.waitOneFrame ld a,[W_OPTIONS] - and a,$0f + and $f ld [H_FRAMECOUNTER],a jr .checkButtons .waitOneFrame @@ -3966,7 +3985,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2) jp z,.loop1 .checkIfAButtonOrBButtonPressed ld a,[hJoy5] - and a,%00000011 ; pressed A button or B button? + and A_BUTTON | B_BUTTON jr z,.skipPlayingSound .AButtonOrBButtonPressed push hl @@ -3996,14 +4015,14 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c) and a ; is the y coordinate 0? jr z,.adjustForXCoord ld hl,wTileMap - ld bc,20 ; screen width + ld bc,SCREEN_WIDTH .topMenuItemLoop add hl,bc dec a jr nz,.topMenuItemLoop .adjustForXCoord ld a,[wTopMenuItemX] - ld b,$00 + ld b,0 ld c,a add hl,bc push hl @@ -4156,7 +4175,7 @@ AutoTextBoxDrawingCommon:: ; 3c41 (0:3c41) ret PrintText:: ; 3c49 (0:3c49) -; given a pointer in hl, print the text there +; Print text hl at (1, 14). push hl ld a,1 ld [wd125],a @@ -4168,256 +4187,244 @@ Func_3c59:: ; 3c59 (0:3c59) bcCoord 1, 14 jp TextCommandProcessor -; converts a big-endian binary number into decimal and prints it -; INPUT: -; b = flags and number of bytes -; bit 7: if set, print leading zeroes -; if unset, do not print leading zeroes -; bit 6: if set, left-align the string (do not pad empty digits with spaces) -; if unset, right-align the string -; bits 4-5: unused -; bits 0-3: number of bytes (only 1 - 3 bytes supported) -; c = number of decimal digits -; de = address of the number (big-endian) -PrintNumber:: ; 3c5f (0:3c5f) + +PrintNumber:: ; 3c5f +; Print the c-digit, b-byte value at de. +; Allows 2 to 7 digits. For 1-digit numbers, add +; the value to char "0" instead of calling PrintNumber. +; Flags LEADING_ZEROES and LEFT_ALIGN can be given +; in bits 7 and 6 of b respectively. +LEADING_ZEROES EQU 7 +LEFT_ALIGN EQU 6 + push bc xor a - ld [H_PASTLEADINGZEROES],a - ld [H_NUMTOPRINT],a - ld [H_NUMTOPRINT + 1],a - ld a,b - and a,%00001111 - cp a,1 - jr z,.oneByte - cp a,2 - jr z,.twoBytes -.threeBytes - ld a,[de] - ld [H_NUMTOPRINT],a + ld [H_PASTLEADINGZEROES], a + ld [H_NUMTOPRINT], a + ld [H_NUMTOPRINT + 1], a + ld a, b + and $f + cp 1 + jr z, .byte + cp 2 + jr z, .word +.long + ld a, [de] + ld [H_NUMTOPRINT], a inc de - ld a,[de] - ld [H_NUMTOPRINT + 1],a + ld a, [de] + ld [H_NUMTOPRINT + 1], a inc de - ld a,[de] - ld [H_NUMTOPRINT + 2],a - jr .checkNumDigits -.twoBytes - ld a,[de] - ld [H_NUMTOPRINT + 1],a + ld a, [de] + ld [H_NUMTOPRINT + 2], a + jr .start + +.word + ld a, [de] + ld [H_NUMTOPRINT + 1], a inc de - ld a,[de] - ld [H_NUMTOPRINT + 2],a - jr .checkNumDigits -.oneByte - ld a,[de] - ld [H_NUMTOPRINT + 2],a -.checkNumDigits + ld a, [de] + ld [H_NUMTOPRINT + 2], a + jr .start + +.byte + ld a, [de] + ld [H_NUMTOPRINT + 2], a + +.start push de - ld d,b - ld a,c - ld b,a - xor a - ld c,a - ld a,b ; a = number of decimal digits - cp a,2 - jr z,.tensPlace - cp a,3 - jr z,.hundredsPlace - cp a,4 - jr z,.thousandsPlace - cp a,5 - jr z,.tenThousandsPlace - cp a,6 - jr z,.hundredThousandsPlace -.millionsPlace - ld a,1000000 >> 16 - ld [H_POWEROFTEN],a - ld a,(1000000 >> 8) & $FF - ld [H_POWEROFTEN + 1],a - ld a,1000000 & $FF - ld [H_POWEROFTEN + 2],a - call PrintNumber_PrintDigit - call PrintNumber_AdvancePointer -.hundredThousandsPlace - ld a,100000 >> 16 - ld [H_POWEROFTEN],a - ld a,(100000 >> 8) & $FF - ld [H_POWEROFTEN + 1],a - ld a,100000 & $FF - ld [H_POWEROFTEN + 2],a - call PrintNumber_PrintDigit - call PrintNumber_AdvancePointer -.tenThousandsPlace - xor a - ld [H_POWEROFTEN],a - ld a,10000 >> 8 - ld [H_POWEROFTEN + 1],a - ld a,10000 & $FF - ld [H_POWEROFTEN + 2],a - call PrintNumber_PrintDigit - call PrintNumber_AdvancePointer -.thousandsPlace - xor a - ld [H_POWEROFTEN],a - ld a,1000 >> 8 - ld [H_POWEROFTEN + 1],a - ld a,1000 & $FF - ld [H_POWEROFTEN + 2],a - call PrintNumber_PrintDigit - call PrintNumber_AdvancePointer -.hundredsPlace - xor a - ld [H_POWEROFTEN],a + + ld d, b + ld a, c + ld b, a xor a - ld [H_POWEROFTEN + 1],a - ld a,100 - ld [H_POWEROFTEN + 2],a - call PrintNumber_PrintDigit - call PrintNumber_AdvancePointer -.tensPlace - ld c,00 - ld a,[H_NUMTOPRINT + 2] -.loop - cp a,10 - jr c,.underflow - sub a,10 + ld c, a + ld a, b + + cp 2 + jr z, .tens + cp 3 + jr z, .hundreds + cp 4 + jr z, .thousands + cp 5 + jr z, .ten_thousands + cp 6 + jr z, .hundred_thousands + +print_digit: macro + +if (\1) / $10000 + ld a, \1 / $10000 % $100 +else xor a +endc + ld [H_POWEROFTEN + 0], a + +if (\1) / $100 + ld a, \1 / $100 % $100 +else xor a +endc + ld [H_POWEROFTEN + 1], a + + ld a, \1 / $1 % $100 + ld [H_POWEROFTEN + 2], a + + call .PrintDigit + call .NextDigit +endm + +.millions print_digit 1000000 +.hundred_thousands print_digit 100000 +.ten_thousands print_digit 10000 +.thousands print_digit 1000 +.hundreds print_digit 100 + +.tens + ld c, 0 + ld a, [H_NUMTOPRINT + 2] +.mod + cp 10 + jr c, .ok + sub 10 inc c - jr .loop -.underflow - ld b,a - ld a,[H_PASTLEADINGZEROES] + jr .mod +.ok + + ld b, a + ld a, [H_PASTLEADINGZEROES] or c - ld [H_PASTLEADINGZEROES],a - jr nz,.pastLeadingZeroes - call PrintNumber_PrintLeadingZero - jr .advancePointer -.pastLeadingZeroes - ld a,"0" + ld [H_PASTLEADINGZEROES], a + jr nz, .past + call .PrintLeadingZero + jr .next +.past + ld a, "0" add c - ld [hl],a -.advancePointer - call PrintNumber_AdvancePointer -.onesPlace - ld a,"0" + ld [hl], a +.next + + call .NextDigit +.ones + ld a, "0" add b - ld [hli],a + ld [hli], a pop de dec de pop bc ret -; prints a decimal digit -; This works by repeatedely subtracting a power of ten until the number becomes negative. -; The number of subtractions it took in order to make the number negative is the digit for the current number place. -; The last value that the number had before becoming negative is kept as the new value of the number. -; A more succinct description is that the number is divided by a power of ten -; and the quotient becomes the digit while the remainder is stored as the new value of the number. -PrintNumber_PrintDigit:: ; 3d25 (0:3d25) - ld c,0 ; counts number of loop iterations to determine the decimal digit +.PrintDigit: +; Divide by the current decimal place. +; Print the quotient, and keep the modulus. + ld c, 0 .loop - ld a,[H_POWEROFTEN] - ld b,a - ld a,[H_NUMTOPRINT] - ld [H_SAVEDNUMTOPRINT],a + ld a, [H_POWEROFTEN] + ld b, a + ld a, [H_NUMTOPRINT] + ld [H_SAVEDNUMTOPRINT], a cp b - jr c,.underflow0 + jr c, .underflow0 sub b - ld [H_NUMTOPRINT],a - ld a,[H_POWEROFTEN + 1] - ld b,a - ld a,[H_NUMTOPRINT + 1] - ld [H_SAVEDNUMTOPRINT + 1],a + ld [H_NUMTOPRINT], a + ld a, [H_POWEROFTEN + 1] + ld b, a + ld a, [H_NUMTOPRINT + 1] + ld [H_SAVEDNUMTOPRINT + 1], a cp b - jr nc,.noBorrowForByte1 -.byte1BorrowFromByte0 - ld a,[H_NUMTOPRINT] - or a,0 - jr z,.underflow1 + jr nc, .noborrow1 + + ld a, [H_NUMTOPRINT] + or 0 + jr z, .underflow1 dec a - ld [H_NUMTOPRINT],a - ld a,[H_NUMTOPRINT + 1] -.noBorrowForByte1 + ld [H_NUMTOPRINT], a + ld a, [H_NUMTOPRINT + 1] +.noborrow1 + sub b - ld [H_NUMTOPRINT + 1],a - ld a,[H_POWEROFTEN + 2] - ld b,a - ld a,[H_NUMTOPRINT + 2] - ld [H_SAVEDNUMTOPRINT + 2],a + ld [H_NUMTOPRINT + 1], a + ld a, [H_POWEROFTEN + 2] + ld b, a + ld a, [H_NUMTOPRINT + 2] + ld [H_SAVEDNUMTOPRINT + 2], a cp b - jr nc,.noBorrowForByte2 -.byte2BorrowFromByte1 - ld a,[H_NUMTOPRINT + 1] + jr nc, .noborrow2 + + ld a, [H_NUMTOPRINT + 1] and a - jr nz,.finishByte2BorrowFromByte1 -.byte2BorrowFromByte0 - ld a,[H_NUMTOPRINT] + jr nz, .borrowed + + ld a, [H_NUMTOPRINT] and a - jr z,.underflow2 + jr z, .underflow2 dec a - ld [H_NUMTOPRINT],a + ld [H_NUMTOPRINT], a xor a -.finishByte2BorrowFromByte1 +.borrowed + dec a - ld [H_NUMTOPRINT + 1],a - ld a,[H_NUMTOPRINT + 2] -.noBorrowForByte2 + ld [H_NUMTOPRINT + 1], a + ld a, [H_NUMTOPRINT + 2] +.noborrow2 sub b - ld [H_NUMTOPRINT + 2],a + ld [H_NUMTOPRINT + 2], a inc c jr .loop + .underflow2 - ld a,[H_SAVEDNUMTOPRINT + 1] - ld [H_NUMTOPRINT + 1],a + ld a, [H_SAVEDNUMTOPRINT + 1] + ld [H_NUMTOPRINT + 1], a .underflow1 - ld a,[H_SAVEDNUMTOPRINT] - ld [H_NUMTOPRINT],a + ld a, [H_SAVEDNUMTOPRINT] + ld [H_NUMTOPRINT], a .underflow0 - ld a,[H_PASTLEADINGZEROES] + ld a, [H_PASTLEADINGZEROES] or c - jr z,PrintNumber_PrintLeadingZero - ld a,"0" + jr z, .PrintLeadingZero + + ld a, "0" add c - ld [hl],a - ld [H_PASTLEADINGZEROES],a + ld [hl], a + ld [H_PASTLEADINGZEROES], a ret -; prints a leading zero unless they are turned off in the flags -PrintNumber_PrintLeadingZero:: ; 3d83 (0:3d83) - bit 7,d ; print leading zeroes? +.PrintLeadingZero: + bit LEADING_ZEROES, d ret z - ld [hl],"0" - ret - -; increments the pointer unless leading zeroes are not being printed, -; the number is left-aligned, and no nonzero digits have been printed yet -PrintNumber_AdvancePointer:: ; 3d89 (0:3d89) - bit 7,d ; print leading zeroes? - jr nz,.incrementPointer - bit 6,d ; left alignment or right alignment? - jr z,.incrementPointer - ld a,[H_PASTLEADINGZEROES] + ld [hl], "0" + ret + +.NextDigit: +; Increment unless the number is left-aligned, +; leading zeroes are not printed, and no digits +; have been printed yet. + bit LEADING_ZEROES, d + jr nz, .inc + bit LEFT_ALIGN, d + jr z, .inc + ld a, [H_PASTLEADINGZEROES] and a ret z -.incrementPointer +.inc inc hl ret -; calls a function from a table of function pointers -; INPUT: -; a = index within table -; hl = address of function pointer table -CallFunctionInTable:: ; 3d97 (0:3d97) + +CallFunctionInTable:: +JumpTable:: +; Call function a in jumptable hl. +; de is not preserved. push hl push de push bc add a - ld d,0 - ld e,a - add hl,de - ld a,[hli] - ld h,[hl] - ld l,a - ld de,.returnAddress + ld d, 0 + ld e, a + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld de, .returnAddress push de jp [hl] .returnAddress @@ -4570,7 +4577,7 @@ Random:: push de push bc callba Random_ - ld a,[hRandomAdd] + ld a, [hRandomAdd] pop bc pop de pop hl @@ -4623,95 +4630,95 @@ Func_3eb5:: ; 3eb5 (0:3eb5) PrintPredefTextID:: ; 3ef5 (0:3ef5) ld [H_DOWNARROWBLINKCNT2], a ; $ff8c - ld hl, PointerTable_3f22 + ld hl, TextPredefs call Func_3f0f ld hl, wcf11 set 0, [hl] call DisplayTextID Func_3f05:: ; 3f05 (0:3f05) - ld hl, W_MAPTEXTPTR ; wd36c + ld hl, W_MAPTEXTPTR ld a, [$ffec] ld [hli], a - ld a, [$ffed] + ld a, [$ffec + 1] ld [hl], a ret Func_3f0f:: ; 3f0f (0:3f0f) - ld a, [W_MAPTEXTPTR] ; wd36c + ld a, [W_MAPTEXTPTR] ld [$ffec], a ld a, [W_MAPTEXTPTR + 1] - ld [$ffed], a + ld [$ffec + 1], a ld a, l - ld [W_MAPTEXTPTR], a ; wd36c + ld [W_MAPTEXTPTR], a ld a, h ld [W_MAPTEXTPTR + 1], a ret -PointerTable_3f22:: ; 3f22 (0:3f22) - dw CardKeySuccessText ; id = 01 - dw CardKeyFailText ; id = 02 - dw RedBedroomPC ; id = 03 - dw RedBedroomSNESText ; id = 04 - dw PushStartText ; id = 05 - dw SaveOptionText ; id = 06 - dw StrengthsAndWeaknessesText ; id = 07 - dw OakLabEmailText ; id = 08 - dw AerodactylFossilText ; id = 09 - dw Route15UpstairsBinocularsText ; id = 0A - dw KabutopsFossilText ; id = 0B - dw GymStatueText1 ; id = 0C - dw GymStatueText2 ; id = 0D - dw BookcaseText ; id = 0E - dw ViridianCityPokecenterBenchGuyText ; id = 0F - dw PewterCityPokecenterBenchGuyText ; id = 10 - dw CeruleanCityPokecenterBenchGuyText ; id = 11 - dw LavenderCityPokecenterBenchGuyText ; id = 12 - dw VermilionCityPokecenterBenchGuyText ; id = 13 - dw CeladonCityPokecenterBenchGuyText ; id = 14 - dw CeladonCityHotelText ; id = 15 - dw FuchsiaCityPokecenterBenchGuyText ; id = 16 - dw CinnabarIslandPokecenterBenchGuyText ; id = 17 - dw SaffronCityPokecenterBenchGuyText ; id = 18 - dw MtMoonPokecenterBenchGuyText ; id = 19 - dw RockTunnelPokecenterBenchGuyText ; id = 1A - dw UnusedBenchGuyText1 ; id = 1B - dw UnusedBenchGuyText2 ; id = 1C - dw UnusedBenchGuyText3 ; id = 1D - dw TerminatorText_62508 ; id = 1E - dw PredefText1f ; id = 1F - dw ViridianSchoolNotebook ; id = 20 - dw ViridianSchoolBlackboard ; id = 21 - dw JustAMomentText ; id = 22 - dw PredefText23 ; id = 23 - dw FoundHiddenItemText ; id = 24 - dw HiddenItemBagFullText ; id = 25 - dw VermilionGymTrashText ; id = 26 - dw IndigoPlateauHQText ; id = 27 - dw GameCornerOutOfOrderText ; id = 28 - dw GameCornerOutToLunchText ; id = 29 - dw GameCornerSomeonesKeysText ; id = 2A - dw FoundHiddenCoinsText ; id = 2B - dw DroppedHiddenCoinsText ; id = 2C - dw BillsHouseMonitorText ; id = 2D - dw BillsHouseInitiatedText ; id = 2E - dw BillsHousePokemonList ; id = 2F - dw MagazinesText ; id = 30 - dw CinnabarGymQuiz ; id = 31 - dw GameCornerNoCoinsText ; id = 32 - dw GameCornerCoinCaseText ; id = 33 - dw LinkCableHelp ; id = 34 - dw TMNotebook ; id = 35 - dw FightingDojoText ; id = 36 - dw FightingDojoText_52a10 ; id = 37 - dw FightingDojoText_52a1d ; id = 38 - dw NewBicycleText ; id = 39 - dw IndigoPlateauStatues ; id = 3A - dw VermilionGymTrashSuccesText1 ; id = 3B - dw VermilionGymTrashSuccesText2 ; id = 3C - dw VermilionGymTrashSuccesText3 ; id = 3D - dw VermilionGymTrashFailText ; id = 3E - dw TownMapText ; id = 3F - dw BookOrSculptureText ; id = 40 - dw ElevatorText ; id = 41 - dw PokemonStuffText ; id = 42 +TextPredefs:: + dw CardKeySuccessText ; 01 + dw CardKeyFailText ; 02 + dw RedBedroomPC ; 03 + dw RedBedroomSNESText ; 04 + dw PushStartText ; 05 + dw SaveOptionText ; 06 + dw StrengthsAndWeaknessesText ; 07 + dw OakLabEmailText ; 08 + dw AerodactylFossilText ; 09 + dw Route15UpstairsBinocularsText ; 0A + dw KabutopsFossilText ; 0B + dw GymStatueText1 ; 0C + dw GymStatueText2 ; 0D + dw BookcaseText ; 0E + dw ViridianCityPokecenterBenchGuyText ; 0F + dw PewterCityPokecenterBenchGuyText ; 10 + dw CeruleanCityPokecenterBenchGuyText ; 11 + dw LavenderCityPokecenterBenchGuyText ; 12 + dw VermilionCityPokecenterBenchGuyText ; 13 + dw CeladonCityPokecenterBenchGuyText ; 14 + dw CeladonCityHotelText ; 15 + dw FuchsiaCityPokecenterBenchGuyText ; 16 + dw CinnabarIslandPokecenterBenchGuyText ; 17 + dw SaffronCityPokecenterBenchGuyText ; 18 + dw MtMoonPokecenterBenchGuyText ; 19 + dw RockTunnelPokecenterBenchGuyText ; 1A + dw UnusedBenchGuyText1 ; 1B + dw UnusedBenchGuyText2 ; 1C + dw UnusedBenchGuyText3 ; 1D + dw TerminatorText_62508 ; 1E + dw PredefText1f ; 1F + dw ViridianSchoolNotebook ; 20 + dw ViridianSchoolBlackboard ; 21 + dw JustAMomentText ; 22 + dw PredefText23 ; 23 + dw FoundHiddenItemText ; 24 + dw HiddenItemBagFullText ; 25 + dw VermilionGymTrashText ; 26 + dw IndigoPlateauHQText ; 27 + dw GameCornerOutOfOrderText ; 28 + dw GameCornerOutToLunchText ; 29 + dw GameCornerSomeonesKeysText ; 2A + dw FoundHiddenCoinsText ; 2B + dw DroppedHiddenCoinsText ; 2C + dw BillsHouseMonitorText ; 2D + dw BillsHouseInitiatedText ; 2E + dw BillsHousePokemonList ; 2F + dw MagazinesText ; 30 + dw CinnabarGymQuiz ; 31 + dw GameCornerNoCoinsText ; 32 + dw GameCornerCoinCaseText ; 33 + dw LinkCableHelp ; 34 + dw TMNotebook ; 35 + dw FightingDojoText ; 36 + dw FightingDojoText_52a10 ; 37 + dw FightingDojoText_52a1d ; 38 + dw NewBicycleText ; 39 + dw IndigoPlateauStatues ; 3A + dw VermilionGymTrashSuccesText1 ; 3B + dw VermilionGymTrashSuccesText2 ; 3C + dw VermilionGymTrashSuccesText3 ; 3D + dw VermilionGymTrashFailText ; 3E + dw TownMapText ; 3F + dw BookOrSculptureText ; 40 + dw ElevatorText ; 41 + dw PokemonStuffText ; 42 -- cgit v1.2.3 From d59dfadf66926ea0c7b5f8bbeaa9b83ee7bb3cb5 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Sep 2014 21:15:11 -0700 Subject: Add macros for text predefs. --- home.asm | 132 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) (limited to 'home.asm') diff --git a/home.asm b/home.asm index 7b5c8c6b..26ce6341 100644 --- a/home.asm +++ b/home.asm @@ -4656,69 +4656,69 @@ Func_3f0f:: ; 3f0f (0:3f0f) ret TextPredefs:: - dw CardKeySuccessText ; 01 - dw CardKeyFailText ; 02 - dw RedBedroomPC ; 03 - dw RedBedroomSNESText ; 04 - dw PushStartText ; 05 - dw SaveOptionText ; 06 - dw StrengthsAndWeaknessesText ; 07 - dw OakLabEmailText ; 08 - dw AerodactylFossilText ; 09 - dw Route15UpstairsBinocularsText ; 0A - dw KabutopsFossilText ; 0B - dw GymStatueText1 ; 0C - dw GymStatueText2 ; 0D - dw BookcaseText ; 0E - dw ViridianCityPokecenterBenchGuyText ; 0F - dw PewterCityPokecenterBenchGuyText ; 10 - dw CeruleanCityPokecenterBenchGuyText ; 11 - dw LavenderCityPokecenterBenchGuyText ; 12 - dw VermilionCityPokecenterBenchGuyText ; 13 - dw CeladonCityPokecenterBenchGuyText ; 14 - dw CeladonCityHotelText ; 15 - dw FuchsiaCityPokecenterBenchGuyText ; 16 - dw CinnabarIslandPokecenterBenchGuyText ; 17 - dw SaffronCityPokecenterBenchGuyText ; 18 - dw MtMoonPokecenterBenchGuyText ; 19 - dw RockTunnelPokecenterBenchGuyText ; 1A - dw UnusedBenchGuyText1 ; 1B - dw UnusedBenchGuyText2 ; 1C - dw UnusedBenchGuyText3 ; 1D - dw TerminatorText_62508 ; 1E - dw PredefText1f ; 1F - dw ViridianSchoolNotebook ; 20 - dw ViridianSchoolBlackboard ; 21 - dw JustAMomentText ; 22 - dw PredefText23 ; 23 - dw FoundHiddenItemText ; 24 - dw HiddenItemBagFullText ; 25 - dw VermilionGymTrashText ; 26 - dw IndigoPlateauHQText ; 27 - dw GameCornerOutOfOrderText ; 28 - dw GameCornerOutToLunchText ; 29 - dw GameCornerSomeonesKeysText ; 2A - dw FoundHiddenCoinsText ; 2B - dw DroppedHiddenCoinsText ; 2C - dw BillsHouseMonitorText ; 2D - dw BillsHouseInitiatedText ; 2E - dw BillsHousePokemonList ; 2F - dw MagazinesText ; 30 - dw CinnabarGymQuiz ; 31 - dw GameCornerNoCoinsText ; 32 - dw GameCornerCoinCaseText ; 33 - dw LinkCableHelp ; 34 - dw TMNotebook ; 35 - dw FightingDojoText ; 36 - dw FightingDojoText_52a10 ; 37 - dw FightingDojoText_52a1d ; 38 - dw NewBicycleText ; 39 - dw IndigoPlateauStatues ; 3A - dw VermilionGymTrashSuccesText1 ; 3B - dw VermilionGymTrashSuccesText2 ; 3C - dw VermilionGymTrashSuccesText3 ; 3D - dw VermilionGymTrashFailText ; 3E - dw TownMapText ; 3F - dw BookOrSculptureText ; 40 - dw ElevatorText ; 41 - dw PokemonStuffText ; 42 + add_tx_pre CardKeySuccessText ; 01 + add_tx_pre CardKeyFailText ; 02 + add_tx_pre RedBedroomPC ; 03 + add_tx_pre RedBedroomSNESText ; 04 + add_tx_pre PushStartText ; 05 + add_tx_pre SaveOptionText ; 06 + add_tx_pre StrengthsAndWeaknessesText ; 07 + add_tx_pre OakLabEmailText ; 08 + add_tx_pre AerodactylFossilText ; 09 + add_tx_pre Route15UpstairsBinocularsText ; 0A + add_tx_pre KabutopsFossilText ; 0B + add_tx_pre GymStatueText1 ; 0C + add_tx_pre GymStatueText2 ; 0D + add_tx_pre BookcaseText ; 0E + add_tx_pre ViridianCityPokecenterBenchGuyText ; 0F + add_tx_pre PewterCityPokecenterBenchGuyText ; 10 + add_tx_pre CeruleanCityPokecenterBenchGuyText ; 11 + add_tx_pre LavenderCityPokecenterBenchGuyText ; 12 + add_tx_pre VermilionCityPokecenterBenchGuyText ; 13 + add_tx_pre CeladonCityPokecenterBenchGuyText ; 14 + add_tx_pre CeladonCityHotelText ; 15 + add_tx_pre FuchsiaCityPokecenterBenchGuyText ; 16 + add_tx_pre CinnabarIslandPokecenterBenchGuyText ; 17 + add_tx_pre SaffronCityPokecenterBenchGuyText ; 18 + add_tx_pre MtMoonPokecenterBenchGuyText ; 19 + add_tx_pre RockTunnelPokecenterBenchGuyText ; 1A + add_tx_pre UnusedBenchGuyText1 ; 1B + add_tx_pre UnusedBenchGuyText2 ; 1C + add_tx_pre UnusedBenchGuyText3 ; 1D + add_tx_pre TerminatorText_62508 ; 1E + add_tx_pre PredefText1f ; 1F + add_tx_pre ViridianSchoolNotebook ; 20 + add_tx_pre ViridianSchoolBlackboard ; 21 + add_tx_pre JustAMomentText ; 22 + add_tx_pre PredefText23 ; 23 + add_tx_pre FoundHiddenItemText ; 24 + add_tx_pre HiddenItemBagFullText ; 25 + add_tx_pre VermilionGymTrashText ; 26 + add_tx_pre IndigoPlateauHQText ; 27 + add_tx_pre GameCornerOutOfOrderText ; 28 + add_tx_pre GameCornerOutToLunchText ; 29 + add_tx_pre GameCornerSomeonesKeysText ; 2A + add_tx_pre FoundHiddenCoinsText ; 2B + add_tx_pre DroppedHiddenCoinsText ; 2C + add_tx_pre BillsHouseMonitorText ; 2D + add_tx_pre BillsHouseInitiatedText ; 2E + add_tx_pre BillsHousePokemonList ; 2F + add_tx_pre MagazinesText ; 30 + add_tx_pre CinnabarGymQuiz ; 31 + add_tx_pre GameCornerNoCoinsText ; 32 + add_tx_pre GameCornerCoinCaseText ; 33 + add_tx_pre LinkCableHelp ; 34 + add_tx_pre TMNotebook ; 35 + add_tx_pre FightingDojoText ; 36 + add_tx_pre FightingDojoText_52a10 ; 37 + add_tx_pre FightingDojoText_52a1d ; 38 + add_tx_pre NewBicycleText ; 39 + add_tx_pre IndigoPlateauStatues ; 3A + add_tx_pre VermilionGymTrashSuccesText1 ; 3B + add_tx_pre VermilionGymTrashSuccesText2 ; 3C + add_tx_pre VermilionGymTrashSuccesText3 ; 3D + add_tx_pre VermilionGymTrashFailText ; 3E + add_tx_pre TownMapText ; 3F + add_tx_pre BookOrSculptureText ; 40 + add_tx_pre ElevatorText ; 41 + add_tx_pre PokemonStuffText ; 42 -- cgit v1.2.3