mirror of
https://github.com/KarolS/millfork.git
synced 2024-11-01 05:05:32 +00:00
110 lines
1.9 KiB
Plaintext
110 lines
1.9 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
|
|
|
|
noinline asm void __divmod_u16u8u16u8() {
|
|
? XOR A
|
|
? LD B, 16
|
|
__divmod_u16u8u16u8_loop:
|
|
? ADD HL,HL
|
|
? RLA
|
|
#if CPUFEATURE_Z80 || CPUFEATURE_GAMEBOY
|
|
? JR C, __divmod_u16u8u16u8_overflow
|
|
#else
|
|
? JP C, __divmod_u16u8u16u8_overflow
|
|
#endif
|
|
? CP D
|
|
#if CPUFEATURE_Z80 || CPUFEATURE_GAMEBOY
|
|
? JR C, __divmod_u16u8u16u8_skip
|
|
#else
|
|
? JP C, __divmod_u16u8u16u8_skip
|
|
#endif
|
|
__divmod_u16u8u16u8_overflow:
|
|
? SUB D
|
|
? INC L
|
|
__divmod_u16u8u16u8_skip:
|
|
#if CPUFEATURE_Z80
|
|
? DJNZ __divmod_u16u8u16u8_loop
|
|
#elseif CPUFEATURE_GAMEBOY
|
|
? DEC B
|
|
? JR NZ, __divmod_u16u8u16u8_loop
|
|
#else
|
|
? DEC B
|
|
? JP NZ, __divmod_u16u8u16u8_loop
|
|
#endif
|
|
? RET
|
|
}
|
|
|
|
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
|
|
}
|