Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Output in HL
- ; Destroys A
- ; Preserves everything else (except DE, if result is negative)
- DEMultBC:
- call AbsDE
- ld a,$B7
- jp m,+_ ; Jump if BC was POSITIVE
- xor a,%10000000
- _: call AbsBC
- jp m,+_ ; Jump if DE was POSITIVE
- xor a,%10000000
- _: ld (MultSMC),a
- or a,a \ sbc hl,hl
- dec sp \ push bc \ inc sp \ pop af
- rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- ld a,b
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- ld a,c
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- add hl,hl \ rla \ jr nc,$+3 \ add hl,de
- res 7,a ; make sure the sign does not lie
- push af \ inc sp \ push hl \ inc sp \ pop hl \ inc sp ; A -> HLu -> H -> L
- MultSMC: or a,a
- ret nc
- ex de,hl
- or a,a \ sbc hl,hl
- sbc hl,de
- ret
- ; Output in DE
- DEDivBC: ; Mostly copied from Xeda
- ld a,$B7
- call AbsDE
- jp m,+_
- xor a,%10000000
- _: call AbsBC
- jp m,+_
- xor a,%10000000
- _: ld (DivSMC),a
- dec sp \ push de \ inc sp \ pop af
- or a,a \ sbc hl,hl
- ld l,a ; DEu
- ld a,d
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ cpl \ ld d,a
- ld a,e
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ adc hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ cpl \ ld e,a
- ; HL = remainder
- ; DE = integer result
- ; Let's do a byte shift on DE to make room for the decimal result
- push de \ dec sp \ pop de \ inc sp
- xor a,a
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ add hl,hl \ sbc hl,bc \ jr nc,$+3 \ add hl,bc
- rla \ cpl \ ld e,a
- DivSMC: or a,a
- ret nc
- or a,a \ sbc hl,hl
- ; or a,a ; shouldn't be necessary
- sbc hl,de
- ex de,hl
- ret
- ; Result in DE
- ; S flag is set to opposite of input sign
- AbsDE:
- or a,a
- sbc hl,hl
- sbc hl,de
- ret m ; If ( 0 - DE ) is negative, then DE is positive (so return)
- ex de,hl
- ret
- ; Result in BC
- ; S flag is set to opposite of input sign
- AbsBC:
- or a,a
- sbc hl,hl
- sbc hl,bc
- ret m ; If ( 0 - BC ) is negative, then BC is positive (so return)
- push hl \ pop bc
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement