?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_i8tof32
  2. #define included_i8tof32
  3.  
  4. i8tof32:
  5. ;Inputs:
  6. ;   A holds a 8-bit signed integer, (-128 to 127)
  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.   or a
  15.   jp p,$+6
  16.   neg
  17.   scf
  18.  
  19. ; #ifndef included_u8tof32
  20. ; ##define included_u8tof32
  21. ;   .db $21   ; start of `ld hl,*` to skip the next byte
  22. ; u8tof32:
  23. ;   push hl
  24. ;   push af
  25. ; #else
  26. ; .echo "Hint: it looks like you are using u8tof32 as well as i8tof32. i8tof32 already has code for u8tof32, so you can save bytes by including it first."
  27. ; #endif
  28. ;
  29.   ; Begin writing the float
  30.   ld h,b
  31.   ld l,c
  32.   ld (hl),0
  33.   inc hl
  34.   ld (hl),0
  35.   inc hl
  36.  
  37.   jr nz,$+8
  38.   ld (hl),a
  39.   inc hl
  40.   ld (hl),a
  41.   pop af
  42.   pop hl
  43.   ret
  44.  
  45.   push bc
  46.   rl c        ; save the sign
  47.   ld b,$7F+8  ;Initial exponent
  48.  
  49.   dec b
  50.   add a,a
  51.   jr nc,$-2
  52.  
  53.   rr c  ; shift in a 1 and shift out the sign
  54.   rr b  ; shift the exponent down, shifting in the sign
  55.   rra   ; shift the lsb of the exponent into the significand
  56.   ld (hl),a
  57.   inc hl
  58.   ld (hl),b
  59.  
  60.   pop bc
  61.   pop af
  62.   pop hl
  63.   ret
  64. #endif
  65.