forked from rileym65/Basic-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpass.c
More file actions
127 lines (123 loc) · 3.75 KB
/
Copy pathpass.c
File metadata and controls
127 lines (123 loc) · 3.75 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
/*
*******************************************************************
*** 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"
int pass(char* filename) {
int i;
char tmp[16];
source = fopen(filename,"r");
if (source == NULL) {
printf("Could not open %s\n",filename);
exit(1);
}
address = programStart;
if (useElfos) address -= 6;
outAddress = address;
lastLineNumber = 0;
lineCount = 0;
library();
while (fgets(currentLine, 1023, source) != NULL) {
while (strlen(currentLine) > 0 && currentLine[strlen(currentLine)-1] < 32) currentLine[strlen(currentLine)-1] = 0;
if (currentLine[0] == '.') strcpy(currentLine,"");
if (strlen(currentLine) > 0) {
lineCount++;
if (passNumber == 2 && showList) printf("%s\n",currentLine);
compileLine(currentLine);
}
}
fclose(source);
if (showCompiler && passNumber == 2) printf("%04x:",address);
if (useStg) {
Asm(" ldi STG_.1");
Asm(" phi rf");
Asm(" ldi STG_.0");
Asm(" plo rf");
Asm(" lda rf");
Asm(" phi r2");
Asm(" ldn rf");
Asm(" plo r2");
Asm(" sex r2");
Asm(" irx");
Asm(" ldxa");
Asm(" plo r6");
Asm(" ldx");
Asm(" phi r6");
Asm(" sep sret");
}
else if (exitAddress != 0xffff) {
sprintf(buffer," lbr 0%xh ; Jump to exit address",exitAddress); Asm(buffer);
}
else if (useElfos) {
Asm(" lbr 0303h ; Jump to exit address");
}
else {
Asm(" idl ; Idle the CPU");
Asm(" lbr $-1");
}
if (passNumber == 2 && showCompiler) printf("\n");
if (useData) {
if (passNumber == 1) {
dataAddress = address;
}
if (showCompiler && passNumber == 2) printf("%04x:",address);
strcpy(buffer, "data: dw ");
for (i=0; i<numData; i++) {
if (use32Bits) {
sprintf(tmp,"%d,%d",(data[i] & 0xffff0000) >> 16, data[i] & 0xffff);
}
else {
sprintf(tmp,"%d",data[i]);
}
if (strlen(buffer) > 16) strcat(buffer,",");
strcat(buffer,tmp);
if (strlen(buffer) > 60) {
Asm(buffer);
strcpy(buffer, " dw ");
}
}
if (strlen(buffer) > 16) Asm(buffer);
if (passNumber == 2 && showCompiler) printf("\n");
}
sprintf(buffer,"iobuffer: ds %d",iBufferSize); Asm(buffer);
if (getDefine("LFSR")) {
Asm("LFSR_: dw 0");
Asm("LFSR__: dw 0");
}
if (useData) {
Asm("DATA_: dw 0");
}
if (getDefine("HEAP")) {
Asm("HEAP_: dw 0");
}
if (useStg) {
Asm("STG_: dw 0");
}
if (getDefine ("FILES")) {
Asm("file1_: dw 0");
Asm("file2_: dw 0");
Asm("file3_: dw 0");
Asm("file4_: dw 0");
Asm("file5_: dw 0");
Asm("file6_: dw 0");
Asm("file7_: dw 0");
Asm("file8_: dw 0");
}
Asm("FREE_: dw 0");
for (i=0; i<numberOfVariables; i++) {
sprintf(buffer,"v_%s: ",variableNames[i]);
while (strlen(buffer) < 10) strcat(buffer," ");
if (use32Bits)
strcat(buffer,"dd 0");
else
strcat(buffer,"dw 0");
Asm(buffer);
}
Asm("end__: equ $");
return(0);
}