From a1267aea4ebbd7296a9236d8ae94d0f70ce76259 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 9 Feb 2021 17:43:53 -0800 Subject: [PATCH] Added mouse-down detect to example --- emulator.c | 7 +++++-- examples/mouse.usm | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/emulator.c b/emulator.c index 75249c0..593a23f 100644 --- 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 index 968ab1c..3b61950 100644 --- 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