commit 36bfb2a417b4a604874886cf1a7fa5f9801109bf
parent 1beb714ce104b67efb3f8eb0723787f230c2c77f
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 16 Feb 2021 12:19:48 -0800
started drag example
Diffstat:
8 files changed, 81 insertions(+), 8 deletions(-)
diff --git a/assembler.c b/assembler.c
@@ -140,6 +140,8 @@ makevariable(char *id, Uint16 *addr, FILE *f)
char wv[64];
Uint8 origin;
fscanf(f, "%s", wv);
+ if(!sihx(wv))
+ return error("Variable value is invalid", wv);
origin = *addr;
*addr += shex(wv);
return makelabel(id, origin, shex(wv));
diff --git a/build.sh b/build.sh
@@ -19,5 +19,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/controller.usm bin/boot.rom
+./bin/assembler examples/drag.usm bin/boot.rom
./bin/emulator bin/boot.rom
diff --git a/emulator.c b/emulator.c
@@ -252,8 +252,10 @@ screenw(Device *d, Memory *m, Uint8 b)
(d->mem[2] << 8) + d->mem[3],
(d->mem[0] << 8) + d->mem[1],
d->mem[4]);
- if(d->mem[5])
+ if(d->mem[5] == 1)
REQDRAW = 1;
+ if(d->mem[5] == 2)
+ clear(pixels);
d->ptr = 0;
}
(void)m;
diff --git a/examples/controller.usm b/examples/controller.usm
@@ -1,4 +1,4 @@
-( comment )
+( controller )
:dev/r fff8 ( const read port )
:dev/w fff9 ( const write port )
diff --git a/examples/drag.usm b/examples/drag.usm
@@ -0,0 +1,69 @@
+( drag )
+
+:dev/r fff8 ( std read port )
+:dev/w fff9 ( std write port )
+
+;drawx 2 ;drawy 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1
+
+|0100 @RESET
+
+ #05 =dev/r ( set dev/read mouse )
+ #01 =dev/w ( set dev/write to screen )
+
+BRK
+
+|c000 @FRAME
+
+ ( get touch )
+ #04 IOR #01 NEQ ,frame-end ROT JMP? POP2
+
+ ( clear )
+ #00 =color
+ ~x ~y #0060 #0040 ,fillrect JSR
+
+ ( fill rect x y w h )
+ #01 =color
+ #00 IOR2 ( get mouse-x ) =x
+ #02 IOR2 ( get mouse-y ) =y
+ ~x ~y #0060 #0040 ,fillrect JSR
+
+ ,redraw JSR
+
+ @frame-end
+
+BRK
+
+@fillrect
+ =h =w =y =x ( store values in variables )
+ ~x =drawx ~y =drawy ( store draw pos in variables )
+ @fillrectrow
+ ~x =drawx
+ @fillrectcol
+ ( draw ) ~drawx ~drawy IOW2 IOW2 ~color IOW #00 IOW
+ ~drawx #0001 ADD2 =drawx
+ ~drawx ~w ~x ADD2 LTH2 ,fillrectcol ROT JMP? POP2
+ ~drawy #0001 ADD2 =drawy
+ ~drawy ~h ~y ADD2 LTH2 ,fillrectrow ROT JMP? POP2
+ RTS
+
+@getmouse
+ #00 IOR2 ( get mouse x )
+ #02 IOR2 ( get mouse y )
+ RTS
+
+@redraw
+ #0000 IOW2
+ #0000 IOW2
+ #00 IOW
+ #01 IOW
+ RTS
+
+@clear
+ #0000 IOW2
+ #0000 IOW2
+ #00 IOW
+ #02 IOW
+ RTS
+
+|d000 @ERROR BRK
+|FFFA .RESET .FRAME .ERROR
diff --git a/examples/hello.usm b/examples/hello.usm
@@ -1,4 +1,4 @@
-( comment )
+( hello world )
:dev/w fff9 ( const write port )
@@ -32,11 +32,11 @@ BRK
@displaygui
#02 =dev/w ( set dev/write to sprite )
- @displayguiloop
+ @guiloop
DUP2 LDR ,printchar JSR
#0001 ADD2
~x #0008 ADD2 =x
- DUP2 LDR #00 NEQ ,displayguiloop ROT JMP? POP2
+ DUP2 LDR #00 NEQ ,guiloop ROT JMP? POP2
RTS
@printchar
diff --git a/examples/pixels.usm b/examples/pixels.usm
@@ -1,4 +1,4 @@
-( my default test file )
+( pixels )
:dev/r fff8 ( std read port )
:dev/w fff9 ( std write port )
diff --git a/examples/sprite.usm b/examples/sprite.usm
@@ -1,4 +1,4 @@
-( comment )
+( sprite )
:dev/w fff9 ( const write port )