bobbimanners / Applecorn

Allows Acorn BBC Microcomputer language ROMs to run on Apple //e enhanced, //c and IIGS.
GNU General Public License v3.0
48 stars 8 forks source link

Keyboard mapping on emulators #226

Open jgharston opened 1 year ago

jgharston commented 1 year ago

I don't know how accurately the emulators I'm using match real hardware, so I could do with some real hardware test information. Hours online tracking down documentation hasn't been much help.

With KEGS, keypad-enter and keypad-equals both return '='. Is that the same on real hardware. KEGS doesn't map anything to the IIgs keypad-clear key, the top-left keypad key, so I don't know what keycode it returns. On KEGS, Shift-Keypad-key sets the KBDMOD 'KPAD' bit, but doesn't set the KBDMOD 'Shift Key' bit.

I think this is slightly different on KEGS for Android, so I'll check that later.

bobbimanners commented 1 year ago

I put out a question on the Apple II Slack to see if any of the emulators handles this properly. The two GS emulators I use (MAME and GSPort) don't simulate the ADB extended function keys as far as I know. I must admit I didn't test with teh keypad on the real GS, just the F-keys.

(KEGS is the parent of GSPlus, and is now being actively maintained again, so it's generally a good one.)

bobbimanners commented 1 year ago

Some KEGS info ... all of the kegs based emulators use the function keys for their own uses. Not sure if it is possible to have the emulators ignore those keys and pass them through. The windows version of GSPlus does not handle the numpad.. Not sure about mame or any of the others though

bobbimanners commented 1 year ago

Maybe you want to try an emulator called Crossrunner. Just had someone check, and the ADB function keys are emulated there.

bobbimanners commented 1 year ago

Crossrunner: https://1drv.ms/u/s!Ai7zHzBSA6KTgcgszmU32rvSi6iDnQ?e=3TuslW

Oh and it is for Windows >= 7

ksherlock commented 1 year ago

The IIgs numeric keypad (and Apple Extended I) looks like:

C = / *
7 8 9 +
4 5 6 -
1 2 3 En
0   . ter

where C = clear, 0 is double-width, and Enter is double-height.

The platinum IIe is identical, but Clear is called "Esc".

The Apple Extended Keyboard II (and most modern mac-centric keyboards?) have the + and - keys swapped.

Windows looks like:

N / * -
7 8 9 +
4 5 6 +
1 2 3 En
0   . ter

Where N = num lock, + is double height, Enter is double height, and 0 is double width.

I think that's one reason emulators tend to get it wrong.

jgharston commented 1 year ago

On 27-12-2022 00:27, ksherlock wrote:

  • Keypad enter generates a $0d key code.
    • Keypad Clear generates a $1b key code.
    • (in both cases the keypad is set. shift/option/etc modifiers should work as well)

Ta, that makes sense. I coded defensively, and I think it will work straight off.

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

Not sure what you are intending with the numeric pad but results of testing here on GS + Wombat + USB keyboard are that the function keys work (including with modifiers), but numpad does nothing.

jgharston commented 1 year ago

On 27-12-2022 00:27, ksherlock wrote:

  • Keypad enter generates a $0d key code.
  • Keypad Clear generates a $1b key code.

So, now updated, this should be correct: https://mdfs.net/Software/BBCBasic/Apple/docs/Keyboard.txt

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

I should run your KBDTEST on the real GS and verify.

jgharston commented 1 year ago

On 27-12-2022 03:58, Bobbi Webber-Manners wrote:

Not sure what you are intending with the numeric pad but results of testing here on GS + Wombat + USB keyboard are that the function keys work (including with modifiers), but numpad does nothing.

Hmm. Can you test on real hardware (doesn't need to be right now, I'm off to bed soon) with Apple Basic something like:

10 LET A=PEEK($C000) 20 IF A<128 THEN GOTO 10 30 LET B=PEEK($C025) 40 PRINT A,B 50 GOTO 10

and report what pressing keypad keys and function keys does. Try both the USB keyboard, and the native keyboard.

Ta.

KEGS gives, eg: 48 16 for keypad0 49 16 for keypad1 50 16 for keypad2 51 16 for keypad3 52 16 for keypad4 etc. 48 0 for main0 49 0 for main1 50 0 for main2 51 0 for main3 52 0 for main4 etc.

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

KEGS is probably right. If the KEYPAD bit is set (I assume that is the 16 above, without checking), is the keyboard driver supposed to accept it or filter it out if not an f-key? I think my code only allowed f-keys through, but in principle we could have the number pad work also. Right now it doesn't on my setup at least.

jgharston commented 1 year ago

On 27-12-2022 04:12, Bobbi Webber-Manners wrote:

KEGS is probably right. If the KEYPAD bit is set (I assume that is the 16 above, without checking), is the keyboard driver supposed to accept it or filter it out if not an f-key? I think my code only allowed f-keys through, but in principle we could have the number pad work also. Right now it doesn't on my setup at least.

I've written the keyboard driver to follow the Acorn methodology of the base of the keypad being set with FX238, so it can be function keys (FX238,128) or it can be digits (*FX238,48), or anything else.

Trawlling through documentation and photographs, I believe this is now correct documentation of AppleII keyboard keycodes: https://mdfs.net/Docs/Comp/Keyboard/Apple/AppleIIkey

Is it me, or is this documentation really hard to track down? For the Beeb you just turn to page 495/511 of the User Guide.

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

Ah I have to play with *FX238 then :)

