summaryrefslogtreecommitdiff
path: root/engine/routines
diff options
context:
space:
mode:
authormid-kid <esteve.varela@gmail.com>2018-03-25 18:24:14 +0200
committermid-kid <esteve.varela@gmail.com>2018-03-25 18:24:14 +0200
commitbe76ee56a89e72c0b87a605321bb1670e86f8220 (patch)
tree277ffa2bc094e74b27ec5b72f748b93e58b3437f /engine/routines
parent0d9241889fc8a2f047b9fd6db25e55de1e721877 (diff)
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.
Diffstat (limited to 'engine/routines')
-rw-r--r--engine/routines/emptyallsrambanks.asm19
-rw-r--r--engine/routines/flagpredef.asm70
-rw-r--r--engine/routines/getsquareroot.asm32
-rw-r--r--engine/routines/initlist.asm54
-rwxr-xr-xengine/routines/math.asm196
-rw-r--r--engine/routines/predef.asm29
-rwxr-xr-xengine/routines/printnum.asm300
-rwxr-xr-xengine/routines/sine.asm4
-rw-r--r--engine/routines/unreferenced_getgen1trainerclassname.asm21
9 files changed, 0 insertions, 725 deletions
diff --git a/engine/routines/emptyallsrambanks.asm b/engine/routines/emptyallsrambanks.asm
deleted file mode 100644
index 8b060f3ef..000000000
--- a/engine/routines/emptyallsrambanks.asm
+++ /dev/null
@@ -1,19 +0,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
diff --git a/engine/routines/flagpredef.asm b/engine/routines/flagpredef.asm
deleted file mode 100644
index 2a6d91ee1..000000000
--- a/engine/routines/flagpredef.asm
+++ /dev/null
@@ -1,70 +0,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
diff --git a/engine/routines/getsquareroot.asm b/engine/routines/getsquareroot.asm
deleted file mode 100644
index 412fd04ff..000000000
--- a/engine/routines/getsquareroot.asm
+++ /dev/null
@@ -1,32 +0,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
diff --git a/engine/routines/initlist.asm b/engine/routines/initlist.asm
deleted file mode 100644
index 26c77b5bb..000000000
--- a/engine/routines/initlist.asm
+++ /dev/null
@@ -1,54 +0,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
diff --git a/engine/routines/math.asm b/engine/routines/math.asm
deleted file mode 100755
index 0cd6b0b47..000000000
--- a/engine/routines/math.asm
+++ /dev/null
@@ -1,196 +0,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
diff --git a/engine/routines/predef.asm b/engine/routines/predef.asm
deleted file mode 100644
index 13c593c90..000000000
--- a/engine/routines/predef.asm
+++ /dev/null
@@ -1,29 +0,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"
diff --git a/engine/routines/printnum.asm b/engine/routines/printnum.asm
deleted file mode 100755
index fec798d5c..000000000
--- a/engine/routines/printnum.asm
+++ /dev/null
@@ -1,300 +0,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
diff --git a/engine/routines/sine.asm b/engine/routines/sine.asm
deleted file mode 100755
index 23e86c015..000000000
--- a/engine/routines/sine.asm
+++ /dev/null
@@ -1,4 +0,0 @@
-_Sine:: ; 84d9
-; a = d * sin(e * pi/32)
- ld a, e
- calc_sine_wave
diff --git a/engine/routines/unreferenced_getgen1trainerclassname.asm b/engine/routines/unreferenced_getgen1trainerclassname.asm
deleted file mode 100644
index da8e98b61..000000000
--- a/engine/routines/unreferenced_getgen1trainerclassname.asm
+++ /dev/null
@@ -1,21 +0,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"