?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_xtoTI
  2. #define included_xtoTI
  3. #include "mov.z80"
  4. #include "pushpop.z80"
  5. #include "xtostr.z80"
  6. #include "strtox.z80"
  7.  
  8. #ifdef char_TI_TOK
  9. #define char_NEG  $1A
  10. #define char_ENG  $1B
  11. #define char_DEC  '.'
  12. #else
  13. ;otherwise, char_TI_CHR
  14. #define char_NEG  $B0
  15. #define char_ENG  $3B
  16. #define char_DEC  $3A
  17. #endif
  18. #ifndef strtox_ptr
  19. #define strtox_ptr xOP1+25
  20. #endif
  21.  
  22. #define OP1 8478h
  23. ;NOTE! Doesn't check special cases!
  24. xtoTI:
  25.   call pushpop
  26.   push bc
  27.  
  28. ;Convert the float to a string
  29.   ld bc,xOP1+9
  30.   call xtostr
  31.  
  32. ;Convert the string to a TI-float
  33. ;Check if there is a negative sign.
  34.   pop de
  35.   ld h,b
  36.   ld l,c
  37.   ld a,(hl)
  38.   sub char_NEG
  39.   sub 1
  40.   ld a,0
  41.   jr nc,+_
  42.   rra
  43.   inc hl
  44. _:
  45.   ld (de),a
  46.   push de
  47.   call strtox_sub0
  48.   pop de
  49.   inc de
  50. ;Now we have 10 base-100 digits at xOP1 and BC is our exponent
  51.   ld a,c
  52.   add a,127
  53.   jr nc,+_
  54.   inc b
  55. _:
  56.   dec b
  57.   inc b
  58.   jr nz,xtoTI_inf
  59.  
  60.   ld (de),a
  61.   ld bc,$0700
  62.   ld hl,xOP1+9
  63. _:
  64.   inc de
  65.   push hl
  66.   ld l,(hl)
  67. ;L_To_BCD_no_overflow:
  68.     ld h,c
  69.     add hl,hl
  70.     add hl,hl
  71.     add hl,hl
  72.     add hl,hl
  73.     ld a,h \ daa  \ rl l
  74.     adc a,a \ daa \ rl l
  75.     adc a,a \ daa \ rl l
  76.     adc a,a \ daa \ rl l
  77.     adc a,a \ daa
  78.   ld (de),a
  79.   pop hl
  80.   dec hl
  81.   djnz -_
  82.   ret
  83. xtoTI_inf:
  84.   ex de,hl
  85.   ld hl,OP1+1
  86.   ld (hl),128+99
  87.   ld bc,$0799
  88. _:
  89.   inc hl
  90.   ld (hl),c
  91.   djnz -_
  92.   ret
  93. #endif
  94.