Browse Source

gint/keyboard: detailed test of the new keydev mechanic

master
Lephenixnoir 9 months ago
parent
commit
ca1df5cb20
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
  1. 3
      .gitignore
  2. 6
      CMakeLists.txt
  3. BIN
      assets-fx/fonts/mini.png
  4. BIN
      assets-fx/img/kbd_events.png
  5. BIN
      assets-fx/img/kbd_pressed.png
  6. BIN
      assets-fx/img/kbd_released.png
  7. BIN
      assets-fx/img/keypress.png
  8. BIN
      assets-fx/img/keyrelease.png
  9. BIN
      assets-fx/img/opt_gint_keyboard.png
  10. 81
      include/gintctl/assets.h
  11. 178
      src/gint/keyboard.c
  12. 9
      src/gintctl.c

3
.gitignore

@ -5,3 +5,6 @@ build-cg/
# Targets
gintctl.g1a
gintctl.g3a
# Development files
*.sublime-*

6
CMakeLists.txt

@ -54,13 +54,15 @@ set(ASSETS_fx
assets-fx/img/bopti_1col.png
assets-fx/img/bopti_2col.png
assets-fx/img/bopti_3col.png
assets-fx/img/keypress.png
assets-fx/img/keyrelease.png
assets-fx/img/kbd_events.png
assets-fx/img/kbd_pressed.png
assets-fx/img/kbd_released.png
assets-fx/img/libimg_swords.png
assets-fx/img/opt_dump.png
assets-fx/img/opt_gint_bopti.png
assets-fx/img/opt_gint_cpumem.png
assets-fx/img/opt_gint_gray.png
assets-fx/img/opt_gint_keyboard.png
assets-fx/img/opt_gint_ram.png
assets-fx/img/opt_gint_rtc.png
assets-fx/img/opt_gint_spuram.png

BIN
assets-fx/fonts/mini.png

Before

Width: 112  |  Height: 64  |  Size: 16 KiB

After

Width: 112  |  Height: 64  |  Size: 16 KiB

BIN
assets-fx/img/kbd_events.png

After

Width: 49  |  Height: 7  |  Size: 244 B

BIN
assets-fx/img/kbd_pressed.png

After

Width: 31  |  Height: 44  |  Size: 350 B

BIN
assets-fx/img/kbd_released.png

After

Width: 31  |  Height: 44  |  Size: 362 B

BIN
assets-fx/img/keypress.png

Before

Width: 5  |  Height: 5  |  Size: 146 B

BIN
assets-fx/img/keyrelease.png

Before

Width: 5  |  Height: 5  |  Size: 166 B

BIN
assets-fx/img/opt_gint_keyboard.png

After

Width: 128  |  Height: 8  |  Size: 3.4 KiB

81
include/gintctl/assets.h

@ -0,0 +1,81 @@
//---
// gintctl:assets - List of imported assets
//---
#ifndef _GINTCTL_ASSETS
#define _GINTCTL_ASSETS
#include <libimg.h>
#ifdef FX9860G
extern font_t
font_hexa,
font_mini,
font_title,
font_uf5x7;
extern bopti_image_t
img_bopti_1col,
img_bopti_2col,
img_bopti_3col,
img_kbd_events,
img_kbd_pressed,
img_kbd_released,
img_opt_dump,
img_opt_gint_bopti,
img_opt_gint_cpumem,
img_opt_gint_gray,
img_opt_gint_keyboard,
img_opt_gint_ram,
img_opt_gint_rtc,
img_opt_gint_spuram,
img_opt_gint_timer_callbacks,
img_opt_gint_timers,
img_opt_gint_tlb,
img_opt_libs_jui,
img_opt_main,
img_opt_mem,
img_opt_perf_libprof,
img_opt_perf_render,
img_opt_switch_ctx,
img_opt_switch_ctx_sh3,
img_opt_switch,
img_profile_gray_alpha,
img_profile_gray,
img_profile_mono_alpha,
img_profile_mono,
img_rtc_arrows,
img_rtc_segments,
img_tlb_cells;
extern img_t
img_libimg_swords;
#endif /* FX9860G */
#ifdef FXCG50
extern bopti_image_t
img_applejack_31x27,
img_applejack_36x25,
img_kbd_pressed,
img_kbd_released,
img_potion_17x22,
img_potion_18x22,
img_potion_21x22,
img_rtc_arrows,
img_rtc_segments,
img_swift,
img_swords;
extern img_t
img_libimg_even_odd,
img_libimg_odd_even,
img_libimg_sq_even,
img_libimg_sq_odd,
img_libimg_train;
#endif /* FXCG50 */
#endif /* _GINTCTL_ASSETS */

178
src/gint/keyboard.c

@ -1,15 +1,26 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/drivers/keydev.h>
#include <gint/gint.h>
#include <gint/clock.h>
#include <gintctl/util.h>
#include <gintctl/assets.h>
void position(int row, int col, int *x, int *y, GUNUSED int *w, GUNUSED int *h)
static void position(int row, int col, int *x, int *y, int *w, int *h)
{
#ifdef FX9860G
*y = 10 + 6 * row;
if(row <= 4) *x = 5 + 6 * col;
if(row >= 5) *x = 6 + 7 * col;
*x = 1 + (5 + (row>=5)) * col;
*y = 1 + 4 * row + (row >= 1) + (row >= 3);
*w = 4;
*h = 3 + (row == 0 || row >= 5);
if(row >= 5) *y += 1 + (row - 5);
if((row == 1 || row == 2) && col >= 4)
{
*x += 3 * (row == 2) - 2 * (col == 5);
*y += 1 + (row == 1) - 3 * (col == 5);
*w = 3;
}
#endif
#ifdef FXCG50
@ -26,15 +37,12 @@ void position(int row, int col, int *x, int *y, GUNUSED int *w, GUNUSED int *h)
#endif
}
void render_keyboard(void)
static void render_keyboard(keydev_t *d, int x0, int y0)
{
GUNUSED int x, y, w, h;
#ifdef FXCG50
int x, y, w, h;
extern bopti_image_t img_kbd_pressed;
extern bopti_image_t img_kbd_released;
dimage(15, 21, &img_kbd_released);
#endif
dimage(x0, y0, &img_kbd_released);
for(int row = 0; row < 9; row++)
{
@ -45,26 +53,24 @@ void render_keyboard(void)
{
int code = (major << 4) | (col + 1);
if(code == 0x45) code = 0x07;
if(!keydev_keydown(d, code)) continue;
#ifdef FXCG50
if(!keydown(code)) continue;
position(row, col, &x, &y, &w, &h);
dsubimage(15+x, 21+y, &img_kbd_pressed, x,y,w,h, 0);
#endif
#ifdef FX9860G
extern bopti_image_t img_keypress;
extern bopti_image_t img_keyrelease;
position(row, col, &x, &y, &w, &h);
if(keydown(code)) dimage(x, y, &img_keypress);
else dimage(x, y, &img_keyrelease);
#endif
dsubimage(x0+x, y0+y, &img_kbd_pressed, x,y,w,h, 0);
}
}
}
static void render(key_event_t *last_events, int counter)
static void render_option(int x, int y, char const *name, bool enabled)
{
int w, h;
dsize(name, NULL, &w, &h);
if(enabled) drect(x, y, x+w+1, y+h+1, C_BLACK);
dtext(x+1, y+1, (enabled ? C_WHITE : C_BLACK), name);
}
static char const *key_name(int key)
{
char const *key_names[] = {
"F1", "F2", "F3", "F4", "F5", "F6",
@ -72,12 +78,22 @@ static void render(key_event_t *last_events, int counter)
"ALPHA", "x^2", "^", "EXIT", "Down", "Right",
"X,O,T", "log", "ln", "sin", "cos", "tan",
"frac", "F<>D", "(", ")", ",", "->",
"7", "8", "9", "DEL", "AC/ON", "0x46",
"7", "8", "9", "DEL", "AC.ON", "0x46",
"4", "5", "6", "*", "/", "0x47",
"1", "2", "3", "+", "-", "0x48",
"0", ".", "x10^", "(-)", "EXE", "0x49",
};
if(key == 0) return "N/A";
if(key == KEY_ACON) key = 0x45;
int row = 9 - (key >> 4);
int col = (key & 15) - 1;
return key_names[6*row + col];
}
static void render(keydev_t *d, key_event_t *last_events, int counter)
{
key_event_t ev;
dclear(C_WHITE);
@ -89,8 +105,11 @@ static void render(key_event_t *last_events, int counter)
#ifdef FX9860G
row_print(1, 1, "Keyboard state");
int y0=52, dy=8, maxev=6;
int x1=55, x2=67;
dimage(0, 56, &img_opt_gint_keyboard);
int y0=47, dy=7, maxev=6;
int x1=87, x2=117;
font_t const *old_font = dfont(&font_mini);
#endif
for(int i=0, y=y0; i < maxev; i++, y-=dy)
@ -98,54 +117,123 @@ static void render(key_event_t *last_events, int counter)
ev = last_events[(counter+15 - i) % 16];
if(ev.type == KEYEV_NONE) continue;
int key = (ev.key == KEY_ACON ? 0x45 : ev.key);
int row = 9 - (key >> 4);
int col = (key & 15) - 1;
char const *name = key_names[6*row + col];
int t = ev.type;
dsubimage(x1, y, &img_kbd_events,
(t == KEYEV_DOWN ? 1 : (t == KEYEV_UP ? 7 : 13)),
0, 5, 7, DIMAGE_NONE);
dtext(x1 + 7, y + 1, C_BLACK, key_name(ev.key));
if(ev.type == KEYEV_UP)
dprint(x2, y, C_BLACK, "Up %s", name);
if(ev.type == KEYEV_DOWN)
dprint(x1, y, C_BLACK, "Down %s", name);
if(ev.shift)
dsubimage(x2, y, &img_kbd_events, 19, 0, 5, 7, DIMAGE_NONE);
if(ev.alpha)
dsubimage(x2+5, y, &img_kbd_events, 25, 0, 5, 7, DIMAGE_NONE);
}
render_keyboard();
render_keyboard(d, _(2,15), _(10,21));
#ifdef FX9860G
int tr = d->tr.enabled;
dtext(35, 10, C_BLACK, "Shift:");
render_option(35, 16, "Del", (tr & KEYDEV_TR_DELAYED_SHIFT) != 0);
render_option(47, 16, "Ins", (tr & KEYDEV_TR_INSTANT_SHIFT) != 0);
dtext(35, 24, C_BLACK, "Alpha:");
render_option(35, 30, "Del", (tr & KEYDEV_TR_DELAYED_ALPHA) != 0);
render_option(47, 30, "Ins", (tr & KEYDEV_TR_INSTANT_ALPHA) != 0);
render_option(35, 38, "-Mods", (tr & KEYDEV_TR_DELETE_MODIFIERS) != 0);
render_option(35, 46, "-Rels", (tr & KEYDEV_TR_DELETE_RELEASES) != 0);
render_option(64, 9, "Reps", (tr & KEYDEV_TR_REPEATS) != 0);
if(d->delayed_shift)
dsubimage(54, 10, &img_kbd_events, 43, 1, 5, 5, DIMAGE_NONE);
else if(d->pressed_shift)
dsubimage(54, 10, &img_kbd_events, 37, 1, 5, 5, DIMAGE_NONE);
else
dsubimage(54, 10, &img_kbd_events, 31, 1, 5, 5, DIMAGE_NONE);
if(d->delayed_alpha)
dsubimage(55, 24, &img_kbd_events, 43, 1, 5, 5, DIMAGE_NONE);
else if(d->pressed_alpha)
dsubimage(55, 24, &img_kbd_events, 37, 1, 5, 5, DIMAGE_NONE);
else
dsubimage(55, 24, &img_kbd_events, 31, 1, 5, 5, DIMAGE_NONE);
dtext(65, 17, C_BLACK, key_name(d->rep_key));
dprint(65, 29, C_BLACK, "L:%d", d->events_lost);
dfont(old_font);
#endif
}
int handle_event(key_event_t *last_events, int counter)
static int handle_event(keydev_t *d, key_event_t *last_events, int counter)
{
key_event_t ev = last_events[(counter + 15) % 16];
if(ev.type != KEYEV_DOWN) return 0;
if(ev.key == KEY_EXIT) return 1;
if(ev.key == KEY_MENU) render(last_events, counter), dupdate(), gint_osmenu();
if(ev.key == KEY_MENU)
{
render(d, last_events, counter);
dupdate();
gint_osmenu();
return 0;
}
keydev_transform_t tr = keydev_transform(d);
if(ev.key == KEY_F1) tr.enabled ^= KEYDEV_TR_DELAYED_SHIFT;
if(ev.key == KEY_F2) tr.enabled ^= KEYDEV_TR_INSTANT_SHIFT;
if(ev.key == KEY_F3) tr.enabled ^= KEYDEV_TR_DELAYED_ALPHA;
if(ev.key == KEY_F4) tr.enabled ^= KEYDEV_TR_INSTANT_ALPHA;
if(ev.key == KEY_F5) tr.enabled ^= KEYDEV_TR_REPEATS;
if(ev.key == KEY_F6) tr.enabled ^= KEYDEV_TR_DELETE_MODIFIERS;
keydev_set_transform(d, tr);
return 0;
}
/* gintct_gint_keybaord: Real-time keyboard visualization */
static int repeater(GUNUSED int key, GUNUSED int duration, GUNUSED int count)
{
if(count == 4) return -1;
/* Wait 250 ms until the next repeat */
return 250000;
}
/* gintct_gint_keyboard: Real-time keyboard visualization */
void gintctl_gint_keyboard(void)
{
keydev_t *d = keydev_std();
keydev_transform_t tr = keydev_transform(d);
keydev_transform_t base = { .enabled = 0, .repeater = repeater };
keydev_set_transform(d, base);
/* All initialized with type=KEYEV_NONE */
key_event_t last_events[16] = { 0 };
key_event_t ev;
int counter = 0;
while(1)
bool loop = true;
while(loop)
{
render(last_events, counter);
render(d, last_events, counter);
dupdate();
/* Redraw at each event if needed */
last_events[counter] = waitevent(NULL);
while((ev = keydev_read(d)).type == KEYEV_NONE) sleep();
last_events[counter] = ev;
counter = (counter+1) % 16;
if(handle_event(last_events, counter)) return;
if(handle_event(d, last_events, counter)) break;
while((ev = pollevent()).type != KEYEV_NONE)
while((ev = keydev_read(d)).type != KEYEV_NONE && loop)
{
last_events[counter] = ev;
counter = (counter+1) % 16;
if(handle_event(last_events, counter)) return;
if(handle_event(d, last_events, counter)) loop = false;
}
}
keydev_set_transform(d, tr);
}

