-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added f24tof32 and f32tox (issue #29)
- Loading branch information
Zeda
committed
Apr 23, 2021
1 parent
795f8a6
commit f2ab1ec
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef included_f24tof32 | ||
#define included_f24tof32 | ||
#include "pushpop.z80" | ||
|
||
f24tof32: | ||
;convert an "f24" float to an IEEE-754 binary32 | ||
;Input: AHL is the input float. BC points to where the f32 should be written. | ||
;Destroys: None | ||
call pushpop | ||
ex de,hl | ||
ld h,b | ||
ld l,c | ||
; Check for special values | ||
ld c,a ;save for the sign | ||
add a,a | ||
jr z,f24tof32_return_0 | ||
inc a | ||
inc a | ||
jr z,f24tof32_return_infnan | ||
add a,126 | ||
rra | ||
rl c | ||
rra | ||
rr d | ||
rr e | ||
ld (hl),0 | ||
rr (hl) | ||
inc hl | ||
ld (hl),e | ||
inc hl | ||
ld (hl),d | ||
inc hl | ||
ld (hl),a | ||
ret | ||
f24tof32_return_0: | ||
ld (hl),a | ||
inc hl | ||
ld (hl),a | ||
inc hl | ||
ld (hl),a | ||
rra | ||
inc hl | ||
ld (hl),a | ||
ret | ||
f24tof32_return_infnan: | ||
ld a,d | ||
or e | ||
ld (hl),a | ||
inc hl | ||
ld (hl),a | ||
inc hl | ||
or %10000000 | ||
ld (hl),a | ||
inc hl | ||
ld a,c | ||
or %01111111 | ||
ld (hl),a | ||
ret | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#ifndef included_f32tox | ||
#define included_f32tox | ||
#include "pushpop.z80" | ||
|
||
f32tox: | ||
;convert an IEEE-754 binary32 to an extended-precision float. | ||
;Input: HL points to the input float, BC points to where to output | ||
;Destroys: None | ||
call pushpop | ||
ld d,b | ||
ld e,c | ||
xor a | ||
ld (de),a | ||
inc de | ||
ld (de),a | ||
inc de | ||
ld (de),a | ||
inc de | ||
ld (de),a | ||
inc de | ||
ld (de),a | ||
inc de | ||
ldi | ||
ldi | ||
ld a,(hl) | ||
inc hl | ||
ld c,a | ||
or %10000000 | ||
ld (de),a | ||
inc de | ||
ld a,c | ||
add a,a | ||
ld a,(hl) | ||
adc a,a | ||
jr z,f32tox_return_0 | ||
inc a | ||
jr z,f32tox_return_infnan | ||
;A-128+16384 is the exponent | ||
rr c ; save the sign | ||
sub 128 | ||
ld (de),a | ||
inc de | ||
ld a,%10000000 | ||
sbc a,0 | ||
rl c | ||
rra | ||
ld (de),a | ||
ret | ||
|
||
f32tox_return_infnan: | ||
rr c ; save the sign | ||
ex de,hl | ||
dec hl | ||
ld a,(hl) | ||
add a,a | ||
dec hl | ||
or (hl) | ||
dec hl | ||
or (hl) | ||
inc hl | ||
inc hl | ||
sub 1 ; if A was 0 (inf),sets carry, else resets | ||
ld a,$80 | ||
rra | ||
ld (hl),a | ||
xor a | ||
ex de,hl | ||
rl c ; restore the sign | ||
.db 1 ; start of `ld bc,**` to eat the next two bytes | ||
f32tox_return_0: | ||
dec de | ||
ld (de),a | ||
inc de | ||
ld (de),a | ||
inc de | ||
rra | ||
ld (de),a | ||
ret | ||
#endif |