This commit is contained in:
parent
770d65bd9f
commit
e86503901c
|
@ -62,9 +62,9 @@ BRK
|
|||
|
||||
## TODOs
|
||||
|
||||
- short variable
|
||||
- Implement signed flag to operators.
|
||||
- On-screen debugger.
|
||||
- 16b mode for str/ldr
|
||||
- Auto-advance ldr?
|
||||
- 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));
|
||||
}
|
||||
|
||||
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
|
||||
pass1(FILE *f)
|
||||
{
|
||||
int skip = 0, vars = 0;
|
||||
int skip = 0;
|
||||
Uint16 addr = 0;
|
||||
char w[64];
|
||||
while(fscanf(f, "%s", w) == 1) {
|
||||
if(cmnt(w, &skip))
|
||||
continue;
|
||||
if(w[0] == '@' && !makelabel(w + 1, addr))
|
||||
return error("Pass1 failed", w);
|
||||
if(w[0] == ';' && !makelabel(w + 1, vars++))
|
||||
return error("Pass1 failed", w);
|
||||
if(w[0] == ':') {
|
||||
if(w[0] == '@') {
|
||||
if(!makelabel(w + 1, addr))
|
||||
return error("Pass1 failed", w);
|
||||
} else if(w[0] == ';') {
|
||||
if(!makevariable(w + 1, &addr, f))
|
||||
return error("Pass1 failed", w);
|
||||
} else if(w[0] == ':') {
|
||||
if(!makeconst(w + 1, f))
|
||||
return error("Pass1 failed", w);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if(findoperator(w) || scmp(w, "BRK"))
|
||||
} else if(findoperator(w) || scmp(w, "BRK"))
|
||||
addr += 1;
|
||||
else {
|
||||
switch(w[0]) {
|
||||
case '|': addr = shex(w + 1); break;
|
||||
case '@':
|
||||
case ';': break;
|
||||
case '"': addr += slen(w + 1) + 2; break;
|
||||
case '#': addr += 4; break;
|
||||
case '.': addr += 2; break;
|
||||
|
@ -189,12 +197,13 @@ pass2(FILE *f)
|
|||
Uint8 op = 0;
|
||||
Label *l;
|
||||
if(w[0] == '@') continue;
|
||||
if(w[0] == ';') continue;
|
||||
if(cmnt(w, &skip)) continue;
|
||||
if(w[0] == '|')
|
||||
p.ptr = shex(w + 1);
|
||||
else if(w[0] == ':')
|
||||
fscanf(f, "%s", w);
|
||||
else if(w[0] == ';')
|
||||
fscanf(f, "%s", w);
|
||||
else if(w[0] == '"')
|
||||
pushtext(w + 1);
|
||||
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
|
||||
|
||||
# run
|
||||
./bin/assembler examples/test.usm bin/boot.rom
|
||||
./bin/assembler examples/pixels.usm bin/boot.rom
|
||||
./bin/emulator bin/boot.rom
|
||||
|
|
|
@ -37,7 +37,7 @@ SDL_Renderer *gRenderer;
|
|||
SDL_Texture *gTexture;
|
||||
Uint32 *pixels;
|
||||
|
||||
Device *devscreen, *devmouse, *devkey;
|
||||
Device *devconsole, *devscreen, *devmouse, *devkey;
|
||||
|
||||
int
|
||||
error(char *msg, const char *err)
|
||||
|
@ -288,7 +288,7 @@ main(int argc, char **argv)
|
|||
if(!init())
|
||||
return error("Init", "Failed");
|
||||
|
||||
portuxn(&u, "console", consoler, consolew);
|
||||
devconsole = portuxn(&u, "console", consoler, consolew);
|
||||
devscreen = portuxn(&u, "screen", screenr, screenw);
|
||||
devmouse = portuxn(&u, "mouse", mouser, mousew);
|
||||
devkey = portuxn(&u, "key", keyr, keyw);
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
( benchmark )
|
||||
|
||||
;iterator
|
||||
:dev1r FFF0
|
||||
:dev1w FFF1
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
( arithmetic )
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
( blank )
|
||||
|
||||
;iterator
|
||||
:dev1r FFF0
|
||||
:dev1w FFF1
|
||||
|
||||
|0100 @RESET BRK
|
||||
|c000 @FRAME BRK
|
||||
|d000 @ERROR BRK
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
( draw pixel )
|
||||
|
||||
:dev/w fff9 ( keep write port in a const )
|
||||
;x 2
|
||||
;y 2
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
( redraw - color - x - y )
|
||||
,00 ,01 ,0000 ,0000 ,putpixel JSR
|
||||
,00 ,02 ,0001 ,0001 ,putpixel JSR
|
||||
,01 ,03 ,0002 ,0002 ,putpixel JSR
|
||||
( set dev/write to screen )
|
||||
|
||||
,01 ,dev/w STR
|
||||
|
||||
,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
|
||||
|
||||
@putpixel
|
||||
SWP ,01 IOW ,01 IOW ( y )
|
||||
SWP ,01 IOW ,01 IOW ( x )
|
||||
,01 IOW ( color )
|
||||
,01 IOW ( redraw )
|
||||
RTS
|
||||
|
||||
|c000 @FRAME BRK
|
||||
|d000 @ERROR BRK
|
||||
|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/w fff9 ( std write port )
|
||||
;width0
|
||||
;width1
|
||||
;height0
|
||||
;height1
|
||||
;width 2
|
||||
;height 2
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
|
@ -13,14 +11,14 @@
|
|||
,01 DUP ,dev/r STR ,dev/w STR
|
||||
|
||||
( load screen size )
|
||||
,00 IOR^ ,width0 STR^
|
||||
,02 IOR^ ,height0 STR^
|
||||
,00 IOR^ ,width STR^
|
||||
,02 IOR^ ,height STR^
|
||||
|
||||
( draw pixel at screen center )
|
||||
|
||||
,0101
|
||||
,width0 LDR^ ,0002 DIV^
|
||||
,height0 LDR^ ,0002 DIV^
|
||||
,width LDR^ ,0002 DIV^
|
||||
,height LDR^ ,0002 DIV^
|
||||
,putpixel JSR
|
||||
|
||||
BRK
|
||||
|
|
|
@ -3,34 +3,12 @@
|
|||
:dev/r fff8 ( std read port )
|
||||
:dev/w fff9 ( std write port )
|
||||
|
||||
;i ;x0 ;x1 ;y0 ;y1
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
,01 ,dev/w STR ( set dev/write screen#01 )
|
||||
|
||||
BRK
|
||||
|
||||
|c000 @FRAME
|
||||
|
||||
,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
|
||||
|
||||
|c000 @FRAME BRK
|
||||
|d000 @ERROR BRK
|
||||
|FFFA .RESET .FRAME .ERROR
|
||||
|
|
Loading…
Reference in New Issue