i6502/acia6551.go

120 lines
1.8 KiB
Go
Raw Normal View History

2014-08-17 14:49:22 +00:00
package i6502
2014-08-18 14:37:51 +00:00
import "fmt"
2014-08-17 15:18:14 +00:00
const (
aciaData = iota
aciaStatus
aciaCommand
aciaControl
)
2014-08-17 14:49:22 +00:00
/*
ACIA 6551 Serial IO
2014-08-18 14:37:51 +00:00
This Asynchronous Communications Interface Adapater can be
directly attached to the 6502's address and data busses.
It provides serial IO.
The supplied Rx and Tx channels can be used to read and wirte
data to the ACIA 6551.
2014-08-17 14:49:22 +00:00
*/
type Acia6551 struct {
2014-08-17 15:18:14 +00:00
Rx chan byte // Reading (Acia Input) line
Tx chan byte // Transmitting (Acia Output) line
2014-08-17 20:36:01 +00:00
rxData byte
txData byte
2014-08-17 15:18:14 +00:00
commandData byte
controlData byte
rxFull bool
txEmpty bool
rxIrqEnabled bool
txIrqEnabled bool
2014-08-17 20:36:01 +00:00
overrun bool
2014-08-17 14:49:22 +00:00
}
func NewAcia6551(rx chan byte, tx chan byte) (*Acia6551, error) {
2014-08-17 15:18:14 +00:00
acia := &Acia6551{Tx: tx, Rx: rx}
acia.Reset()
go func() {
2014-08-18 14:37:51 +00:00
for {
select {
case data := <-acia.Rx:
acia.rxData = data
acia.rxFull = true
fmt.Printf("Rx: 0x%02X\n", data)
}
}
2014-08-17 15:18:14 +00:00
}()
go func() {
// Handle tx data channel
}()
return acia, nil
2014-08-17 14:49:22 +00:00
}
2014-08-17 15:18:14 +00:00
func (a *Acia6551) Size() uint16 {
// We have a only 4 addresses, Data, Status, Command and Control
2014-08-17 14:49:22 +00:00
return 0x04
}
2014-08-17 20:36:01 +00:00
// Emulates a hardware reset
2014-08-17 15:18:14 +00:00
func (a *Acia6551) Reset() {
a.rxData = 0
a.rxFull = false
a.txData = 0
a.txEmpty = true
a.rxIrqEnabled = false
a.txIrqEnabled = false
2014-08-17 20:36:01 +00:00
a.overrun = false
a.setControl(0)
a.setCommand(0)
2014-08-17 15:18:14 +00:00
}
2014-08-17 20:36:01 +00:00
func (a *Acia6551) setControl(data byte) {
2014-08-17 14:49:22 +00:00
}
2014-08-17 20:36:01 +00:00
func (a *Acia6551) setCommand(data byte) {
}
2014-08-18 14:37:51 +00:00
// Used by the AddressBus to read data from the ACIA 6551
2014-08-17 20:36:01 +00:00
func (a *Acia6551) Read(address uint16) byte {
switch address {
case aciaData:
// Read Rx
case aciaStatus:
// Read Status reg.
case aciaCommand:
// Read command
case aciaControl:
// Read control
}
return 0x00
}
func (a *Acia6551) Write(address uint16, data byte) {
switch address {
case aciaData:
// Write Tx
case aciaStatus:
// Reset
case aciaCommand:
// Write command
case aciaControl:
// Write control
}
2014-08-17 14:49:22 +00:00
}