forked from rileym65/Basic-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcinput.c
More file actions
134 lines (131 loc) · 4.46 KB
/
Copy pathcinput.c
File metadata and controls
134 lines (131 loc) · 4.46 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
/*
*******************************************************************
*** 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* cinput(char* line) {
int fp;
char qt;
word addr;
char name[256];
int pos;
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;
}
if (*line == '"') {
Asm(" sep scall ; Display prompt");
Asm(" dw f_inmsg");
strcpy(buffer," db '");
line++;
while (*line != '"' && *line != 0) {
buffer[strlen(buffer)+1] = 0;
buffer[strlen(buffer)] = *line++;
}
strcat(buffer,"',0"); Asm(buffer);
if (*line == '"') line++;
line = trim(line);
if (*line != ',') {
showError("Syntax error");
exit(1);
}
line++;
}
fp = 0;
line = trim(line);
while (*line != ':' && *line != 0) {
if (!(*line >= 'a' && *line <= 'z') &&
!(*line >= 'A' && *line <= 'Z')) {
showError("Syntax error");
exit(1);
}
pos = 0;
while ((*line >= 'a' && *line <= 'z') ||
(*line >= 'A' && *line <= 'Z') ||
(*line >= '0' && *line <= '9') ||
*line == '_') {
name[pos++] = *line++;
if (useFp) {
if (*line == '!') {
name[pos++] = *line++;
fp = -1;
while ((*line >= 'a' && *line <= 'z') ||
(*line >= 'A' && *line <= 'Z') ||
(*line >= '0' && *line <= '9') ||
*line == '_') {
showError("Invalid variable name");
exit(1);
}
}
}
}
name[pos] = 0;
if (strlen(name) == 0) {
showError("Syntax error");
exit(1);
}
addr = getVariable(name);
Asm(" sep scall ; display question mark");
Asm(" dw f_inmsg");
Asm(" db '? ',0");
Asm(" ldi iobuffer.1 ; Point to keyboard buffer");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
Asm(" sep scall ; Get input from user");
Asm(" dw f_input");
Asm(" ldi iobuffer.1 ; Point to keyboard buffer");
Asm(" phi rf");
Asm(" ldi iobuffer.0");
Asm(" plo rf");
if (fp) {
sprintf(buffer," ldi v_%s.1 ; Point to destination variable",name); Asm(buffer);
Asm(" phi rd");
sprintf(buffer," ldi v_%s.0",name); Asm(buffer);
Asm(" plo rd");
Asm(" sep scall ; Convert ASCII to integer");
Asm(" dw atof");
}
else if (use32Bits) {
sprintf(buffer," ldi v_%s.1 ; Point to destination variable",name); Asm(buffer);
Asm(" phi rd");
sprintf(buffer," ldi v_%s.0",name); Asm(buffer);
Asm(" plo rd");
Asm(" sep scall ; Convert ASCII to integer");
Asm(" dw atoi32");
}
else {
Asm(" sep scall ; Convert ASCII to integer");
Asm(" dw atoi");
sprintf(buffer," ldi v_%s.1 ; Point to destination variable",name); Asm(buffer);
Asm(" phi rf");
sprintf(buffer," ldi v_%s.0",name); Asm(buffer);
Asm(" plo rf");
Asm(" ghi rc ; Store value into variable");
Asm(" str rf");
Asm(" inc rf");
Asm(" glo rc");
Asm(" str rf");
}
Asm(" sep scall ; Display cr/lf");
Asm(" dw f_inmsg");
Asm(" db 10,13,0");
line = trim(line);
if (*line != ':' && *line != ',' && *line != 0) {
showError("Syntax error");
exit(1);
}
if (*line == ',') line++;
}
return line;
}