?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_u8tof32
  2. #define included_u8tof32
  3.  
  4. u8tof32:
  5. ;Inputs:
  6. ;   A holds a 8-bit unsigned integer, (0 to 255)
  7. ;   BC points to where to write the float
  8. ;Outputs:
  9. ;   Converts A to an f32 float at BC
  10. ;
  11.   push hl
  12.   push af
  13.  
  14.   ; Begin writing the float
  15.   ld h,b
  16.   ld l,c
  17.   ld (hl),0
  18.   inc hl
  19.   ld (hl),0
  20.   inc hl
  21.  
  22.   or a
  23.   jr nz,$+8
  24.   ld (hl),a
  25.   inc hl
  26.   ld (hl),a
  27.   pop af
  28.   pop hl
  29.   ret
  30.  
  31.   push bc
  32.   rl c        ; save the sign
  33.   ld b,$7F+8  ;Initial exponent
  34.  
  35.   dec b
  36.   add a,a
  37.   jr nc,$-2
  38.  
  39.   rr c  ; shift in a 1 and shift out the sign
  40.   rr b  ; shift the exponent down, shifting in the sign
  41.   rra   ; shift the lsb of the exponent into the significand
  42.   ld (hl),a
  43.   inc hl
  44.   ld (hl),b
  45.  
  46.   pop bc
  47.   pop af
  48.   pop hl
  49.   ret
  50. #endif
  51.