-
Notifications
You must be signed in to change notification settings - Fork 4
/
op_bitop_test.go
202 lines (194 loc) · 4.58 KB
/
op_bitop_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package z80
import (
"fmt"
"testing"
)
func TestBitop_BITbr(t *testing.T) {
t.Parallel()
for i := 0; i <= 7; i++ {
for j := 0; j <= 7; j++ {
if j == 6 {
continue
}
b, r := i, j
n := fmt.Sprintf("BIT %d, %s", b, rLabel[r])
t.Run(n, func(t *testing.T) {
t.Parallel()
var gpr, wantGPR GPR
p := rGet(t, &gpr, r)
for v := 0; v <= 255; v++ {
gpr = testInitGPR
*p = uint8(v)
mem := MapMemory{}.Put(0, 0xcb, uint8(0x40|b<<3|r))
wantGPR = gpr
flagOp{}.Put(Z, v&(1<<b) == 0).Set(H).Reset(N).
ApplyOn(&wantGPR.AF.Lo)
tSteps(t, "",
States{GPR: gpr, SPR: SPR{IX: 0x1000}},
mem,
1,
States{
GPR: wantGPR,
SPR: SPR{PC: 2, IR: Register{Lo: 0x02},
IX: 0x1000,
}},
mem.Clone(),
maskS|maskPV|mask5|mask3|maskC,
)
}
})
}
}
}
func TestBitop_BITbIXd(t *testing.T) {
t.Parallel()
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("BIT %d, (IX+d)", b)
t.Run(n, func(t *testing.T) {
t.Parallel()
for d := -128; d <= 127; d++ {
for v := 0; v <= 255; v++ {
mem := MapMemory{}.
Put(0, 0xdd, 0xcb, uint8(d), uint8(0x46|b<<3)).
Put(0x1000+uint16(d), uint8(v))
wantZ := v&(1<<b) == 0
var flag uint8
flagOp{}.Put(Z, wantZ).Set(H).Reset(N).ApplyOn(&flag)
tSteps(t, "",
States{GPR: GPR{}, SPR: SPR{IX: 0x1000}},
mem,
1,
States{
GPR: GPR{AF: Register{Lo: flag}},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03},
IX: 0x1000,
}},
mem.Clone(),
maskS|maskPV|mask5|mask3|maskC,
)
}
}
})
}
}
func TestBitop_BITbIYd(t *testing.T) {
t.Parallel()
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("BIT %d, (IY+d)", b)
t.Run(n, func(t *testing.T) {
t.Parallel()
for d := -128; d <= 127; d++ {
for v := 0; v <= 255; v++ {
mem := MapMemory{}.
Put(0, 0xfd, 0xcb, uint8(d), uint8(0x46|b<<3)).
Put(0x4180+uint16(d), uint8(v))
wantZ := v&(1<<b) == 0
var flag uint8
flagOp{}.Put(Z, wantZ).Set(H).Reset(N).ApplyOn(&flag)
tSteps(t, "",
States{GPR: GPR{}, SPR: SPR{IY: 0x4180}},
mem,
1,
States{
GPR: GPR{AF: Register{Lo: flag}},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03},
IY: 0x4180,
}},
mem.Clone(),
maskS|maskPV|mask5|mask3|maskC,
)
}
}
})
}
}
func TestBitop_SETbIXd(t *testing.T) {
t.Parallel()
const base uint16 = 0x5678
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("SET %d, (IX+d)", b)
t.Run(n, func(t *testing.T) {
for d := -128; d <= 127; d++ {
mem := MapMemory{}.
Put(0, 0xdd, 0xcb, uint8(d), uint8(0xc6|b<<3)).
Put(base+uint16(d), 0)
wantMem := mem.Clone().Put(base+uint16(d), 1<<b)
tOneStep(t,
States{GPR: GPR{}, SPR: SPR{IX: base}},
mem,
States{GPR: GPR{},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03}, IX: base}},
wantMem)
}
})
}
}
func TestBitop_SETbIYd(t *testing.T) {
t.Parallel()
const base uint16 = 0x9abc
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("SET %d, (IY+d)", b)
t.Run(n, func(t *testing.T) {
for d := -128; d <= 127; d++ {
mem := MapMemory{}.
Put(0, 0xfd, 0xcb, uint8(d), uint8(0xc6|b<<3)).
Put(base+uint16(d), 0)
wantMem := mem.Clone().Put(base+uint16(d), 1<<b)
tOneStep(t,
States{GPR: GPR{}, SPR: SPR{IY: base}},
mem,
States{GPR: GPR{},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03}, IY: base}},
wantMem)
}
})
}
}
func TestBitop_RESbIXd(t *testing.T) {
t.Parallel()
const base uint16 = 0x5678
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("RES %d, (IX+d)", b)
t.Run(n, func(t *testing.T) {
for d := -128; d <= 127; d++ {
mem := MapMemory{}.
Put(0, 0xdd, 0xcb, uint8(d), uint8(0x86|b<<3)).
Put(base+uint16(d), 0xff)
wantMem := mem.Clone().Put(base+uint16(d), 0xff&^(1<<b))
tOneStep(t,
States{GPR: GPR{}, SPR: SPR{IX: base}},
mem,
States{GPR: GPR{},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03}, IX: base}},
wantMem)
}
})
}
}
func TestBitop_RESbIYd(t *testing.T) {
t.Parallel()
const base uint16 = 0x9abc
for i := 0; i <= 7; i++ {
b := i
n := fmt.Sprintf("RES %d, (IY+d)", b)
t.Run(n, func(t *testing.T) {
for d := -128; d <= 127; d++ {
mem := MapMemory{}.
Put(0, 0xfd, 0xcb, uint8(d), uint8(0x86|b<<3)).
Put(base+uint16(d), 0xff)
wantMem := mem.Clone().Put(base+uint16(d), 0xff&^(1<<b))
tOneStep(t,
States{GPR: GPR{}, SPR: SPR{IY: base}},
mem,
States{GPR: GPR{},
SPR: SPR{PC: 4, IR: Register{Lo: 0x03}, IY: base}},
wantMem)
}
})
}
}