Implemented scroll x/y

This commit is contained in:
neauoire 2021-12-28 10:45:34 -08:00
parent 8488ce64a4
commit a1dc75a2bc
6 changed files with 62 additions and 57 deletions

View File

@ -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 )

View File

@ -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 &note $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 )

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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 */