?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_f32tox
  2. #define included_f32tox
  3. #include "pushpop.z80"
  4.  
  5. f32tox:
  6. ;convert an IEEE-754 binary32 to an extended-precision float.
  7. ;Input: HL points to the input float, BC points to where to output
  8. ;Destroys: None
  9.   call pushpop
  10.   ld d,b
  11.   ld e,c
  12.   xor a
  13.   ld (de),a
  14.   inc de
  15.   ld (de),a
  16.   inc de
  17.   ld (de),a
  18.   inc de
  19.   ld (de),a
  20.   inc de
  21.   ld (de),a
  22.   inc de
  23.   ldi
  24.   ldi
  25.   ld a,(hl)
  26.   inc hl
  27.   ld c,a
  28.   or %10000000
  29.   ld (de),a
  30.   inc de
  31.   ld a,c
  32.   add a,a
  33.   ld a,(hl)
  34.   adc a,a
  35.   jr z,f32tox_return_0
  36.   inc a
  37.   jr z,f32tox_return_infnan
  38. ;A-128+16384 is the exponent
  39.   rr c    ; save the sign
  40.   sub 128
  41.   ld (de),a
  42.   inc de
  43.   ld a,%10000000
  44.   sbc a,0
  45.   rl c
  46.   rra
  47.   ld (de),a
  48.   ret
  49.  
  50. f32tox_return_infnan:
  51.   rr c  ; save the sign
  52.   ex de,hl
  53.   dec hl
  54.   ld a,(hl)
  55.   add a,a
  56.   dec hl
  57.   or (hl)
  58.   dec hl
  59.   or (hl)
  60.   inc hl
  61.   inc hl
  62.   sub 1   ; if A was 0 (inf),sets carry, else resets
  63.   ld a,$80
  64.   rra
  65.   ld (hl),a
  66.   xor a
  67.   ex de,hl
  68.   rl c  ; restore the sign
  69.   .db 1 ; start of `ld bc,**` to eat the next two bytes
  70. f32tox_return_0:
  71.   dec de
  72.   ld (de),a
  73.   inc de
  74.   ld (de),a
  75.   inc de
  76.   rra
  77.   ld (de),a
  78.   ret
  79. #endif
  80.