2019-06-01 15:11:25 +00:00
|
|
|
package main
|
2019-04-13 18:29:31 +00:00
|
|
|
|
|
|
|
import (
|
2019-10-05 23:26:00 +00:00
|
|
|
"fmt"
|
2019-04-13 18:29:31 +00:00
|
|
|
|
2020-10-03 21:38:26 +00:00
|
|
|
"github.com/ivanizag/izapple2"
|
2020-10-16 18:41:34 +00:00
|
|
|
"github.com/ivanizag/izapple2/screen"
|
2019-04-13 18:29:31 +00:00
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sdlKeyboard struct {
|
2020-10-03 21:38:26 +00:00
|
|
|
a *izapple2.Apple2
|
2020-10-10 15:35:25 +00:00
|
|
|
keyChannel *izapple2.KeyboardChannel
|
2020-07-31 07:46:53 +00:00
|
|
|
|
|
|
|
showPages bool
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 21:38:26 +00:00
|
|
|
func newSDLKeyBoard(a *izapple2.Apple2) *sdlKeyboard {
|
2019-04-13 18:29:31 +00:00
|
|
|
var k sdlKeyboard
|
2019-05-05 10:38:24 +00:00
|
|
|
k.a = a
|
2020-10-10 15:35:25 +00:00
|
|
|
k.keyChannel = izapple2.NewKeyboardChannel(a)
|
2019-05-09 22:09:15 +00:00
|
|
|
return &k
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-10 15:35:25 +00:00
|
|
|
func (k *sdlKeyboard) putText(text string) {
|
|
|
|
k.keyChannel.PutText(text)
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
|
2019-04-27 22:13:34 +00:00
|
|
|
/*
|
|
|
|
See "Apple II reference manual", page 5
|
|
|
|
|
|
|
|
To get keys as understood by the Apple2 hardware run:
|
|
|
|
10 A=PEEK(49152)
|
|
|
|
20 PRINT A, A - 128
|
|
|
|
30 GOTO 10
|
2019-04-13 18:29:31 +00:00
|
|
|
*/
|
|
|
|
if keyEvent.Type != sdl.KEYDOWN {
|
|
|
|
// Process only key pushes
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
key := keyEvent.Keysym
|
|
|
|
ctrl := key.Mod&sdl.KMOD_CTRL != 0
|
|
|
|
|
|
|
|
if ctrl {
|
|
|
|
if key.Sym >= 'a' && key.Sym <= 'z' {
|
2020-10-10 15:35:25 +00:00
|
|
|
k.keyChannel.PutChar(uint8(key.Sym) - 97 + 1)
|
2019-04-13 18:29:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result := uint8(0)
|
|
|
|
|
|
|
|
switch key.Sym {
|
|
|
|
case sdl.K_ESCAPE:
|
|
|
|
result = 27
|
2019-05-23 22:41:43 +00:00
|
|
|
case sdl.K_BACKSPACE:
|
|
|
|
result = 8
|
2019-04-13 18:29:31 +00:00
|
|
|
case sdl.K_RETURN:
|
|
|
|
result = 13
|
|
|
|
case sdl.K_RETURN2:
|
|
|
|
result = 13
|
|
|
|
case sdl.K_LEFT:
|
|
|
|
if ctrl {
|
|
|
|
result = 31 // Base64A
|
2020-10-07 07:37:13 +00:00
|
|
|
} else {
|
|
|
|
result = 8
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
case sdl.K_RIGHT:
|
|
|
|
result = 21
|
|
|
|
|
2019-11-08 23:21:34 +00:00
|
|
|
// Apple //e
|
2019-04-13 18:29:31 +00:00
|
|
|
case sdl.K_UP:
|
2019-11-08 23:21:34 +00:00
|
|
|
result = 11 // 31 in the Base64A
|
2019-04-13 18:29:31 +00:00
|
|
|
case sdl.K_DOWN:
|
|
|
|
result = 10
|
2019-11-08 23:21:34 +00:00
|
|
|
case sdl.K_TAB:
|
|
|
|
result = 9
|
|
|
|
case sdl.K_DELETE:
|
|
|
|
result = 127 // 24 in the Base64A
|
|
|
|
|
|
|
|
// Base64A clone particularities
|
|
|
|
case sdl.K_F2:
|
|
|
|
result = 127 // Base64A
|
2019-05-05 10:38:24 +00:00
|
|
|
|
|
|
|
// Control of the emulator
|
2019-11-20 23:13:53 +00:00
|
|
|
case sdl.K_F1:
|
|
|
|
if ctrl {
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandReset)
|
2019-11-20 23:13:53 +00:00
|
|
|
}
|
2019-05-05 10:38:24 +00:00
|
|
|
case sdl.K_F5:
|
2019-11-07 22:20:14 +00:00
|
|
|
if ctrl {
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandShowSpeed)
|
2019-11-07 22:20:14 +00:00
|
|
|
} else {
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandToggleSpeed)
|
2019-11-07 22:20:14 +00:00
|
|
|
}
|
2019-05-17 21:28:20 +00:00
|
|
|
case sdl.K_F7:
|
2020-08-13 14:50:48 +00:00
|
|
|
k.showPages = !k.showPages
|
2019-05-18 21:40:59 +00:00
|
|
|
case sdl.K_F9:
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandDumpDebugInfo)
|
2019-06-09 21:54:27 +00:00
|
|
|
case sdl.K_F10:
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandNextCharGenPage)
|
2019-10-02 21:00:02 +00:00
|
|
|
case sdl.K_F11:
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandToggleCPUTrace)
|
2019-06-02 20:59:51 +00:00
|
|
|
case sdl.K_F12:
|
2020-10-10 15:35:25 +00:00
|
|
|
case sdl.K_PRINTSCREEN:
|
2020-10-16 18:41:34 +00:00
|
|
|
err := screen.SaveSnapshot(k.a, screen.ScreenModeNTSC, "snapshot.png")
|
2019-10-05 23:26:00 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error saving snapshoot: %v.\n.", err)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Saving snapshot")
|
|
|
|
}
|
2020-03-14 02:29:12 +00:00
|
|
|
case sdl.K_PAUSE:
|
2020-10-03 21:38:26 +00:00
|
|
|
k.a.SendCommand(izapple2.CommandPauseUnpauseEmulator)
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Missing values 91 to 95. Usually control for [\]^_
|
|
|
|
// On the Base64A it's control for \]./
|
|
|
|
|
|
|
|
if result != 0 {
|
2020-10-10 15:35:25 +00:00
|
|
|
k.keyChannel.PutChar(result)
|
2019-04-13 18:29:31 +00:00
|
|
|
}
|
|
|
|
}
|