From 856ff0057316987f85fcae545ee5836334835342 Mon Sep 17 00:00:00 2001 From: Ariejan de Vroom Date: Sun, 17 Aug 2014 17:18:14 +0200 Subject: [PATCH] Add ACIA Reset() --- acia6551.go | 50 +++++++++++++++++++++++++++++++++++++++++++----- acia6551_test.go | 25 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/acia6551.go b/acia6551.go index ffcbc80..3bdbe2f 100644 --- a/acia6551.go +++ b/acia6551.go @@ -1,22 +1,62 @@ package i6502 +const ( + aciaData = iota + aciaStatus + aciaCommand + aciaControl +) + /* ACIA 6551 Serial IO */ type Acia6551 struct { - rx chan byte // Reading (Acia Input) line - tx chan byte // Transmitting (Acia Output) line + Rx chan byte // Reading (Acia Input) line + Tx chan byte // Transmitting (Acia Output) line + + rxData byte + txData byte + commandData byte + controlData byte + + rxFull bool + txEmpty bool + + rxIrqEnabled bool + txIrqEnabled bool } func NewAcia6551(rx chan byte, tx chan byte) (*Acia6551, error) { - return &Acia6551{tx: tx, rx: rx}, nil + acia := &Acia6551{Tx: tx, Rx: rx} + acia.Reset() + + go func() { + // Handle rx data channel + }() + + go func() { + // Handle tx data channel + }() + + return acia, nil } -func (r *Acia6551) Size() uint16 { - // We have a only 4 addresses, RX, TX, Command and Control +func (a *Acia6551) Size() uint16 { + // We have a only 4 addresses, Data, Status, Command and Control return 0x04 } +func (a *Acia6551) Reset() { + a.rxData = 0 + a.rxFull = false + + a.txData = 0 + a.txEmpty = true + + a.rxIrqEnabled = false + a.txIrqEnabled = false +} + /* func (r *Rom) Read(address uint16) byte { return r.data[address] diff --git a/acia6551_test.go b/acia6551_test.go index 9e19e15..8763d79 100644 --- a/acia6551_test.go +++ b/acia6551_test.go @@ -5,6 +5,14 @@ import ( "testing" ) +func AciaSubject() *Acia6551 { + tx := make(chan byte) + rx := make(chan byte) + acia, _ := NewAcia6551(rx, tx) + + return acia +} + func TestNewAcia6551(t *testing.T) { tx := make(chan byte) rx := make(chan byte) @@ -13,3 +21,20 @@ func TestNewAcia6551(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 0x4, acia.Size()) } + +func TestAciaReset(t *testing.T) { + a := AciaSubject() + a.Reset() + + assert.Equal(t, a.txData, 0) + assert.True(t, a.txEmpty) + + assert.Equal(t, a.rxData, 0) + assert.False(t, a.rxFull) + + assert.False(t, a.txIrqEnabled) + assert.False(t, a.rxIrqEnabled) +} + +func TestAciaCommand(t *testing.T) { +}