Apple2-IO-RPi/RaspberryPi/apple2driver/a2io/userio.go

90 lines
2.4 KiB
Go
Raw Normal View History

2022-01-11 04:00:58 +00:00
// Copyright Terence J. Boldt (c)2021-2022
// 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
package a2io
import (
"errors"
"fmt"
"strings"
)
2021-11-03 09:33:09 +00:00
// UserIo implements A2Io for the purpose of debugging locally
type UserIo struct {
}
2021-11-03 09:33:09 +00:00
// Init is only here to complete A2Io interface
func (userIo UserIo) Init() {
}
2021-11-03 09:33:09 +00:00
// WriteByte simulates writing to the Apple II but uses stdout instead
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
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
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
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
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
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
func (userIo UserIo) ReadBlock(buffer []byte) error {
fmt.Printf("ReadBlock: (Not supported)")
return errors.New("ReadBlock not supported")
}
// SendCharacter is a pass-through to vt100 implementation
func (userIo UserIo) SendCharacter(character byte) {
sendCharacter(userIo, character)
}
// ReadCharacter is a pass-through to vt100 implementation
func (userIo UserIo) ReadCharacter() (string, error) {
return readCharacter(userIo)
}