From a1dc75a2bcd6a97bc78617c93475b7b605ee0f45 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 28 Dec 2021 10:45:34 -0800 Subject: [PATCH] Implemented scroll x/y --- projects/examples/blank.tal | 22 +++++++++---------- projects/examples/demos/piano.tal | 30 ++++++++++++++----------- projects/examples/devices/mouse.tal | 25 ++++++++++----------- src/devices/mouse.c | 34 +++++++++++++++-------------- src/devices/mouse.h | 4 ++-- src/uxnemu.c | 4 ++-- 6 files changed, 62 insertions(+), 57 deletions(-) diff --git a/projects/examples/blank.tal b/projects/examples/blank.tal index af91236..0eeb812 100644 --- a/projects/examples/blank.tal +++ b/projects/examples/blank.tal @@ -22,17 +22,17 @@ ( devices ) -|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] -|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] -|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] -|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] -|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] -|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] -|80 @Controller [ &vector $2 &button $1 &key $1 ] -|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] -|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] +|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 +|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 +|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 +|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 +|40 @Audio1 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 +|50 @Audio2 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 +|60 @Audio3 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 +|80 @Controller &vector $2 &button $1 &key $1 +|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2 +|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 +|b0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ( variables ) diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal index 2679790..76bf2b8 100644 --- a/projects/examples/demos/piano.tal +++ b/projects/examples/demos/piano.tal @@ -20,14 +20,13 @@ ( devices ) -|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] -|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ] -|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] -|70 @Midi [ &vector $2 &channel $1 ¬e $1 &velocity $1 ] -|80 @Controller [ &vector $2 &button $1 &key $1 ] -|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] +|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 +|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 +|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 +|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 +|80 @Controller &vector $2 &button $1 &key $1 +|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2 +|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ( variables ) @@ -35,11 +34,16 @@ @last-note $1 @octave $1 -@pointer [ &x $2 &y $2 ] -@center [ &x $2 &y $2 ] -@adsr-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] -@wave-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] -@octave-view [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] +@pointer + &x $2 &y $2 +@center + &x $2 &y $2 +@adsr-view + &x1 $2 &y1 $2 &x2 $2 &y2 $2 +@wave-view + &x1 $2 &y1 $2 &x2 $2 &y2 $2 +@octave-view + &x1 $2 &y1 $2 &x2 $2 &y2 $2 ( program ) diff --git a/projects/examples/devices/mouse.tal b/projects/examples/devices/mouse.tal index ee28f86..f8b6438 100644 --- a/projects/examples/devices/mouse.tal +++ b/projects/examples/devices/mouse.tal @@ -8,15 +8,17 @@ ( devices ) -|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] -|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] +|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 +|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 +|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2 |0000 @color $1 -@line [ &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 ] -@pointer [ &x $2 &y $2 &lastx $2 &lasty $2 &state $1 ] +@line + &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 +@pointer + &x $2 &y $2 &lastx $2 &lasty $2 &state $1 ( program ) @@ -73,19 +75,16 @@ BRK @draw-cursor ( -- ) - ;pointer_icn .Screen/addr DEO2 + ;pointer-icn .Screen/addr DEO2 + ( clear last cursor ) .pointer/x LDZ2 .Screen/x DEO2 .pointer/y LDZ2 .Screen/y DEO2 #40 .Screen/sprite DEO - ( record pointer positions ) - .Mouse/x DEI2 .pointer/x STZ2 - .Mouse/y DEI2 .pointer/y STZ2 - ( draw new cursor ) - .pointer/x LDZ2 .Screen/x DEO2 - .pointer/y LDZ2 .Screen/y DEO2 + .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 + .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 #43 .Mouse/state DEI #00 NEQ DUP ADD SUB .Screen/sprite DEO RTN @@ -118,4 +117,4 @@ RTN RTN -@pointer_icn [ 80c0 e0f0 f8e0 1000 ] +@pointer-icn 80c0 e0f0 f8e0 1000 diff --git a/src/devices/mouse.c b/src/devices/mouse.c index 77df242..7671cda 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -13,22 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -void -mouse_xy(Device *d, Uint16 x, Uint16 y) -{ - poke16(d->dat, 0x2, x); - poke16(d->dat, 0x4, y); - uxn_eval(d->u, d->vector); -} - -void -mouse_z(Device *d, Uint8 z) -{ - d->dat[7] = z; - uxn_eval(d->u, d->vector); - d->dat[7] = 0x00; -} - void mouse_down(Device *d, Uint8 mask) { @@ -41,4 +25,22 @@ mouse_up(Device *d, Uint8 mask) { d->dat[6] &= (~mask); uxn_eval(d->u, d->vector); +} + +void +mouse_pos(Device *d, Uint16 x, Uint16 y) +{ + poke16(d->dat, 0x2, x); + poke16(d->dat, 0x4, y); + uxn_eval(d->u, d->vector); +} + +void +mouse_mod(Device *d, Uint16 x, Uint16 y) +{ + poke16(d->dat, 0xa, x); + poke16(d->dat, 0xc, y); + uxn_eval(d->u, d->vector); + poke16(d->dat, 0xa, 0); + poke16(d->dat, 0xc, 0); } \ No newline at end of file diff --git a/src/devices/mouse.h b/src/devices/mouse.h index 607ee78..839a8fe 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -void mouse_xy(Device *d, Uint16 x, Uint16 y); -void mouse_z(Device *d, Uint8 z); void mouse_down(Device *d, Uint8 mask); void mouse_up(Device *d, Uint8 mask); +void mouse_pos(Device *d, Uint16 x, Uint16 y); +void mouse_mod(Device *d, Uint16 x, Uint16 y); diff --git a/src/uxnemu.c b/src/uxnemu.c index 4ef5676..4d802be 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -501,13 +501,13 @@ run(Uxn *u) uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0)); /* Mouse */ else if(event.type == SDL_MOUSEWHEEL) - mouse_z(devmouse, event.wheel.y); + mouse_mod(devmouse, event.wheel.x, event.wheel.y); else if(event.type == SDL_MOUSEBUTTONUP) mouse_up(devmouse, 0x1 << (event.button.button - 1)); else if(event.type == SDL_MOUSEBUTTONDOWN) mouse_down(devmouse, 0x1 << (event.button.button - 1)); else if(event.type == SDL_MOUSEMOTION) - mouse_xy(devmouse, + mouse_pos(devmouse, clamp(event.motion.x - PAD, 0, ppu.width - 1), clamp(event.motion.y - PAD, 0, ppu.height - 1)); /* Controller */