-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_comparetest.go
More file actions
164 lines (128 loc) · 4.69 KB
/
Copy pathset_comparetest.go
File metadata and controls
164 lines (128 loc) · 4.69 KB
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
package cpu
// This is the implementation of what the `CMP`, `CPX`, and `CPY` instructions
// do.
//
// This will change the flags in the Core it's run in.
func (c *Core) cmp_impl(what, with byte) {
if what == with {
c.Flags = c.Flags | FLAG_ZERO
c.Flags = c.Flags | FLAG_CARRY
} else if what < with {
c.Flags = c.Flags & ^FLAG_ZERO
c.Flags = c.Flags & ^FLAG_CARRY
} else if what > with {
c.Flags = c.Flags & ^FLAG_ZERO
c.Flags = c.Flags | FLAG_CARRY
}
if (uint16(what)-uint16(with))&0b10000000 > 0 {
c.Flags = c.Flags | FLAG_NEGATIVE
} else {
c.Flags = c.Flags & ^FLAG_NEGATIVE
}
}
// This is the implementation of what the `BIT` instruction does.
//
// This will change the flags in the Core it's run in.
func (c *Core) bit_impl(with byte) {
var r = c.A & with
if r == 0 {
c.Flags = c.Flags | FLAG_ZERO
} else {
c.Flags = c.Flags & ^FLAG_ZERO
}
if r&0b01000000 > 0 {
c.Flags = c.Flags | FLAG_OVERFLOW
} else {
c.Flags = c.Flags & ^FLAG_OVERFLOW
}
if r&0b10000000 > 0 {
c.Flags = c.Flags | FLAG_NEGATIVE
} else {
c.Flags = c.Flags & ^FLAG_NEGATIVE
}
}
// Compare Memory with Accumulator - Absolute
func (c *Core) CMP____a(addr uint16) { c.PC += 3; c.cmp_impl(c.A, c.Memory[addr]) }
// Compare Memory with Accumulator - Absolute indexed with X
func (c *Core) CMP___ax(addr uint16) { c.PC += 3; c.cmp_impl(c.A, c.Memory[addr+uint16(c.X)]) }
// Compare Memory with Accumulator - Absolute indexed with Y
func (c *Core) CMP___ay(addr uint16) { c.PC += 3; c.cmp_impl(c.A, c.Memory[addr+uint16(c.Y)]) }
// Compare Memory with Accumulator - Immediate
func (c *Core) CMP__Imm(literal byte) { c.PC += 2; c.cmp_impl(c.A, literal) }
// Compare Memory with Accumulator - Zero Page
func (c *Core) CMP__ZPg(zp byte) { c.PC += 2; c.cmp_impl(c.A, c.Memory[zp]) }
// Compare Memory with Accumulator - Zero Page Indexed Indirect
func (c *Core) CMP_IZPx(zp byte) { c.PC += 2; c.cmp_impl(c.A, c.Memory[c.indirectZpX(zp)]) }
// Compare Memory with Accumulator - Zero Page indexed with X
func (c *Core) CMP__ZPx(zp byte) { c.PC += 2; c.cmp_impl(c.A, c.Memory[(zp+c.X)&0xFF]) }
// Compare Memory with Accumulator - Zero Page Indirect Indexed with Y
func (c *Core) CMP_IZPy(zp byte) { c.PC += 2; c.cmp_impl(c.A, c.Memory[c.indirectZpY(zp)]) }
// Compare Memory with X - Absolute
func (c *Core) CPX____a(addr uint16) { c.PC += 3; c.cmp_impl(c.X, c.Memory[addr]) }
// Compare Memory with X - Immediate
func (c *Core) CPX__Imm(literal byte) { c.PC += 2; c.cmp_impl(c.X, literal) }
// Compare Memory with X - Zero Page
func (c *Core) CPX__ZPg(zp byte) { c.PC += 2; c.cmp_impl(c.X, c.Memory[zp]) }
// Compare Memory with Y - Absolute
func (c *Core) CPY____a(addr uint16) { c.PC += 3; c.cmp_impl(c.Y, c.Memory[addr]) }
// Compare Memory with Y - Immediate
func (c *Core) CPY__Imm(literal byte) { c.PC += 2; c.cmp_impl(c.Y, literal) }
// Compare Memory with Y - Zero Page
func (c *Core) CPY__ZPg(zp byte) { c.PC += 2; c.cmp_impl(c.Y, c.Memory[zp]) }
// Bit Test Memory with Accumulator - Absolute
func (c *Core) BIT____a(addr uint16) { c.PC += 3; c.bit_impl(c.Memory[addr]) }
// Bit Test Memory with Accumulator - Zero Page
func (c *Core) BIT__ZPg(zp byte) { c.PC += 2; c.bit_impl(c.Memory[zp]) }
// 65c02 Instructions/Implementations below this line
func (c *Core) trb_impl(loc uint16) {
what := c.Memory[loc]
var r = c.A & what
c.Memory[loc] = (c.A ^ 0xFF) & what
if r == 0 {
c.Flags = c.Flags | FLAG_ZERO
} else {
c.Flags = c.Flags & ^FLAG_ZERO
}
}
func (c *Core) tsb_impl(loc uint16) {
what := c.Memory[loc]
var r = c.A & what
c.Memory[loc] = c.A | what
if r == 0 {
c.Flags = c.Flags | FLAG_ZERO
} else {
c.Flags = c.Flags & ^FLAG_ZERO
}
}
// Bit Test Memory with Accumulator - Absolute Indexed with X
//
// CMOS 65c02
func (c *Core) BIT___ax(addr uint16) { c.bit_impl(c.Memory[addr+uint16(c.X)]) }
// Bit Test Memory with Accumulator - Zero Page Indexed with X
//
// CMOS 65c02
func (c *Core) BIT__ZPx(zp byte) { c.bit_impl(c.Memory[(zp+c.X)&0xFF]) }
// Bit Test Memory with Accumulator - Immediate
//
// CMOS 65c02
func (c *Core) BIT__Imm(literal byte) { c.bit_impl(literal) }
// Compare Memory with Accumulator - Zero Page Indirect
//
// CMOS 65c02
func (c *Core) CMP__IZP(zp byte) { c.PC += 2; c.cmp_impl(c.A, c.Memory[c.indirectZp(zp)]) }
// Test and Reset Bits - Absolute
//
// CMOS 65c02
func (c *Core) TRB____a(addr uint16) { c.PC += 3; c.trb_impl(addr) }
// Test and Reset Bits - Zero Page
//
// CMOS 65c02
func (c *Core) TRB__ZPg(zp byte) { c.PC += 2; c.trb_impl(uint16(zp)) }
// Test and Set Bits - Absolute
//
// CMOS 65c02
func (c *Core) TSB____a(addr uint16) { c.PC += 3; c.tsb_impl(addr) }
// Test and Set Bits - Zero Page
//
// CMOS 65c02
func (c *Core) TSB__ZPg(zp byte) { c.PC += 2; c.tsb_impl(uint16(zp)) }