From d3cc861d334c8b773c1b6c662ed9924c43cef009 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Wed, 4 Apr 2018 22:26:07 +0200 Subject: Fix snake_case filenames Renamed a bunch of files, most of them one-off functions, to better fit the general snake_case naming scheme. Also renamed some awfully long filenames. --- engine/math/get_square_root.asm | 32 +++++ engine/math/getsquareroot.asm | 32 ----- engine/math/print_num.asm | 300 ++++++++++++++++++++++++++++++++++++++++ engine/math/printnum.asm | 300 ---------------------------------------- 4 files changed, 332 insertions(+), 332 deletions(-) create mode 100644 engine/math/get_square_root.asm delete mode 100644 engine/math/getsquareroot.asm create mode 100644 engine/math/print_num.asm delete mode 100644 engine/math/printnum.asm (limited to 'engine/math') diff --git a/engine/math/get_square_root.asm b/engine/math/get_square_root.asm new file mode 100644 index 000000000..412fd04ff --- /dev/null +++ b/engine/math/get_square_root.asm @@ -0,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 diff --git a/engine/math/getsquareroot.asm b/engine/math/getsquareroot.asm deleted file mode 100644 index 412fd04ff..000000000 --- a/engine/math/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/math/print_num.asm b/engine/math/print_num.asm new file mode 100644 index 000000000..fec798d5c --- /dev/null +++ b/engine/math/print_num.asm @@ -0,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], "" + +.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], "" + 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/math/printnum.asm b/engine/math/printnum.asm deleted file mode 100644 index fec798d5c..000000000 --- a/engine/math/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], "" - -.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], "" - 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 -- cgit v1.2.3