?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_f16toi16
  2. #define included_f16toi16
  3.  
  4. f16toi16:
  5.   ld a,h
  6.   and %01111100
  7.   jr z,f16toi16_zero
  8.   rra
  9.   rra
  10. ;A is the exponent + 15
  11.   sub 15
  12.   jr c,f16toi16_zero
  13.   cp 15
  14.   jr nc,f16toi16_inf
  15.   ld b,a
  16.  
  17. ;save the sign
  18.   ld d,h
  19.  
  20. ;set HL as the significand
  21.   ld a,h
  22.   and 3
  23.   or 4
  24.   ld h,a
  25.  
  26.   call f16toi16_sub
  27.  
  28.   sla d
  29.   ret nc
  30.   xor a
  31.   sub l
  32.   ld l,a
  33.   sbc a,a
  34.   sub h
  35.   ld h,a
  36.   ret
  37.  
  38. f16toi16_sub:
  39. ;if B is 10, can basicaly return HL
  40.   ld a,b
  41.   sub 10
  42.   ret z
  43.   jr nc,f16toi16_shiftleft
  44. ;HL needs to be shifted right
  45.   srl h
  46.   rr l
  47.   dec a
  48.   ret z
  49.   srl h
  50.   rr l
  51.   dec a
  52.   ret z
  53.   srl h
  54.   ld b,a
  55.   ld a,l
  56. f16toi16_loop:
  57.   rra
  58.   or a
  59.   djnz f16toi16_loop
  60.   ld l,a
  61.   ret
  62.  
  63. f16toi16_shiftleft:
  64.   add hl,hl
  65.   djnz f16toi16_shiftleft
  66.   ret
  67.  
  68. f16toi16_inf:
  69.   sla h
  70.   ld hl,$7FFF
  71.   ret nc
  72.   inc hl
  73.   ret
  74.  
  75. f16toi16_zero:
  76.   ld hl,0
  77.   ret
  78.  
  79. #endif
  80.