?login_element?

Subversion Repositories NedoOS

Rev

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

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