From 4991feeb6f28097f510d2fe5ab2247c1682383df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Izaguirre?= Date: Sat, 31 Aug 2024 16:43:09 +0200 Subject: [PATCH] Improved open and close apple handling on macs --- frontend/a2sdl/main.go | 35 ++++++++++++++++++----------------- keyboard.go | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/frontend/a2sdl/main.go b/frontend/a2sdl/main.go index c1e71cc..b49cfd8 100644 --- a/frontend/a2sdl/main.go +++ b/frontend/a2sdl/main.go @@ -151,25 +151,26 @@ func sdlRun(a *izapple2.Apple2) { var helpMessage = ` - F1: Show/Hide help - Ctrl-F2: Reset - F4: Show/Hide CPU trace - F5: Fast/Normal speed - Ctrl-F5: Show speed - F6: Next screen mode - F7: Show/Hide pages - F10: Next character set - Ctrl-F10: Show/Hide character set - Shift-F10: Show/Hide alternate text - F12: Save screen snapshot - Pause: Pause the emulation - - Drop a file on the left or right - side of the window to load a disk + F1: Show/Hide help + Ctrl-F2: Reset + F4: Show/Hide CPU trace + F5: Fast/Normal speed + Ctrl-F5: Show speed + F6: Next screen mode + F7: Show/Hide pages + F10: Next character set + Ctrl-F10: Show/Hide character set + Shift-F10: Show/Hide alternate text + F12: Save screen snapshot + Pause: Pause the emulation + + Left alt or option key: Open-Apple + Right alt or option key: Closed-Apple + +Drop a file on the left or right +side of the window to load a disk Run izapple2 -h for more options - - More info at https://github.com/ivanizag/izapple2 ` diff --git a/keyboard.go b/keyboard.go index 70447ab..261f60b 100644 --- a/keyboard.go +++ b/keyboard.go @@ -1,6 +1,9 @@ package izapple2 -import "unicode" +import ( + "slices" + "unicode" +) // KeyboardProvider provides a keyboard implementation type KeyboardProvider interface { @@ -29,8 +32,19 @@ func (k *KeyboardChannel) PutText(text string) { } } +var macOptionChars = []rune("ı˝•£‰ ⁄‘’≈œæ€®†¥øπå∫∂ƒ™¶§∑©√ßµ„…≤≥çñŒÆ€‡∏fl¯ˇ˘‹›◊˙˚") +var macOptionSubs = []rune("!\"·$%&/()=qwertyopasdfghjkxcvbm,.<>cnQWETPGJKLZXVNM") + // PutRune sends a rune to the emulator if it is valid printable ASCII func (k *KeyboardChannel) PutRune(ch rune) { + + // Some substitutions useful for Macs that transform chars with the option key + pos := slices.Index(macOptionChars, ch) + if pos >= 0 { + println("Mac option char: ", string(ch), " -> ", string(macOptionSubs[pos])) + ch = rune(macOptionSubs[pos]) + } + // We will use computed text only for printable ASCII chars if ch >= ' ' && ch <= '~' { if k.a.IsForceCaps() && ch >= 'a' && ch <= 'z' {