Browse code

Fixed issue with addr offset

neauoire authored on 06/02/2021 04:18:30
Showing 4 changed files
... ...
@@ -40,18 +40,21 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
40 40
 
41 41
 @loop
42 42
 	,dev1w STR
43
-	,iterator LDR
44
-	,01 ADD
45
-	,iterator STR 
46
-	,iterator LDR
43
+	,incr JSU ( call incr )
47 44
 	,05 NEQ ,loop ROT JSC
48 45
 
49 46
 BRK ( RESET )
50 47
 
48
+@incr
49
+	,iterator LDR
50
+	,01 ADD
51
+	,iterator STR 
52
+	,iterator LDR
53
+	RTS
54
+	
51 55
 |c000 @FRAME BRK 
52 56
 |d000 @ERROR BRK 
53 57
 |FFFA .RESET .FRAME .ERROR
54
-
55 58
 ```
56 59
 
57 60
 ## Mission
... ...
@@ -82,4 +85,4 @@ https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c
82 85
 http://www.w3group.de/stable_glossar.html
83 86
 http://www.emulator101.com/6502-addressing-modes.html
84 87
 http://forth.works/8f0c04f616b6c34496eb2141785b4454
85
-https://justinmeiners.github.io/lc3-vm/
86 88
\ No newline at end of file
89
+https://justinmeiners.github.io/lc3-vm/
... ...
@@ -10,14 +10,18 @@
10 10
 
11 11
 @loop
12 12
 	,dev1w STR
13
-	,iterator LDR
14
-	,01 ADD
15
-	,iterator STR 
16
-	,iterator LDR
13
+	,incr JSU ( call incr )
17 14
 	,05 NEQ ,loop ROT JSC
18 15
 
19 16
 BRK ( RESET )
20 17
 
18
+@incr
19
+	,iterator LDR
20
+	,01 ADD
21
+	,iterator STR 
22
+	,iterator LDR
23
+	RTS
24
+	
21 25
 |c000 @FRAME BRK 
22 26
 |d000 @ERROR BRK 
23 27
 |FFFA .RESET .FRAME .ERROR
... ...
@@ -164,7 +164,7 @@ reset(void)
164 164
 int
165 165
 error(char *name)
166 166
 {
167
-	printf("Error: %s\n", name);
167
+	printf("Error: %s, at 0x%04x\n", name, cpu.counter);
168 168
 	return 0;
169 169
 }
170 170
 
... ...
@@ -195,8 +195,7 @@ eval(void)
195 195
 	if(instr > 0x10)
196 196
 		setflag(FLAG_ZERO, 0);
197 197
 	if(cpu.counter == 128) {
198
-		printf("REACHED COUNTER\n");
199
-		return 0;
198
+		return error("Reached bounds");
200 199
 	}
201 200
 	cpu.counter++;
202 201
 	return 1;
... ...
@@ -107,12 +107,6 @@ shex(char *s) /* string to num */
107 107
 	return n;
108 108
 }
109 109
 
110
-int
111
-ismarker(char *w)
112
-{
113
-	return w[0] == '[' || w[0] == ']' || w[0] == '{' || w[0] == '}';
114
-}
115
-
116 110
 int
117 111
 iscomment(char *w, int *skip)
118 112
 {
... ...
@@ -173,7 +167,7 @@ findlabel(char *s)
173 167
 int
174 168
 error(char *name, char *id)
175 169
 {
176
-	printf("Error: %s(%s)\n", name, id);
170
+	printf("Error: %s[%s]\n", name, id);
177 171
 	return 0;
178 172
 }
179 173
 
... ...
@@ -241,9 +235,7 @@ pass1(FILE *f)
241 235
 		else if(w[0] == '"')
242 236
 			addr += slen(w + 1) + 2;
243 237
 		else if(w[0] == ',')
244
-			addr += 4;
245
-		else if(ismarker(w))
246
-			addr += 0;
238
+			addr += 2 + (sihx(w + 1) && slen(w + 1) == 2 ? 1 : 2);
247 239
 		else
248 240
 			return error("Unknown label", w);
249 241
 	}
... ...
@@ -262,7 +254,7 @@ pass2(FILE *f)
262 254
 		if(w[0] == '@') continue;
263 255
 		if(w[0] == ';') continue;
264 256
 		suca(w);
265
-		if(iscomment(w, &skip) || ismarker(w)) continue;
257
+		if(iscomment(w, &skip)) continue;
266 258
 		if(w[0] == '|')
267 259
 			p.ptr = shex(w + 1);
268 260
 		else if(w[0] == ':')