Recomment misc functions in home.asm.

This commit is contained in:
yenatch 2014-09-17 21:02:59 -07:00
parent fcfed136c6
commit 3de9d14d3e
2 changed files with 447 additions and 436 deletions

View file

@ -1,12 +1,3 @@
A_BUTTON EQU %00000001
B_BUTTON EQU %00000010
SELECT EQU %00000100
START EQU %00001000
D_RIGHT EQU %00010000
D_LEFT EQU %00100000
D_UP EQU %01000000
D_DOWN EQU %10000000
MAX_LEVEL EQU 100 MAX_LEVEL EQU 100
NUM_MOVES EQU 4 NUM_MOVES EQU 4
@ -18,3 +9,16 @@ NUM_BOXES EQU 12
HOF_MON EQU $10 HOF_MON EQU $10
HOF_TEAM EQU PARTY_LENGTH * HOF_MON HOF_TEAM EQU PARTY_LENGTH * HOF_MON
NUM_HOF_TEAMS EQU 50 NUM_HOF_TEAMS EQU 50
A_BUTTON EQU %00000001
B_BUTTON EQU %00000010
SELECT EQU %00000100
START EQU %00001000
D_RIGHT EQU %00010000
D_LEFT EQU %00100000
D_UP EQU %01000000
D_DOWN EQU %10000000
SCREEN_WIDTH EQU 20
SCREEN_HEIGHT EQU 18

577
home.asm
View file

