?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #ifndef included_f32tosingle
  2. #define included_f32tosingle
  3. #include "pushpop.z80"
  4.  
  5. f32tosingle:
  6. ;convert an IEEE-754 binary32 to this library's "single" format.
  7. ;HL points to the input, BC is where to output
  8.   call pushpop
  9.  
  10. ;no matter what, the bottom 16 bits can be the same
  11.   ld d,b
  12.   ld e,c
  13.   ld a,(hl)
  14.   ldi
  15.   or (hl)
  16.   ldi
  17.   ld c,a    ;the OR of the bottom two bytes. Needed for NaN vs. Inf
  18.   ld a,(hl)
  19.   inc hl
  20.   ld h,(hl)
  21.  
  22. ;first, check for special values
  23.   add a,a
  24.   ld l,a
  25.   ld a,h
  26.   adc a,a
  27.   jr z,f32tosingle_return_0
  28.   inc a
  29.   jr z,f32tosingle_inf_NaN
  30. ;carry is the new sign
  31.   rr l
  32.  
  33. ;AL needs to be written to DE
  34.   ex de,hl
  35.   ld (hl),e
  36.   inc hl
  37.   ld (hl),a
  38.   ret
  39.  
  40. f32tosingle_inf_NaN:
  41. ;if C is 0 and L is 0, then it is inf, else NaN
  42.   rr h
  43.   cp c
  44.   jr nz,+_
  45.   cp l
  46.   jr nz,+_
  47. ;  add a,$40
  48.   .db $F6     ;\  this branch becomes:
  49. _:            ; |    or $C6   ;set's bit 7, which is what we want
  50.   add a,$40   ;/     ld b,b   ;might cause issues on eZ80
  51.   sla h
  52.  
  53. f32tosingle_return_0:
  54.   rra
  55.   ld (de),a
  56.   inc de
  57.   xor a
  58.   ld (de),a
  59.   ret
  60.  
  61.  
  62. #endif
  63.