-
Notifications
You must be signed in to change notification settings - Fork 2
/
simulate_test.go
69 lines (52 loc) · 928 Bytes
/
simulate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package dodosim
import (
"fmt"
"io/ioutil"
"testing"
)
type Ramtest [0x10000]uint8
func (ram *Ramtest) Start() uint16 {
return 0x0
}
func (ram *Ramtest) Length() uint32 {
return 0x10000
}
func (ram *Ramtest) Read(addr uint16) uint8 {
return ram[addr]
}
func (ram *Ramtest) Write(addr uint16, val uint8) {
ram[addr] = val
}
func TestSimulator(t *testing.T) {
bus := new(Bus)
bus.New()
ram := new(Ramtest)
bus.Add(ram)
dat, err := ioutil.ReadFile("6502_functional_test.bin")
if err != nil {
fmt.Println(err)
return
}
for i, b := range dat {
ram[i] = b
}
bus.BuildMap()
cpu := new(Cpu)
cpu.Reset(bus)
cpu.PC = 0x400
BuildTable()
for {
before := cpu.PC
opcode := bus.Read(cpu.PC)
cpu.PC++
cpu.Status |= Constant
Execute(cpu, bus, opcode)
if before == cpu.PC {
if cpu.PC != 13209 {
t.Error("Failure. Trap at ", cpu.PC)
}
return
}
}
t.Error("End Condition")
}