From b23ed9629e3b64995475fde1e8d6c4ce5083af48 Mon Sep 17 00:00:00 2001 From: calamari Date: Sat, 24 Sep 2022 19:48:07 -0700 Subject: [PATCH 1/6] Add HWCALC entry for fx-9860G Slim --- include/gint/hardware.h | 2 ++ src/kernel/hardware.c | 3 ++- src/kernel/inth.S | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/gint/hardware.h b/include/gint/hardware.h index 8e86b80..6955e4d 100644 --- a/include/gint/hardware.h +++ b/include/gint/hardware.h @@ -105,6 +105,8 @@ void hw_detect(void); #define HWCALC_FXCG50 5 /* fx-CG 50 emulator, hardcoded in kernel/inth.S */ #define HWCALC_FXCG_MANAGER 6 +/* fx-9860G Slim, SH-3-based fx-9860G with hardware differences */ +#define HWCALC_FX9860G_SLIM 7 /* ** Keyboard diff --git a/src/kernel/hardware.c b/src/kernel/hardware.c index 732cd93..f94fcaa 100644 --- a/src/kernel/hardware.c +++ b/src/kernel/hardware.c @@ -69,7 +69,8 @@ void hw_detect(void) gint[HWCALC] = HWCALC_FX9860G_SH4; if(gint[HWMPU] == HWMPU_SH7337 || gint[HWMPU] == HWMPU_SH7355) { - gint[HWCALC] = HWCALC_FX9860G_SH3; + gint[HWCALC] = (SH7705_PFC.PEDR & 0x08) ? HWCALC_FX9860G_SH3 : + HWCALC_FX9860G_SLIM; } /* Tell Graph 35+E II from OS version (this is accurate unless someone diff --git a/src/kernel/inth.S b/src/kernel/inth.S index b071afc..4823cd7 100644 --- a/src/kernel/inth.S +++ b/src/kernel/inth.S @@ -102,7 +102,7 @@ _gint_inth_7305: #ifdef FX9860G -/* SH7705-TYPE INTERRUT HANDLER ENTRY - 56 BYTES */ +/* SH7705-TYPE INTERRUPT HANDLER ENTRY - 56 BYTES */ _gint_inth_7705: /* Save caller-saved registers as before */ -- 2.45.0 From a4adc5e1bdf7b29a9386b7104b11be27ef08677d Mon Sep 17 00:00:00 2001 From: calamari Date: Sat, 24 Sep 2022 19:49:29 -0700 Subject: [PATCH 2/6] Support fx-9860G Slim backlight --- src/t6k11/t6k11.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/t6k11/t6k11.c b/src/t6k11/t6k11.c index 89fbc82..e4e2773 100644 --- a/src/t6k11/t6k11.c +++ b/src/t6k11/t6k11.c @@ -168,8 +168,16 @@ void t6k11_backlight(int setting) TODO: Document the PFC to remove these addresses */ if(isSH3()) { - port = (void *)0xa400012c; - mask = 0x80; + if (gint[HWCALC] == HWCALC_FX9860G_SLIM) + { + port = (void *)0xa4000126; + mask = 0x20; + } + else + { + port = (void *)0xa400012c; + mask = 0x80; + } } else { -- 2.45.0 From 98fea4f2ec969040227f2476186cab54f81d1e2c Mon Sep 17 00:00:00 2001 From: calamari Date: Sun, 25 Sep 2022 01:34:40 -0700 Subject: [PATCH 3/6] Translate fx-9860G Slim keyboard scancodes to standard scancodes The Slim has two keys that the standard 9860G doesn't: HELP and LIGHT. Those are mapped to virtual scancodes, resulting in virtual keycodes. --- include/gint/drivers/keydev.h | 8 +++--- include/gint/keyboard.h | 2 +- include/gint/keycodes.h | 4 +++ src/keysc/getkey.c | 3 ++- src/keysc/iokbd.c | 48 ++++++++++++++++++++++++++++++++++- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/include/gint/drivers/keydev.h b/include/gint/drivers/keydev.h index 9d68017..39132cd 100644 --- a/include/gint/drivers/keydev.h +++ b/include/gint/drivers/keydev.h @@ -135,9 +135,9 @@ typedef struct { is useful for demo/replays that input events without the physical keyboard, and a couple of corner uses like control over USB. - The keyboard device has built-in event transformations, which modifty the + The keyboard device has built-in event transformations, which modify the stream of events by adding information, combining modifiers, and removing - undesired events. Because the event transformation reky on the current state + undesired events. Because the event transformation rely on the current state of the keyboard, they must be run by the driver whenever events are read, so they are tied to the device. @@ -173,7 +173,7 @@ typedef struct { /* Candidate key for repeats (or 0 if no key is candidate yet) */ int rep_key; - /* Number of repeats alreay sent */ + /* Number of repeats already sent */ int rep_count; /* Time since key was first pressed (us) */ int rep_time; @@ -181,7 +181,7 @@ typedef struct { int rep_delay; /* Latest state of keys we are aware of. At every processing step, the - different between this and the fresh information is queued and this + difference between this and the fresh information is queued and this is updated. state_now is identical to the real state obtained from the device unless earlier events failed to be queued, in which case a difference is maintained so they will be reconsidered later. */ diff --git a/include/gint/keyboard.h b/include/gint/keyboard.h index 13af587..edbbcee 100644 --- a/include/gint/keyboard.h +++ b/include/gint/keyboard.h @@ -207,7 +207,7 @@ enum { /* Enable modifiers keys */ GETKEY_MOD_SHIFT = 0x01, GETKEY_MOD_ALPHA = 0x02, - /* SHIFT + OPTN toggles backlight (requires GETKEY_MOD_SHIFT) */ + /* SHIFT + OPTN (requires GETKEY_MOD_SHIFT) or LIGHT toggles backlight */ GETKEY_BACKLIGHT = 0x04, /* MENU triggers a task switch and displays the main menu */ GETKEY_MENU = 0x08, diff --git a/include/gint/keycodes.h b/include/gint/keycodes.h index d3fdd48..ec698ff 100644 --- a/include/gint/keycodes.h +++ b/include/gint/keycodes.h @@ -75,6 +75,10 @@ enum { of the matrix one could use a ghosting effect to boot the calc. */ KEY_ACON = 0x07, + /* Virtual key codes */ + KEY_HELP = 0x20, /* fx-9860G Slim: 0x75 */ + KEY_LIGHT = 0x10, /* fx-9860G Slim: 0x76 */ + /* Key aliases (handle with care =D) */ KEY_X2 = KEY_SQUARE, KEY_CARET = KEY_POWER, diff --git a/src/keysc/getkey.c b/src/keysc/getkey.c index 4912170..c068f76 100644 --- a/src/keysc/getkey.c +++ b/src/keysc/getkey.c @@ -51,7 +51,8 @@ key_event_t getkey_opt(int opt, volatile int *timeout) #ifdef FX9860G /* Backlight toggle */ if((opt & GETKEY_BACKLIGHT) && e.type == KEYEV_DOWN && - e.key == KEY_OPTN && e.shift && !e.alpha) + ((e.key == KEY_LIGHT) || + (e.key == KEY_OPTN && e.shift && !e.alpha))) { t6k11_backlight(-1); continue; diff --git a/src/keysc/iokbd.c b/src/keysc/iokbd.c index fbadb4c..bf60e9a 100644 --- a/src/keysc/iokbd.c +++ b/src/keysc/iokbd.c @@ -4,6 +4,7 @@ #include #include +#include /* This file is SH7705-only. */ #ifdef FX9860G @@ -111,12 +112,57 @@ uint8_t iokbd_row(int row) return input; } +static const uint16_t SLIM_SC[] = { + 0x0940, 0x0920, 0x0910, 0x0908, 0x0904, 0x0902, + 0x0840, 0x0820, 0x0810, 0x0808, + 0x0740, 0x0720, 0x0710, 0x0708, 0x0704, 0x0702, + 0x0640, 0x0620, 0x0610, 0x0608, 0x0604, 0x0602, + 0x0540, 0x0520, 0x0510, 0x0508, 0x0504, 0x0502, + 0x0440, 0x0420, 0x0410, 0x0408, 0x0404, 0x0402, + 0x0340, 0x0320, 0x0310, 0x0308, 0x0304, 0x0302, + 0x0240, 0x0220, 0x0210, 0x0208, 0x0204, 0x0202, + 0x0101, + 0x0020, 0x0010, 0x0008, 0x0004, 0x0002 +}; + +#define SCANCODE_COUNT (sizeof(SLIM_SC) / sizeof(uint16_t)) + +static const uint16_t SLIM_TR[] = { + 0x0940, 0x0620, 0x0720, 0x0710, 0x0804, 0x0802, + 0x0808, 0x0640, 0x0840, 0x0740, + 0x0910, 0x0608, 0x0502, 0x0810, 0x0280, 0x0180, + 0x0920, 0x0610, 0x0504, 0x0820, 0x0704, 0x0702, + 0x0904, 0x0602, 0x0420, 0x0320, 0x0220, 0x0120, + 0x0908, 0x0604, 0x0440, 0x0340, 0x0240, 0x0140, + 0x0708, 0x0520, 0x0408, 0x0308, 0x0208, 0x0108, + 0x0902, 0x0540, 0x0410, 0x0310, 0x0210, 0x0110, + 0x0001, + 0x0510, 0x0508, 0x0304, 0x0104, 0x0204 +}; + /* iokbd_scan() - scan ports A/B/M to generate 12 rows of key data */ void iokbd_scan(uint8_t *scan) { - /* Scan each row independently; the gain from scanning them altogether + /* Scan each row independently; the gain from scanning them all together is probably not worth it */ for(int i = 0; i < 12; i++) scan[i] = iokbd_row(i); + + /* Translate fx-9860G Slim scancodes to standard scancodes */ + if (gint[HWCALC] == HWCALC_FX9860G_SLIM) + { + uint8_t slim_scan[12]; + for (uint i = 0; i < 10; i++) + { + slim_scan[i] = scan[i]; + scan[i] = 0x00; + } + + for (uint i = 0; i < SCANCODE_COUNT; ++i) + { + if (slim_scan[SLIM_SC[i] >> 8] & (SLIM_SC[i] & 0xFF)) + scan[SLIM_TR[i] >> 8] |= (SLIM_TR[i] & 0xFF); + } + } } #endif /* FX9860G */ -- 2.45.0 From 5c331e5fa0209be2c62c21c772209de426898686 Mon Sep 17 00:00:00 2001 From: calamari Date: Sun, 25 Sep 2022 10:37:18 -0700 Subject: [PATCH 4/6] Add isSlim() macro --- include/gint/hardware.h | 6 ++++++ src/keysc/iokbd.c | 2 +- src/t6k11/t6k11.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/gint/hardware.h b/include/gint/hardware.h index 6955e4d..06924fd 100644 --- a/include/gint/hardware.h +++ b/include/gint/hardware.h @@ -45,6 +45,12 @@ void hw_detect(void); #define isSH4() (!isSH3()) #endif +#if defined(FX9860G) +#define isSlim() (gint[HWCALC] == HWCALC_FX9860G_SLIM) +#else +#define isSlim() 0 +#endif + #ifdef FXCG50 #define isSH3() 0 #define isSH4() 1 diff --git a/src/keysc/iokbd.c b/src/keysc/iokbd.c index bf60e9a..064ac7e 100644 --- a/src/keysc/iokbd.c +++ b/src/keysc/iokbd.c @@ -148,7 +148,7 @@ void iokbd_scan(uint8_t *scan) for(int i = 0; i < 12; i++) scan[i] = iokbd_row(i); /* Translate fx-9860G Slim scancodes to standard scancodes */ - if (gint[HWCALC] == HWCALC_FX9860G_SLIM) + if (isSlim()) { uint8_t slim_scan[12]; for (uint i = 0; i < 10; i++) diff --git a/src/t6k11/t6k11.c b/src/t6k11/t6k11.c index e4e2773..678724a 100644 --- a/src/t6k11/t6k11.c +++ b/src/t6k11/t6k11.c @@ -168,7 +168,7 @@ void t6k11_backlight(int setting) TODO: Document the PFC to remove these addresses */ if(isSH3()) { - if (gint[HWCALC] == HWCALC_FX9860G_SLIM) + if (isSlim()) { port = (void *)0xa4000126; mask = 0x20; -- 2.45.0 From ddf340cccd2ab53433428cda3f88d1d18a8ac3bc Mon Sep 17 00:00:00 2001 From: calamari Date: Sun, 25 Sep 2022 10:37:41 -0700 Subject: [PATCH 5/6] Support gint_osmenu() on fx-9860G Slim --- src/kernel/osmenu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kernel/osmenu.c b/src/kernel/osmenu.c index 3f6a608..d0ebb5c 100644 --- a/src/kernel/osmenu.c +++ b/src/kernel/osmenu.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -17,7 +18,10 @@ static int __osmenu_id; static void __osmenu_handler(void) { - __PutKeyCode(0x04, 0x09, 0); + if (isSlim()) + __PutKeyCode(0x07, 0x0A, 0); + else + __PutKeyCode(0x04, 0x09, 0); __Timer_Stop(__osmenu_id); __Timer_Deinstall(__osmenu_id); -- 2.45.0 From a735e074d88f5d41e15d37f9eb62cc0499ffabb0 Mon Sep 17 00:00:00 2001 From: calamari Date: Sun, 25 Sep 2022 11:23:07 -0700 Subject: [PATCH 6/6] Clean up style mismatch --- src/kernel/osmenu.c | 2 +- src/keysc/iokbd.c | 8 ++++---- src/t6k11/t6k11.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kernel/osmenu.c b/src/kernel/osmenu.c index d0ebb5c..3c54465 100644 --- a/src/kernel/osmenu.c +++ b/src/kernel/osmenu.c @@ -18,7 +18,7 @@ static int __osmenu_id; static void __osmenu_handler(void) { - if (isSlim()) + if(isSlim()) __PutKeyCode(0x07, 0x0A, 0); else __PutKeyCode(0x04, 0x09, 0); diff --git a/src/keysc/iokbd.c b/src/keysc/iokbd.c index 064ac7e..b33ed10 100644 --- a/src/keysc/iokbd.c +++ b/src/keysc/iokbd.c @@ -148,18 +148,18 @@ void iokbd_scan(uint8_t *scan) for(int i = 0; i < 12; i++) scan[i] = iokbd_row(i); /* Translate fx-9860G Slim scancodes to standard scancodes */ - if (isSlim()) + if(isSlim()) { uint8_t slim_scan[12]; - for (uint i = 0; i < 10; i++) + for(uint i = 0; i < 10; i++) { slim_scan[i] = scan[i]; scan[i] = 0x00; } - for (uint i = 0; i < SCANCODE_COUNT; ++i) + for(uint i = 0; i < SCANCODE_COUNT; ++i) { - if (slim_scan[SLIM_SC[i] >> 8] & (SLIM_SC[i] & 0xFF)) + if(slim_scan[SLIM_SC[i] >> 8] & (SLIM_SC[i] & 0xFF)) scan[SLIM_TR[i] >> 8] |= (SLIM_TR[i] & 0xFF); } } diff --git a/src/t6k11/t6k11.c b/src/t6k11/t6k11.c index 678724a..516bbd1 100644 --- a/src/t6k11/t6k11.c +++ b/src/t6k11/t6k11.c @@ -168,7 +168,7 @@ void t6k11_backlight(int setting) TODO: Document the PFC to remove these addresses */ if(isSH3()) { - if (isSlim()) + if(isSlim()) { port = (void *)0xa4000126; mask = 0x20; -- 2.45.0