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