Added experimental dev1

This commit is contained in:
neauoire 2021-02-05 11:57:37 -08:00
parent e2b6b6907d
commit 1e0d5bbf50
6 changed files with 57 additions and 34 deletions

View File

@ -25,6 +25,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
- `( comment )`, toggle parsing on/off
- `|0010`, move to position in the program
- `"hello`, push literal bytes for word "hello"
```
;value ( alloc a zero-page variable )

View File

@ -29,7 +29,7 @@ contexts:
- match: '\;(\S+)\s?'
scope: string.control
pop: true
- match: '\_(\S+)\s?'
- match: '\@(\S+)\s?'
scope: string.control
pop: true
- match: '\,(\S+)\s?'
@ -38,6 +38,9 @@ contexts:
- match: '\.(\S+)\s?'
scope: keyword.control
pop: true
- match: '\"(\S+)\s?'
scope: keyword.control
pop: true
comments:
- match: '\('

View File

@ -1,24 +1,27 @@
( blank project )
;variable1
;variable2
_constant1 abcd
:constant1 9abc
|0100 ( -------------------------------- )
:RESET BRK
@RESET
,abcd
BRK ( RESET-END )
|c000 ( -------------------------------- )
:FRAME ( FRAME-START )
@FRAME ( FRAME-START )
,abcd
BRK ( FRAME-END )
|d000 ( -------------------------------- )
:ERROR BRK
@ERROR BRK
|FFFA ( -------------------------------- )

View File

@ -1,30 +1,21 @@
( blank project )
;variable1
:constant1 9abc
:dev1r FFF0
:dev1w FFF1
|0100 ( -------------------------------- )
|0100 @RESET
@RESET
"hello
,abcd
,dev1w STR
,dev1w STR
,dev1w STR
,dev1w STR
,dev1w STR
BRK ( RESET-END )
BRK ( RESET )
|c000 ( -------------------------------- )
@FRAME ( FRAME-START )
,abcd
BRK ( FRAME-END )
|d000 ( -------------------------------- )
@ERROR BRK
|FFFA ( -------------------------------- )
.RESET
.FRAME
.ERROR
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR

21
uxn.c
View File

@ -85,7 +85,7 @@ echom(Memory *m, Uint8 len, char *name)
/* clang-format off */
Uint8 mempeek8(Uint16 s) { return cpu.rom.dat[s] & 0xff; }
Uint8 rampeek8(Uint16 s) { return cpu.ram.dat[s] & 0xff; }
Uint16 mempeek16(Uint16 s) { return (cpu.rom.dat[s] << 8) + (cpu.rom.dat[s+1] & 0xff); }
void wspush8(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; }
Uint8 wspop8(void) { return cpu.wst.dat[--cpu.wst.ptr]; }
@ -158,6 +158,14 @@ error(char *name)
return 0;
}
int
device1(Uint8 *read, Uint8 *write)
{
printf("%c", *write);
*write = 0;
return 0;
}
int
eval(void)
{
@ -192,12 +200,15 @@ start(FILE *f)
cpu.vframe = mempeek16(0xfffc);
cpu.verror = mempeek16(0xfffe);
/* eval reset */
printf("Phase: reset\n");
printf("\nPhase: reset\n");
cpu.rom.ptr = cpu.vreset;
while(!(cpu.status & FLAG_HALT) && eval())
;
while(!(cpu.status & FLAG_HALT) && eval()) {
/* experimental */
if(cpu.ram.dat[0xfff1])
device1(&cpu.ram.dat[0xfff0], &cpu.ram.dat[0xfff1]);
}
/*eval frame */
printf("Phase: frame\n");
printf("\nPhase: frame\n");
setflag(FLAG_HALT, 0);
cpu.rom.ptr = cpu.vframe;
while(!(cpu.status & FLAG_HALT) && eval())

View File

@ -148,6 +148,16 @@ pushshort(Uint16 s, int lit)
pushbyte(s & 0xff, 0);
}
void
pushword(char *w)
{
int i = slen(w);
pushbyte(0x02, 0);
pushbyte(slen(w), 0);
while(i > 0)
pushbyte(w[--i], 0);
}
Label *
findlabel(char *s)
{
@ -228,6 +238,8 @@ pass1(FILE *f)
addr += 0;
else if(w[0] == '.')
addr += 2;
else if(w[0] == '"')
addr += slen(w + 1);
else if(w[0] == ',')
addr += 4;
else if(ismarker(w))
@ -255,6 +267,8 @@ pass2(FILE *f)
p.ptr = shex(w + 1);
else if(w[0] == ':')
fscanf(f, "%s", w);
else if(w[0] == '"')
pushword(w + 1);
else if((op = findop(w)) || scmp(w, "BRK"))
pushbyte(op, 0);
else if((l = findlabel(w + 1)))