The Beeb documentation is more centralized and better organized I think. Every generation of Apple II had its own docs (][/}{+, //e, //c and GS) and each has its own quirks. There are also a pile of Apple 'Tech Notes' to clarify various corner cases. The Apple docs are generally pretty good but there are too many of them, and it is hard to know if you are looking in the right place.

For the //e the Technical Reference Manual is the most useful. The GS splits this into a Hardware Reference Manual and a Firmware Reference Manual. The ProDOS Technical Reference manual is also very useful.

Let me know if there is anything in particular you are looking for. I have a folder of handy PDFs!

jgharston commented 1 year ago

Something that would be useful is to run in Apple Basic on real hardware: 10 LET A=PEEK(49152) 20 IF A>127 THEN PRINT A-128 30 GOTO 10

And tell me what pressing Ctrl-(~) gives. I can't find if it does (ASC"~"AND31) which is 28 or (ASC""AND31) which is 0. Or even, just ignores Ctrl and gives ` or ~.

bobbimanners commented 1 year ago

Will do that right now.

bobbimanners commented 1 year ago

On the GS, Ctrl-~ gives me 96 (same as ~ with no modifiers)

bobbimanners commented 1 year ago

And I get 48 for keypad 0, same as 0 on the main keyboard.

jgharston commented 1 year ago

On 28-12-2022 03:48, Bobbi Webber-Manners wrote:

And I get 48 for keypad 0, same as 0 on the main keyboard.

What machine/keyboard is this?

What does this give for the keypad keys? REPEAT:PRINT ~GET,~?&C025:UNTIL FALSE

On KEGS it gives me: 30 10 31 10 32 10 33 10 34 10 etc for the keypad and 30 0 31 0 32 0 33 0 34 0 for the main keyboard.

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

This is my ROM01 GS, which has a Wombat and a USB keyboard (Mac USB keyboard circa 2005). I don't have an actual ADB keyboard, but the Wombat is equivalent to an ADB Extended keyboard. I can ask other people on the Apple II Slack to test on with various keyboards if need be.

Running your one-liner, I get this for the main keyboard number keys: 30 4 31 4 etc.

And for the keypad, I get: D 14 (Enter) 18 14 (Clear) but all the others are dead / filtered out ...

bobbimanners commented 1 year ago

A bit more testing info for you from my GS. I was playing with View and noticed that the numpad is working as F-keys, so that is good. However, the arrow keys no longer seem to be working on the GS at least.

bobbimanners commented 1 year ago

Had a quick test in MAME using the (simulated) //e, and arrow keys don't work in View there either. However they do work in BBC BASIC both in MAME and on my (real) GS.

jgharston commented 1 year ago

Weird. It looks like oddities of emulator implementation. On my desktop, but not my laptop, Applecorn doesn't give anything from Ctrl-digit, but KEGS gives digits from Ctrl-digit, which is a bugger because the Windows UK keyboard driver translates RightAlt into ALT+CTRL. I'm very reluctant to make any OS changes on my development desktop as it is now my sole remaining machine that will properly go full-screen for PDP11 emulation. That was a frustrating kick in the nuts when my laptop said "Welcome to Windows 7!" and weeks of frustratedly trying to get full-screen code to work again.

jgharston commented 1 year ago

I spent yesterday frustatedly trying to get my Android tablet to re-install KEGS and Apple2ix. I think it's near death, and at this rate if it doesn't behave it's going to be percussively punished over the edge of the table.

bobbimanners commented 1 year ago

Yes, not sure what the deal is with the arrow keys. They did used to work prior to refactoring, so I guess we can see what it was doing then and compare.

jgharston commented 1 year ago

This: https://mdfs.net/Docs/Comp/Keyboard/Apple/AppleIIkey

is updated from documantation and testing to be what various AppleII keyboards keypresses "should" return. A perennial problem is that emulators tend to omit corner cases, or things the writers just never thought would happen - such as a keyboard with a keypad.

It would be worth getting a community effort to get people to use real hardware and tabulate all 16 combinations of each keypress:

             | key | shift | ctrl | shift+ctrl

----------------+-----+-------+------+------------ key | | | | left apple | | | | right apple | | | | left+right apple| | | |

10 LET A=PEEK(49152) 20 IF A<128 THEN GOTO 10 30 POKE 49152+16,A 40 PRINT A,PEEK(49152+37) 50 GOTO 10

If I lived nearer a hand-on computer museum I'd spend an afternoon testing.

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

The non functioning arrow keys in View or ISO Pascal editor is reproducible in MAME. Tried it the other day.

ksherlock commented 1 year ago

Apple IIgs, ROM 1, original keyboard (the ADB code to key code translation is handled by the ADB glu code which differs between ROM versions.

Modifier bits always reflect shift/ctrl/etc status.

Shift doesn't affect the above control codes.

This looks consistent with your keycode chart.

MAME (250) doesn't handle control-6 or control-- correctly. MAME also loses the keypad modifier bit when shift/control are used with keypad entry (eg, shift-keypad 4 generates modifier 1 instead of modifier 17). MAME is switching to proper ADB next month which should fix those problems so I'll try again with it enabled.

ksherlock commented 1 year ago

I just noticed, numpad clear isn't escape ($1b / 27), it's cancel ($18 / 24).

MAME with ADB emulation seems to get everything correct (or will ; there's a mapping problem with clear/=).

ksherlock commented 1 year ago

Also, the arrow keys ($7b-$7e) the Macintosh Toolbox diagram are a lie :) The actual ADB codes are $3b-$3e but the macintosh software remaps them to $7b-$7e before giving them to applications. On the Apple II, they're 8, 21, 10, 11; no keypad modifier.

jgharston commented 1 year ago

On 31-12-2022 17:49, ksherlock wrote:

MAME (250) doesn't handle control-6 or control-- correctly (because it uses the IIe keyboard mapping?). MAME also loses the keypad modifier bit when shift/control are used with keypad entry (eg, shift-keypad 4 generates modifier 1 instead of modifier 17). MAME is switching to proper ADB next month which should fix those problems so I'll try again with it enabled.

KEGS 0.60 on Windows also loses SHIFT when the keypad keys are pressed. I notice the latest version is 1.16, so I'll install that and check.

-- J.G.Harston - @.*** - mdfs.net/jgh

jgharston commented 1 year ago

On 31-12-2022 19:26, ksherlock wrote:

I just noticed, numpad clear isn't escape ($1b / 27), it's cancel ($18 / 24).

On the AppleIIgs the key is labelled CLEAR, but on the AppleIIe Platinum the key is labelled ESC. Does it return $18/24 on both, or does it return the character that matches the label?

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

@jgharston Anything else to do here, or shall I close it?