Pass fn keys directly to the supervisor

This commit is contained in:
neauoire 2022-01-07 10:55:09 -08:00
parent 19a8e56cd6
commit 38334a633b
5 changed files with 42 additions and 4 deletions

View File

@ -29,7 +29,7 @@
|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
|80 @Controller &vector $2 &button $1 &key $1 &func $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $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

View File

@ -29,6 +29,7 @@
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|80 @Controller &vector $2 &button $1 &key $1 &func $1
( variables )
@ -53,6 +54,7 @@
( vectors )
;on-error .System/vector DEO2
;on-frame .Screen/vector DEO2
;on-button .Controller/vector DEO2
BRK
@ -63,6 +65,12 @@ BRK
BRK
@on-button ( -> )
.Controller/func DEI DEBUG
BRK
@on-error ( -> )
( background )

View File

@ -39,4 +39,14 @@ controller_key(Device *d, Uint8 key)
uxn_eval(d->u, d->vector);
d->dat[3] = 0x00;
}
}
void
controller_special(Device *d, Uint8 key)
{
if(key) {
d->dat[4] = key;
uxn_eval(d->u, d->vector);
d->dat[4] = 0x00;
}
}

View File

@ -12,4 +12,5 @@ WITH REGARD TO THIS SOFTWARE.
void controller_down(Device *d, Uint8 mask);
void controller_up(Device *d, Uint8 mask);
void controller_key(Device *d, Uint8 key);
void controller_key(Device *d, Uint8 key);
void controller_special(Device *d, Uint8 key);

View File

@ -272,8 +272,8 @@ start(Uxn *u, char *rom)
/* audio2 */ uxn_port(u, 0x5, 0xffff, audio_dei, audio_deo);
/* audio3 */ uxn_port(u, 0x6, 0xffff, audio_dei, audio_deo);
/* unused */ uxn_port(u, 0x7, 0xffff, nil_dei, nil_deo);
/* control */ devctrl = uxn_port(u, 0x8, 0xffff, nil_dei, nil_deo);
/* mouse */ devmouse = uxn_port(u, 0x9, 0xffff, nil_dei, nil_deo);
/* control */ devctrl = uxn_port(u, 0x8, 0x0000, nil_dei, nil_deo);
/* mouse */ devmouse = uxn_port(u, 0x9, 0x0000, nil_dei, nil_deo);
/* file */ uxn_port(u, 0xa, 0xffff, nil_dei, file_deo);
/* datetime */ uxn_port(u, 0xb, 0xffff, datetime_dei, nil_deo);
/* unused */ uxn_port(u, 0xc, 0xffff, nil_dei, nil_deo);
@ -285,6 +285,7 @@ start(Uxn *u, char *rom)
uxn_port(&supervisor, 0x0, 0xffff, system_dei, system_deo);
uxn_port(&supervisor, 0x1, 0xffff, nil_dei, console_deo);
uxn_port(&supervisor, 0x2, 0xffff, screen_dei, screen_deo);
uxn_port(&supervisor, 0x8, 0x0000, nil_dei, nil_deo);
uxn_eval(&supervisor, PAGE_PROGRAM);
@ -348,6 +349,22 @@ get_button(SDL_Event *event)
return 0x00;
}
static Uint8
get_fkey(SDL_Event *event)
{
switch(event->key.keysym.sym) {
case SDLK_F1: return 0x01;
case SDLK_F2: return 0x02;
case SDLK_F3: return 0x04;
case SDLK_F4: return 0x08;
case SDLK_F5: return 0x10;
case SDLK_F6: return 0x20;
case SDLK_F7: return 0x40;
case SDLK_F8: return 0x80;
}
return 0x00;
}
static Uint8
get_button_joystick(SDL_Event *event)
{
@ -442,6 +459,8 @@ run(Uxn *u)
controller_key(devctrl, get_key(&event));
else if(get_button(&event))
controller_down(devctrl, get_button(&event));
else if(get_fkey(&event))
controller_special(&supervisor.dev[0x8], get_fkey(&event));
else
do_shortcut(u, &event);
ksym = event.key.keysym.sym;