?login_element?

Subversion Repositories NedoOS

Rev

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

  1.  ifndef included_i16tox
  2.  define included_i16tox
  3.  
  4. i16tox:
  5. ; Converts the 16-bit signed integer in HL to an extended precision float at BC
  6. ;so extended-precision routines expect variables left unchanged, we'll pushpop
  7.   call pushpop
  8.   ex de,hl
  9.   ld h,b
  10.   ld l,c
  11.   xor a
  12.   ld b,6
  13. ;_:
  14.   ld (hl),a
  15.   inc hl
  16.   djnz $-2;-_
  17.   or d
  18.   or e
  19.   jr nz,i16toxnz;+_
  20.   ld b,4
  21.   ld (hl),a
  22.   inc hl
  23.   djnz $-2
  24.   ret
  25. i16toxnz;_:
  26.  
  27. ;HL points to where the bottom byte should be written
  28. ;DE is the value to convert
  29.  
  30. ;set up the exponent
  31.   ld bc,$400E
  32.  
  33. ;get the sign
  34.   ld a,d
  35.   sla e
  36.   adc a,a
  37.   jr nc,i16toxnzp;+_
  38.   ld b,$C0    ;it is negative
  39.   ld d,a
  40.   xor a
  41.   sub e
  42.   ld e,a
  43.   sbc a,a
  44.   sub d
  45. i16toxnzp;_:
  46.   jp m,i16tox_norm_done
  47. i16tox_norm_loop:
  48.   dec c
  49.   sla e
  50.   adc a,a
  51.   jp p,i16tox_norm_loop
  52. i16tox_norm_done:
  53.   ld (hl),e
  54.   inc hl
  55.   ld (hl),a
  56.   inc hl
  57.   ld (hl),c
  58.   inc hl
  59.   ld (hl),b
  60.   ret
  61.  endif
  62.