-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpu_test.go
59 lines (54 loc) · 1.24 KB
/
cpu_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
package m68k_test
import (
"testing"
"github.com/cavaliercoder/go-m68k/m68ktest"
)
func TestReset(t *testing.T) {
// init dirty processor
p := m68ktest.NewProcessor(t)
for i := 0; i < 8; i++ {
p.A[i], p.D[i] = 0xFFFFFFFF, 0xFFFFFFFF
}
p.SR = 0xFFFFFFFF
p.PC = 0xFFFFFFFF
p.M.Write(0x1000, []byte{0xFF, 0xFF, 0xFF, 0xFF})
// reset and test
p.Reset()
for i := 0; i < 8; i++ {
if p.A[i] != 0 {
t.Errorf("Address register %d was not reset", i)
}
if p.D[i] != 0 {
t.Errorf("Data register %d was not reset", i)
}
}
if p.SR != 0 {
t.Error("Condition code register was not reset")
}
if p.PC != 0 {
t.Error("Program counter not reset")
}
b := make([]byte, 4)
_, err := p.M.Read(0x1000, b)
if err != nil {
panic(err)
}
for i := 0; i < len(b); i++ {
if b[i] != 0 {
t.Error("Memory was not zeroed")
break
}
}
}
func BenchmarkHelloWorld(b *testing.B) {
progHelloWorld := m68ktest.LoadBytes(nil, []byte{
0x41, 0xFA, 0x00, 0x12, 0x12, 0x18, 0x67, 0x08, 0x10, 0x3C, 0x00, 0x06, 0x4E,
0x4F, 0x60, 0xF4, 0x4E, 0x72, 0x27, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20,
0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x0D, 0x0A, 0x00,
})
b.ResetTimer()
for n := 0; n < b.N; n++ {
progHelloWorld.PC = 0x1000
progHelloWorld.Run()
}
}