2022-01-11 04:00:58 +00:00
|
|
|
// Copyright Terence J. Boldt (c)2021-2022
|
2021-10-30 13:50:00 +00:00
|
|
|
// Use of this source code is governed by an MIT
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// This file is only used during development for interactive testing of the
|
|
|
|
// driver code. Simply replace `comm := a2io.A2Gpio{}` with
|
|
|
|
// `comm := a2io.UserIo{}` in the driver.go file to allow local testing
|
2021-11-03 09:33:09 +00:00
|
|
|
|
2021-10-30 13:50:00 +00:00
|
|
|
package a2io
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// UserIo implements A2Io for the purpose of debugging locally
|
2021-10-30 13:50:00 +00:00
|
|
|
type UserIo struct {
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// Init is only here to complete A2Io interface
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) Init() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// WriteByte simulates writing to the Apple II but uses stdout instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) WriteByte(data byte) error {
|
|
|
|
fmt.Printf("WriteByte: %02X\n", data)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// WriteString simulates writing to the Apple II but uses stdout instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) WriteString(outString string) error {
|
|
|
|
fmt.Printf("WriteString: %s\n", strings.ReplaceAll(outString, "\r", "\n"))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// WriteBlock simulates writing to the Apple II but uses stdout instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) WriteBlock(buffer []byte) error {
|
|
|
|
fmt.Printf("WriteBlock:\n")
|
|
|
|
return userIo.WriteBuffer(buffer)
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// WriteBuffer simulates writing to the Apple II but uses stdout instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) WriteBuffer(buffer []byte) error {
|
|
|
|
fmt.Printf("WriteBuffer:\n")
|
|
|
|
for i, b := range buffer {
|
|
|
|
if i%16 == 0 {
|
|
|
|
fmt.Printf("\n%04X:", i)
|
|
|
|
}
|
|
|
|
fmt.Printf(" %02X", b)
|
|
|
|
}
|
|
|
|
fmt.Printf("\n")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// ReadByte simulates reading to the Apple II but uses stdin instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) ReadByte() (byte, error) {
|
|
|
|
fmt.Printf("ReadByte: ")
|
|
|
|
var b byte
|
|
|
|
fmt.Scanf("%x", &b)
|
|
|
|
fmt.Printf("\n")
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// ReadString simulates reading to the Apple II but uses stdin instead
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) ReadString() (string, error) {
|
|
|
|
fmt.Printf("ReadString: ")
|
|
|
|
var s string
|
|
|
|
fmt.Scanf("%s", &s)
|
|
|
|
fmt.Printf("\n")
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 09:33:09 +00:00
|
|
|
// ReadBlock should simulate reading to the Apple II but is not yet supported
|
2021-10-30 13:50:00 +00:00
|
|
|
func (userIo UserIo) ReadBlock(buffer []byte) error {
|
|
|
|
fmt.Printf("ReadBlock: (Not supported)")
|
|
|
|
return errors.New("ReadBlock not supported")
|
|
|
|
}
|
2021-11-11 02:44:28 +00:00
|
|
|
|
|
|
|
// SendCharacter is a pass-through to vt100 implementation
|
|
|
|
func (userIo UserIo) SendCharacter(character byte) {
|
|
|
|
sendCharacter(userIo, character)
|
|
|
|
}
|
2021-11-25 23:45:56 +00:00
|
|
|
|
|
|
|
// ReadCharacter is a pass-through to vt100 implementation
|
|
|
|
func (userIo UserIo) ReadCharacter() (string, error) {
|
|
|
|
return readCharacter(userIo)
|
|
|
|
}
|