?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_i16tof32
  2. #define included_i16tof32
  3. #include "pushpop.z80"
  4.  
  5. i16tof32:
  6. ;Inputs:
  7. ;   HL holds a 16-bit signed integer, (-32768 to 32767)
  8. ;   BC points to where to write the float
  9. ;Outputs:
  10. ;   Converts A 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,i16tof32_finish
  22.  
  23.   ld a,h
  24.   or a
  25.   jp p,$+10
  26.   xor a
  27.   sub l
  28.   ld l,a
  29.   sbc a,a
  30.   sub h
  31.   ld h,a
  32.   scf
  33.  
  34.   rla         ; save the sign
  35.   ld d,$7F+16 ;Initial exponent
  36.  
  37.   dec d
  38.   add hl,hl
  39.   jr nc,$-2
  40.  
  41.   rra   ; shift out the sign
  42.   rr d  ; shift the exponent down, shifting in the sign
  43.   rr h  ; shift the lsb of the exponent into the significand
  44.   rr l
  45.  
  46.   ld a,l
  47. i16tof32_finish:
  48.   ld (bc),a
  49.   inc bc
  50.   ld a,h
  51.   ld (bc),a
  52.   inc bc
  53.   ld a,d
  54.   ld (bc),a
  55.   ret
  56. #endif
  57.