ref: be76ee56a89e72c0b87a605321bb1670e86f8220
parent: 0d9241889fc8a2f047b9fd6db25e55de1e721877
author: mid-kid <esteve.varela@gmail.com>
date: Sun Mar 25 14:24:14 EDT 2018
Organize the engine/ directory, director's cut Cleaned up `engine/routines`, in favor of moving files into more appropriate directories. predef-related routines are now in top-level `engine`. `rtc/delete_save_change_clock.asm` has been split into both `menus/delete_save.asm` and `rtc/reset_password.asm`. Made a new subdirectory: * engine/math: Contains all generic math-related routines.
--- /dev/null
+++ b/engine/battle/unreferenced_getgen1trainerclassname.asm
@@ -1,0 +1,21 @@
+Unreferenced_GetGen1TrainerClassName: ; 50a28
+ ld hl, Gen1TrainerClassNames
+ ld a, [wTrainerClass]
+ dec a
+ ld c, a
+ ld b, 0
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wStringBuffer1
+.copy
+ ld a, [hli]
+ ld [de], a
+ inc de
+ cp "@"
+ jr nz, .copy
+ ret
+
+INCLUDE "data/text/unused_gen1_trainer_names.asm"
--- /dev/null
+++ b/engine/flagpredef.asm
@@ -1,0 +1,70 @@
+SmallFarFlagAction: ; 4d7c1
+; Perform action b on bit c in flag array hl.
+; If checking a flag, check flag array d:hl unless d is 0.
+
+; For longer flag arrays, see FlagAction.
+
+ push hl
+ push bc
+
+; Divide by 8 to get the byte we want.
+ push bc
+ srl c
+ srl c
+ srl c
+ ld b, 0
+ add hl, bc
+ pop bc
+
+; Which bit we want from the byte
+ ld a, c
+ and 7
+ ld c, a
+
+; Shift left until we can mask the bit
+ ld a, 1
+ jr z, .shifted
+.shift
+ add a
+ dec c
+ jr nz, .shift
+.shifted
+ ld c, a
+
+; What are we doing to this flag?
+ dec b
+ jr z, .set ; 1
+ dec b
+ jr z, .check ; 2
+
+.reset
+ ld a, c
+ cpl
+ and [hl]
+ ld [hl], a
+ jr .done
+
+.set
+ ld a, [hl]
+ or c
+ ld [hl], a
+ jr .done
+
+.check
+ ld a, d
+ cp 0
+ jr nz, .farcheck
+
+ ld a, [hl]
+ and c
+ jr .done
+
+.farcheck
+ call GetFarByte
+ and c
+
+.done
+ pop bc
+ pop hl
+ ld c, a
+ ret
--- /dev/null
+++ b/engine/link/initlist.asm
@@ -1,0 +1,54 @@
+InitList: ; 50db9
+ ld a, [wInitListType]
+
+ cp INIT_ENEMYOT_LIST
+ jr nz, .check_party_ot_name
+ ld hl, wOTPartyCount
+ ld de, wOTPartyMonOT
+ ld a, ENEMY_OT_NAME
+ jr .done
+
+.check_party_ot_name
+ cp INIT_PLAYEROT_LIST
+ jr nz, .check_mon_name
+ ld hl, wPartyCount
+ ld de, wPartyMonOT
+ ld a, PARTY_OT_NAME
+ jr .done
+
+.check_mon_name
+ cp INIT_MON_LIST
+ jr nz, .check_item_name
+ ld hl, wCurMart
+ ld de, PokemonNames
+ ld a, MON_NAME
+ jr .done
+
+.check_item_name
+ cp INIT_BAG_ITEM_LIST
+ jr nz, .check_ob_item_name
+ ld hl, wNumItems
+ ld de, ItemNames
+ ld a, ITEM_NAME
+ jr .done
+
+.check_ob_item_name
+ ld hl, wCurMart
+ ld de, ItemNames
+ ld a, ITEM_NAME
+.done
+ ld [wNamedObjectTypeBuffer], a
+ ld a, l
+ ld [wListPointer], a
+ ld a, h
+ ld [wListPointer + 1], a
+ ld a, e
+ ld [wUnusedD102], a
+ ld a, d
+ ld [wUnusedD102 + 1], a
+ ld bc, ItemAttributes
+ ld a, c
+ ld [wItemAttributesPtr], a
+ ld a, b
+ ld [wItemAttributesPtr + 1], a
+ ret
--- /dev/null
+++ b/engine/math/getsquareroot.asm
@@ -1,0 +1,32 @@
+NUM_SQUARE_ROOTS EQU 255
+
+GetSquareRoot: ; 13b87
+; Return the square root of de in b.
+
+; Rather than calculating the result, we take the index of the
+; first value in a table of squares that isn't lower than de.
+
+ ld hl, .Squares
+ ld b, 0
+.loop
+; Make sure we don't go past the end of the table.
+ inc b
+ ld a, b
+ cp NUM_SQUARE_ROOTS
+ ret z
+
+; Iterate over the table until b**2 >= de.
+ ld a, [hli]
+ sub e
+ ld a, [hli]
+ sbc d
+
+ jr c, .loop
+ ret
+
+.Squares: ; 13b98
+x = 1
+rept NUM_SQUARE_ROOTS
+ dw x * x
+x = x + 1
+endr
--- /dev/null
+++ b/engine/math/math.asm
@@ -1,0 +1,196 @@
+_Multiply:: ; 66de
+
+; hMultiplier is one byte.
+ ld a, 8
+ ld b, a
+
+ xor a
+ ld [hProduct], a
+ ld [hMathBuffer + 1], a
+ ld [hMathBuffer + 2], a
+ ld [hMathBuffer + 3], a
+ ld [hMathBuffer + 4], a
+
+
+.loop
+ ld a, [hMultiplier]
+ srl a
+ ld [hMultiplier], a
+ jr nc, .next
+
+ ld a, [hMathBuffer + 4]
+ ld c, a
+ ld a, [hMultiplicand + 2]
+ add c
+ ld [hMathBuffer + 4], a
+
+ ld a, [hMathBuffer + 3]
+ ld c, a
+ ld a, [hMultiplicand + 1]
+ adc c
+ ld [hMathBuffer + 3], a
+
+ ld a, [hMathBuffer + 2]
+ ld c, a
+ ld a, [hMultiplicand + 0]
+ adc c
+ ld [hMathBuffer + 2], a
+
+ ld a, [hMathBuffer + 1]
+ ld c, a
+ ld a, [hProduct]
+ adc c
+ ld [hMathBuffer + 1], a
+
+.next
+ dec b
+ jr z, .done
+
+
+; hMultiplicand <<= 1
+
+ ld a, [hMultiplicand + 2]
+ add a
+ ld [hMultiplicand + 2], a
+
+ ld a, [hMultiplicand + 1]
+ rla
+ ld [hMultiplicand + 1], a
+
+ ld a, [hMultiplicand + 0]
+ rla
+ ld [hMultiplicand + 0], a
+
+ ld a, [hProduct]
+ rla
+ ld [hProduct], a
+
+ jr .loop
+
+
+.done
+ ld a, [hMathBuffer + 4]
+ ld [hProduct + 3], a
+
+ ld a, [hMathBuffer + 3]
+ ld [hProduct + 2], a
+
+ ld a, [hMathBuffer + 2]
+ ld [hProduct + 1], a
+
+ ld a, [hMathBuffer + 1]
+ ld [hProduct + 0], a
+
+ ret
+; 673e
+
+
+_Divide:: ; 673e
+ xor a
+ ld [hMathBuffer + 0], a
+ ld [hMathBuffer + 1], a
+ ld [hMathBuffer + 2], a
+ ld [hMathBuffer + 3], a
+ ld [hMathBuffer + 4], a
+
+ ld a, 9
+ ld e, a
+
+.loop
+ ld a, [hMathBuffer + 0]
+ ld c, a
+ ld a, [hDividend + 1]
+ sub c
+ ld d, a
+
+ ld a, [hDivisor]
+ ld c, a
+ ld a, [hDividend + 0]
+ sbc c
+ jr c, .next
+
+ ld [hDividend + 0], a
+
+ ld a, d
+ ld [hDividend + 1], a
+
+ ld a, [hMathBuffer + 4]
+ inc a
+ ld [hMathBuffer + 4], a
+
+ jr .loop
+
+.next
+ ld a, b
+ cp 1
+ jr z, .done
+
+ ld a, [hMathBuffer + 4]
+ add a
+ ld [hMathBuffer + 4], a
+
+ ld a, [hMathBuffer + 3]
+ rla
+ ld [hMathBuffer + 3], a
+
+ ld a, [hMathBuffer + 2]
+ rla
+ ld [hMathBuffer + 2], a
+
+ ld a, [hMathBuffer + 1]
+ rla
+ ld [hMathBuffer + 1], a
+
+ dec e
+ jr nz, .next2
+
+ ld e, 8
+ ld a, [hMathBuffer + 0]
+ ld [hDivisor], a
+ xor a
+ ld [hMathBuffer + 0], a
+
+ ld a, [hDividend + 1]
+ ld [hDividend + 0], a
+
+ ld a, [hDividend + 2]
+ ld [hDividend + 1], a
+
+ ld a, [hDividend + 3]
+ ld [hDividend + 2], a
+
+.next2
+ ld a, e
+ cp 1
+ jr nz, .okay
+ dec b
+
+.okay
+ ld a, [hDivisor]
+ srl a
+ ld [hDivisor], a
+
+ ld a, [hMathBuffer + 0]
+ rr a
+ ld [hMathBuffer + 0], a
+
+ jr .loop
+
+.done
+ ld a, [hDividend + 1]
+ ld [hDivisor], a
+
+ ld a, [hMathBuffer + 4]
+ ld [hDividend + 3], a
+
+ ld a, [hMathBuffer + 3]
+ ld [hDividend + 2], a
+
+ ld a, [hMathBuffer + 2]
+ ld [hDividend + 1], a
+
+ ld a, [hMathBuffer + 1]
+ ld [hDividend + 0], a
+
+ ret
+; 67c1
--- /dev/null
+++ b/engine/math/printnum.asm
@@ -1,0 +1,300 @@
+_PrintNum:: ; c4c7
+; Print c digits of the b-byte value from de to hl.
+; Allows 2 to 7 digits. For 1-digit numbers, add
+; the value to char "0" instead of calling PrintNum.
+; Some extra flags can be given in bits 5-7 of b.
+; Bit 5: money if set (unless left-aligned without leading zeros)
+; Bit 6: right-aligned if set
+; Bit 7: print leading zeros if set
+
+ push bc
+
+ bit 5, b
+ jr z, .main
+ bit 7, b
+ jr nz, .moneyflag
+ bit 6, b
+ jr z, .main
+
+.moneyflag ; 101xxxxx or 011xxxxx
+ ld a, "¥"
+ ld [hli], a
+ res 5, b ; 100xxxxx or 010xxxxx
+
+.main
+ xor a
+ ld [hPrintNum1], a
+ ld [hPrintNum2], a
+ ld [hPrintNum3], a
+ ld a, b
+ and $f
+ cp 1
+ jr z, .byte
+ cp 2
+ jr z, .word
+; maximum 3 bytes
+.long
+ ld a, [de]
+ ld [hPrintNum2], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum3], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum4], a
+ jr .start
+
+.word
+ ld a, [de]
+ ld [hPrintNum3], a
+ inc de
+ ld a, [de]
+ ld [hPrintNum4], a
+ jr .start
+
+.byte
+ ld a, [de]
+ ld [hPrintNum4], a
+
+.start
+ push de
+
+ ld d, b
+ ld a, c
+ swap a
+ and $f
+ ld e, a
+ ld a, c
+ and $f
+ ld b, a
+ ld c, 0
+ cp 2
+ jr z, .two
+ cp 3
+ jr z, .three
+ cp 4
+ jr z, .four
+ cp 5
+ jr z, .five
+ cp 6
+ jr z, .six
+
+.seven
+ ld a, HIGH(1000000 >> 8)
+ ld [hPrintNum5], a
+ ld a, HIGH(1000000) ; mid
+ ld [hPrintNum6], a
+ ld a, LOW(1000000)
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.six
+ ld a, HIGH(100000 >> 8)
+ ld [hPrintNum5], a
+ ld a, HIGH(100000) ; mid
+ ld [hPrintNum6], a
+ ld a, LOW(100000)
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.five
+ xor a ; HIGH(10000 >> 8)
+ ld [hPrintNum5], a
+ ld a, HIGH(10000) ; mid
+ ld [hPrintNum6], a
+ ld a, LOW(10000)
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.four
+ xor a ; HIGH(1000 >> 8)
+ ld [hPrintNum5], a
+ ld a, HIGH(1000) ; mid
+ ld [hPrintNum6], a
+ ld a, LOW(1000)
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.three
+ xor a ; HIGH(100 >> 8)
+ ld [hPrintNum5], a
+ xor a ; HIGH(100) ; mid
+ ld [hPrintNum6], a
+ ld a, LOW(100)
+ ld [hPrintNum7], a
+ call .PrintDigit
+ call .AdvancePointer
+
+.two
+ dec e
+ jr nz, .two_skip
+ ld a, "0"
+ ld [hPrintNum1], a
+.two_skip
+
+ ld c, 0
+ ld a, [hPrintNum4]
+.mod_10
+ cp 10
+ jr c, .modded_10
+ sub 10
+ inc c
+ jr .mod_10
+.modded_10
+
+ ld b, a
+ ld a, [hPrintNum1]
+ or c
+ jr nz, .money
+ call .PrintLeadingZero
+ jr .money_leading_zero
+
+.money
+ call .PrintYen
+ push af
+ ld a, "0"
+ add c
+ ld [hl], a
+ pop af
+ ld [hPrintNum1], a
+ inc e
+ dec e
+ jr nz, .money_leading_zero
+ inc hl
+ ld [hl], "<DOT>"
+
+.money_leading_zero
+ call .AdvancePointer
+ call .PrintYen
+ ld a, "0"
+ add b
+ ld [hli], a
+
+ pop de
+ pop bc
+ ret
+
+.PrintYen: ; c5ba
+ push af
+ ld a, [hPrintNum1]
+ and a
+ jr nz, .stop
+ bit 5, d
+ jr z, .stop
+ ld a, "¥"
+ ld [hli], a
+ res 5, d
+
+.stop
+ pop af
+ ret
+
+.PrintDigit: ; c5cb (3:45cb)
+ dec e
+ jr nz, .ok
+ ld a, "0"
+ ld [hPrintNum1], a
+.ok
+ ld c, 0
+.loop
+ ld a, [hPrintNum5]
+ ld b, a
+ ld a, [hPrintNum2]
+ ld [hPrintNum8], a
+ cp b
+ jr c, .skip1
+ sub b
+ ld [hPrintNum2], a
+ ld a, [hPrintNum6]
+ ld b, a
+ ld a, [hPrintNum3]
+ ld [hPrintNum9], a
+ cp b
+ jr nc, .skip2
+ ld a, [hPrintNum2]
+ or 0
+ jr z, .skip3
+ dec a
+ ld [hPrintNum2], a
+ ld a, [hPrintNum3]
+.skip2
+ sub b
+ ld [hPrintNum3], a
+ ld a, [hPrintNum7]
+ ld b, a
+ ld a, [hPrintNum4]
+ ld [hPrintNum10], a
+ cp b
+ jr nc, .skip4
+ ld a, [hPrintNum3]
+ and a
+ jr nz, .skip5
+ ld a, [hPrintNum2]
+ and a
+ jr z, .skip6
+ dec a
+ ld [hPrintNum2], a
+ xor a
+.skip5
+ dec a
+ ld [hPrintNum3], a
+ ld a, [hPrintNum4]
+.skip4
+ sub b
+ ld [hPrintNum4], a
+ inc c
+ jr .loop
+.skip6
+ ld a, [hPrintNum9]
+ ld [hPrintNum3], a
+.skip3
+ ld a, [hPrintNum8]
+ ld [hPrintNum2], a
+.skip1
+ ld a, [hPrintNum1]
+ or c
+ jr z, .PrintLeadingZero
+ ld a, [hPrintNum1]
+ and a
+ jr nz, .done
+ bit 5, d
+ jr z, .done
+ ld a, "¥"
+ ld [hli], a
+ res 5, d
+.done
+ ld a, "0"
+ add c
+ ld [hl], a
+ ld [hPrintNum1], a
+ inc e
+ dec e
+ ret nz
+ inc hl
+ ld [hl], "<DOT>"
+ ret
+
+.PrintLeadingZero: ; c644
+; prints a leading zero unless they are turned off in the flags
+ bit 7, d ; print leading zeroes?
+ ret z
+ ld [hl], "0"
+ ret
+
+.AdvancePointer: ; c64a
+; increments the pointer unless leading zeroes are not being printed,
+; the number is left-aligned, and no nonzero digits have been printed yet
+ bit 7, d ; print leading zeroes?
+ jr nz, .inc
+ bit 6, d ; left alignment or right alignment?
+ jr z, .inc
+ ld a, [hPrintNum1]
+ and a
+ ret z
+.inc
+ inc hl
+ ret
--- /dev/null
+++ b/engine/math/sine.asm
@@ -1,0 +1,4 @@
+_Sine:: ; 84d9
+; a = d * sin(e * pi/32)
+ ld a, e
+ calc_sine_wave
--- /dev/null
+++ b/engine/menus/delete_save.asm
@@ -1,0 +1,36 @@
+_DeleteSaveData: ; 4d54c
+ farcall BlankScreen
+ ld b, SCGB_DIPLOMA
+ call GetSGBLayout
+ call LoadStandardFont
+ call LoadFontsExtra
+ ld de, MUSIC_MAIN_MENU
+ call PlayMusic
+ ld hl, .Text_ClearAllSaveData
+ call PrintText
+ ld hl, .NoYesMenuHeader
+ call CopyMenuHeader
+ call VerticalMenu
+ ret c
+ ld a, [wMenuCursorY]
+ cp $1
+ ret z
+ farcall EmptyAllSRAMBanks
+ ret
+
+.Text_ClearAllSaveData: ; 0x4d580
+ ; Clear all save data?
+ text_jump UnknownText_0x1c564a
+ db "@"
+
+.NoYesMenuHeader: ; 0x4d585
+ db 0 ; flags
+ menu_coords 14, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
+ dw .MenuData
+ db 1 ; default option
+
+.MenuData: ; 0x4d58d
+ db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
+ db 2 ; items
+ db "NO@"
+ db "YES@"
--- /dev/null
+++ b/engine/menus/emptyallsrambanks.asm
@@ -1,0 +1,19 @@
+EmptyAllSRAMBanks: ; 4cf1f
+ ld a, 0
+ call .EmptyBank
+ ld a, 1
+ call .EmptyBank
+ ld a, 2
+ call .EmptyBank
+ ld a, 3
+ call .EmptyBank
+ ret
+
+.EmptyBank: ; 4cf34
+ call GetSRAMBank
+ ld hl, SRAM_Begin
+ ld bc, SRAM_End - SRAM_Begin
+ xor a
+ call ByteFill
+ call CloseSRAM
+ ret
--- /dev/null
+++ b/engine/predef.asm
@@ -1,0 +1,29 @@
+GetPredefPointer:: ; 854b
+; Return the bank and address of wPredefID in a and wPredefAddress.
+
+; Save hl for later (back in Predef)
+ ld a, h
+ ld [wPredefTemp], a
+ ld a, l
+ ld [wPredefTemp + 1], a
+
+ push de
+ ld a, [wPredefID]
+ ld e, a
+ ld d, 0
+ ld hl, PredefPointers
+ add hl, de
+ add hl, de
+ add hl, de
+ pop de
+
+ ld a, [hli]
+ ld [wPredefAddress + 1], a
+ ld a, [hli]
+ ld [wPredefAddress], a
+ ld a, [hl]
+
+ ret
+; 856b
+
+INCLUDE "data/predef_pointers.asm"
--- a/engine/routines/emptyallsrambanks.asm
+++ /dev/null
@@ -1,19 +1,0 @@
-EmptyAllSRAMBanks: ; 4cf1f
- ld a, 0
- call .EmptyBank
- ld a, 1
- call .EmptyBank
- ld a, 2
- call .EmptyBank
- ld a, 3
- call .EmptyBank
- ret
-
-.EmptyBank: ; 4cf34
- call GetSRAMBank
- ld hl, SRAM_Begin
- ld bc, SRAM_End - SRAM_Begin
- xor a
- call ByteFill
- call CloseSRAM
- ret
--- a/engine/routines/flagpredef.asm
+++ /dev/null
@@ -1,70 +1,0 @@
-SmallFarFlagAction: ; 4d7c1
-; Perform action b on bit c in flag array hl.
-; If checking a flag, check flag array d:hl unless d is 0.
-
-; For longer flag arrays, see FlagAction.
-
- push hl
- push bc
-
-; Divide by 8 to get the byte we want.
- push bc
- srl c
- srl c
- srl c
- ld b, 0
- add hl, bc
- pop bc
-
-; Which bit we want from the byte
- ld a, c
- and 7
- ld c, a
-
-; Shift left until we can mask the bit
- ld a, 1
- jr z, .shifted
-.shift
- add a
- dec c
- jr nz, .shift
-.shifted
- ld c, a
-
-; What are we doing to this flag?
- dec b
- jr z, .set ; 1
- dec b
- jr z, .check ; 2
-
-.reset
- ld a, c
- cpl
- and [hl]
- ld [hl], a
- jr .done
-
-.set
- ld a, [hl]
- or c
- ld [hl], a
- jr .done
-
-.check
- ld a, d
- cp 0
- jr nz, .farcheck
-
- ld a, [hl]
- and c
- jr .done
-
-.farcheck
- call GetFarByte
- and c
-
-.done
- pop bc
- pop hl
- ld c, a
- ret
--- a/engine/routines/getsquareroot.asm
+++ /dev/null
@@ -1,32 +1,0 @@
-NUM_SQUARE_ROOTS EQU 255
-
-GetSquareRoot: ; 13b87
-; Return the square root of de in b.
-
-; Rather than calculating the result, we take the index of the
-; first value in a table of squares that isn't lower than de.
-
- ld hl, .Squares
- ld b, 0
-.loop
-; Make sure we don't go past the end of the table.
- inc b
- ld a, b
- cp NUM_SQUARE_ROOTS
- ret z
-
-; Iterate over the table until b**2 >= de.
- ld a, [hli]
- sub e
- ld a, [hli]
- sbc d
-
- jr c, .loop
- ret
-
-.Squares: ; 13b98
-x = 1
-rept NUM_SQUARE_ROOTS
- dw x * x
-x = x + 1
-endr
--- a/engine/routines/initlist.asm
+++ /dev/null
@@ -1,54 +1,0 @@
-InitList: ; 50db9
- ld a, [wInitListType]
-
- cp INIT_ENEMYOT_LIST
- jr nz, .check_party_ot_name
- ld hl, wOTPartyCount
- ld de, wOTPartyMonOT
- ld a, ENEMY_OT_NAME
- jr .done
-
-.check_party_ot_name
- cp INIT_PLAYEROT_LIST
- jr nz, .check_mon_name
- ld hl, wPartyCount
- ld de, wPartyMonOT
- ld a, PARTY_OT_NAME
- jr .done
-
-.check_mon_name
- cp INIT_MON_LIST
- jr nz, .check_item_name
- ld hl, wCurMart
- ld de, PokemonNames
- ld a, MON_NAME
- jr .done
-
-.check_item_name
- cp INIT_BAG_ITEM_LIST
- jr nz, .check_ob_item_name
- ld hl, wNumItems
- ld de, ItemNames
- ld a, ITEM_NAME
- jr .done
-
-.check_ob_item_name
- ld hl, wCurMart
- ld de, ItemNames
- ld a, ITEM_NAME
-.done
- ld [wNamedObjectTypeBuffer], a
- ld a, l
- ld [wListPointer], a
- ld a, h
- ld [wListPointer + 1], a
- ld a, e
- ld [wUnusedD102], a
- ld a, d
- ld [wUnusedD102 + 1], a
- ld bc, ItemAttributes
- ld a, c
- ld [wItemAttributesPtr], a
- ld a, b
- ld [wItemAttributesPtr + 1], a
- ret
--- a/engine/routines/math.asm
+++ /dev/null
@@ -1,196 +1,0 @@
-_Multiply:: ; 66de
-
-; hMultiplier is one byte.
- ld a, 8
- ld b, a
-
- xor a
- ld [hProduct], a
- ld [hMathBuffer + 1], a
- ld [hMathBuffer + 2], a
- ld [hMathBuffer + 3], a
- ld [hMathBuffer + 4], a
-
-
-.loop
- ld a, [hMultiplier]
- srl a
- ld [hMultiplier], a
- jr nc, .next
-
- ld a, [hMathBuffer + 4]
- ld c, a
- ld a, [hMultiplicand + 2]
- add c
- ld [hMathBuffer + 4], a
-
- ld a, [hMathBuffer + 3]
- ld c, a
- ld a, [hMultiplicand + 1]
- adc c
- ld [hMathBuffer + 3], a
-
- ld a, [hMathBuffer + 2]
- ld c, a
- ld a, [hMultiplicand + 0]
- adc c
- ld [hMathBuffer + 2], a
-
- ld a, [hMathBuffer + 1]
- ld c, a
- ld a, [hProduct]
- adc c
- ld [hMathBuffer + 1], a
-
-.next
- dec b
- jr z, .done
-
-
-; hMultiplicand <<= 1
-
- ld a, [hMultiplicand + 2]
- add a
- ld [hMultiplicand + 2], a
-
- ld a, [hMultiplicand + 1]
- rla
- ld [hMultiplicand + 1], a
-
- ld a, [hMultiplicand + 0]
- rla
- ld [hMultiplicand + 0], a
-
- ld a, [hProduct]
- rla
- ld [hProduct], a
-
- jr .loop
-
-
-.done
- ld a, [hMathBuffer + 4]
- ld [hProduct + 3], a
-
- ld a, [hMathBuffer + 3]
- ld [hProduct + 2], a
-
- ld a, [hMathBuffer + 2]
- ld [hProduct + 1], a
-
- ld a, [hMathBuffer + 1]
- ld [hProduct + 0], a
-
- ret
-; 673e
-
-
-_Divide:: ; 673e
- xor a
- ld [hMathBuffer + 0], a
- ld [hMathBuffer + 1], a
- ld [hMathBuffer + 2], a
- ld [hMathBuffer + 3], a
- ld [hMathBuffer + 4], a
-
- ld a, 9
- ld e, a
-
-.loop
- ld a, [hMathBuffer + 0]
- ld c, a
- ld a, [hDividend + 1]
- sub c
- ld d, a
-
- ld a, [hDivisor]
- ld c, a
- ld a, [hDividend + 0]
- sbc c
- jr c, .next
-
- ld [hDividend + 0], a
-
- ld a, d
- ld [hDividend + 1], a
-
- ld a, [hMathBuffer + 4]
- inc a
- ld [hMathBuffer + 4], a
-
- jr .loop
-
-.next
- ld a, b
- cp 1
- jr z, .done
-
- ld a, [hMathBuffer + 4]
- add a
- ld [hMathBuffer + 4], a
-
- ld a, [hMathBuffer + 3]
- rla
- ld [hMathBuffer + 3], a
-
- ld a, [hMathBuffer + 2]
- rla
- ld [hMathBuffer + 2], a
-
- ld a, [hMathBuffer + 1]
- rla
- ld [hMathBuffer + 1], a
-
- dec e
- jr nz, .next2
-
- ld e, 8
- ld a, [hMathBuffer + 0]
- ld [hDivisor], a
- xor a
- ld [hMathBuffer + 0], a
-
- ld a, [hDividend + 1]
- ld [hDividend + 0], a
-
- ld a, [hDividend + 2]
- ld [hDividend + 1], a
-
- ld a, [hDividend + 3]
- ld [hDividend + 2], a
-
-.next2
- ld a, e
- cp 1
- jr nz, .okay
- dec b
-
-.okay
- ld a, [hDivisor]
- srl a
- ld [hDivisor], a
-
- ld a, [hMathBuffer + 0]
- rr a
- ld [hMathBuffer + 0], a
-
- jr .loop
-
-.done
- ld a, [hDividend + 1]
- ld [hDivisor], a
-
- ld a, [hMathBuffer + 4]
- ld [hDividend + 3], a
-
- ld a, [hMathBuffer + 3]
- ld [hDividend + 2], a
-
- ld a, [hMathBuffer + 2]
- ld [hDividend + 1], a
-
- ld a, [hMathBuffer + 1]
- ld [hDividend + 0], a
-
- ret
-; 67c1
--- a/engine/routines/predef.asm
+++ /dev/null
@@ -1,29 +1,0 @@
-GetPredefPointer:: ; 854b
-; Return the bank and address of wPredefID in a and wPredefAddress.
-
-; Save hl for later (back in Predef)
- ld a, h
- ld [wPredefTemp], a
- ld a, l
- ld [wPredefTemp + 1], a
-
- push de
- ld a, [wPredefID]
- ld e, a
- ld d, 0
- ld hl, PredefPointers
- add hl, de
- add hl, de
- add hl, de
- pop de
-
- ld a, [hli]
- ld [wPredefAddress + 1], a
- ld a, [hli]
- ld [wPredefAddress], a
- ld a, [hl]
-
- ret
-; 856b
-
-INCLUDE "data/predef_pointers.asm"
--- a/engine/routines/printnum.asm
+++ /dev/null
@@ -1,300 +1,0 @@
-_PrintNum:: ; c4c7
-; Print c digits of the b-byte value from de to hl.
-; Allows 2 to 7 digits. For 1-digit numbers, add
-; the value to char "0" instead of calling PrintNum.
-; Some extra flags can be given in bits 5-7 of b.
-; Bit 5: money if set (unless left-aligned without leading zeros)
-; Bit 6: right-aligned if set
-; Bit 7: print leading zeros if set
-
- push bc
-
- bit 5, b
- jr z, .main
- bit 7, b
- jr nz, .moneyflag
- bit 6, b
- jr z, .main
-
-.moneyflag ; 101xxxxx or 011xxxxx
- ld a, "¥"
- ld [hli], a
- res 5, b ; 100xxxxx or 010xxxxx
-
-.main
- xor a
- ld [hPrintNum1], a
- ld [hPrintNum2], a
- ld [hPrintNum3], a
- ld a, b
- and $f
- cp 1
- jr z, .byte
- cp 2
- jr z, .word
-; maximum 3 bytes
-.long
- ld a, [de]
- ld [hPrintNum2], a
- inc de
- ld a, [de]
- ld [hPrintNum3], a
- inc de
- ld a, [de]
- ld [hPrintNum4], a
- jr .start
-
-.word
- ld a, [de]
- ld [hPrintNum3], a
- inc de
- ld a, [de]
- ld [hPrintNum4], a
- jr .start
-
-.byte
- ld a, [de]
- ld [hPrintNum4], a
-
-.start
- push de
-
- ld d, b
- ld a, c
- swap a
- and $f
- ld e, a
- ld a, c
- and $f
- ld b, a
- ld c, 0
- cp 2
- jr z, .two
- cp 3
- jr z, .three
- cp 4
- jr z, .four
- cp 5
- jr z, .five
- cp 6
- jr z, .six
-
-.seven
- ld a, HIGH(1000000 >> 8)
- ld [hPrintNum5], a
- ld a, HIGH(1000000) ; mid
- ld [hPrintNum6], a
- ld a, LOW(1000000)
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.six
- ld a, HIGH(100000 >> 8)
- ld [hPrintNum5], a
- ld a, HIGH(100000) ; mid
- ld [hPrintNum6], a
- ld a, LOW(100000)
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.five
- xor a ; HIGH(10000 >> 8)
- ld [hPrintNum5], a
- ld a, HIGH(10000) ; mid
- ld [hPrintNum6], a
- ld a, LOW(10000)
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.four
- xor a ; HIGH(1000 >> 8)
- ld [hPrintNum5], a
- ld a, HIGH(1000) ; mid
- ld [hPrintNum6], a
- ld a, LOW(1000)
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.three
- xor a ; HIGH(100 >> 8)
- ld [hPrintNum5], a
- xor a ; HIGH(100) ; mid
- ld [hPrintNum6], a
- ld a, LOW(100)
- ld [hPrintNum7], a
- call .PrintDigit
- call .AdvancePointer
-
-.two
- dec e
- jr nz, .two_skip
- ld a, "0"
- ld [hPrintNum1], a
-.two_skip
-
- ld c, 0
- ld a, [hPrintNum4]
-.mod_10
- cp 10
- jr c, .modded_10
- sub 10
- inc c
- jr .mod_10
-.modded_10
-
- ld b, a
- ld a, [hPrintNum1]
- or c
- jr nz, .money
- call .PrintLeadingZero
- jr .money_leading_zero
-
-.money
- call .PrintYen
- push af
- ld a, "0"
- add c
- ld [hl], a
- pop af
- ld [hPrintNum1], a
- inc e
- dec e
- jr nz, .money_leading_zero
- inc hl
- ld [hl], "<DOT>"
-
-.money_leading_zero
- call .AdvancePointer
- call .PrintYen
- ld a, "0"
- add b
- ld [hli], a
-
- pop de
- pop bc
- ret
-
-.PrintYen: ; c5ba
- push af
- ld a, [hPrintNum1]
- and a
- jr nz, .stop
- bit 5, d
- jr z, .stop
- ld a, "¥"
- ld [hli], a
- res 5, d
-
-.stop
- pop af
- ret
-
-.PrintDigit: ; c5cb (3:45cb)
- dec e
- jr nz, .ok
- ld a, "0"
- ld [hPrintNum1], a
-.ok
- ld c, 0
-.loop
- ld a, [hPrintNum5]
- ld b, a
- ld a, [hPrintNum2]
- ld [hPrintNum8], a
- cp b
- jr c, .skip1
- sub b
- ld [hPrintNum2], a
- ld a, [hPrintNum6]
- ld b, a
- ld a, [hPrintNum3]
- ld [hPrintNum9], a
- cp b
- jr nc, .skip2
- ld a, [hPrintNum2]
- or 0
- jr z, .skip3
- dec a
- ld [hPrintNum2], a
- ld a, [hPrintNum3]
-.skip2
- sub b
- ld [hPrintNum3], a
- ld a, [hPrintNum7]
- ld b, a
- ld a, [hPrintNum4]
- ld [hPrintNum10], a
- cp b
- jr nc, .skip4
- ld a, [hPrintNum3]
- and a
- jr nz, .skip5
- ld a, [hPrintNum2]
- and a
- jr z, .skip6
- dec a
- ld [hPrintNum2], a
- xor a
-.skip5
- dec a
- ld [hPrintNum3], a
- ld a, [hPrintNum4]
-.skip4
- sub b
- ld [hPrintNum4], a
- inc c
- jr .loop
-.skip6
- ld a, [hPrintNum9]
- ld [hPrintNum3], a
-.skip3
- ld a, [hPrintNum8]
- ld [hPrintNum2], a
-.skip1
- ld a, [hPrintNum1]
- or c
- jr z, .PrintLeadingZero
- ld a, [hPrintNum1]
- and a
- jr nz, .done
- bit 5, d
- jr z, .done
- ld a, "¥"
- ld [hli], a
- res 5, d
-.done
- ld a, "0"
- add c
- ld [hl], a
- ld [hPrintNum1], a
- inc e
- dec e
- ret nz
- inc hl
- ld [hl], "<DOT>"
- ret
-
-.PrintLeadingZero: ; c644
-; prints a leading zero unless they are turned off in the flags
- bit 7, d ; print leading zeroes?
- ret z
- ld [hl], "0"
- ret
-
-.AdvancePointer: ; c64a
-; increments the pointer unless leading zeroes are not being printed,
-; the number is left-aligned, and no nonzero digits have been printed yet
- bit 7, d ; print leading zeroes?
- jr nz, .inc
- bit 6, d ; left alignment or right alignment?
- jr z, .inc
- ld a, [hPrintNum1]
- and a
- ret z
-.inc
- inc hl
- ret
--- a/engine/routines/sine.asm
+++ /dev/null
@@ -1,4 +1,0 @@
-_Sine:: ; 84d9
-; a = d * sin(e * pi/32)
- ld a, e
- calc_sine_wave
--- a/engine/routines/unreferenced_getgen1trainerclassname.asm
+++ /dev/null
@@ -1,21 +1,0 @@
-Unreferenced_GetGen1TrainerClassName: ; 50a28
- ld hl, Gen1TrainerClassNames
- ld a, [wTrainerClass]
- dec a
- ld c, a
- ld b, 0
- add hl, bc
- add hl, bc
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld de, wStringBuffer1
-.copy
- ld a, [hli]
- ld [de], a
- inc de
- cp "@"
- jr nz, .copy
- ret
-
-INCLUDE "data/text/unused_gen1_trainer_names.asm"
--- a/engine/rtc/clock_reset.asm
+++ /dev/null
@@ -1,254 +1,0 @@
-
-ResetClock_GetWraparoundTime: ; 20000 (8:4000)
- push hl
- dec a
- ld e, a
- ld d, 0
- ld hl, .WrapAroundTimes
-rept 4
- add hl, de
-endr
- ld e, [hl]
- inc hl
- ld d, [hl]
- inc hl
- ld b, [hl]
- inc hl
- ld c, [hl]
- pop hl
- ret
-; 20015 (8:4015)
-
-.WrapAroundTimes: ; 20015
- dw wBuffer4
- db 7, 4
-
- dw wBuffer5
- db 24, 12
-
- dw wBuffer6
- db 60, 15
-; 20021
-
-RestartClock: ; 20021 (8:4021)
-; If we're here, we had an RTC overflow.
- ld hl, .Text_ClockTimeMayBeWrong
- call PrintText
- ld hl, wOptions
- ld a, [hl]
- push af
- set NO_TEXT_SCROLL, [hl]
- call LoadStandardMenuHeader
- call ClearTileMap
- ld hl, .Text_SetWithControlPad
- call PrintText
- call .SetClock
- call ExitMenu
- pop bc
- ld hl, wOptions
- ld [hl], b
- ld c, a
- ret
-; 20047 (8:4047)
-
-.Text_ClockTimeMayBeWrong: ; 0x20047
- ; The clock's time may be wrong. Please reset the time.
- text_jump UnknownText_0x1c40e6
- db "@"
-; 0x2004c
-
-.Text_SetWithControlPad: ; 0x2004c
- ; Set with the Control Pad. Confirm: A Button Cancel: B Button
- text_jump UnknownText_0x1c411c
- db "@"
-; 0x20051
-
-.SetClock: ; 20051 (8:4051)
- ld a, 1
- ld [wBuffer1], a ; which digit
- ld [wBuffer2], a
- ld a, 8
- ld [wBuffer3], a
- call UpdateTime
- call GetWeekday
- ld [wBuffer4], a
- ld a, [hHours]
- ld [wBuffer5], a
- ld a, [hMinutes]
- ld [wBuffer6], a
-
-.loop
- call .joy_loop
- jr nc, .loop
- and a
- ret nz
- call .PrintTime
- ld hl, .Text_IsThisOK
- call PrintText
- call YesNoBox
- jr c, .cancel
- ld a, [wBuffer4]
- ld [wStringBuffer2], a
- ld a, [wBuffer5]
- ld [wStringBuffer2 + 1], a
- ld a, [wBuffer6]
- ld [wStringBuffer2 + 2], a
- xor a
- ld [wStringBuffer2 + 3], a
- call InitTime
- call .PrintTime
- ld hl, .Text_ClockReset
- call PrintText
- call WaitPressAorB_BlinkCursor
- xor a
- ret
-
-.cancel
- ld a, $1
- ret
-; 200b0 (8:40b0)
-
-.Text_IsThisOK: ; 0x200b0
- ; Is this OK?
- text_jump UnknownText_0x1c415b
- db "@"
-; 0x200b5
-
-.Text_ClockReset: ; 0x200b5
- ; The clock has been reset.
- text_jump UnknownText_0x1c4168
- db "@"
-; 0x200ba
-
-.joy_loop
- call JoyTextDelay_ForcehJoyDown
- ld c, a
- push af
- call .PrintTime
- pop af
- bit 0, a
- jr nz, .press_A
- bit 1, a
- jr nz, .press_B
- bit 6, a
- jr nz, .pressed_up
- bit 7, a
- jr nz, .pressed_down
- bit 5, a
- jr nz, .pressed_left
- bit 4, a
- jr nz, .pressed_right
- jr .joy_loop
-
-.press_A
- ld a, $0
- scf
- ret
-
-.press_B
- ld a, $1
- scf
- ret
-
-.pressed_up
- ld a, [wBuffer1]
- call ResetClock_GetWraparoundTime
- ld a, [de]
- inc a
- ld [de], a
- cp b
- jr c, .done_scroll
- ld a, $0
- ld [de], a
- jr .done_scroll
-
-.pressed_down
- ld a, [wBuffer1]
- call ResetClock_GetWraparoundTime
- ld a, [de]
- dec a
- ld [de], a
- cp -1
- jr nz, .done_scroll
- ld a, b
- dec a
- ld [de], a
- jr .done_scroll
-
-.pressed_left
- ld hl, wBuffer1
- dec [hl]
- jr nz, .done_scroll
- ld [hl], $3
- jr .done_scroll
-
-.pressed_right
- ld hl, wBuffer1
- inc [hl]
- ld a, [hl]
- cp $4
- jr c, .done_scroll
- ld [hl], $1
-
-.done_scroll
- xor a
- ret
-
-.PrintTime: ; 2011f (8:411f)
- hlcoord 0, 5
- ld b, 5
- ld c, 18
- call TextBox
- decoord 1, 8
- ld a, [wBuffer4]
- ld b, a
- farcall PrintDayOfWeek
- ld a, [wBuffer5]
- ld b, a
- ld a, [wBuffer6]
- ld c, a
- decoord 11, 8
- farcall PrintHoursMins
- ld a, [wBuffer2]
- lb de, " ", " "
- call .PlaceChars
- ld a, [wBuffer1]
- lb de, "▲", "▼"
- call .PlaceChars
- ld a, [wBuffer1]
- ld [wBuffer2], a
- ret
-; 20160 (8:4160)
-
-.unreferenced ; 20160
-; unused
- ld a, [wBuffer3]
- ld b, a
- call Coord2Tile
- ret
-; 20168
-
-.PlaceChars: ; 20168 (8:4168)
- push de
- call ResetClock_GetWraparoundTime
- ld a, [wBuffer3]
- dec a
- ld b, a
- call Coord2Tile
- pop de
- ld [hl], d
- ld bc, 2 * SCREEN_WIDTH
- add hl, bc
- ld [hl], e
- ret
-; 2017c (8:417c)
-
-UnreferencedString_HourJP: ; 2017c
-; unused
- db "じ@" ; HR
-; 2017e
-
-UnreferencedString_MinuteJP: ; 2017e
-; unused
- db "ふん@" ; MIN
-; 20181
--- a/engine/rtc/delete_save_change_clock.asm
+++ /dev/null
@@ -1,296 +1,0 @@
-_ResetClock: ; 4d3b1
- farcall BlankScreen
- ld b, SCGB_DIPLOMA
- call GetSGBLayout
- call LoadStandardFont
- call LoadFontsExtra
- ld de, MUSIC_MAIN_MENU
- call PlayMusic
- ld hl, .text_askreset
- call PrintText
- ld hl, .NoYes_MenuHeader
- call CopyMenuHeader
- call VerticalMenu
- ret c
- ld a, [wMenuCursorY]
- cp $1
- ret z
- call ClockResetPassword
- jr c, .wrongpassword
- ld a, BANK(sRTCStatusFlags)
- call GetSRAMBank
- ld a, $80
- ld [sRTCStatusFlags], a
- call CloseSRAM
- ld hl, .text_okay
- call PrintText
- ret
-
-.wrongpassword
- ld hl, .text_wrong
- call PrintText
- ret
-
-.text_okay ; 0x4d3fe
- ; Password OK. Select CONTINUE & reset settings.
- text_jump UnknownText_0x1c55db
- db "@"
-
-.text_wrong ; 0x4d403
- ; Wrong password!
- text_jump UnknownText_0x1c560b
- db "@"
-
-.text_askreset ; 0x4d408
- ; Reset the clock?
- text_jump UnknownText_0x1c561c
- db "@"
-
-.NoYes_MenuHeader: ; 0x4d40d
- db 0 ; flags
- menu_coords 14, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
- dw .NoYes_MenuData
- db 1 ; default option
-
-.NoYes_MenuData: ; 0x4d415
- db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
- db 2 ; items
- db "NO@"
- db "YES@"
-
-ClockResetPassword: ; 4d41e
- call .CalculatePassword
- push de
- ld hl, wStringBuffer2
- ld bc, 5
- xor a
- call ByteFill
- ld a, $4
- ld [wStringBuffer2 + 5], a
- ld hl, .pleaseenterpasswordtext
- call PrintText
-.loop
- call .updateIDdisplay
-.loop2
- call JoyTextDelay
- ld a, [hJoyLast]
- ld b, a
- and A_BUTTON
- jr nz, .confirm
- ld a, b
- and D_PAD
- jr z, .loop2
- call .dpadinput
- ld c, 3
- call DelayFrames
- jr .loop
-
-.confirm
- call .ConvertDecIDToBytes
- pop de
- ld a, e
- cp l
- jr nz, .nope
- ld a, d
- cp h
- jr nz, .nope
- and a
- ret
-
-.nope
- scf
- ret
-
-.pleaseenterpasswordtext ; 0x4d463
- ; Please enter the password.
- text_jump UnknownText_0x1c562e
- db "@"
-
-.updateIDdisplay ; 4d468
- hlcoord 14, 15
- ld de, wStringBuffer2
- ld c, 5
-.loop3
- ld a, [de]
- add "0"
- ld [hli], a
- inc de
- dec c
- jr nz, .loop3
- hlcoord 14, 16
- ld bc, 5
- ld a, " "
- call ByteFill
- hlcoord 14, 16
- ld a, [wStringBuffer2 + 5]
- ld e, a
- ld d, $0
- add hl, de
- ld [hl], "▲"
- ret
-
-.dpadinput ; 4d490
- ld a, b
- and D_LEFT
- jr nz, .left
- ld a, b
- and D_RIGHT
- jr nz, .right
- ld a, b
- and D_UP
- jr nz, .up
- ld a, b
- and D_DOWN
- jr nz, .down
- ret
-
-.left
- ld a, [wStringBuffer2 + 5]
- and a
- ret z
- dec a
- ld [wStringBuffer2 + 5], a
- ret
-
-.right
- ld a, [wStringBuffer2 + 5]
- cp $4
- ret z
- inc a
- ld [wStringBuffer2 + 5], a
- ret
-
-.up
- call .getcurrentdigit
- ld a, [hl]
- cp 9
- jr z, .wraparound_up
- inc a
- ld [hl], a
- ret
-
-.wraparound_up
- ld [hl], $0
- ret
-
-.down
- call .getcurrentdigit
- ld a, [hl]
- and a
- jr z, .wraparound_down
- dec a
- ld [hl], a
- ret
-
-.wraparound_down
- ld [hl], 9
- ret
-
-.getcurrentdigit ; 4d4d5
- ld a, [wStringBuffer2 + 5]
- ld e, a
- ld d, $0
- ld hl, wStringBuffer2
- add hl, de
- ret
-
-.ConvertDecIDToBytes: ; 4d4e0
- ld hl, 0
- ld de, wStringBuffer2 + 4
- ld bc, 1
- call .ConvertToBytes
- ld bc, 10
- call .ConvertToBytes
- ld bc, 100
- call .ConvertToBytes
- ld bc, 1000
- call .ConvertToBytes
- ld bc, 10000
-.ConvertToBytes: ; 4d501
- ld a, [de]
- dec de
- push hl
- ld hl, 0
- call AddNTimes
- ld c, l
- ld b, h
- pop hl
- add hl, bc
- ret
-
-.CalculatePassword: ; 4d50f
- ld a, BANK(sPlayerData)
- call GetSRAMBank
- ld de, 0
- ld hl, sPlayerData + (wPlayerID - wPlayerData)
- ld c, $2
- call .ComponentFromNumber
- ld hl, sPlayerData + (wPlayerName - wPlayerData)
- ld c, NAME_LENGTH_JAPANESE - 1
- call .ComponentFromString
- ld hl, sPlayerData + (wMoney - wPlayerData)
- ld c, $3
- call .ComponentFromNumber
- call CloseSRAM
- ret
-
-.ComponentFromNumber: ; 4d533
- ld a, [hli]
- add e
- ld e, a
- ld a, $0
- adc d
- ld d, a
- dec c
- jr nz, .ComponentFromNumber
- ret
-
-.ComponentFromString: ; 4d53e
- ld a, [hli]
- cp "@"
- ret z
- add e
- ld e, a
- ld a, $0
- adc d
- ld d, a
- dec c
- jr nz, .ComponentFromString
- ret
-
-_DeleteSaveData: ; 4d54c
- farcall BlankScreen
- ld b, SCGB_DIPLOMA
- call GetSGBLayout
- call LoadStandardFont
- call LoadFontsExtra
- ld de, MUSIC_MAIN_MENU
- call PlayMusic
- ld hl, .Text_ClearAllSaveData
- call PrintText
- ld hl, .NoYesMenuHeader
- call CopyMenuHeader
- call VerticalMenu
- ret c
- ld a, [wMenuCursorY]
- cp $1
- ret z
- farcall EmptyAllSRAMBanks
- ret
-
-.Text_ClearAllSaveData: ; 0x4d580
- ; Clear all save data?
- text_jump UnknownText_0x1c564a
- db "@"
-
-.NoYesMenuHeader: ; 0x4d585
- db 0 ; flags
- menu_coords 14, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
- dw .MenuData
- db 1 ; default option
-
-.MenuData: ; 0x4d58d
- db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
- db 2 ; items
- db "NO@"
- db "YES@"
--- /dev/null
+++ b/engine/rtc/reset_password.asm
@@ -1,0 +1,259 @@
+_ResetClock: ; 4d3b1
+ farcall BlankScreen
+ ld b, SCGB_DIPLOMA
+ call GetSGBLayout
+ call LoadStandardFont
+ call LoadFontsExtra
+ ld de, MUSIC_MAIN_MENU
+ call PlayMusic
+ ld hl, .text_askreset
+ call PrintText
+ ld hl, .NoYes_MenuHeader
+ call CopyMenuHeader
+ call VerticalMenu
+ ret c
+ ld a, [wMenuCursorY]
+ cp $1
+ ret z
+ call ClockResetPassword
+ jr c, .wrongpassword
+ ld a, BANK(sRTCStatusFlags)
+ call GetSRAMBank
+ ld a, $80
+ ld [sRTCStatusFlags], a
+ call CloseSRAM
+ ld hl, .text_okay
+ call PrintText
+ ret
+
+.wrongpassword
+ ld hl, .text_wrong
+ call PrintText
+ ret
+
+.text_okay ; 0x4d3fe
+ ; Password OK. Select CONTINUE & reset settings.
+ text_jump UnknownText_0x1c55db
+ db "@"
+
+.text_wrong ; 0x4d403
+ ; Wrong password!
+ text_jump UnknownText_0x1c560b
+ db "@"
+
+.text_askreset ; 0x4d408
+ ; Reset the clock?
+ text_jump UnknownText_0x1c561c
+ db "@"
+
+.NoYes_MenuHeader: ; 0x4d40d
+ db 0 ; flags
+ menu_coords 14, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
+ dw .NoYes_MenuData
+ db 1 ; default option
+
+.NoYes_MenuData: ; 0x4d415
+ db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
+ db 2 ; items
+ db "NO@"
+ db "YES@"
+
+ClockResetPassword: ; 4d41e
+ call .CalculatePassword
+ push de
+ ld hl, wStringBuffer2
+ ld bc, 5
+ xor a
+ call ByteFill
+ ld a, $4
+ ld [wStringBuffer2 + 5], a
+ ld hl, .pleaseenterpasswordtext
+ call PrintText
+.loop
+ call .updateIDdisplay
+.loop2
+ call JoyTextDelay
+ ld a, [hJoyLast]
+ ld b, a
+ and A_BUTTON
+ jr nz, .confirm
+ ld a, b
+ and D_PAD
+ jr z, .loop2
+ call .dpadinput
+ ld c, 3
+ call DelayFrames
+ jr .loop
+
+.confirm
+ call .ConvertDecIDToBytes
+ pop de
+ ld a, e
+ cp l
+ jr nz, .nope
+ ld a, d
+ cp h
+ jr nz, .nope
+ and a
+ ret
+
+.nope
+ scf
+ ret
+
+.pleaseenterpasswordtext ; 0x4d463
+ ; Please enter the password.
+ text_jump UnknownText_0x1c562e
+ db "@"
+
+.updateIDdisplay ; 4d468
+ hlcoord 14, 15
+ ld de, wStringBuffer2
+ ld c, 5
+.loop3
+ ld a, [de]
+ add "0"
+ ld [hli], a
+ inc de
+ dec c
+ jr nz, .loop3
+ hlcoord 14, 16
+ ld bc, 5
+ ld a, " "
+ call ByteFill
+ hlcoord 14, 16
+ ld a, [wStringBuffer2 + 5]
+ ld e, a
+ ld d, $0
+ add hl, de
+ ld [hl], "▲"
+ ret
+
+.dpadinput ; 4d490
+ ld a, b
+ and D_LEFT
+ jr nz, .left
+ ld a, b
+ and D_RIGHT
+ jr nz, .right
+ ld a, b
+ and D_UP
+ jr nz, .up
+ ld a, b
+ and D_DOWN
+ jr nz, .down
+ ret
+
+.left
+ ld a, [wStringBuffer2 + 5]
+ and a
+ ret z
+ dec a
+ ld [wStringBuffer2 + 5], a
+ ret
+
+.right
+ ld a, [wStringBuffer2 + 5]
+ cp $4
+ ret z
+ inc a
+ ld [wStringBuffer2 + 5], a
+ ret
+
+.up
+ call .getcurrentdigit
+ ld a, [hl]
+ cp 9
+ jr z, .wraparound_up
+ inc a
+ ld [hl], a
+ ret
+
+.wraparound_up
+ ld [hl], $0
+ ret
+
+.down
+ call .getcurrentdigit
+ ld a, [hl]
+ and a
+ jr z, .wraparound_down
+ dec a
+ ld [hl], a
+ ret
+
+.wraparound_down
+ ld [hl], 9
+ ret
+
+.getcurrentdigit ; 4d4d5
+ ld a, [wStringBuffer2 + 5]
+ ld e, a
+ ld d, $0
+ ld hl, wStringBuffer2
+ add hl, de
+ ret
+
+.ConvertDecIDToBytes: ; 4d4e0
+ ld hl, 0
+ ld de, wStringBuffer2 + 4
+ ld bc, 1
+ call .ConvertToBytes
+ ld bc, 10
+ call .ConvertToBytes
+ ld bc, 100
+ call .ConvertToBytes
+ ld bc, 1000
+ call .ConvertToBytes
+ ld bc, 10000
+.ConvertToBytes: ; 4d501
+ ld a, [de]
+ dec de
+ push hl
+ ld hl, 0
+ call AddNTimes
+ ld c, l
+ ld b, h
+ pop hl
+ add hl, bc
+ ret
+
+.CalculatePassword: ; 4d50f
+ ld a, BANK(sPlayerData)
+ call GetSRAMBank
+ ld de, 0
+ ld hl, sPlayerData + (wPlayerID - wPlayerData)
+ ld c, $2
+ call .ComponentFromNumber
+ ld hl, sPlayerData + (wPlayerName - wPlayerData)
+ ld c, NAME_LENGTH_JAPANESE - 1
+ call .ComponentFromString
+ ld hl, sPlayerData + (wMoney - wPlayerData)
+ ld c, $3
+ call .ComponentFromNumber
+ call CloseSRAM
+ ret
+
+.ComponentFromNumber: ; 4d533
+ ld a, [hli]
+ add e
+ ld e, a
+ ld a, $0
+ adc d
+ ld d, a
+ dec c
+ jr nz, .ComponentFromNumber
+ ret
+
+.ComponentFromString: ; 4d53e
+ ld a, [hli]
+ cp "@"
+ ret z
+ add e
+ ld e, a
+ ld a, $0
+ adc d
+ ld d, a
+ dec c
+ jr nz, .ComponentFromString
+ ret
--- /dev/null
+++ b/engine/rtc/restart_clock.asm
@@ -1,0 +1,253 @@
+RestartClock_GetWraparoundTime: ; 20000 (8:4000)
+ push hl
+ dec a
+ ld e, a
+ ld d, 0
+ ld hl, .WrapAroundTimes
+rept 4
+ add hl, de
+endr
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ pop hl
+ ret
+; 20015 (8:4015)
+
+.WrapAroundTimes: ; 20015
+ dw wBuffer4
+ db 7, 4
+
+ dw wBuffer5
+ db 24, 12
+
+ dw wBuffer6
+ db 60, 15
+; 20021
+
+RestartClock: ; 20021 (8:4021)
+; If we're here, we had an RTC overflow.
+ ld hl, .Text_ClockTimeMayBeWrong
+ call PrintText
+ ld hl, wOptions
+ ld a, [hl]
+ push af
+ set NO_TEXT_SCROLL, [hl]
+ call LoadStandardMenuHeader
+ call ClearTileMap
+ ld hl, .Text_SetWithControlPad
+ call PrintText
+ call .SetClock
+ call ExitMenu
+ pop bc
+ ld hl, wOptions
+ ld [hl], b
+ ld c, a
+ ret
+; 20047 (8:4047)
+
+.Text_ClockTimeMayBeWrong: ; 0x20047
+ ; The clock's time may be wrong. Please reset the time.
+ text_jump UnknownText_0x1c40e6
+ db "@"
+; 0x2004c
+
+.Text_SetWithControlPad: ; 0x2004c
+ ; Set with the Control Pad. Confirm: A Button Cancel: B Button
+ text_jump UnknownText_0x1c411c
+ db "@"
+; 0x20051
+
+.SetClock: ; 20051 (8:4051)
+ ld a, 1
+ ld [wBuffer1], a ; which digit
+ ld [wBuffer2], a
+ ld a, 8
+ ld [wBuffer3], a
+ call UpdateTime
+ call GetWeekday
+ ld [wBuffer4], a
+ ld a, [hHours]
+ ld [wBuffer5], a
+ ld a, [hMinutes]
+ ld [wBuffer6], a
+
+.loop
+ call .joy_loop
+ jr nc, .loop
+ and a
+ ret nz
+ call .PrintTime
+ ld hl, .Text_IsThisOK
+ call PrintText
+ call YesNoBox
+ jr c, .cancel
+ ld a, [wBuffer4]
+ ld [wStringBuffer2], a
+ ld a, [wBuffer5]
+ ld [wStringBuffer2 + 1], a
+ ld a, [wBuffer6]
+ ld [wStringBuffer2 + 2], a
+ xor a
+ ld [wStringBuffer2 + 3], a
+ call InitTime
+ call .PrintTime
+ ld hl, .Text_ClockReset
+ call PrintText
+ call WaitPressAorB_BlinkCursor
+ xor a
+ ret
+
+.cancel
+ ld a, $1
+ ret
+; 200b0 (8:40b0)
+
+.Text_IsThisOK: ; 0x200b0
+ ; Is this OK?
+ text_jump UnknownText_0x1c415b
+ db "@"
+; 0x200b5
+
+.Text_ClockReset: ; 0x200b5
+ ; The clock has been reset.
+ text_jump UnknownText_0x1c4168
+ db "@"
+; 0x200ba
+
+.joy_loop
+ call JoyTextDelay_ForcehJoyDown
+ ld c, a
+ push af
+ call .PrintTime
+ pop af
+ bit 0, a
+ jr nz, .press_A
+ bit 1, a
+ jr nz, .press_B
+ bit 6, a
+ jr nz, .pressed_up
+ bit 7, a
+ jr nz, .pressed_down
+ bit 5, a
+ jr nz, .pressed_left
+ bit 4, a
+ jr nz, .pressed_right
+ jr .joy_loop
+
+.press_A
+ ld a, $0
+ scf
+ ret
+
+.press_B
+ ld a, $1
+ scf
+ ret
+
+.pressed_up
+ ld a, [wBuffer1]
+ call RestartClock_GetWraparoundTime
+ ld a, [de]
+ inc a
+ ld [de], a
+ cp b
+ jr c, .done_scroll
+ ld a, $0
+ ld [de], a
+ jr .done_scroll
+
+.pressed_down
+ ld a, [wBuffer1]
+ call RestartClock_GetWraparoundTime
+ ld a, [de]
+ dec a
+ ld [de], a
+ cp -1
+ jr nz, .done_scroll
+ ld a, b
+ dec a
+ ld [de], a
+ jr .done_scroll
+
+.pressed_left
+ ld hl, wBuffer1
+ dec [hl]
+ jr nz, .done_scroll
+ ld [hl], $3
+ jr .done_scroll
+
+.pressed_right
+ ld hl, wBuffer1
+ inc [hl]
+ ld a, [hl]
+ cp $4
+ jr c, .done_scroll
+ ld [hl], $1
+
+.done_scroll
+ xor a
+ ret
+
+.PrintTime: ; 2011f (8:411f)
+ hlcoord 0, 5
+ ld b, 5
+ ld c, 18
+ call TextBox
+ decoord 1, 8
+ ld a, [wBuffer4]
+ ld b, a
+ farcall PrintDayOfWeek
+ ld a, [wBuffer5]
+ ld b, a
+ ld a, [wBuffer6]
+ ld c, a
+ decoord 11, 8
+ farcall PrintHoursMins
+ ld a, [wBuffer2]
+ lb de, " ", " "
+ call .PlaceChars
+ ld a, [wBuffer1]
+ lb de, "▲", "▼"
+ call .PlaceChars
+ ld a, [wBuffer1]
+ ld [wBuffer2], a
+ ret
+; 20160 (8:4160)
+
+.unreferenced ; 20160
+; unused
+ ld a, [wBuffer3]
+ ld b, a
+ call Coord2Tile
+ ret
+; 20168
+
+.PlaceChars: ; 20168 (8:4168)
+ push de
+ call RestartClock_GetWraparoundTime
+ ld a, [wBuffer3]
+ dec a
+ ld b, a
+ call Coord2Tile
+ pop de
+ ld [hl], d
+ ld bc, 2 * SCREEN_WIDTH
+ add hl, bc
+ ld [hl], e
+ ret
+; 2017c (8:417c)
+
+UnreferencedString_HourJP: ; 2017c
+; unused
+ db "じ@" ; HR
+; 2017e
+
+UnreferencedString_MinuteJP: ; 2017e
+; unused
+ db "ふん@" ; MIN
+; 20181
--- a/main.asm
+++ b/main.asm
@@ -10,7 +10,7 @@
INCLUDE "engine/overworld/init_map.asm"
INCLUDE "engine/pokemon/learn.asm"
INCLUDE "engine/pokemon/checknickerrors.asm"
-INCLUDE "engine/routines/math.asm"
+INCLUDE "engine/math/math.asm"
INCLUDE "data/items/attributes.asm"
INCLUDE "engine/overworld/npc_movement.asm"
INCLUDE "engine/events/happiness_egg.asm"
@@ -20,8 +20,8 @@
SECTION "bank2", ROMX
INCLUDE "engine/overworld/player_object.asm"
-INCLUDE "engine/routines/sine.asm"
-INCLUDE "engine/routines/predef.asm"
+INCLUDE "engine/math/sine.asm"
+INCLUDE "engine/predef.asm"
INCLUDE "engine/gfx/color.asm"
@@ -29,7 +29,7 @@
INCLUDE "engine/events/checktime.asm"
INCLUDE "engine/events/specials.asm"
-INCLUDE "engine/routines/printnum.asm"
+INCLUDE "engine/math/printnum.asm"
INCLUDE "engine/pokemon/health.asm"
INCLUDE "engine/events/overworld.asm"
INCLUDE "engine/items/items.asm"
@@ -65,7 +65,7 @@
INCLUDE "engine/events/pokerus/apply_pokerus_tick.asm"
INCLUDE "engine/events/bug_contest/contest_2.asm"
INCLUDE "engine/pokemon/correcterrorsinplayerparty.asm"
-INCLUDE "engine/routines/getsquareroot.asm"
+INCLUDE "engine/math/getsquareroot.asm"
SECTION "bank5", ROMX
@@ -95,7 +95,7 @@
SECTION "Clock Reset", ROMX
-INCLUDE "engine/rtc/clock_reset.asm"
+INCLUDE "engine/rtc/restart_clock.asm"
SECTION "bank9", ROMX
@@ -208,7 +208,7 @@
INCLUDE "engine/tilesets/map_palettes.asm"
INCLUDE "gfx/tileset_palette_maps.asm"
INCLUDE "data/collision_permissions.asm"
-INCLUDE "engine/routines/emptyallsrambanks.asm"
+INCLUDE "engine/menus/emptyallsrambanks.asm"
INCLUDE "engine/menus/savemenu_copytilemapatonce.asm"
INCLUDE "engine/events/checksave.asm"
INCLUDE "data/maps/scenes.asm"
@@ -222,9 +222,10 @@
INCBIN "gfx/new_game/shrink2.2bpp.lz"
INCLUDE "engine/link/link_2.asm"
-INCLUDE "engine/rtc/delete_save_change_clock.asm"
+INCLUDE "engine/rtc/reset_password.asm"
+INCLUDE "engine/menus/delete_save.asm"
INCLUDE "data/tilesets.asm"
-INCLUDE "engine/routines/flagpredef.asm"
+INCLUDE "engine/flagpredef.asm"
INCLUDE "engine/gfx/trademonfrontpic.asm"
INCLUDE "engine/events/pokerus/check_pokerus.asm"
INCLUDE "engine/events/lucky_number.asm"
@@ -253,9 +254,9 @@
INCLUDE "engine/events/sacred_ash.asm"
INCLUDE "engine/pokemon/tempmon.asm"
INCLUDE "engine/pokemon/types.asm"
-INCLUDE "engine/routines/unreferenced_getgen1trainerclassname.asm"
+INCLUDE "engine/battle/unreferenced_getgen1trainerclassname.asm"
INCLUDE "engine/pokemon/mon_stats.asm"
-INCLUDE "engine/routines/initlist.asm"
+INCLUDE "engine/link/initlist.asm"
INCLUDE "engine/pokemon/experience.asm"
INCLUDE "engine/pokemon/switchpartymons.asm"
INCLUDE "engine/gfx/load_pics.asm"