?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_xtof32
  2. #define included_xtof32
  3. #include "pushpop.z80"
  4.  
  5. xtof32:
  6. ;Inputs:
  7. ;   HL points to the input extended-precision float
  8. ;   BC points to where to output the result
  9. ;Outputs:
  10. ;   The extended-precision float is converted to an f32 at BC.
  11. ;Destroys:
  12. ;   None
  13. ;
  14.  
  15.   call pushpop
  16. xtof32_nopush:
  17. ; We don't need the first 5 bytes
  18.   inc hl
  19.   inc hl
  20.   inc hl
  21.   inc hl
  22.   inc hl
  23.   ld d,b
  24.   ld e,c
  25.   ldi
  26.   ldi
  27.   ld c,(hl)
  28.   inc hl
  29.   ld b,(hl)
  30.   inc hl
  31.   ld a,(hl)
  32. ;AB is the exponent and sign
  33.   add a,a
  34.   or b
  35.   jr z,xtof32_special
  36.   ld a,c
  37.   ld (de),a
  38.   inc de
  39.   ld c,(hl)
  40.   res 7,c
  41.  
  42.   ld a,b
  43.   sub 129
  44.   ld (de),a
  45.   ld a,c
  46.   sbc a,63
  47.   jr c,xtof32_zero
  48.   jr nz,xtof32_inf
  49.   ld a,(de)
  50.   inc a
  51.   jr z,xtof32_inf
  52.   ld a,(hl)
  53.   add a,a ; get the sign
  54.   ld a,(de)
  55.   rra
  56.   ld (de),a
  57.   dec de
  58.   ld a,(de)
  59.   rla
  60.   rrca
  61.   ld (de),a
  62.   ret
  63.  
  64. xtof32_zero:
  65.   xor a
  66.   ld (de),a
  67.   dec de
  68.   ld (de),a
  69.   ret
  70. xtof32_inf:
  71.   ex de,hl
  72.   ld a,(de)
  73.   or %01111111
  74.   ld (hl),a
  75.   dec hl
  76.   ld (hl),%10000000
  77.   dec hl
  78.   ld (hl),0
  79.   dec hl
  80.   ld (hl),0
  81.   ret
  82.  
  83. xtof32_special:
  84.   inc de
  85.   ld a,c
  86.   add a,a
  87.   jr c,xtof32_inf
  88.   jp p,xtof32_zero
  89. xtof32_nan:
  90. ;significand needs to be non-zero to encode NaN
  91.   ld a,(hl)
  92.   or %01111111
  93.   ld (de),a
  94.   add a,a
  95.   dec de
  96.   ld (de),a
  97.   ret
  98. #endif
  99.