@ -169,63 +169,76 @@ LoadDestinationWarpPosition:: ; 1313 (0:1313)
ld [$2000],a ld [$2000],a
ret 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) 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 hl
push de push de
push bc push bc
ld a,$71 ; left of HP bar tile 1
; Left
ld a, $71 ; "HP:"
ld [hli], a ld [hli], a
ld a,$62 ; left of HP bar tile 2 ld a, $62
ld [hli], a ld [hli], a
push hl push hl
ld a,$63 ; empty bar section tile
.drawEmptyBarLoop ; Middle
ld a, $63 ; empty
.draw
ld [hli],a ld [hli],a
dec d dec d
jr nz,.drawEmptyBarLoop jr nz, .draw
; Right
ld a,[wListMenuID] ld a,[wListMenuID]
dec a ; what should the right of HP bar tile be? dec a
ld a,$6d ; right of HP bar tile, in status screen and battles ld a, $6d ; status screen and battle
jr z,.writeTile jr z, .ok
dec a ; right of HP bar tile, in pokemon menu dec a ; pokemon menu
.writeTile .ok
ld [hl],a ld [hl],a
pop hl pop hl
ld a, e ld a, e
and a ; is there enough health to show up on the HP bar? and a
jr nz,.loop ; if so, draw the HP bar jr nz, .fill
; If c iz nonzero, draw a pixel anyway.
ld a, c ld a, c
and a ; should a sliver of health be shown no matter what? and a
jr z, .done jr z, .done
ld e,1 ; if so, fill one eighth of a bar section ld e, 1
; loop to draw every full bar section
.loop .fill
ld a, e ld a, e
sub a,8 sub 8
jr c,.drawPartialBarSection jr c, .partial
ld e, a ld e, a
ld a,$6b ; filled bar section tile ld a, $6b ; full
ld [hli], a ld [hli], a
ld a, e ld a, e
and a and a
jr z, .done jr z, .done
jr .loop jr .fill
; draws a partial bar section at the end (if necessary)
; there are 7 possible partial bar sections from 1/8 to 7/8 full .partial
.drawPartialBarSection ; Fill remaining pixels at the end if necessary.
ld a,$63 ; empty bar section tile ld a, $63 ; empty
add e ; add e to get the appropriate partial bar section tile add e
ld [hl],a ; write the tile ld [hl], a
.done .done
pop bc pop bc
pop de pop de
pop hl pop hl
ret ret
; loads pokemon data from one of multiple sources to wcf98 ; loads pokemon data from one of multiple sources to wcf98
; loads base stats to W_MONHDEXNUM ; loads base stats to W_MONHDEXNUM
; INPUT: ; INPUT:
@ -248,14 +261,14 @@ LoadMonData:: ; 1372 (0:1372)
Func_137a:: ; 137a (0:137a) Func_137a:: ; 137a (0:137a)
ld hl, wd0dc ld hl, wd0dc
ld e, b ld e, b
ld d, $0 ld d, 0
add hl, de add hl, de
ld a, c ld a, c
ld [hl], a ld [hl], a
ret ret
LoadFlippedFrontSpriteByMonIndex:: ; 1384 (0:1384) LoadFlippedFrontSpriteByMonIndex:: ; 1384 (0:1384)
ld a, $1 ld a, 1
ld [W_SPRITEFLIPPED], a ld [W_SPRITEFLIPPED], a
LoadFrontSpriteByMonIndex:: ; 1389 (0:1389) LoadFrontSpriteByMonIndex:: ; 1389 (0:1389)
@ -298,18 +311,15 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389)
ld [$2000], a ld [$2000], a
ret ret
; plays the cry of a pokemon
; INPUT:
; a = pokemon ID
PlayCry:: ; 13d0 (0:13d0)
call GetCryData
call PlaySound ; play cry
jp WaitForSoundToFinish ; wait for sound to be done playing
; gets a pokemon's cry data PlayCry:: ; 13d0 (0:13d0)
; INPUT: ; Play monster a's cry.
; a = pokemon ID call GetCryData
call PlaySound
jp WaitForSoundToFinish
GetCryData:: ; 13d9 (0:13d9) GetCryData:: ; 13d9 (0:13d9)
; Load cry data for monster a.
dec a dec a
ld c, a ld c, a
ld b, 0 ld b, 0
@ -317,22 +327,28 @@ GetCryData:: ; 13d9 (0:13d9)
add hl, bc add hl, bc
add hl, bc add hl, bc
add hl, bc add hl, bc
ld a, Bank(CryData) ld a, Bank(CryData)
call BankswitchHome call BankswitchHome
ld a, [hli] ld a, [hli]
ld b,a ld b, a ; cry id
ld a, [hli] ld a, [hli]
ld [wc0f1], a ld [wc0f1], a
ld a, [hl] ld a, [hl]
ld [wc0f2], a ld [wc0f2], a
call BankswitchBack call BankswitchBack
ld a,b ; a = cryID
ld c,$14 ; base sound ID for pokemon cries ; Cry headers have 3 channels,
rlca ; and start from index $14,
add b ; a = cryID * 3 ; so add 3 times the cry id.
add c ; a = $14 + cryID * 3 ld a, b
ld c, $14
rlca ; * 2
add b
add c
ret ret
DisplayPartyMenu:: ; 13fc (0:13fc) DisplayPartyMenu:: ; 13fc (0:13fc)
ld a,[$ffd7] ld a,[$ffd7]
push af push af
@ -354,7 +370,7 @@ GoBackToPartyMenu:: ; 1411 (0:1411)
jp HandlePartyMenuInput jp HandlePartyMenuInput
PartyMenuInit:: ; 1420 (0:1420) PartyMenuInit:: ; 1420 (0:1420)
ld a,$01 ld a, 1 ; hardcoded bank
call BankswitchHome call BankswitchHome
call LoadHpBarAndStatusTilePatterns call LoadHpBarAndStatusTilePatterns
ld hl, wd730 ld hl, wd730
@ -381,7 +397,7 @@ PartyMenuInit:: ; 1420 (0:1420)
ld [hli], a ; max menu item ID ld [hli], a ; max menu item ID
ld a, [wd11f] ld a, [wd11f]
and a and a
ld a,%00000011 ; A button and B button ld a, A_BUTTON + B_BUTTON
jr z, .next jr z, .next
xor a xor a
ld [wd11f], a ld [wd11f], a
@ -672,7 +688,7 @@ PrintBCDNumber:: ; 15cd (0:15cd)
ret ret
PrintBCDDigit:: ; 1604 (0:1604) PrintBCDDigit:: ; 1604 (0:1604)
and a,%00001111 and $f
and a and a
jr z,.zeroDigit jr z,.zeroDigit
.nonzeroDigit .nonzeroDigit
@ -1403,7 +1419,7 @@ DisplayListMenuID:: ; 2be6 (0:2be6)
ld [wTopMenuItemY],a ld [wTopMenuItemY],a
ld a,5 ld a,5
ld [wTopMenuItemX],a ld [wTopMenuItemX],a
ld a,%00000111 ; A button, B button, Select button ld a,A_BUTTON | B_BUTTON | SELECT
ld [wMenuWatchedKeys],a ld [wMenuWatchedKeys],a
ld c,10 ld c,10
call DelayFrames call DelayFrames
@ -1827,7 +1843,7 @@ PrintListMenuEntries:: ; 2e5a (0:2e5a)
ld bc,20 + 8 ; 1 row down and 8 columns right ld bc,20 + 8 ; 1 row down and 8 columns right
add hl,bc add hl,bc
ld a,"×" ld a,"×"
ldi [hl],a ld [hli],a
ld a,[wd11e] ld a,[wd11e]
push af push af
ld a,[de] ld a,[de]
@ -2653,8 +2669,8 @@ FuncTX_ItemStoragePC:: ; 3460 (0:3460)
FuncTX_BillsPC:: ; 346a (0:346a) FuncTX_BillsPC:: ; 346a (0:346a)
call SaveScreenTilesToBuffer2 call SaveScreenTilesToBuffer2
ld b, BANK(Func_214c2) ld b, BANK(BillsPC_)
ld hl, Func_214c2 ld hl, BillsPC_
jr bankswitchAndContinue jr bankswitchAndContinue
FuncTX_SlotMachine:: ; 3474 (0:3474) FuncTX_SlotMachine:: ; 3474 (0:3474)
@ -3064,65 +3080,63 @@ Func_366b:: ; 366b (0:366b)
pop hl pop hl
ret ret
; copies the tile patterns for letters and numbers into VRAM
LoadFontTilePatterns:: ; 3680 (0:3680) LoadFontTilePatterns::
ld a, [rLCDC] ld a, [rLCDC]
bit 7, a ; is the LCD enabled? bit 7, a ; is the LCD enabled?
jr nz,.lcdEnabled jr nz, .on
.lcdDisabled .off
ld hl, FontGraphics ld hl, FontGraphics
ld de, vFont ld de, vFont
ld bc, $400 ld bc, $400
ld a, BANK(FontGraphics) ld a, BANK(FontGraphics)
jp FarCopyDataDouble ; if LCD is off, transfer all at once jp FarCopyDataDouble ; if LCD is off, transfer all at once
.lcdEnabled .on
ld de, FontGraphics ld de, FontGraphics
ld hl, vFont ld hl, vFont
ld bc,(BANK(FontGraphics) << 8 | $80) ld bc, BANK(FontGraphics) << 8 | $80
jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank
; copies the text box tile patterns into VRAM LoadTextBoxTilePatterns::
LoadTextBoxTilePatterns:: ; 36a0 (0:36a0)
ld a, [rLCDC] ld a, [rLCDC]
bit 7, a ; is the LCD enabled? bit 7, a ; is the LCD enabled?
jr nz,.lcdEnabled jr nz, .on
.lcdDisabled .off
ld hl, TextBoxGraphics ld hl, TextBoxGraphics
ld de, vChars2 + $600 ld de, vChars2 + $600
ld bc, $200 ld bc, $200
ld a, BANK(TextBoxGraphics) ld a, BANK(TextBoxGraphics)
jp FarCopyData2 ; if LCD is off, transfer all at once jp FarCopyData2 ; if LCD is off, transfer all at once
.lcdEnabled .on
ld de, TextBoxGraphics ld de, TextBoxGraphics
ld hl, vChars2 + $600 ld hl, vChars2 + $600
ld bc,(BANK(TextBoxGraphics) << 8 | $20) ld bc, BANK(TextBoxGraphics) << 8 | $20
jp CopyVideoData ; if LCD is on, transfer during V-blank jp CopyVideoData ; if LCD is on, transfer during V-blank
; copies HP bar and status display tile patterns into VRAM LoadHpBarAndStatusTilePatterns::
LoadHpBarAndStatusTilePatterns:: ; 36c0 (0:36c0)
ld a, [rLCDC] ld a, [rLCDC]
bit 7, a ; is the LCD enabled? bit 7, a ; is the LCD enabled?
jr nz,.lcdEnabled jr nz, .on
.lcdDisabled .off
ld hl, HpBarAndStatusGraphics ld hl, HpBarAndStatusGraphics
ld de, vChars2 + $620 ld de, vChars2 + $620
ld bc, $1e0 ld bc, $1e0
ld a, BANK(HpBarAndStatusGraphics) ld a, BANK(HpBarAndStatusGraphics)
jp FarCopyData2 ; if LCD is off, transfer all at once jp FarCopyData2 ; if LCD is off, transfer all at once
.lcdEnabled .on
ld de, HpBarAndStatusGraphics ld de, HpBarAndStatusGraphics
ld hl, vChars2 + $620 ld hl, vChars2 + $620
ld bc,(BANK(HpBarAndStatusGraphics) << 8 | $1e) ld bc, BANK(HpBarAndStatusGraphics) << 8 | $1e
jp CopyVideoData ; if LCD is on, transfer during V-blank 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::
FillMemory:: ; 36e0 (0:36e0) ; Fill bc bytes at hl with a.
push de push de
ld d, a ld d, a
.loop .loop
ld a, d ld a, d
ldi [hl], a ld [hli], a
dec bc dec bc
ld a, b ld a, b
or c or c
@ -3130,15 +3144,16 @@ FillMemory:: ; 36e0 (0:36e0)
pop de pop de
ret ret
; loads sprite that de points to
; bank of sprite is given in a
UncompressSpriteFromDE:: ; 36eb (0:36eb) UncompressSpriteFromDE:: ; 36eb (0:36eb)
; Decompress pic at a:de.
ld hl, W_SPRITEINPUTPTR ld hl, W_SPRITEINPUTPTR
ld [hl], e ld [hl], e
inc hl inc hl
ld [hl], d ld [hl], d
jp UncompressSpriteData jp UncompressSpriteData
SaveScreenTilesToBuffer2:: ; 36f4 (0:36f4) SaveScreenTilesToBuffer2:: ; 36f4 (0:36f4)
ld hl, wTileMap ld hl, wTileMap
ld de, wTileMapBackup2 ld de, wTileMapBackup2
@ -3229,8 +3244,12 @@ GetName:: ; 376b (0:376b)
; returns pointer to name in de ; returns pointer to name in de
ld a,[wd0b5] ld a,[wd0b5]
ld [wd11e],a ld [wd11e],a
; TM names are separate from item names.
; BUG: This applies to all names instead of just items.
cp HM_01 cp HM_01
jp nc, GetMachineName jp nc, GetMachineName
ld a,[H_LOADEDROMBANK] ld a,[H_LOADEDROMBANK]
push af push af
push hl push hl
@ -3400,7 +3419,7 @@ JoypadLowSensitivity:: ; 3831 (0:3831)
.delayOver .delayOver
; if [hJoy6] = 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] ld a,[hJoyHeld]
and a,%00000011 ; A and B buttons and A_BUTTON | B_BUTTON
jr z,.setShortDelay jr z,.setShortDelay
ld a,[hJoy6] ; flag ld a,[hJoy6] ; flag
and a and a
@ -3513,7 +3532,7 @@ PrintLetterDelay:: ; 38d3 (0:38d3)
bit 0,a bit 0,a
jr z,.waitOneFrame jr z,.waitOneFrame
ld a,[W_OPTIONS] ld a,[W_OPTIONS]
and a,$0f and $f
ld [H_FRAMECOUNTER],a ld [H_FRAMECOUNTER],a
jr .checkButtons jr .checkButtons
.waitOneFrame .waitOneFrame
@ -3966,7 +3985,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
jp z,.loop1 jp z,.loop1
.checkIfAButtonOrBButtonPressed .checkIfAButtonOrBButtonPressed
ld a,[hJoy5] ld a,[hJoy5]
and a,%00000011 ; pressed A button or B button? and A_BUTTON | B_BUTTON
jr z,.skipPlayingSound jr z,.skipPlayingSound
.AButtonOrBButtonPressed .AButtonOrBButtonPressed
push hl push hl
@ -3996,14 +4015,14 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c)
and a ; is the y coordinate 0? and a ; is the y coordinate 0?
jr z,.adjustForXCoord jr z,.adjustForXCoord
ld hl,wTileMap ld hl,wTileMap
ld bc,20 ; screen width ld bc,SCREEN_WIDTH
.topMenuItemLoop .topMenuItemLoop
add hl,bc add hl,bc
dec a dec a
jr nz,.topMenuItemLoop jr nz,.topMenuItemLoop
.adjustForXCoord .adjustForXCoord
ld a,[wTopMenuItemX] ld a,[wTopMenuItemX]
ld b,$00 ld b,0
ld c,a ld c,a
add hl,bc add hl,bc
push hl push hl
@ -4156,7 +4175,7 @@ AutoTextBoxDrawingCommon:: ; 3c41 (0:3c41)
ret ret
PrintText:: ; 3c49 (0:3c49) PrintText:: ; 3c49 (0:3c49)
; given a pointer in hl, print the text there ; Print text hl at (1, 14).
push hl push hl
ld a,1 ld a,1
ld [wd125],a ld [wd125],a
@ -4168,30 +4187,28 @@ Func_3c59:: ; 3c59 (0:3c59)
bcCoord 1, 14 bcCoord 1, 14
jp TextCommandProcessor jp TextCommandProcessor
; converts a big-endian binary number into decimal and prints it
; INPUT: PrintNumber:: ; 3c5f
; b = flags and number of bytes ; Print the c-digit, b-byte value at de.
; bit 7: if set, print leading zeroes ; Allows 2 to 7 digits. For 1-digit numbers, add
; if unset, do not print leading zeroes ; the value to char "0" instead of calling PrintNumber.
; bit 6: if set, left-align the string (do not pad empty digits with spaces) ; Flags LEADING_ZEROES and LEFT_ALIGN can be given
; if unset, right-align the string ; in bits 7 and 6 of b respectively.
; bits 4-5: unused LEADING_ZEROES EQU 7
; bits 0-3: number of bytes (only 1 - 3 bytes supported) LEFT_ALIGN EQU 6
; c = number of decimal digits
; de = address of the number (big-endian)
PrintNumber:: ; 3c5f (0:3c5f)
push bc push bc
xor a xor a
ld [H_PASTLEADINGZEROES], a ld [H_PASTLEADINGZEROES], a
ld [H_NUMTOPRINT], a ld [H_NUMTOPRINT], a
ld [H_NUMTOPRINT + 1], a ld [H_NUMTOPRINT + 1], a
ld a, b ld a, b
and a,%00001111 and $f
cp a,1 cp 1
jr z,.oneByte jr z, .byte
cp a,2 cp 2
jr z,.twoBytes jr z, .word
.threeBytes .long
ld a, [de] ld a, [de]
ld [H_NUMTOPRINT], a ld [H_NUMTOPRINT], a
inc de inc de
@ -4200,104 +4217,94 @@ PrintNumber:: ; 3c5f (0:3c5f)
inc de inc de
ld a, [de] ld a, [de]
ld [H_NUMTOPRINT + 2], a ld [H_NUMTOPRINT + 2], a
jr .checkNumDigits jr .start
.twoBytes
.word
ld a, [de] ld a, [de]
ld [H_NUMTOPRINT + 1], a ld [H_NUMTOPRINT + 1], a
inc de inc de
ld a, [de] ld a, [de]
ld [H_NUMTOPRINT + 2], a ld [H_NUMTOPRINT + 2], a
jr .checkNumDigits jr .start
.oneByte
.byte
ld a, [de] ld a, [de]
ld [H_NUMTOPRINT + 2], a ld [H_NUMTOPRINT + 2], a
.checkNumDigits
.start
push de push de
ld d, b ld d, b
ld a, c ld a, c
ld b, a ld b, a
xor a xor a
ld c, a ld c, a
ld a,b ; a = number of decimal digits ld a, b
cp a,2
jr z,.tensPlace cp 2
cp a,3 jr z, .tens
jr z,.hundredsPlace cp 3
cp a,4 jr z, .hundreds
jr z,.thousandsPlace cp 4
cp a,5 jr z, .thousands
jr z,.tenThousandsPlace cp 5
cp a,6 jr z, .ten_thousands
jr z,.hundredThousandsPlace cp 6
.millionsPlace jr z, .hundred_thousands
ld a,1000000 >> 16
ld [H_POWEROFTEN],a print_digit: macro
ld a,(1000000 >> 8) & $FF
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 [H_POWEROFTEN + 1], a
ld a,1000000 & $FF
ld a, \1 / $1 % $100
ld [H_POWEROFTEN + 2], a ld [H_POWEROFTEN + 2], a
call PrintNumber_PrintDigit
call PrintNumber_AdvancePointer call .PrintDigit
.hundredThousandsPlace call .NextDigit
ld a,100000 >> 16 endm
ld [H_POWEROFTEN],a
ld a,(100000 >> 8) & $FF .millions print_digit 1000000
ld [H_POWEROFTEN + 1],a .hundred_thousands print_digit 100000
ld a,100000 & $FF .ten_thousands print_digit 10000
ld [H_POWEROFTEN + 2],a .thousands print_digit 1000
call PrintNumber_PrintDigit .hundreds print_digit 100
call PrintNumber_AdvancePointer
.tenThousandsPlace .tens
xor a ld c, 0
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
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] ld a, [H_NUMTOPRINT + 2]
.loop .mod
cp a,10 cp 10
jr c,.underflow jr c, .ok
sub a,10 sub 10
inc c inc c
jr .loop jr .mod
.underflow .ok
ld b, a ld b, a
ld a, [H_PASTLEADINGZEROES] ld a, [H_PASTLEADINGZEROES]
or c or c
ld [H_PASTLEADINGZEROES], a ld [H_PASTLEADINGZEROES], a
jr nz,.pastLeadingZeroes jr nz, .past
call PrintNumber_PrintLeadingZero call .PrintLeadingZero
jr .advancePointer jr .next
.pastLeadingZeroes .past
ld a, "0" ld a, "0"
add c add c
ld [hl], a ld [hl], a
.advancePointer .next
call PrintNumber_AdvancePointer
.onesPlace call .NextDigit
.ones
ld a, "0" ld a, "0"
add b add b
ld [hli], a ld [hli], a
@ -4306,14 +4313,10 @@ PrintNumber:: ; 3c5f (0:3c5f)
pop bc pop bc
ret ret
; prints a decimal digit .PrintDigit:
; This works by repeatedely subtracting a power of ten until the number becomes negative. ; Divide by the current decimal place.
; The number of subtractions it took in order to make the number negative is the digit for the current number place. ; Print the quotient, and keep the modulus.
; The last value that the number had before becoming negative is kept as the new value of the number. ld c, 0
; 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
.loop .loop
ld a, [H_POWEROFTEN] ld a, [H_POWEROFTEN]
ld b, a ld b, a
@ -4328,15 +4331,16 @@ PrintNumber_PrintDigit:: ; 3d25 (0:3d25)
ld a, [H_NUMTOPRINT + 1] ld a, [H_NUMTOPRINT + 1]
ld [H_SAVEDNUMTOPRINT + 1], a ld [H_SAVEDNUMTOPRINT + 1], a
cp b cp b
jr nc,.noBorrowForByte1 jr nc, .noborrow1
.byte1BorrowFromByte0
ld a, [H_NUMTOPRINT] ld a, [H_NUMTOPRINT]
or a,0 or 0
jr z, .underflow1 jr z, .underflow1
dec a dec a
ld [H_NUMTOPRINT], a ld [H_NUMTOPRINT], a
ld a, [H_NUMTOPRINT + 1] ld a, [H_NUMTOPRINT + 1]
.noBorrowForByte1 .noborrow1
sub b sub b
ld [H_NUMTOPRINT + 1], a ld [H_NUMTOPRINT + 1], a
ld a, [H_POWEROFTEN + 2] ld a, [H_POWEROFTEN + 2]
@ -4344,27 +4348,29 @@ PrintNumber_PrintDigit:: ; 3d25 (0:3d25)
ld a, [H_NUMTOPRINT + 2] ld a, [H_NUMTOPRINT + 2]
ld [H_SAVEDNUMTOPRINT + 2], a ld [H_SAVEDNUMTOPRINT + 2], a
cp b cp b
jr nc,.noBorrowForByte2 jr nc, .noborrow2
.byte2BorrowFromByte1
ld a, [H_NUMTOPRINT + 1] ld a, [H_NUMTOPRINT + 1]
and a and a
jr nz,.finishByte2BorrowFromByte1 jr nz, .borrowed
.byte2BorrowFromByte0
ld a, [H_NUMTOPRINT] ld a, [H_NUMTOPRINT]
and a and a
jr z, .underflow2 jr z, .underflow2
dec a dec a
ld [H_NUMTOPRINT], a ld [H_NUMTOPRINT], a
xor a xor a
.finishByte2BorrowFromByte1 .borrowed
dec a dec a
ld [H_NUMTOPRINT + 1], a ld [H_NUMTOPRINT + 1], a
ld a, [H_NUMTOPRINT + 2] ld a, [H_NUMTOPRINT + 2]
.noBorrowForByte2 .noborrow2
sub b sub b
ld [H_NUMTOPRINT + 2], a ld [H_NUMTOPRINT + 2], a
inc c inc c
jr .loop jr .loop
.underflow2 .underflow2
ld a, [H_SAVEDNUMTOPRINT + 1] ld a, [H_SAVEDNUMTOPRINT + 1]
ld [H_NUMTOPRINT + 1], a ld [H_NUMTOPRINT + 1], a
@ -4374,39 +4380,40 @@ PrintNumber_PrintDigit:: ; 3d25 (0:3d25)
.underflow0 .underflow0
ld a, [H_PASTLEADINGZEROES] ld a, [H_PASTLEADINGZEROES]
or c or c
jr z,PrintNumber_PrintLeadingZero jr z, .PrintLeadingZero
ld a, "0" ld a, "0"
add c add c
ld [hl], a ld [hl], a
ld [H_PASTLEADINGZEROES], a ld [H_PASTLEADINGZEROES], a
ret ret
; prints a leading zero unless they are turned off in the flags .PrintLeadingZero:
PrintNumber_PrintLeadingZero:: ; 3d83 (0:3d83) bit LEADING_ZEROES, d
bit 7,d ; print leading zeroes?
ret z ret z
ld [hl], "0" ld [hl], "0"
ret ret
; increments the pointer unless leading zeroes are not being printed, .NextDigit:
; the number is left-aligned, and no nonzero digits have been printed yet ; Increment unless the number is left-aligned,
PrintNumber_AdvancePointer:: ; 3d89 (0:3d89) ; leading zeroes are not printed, and no digits
bit 7,d ; print leading zeroes? ; have been printed yet.
jr nz,.incrementPointer bit LEADING_ZEROES, d
bit 6,d ; left alignment or right alignment? jr nz, .inc
jr z,.incrementPointer bit LEFT_ALIGN, d
jr z, .inc
ld a, [H_PASTLEADINGZEROES] ld a, [H_PASTLEADINGZEROES]
and a and a
ret z ret z
.incrementPointer .inc
inc hl inc hl
ret ret
; calls a function from a table of function pointers
; INPUT: CallFunctionInTable::
; a = index within table JumpTable::
; hl = address of function pointer table ; Call function a in jumptable hl.
CallFunctionInTable:: ; 3d97 (0:3d97) ; de is not preserved.
push hl push hl
push de push de
push bc push bc
@ -4623,95 +4630,95 @@ Func_3eb5:: ; 3eb5 (0:3eb5)
PrintPredefTextID:: ; 3ef5 (0:3ef5) PrintPredefTextID:: ; 3ef5 (0:3ef5)
ld [H_DOWNARROWBLINKCNT2], a ; $ff8c ld [H_DOWNARROWBLINKCNT2], a ; $ff8c
ld hl, PointerTable_3f22 ld hl, TextPredefs
call Func_3f0f call Func_3f0f
ld hl, wcf11 ld hl, wcf11
set 0, [hl] set 0, [hl]
call DisplayTextID call DisplayTextID
Func_3f05:: ; 3f05 (0:3f05) Func_3f05:: ; 3f05 (0:3f05)
ld hl, W_MAPTEXTPTR ; wd36c ld hl, W_MAPTEXTPTR
ld a, [$ffec] ld a, [$ffec]
ld [hli], a ld [hli], a
ld a, [$ffed] ld a, [$ffec + 1]
ld [hl], a ld [hl], a
ret ret
Func_3f0f:: ; 3f0f (0:3f0f) Func_3f0f:: ; 3f0f (0:3f0f)
ld a, [W_MAPTEXTPTR] ; wd36c ld a, [W_MAPTEXTPTR]
ld [$ffec], a ld [$ffec], a
ld a, [W_MAPTEXTPTR + 1] ld a, [W_MAPTEXTPTR + 1]
ld [$ffed], a ld [$ffec + 1], a
ld a, l ld a, l
ld [W_MAPTEXTPTR], a ; wd36c ld [W_MAPTEXTPTR], a
ld a, h ld a, h
ld [W_MAPTEXTPTR + 1], a ld [W_MAPTEXTPTR + 1], a
ret ret
PointerTable_3f22:: ; 3f22 (0:3f22) TextPredefs::
dw CardKeySuccessText ; id = 01 dw CardKeySuccessText ; 01
dw CardKeyFailText ; id = 02 dw CardKeyFailText ; 02
dw RedBedroomPC ; id = 03 dw RedBedroomPC ; 03
dw RedBedroomSNESText ; id = 04 dw RedBedroomSNESText ; 04
dw PushStartText ; id = 05 dw PushStartText ; 05
dw SaveOptionText ; id = 06 dw SaveOptionText ; 06
dw StrengthsAndWeaknessesText ; id = 07 dw StrengthsAndWeaknessesText ; 07
dw OakLabEmailText ; id = 08 dw OakLabEmailText ; 08
dw AerodactylFossilText ; id = 09 dw AerodactylFossilText ; 09
dw Route15UpstairsBinocularsText ; id = 0A dw Route15UpstairsBinocularsText ; 0A
dw KabutopsFossilText ; id = 0B dw KabutopsFossilText ; 0B
dw GymStatueText1 ; id = 0C dw GymStatueText1 ; 0C
dw GymStatueText2 ; id = 0D dw GymStatueText2 ; 0D
dw BookcaseText ; id = 0E dw BookcaseText ; 0E
dw ViridianCityPokecenterBenchGuyText ; id = 0F dw ViridianCityPokecenterBenchGuyText ; 0F
dw PewterCityPokecenterBenchGuyText ; id = 10 dw PewterCityPokecenterBenchGuyText ; 10
dw CeruleanCityPokecenterBenchGuyText ; id = 11 dw CeruleanCityPokecenterBenchGuyText ; 11
dw LavenderCityPokecenterBenchGuyText ; id = 12 dw LavenderCityPokecenterBenchGuyText ; 12
dw VermilionCityPokecenterBenchGuyText ; id = 13 dw VermilionCityPokecenterBenchGuyText ; 13
dw CeladonCityPokecenterBenchGuyText ; id = 14 dw CeladonCityPokecenterBenchGuyText ; 14
dw CeladonCityHotelText ; id = 15 dw CeladonCityHotelText ; 15
dw FuchsiaCityPokecenterBenchGuyText ; id = 16 dw FuchsiaCityPokecenterBenchGuyText ; 16
dw CinnabarIslandPokecenterBenchGuyText ; id = 17 dw CinnabarIslandPokecenterBenchGuyText ; 17
dw SaffronCityPokecenterBenchGuyText ; id = 18 dw SaffronCityPokecenterBenchGuyText ; 18
dw MtMoonPokecenterBenchGuyText ; id = 19 dw MtMoonPokecenterBenchGuyText ; 19
dw RockTunnelPokecenterBenchGuyText ; id = 1A dw RockTunnelPokecenterBenchGuyText ; 1A
dw UnusedBenchGuyText1 ; id = 1B dw UnusedBenchGuyText1 ; 1B
dw UnusedBenchGuyText2 ; id = 1C dw UnusedBenchGuyText2 ; 1C
dw UnusedBenchGuyText3 ; id = 1D dw UnusedBenchGuyText3 ; 1D
dw TerminatorText_62508 ; id = 1E dw TerminatorText_62508 ; 1E
dw PredefText1f ; id = 1F dw PredefText1f ; 1F
dw ViridianSchoolNotebook ; id = 20 dw ViridianSchoolNotebook ; 20
dw ViridianSchoolBlackboard ; id = 21 dw ViridianSchoolBlackboard ; 21
dw JustAMomentText ; id = 22 dw JustAMomentText ; 22
dw PredefText23 ; id = 23 dw PredefText23 ; 23
dw FoundHiddenItemText ; id = 24 dw FoundHiddenItemText ; 24
dw HiddenItemBagFullText ; id = 25 dw HiddenItemBagFullText ; 25
dw VermilionGymTrashText ; id = 26 dw VermilionGymTrashText ; 26
dw IndigoPlateauHQText ; id = 27 dw IndigoPlateauHQText ; 27
dw GameCornerOutOfOrderText ; id = 28 dw GameCornerOutOfOrderText ; 28
dw GameCornerOutToLunchText ; id = 29 dw GameCornerOutToLunchText ; 29
dw GameCornerSomeonesKeysText ; id = 2A dw GameCornerSomeonesKeysText ; 2A
dw FoundHiddenCoinsText ; id = 2B dw FoundHiddenCoinsText ; 2B
dw DroppedHiddenCoinsText ; id = 2C dw DroppedHiddenCoinsText ; 2C
dw BillsHouseMonitorText ; id = 2D dw BillsHouseMonitorText ; 2D
dw BillsHouseInitiatedText ; id = 2E dw BillsHouseInitiatedText ; 2E
dw BillsHousePokemonList ; id = 2F dw BillsHousePokemonList ; 2F
dw MagazinesText ; id = 30 dw MagazinesText ; 30
dw CinnabarGymQuiz ; id = 31 dw CinnabarGymQuiz ; 31
dw GameCornerNoCoinsText ; id = 32 dw GameCornerNoCoinsText ; 32
dw GameCornerCoinCaseText ; id = 33 dw GameCornerCoinCaseText ; 33
dw LinkCableHelp ; id = 34 dw LinkCableHelp ; 34
dw TMNotebook ; id = 35 dw TMNotebook ; 35
dw FightingDojoText ; id = 36 dw FightingDojoText ; 36
dw FightingDojoText_52a10 ; id = 37 dw FightingDojoText_52a10 ; 37
dw FightingDojoText_52a1d ; id = 38 dw FightingDojoText_52a1d ; 38
dw NewBicycleText ; id = 39 dw NewBicycleText ; 39
dw IndigoPlateauStatues ; id = 3A dw IndigoPlateauStatues ; 3A
dw VermilionGymTrashSuccesText1 ; id = 3B dw VermilionGymTrashSuccesText1 ; 3B
dw VermilionGymTrashSuccesText2 ; id = 3C dw VermilionGymTrashSuccesText2 ; 3C
dw VermilionGymTrashSuccesText3 ; id = 3D dw VermilionGymTrashSuccesText3 ; 3D
dw VermilionGymTrashFailText ; id = 3E dw VermilionGymTrashFailText ; 3E
dw TownMapText ; id = 3F dw TownMapText ; 3F
dw BookOrSculptureText ; id = 40 dw BookOrSculptureText ; 40
dw ElevatorText ; id = 41 dw ElevatorText ; 41
dw PokemonStuffText ; id = 42 dw PokemonStuffText ; 42