forked from koron-go/z80
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_exbtsg.go
166 lines (148 loc) · 3.06 KB
/
op_exbtsg.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
package z80
func oopEXDEHL(cpu *CPU) {
cpu.HL, cpu.DE = cpu.DE, cpu.HL
cpu.LastOpCycles = 4
}
func oopEXAFAF(cpu *CPU) {
cpu.AF, cpu.Alternate.AF = cpu.Alternate.AF, cpu.AF
cpu.LastOpCycles = 4
}
func oopEXX(cpu *CPU) {
cpu.BC, cpu.Alternate.BC = cpu.Alternate.BC, cpu.BC
cpu.DE, cpu.Alternate.DE = cpu.Alternate.DE, cpu.DE
cpu.HL, cpu.Alternate.HL = cpu.Alternate.HL, cpu.HL
cpu.LastOpCycles = 4
}
func oopEXSPPHL(cpu *CPU) {
v := cpu.readU16(cpu.SP)
cpu.writeU16(cpu.SP, cpu.HL.U16())
cpu.HL.SetU16(v)
cpu.LastOpCycles = 19
}
func oopEXSPPIX(cpu *CPU) {
v := cpu.readU16(cpu.SP)
cpu.writeU16(cpu.SP, cpu.IX)
cpu.IX = v
cpu.LastOpCycles = 23
}
func oopEXSPPIY(cpu *CPU) {
v := cpu.readU16(cpu.SP)
cpu.writeU16(cpu.SP, cpu.IY)
cpu.IY = v
cpu.LastOpCycles = 23
}
func (cpu *CPU) updateFlagLDID(a uint8) {
var nand uint8 = mask53 | maskH | maskPV | maskN
var or uint8
if cpu.BC.Lo != 0 || cpu.BC.Hi != 0 {
or |= maskPV
}
a += cpu.AF.Hi
or |= a&mask3 | (a<<4)&mask5
cpu.AF.Lo = cpu.AF.Lo&^nand | or
}
func oopLDI(cpu *CPU) {
de := cpu.DE.U16()
hl := cpu.HL.U16()
bc := cpu.BC.U16()
a := cpu.Memory.Get(hl)
cpu.Memory.Set(de, a)
cpu.DE.SetU16(de + 1)
cpu.HL.SetU16(hl + 1)
cpu.BC.SetU16(bc - 1)
cpu.updateFlagLDID(a)
cpu.LastOpCycles = 16
}
func oopLDIR(cpu *CPU) {
oopLDI(cpu)
if cpu.AF.Lo&maskPV != 0 { // cpu.BC != 0
cpu.PC -= 2
cpu.LastOpCycles = 21
} else {
cpu.LastOpCycles = 16
}
}
func oopLDD(cpu *CPU) {
de := cpu.DE.U16()
hl := cpu.HL.U16()
bc := cpu.BC.U16()
a := cpu.Memory.Get(hl)
cpu.Memory.Set(de, a)
cpu.DE.SetU16(de - 1)
cpu.HL.SetU16(hl - 1)
cpu.BC.SetU16(bc - 1)
cpu.updateFlagLDID(a)
cpu.LastOpCycles = 16
}
func oopLDDR(cpu *CPU) {
oopLDD(cpu)
if cpu.AF.Lo&maskPV != 0 { // cpu.BC != 0
cpu.PC -= 2
cpu.LastOpCycles = 21
} else {
cpu.LastOpCycles = 16
}
}
func (cpu *CPU) updateFlagCPx(r, a, b uint8) {
c := r ^ a ^ b
var nand uint8 = maskS53 | maskZ | maskH | maskPV | maskN
var or uint8
or |= r & maskS
if r == 0 {
or |= maskZ
}
or |= c & maskH
if cpu.BC.Lo != 0 || cpu.BC.Hi != 0 {
or |= maskPV
}
or |= maskN
r2 := r - (c & 0x10 >> 4)
or |= r2 & 0x02 << 4 // mask5
or |= r2 & mask3
//if r&0x0f == 8 && c&maskH != 0 {
// or &= ^uint8(mask3)
//}
cpu.AF.Lo = cpu.AF.Lo&^nand | or
}
func oopCPI(cpu *CPU) {
hl := cpu.HL.U16()
bc := cpu.BC.U16()
a := cpu.AF.Hi
x := cpu.Memory.Get(hl)
r := a - x
cpu.HL.SetU16(hl + 1)
cpu.BC.SetU16(bc - 1)
cpu.updateFlagCPx(r, a, x)
cpu.LastOpCycles = 16
}
func oopCPIR(cpu *CPU) {
oopCPI(cpu)
// cpu.BC != 0 && A - (HL) != 0
if cpu.AF.Lo&maskPV != 0 && cpu.AF.Lo&maskZ == 0 {
cpu.PC -= 2
cpu.LastOpCycles = 21
} else {
cpu.LastOpCycles = 16
}
}
func oopCPD(cpu *CPU) {
hl := cpu.HL.U16()
bc := cpu.BC.U16()
a := cpu.AF.Hi
x := cpu.Memory.Get(hl)
r := a - x
cpu.HL.SetU16(hl - 1)
cpu.BC.SetU16(bc - 1)
cpu.updateFlagCPx(r, a, x)
cpu.LastOpCycles = 16
}
func oopCPDR(cpu *CPU) {
oopCPD(cpu)
// cpu.BC != 0 && A - (HL) != 0
if cpu.AF.Lo&maskPV != 0 && cpu.AF.Lo&maskZ == 0 {
cpu.PC -= 2
cpu.LastOpCycles = 21
} else {
cpu.LastOpCycles = 16
}
}