Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f8p16_abs_inv:
- ;| 1.0/(ix+6) | ==> HL (8.16 fixed-point)
- ;only computes 8 bits of fractional precision
- ;overflow ==> 0x7FFFFF
- ;underflow ==> 0x000000
- ;get the denominator in DE
- ld de,(ix+6)
- ;make sure DE is negative
- ;Also, using ix+6 as scrap, so set that to 0
- xor a
- sbc hl,hl
- ld (ix+6),hl
- sbc hl,de
- jp p,f8p16_abs_inv_DE_negated
- ex de,hl
- f8p16_abs_inv_DE_negated:
- ;if 1.0>DE, then output is less than 1.0
- ;if 1.0<DE, then output is greater than 1.0
- ;if 1.0=DE, then output is 1.0
- ld hl,65535
- adc hl,de
- ;suppose input <= 1. Then carry is set
- ;suppose input > 1. Then carry reset
- jr c,f8p16_abs_inv_big
- f8p16_abs_inv_small:
- ;DE>1.0
- sbc hl,de
- ;HL is 1.0
- ;so we know the top 8 bits of the result are 0
- jr f8p16_abs_inv_frac
- f8p16_abs_inv_big:
- ;so input <= 1.0
- jr z,return_1p00
- ;so input < 1.0
- ld hl,256 ;numerator
- call f8p16_abs_inv_sub
- or a
- jp m,f8p16_abs_inv_overflow
- ld (ix+8),a
- f8p16_abs_inv_frac:
- call f8p16_abs_inv_sub
- ;want to round
- add hl,hl
- add hl,de
- ld hl,(ix+6)
- ld h,a
- ret nc
- ld de,255
- adc hl,de
- ret p
- f8p16_abs_inv_overflow:
- ld hl,$7FFFFF
- ret
- return_1p00:
- ld hl,$010000
- ret
- f8p16_abs_inv_sub:
- ld b,8
- f8p16_abs_inv_sub_loop:
- add hl,hl
- add hl,de
- jr c,$+4
- sbc hl,de
- rla
- djnz f8p16_abs_inv_sub_loop
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement