?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_f24toi16
  2. #define included_f24toi16
  3.  
  4. f24toi16:
  5. ;AHL to a 16-bit signed integer
  6. ;NaN ==> 0
  7. ;+inf ==> 32767
  8. ;-inf ==> -32768
  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.   jr z,f24toi16_return_0
  16.  
  17. ;check if inf or NaN
  18.   cp $FE
  19.   jr nz,+_
  20.   ld a,h
  21.   or l
  22.   jr nz,f24toi16_return_0
  23. f24toi16_return_inf:
  24.   sla c
  25.   ld hl,32767
  26.   ret nc
  27.   inc hl
  28.   ret
  29. _:
  30.  
  31. ;now if exponent is less than 0, just return 0
  32.   cp 63*2
  33.   jr nc,+_
  34. f24toi16_return_0:
  35.   ld hl,0
  36.   ret
  37. _:
  38.  
  39. ;if the exponent is greater than 14, return +- "inf"
  40.   rra
  41.   sub 63
  42.   cp 15
  43.   jr nc,f24toi16_return_inf
  44.  
  45. ;all is good!
  46. ;A is the exponent
  47. ;1+A is the number of bits to read
  48.   or a
  49.   ld b,a
  50.   ld d,0
  51.   ld a,1
  52.   jr z,+_
  53.  
  54.   add hl,hl
  55.   rla
  56.   rl d
  57.   djnz $-4
  58. _:
  59.   sla c
  60.   ld e,a
  61.   ex de,hl
  62.   ret nc
  63.   xor a
  64.   sub l
  65.   ld l,a
  66.   sbc a,a
  67.   sub h
  68.   ld h,a
  69.   ret
  70. #endif
  71.