diff options
Diffstat (limited to 'home')
-rw-r--r-- | home/math.asm | 47 | ||||
-rwxr-xr-x | home/print_num.asm | 303 | ||||
-rwxr-xr-x | home/print_text.asm | 149 | ||||
-rw-r--r-- | home/text.asm | 2 |
4 files changed, 475 insertions, 26 deletions
diff --git a/home/math.asm b/home/math.asm index ffa3c282..71de08f9 100644 --- a/home/math.asm +++ b/home/math.asm @@ -1,71 +1,68 @@ -SkipNames:: - ld bc, $b +AddNTimes:: +; Add bc * a to hl. and a ret z -.asm_319e +.loop add hl, bc dec a - jr nz, .asm_319e - ret - -AddNTimes:: ; 31a3 (0:31a3) - and a - ret z -.asm_31a5 - add hl, bc - dec a - jr nz, .asm_31a5 + jr nz, .loop ret SimpleMultiply:: +; Return a * c. and a ret z + push bc ld b, a xor a -.asm_31af +.loop add c dec b - jr nz, .asm_31af + jr nz, .loop pop bc ret - -SimpleDivide:: ; 31b5 (0:31b5) - ld b, $0 -.asm_31b7 + +SimpleDivide:: +; Divide a by c. Return quotient b and remainder a. + ld b, 0 +.loop inc b sub c - jr nc, .asm_31b7 + jr nc, .loop dec b add c ret Multiply:: +; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct. +; All values are big endian. push hl push bc - callfar Multiply_ ; 1:67bd + callfar _Multiply pop bc pop hl ret Divide:: +; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient. +; All values are big endian. push hl push de push bc - - homecall Divide_ ; 1:681d - + homecall _Divide pop bc pop de pop hl ret SubtractSigned:: +; Return a - b, sign in carry. sub b ret nc cpl - add $1 + add 1 scf ret diff --git a/home/print_num.asm b/home/print_num.asm new file mode 100755 index 00000000..70f07607 --- /dev/null +++ b/home/print_num.asm @@ -0,0 +1,303 @@ +PrintNum:: +; 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. +; The high nybble of the c register specifies how many of the total amount of +; digits will be in front of the decimal point. +; 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: left-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 + ldh [$ffb5], a + ldh [$ffb6], a + ldh [$ffb7], a + ld a, b + and $f + cp 1 + jr z, .byte + cp 2 + jr z, .word +; maximum 3 bytes +.long + ld a, [de] + ldh [$ffb6], a + inc de + ld a, [de] + ldh [$ffb7], a + inc de + ld a, [de] + ldh [$ffb8], a + jr .start + +.word + ld a, [de] + ldh [$ffb7], a + inc de + ld a, [de] + ldh [$ffb8], a + jr .start + +.byte + ld a, [de] + ldh [$ffb8], 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) + ldh [$ffb9], a + ld a, HIGH(1000000) ; mid + ldh [$ffba], a + ld a, LOW(1000000) + ldh [$ffbb], a + call .PrintDigit + call .AdvancePointer + +.six + ld a, HIGH(100000 >> 8) + ldh [$ffb9], a + ld a, HIGH(100000) ; mid + ldh [$ffba], a + ld a, LOW(100000) + ldh [$ffbb], a + call .PrintDigit + call .AdvancePointer + +.five + xor a ; HIGH(10000 >> 8) + ldh [$ffb9], a + ld a, HIGH(10000) ; mid + ldh [$ffba], a + ld a, LOW(10000) + ldh [$ffbb], a + call .PrintDigit + call .AdvancePointer + +.four + xor a ; HIGH(1000 >> 8) + ldh [$ffb9], a + ld a, HIGH(1000) ; mid + ldh [$ffba], a + ld a, LOW(1000) + ldh [$ffbb], a + call .PrintDigit + call .AdvancePointer + +.three + xor a ; HIGH(100 >> 8) + ldh [$ffb9], a + xor a ; HIGH(100) ; mid + ldh [$ffba], a + ld a, LOW(100) + ldh [$ffbb], a + call .PrintDigit + call .AdvancePointer + +.two + dec e + jr nz, .two_skip + ld a, "0" + ldh [$ffb5], a + +.two_skip + ld c, 0 + ldh a, [$ffb8] + +.mod_10 + cp 10 + jr c, .modded_10 + sub 10 + inc c + jr .mod_10 + +.modded_10 + ld b, a + ldh a, [$ffb5] + 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 + ldh [$ffb5], a + inc e + dec e + jr nz, .money_leading_zero + inc hl + ld [hl], $e8 + +.money_leading_zero + call .AdvancePointer + call .PrintYen + ld a, "0" + add b + ld [hli], a + + pop de + pop bc + ret + +.PrintYen: + push af + ldh a, [$ffb5] + and a + jr nz, .stop + bit 5, d + jr z, .stop + ld a, "¥" + ld [hli], a + res 5, d + +.stop + pop af + ret + +.PrintDigit: + dec e + jr nz, .ok + ld a, "0" + ldh [$ffb5], a +.ok + ld c, 0 +.loop + ldh a, [$ffb9] + ld b, a + ldh a, [$ffb6] + ldh [$ffbc], a + cp b + jr c, .skip1 + sub b + ldh [$ffb6], a + ldh a, [$ffba] + ld b, a + ldh a, [$ffb7] + ldh [$ffbd], a + cp b + jr nc, .skip2 + ldh a, [$ffb6] + or 0 + jr z, .skip3 + dec a + ldh [$ffb6], a + ldh a, [$ffb7] +.skip2 + sub b + ldh [$ffb7], a + ldh a, [$ffbb] + ld b, a + ldh a, [$ffb8] + ldh [$ffbe], a + cp b + jr nc, .skip4 + ldh a, [$ffb7] + and a + jr nz, .skip5 + ldh a, [$ffb6] + and a + jr z, .skip6 + dec a + ldh [$ffb6], a + xor a +.skip5 + dec a + ldh [$ffb7], a + ldh a, [$ffb8] +.skip4 + sub b + ldh [$ffb8], a + inc c + jr .loop +.skip6 + ldh a, [$ffbd] + ldh [$ffb7], a +.skip3 + ldh a, [$ffbc] + ldh [$ffb6], a +.skip1 + ldh a, [$ffb5] + or c + jr z, .PrintLeadingZero + ldh a, [$ffb5] + 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 + ldh [$ffb5], a + inc e + dec e + ret nz + inc hl + ld [hl], $e8 + ret + +.PrintLeadingZero: +; 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: +; 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 + ldh a, [$ffb5] + and a + ret z +.inc + inc hl + ret
\ No newline at end of file diff --git a/home/print_text.asm b/home/print_text.asm new file mode 100755 index 00000000..31cbd744 --- /dev/null +++ b/home/print_text.asm @@ -0,0 +1,149 @@ +PrintLetterDelay:: +; Wait before printing the next letter. + +; The text speed setting in wOptions is actually a frame count: +; fast: 1 frame +; mid: 3 frames +; slow: 5 frames + +; wTextboxFlags[!0] and A or B override text speed with a one-frame delay. +; wOptions[4] and wTextboxFlags[!1] disable the delay. + + ld a, [wOptions] + bit NO_TEXT_SCROLL, a + ret nz + +; non-scrolling text? + ld a, [wTextboxFlags] + bit NO_TEXT_DELAY_F, a + ret z + + push hl + push de + push bc + + ld hl, hOAMUpdate + ld a, [hl] + push af + +; orginally turned oam update off... +; ld a, 1 + ld [hl], a + +; force fast scroll? + ld a, [wTextboxFlags] + bit FAST_TEXT_DELAY_F, a + jr z, .fast + +; text speed + ld a, [wOptions] + and %111 + jr .updatedelay + +.fast + ld a, TEXT_DELAY_FAST + +.updatedelay + ld [wTextDelayFrames], a + +.checkjoypad + call GetJoypad + +; input override + ld a, [wDisableTextAcceleration] + and a + jr nz, .wait + +; Wait one frame if holding A or B. + ldh a, [hJoyDown] + bit A_BUTTON_F, a + jr z, .checkb + jr .delay +.checkb + bit B_BUTTON_F, a + jr z, .wait + +.delay + call DelayFrame + jr .end + +.wait + ld a, [wTextDelayFrames] + and a + jr nz, .checkjoypad + +.end + pop af + ldh [hOAMUpdate], a + pop bc + pop de + pop hl + ret + +CopyDataUntil:: +; Copy [hl .. bc) to de. + +; In other words, the source data is +; from hl up to but not including bc, +; and the destination is de. + + ld a, [hli] + ld [de], a + inc de + ld a, h + cp b + jr nz, CopyDataUntil + ld a, l + cp c + jr nz, CopyDataUntil + ret + +INCLUDE "home/print_num.asm" + +Function33ce:: +; Print c-digit hex number from de to hl +.asm_33ce + push bc + call Function33d7 + pop bc + dec c + jr nz, .asm_33ce + ret + +Function33d7:: ; 33d7 (0:33d7) + ld a, [de] + swap a + and $f + call Function33e9 + ld [hli], a + ld a, [de] + and $f + call Function33e9 + ld [hli], a + inc de + ret + +Function33e9:: ; 33e9 (0:33e9) + ld bc, .digits + add c + ld c, a + ld a, $0 + adc b + ld b, a + ld a, [bc] + ret + +.digits db "0123456789ABCDEF" + +FarPrintText:: + ld [wBuffer], a + ld a, [hROMBank] + push af + ld a, [wBuffer] + rst Bankswitch + + call PrintText + + pop af + rst Bankswitch + ret
\ No newline at end of file diff --git a/home/text.asm b/home/text.asm index a1bc5b08..d1cee382 100644 --- a/home/text.asm +++ b/home/text.asm @@ -247,7 +247,7 @@ endm call Diacritic .place ld [hli], a - call Function31e2 + call PrintLetterDelay jp NextChar print_name: macro |