?login_element?

Subversion Repositories NedoOS

Rev

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

  1.  ifndef included_xmod1
  2.  define included_xmod1
  3.  include "../common/pushpop.asm"
  4.  include "../common/mov.asm"
  5.  include "routines/sla64.asm"
  6.  include "routines/normalizexOP1.asm"
  7.  include "constantsx.asm"
  8.  include "xadd.asm"
  9.  
  10.  
  11. ;This routine performs `x mod 1`, returning a non-negative value.
  12. ;+inf -> NaN
  13. ;-inf -> NaN
  14. ;NaN  -> NaN
  15.  
  16. xmod1:
  17.   call pushpop
  18.   push bc
  19.   ld de,xOP1
  20.   call mov10
  21.  
  22. ;Take care of special cases
  23.   ld hl,(xOP1+8)
  24.   ld a,h
  25.   and $7F
  26.   ld h,a
  27.   or l
  28.   jp z,xmod1_special
  29.  
  30. ;If H<0x40, then there is no integer part!
  31.   ld a,h
  32.   sub $40
  33.   jr c,xmod1_end
  34.  
  35. ;if A is non-zero, then this number is too big to have stored an integer part
  36.   jp nz,xmod1_return_0
  37.  
  38. ;If L is >=63, then this number is too big to have stored an integer part
  39.   ld a,l
  40.   cp 63
  41.   jp nc,xmod1_return_0
  42.   inc a
  43. ;Now we need to shift the mantissa up to remove the integer part
  44.   cp 32
  45.   jr c,xmod1less32;+_
  46.   sub 32
  47.   ld hl,(xOP1+2) : ld (xOP1+6),hl
  48.   ld hl,(xOP1) : ld (xOP1+4),hl
  49.   ld hl,0
  50.   ld (xOP1),hl : ld (xOP1+2),hl
  51. xmod1less32;_:
  52.   cp 16
  53.   jr c,xmod1less16;+_
  54.   sub 16
  55.   ld hl,(xOP1+4) : ld (xOP1+6),hl
  56.   ld hl,(xOP1+2) : ld (xOP1+4),hl
  57.   ld hl,(xOP1) : ld (xOP1+2),hl
  58.   ld hl,0
  59.   ld (xOP1),hl
  60. xmod1less16;_:
  61.   cp 8
  62.   jr c,xmod1less8;+_
  63.   ld hl,(xOP1+5) : ld (xOP1+6),hl
  64.   ld hl,(xOP1+3) : ld (xOP1+4),hl
  65.   ld hl,(xOP1+1) : ld (xOP1+2),hl
  66.   ld hl,(xOP1)
  67.   ld l,0
  68.   ld (xOP1),hl
  69. xmod1less8;_:
  70.   and 7
  71.   jr z,xmod1_normalize
  72.   ld b,a
  73. ;_:
  74.   call sla64_xOP1
  75.   djnz $-3;-_
  76. xmod1_normalize:
  77.   ld a,(xOP1+9)
  78.   add a,a
  79.   ld hl,$7FFF
  80.   rr h
  81.   ld (xOP1+8),hl
  82.   call normalizexOP1
  83. xmod1_end:
  84. ;If it is negative, add 1
  85.   ld a,(xOP1+9)
  86.   add a,a
  87.   jr nc,return_xOP1
  88.   ld hl,xOP1
  89.   ld de,xconst_1
  90.   ld b,h
  91.   ld c,l
  92.   call xadd
  93. return_xOP1:
  94.   ld hl,xOP1
  95.   pop de
  96.   jp mov10
  97. xmod1_special:
  98.   ld a,(xOP1+7)
  99.   add a,a
  100.   jr nc,return_xOP1
  101.   ld a,$40
  102.   ld (xOP1+7),a
  103.   jr return_xOP1
  104. xmod1_return_0:
  105.   xor a
  106.   ld h,a
  107.   ld l,a
  108.   ld (xOP1+7),a
  109.   ld (xOP1+8),hl
  110.   jr return_xOP1
  111.  endif
  112.