9
src/gintctl.c

@ -3,11 +3,13 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/gint.h>
#include <gint/drivers/keydev.h>
#include <gint/hardware.h>
#include <gint/kprint.h>
#include <gintctl/util.h>
#include <gintctl/menu.h>
#include <gintctl/assets.h>
#include <gintctl/gint.h>
#include <gintctl/perf.h>
@ -132,7 +134,6 @@ static void draw(struct menu *menu)
else gintctl_main();
#ifdef FX9860G
extern bopti_image_t img_opt_main;
dimage(0, 56, &img_opt_main);
#endif
@ -166,10 +167,14 @@ int main(GUNUSED int isappli, GUNUSED int optnum)
#ifdef FX9860G
/* Use the Unicode font uf5x7 on fx-9860G */
extern font_t font_uf5x7;
dfont(&font_uf5x7);
#endif
keydev_transform_t tr = keydev_transform(keydev_std());
tr.enabled |= KEYDEV_TR_DELAYED_SHIFT | KEYDEV_TR_INSTANT_SHIFT;
tr.enabled |= KEYDEV_TR_DELAYED_ALPHA | KEYDEV_TR_INSTANT_ALPHA;
keydev_set_transform(keydev_std(), tr);
key_event_t ev;
int key = 0;
struct menu *menu = NULL;

Loading…
Cancel
Save