1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-01 05:05:32 +00:00
millfork/include/zp_reg.mfk

107 lines
1.7 KiB
Plaintext
Raw Normal View History

#if not(ARCH_6502)
#warn zp_reg module should be used only on 6502-compatible targets
#endif
2018-12-19 00:09:27 +00:00
noinline asm byte __mul_u8u8u8() {
? LDA #0
2018-06-18 20:40:32 +00:00
? JMP __mul_u8u8u8_start
__mul_u8u8u8_add:
? CLC
2019-06-28 15:57:26 +00:00
? ADC __reg
2018-06-18 20:40:32 +00:00
__mul_u8u8u8_loop:
2019-06-28 15:57:26 +00:00
? ASL __reg
2018-06-18 20:40:32 +00:00
__mul_u8u8u8_start:
2019-06-28 15:57:26 +00:00
? LSR __reg+1
? BCS __mul_u8u8u8_add
? BNE __mul_u8u8u8_loop
? RTS
}
2018-12-14 21:50:20 +00:00
2019-06-05 23:17:34 +00:00
// divide __reg[0]/__reg[1]
noinline asm byte __mod_u8u8u8u8() {
? LDA #0
? LDX #7
? CLC
__divmod_u8u8u8u8_start:
2019-06-28 15:57:26 +00:00
? ROL __reg
2019-06-05 23:17:34 +00:00
? ROL
2019-06-28 15:57:26 +00:00
? CMP __reg+1
2019-06-05 23:17:34 +00:00
? BCC __divmod_u8u8u8u8_skip
2019-06-28 15:57:26 +00:00
? SBC __reg+1
2019-06-05 23:17:34 +00:00
__divmod_u8u8u8u8_skip:
? DEX
? BPL __divmod_u8u8u8u8_start
2019-06-28 15:57:26 +00:00
? ROL __reg
2019-06-05 23:17:34 +00:00
? RTS
}
asm byte __div_u8u8u8u8() {
? JSR __mod_u8u8u8u8
2019-06-28 15:57:26 +00:00
? LDA __reg
2019-06-05 23:17:34 +00:00
? RTS
}
2018-12-14 21:50:20 +00:00
#if ZPREG_SIZE >= 3
2018-12-19 00:09:27 +00:00
noinline asm word __mul_u16u8u16() {
2018-12-14 21:50:20 +00:00
? LDA #0
? TAX
? JMP __mul_u16u8u16_start
__mul_u16u8u16_add:
? CLC
2019-06-28 15:57:26 +00:00
? ADC __reg
2018-12-14 21:50:20 +00:00
? TAY
? TXA
2019-06-28 15:57:26 +00:00
? ADC __reg+1
2018-12-14 21:50:20 +00:00
? TAX
? TYA
__mul_u16u8u16_loop:
2019-06-28 15:57:26 +00:00
? ASL __reg
? ROL __reg+1
2018-12-14 21:50:20 +00:00
__mul_u16u8u16_start:
2019-06-28 15:57:26 +00:00
? LSR __reg+2
2018-12-14 21:50:20 +00:00
? BCS __mul_u16u8u16_add
? BNE __mul_u16u8u16_loop
? RTS
}
2019-06-06 11:06:30 +00:00
// divide (__reg[1]:__reg[0])/__reg[2]
noinline asm byte __mod_u16u8u16u8() {
? LDA #0
? LDX #15
? CLC
__divmod_u16u8u16u8_start:
2019-06-28 15:57:26 +00:00
? ROL __reg
? ROL __reg+1
2019-06-06 11:06:30 +00:00
? ROL
2019-06-28 15:57:26 +00:00
? CMP __reg+2
2019-06-06 11:06:30 +00:00
? BCC __divmod_u16u8u16u8_skip
2019-06-28 15:57:26 +00:00
? SBC __reg+2
2019-06-06 11:06:30 +00:00
__divmod_u16u8u16u8_skip:
? DEX
? BPL __divmod_u16u8u16u8_start
2019-06-28 15:57:26 +00:00
? ROL __reg
? ROL __reg+1
2019-06-06 11:06:30 +00:00
? RTS
}
asm word __div_u16u8u16u8() {
? JSR __mod_u16u8u16u8
2019-06-28 15:57:26 +00:00
? LDA __reg
? LDX __reg+1
2019-06-06 11:06:30 +00:00
? RTS
}
2018-12-14 21:50:20 +00:00
#endif
2019-07-26 22:58:10 +00:00
#if ZPREG_SIZE >= 4
noinline asm word call(word ax) {
JMP ((__reg + 2))
}
#endif