mirror of
https://github.com/ivanizag/izapple2.git
synced 2024-12-21 18:29:45 +00:00
Revert change on keyboard strobe, use it for flow control on the stdin keyboard provider
This commit is contained in:
parent
5e718cdbe2
commit
9ab4e449b8
@ -44,24 +44,32 @@ func (fe *ansiConsoleFrontend) subscribeToTextPages() {
|
||||
|
||||
const refreshDelayMs = 100
|
||||
|
||||
func (fe *ansiConsoleFrontend) GetKey() (key uint8, ok bool) {
|
||||
stdinReader := func(c chan uint8) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
byte, err := reader.ReadByte()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
c <- byte
|
||||
}
|
||||
}
|
||||
func (fe *ansiConsoleFrontend) GetKey(strobed bool) (key uint8, ok bool) {
|
||||
|
||||
// Init the first time
|
||||
if fe.keyChannel == nil {
|
||||
stdinReader := func(c chan uint8) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
byte, err := reader.ReadByte()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
c <- byte
|
||||
}
|
||||
}
|
||||
|
||||
fe.keyChannel = make(chan uint8, 100)
|
||||
go stdinReader(fe.keyChannel)
|
||||
}
|
||||
|
||||
if !strobed {
|
||||
// We must use the strobe to control the flow from stdin
|
||||
ok = false
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case key = <-fe.keyChannel:
|
||||
if key == 10 {
|
||||
|
@ -16,7 +16,7 @@ type softSwitchR func(io *ioC0Page) uint8
|
||||
type softSwitchW func(io *ioC0Page, value uint8)
|
||||
|
||||
type KeyboardProvider interface {
|
||||
GetKey() (key uint8, ok bool)
|
||||
GetKey(strobe bool) (key uint8, ok bool)
|
||||
}
|
||||
|
||||
// See https://www.kreativekorp.com/miscpages/a2info/iomemory.shtml
|
||||
|
@ -93,8 +93,9 @@ func getSoftSwitch(ioFlag uint8, isSet bool) softSwitchR {
|
||||
}
|
||||
|
||||
func getKeySoftSwitch(io *ioC0Page) uint8 {
|
||||
strobed := (io.softSwitchesData[ioDataKeyboard] & (1 << 7)) == 0
|
||||
if io.keyboard != nil {
|
||||
if key, ok := io.keyboard.GetKey(); ok {
|
||||
if key, ok := io.keyboard.GetKey(strobed); ok {
|
||||
io.softSwitchesData[ioDataKeyboard] = key + (1 << 7)
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (k *sdlKeyboard) putChar(ch uint8) {
|
||||
k.keyChannel <- ch
|
||||
}
|
||||
|
||||
func (k *sdlKeyboard) GetKey() (key uint8, ok bool) {
|
||||
func (k *sdlKeyboard) GetKey(_ bool) (key uint8, ok bool) {
|
||||
select {
|
||||
case key = <-k.keyChannel:
|
||||
ok = true
|
||||
|
Loading…
Reference in New Issue
Block a user