-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.py
214 lines (150 loc) · 3.41 KB
/
cpu.py
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
203
204
205
206
207
208
209
210
211
212
213
214
from memory import Memory
class InstructionSet6502:
def brk(self):
# force break
pass
def bit(self):
# test a bit in memory
pass
def jmp(self):
# jump to a new location
pass
def jsr(self):
# jump to a new location and save return address
pass
def nop(self):
# no operation
pass
def rti(self):
# return from interrupt
pass
def rts(self):
# return from subroutine
pass
def dey(self):
# y--
pass
def dex(self):
# x--
pass
def iny(self):
# y++
pass
def inx(self):
# x++
pass
def txa(self):
# transfer x to accumulator
pass
def tax(self):
# transfer accumulator to x
pass
def tya(self):
# transfer y to accumulator
pass
def tay(self):
# transfer accumulator to y
pass
def txs(self):
# transfer x to stack register
pass
def tsx(self):
# transfer stack register to x
pass
def php(self):
pass
def plp(self):
pass
def pla(self):
# pull accumulator from stack
pass
def pha(self):
# push accumulator on stack
pass
class CpuRegister:
stack_register = 0xfd
pc_register = 0
accumulator = 0
flags = 0x34
x = 0
y = 0
MASK_NEGATIVE = 0x80
MASK_OVERFLOW = 0x40
MASK_BREAK = 0x10
MASK_DECIMAL = 0x8
MASK_INTERUPT = 0x4
MASK_ZERO = 0x2
MASK_CARRAY = 0x1
def get_pc(self):
pass
def get_carry(self):
if (self.flags & self.MASK_CARRAY) != 0:
return 1
elif (self.flags & self.MASK_CARRAY) == 0:
return 0
def get_zero(self):
return (self.flags & self.MASK_ZERO)
"""
set method
"""
def _set_carry(self):
self.flags |= self.MASK_CARRAY
def _set_zero(self):
self.flags |= self.MASK_ZERO
def _set_decimal(self):
self.flags |= self.MASK_DECIMAL
def _set_disable_interupt(self):
self.flags |= self.MASK_INTERUPT
def _set_break(self):
self.flags |= self.MASK_BREAK
def _set_negative(self):
self.flags &= ~self.MASK_ZERO
def _set_overflow(self):
self.flags |= self.MASK_OVERFLOW
"""
get method
"""
def is_negative(self):
pass
def is_overflow(self):
pass
def is_break(self):
pass
def is_decimal(self):
pass
def is_zero(self):
pass
def is_carry(self):
pass
def is_disable_interupt(self):
pass
"""
set flag regiser
"""
def set_a(self, value):
self.a = self.a & 0xff
def set_x(self, value):
self.x = self.x & 0xff
def set_y(self, value):
self.y = self.y & 0xff
def set_stack(self, value):
self.stack_register = value & 0xffff
def set_pc(self, value):
self.pc_register = value & 0xff
class CPU(InstructionSet6502):
register = CpuRegister()
memory = Memory()
def execute_instruction(self, op_code):
pass
def execute_pc(self, pc):
pass
def reset(self):
pass
def get_pc(self):
pass
def nmi(self, vector):
# nmi中断
pass
def irq(self, vector):
# irq中断
pass