?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef included_f32tof24
  2. #define included_f32tof24
  3.  
  4. f32tof24:
  5. ;convert an IEEE-754 binary32 to this library's "f24" format.
  6. ;Input: HL points to the input float
  7. ;Output: AHL is the f24 float
  8. ;Destroys: DE,BC
  9.  
  10.   ld a,(hl)
  11.   ld c,a
  12.   add a,a
  13.   inc hl
  14.   ld a,(hl)
  15.   rla
  16.   ld e,a
  17.   inc hl
  18.   ld a,(hl)
  19.   rla
  20.   ld d,a
  21. ; DE is the significand of the output
  22.   inc hl
  23.   ld a,(hl)
  24.   adc a,a
  25.   jr z,f32tof24_return_0_noA
  26.   inc a
  27.   jr z,f32tof24_return_infnan
  28.   rr c    ; save the sign
  29.   sub 65
  30.   jr c,f32tof24_return_0
  31.   cp 127
  32.   jr nc,f32tof24_return_inf
  33.   add a,a
  34.   rl c
  35.   rra
  36.   ex de,hl
  37.  
  38. ; round
  39.   bit 6,c
  40.   ret z
  41.   inc l
  42.   ret z
  43.   inc h
  44.   ret z
  45.   inc a
  46.   ret
  47.  
  48. f32tof24_return_infnan:
  49.   dec a
  50.   rra
  51.   ld b,a  ; save exponent/sign
  52.   ld a,c
  53.   or d
  54.   or e
  55.   ld d,a
  56.   ld a,b
  57.   ex de,hl
  58.   ret
  59.  
  60. f32tof24_return_inf:
  61.   ld a,c
  62.   or %01111111
  63.   ld hl,0
  64.   ret
  65.  
  66. f32tof24_return_0:
  67.   xor a
  68.   rl c
  69. f32tof24_return_0_noA:
  70.   ld h,a
  71.   ld l,a
  72.   rra     ; shift the sign back in
  73.   ret
  74. #endif
  75.