This commit is contained in:
parent
770d65bd9f
commit
e86503901c
|
@ -62,9 +62,9 @@ BRK
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
|
- short variable
|
||||||
- Implement signed flag to operators.
|
- Implement signed flag to operators.
|
||||||
- On-screen debugger.
|
- On-screen debugger.
|
||||||
- 16b mode for str/ldr
|
|
||||||
- Auto-advance ldr?
|
- Auto-advance ldr?
|
||||||
- Getting rid of IOR/IOW would be nice..
|
- Getting rid of IOR/IOW would be nice..
|
||||||
|
|
||||||
|
|
35
assembler.c
35
assembler.c
|
@ -139,32 +139,40 @@ makeconst(char *id, FILE *f)
|
||||||
return makelabel(id, shex(wv));
|
return makelabel(id, shex(wv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
makevariable(char *id, Uint16 *addr, FILE *f)
|
||||||
|
{
|
||||||
|
char wv[64];
|
||||||
|
Uint8 origin;
|
||||||
|
fscanf(f, "%s", wv);
|
||||||
|
origin = *addr;
|
||||||
|
*addr += shex(wv);
|
||||||
|
return makelabel(id, origin);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pass1(FILE *f)
|
pass1(FILE *f)
|
||||||
{
|
{
|
||||||
int skip = 0, vars = 0;
|
int skip = 0;
|
||||||
Uint16 addr = 0;
|
Uint16 addr = 0;
|
||||||
char w[64];
|
char w[64];
|
||||||
while(fscanf(f, "%s", w) == 1) {
|
while(fscanf(f, "%s", w) == 1) {
|
||||||
if(cmnt(w, &skip))
|
if(cmnt(w, &skip))
|
||||||
continue;
|
continue;
|
||||||
if(w[0] == '@' && !makelabel(w + 1, addr))
|
if(w[0] == '@') {
|
||||||
return error("Pass1 failed", w);
|
if(!makelabel(w + 1, addr))
|
||||||
if(w[0] == ';' && !makelabel(w + 1, vars++))
|
return error("Pass1 failed", w);
|
||||||
return error("Pass1 failed", w);
|
} else if(w[0] == ';') {
|
||||||
if(w[0] == ':') {
|
if(!makevariable(w + 1, &addr, f))
|
||||||
|
return error("Pass1 failed", w);
|
||||||
|
} else if(w[0] == ':') {
|
||||||
if(!makeconst(w + 1, f))
|
if(!makeconst(w + 1, f))
|
||||||
return error("Pass1 failed", w);
|
return error("Pass1 failed", w);
|
||||||
else
|
} else if(findoperator(w) || scmp(w, "BRK"))
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(findoperator(w) || scmp(w, "BRK"))
|
|
||||||
addr += 1;
|
addr += 1;
|
||||||
else {
|
else {
|
||||||
switch(w[0]) {
|
switch(w[0]) {
|
||||||
case '|': addr = shex(w + 1); break;
|
case '|': addr = shex(w + 1); break;
|
||||||
case '@':
|
|
||||||
case ';': break;
|
|
||||||
case '"': addr += slen(w + 1) + 2; break;
|
case '"': addr += slen(w + 1) + 2; break;
|
||||||
case '#': addr += 4; break;
|
case '#': addr += 4; break;
|
||||||
case '.': addr += 2; break;
|
case '.': addr += 2; break;
|
||||||
|
@ -189,12 +197,13 @@ pass2(FILE *f)
|
||||||
Uint8 op = 0;
|
Uint8 op = 0;
|
||||||
Label *l;
|
Label *l;
|
||||||
if(w[0] == '@') continue;
|
if(w[0] == '@') continue;
|
||||||
if(w[0] == ';') continue;
|
|
||||||
if(cmnt(w, &skip)) continue;
|
if(cmnt(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] == ':')
|
||||||
fscanf(f, "%s", w);
|
fscanf(f, "%s", w);
|
||||||
|
else if(w[0] == ';')
|
||||||
|
fscanf(f, "%s", w);
|
||||||
else if(w[0] == '"')
|
else if(w[0] == '"')
|
||||||
pushtext(w + 1);
|
pushtext(w + 1);
|
||||||
else if(w[0] == '#')
|
else if(w[0] == '#')
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -24,5 +24,5 @@ rm -f ./bin/emulator
|
||||||
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator
|
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator
|
||||||
|
|
||||||
# run
|
# run
|
||||||
./bin/assembler examples/test.usm bin/boot.rom
|
./bin/assembler examples/pixels.usm bin/boot.rom
|
||||||
./bin/emulator bin/boot.rom
|
./bin/emulator bin/boot.rom
|
||||||
|
|
|
@ -37,7 +37,7 @@ SDL_Renderer *gRenderer;
|
||||||
SDL_Texture *gTexture;
|
SDL_Texture *gTexture;
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
|
|
||||||
Device *devscreen, *devmouse, *devkey;
|
Device *devconsole, *devscreen, *devmouse, *devkey;
|
||||||
|
|
||||||
int
|
int
|
||||||
error(char *msg, const char *err)
|
error(char *msg, const char *err)
|
||||||
|
@ -288,7 +288,7 @@ main(int argc, char **argv)
|
||||||
if(!init())
|
if(!init())
|
||||||
return error("Init", "Failed");
|
return error("Init", "Failed");
|
||||||
|
|
||||||
portuxn(&u, "console", consoler, consolew);
|
devconsole = portuxn(&u, "console", consoler, consolew);
|
||||||
devscreen = portuxn(&u, "screen", screenr, screenw);
|
devscreen = portuxn(&u, "screen", screenr, screenw);
|
||||||
devmouse = portuxn(&u, "mouse", mouser, mousew);
|
devmouse = portuxn(&u, "mouse", mouser, mousew);
|
||||||
devkey = portuxn(&u, "key", keyr, keyw);
|
devkey = portuxn(&u, "key", keyr, keyw);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
( benchmark )
|
( benchmark )
|
||||||
|
|
||||||
;iterator
|
|
||||||
:dev1r FFF0
|
|
||||||
:dev1w FFF1
|
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
( arithmetic )
|
( arithmetic )
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
( blank )
|
( blank )
|
||||||
|
|
||||||
;iterator
|
|
||||||
:dev1r FFF0
|
|
||||||
:dev1w FFF1
|
|
||||||
|
|
||||||
|0100 @RESET BRK
|
|0100 @RESET BRK
|
||||||
|c000 @FRAME BRK
|
|c000 @FRAME BRK
|
||||||
|d000 @ERROR BRK
|
|d000 @ERROR BRK
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
( draw pixel )
|
( draw pixel )
|
||||||
|
|
||||||
|
:dev/w fff9 ( keep write port in a const )
|
||||||
|
;x 2
|
||||||
|
;y 2
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
( redraw - color - x - y )
|
( set dev/write to screen )
|
||||||
,00 ,01 ,0000 ,0000 ,putpixel JSR
|
|
||||||
,00 ,02 ,0001 ,0001 ,putpixel JSR
|
,01 ,dev/w STR
|
||||||
,01 ,03 ,0002 ,0002 ,putpixel JSR
|
|
||||||
|
,0020 ,x STR^ ( set x-pos )
|
||||||
|
,0030 ,y STR^ ( set y-pos )
|
||||||
|
|
||||||
|
( IOW will now send to screen )
|
||||||
|
|
||||||
|
,y LDR^ IOW^ ( y-pos )
|
||||||
|
,x LDR^ IOW^ ( x-pos )
|
||||||
|
,02 IOW ( color )
|
||||||
|
,01 IOW ( redraw )
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@putpixel
|
|
||||||
SWP ,01 IOW ,01 IOW ( y )
|
|
||||||
SWP ,01 IOW ,01 IOW ( x )
|
|
||||||
,01 IOW ( color )
|
|
||||||
,01 IOW ( redraw )
|
|
||||||
RTS
|
|
||||||
|
|
||||||
|c000 @FRAME BRK
|
|c000 @FRAME BRK
|
||||||
|d000 @ERROR BRK
|
|d000 @ERROR BRK
|
||||||
|FFFA .RESET .FRAME .ERROR
|
|FFFA .RESET .FRAME .ERROR
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
( my default test file )
|
||||||
|
|
||||||
|
:dev/r fff8 ( std read port )
|
||||||
|
:dev/w fff9 ( std write port )
|
||||||
|
|
||||||
|
;x 2 ;y 2 ;color 1
|
||||||
|
|
||||||
|
|0100 @RESET
|
||||||
|
|
||||||
|
,01 ,dev/w STR ( set dev/write to screen )
|
||||||
|
,01 ,color STR ( set color )
|
||||||
|
,0020 ,x STR^ ( set x-pos )
|
||||||
|
,0030 ,y STR^ ( set y-pos )
|
||||||
|
|
||||||
|
BRK
|
||||||
|
|
||||||
|
|c000 @FRAME
|
||||||
|
|
||||||
|
,colorize JSR
|
||||||
|
,move JSR
|
||||||
|
( draw )
|
||||||
|
,01 ,color LDR ,x LDR^ ,y LDR^ ,putpixel JSR
|
||||||
|
|
||||||
|
BRK
|
||||||
|
|
||||||
|
@colorize
|
||||||
|
,color LDR ,01 ADD ,color STR ( incr color )
|
||||||
|
,color LDR ,04 LTH RTS?
|
||||||
|
,01 ,color STR
|
||||||
|
RTS
|
||||||
|
|
||||||
|
@move
|
||||||
|
,x LDR^ ,0001 ADD^ ,x STR^ ( incr x )
|
||||||
|
,x LDR^ ,0060 LTH^ RTS? ( if x > 60 )
|
||||||
|
,0020 ,x STR^ ( x = 0x0020 )
|
||||||
|
,y LDR^ ,0001 ADD^ ,y STR^ ( incr y )
|
||||||
|
RTS
|
||||||
|
|
||||||
|
@putpixel
|
||||||
|
IOW^ ( y short )
|
||||||
|
IOW^ ( x short )
|
||||||
|
IOW ( color byte )
|
||||||
|
IOW ( redraw byte )
|
||||||
|
RTS
|
||||||
|
|
||||||
|
|d000 @ERROR BRK
|
||||||
|
|FFFA .RESET .FRAME .ERROR
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
:dev/r fff8 ( std read port )
|
:dev/r fff8 ( std read port )
|
||||||
:dev/w fff9 ( std write port )
|
:dev/w fff9 ( std write port )
|
||||||
;width0
|
;width 2
|
||||||
;width1
|
;height 2
|
||||||
;height0
|
|
||||||
;height1
|
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
|
@ -13,14 +11,14 @@
|
||||||
,01 DUP ,dev/r STR ,dev/w STR
|
,01 DUP ,dev/r STR ,dev/w STR
|
||||||
|
|
||||||
( load screen size )
|
( load screen size )
|
||||||
,00 IOR^ ,width0 STR^
|
,00 IOR^ ,width STR^
|
||||||
,02 IOR^ ,height0 STR^
|
,02 IOR^ ,height STR^
|
||||||
|
|
||||||
( draw pixel at screen center )
|
( draw pixel at screen center )
|
||||||
|
|
||||||
,0101
|
,0101
|
||||||
,width0 LDR^ ,0002 DIV^
|
,width LDR^ ,0002 DIV^
|
||||||
,height0 LDR^ ,0002 DIV^
|
,height LDR^ ,0002 DIV^
|
||||||
,putpixel JSR
|
,putpixel JSR
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
|
@ -3,34 +3,12 @@
|
||||||
:dev/r fff8 ( std read port )
|
:dev/r fff8 ( std read port )
|
||||||
:dev/w fff9 ( std write port )
|
:dev/w fff9 ( std write port )
|
||||||
|
|
||||||
;i ;x0 ;x1 ;y0 ;y1
|
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
,01 ,dev/w STR ( set dev/write screen#01 )
|
,01 ,dev/w STR ( set dev/write screen#01 )
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|c000 @FRAME
|
|c000 @FRAME BRK
|
||||||
|
|
||||||
,i LDR ,04 ADD ,i STR ( incr i )
|
|
||||||
,i LDR ,x1 STR ( set x )
|
|
||||||
,changerow JSR ( update y )
|
|
||||||
,01 ,02 ,x0 LDR^ ,y0 LDR^ ,putpixel JSR
|
|
||||||
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@changerow
|
|
||||||
,i LDR ,00 NEQ RTS?
|
|
||||||
,y1 LDR ,04 ADD ,y1 STR
|
|
||||||
RTS
|
|
||||||
|
|
||||||
@putpixel
|
|
||||||
IOW^ ( y short )
|
|
||||||
IOW^ ( x short )
|
|
||||||
IOW ( color byte )
|
|
||||||
IOW ( redraw byte )
|
|
||||||
RTS
|
|
||||||
|
|
||||||
|d000 @ERROR BRK
|
|d000 @ERROR BRK
|
||||||
|FFFA .RESET .FRAME .ERROR
|
|FFFA .RESET .FRAME .ERROR
|
||||||
|
|
2
uxn.c
2
uxn.c
|
@ -208,6 +208,6 @@ portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Uint8), Uint8 (*wfn)(Device *
|
||||||
d->read = rfn;
|
d->read = rfn;
|
||||||
d->write = wfn;
|
d->write = wfn;
|
||||||
d->len = 0;
|
d->len = 0;
|
||||||
printf("Device#%d: %s \n", u->devices, name);
|
printf("Device #%d: %s \n", u->devices - 1, name);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue