?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_f16tof32
  2. #define included_f16tof32
  3. #include "pushpop.z80"
  4.  
  5. f16tof32:
  6. ;Inputs:
  7. ;   HL is the f16 input
  8. ;   BC is where to write the f32 float
  9. ;Destroys:
  10. ;   none
  11.   call pushpop
  12. ;check for inf or NaN
  13.   ld a,h
  14.   and %01111100
  15.   jr z,f16tof32_zero
  16.   cp %01111100
  17.   jr z,f16tof32_inf_nan
  18. ;it is not a special value
  19.  
  20.   ; we need to shift in the sign and exponent from HL
  21.   ; We need to make roomfor 3 more bits of exponent, and we need to subtract 15
  22.   ; for the original bias, and add 127 for the new bias, for a net of +112
  23.   ; We'll init A to this so that the RLA instructions will pre-add
  24.   ld a,%01100000
  25.   add hl,hl
  26.   rla               ;A = 1100000s
  27.   rla               ;A = 100000s0
  28.   rla               ;A = 00000s00 + 1
  29.   rla               ;A = 0000s000 + 3
  30.   add hl,hl
  31.   rla               ;A = 000s000e + 6
  32.   inc a             ;A = 000s000e + 7
  33.   add hl,hl
  34.   rla               ;A = 00s000ee + 14
  35.   add hl,hl
  36.   rla               ;A = 0s000eee + 28
  37.   add hl,hl
  38.   rla               ;A = s000eeee + 56
  39.  
  40.   ex de,hl
  41.   ld h,b
  42.   ld l,c
  43.   ld (hl),0
  44.   inc hl
  45.   ld (hl),e
  46.   inc hl
  47.   ld (hl),d
  48.   inc hl
  49.   ld (hl),a
  50.   ret
  51.  
  52.  
  53. f16tof32_zero:
  54.   ld (bc),a
  55.   inc bc
  56.   ld (bc),a
  57.   inc bc
  58.   ld (bc),a
  59.   inc bc
  60.   ld a,h
  61.   and %10000000
  62.   ld (bc),a
  63.   ret
  64.  
  65. f16tof32_inf_NaN:
  66.   ld a,h
  67.   and %00000011
  68.   or l
  69.   ld (bc),a
  70.   inc bc
  71.   ld (bc),a
  72.   inc bc
  73.   or %10000000
  74.   ld (bc),a
  75.   inc bc
  76.   ld a,h
  77.   or %01111111
  78.   ld (bc),a
  79.   ret
  80.  
  81. #endif
  82.