?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_i16tof24
  2. #define included_i16tof24
  3.  
  4. i16tof24:
  5. ;Inputs:
  6. ;   HL holds a 16-bit signed integer, (-32768 to 32767)
  7. ;Outputs:
  8. ;   Converts to an f24 float in AHL
  9. ;   returns z flag set if zero, nz otherwise :)
  10.  
  11.   bit 7,h
  12.   jr z,i16tof24_pos
  13.   xor a
  14.   sub l
  15.   ld l,a
  16.   sbc a,a
  17.   sub h
  18.   ld h,a
  19.   ld b,$BF+16
  20.   .db $11     ;start of `ld de,**`, eats the next two bytes
  21. #ifndef included_u16tof24
  22. #define included_u16tof24
  23. u16tof24:
  24. #else
  25. .echo "Tip: i16tof24 already has a subroutine for u16tof24. Save space by including i16tof24.z80 first"
  26. #endif
  27. i16tof24_pos:
  28.   ld b,$3F+16    ;Initial exponent and sign
  29.  
  30. ;Check if HL is 0, if so return AHL == 0x000000
  31.   ld a,h
  32.   or l
  33.   ret z
  34.  
  35. ; HL is non-zero
  36. ; shift HL left until there is an overflow (the implicit bit)
  37. ; meanwhile, decrement B, the exponent each iteration
  38.   dec b
  39.   add hl,hl
  40.   jr nc,$-2
  41.   ld a,b
  42.   ret
  43. #endif
  44.