Fixed issue with addr offset

This commit is contained in:
neauoire 2021-02-05 20:18:30 -08:00
parent 560ead0e32
commit 60cbe91cde
4 changed files with 22 additions and 24 deletions

View File

@ -40,18 +40,21 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
@loop @loop
,dev1w STR ,dev1w STR
,iterator LDR ,incr JSU ( call incr )
,01 ADD
,iterator STR
,iterator LDR
,05 NEQ ,loop ROT JSC ,05 NEQ ,loop ROT JSC
BRK ( RESET ) BRK ( RESET )
@incr
,iterator LDR
,01 ADD
,iterator STR
,iterator LDR
RTS
|c000 @FRAME BRK |c000 @FRAME BRK
|d000 @ERROR BRK |d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR |FFFA .RESET .FRAME .ERROR
``` ```
## Mission ## Mission
@ -82,4 +85,4 @@ https://code.9front.org/hg/plan9front/file/a7f9946e238f/sys/src/games/nes/cpu.c
http://www.w3group.de/stable_glossar.html http://www.w3group.de/stable_glossar.html
http://www.emulator101.com/6502-addressing-modes.html http://www.emulator101.com/6502-addressing-modes.html
http://forth.works/8f0c04f616b6c34496eb2141785b4454 http://forth.works/8f0c04f616b6c34496eb2141785b4454
https://justinmeiners.github.io/lc3-vm/ https://justinmeiners.github.io/lc3-vm/

View File

@ -10,14 +10,18 @@
@loop @loop
,dev1w STR ,dev1w STR
,iterator LDR ,incr JSU ( call incr )
,01 ADD
,iterator STR
,iterator LDR
,05 NEQ ,loop ROT JSC ,05 NEQ ,loop ROT JSC
BRK ( RESET ) BRK ( RESET )
@incr
,iterator LDR
,01 ADD
,iterator STR
,iterator LDR
RTS
|c000 @FRAME BRK |c000 @FRAME BRK
|d000 @ERROR BRK |d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR |FFFA .RESET .FRAME .ERROR

5
uxn.c
View File

@ -164,7 +164,7 @@ reset(void)
int int
error(char *name) error(char *name)
{ {
printf("Error: %s\n", name); printf("Error: %s, at 0x%04x\n", name, cpu.counter);
return 0; return 0;
} }
@ -195,8 +195,7 @@ eval(void)
if(instr > 0x10) if(instr > 0x10)
setflag(FLAG_ZERO, 0); setflag(FLAG_ZERO, 0);
if(cpu.counter == 128) { if(cpu.counter == 128) {
printf("REACHED COUNTER\n"); return error("Reached bounds");
return 0;
} }
cpu.counter++; cpu.counter++;
return 1; return 1;

View File

@ -107,12 +107,6 @@ shex(char *s) /* string to num */
return n; return n;
} }
int
ismarker(char *w)
{
return w[0] == '[' || w[0] == ']' || w[0] == '{' || w[0] == '}';
}
int int
iscomment(char *w, int *skip) iscomment(char *w, int *skip)
{ {
@ -173,7 +167,7 @@ findlabel(char *s)
int int
error(char *name, char *id) error(char *name, char *id)
{ {
printf("Error: %s(%s)\n", name, id); printf("Error: %s[%s]\n", name, id);
return 0; return 0;
} }
@ -241,9 +235,7 @@ pass1(FILE *f)
else if(w[0] == '"') else if(w[0] == '"')
addr += slen(w + 1) + 2; addr += slen(w + 1) + 2;
else if(w[0] == ',') else if(w[0] == ',')
addr += 4; addr += 2 + (sihx(w + 1) && slen(w + 1) == 2 ? 1 : 2);
else if(ismarker(w))
addr += 0;
else else
return error("Unknown label", w); return error("Unknown label", w);
} }
@ -262,7 +254,7 @@ pass2(FILE *f)
if(w[0] == '@') continue; if(w[0] == '@') continue;
if(w[0] == ';') continue; if(w[0] == ';') continue;
suca(w); suca(w);
if(iscomment(w, &skip) || ismarker(w)) continue; if(iscomment(w, &skip)) continue;
if(w[0] == '|') if(w[0] == '|')
p.ptr = shex(w + 1); p.ptr = shex(w + 1);
else if(w[0] == ':') else if(w[0] == ':')