commit a1267aea4ebbd7296a9236d8ae94d0f70ce76259
parent 347b1055f654a2619bf502fcc6767ede24873a27
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 9 Feb 2021 17:43:53 -0800
Added mouse-down detect to example
Diffstat:
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/emulator.c b/emulator.c
@@ -147,11 +147,14 @@ domouse(SDL_Event *event)
{
int x = event->motion.x / ZOOM - PAD * 8;
int y = event->motion.y / ZOOM - PAD * 8;
+
+ devmouse->mem[0] = x;
+ devmouse->mem[1] = y;
switch(event->type) {
case SDL_MOUSEBUTTONUP:
+ devmouse->mem[2] = 0;
+ break;
case SDL_MOUSEBUTTONDOWN:
- devmouse->mem[0] = x;
- devmouse->mem[1] = y;
devmouse->mem[2] = event->button.button == SDL_BUTTON_LEFT;
}
}
diff --git a/examples/mouse.usm b/examples/mouse.usm
@@ -10,9 +10,20 @@
BRK
|c000 @FRAME
- ,01 ,01 ( redraw color )
- ,00 ,01 ,02 IOR ( grab y )
- ,00 ,00 ,02 IOR ( grab x )
+
+ ( get mouse button, or break )
+ ,02 ,02 IOR
+ ,01 NEQ
+ BRK?
+
+ ( print A to console on click )
+ ,02 ,02 IOR
+ ,41 ADD
+ ,putbyte JSR
+
+ ( paint a white pixel )
+ ,01 ,01
+ ,getmouse JSR
,putpixel JSR
BRK
@@ -23,5 +34,13 @@ BRK
,01 IOW ( redraw )
RTS
+@getmouse ( push y,x to stack )
+ ,00 ,01 ,02 IOR ( grab y )
+ ,00 ,00 ,02 IOR ( grab x )
+ RTS
+
+@putbyte ( print to console )
+ ,00 IOW RTS
+
|d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR