2014-08-12 19:28:30 +00:00
|
|
|
package i6502
|
|
|
|
|
|
|
|
import (
|
2014-08-13 04:19:44 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2014-08-12 19:28:30 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-08-13 07:26:33 +00:00
|
|
|
// Creates a new machine, returning the different parts
|
|
|
|
func NewRamMachine() (*Cpu, *AddressBus, *Ram) {
|
|
|
|
ram, _ := NewRam(0x100000) // Full 64kB
|
|
|
|
bus, _ := NewAddressBus()
|
|
|
|
bus.Attach(ram, 0x0000)
|
|
|
|
cpu, _ := NewCpu(bus)
|
|
|
|
|
2014-08-13 09:49:49 +00:00
|
|
|
cpu.Reset()
|
|
|
|
|
2014-08-13 07:26:33 +00:00
|
|
|
return cpu, bus, ram
|
|
|
|
}
|
|
|
|
|
2014-08-12 19:28:30 +00:00
|
|
|
func TestNewCpu(t *testing.T) {
|
2014-08-13 07:26:33 +00:00
|
|
|
cpu, err := NewCpu(nil)
|
2014-08-12 19:28:30 +00:00
|
|
|
|
2014-08-13 04:19:44 +00:00
|
|
|
assert.NotNil(t, cpu)
|
|
|
|
assert.Nil(t, err)
|
2014-08-12 19:28:30 +00:00
|
|
|
}
|
2014-08-13 07:26:33 +00:00
|
|
|
|
|
|
|
func TestCpuAddressBus(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
cpu, _, _ := NewRamMachine()
|
|
|
|
assert.True(cpu.HasAddressBus())
|
|
|
|
}
|
|
|
|
|
2014-08-13 09:49:49 +00:00
|
|
|
func TestCpuReset(t *testing.T) {
|
2014-08-13 07:26:33 +00:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
cpu, _, _ := NewRamMachine()
|
|
|
|
|
|
|
|
cpu.bus.Write(0xFFFC, 0x34)
|
|
|
|
cpu.bus.Write(0xFFFD, 0x12)
|
|
|
|
|
|
|
|
cpu.Reset()
|
|
|
|
|
|
|
|
// **1101** is specified, but we are satisfied with
|
|
|
|
// 00110100 here.
|
|
|
|
assert.Equal(0x34, cpu.P)
|
|
|
|
|
|
|
|
// Read PC from $FFFC-FFFD
|
|
|
|
assert.Equal(0x1234, cpu.PC)
|
|
|
|
}
|
2014-08-13 09:49:49 +00:00
|
|
|
|
|
|
|
func TestProgramLoading(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
program := []byte{0xEA, 0xEB, 0xEC}
|
|
|
|
|
|
|
|
cpu, bus, _ := NewRamMachine()
|
|
|
|
cpu.LoadProgram(program, 0x0300)
|
|
|
|
|
|
|
|
assert.Equal(0xEA, bus.Read(0x0300))
|
|
|
|
assert.Equal(0xEB, bus.Read(0x0301))
|
|
|
|
assert.Equal(0xEC, bus.Read(0x0302))
|
|
|
|
|
|
|
|
assert.Equal(0x0300, cpu.PC)
|
|
|
|
}
|