gint/src/keysc/getkey.c

116 lines
2.7 KiB
C
Raw Normal View History

//---
// gint:keysc:getkey - High-level keyboard monitoring function
//---
#include <gint/keyboard.h>
#include <gint/drivers/keydev.h>
#include <gint/gint.h>
#include <gint/defs/types.h>
#ifdef FX9860G
#include <gint/drivers/t6k11.h>
#endif
/* Feature function */
static getkey_feature_t feature_function = NULL;
/* getkey(): Wait for a key press */
key_event_t getkey(void)
{
return getkey_opt(GETKEY_DEFAULT, NULL);
}
/* getkey_opt(): Enhanced getkey() */
key_event_t getkey_opt(int opt, volatile int *timeout)
{
keydev_t *d = keydev_std();
keydev_transform_t tr = keydev_transform(d);
key_event_t e;
int o = KEYDEV_TR_REPEATS +
KEYDEV_TR_DELETE_MODIFIERS +
KEYDEV_TR_DELETE_RELEASES +
(opt & (GETKEY_MOD_SHIFT + GETKEY_MOD_ALPHA));
keydev_set_transform(d, (keydev_transform_t){ o, tr.repeater });
while(1)
{
e = keydev_read(d);
if(e.type == KEYEV_NONE && timeout && *timeout) break;
/* Skip repeat events that are not enabled by options */
if(e.type == KEYEV_HOLD && !(opt & GETKEY_REP_ALL))
{
if(!(opt & GETKEY_REP_ARROWS))
continue;
if(e.key != KEY_LEFT && e.key != KEY_RIGHT &&
e.key != KEY_UP && e.key != KEY_DOWN)
continue;
}
#ifdef FX9860G
/* Backlight toggle */
if((opt & GETKEY_BACKLIGHT) && e.type == KEYEV_DOWN &&
e.key == KEY_OPTN && e.shift && !e.alpha)
{
t6k11_backlight(-1);
continue;
}
#endif
/* Return-to-menu */
if((opt & GETKEY_MENU) && e.type == KEYEV_DOWN &&
e.key == KEY_MENU && !e.shift && !e.alpha)
{
core, tmu: add gint_switch(), return to menu, and improve timer code * Add the gint_switch() function which executes user-provided code from the system (CASIOWIN) context. * Added interrupt masks to the core context (should have been there long ago). * Added the gint_osmenu() function that switches out of gint to invoke GetKeyWait() and inject KEY_CTRL_MENU to trigger the main menu. This uses many CASIOWIN syscalls, but we don't care because gint is unloaded. Trickery is used to catch the key following the return in the add-in and/or display a new application frame before GetKeyWait() even finishes after coming back. This is only available on fx9860g for now. * Removed any public syscall definition to clear up interfaces. * Patched the DMA interruption problem in a weird way on fxcg50, a driver function will be used to do that properly eventually. * Changed the driver model to save driver contexts in preallocated spaces instead of on the stack for overall less risk. * Enabled return-to-menu with the MENU key on fx9860g in getkey(). * Changed the keyboard driver to emit releases before presses, as a return-to-menu acts as a press+release of different keys in a single driver frame, which confuses getkey(). * Fixed a really stupid bug in memcpy() that made the function really not work. Improvements in the timer driver: * Expose ETMU modules as SH7705_TMU and SH7305_TMU in <gint/mpu/tmu.h>. * Remove the timer_t structures, using SH*_ETMU and SH*_TMU instead. Only interrupt gate entries are left hardcoded. * Discovered that not only every write to the TCNT or TCR of an ETMU takes about 1/32k of a second (hinting at registers being powered by the same clock as the timer), but every write occuring while a previous write is pending is *lost*. This led to terrible bugs when switching ETMU contexts too fast in gint_switch(). * Removed an internal timer_address() function. * Overall simplified the handling of timers and the initialization step.
2020-05-10 14:03:41 +02:00
gint_osmenu();
continue;
}
if(e.type == KEYEV_DOWN || e.type == KEYEV_HOLD)
{
/* Custom global features */
bool accepted = false;
if((opt & GETKEY_FEATURES) && feature_function)
accepted = feature_function(e);
/* Return if the event has not been accepted yet */
if(!accepted) break;
}
}
/* Restore previous transform settings */
keydev_set_transform(d, tr);
return e;
}
/* getkey_feature_function(): Get the current feature function */
getkey_feature_t getkey_feature_function(void)
{
return feature_function;
}
/* getkey_set_feature_function(): Set the global feature function */
void getkey_set_feature_function(getkey_feature_t function)
{
feature_function = function;
}
/* Deprecated repeat functions */
void getkey_repeat(int first, int next)
{
keydev_set_standard_repeats(keydev_std(), first * 1000, next * 1000);
}
getkey_profile_t getkey_repeat_profile(void)
{
return keydev_transform(keydev_std()).repeater;
}
/* getkey_set_repeat_profile(): Set the repeat profile function */
void getkey_set_repeat_profile(getkey_profile_t profile)
{
keydev_transform_t tr = keydev_transform(keydev_std());
tr.repeater = profile;
keydev_set_transform(keydev_std(), tr);
}