?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_f24tou16
  2. #define included_f24tou16
  3.  
  4. f24tou16:
  5. ;AHL to a 16-bit unsigned integer
  6. ;NaN ==> 0
  7. ;too big ==> 65535 (even if neg)
  8. ;negative values in range are mod 65536
  9.  
  10. ;save the sign
  11.   ld c,a
  12.  
  13. ;Check if the input is 0
  14.   add a,a
  15.   jr z,f24tou16_return_0
  16.  
  17.  
  18. ;check if inf or NaN
  19.   cp $FE
  20.   jr nz,+_
  21.   ld a,h
  22.   or l
  23.   jr nz,f24tou16_return_0
  24. f24tou16_return_inf:
  25.   ld hl,-1
  26.   ret
  27. _:
  28.  
  29. ;now if exponent is less than 0, just return 0
  30.   cp 63*2
  31.   jr nc,+_
  32. f24tou16_return_0:
  33.   ld hl,0
  34.   ret
  35. _:
  36.  
  37. ;if the exponent is greater than 15, return 255
  38.   rra
  39.   sub 63
  40.   cp 16
  41.   jr nc,f24tou16_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.   ld d,0
  50.   jr z,+_
  51.  
  52.   add hl,hl
  53.   rla
  54.   rl d
  55.   djnz $-4
  56. _:
  57.   sla c
  58.   ld e,a
  59.   ex de,hl
  60.   ret nc
  61.   xor a
  62.   sub l
  63.   ld l,a
  64.   sbc a,a
  65.   sub h
  66.   ld h,a
  67.   ret
  68.  
  69. #endif
  70.