mirror of
https://github.com/KarolS/millfork.git
synced 2024-12-24 15:29:23 +00:00
77 lines
1.3 KiB
Plaintext
77 lines
1.3 KiB
Plaintext
|
|
#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
|
|
|
|
noinline asm byte __mul_u8u8u8() {
|
|
? 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
|
|
|
|
noinline asm byte __mul_u8u8u8() {
|
|
? 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
|
|
|
|
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
|
|
}
|