Add failing spec with chanels.

This commit is contained in:
Ariejan de Vroom 2014-08-18 16:37:51 +02:00
parent 44738e191f
commit 432119f507
2 changed files with 35 additions and 5 deletions

View File

@ -1,5 +1,7 @@
package i6502
import "fmt"
const (
aciaData = iota
aciaStatus
@ -9,6 +11,14 @@ const (
/*
ACIA 6551 Serial IO
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.
*/
type Acia6551 struct {
Rx chan byte // Reading (Acia Input) line
@ -34,7 +44,14 @@ func NewAcia6551(rx chan byte, tx chan byte) (*Acia6551, error) {
acia.Reset()
go func() {
// Handle rx data channel
for {
select {
case data := <-acia.Rx:
acia.rxData = data
acia.rxFull = true
fmt.Printf("Rx: 0x%02X\n", data)
}
}
}()
go func() {
@ -72,6 +89,7 @@ func (a *Acia6551) setControl(data byte) {
func (a *Acia6551) setCommand(data byte) {
}
// Used by the AddressBus to read data from the ACIA 6551
func (a *Acia6551) Read(address uint16) byte {
switch address {
case aciaData:

View File

@ -1,16 +1,17 @@
package i6502
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func AciaSubject() *Acia6551 {
func AciaSubject() (*Acia6551, chan byte, chan byte) {
tx := make(chan byte)
rx := make(chan byte)
acia, _ := NewAcia6551(rx, tx)
return acia
return acia, rx, tx
}
func TestNewAcia6551(t *testing.T) {
@ -23,7 +24,8 @@ func TestNewAcia6551(t *testing.T) {
}
func TestAciaReset(t *testing.T) {
a := AciaSubject()
a, _, _ := AciaSubject()
a.Reset()
assert.Equal(t, a.txData, 0)
@ -39,5 +41,15 @@ func TestAciaReset(t *testing.T) {
assert.Equal(t, 0, a.controlData)
}
func TestAciaCommand(t *testing.T) {
func TestAciaReadData(t *testing.T) {
a, _, _ := AciaSubject()
a.Rx <- 0x42
assert.True(t, a.rxFull)
fmt.Printf("Reading...\n")
value := a.Read(aciaData)
assert.Equal(t, 0x42, value)
assert.False(t, a.rxFull)
}