forked from rileym65/Basic-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcprint.c
More file actions
162 lines (159 loc) · 5.86 KB
/
Copy pathcprint.c
File metadata and controls
162 lines (159 loc) · 5.86 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
*******************************************************************
*** This software is copyright 2021 by Michael H Riley ***
*** You have permission to use, modify, copy, and distribute ***
*** this software so long as this copyright notice is retained. ***
*** This software may not be used in commercial applications ***
*** without express written permission from the author. ***
*******************************************************************
*/
#include "header.h"
char* cprint(char* line) {
char qt;
char last;
line = trim(line);
if (lblF_inmsg == 0xffff) {
qt = 0;
while (*line != 0 && ((qt == 1) || (qt == 0 && *line != ':'))) {
if (*line == '"') qt = 1-qt;
line++;
}
return line;
}
last = ' ';
while (*line != ':' && *line != 0) {
line=trim(line);
if (*line == '"') {
Asm(" sep scall ; Display message");
Asm(" dw f_inmsg");
strcpy(buffer," db '");
line++;
while (*line != '"' && *line != 0) {
if (*line == '\'') {
strcat(buffer,"',39,'");
line++;
}
else {
buffer[strlen(buffer)+1] = 0;
buffer[strlen(buffer)] = *line++;
}
}
strcat(buffer,"',0"); Asm(buffer);
if (*line == '"') line++;
last = ' ';
}
else if (*line == ',') {
Asm(" ldi 9 ; Display a tab character");
Asm(" sep scall ; Display cr/lf");
Asm(" dw f_type");
line++;
last = ',';
}
else if (*line == ';') {
line++;
last = ';';
}
else {
line = cexpr(line, 2);
if (useFp) {
if (tokens[1] == OP_NUM) {
Asm(" inc r7 ; Point to expression result");
Asm(" glo r7");
Asm(" plo rf");
Asm(" ghi r7");
Asm(" phi rf");
Asm(" ldi iobuffer.1 ; Point to i/o buffer");
Asm(" phi rd");
Asm(" ldi iobuffer.0");
Asm(" plo rd");
Asm(" sep scall ; Display integer value");
Asm(" dw itoa32");
Asm(" ldi iobuffer.1 ; Display result");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
Asm(" sep scall");
Asm(" dw f_msg");
Asm(" inc r7 ; Remove expression result");
Asm(" inc r7");
Asm(" inc r7");
}
else if (tokens[1] == OP_NUMFP) {
Asm(" inc r7 ; Point to expression result");
Asm(" glo r7");
Asm(" plo rf");
Asm(" ghi r7");
Asm(" phi rf");
Asm(" ldi iobuffer.1 ; Point to i/o buffer");
Asm(" phi rd");
Asm(" ldi iobuffer.0");
Asm(" plo rd");
Asm(" sep scall ; Display floating point value");
Asm(" dw ftoa");
Asm(" ldi iobuffer.1 ; Display result");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
Asm(" sep scall");
Asm(" dw f_msg");
Asm(" inc r7 ; Remove expression result");
Asm(" inc r7");
Asm(" inc r7");
}
else {
printf("Expression error\n");
exit(1);
}
}
else if (use32Bits) {
Asm(" inc r7 ; Point to expression result");
Asm(" glo r7");
Asm(" plo rf");
Asm(" ghi r7");
Asm(" phi rf");
Asm(" ldi iobuffer.1 ; Point to i/o buffer");
Asm(" phi rd");
Asm(" ldi iobuffer.0");
Asm(" plo rd");
Asm(" sep scall ; Display integer value");
Asm(" dw itoa32");
Asm(" ldi iobuffer.1 ; Display result");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
Asm(" sep scall");
Asm(" dw f_msg");
Asm(" inc r7 ; Remove expression result");
Asm(" inc r7");
Asm(" inc r7");
}
else {
Asm(" inc r7 ; Recover expression result");
Asm(" lda r7");
Asm(" plo rc");
Asm(" ldn r7");
Asm(" phi rc");
Asm(" ldi iobuffer.1 ; Point to i/o buffer");
Asm(" phi rd");
Asm(" ldi iobuffer.0");
Asm(" plo rd");
Asm(" sep scall ; Display integer value");
Asm(" dw itoa");
Asm(" ldi iobuffer.1 ; Display result");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
Asm(" sep scall");
Asm(" dw f_msg");
}
last = ' ';
}
line=trim(line);
}
if (last != ';' && last != ',') {
Asm(" sep scall ; Display cr/lf");
Asm(" dw f_inmsg");
Asm(" db 10,13,0");
}
return line;
}