1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-10-29 14:30:41 +00:00
millfork/include/i80_math.mfk

77 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-09-28 21:45:26 +00:00
#if not(ARCH_I80)
#warn i80_math module should be used only on 8080-like targets
#endif
#pragma zilog_syntax
#if CPUFEATURE_Z80 || CPUFEATURE_GAMEBOY
2018-12-19 00:09:27 +00:00
noinline asm byte __mul_u8u8u8() {
2018-09-28 21:45:26 +00:00
? LD E,A
? LD A, 0
? JR __mul_u8u8u8_start
__mul_u8u8u8_add:
? ADD A,E
__mul_u8u8u8_loop:
? SLA E
__mul_u8u8u8_start:
? SRL D
? JR C, __mul_u8u8u8_add
? JR NZ, __mul_u8u8u8_loop
? RET
}
#else
2018-12-19 00:09:27 +00:00
noinline asm byte __mul_u8u8u8() {
2018-09-28 21:45:26 +00:00
? LD E,A
? LD C, 0
? JP __mul_u8u8u8_start
__mul_u8u8u8_add:
? LD A,C
? ADD A,E
? LD C,A
__mul_u8u8u8_loop:
? LD A,E
? ADD A,A
? LD E,A
__mul_u8u8u8_start:
? OR A
? LD A,D
? RRA
? LD D,A
? JP C, __mul_u8u8u8_add
? OR A
? JP NZ, __mul_u8u8u8_loop
? LD A,C
? RET
}
#endif
2018-12-14 21:50:20 +00:00
inline asm word __mul_u16u8u16() {
? LD HL,0
? LD B,8
__mul_u16u8u16_loop:
? ADD HL,HL
? ADC A,A
#if CPUFEATURE_Z80 || CPUFEATURE_GAMEBOY
? JR NC,__mul_u16u8u16_skip
#else
? JP NC,__mul_u16u8u16_skip
#endif
? ADD HL,DE
__mul_u16u8u16_skip:
#if CPUFEATURE_Z80
? DJNZ __mul_u16u8u16_loop
#elseif CPUFEATURE_GAMEBOY
? DEC B
? JR NZ,__mul_u16u8u16_loop
#else
? DEC B
? JP NZ,__mul_u16u8u16_loop
#endif
? RET
}