-
Notifications
You must be signed in to change notification settings - Fork 3
/
congoto.c
74 lines (71 loc) · 2.28 KB
/
congoto.c
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
/*
*******************************************************************
*** 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* con(char* line) {
int i;
char mode;
word addr;
word lines[256];
int lineCount;
line = cexpr(line, 0);
if (exprErrors > 0) return line;
line = trim(line);
if (strncasecmp(line,"goto",4) == 0) {
mode = 'G';
line += 4;
}
if (strncasecmp(line,"gosub",5) == 0) {
mode = 'S';
line += 5;
}
lineCount = 0;
while (*line != 0 && *line != ':') {
line = trim(line);
if (*line < '0' || *line > '9') {
showError("Syntax error");
*line = 0;
return line;
}
line = getNumber(line, &addr);
lines[lineCount++] = addr;
line = trim(line);
if (*line != ':' && *line != ',' && *line != 0) {
showError("Syntax error");
*line = 0;
return line;
}
if (*line == ',') line++;
}
Asm(" inc r7 ; Get low value of index");
Asm(" lda r7");
if (use32Bits) {
Asm(" inc r7 ; Remove high word");
Asm(" inc r7");
}
for (i=0; i<lineCount; i++) {
Asm(" smi 1 ; Subtract 1 from index");
if (findLine(lines[i], &addr) != 0) {
showError("Line number not found");
*line = 0;
return line;
}
if (mode == 'G') {
sprintf(buffer," lbz l_%d ; Jump if index is zero", lines[i]); Asm(buffer);
}
if (mode == 'S') {
Asm(" lbnz $+9 ; Jump if index not zero");
Asm(" sep scall ; Perform subroutine call");
sprintf(buffer," dw l_%d", lines[i]); Asm(buffer);
addr = 3 + ((lineCount-i-1) * 11);
sprintf(buffer," lbr $+%d ; Jump past remaining entries",addr); Asm(buffer);
}
}
return line;
}