Naive mouse support
This commit is contained in:
parent
17578d8bbb
commit
347b1055f6
|
@ -196,9 +196,9 @@ pass2(FILE *f)
|
||||||
fscanf(f, "%s", w);
|
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] == '#')
|
||||||
pushshort(shex(w + 1) & 0xff, 1);
|
pushshort(shex(w + 1) & 0xff, 1);
|
||||||
} else if((l = findlabel(w + 1)))
|
else if((l = findlabel(w + 1)))
|
||||||
pushshort(l->addr, w[0] == ',');
|
pushshort(l->addr, w[0] == ',');
|
||||||
else if((op = findoperator(w)) || scmp(w, "BRK"))
|
else if((op = findoperator(w)) || scmp(w, "BRK"))
|
||||||
pushbyte(op, 0);
|
pushbyte(op, 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/pixel.usm bin/boot.rom
|
./bin/assembler examples/mouse.usm bin/boot.rom
|
||||||
./bin/emulator bin/boot.rom
|
./bin/emulator bin/boot.rom
|
||||||
|
|
53
emulator.c
53
emulator.c
|
@ -37,6 +37,8 @@ SDL_Renderer *gRenderer;
|
||||||
SDL_Texture *gTexture;
|
SDL_Texture *gTexture;
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
|
|
||||||
|
Device *devscreen, *devmouse, *devkey;
|
||||||
|
|
||||||
int
|
int
|
||||||
error(char *msg, const char *err)
|
error(char *msg, const char *err)
|
||||||
{
|
{
|
||||||
|
@ -143,8 +145,15 @@ echof(Uxn *c)
|
||||||
void
|
void
|
||||||
domouse(SDL_Event *event)
|
domouse(SDL_Event *event)
|
||||||
{
|
{
|
||||||
(void)event;
|
int x = event->motion.x / ZOOM - PAD * 8;
|
||||||
/* printf("mouse\n"); */
|
int y = event->motion.y / ZOOM - PAD * 8;
|
||||||
|
switch(event->type) {
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
devmouse->mem[0] = x;
|
||||||
|
devmouse->mem[1] = y;
|
||||||
|
devmouse->mem[2] = event->button.button == SDL_BUTTON_LEFT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -157,7 +166,7 @@ dokey(SDL_Event *event)
|
||||||
#pragma mark - Devices
|
#pragma mark - Devices
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
console_onread(Device *d, Uint8 b)
|
consoler(Device *d, Uint8 b)
|
||||||
{
|
{
|
||||||
(void)b;
|
(void)b;
|
||||||
(void)d;
|
(void)d;
|
||||||
|
@ -165,7 +174,7 @@ console_onread(Device *d, Uint8 b)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
console_onwrite(Device *d, Uint8 b)
|
consolew(Device *d, Uint8 b)
|
||||||
{
|
{
|
||||||
(void)d;
|
(void)d;
|
||||||
if(b)
|
if(b)
|
||||||
|
@ -175,7 +184,7 @@ console_onwrite(Device *d, Uint8 b)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
ppur(Device *d, Uint8 b)
|
screenr(Device *d, Uint8 b)
|
||||||
{
|
{
|
||||||
(void)b;
|
(void)b;
|
||||||
(void)d;
|
(void)d;
|
||||||
|
@ -183,7 +192,7 @@ ppur(Device *d, Uint8 b)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
ppuw(Device *d, Uint8 b)
|
screenw(Device *d, Uint8 b)
|
||||||
{
|
{
|
||||||
d->mem[d->len++] = b;
|
d->mem[d->len++] = b;
|
||||||
if(d->len > 5) {
|
if(d->len > 5) {
|
||||||
|
@ -198,6 +207,32 @@ ppuw(Device *d, Uint8 b)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
mouser(Device *d, Uint8 b)
|
||||||
|
{
|
||||||
|
return d->mem[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
mousew(Device *d, Uint8 b)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
keyr(Device *d, Uint8 b)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8
|
||||||
|
keyw(Device *d, Uint8 b)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Generics
|
||||||
|
|
||||||
int
|
int
|
||||||
start(Uxn *u)
|
start(Uxn *u)
|
||||||
{
|
{
|
||||||
|
@ -240,8 +275,10 @@ main(int argc, char **argv)
|
||||||
if(!init())
|
if(!init())
|
||||||
return error("Init", "Failed");
|
return error("Init", "Failed");
|
||||||
|
|
||||||
portuxn(&u, "console", console_onread, console_onwrite);
|
portuxn(&u, "console", consoler, consolew);
|
||||||
portuxn(&u, "PPU", ppur, ppuw);
|
devscreen = portuxn(&u, "screen", screenr, screenw);
|
||||||
|
devmouse = portuxn(&u, "mouse", mouser, mousew);
|
||||||
|
devkey = portuxn(&u, "key", keyr, keyw);
|
||||||
|
|
||||||
start(&u);
|
start(&u);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
( draw pixel )
|
||||||
|
|
||||||
|
|0100 @RESET
|
||||||
|
|
||||||
|
( draw 3 pixels )
|
||||||
|
,00 ,01 ,0000 ,0000 ,putpixel JSR
|
||||||
|
,00 ,02 ,0001 ,0001 ,putpixel JSR
|
||||||
|
,01 ,03 ,0002 ,0002 ,putpixel JSR
|
||||||
|
|
||||||
|
BRK
|
||||||
|
|
||||||
|
|c000 @FRAME
|
||||||
|
,01 ,01 ( redraw color )
|
||||||
|
,00 ,01 ,02 IOR ( grab y )
|
||||||
|
,00 ,00 ,02 IOR ( grab x )
|
||||||
|
,putpixel JSR
|
||||||
|
BRK
|
||||||
|
|
||||||
|
@putpixel
|
||||||
|
SWP ,01 IOW ,01 IOW ( y )
|
||||||
|
SWP ,01 IOW ,01 IOW ( x )
|
||||||
|
,01 IOW ( color )
|
||||||
|
,01 IOW ( redraw )
|
||||||
|
RTS
|
||||||
|
|
||||||
|
|d000 @ERROR BRK
|
||||||
|
|FFFA .RESET .FRAME .ERROR
|
|
@ -2,29 +2,20 @@
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
,0001 IOW ( x0 )
|
( redraw - color - x - y )
|
||||||
,0001 IOW ( x1 )
|
,00 ,01 ,0000 ,0000 ,putpixel JSR
|
||||||
,0001 IOW ( y0 )
|
,00 ,02 ,0001 ,0001 ,putpixel JSR
|
||||||
,0001 IOW ( y1 )
|
,01 ,03 ,0002 ,0002 ,putpixel JSR
|
||||||
,0101 IOW ( clr )
|
|
||||||
,0001 IOW ( noredraw )
|
|
||||||
|
|
||||||
,0001 IOW ( x0 )
|
|
||||||
,0101 IOW ( x1 )
|
|
||||||
,0001 IOW ( y0 )
|
|
||||||
,0001 IOW ( y1 )
|
|
||||||
,0201 IOW ( clr )
|
|
||||||
,0001 IOW ( noredraw )
|
|
||||||
|
|
||||||
,0001 IOW ( x0 )
|
|
||||||
,0201 IOW ( x1 )
|
|
||||||
,0001 IOW ( y0 )
|
|
||||||
,0001 IOW ( y1 )
|
|
||||||
,0301 IOW ( clr )
|
|
||||||
,0101 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
|
||||||
|
|
4
uxn.c
4
uxn.c
|
@ -186,7 +186,7 @@ loaduxn(Uxn *u, char *filepath)
|
||||||
|
|
||||||
/* to start: evaluxn(u, u->vreset); */
|
/* to start: evaluxn(u, u->vreset); */
|
||||||
|
|
||||||
int
|
Device *
|
||||||
portuxn(Uxn *u, char *name, Uint8 (*onread)(Device *, Uint8), Uint8 (*onwrite)(Device *, Uint8))
|
portuxn(Uxn *u, char *name, Uint8 (*onread)(Device *, Uint8), Uint8 (*onwrite)(Device *, Uint8))
|
||||||
{
|
{
|
||||||
Device *d = &u->dev[u->devices++];
|
Device *d = &u->dev[u->devices++];
|
||||||
|
@ -194,5 +194,5 @@ portuxn(Uxn *u, char *name, Uint8 (*onread)(Device *, Uint8), Uint8 (*onwrite)(D
|
||||||
d->wfn = onwrite;
|
d->wfn = onwrite;
|
||||||
d->len = 0;
|
d->len = 0;
|
||||||
printf("Device#%d: %s \n", u->devices, name);
|
printf("Device#%d: %s \n", u->devices, name);
|
||||||
return 1;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
2
uxn.h
2
uxn.h
|
@ -54,4 +54,4 @@ int getflag(Uint8 *status, char flag);
|
||||||
int loaduxn(Uxn *c, char *filepath);
|
int loaduxn(Uxn *c, char *filepath);
|
||||||
int bootuxn(Uxn *c);
|
int bootuxn(Uxn *c);
|
||||||
int evaluxn(Uxn *u, Uint16 vec);
|
int evaluxn(Uxn *u, Uint16 vec);
|
||||||
int portuxn(Uxn *u, char *name, Uint8 (*onread)(Device *, Uint8), Uint8 (*onwrite)(Device *, Uint8));
|
Device *portuxn(Uxn *u, char *name, Uint8 (*onread)(Device *, Uint8), Uint8 (*onwrite)(Device *, Uint8));
|
||||||
|
|
Loading…
Reference in New Issue