?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_i8tof24
  2. #define included_i8tof24
  3.  
  4. i8tof24:
  5. ;Inputs:
  6. ;   A holds a 8-bit signed integer, (-128 to 127)
  7. ;Outputs:
  8. ;   Converts to an f24 float in AHL
  9. ;   returns z flag set if zero, nz otherwise :)
  10.  
  11.   or a
  12.   jp p,+_
  13.   neg
  14.   ld b,$BF+8    ;Initial exponent and sign
  15.   .db $11       ;start of instruction `ld de,**`
  16. _:
  17. #ifndef included_u8tof24
  18. #define included_u8tof24
  19. u8tof24:
  20. #else
  21. .echo "Tip: i8tof24 already has a subroutine for u8tof24. Save space by including i8tof24.z80 first"
  22. #endif
  23.   ld b,$3F+8    ;Initial exponent and sign
  24.  
  25. ;Check if A is 0, if so return AHL == 0x00yyyy
  26.   or a
  27.   ret z
  28.  
  29.  
  30. ; shift A left until there is an overflow (the implicit bit)
  31. ; meanwhile, decrement B, the exponent each iteration
  32.   dec b
  33.   add a,a
  34.   jr nc,$-2
  35.   ld h,a
  36.   ld l,0
  37.   ld a,b
  38.   ret
  39. #endif
  40.