?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_f24tou8
  2. #define included_f24tou8
  3.  
  4. f24tou8:
  5. ;AHL to an 8-bit unsigned integer
  6. ;NaN ==> 0
  7. ;too big ==> 255 (even if neg)
  8. ;negative values in range are mod 256
  9.  
  10. ;save the sign
  11.   ld c,a
  12.  
  13. ;Check if the input is 0
  14.   add a,a
  15.   ret z
  16.  
  17.  
  18. ;check if inf or NaN
  19.   cp $FE
  20.   jr nz,+_
  21.   ld a,h
  22.   or l
  23.   jr nz,f24tou8_return_0
  24. f24tou8_return_inf:
  25.   ld a,255
  26.   ret
  27. _:
  28.  
  29. ;now if exponent is less than 0, just return 0
  30.   cp 63*2
  31.   jr nc,+_
  32. f24tou8_return_0:
  33.   xor a
  34.   ret
  35. _:
  36.  
  37. ;if the exponent is greater than 7, return 255
  38.   rra
  39.   sub 63
  40.   cp 8
  41.   jr nc,f24tou8_return_inf
  42.  
  43. ;all is good!
  44. ;A is the exponent
  45. ;1+A is the number of bits to read
  46.   ld b,a
  47.   or a
  48.   ld a,1
  49.   jr z,+_
  50.  
  51.   add hl,hl
  52.   rla
  53.   djnz $-2
  54. _:
  55.   sla c
  56.   ret nc
  57.   neg
  58.   ret
  59.  
  60. #endif
  61.