?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_u16tof32
  2. #define included_u16tof32
  3. #include "pushpop.z80"
  4.  
  5. u16tof32:
  6. ;Inputs:
  7. ;   HL holds a 16-bit unsigned integer, (0 to 65535)
  8. ;   BC points to where to write the float
  9. ;Outputs:
  10. ;   Converts HL (unsigned) to an f32 float at BC
  11. ;
  12.   call pushpop
  13.  
  14.   xor a
  15.   ld (bc),a
  16.   inc bc
  17.  
  18.   ld a,l
  19.   or h
  20.   ld d,a
  21.   jr z,u16tof32_finish
  22.  
  23.   ld d,$7F+16 ;Initial exponent
  24.  
  25.   dec d
  26.   add hl,hl
  27.   jr nc,$-2
  28.  
  29.   srl d ; shift the exponent down, shifting in the sign
  30.   rr h  ; shift the lsb of the exponent into the significand
  31.   rr l
  32.  
  33.   ld a,l
  34. u16tof32_finish:
  35.   ld (bc),a
  36.   inc bc
  37.   ld a,h
  38.   ld (bc),a
  39.   inc bc
  40.   ld a,d
  41.   ld (bc),a
  42.   ret
  43. #endif
  44.