2020/c64/math.inc
2020-12-09 03:17:54 +01:00

94 lines
1.3 KiB
PHP

// vim: filetype=kickass
.macro i8_div5_a() {
sta zp_temp
lsr
adc #13
adc zp_temp
ror
lsr
lsr
adc zp_temp
ror
adc zp_temp
ror
lsr
lsr
}
.macro i16_div8(lo, hi) {
lsr cursor_pointer_hi
ror cursor_pointer_lo
lsr cursor_pointer_hi
ror cursor_pointer_lo
lsr cursor_pointer_hi
ror cursor_pointer_lo
}
.macro i8_mul5_a() {
sta zp_temp
asl
asl
clc
adc zp_temp
}
// Destroys: lo, hi
.macro i16_mul2(lo, hi) {
asl lo
rol hi
}
// Destroys: lo, hi
.macro i16_mul4(lo, hi) {
i16_mul2(lo, hi)
i16_mul2(lo, hi)
}
// Destroys: lo, hi
.macro i16_mul8(lo, hi) {
i16_mul4(lo, hi)
i16_mul2(lo, hi)
}
// Destroys: a, lo, hi, $fd, $fe
.macro i16_mul10(lo, hi) {
i16_mul2(lo, hi)
lda lo
sta $fd
lda hi
sta $fe
i16_mul4(lo, hi)
i16_i16_add(lo, hi, $fd, $fe)
}
// Destroys: a, dst_lo, dst_hi
.macro i16_i8_add_a(dst_lo, dst_hi) {
clc
adc dst_lo
sta dst_lo
bcc !cc+
inc dst_hi
!cc:
}
// Destroys: a, dst_lo, dst_hi
.macro i16_i16_add(dst_lo, dst_hi, src_lo, src_hi) {
clc
lda dst_lo
adc src_lo
sta dst_lo
lda dst_hi
adc src_hi
sta dst_hi
}
// Destroys: a, dst_lo, dst_hi
.macro i16_inc(lo, hi) {
lda #1
i16_i8_add_a(lo, hi)
}