-
Notifications
You must be signed in to change notification settings - Fork 4
/
flag_test.go
126 lines (106 loc) · 2.98 KB
/
flag_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package z80_test
import (
"testing"
"github.com/koron-go/z80"
)
func TestGetFlag(t *testing.T) {
for i, c := range []struct {
lo uint8
flag z80.Flag
want bool
}{
{0b00000001, z80.FlagC, true},
{0b00000000, z80.FlagC, false},
{0b11111110, z80.FlagC, false},
{0b00000010, z80.FlagN, true},
{0b00000000, z80.FlagN, false},
{0b11111101, z80.FlagN, false},
{0b00000100, z80.FlagPV, true},
{0b00000000, z80.FlagPV, false},
{0b11111011, z80.FlagPV, false},
{0b00010000, z80.FlagH, true},
{0b00000000, z80.FlagH, false},
{0b11100111, z80.FlagH, false},
{0b01000000, z80.FlagZ, true},
{0b00000000, z80.FlagZ, false},
{0b10111111, z80.FlagZ, false},
{0b10000000, z80.FlagS, true},
{0b00000000, z80.FlagS, false},
{0b01111111, z80.FlagS, false},
} {
var cpu z80.CPU
cpu.AF.Lo = c.lo
got := cpu.GetFlag(c.flag)
if got != c.want {
t.Errorf("unexpected value: %d %+v: got=%t", i, c, got)
}
}
}
func TestSetFlag(t *testing.T) {
for i, c := range []struct {
prev uint8
flag z80.Flag
want uint8
}{
{0b00000000, z80.FlagC, 0b00000001},
{0b00000001, z80.FlagC, 0b00000001},
{0b11111110, z80.FlagC, 0b11111111},
{0b00000000, z80.FlagN, 0b00000010},
{0b00000010, z80.FlagN, 0b00000010},
{0b11111101, z80.FlagN, 0b11111111},
{0b00000000, z80.FlagPV, 0b00000100},
{0b00000100, z80.FlagPV, 0b00000100},
{0b11111011, z80.FlagPV, 0b11111111},
{0b00000000, z80.FlagH, 0b00010000},
{0b00010000, z80.FlagH, 0b00010000},
{0b11101111, z80.FlagH, 0b11111111},
{0b00000000, z80.FlagZ, 0b01000000},
{0b01000000, z80.FlagZ, 0b01000000},
{0b10111111, z80.FlagZ, 0b11111111},
{0b00000000, z80.FlagS, 0b10000000},
{0b10000000, z80.FlagS, 0b10000000},
{0b01111111, z80.FlagS, 0b11111111},
} {
var cpu z80.CPU
cpu.AF.Lo = c.prev
cpu.SetFlag(c.flag)
got := cpu.AF.Lo
if got != c.want {
t.Errorf("unexpected value: %d {prev:%08b flag:0x%02x want:%08b}: got=%08b", i, c.prev, c.flag, c.want, got)
}
}
}
func TestResetFlag(t *testing.T) {
for i, c := range []struct {
prev uint8
flag z80.Flag
want uint8
}{
{0b00000001, z80.FlagC, 0b00000000},
{0b00000000, z80.FlagC, 0b00000000},
{0b11111111, z80.FlagC, 0b11111110},
{0b00000010, z80.FlagN, 0b00000000},
{0b00000000, z80.FlagN, 0b00000000},
{0b11111111, z80.FlagN, 0b11111101},
{0b00000100, z80.FlagPV, 0b00000000},
{0b00000000, z80.FlagPV, 0b00000000},
{0b11111111, z80.FlagPV, 0b11111011},
{0b00010000, z80.FlagH, 0b00000000},
{0b00000000, z80.FlagH, 0b00000000},
{0b11111111, z80.FlagH, 0b11101111},
{0b01000000, z80.FlagZ, 0b00000000},
{0b00000000, z80.FlagZ, 0b00000000},
{0b10111111, z80.FlagZ, 0b10111111},
{0b10000000, z80.FlagS, 0b00000000},
{0b00000000, z80.FlagS, 0b00000000},
{0b11111111, z80.FlagS, 0b01111111},
} {
var cpu z80.CPU
cpu.AF.Lo = c.prev
cpu.ResetFlag(c.flag)
got := cpu.AF.Lo
if got != c.want {
t.Errorf("unexpected value: %d {prev:%08b flag:0x%02x want:%08b}: got=%08b", i, c.prev, c.flag, c.want, got)
}
}
}