?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_f32tou8
  2. #define included_f32tou8
  3.  
  4. f32tou8:
  5. ;Inputs: HL points to an f32 float
  6. ;Outputs: A is the unsigned 8-bit integer part of the input (rounded down)
  7. ;Special cases:
  8. ;   NaN              ==> 0
  9. ;   greater than 255 ==> 255
  10. ;   less than 0      ==> 0
  11.  
  12.   push hl
  13.   push de
  14.   push bc
  15.   ld e,(hl)
  16.   inc hl
  17.   ld d,(hl)
  18.   inc hl
  19.   ld a,(hl)
  20.   rlca
  21.   scf
  22.   rra
  23.   ld c,a
  24.   inc hl
  25.   ld a,(hl)
  26.   adc a,a
  27.   ccf
  28.   jr nc,f32tou8_return_carry
  29.   or a
  30.   jr z,f32tou8_return_carry
  31.   inc a
  32.   jr z,f32tou8_infnan
  33.  
  34.   add a,256-135
  35.   jr c,f32tou8_return_carry
  36.   add a,7
  37.   jr nc,f32tou8_return_carry
  38.  
  39.   ld b,a
  40.   inc b
  41.   xor a
  42.   rl c
  43.   rla
  44.   djnz $-3
  45.  
  46.   .db $FE
  47. f32tou8_return_carry:
  48.   sbc a,a
  49. f32tou8_return:
  50.   pop bc
  51.   pop de
  52.   pop hl
  53.   ret
  54.  
  55. f32tou8_infnan:
  56.   ld a,c
  57.   add a,a
  58.   or d
  59.   or e
  60.   sub 1
  61.   jr f32tou8_return_carry
  62. #endif
  63.