Skip to content

Commit

Permalink
Merge pull request #119 from robinsonb5-PRs/oldkeyboards
Browse files Browse the repository at this point in the history
Added two new Amiga keyboard modes for old keyboard with no GUI keys.
  • Loading branch information
harbaum authored Oct 3, 2024
2 parents 2102ac4 + 829affe commit 6a4af68
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mist_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const ini_var_t mist_ini_vars[] = {
{"JOY_KEY_MAP", (void*)joystick_key_map, CUSTOM_HANDLER, 0, 0, 1},
#endif
{"ROM", (void*)ini_rom_upload, CUSTOM_HANDLER, 0, 0, 1},
{"AMIGA_MOD_KEYS", (void*)(&(mist_cfg.amiga_mod_keys)), UINT8, 0, 1, 1},
{"AMIGA_MOD_KEYS", (void*)(&(mist_cfg.amiga_mod_keys)), UINT8, 0, 3, 1},
{"USB_STORAGE", (void*)(&(mist_cfg.usb_storage)), UINT8, 0, 1, 1},
// [MINIMIG_CONFIG]
{"KICK1X_MEMORY_DETECTION_PATCH", (void*)(&(minimig_cfg.kick1x_memory_detection_patch)), UINT8, 0, 1, 2},
Expand Down
66 changes: 54 additions & 12 deletions user_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ static void keyrah_trans(unsigned char *m, unsigned char *k)

void user_io_kbd(unsigned char m, unsigned char *k, uint8_t priority, unsigned short vid, unsigned short pid)
{
static char caps=0;
// ignore lower priority clears if higher priority key was pressed
if(m==0 && (k[0] + k[1] + k[2] + k[3] + k[4] + k[5])==0)
{
Expand All @@ -2237,24 +2238,65 @@ void user_io_kbd(unsigned char m, unsigned char *k, uint8_t priority, unsigned s
// key LCTRL LSHIFT LALT LGUI RCTRL RSHIFT RALT RGUI
// 1 2 4 8 10 20 40 80
unsigned char m_in = m;
// swap RALT/RGUI & LALT/LGUI
m = ((m & 0x40) << 1) | ((m & 0x80) >> 1) | m & 0x20 | m & 0x10 | ((m & 0x8) >> 1) | ((m & 0x4) << 1) | m & 0x2;
// swap CAPSLOCK/LCTRL
switch(mist_cfg.amiga_mod_keys) {
case 1:
// swap RALT/RGUI & LALT/LGUI
m = ((m & 0x40) << 1) | ((m & 0x80) >> 1) | m & 0x20 | m & 0x10 | ((m & 0x8) >> 1) | ((m & 0x4) << 1) | m & 0x2;
break;
case 2:
// swap RGUI/RCTRL & LGUI/CTRL
m = ((m & 0x10) << 3) | ((m & 0x80) >> 3) | m & 0x20 | m & 0x40 | ((m & 0x8) >> 3) | ((m & 0x1) << 3) | m & 0x2 | m & 0x4;
break;
case 3:
// Map Alt to GUI, Ctrl to Alt, GUI to Ctrl
m = ((m & 0x10) << 2) | ((m & 0x80) >> 3) | (m & 0x20) | ((m & 0x40) << 1) | ((m & 0x8) >> 3) | ((m & 0x1) << 2) | (m & 0x2) | ((m & 0x4) << 1) ;
break;
default:
break;
}

// CAPSLOCK/LCTRL mapping
// First map Caps Lock to L Ctrl
for(char i=0;i<6;i++) {
if(k[i] == 0x39) {
m |= 0x1;
k[i] = 0;
}
if(m_in & 0x1) {
if(i<5) {
if(k[i] == 0) {
k[i] = 0x39;
m_in &= ~0x1;
caps|=0x07;
} else if (k[i]) /* any other (non-qualifier) key pressed? */
caps|=0x80;
}

switch(mist_cfg.amiga_mod_keys) {
case 1: // Map L Ctrl to Caps Lock
if(m_in & 0x1) {
for(char i=0;i<6;i++) {
if(k[i] == 0) {
k[i] = 0x39;
break;
}
}
} else {
k[i] = 0x39;
}
}
break;
case 2:
case 3:
// If Caps Lock is pressed and released with no other key events in between, generate a Caps Lock keypress.
// (In modern keyboard firmware parlance, the Caps Lock key has "mod-tap")
if(!(m & 0x01)) { // is Caps Lock (afer mapping to L Ctrl) no longer pressed?
for(char i=0;i<6;++i) {
if(k[i] == 0) { // We have an empty slot in the key report
if(caps&0x80) // Were other (non-modfier) keys were pressed before capslock was released?
caps=0;
else if(caps) {
k[i]=0x39;
--caps;
}
break;
}
}
}
break;
default:
break;
}
}

Expand Down

0 comments on commit 6a4af68

Please sign in to comment.