Merge old work on laptop with new python work
This commit is contained in:
commit
7e842bd7a6
|
|
@ -0,0 +1,49 @@
|
|||
class CPU:
|
||||
def __init__(self):
|
||||
self.running = False
|
||||
self.IP = 254
|
||||
self.acc = 0
|
||||
self.flags = { 'C': False, 'Z': False, 'N': False, 'Eq': False }
|
||||
self.instruction = { 'opcode': False, 'operand': False }
|
||||
self.memory = False
|
||||
|
||||
def load_memory(self, bytes):
|
||||
self.memory = bytes + bytearray(256 - len(bytes))
|
||||
print(self.memory)
|
||||
|
||||
def step(self):
|
||||
if self.IP >= 256:
|
||||
self.IP = 0
|
||||
print(self.IP)
|
||||
self.instruction['opcode'] = self.memory[self.IP]
|
||||
self.IP = self.IP+1
|
||||
self.instruction['operand'] = self.memory[self.IP]
|
||||
self.IP = self.IP+1
|
||||
print(self.instruction)
|
||||
|
||||
nums2mnems = {
|
||||
'hlt': '00',
|
||||
'nop': '01',
|
||||
'add_lit': '04'
|
||||
}
|
||||
|
||||
def hlt(self):
|
||||
self.running = false
|
||||
|
||||
def nop(self):
|
||||
pass
|
||||
|
||||
def add_lit(num):
|
||||
self.acc = self.acc + num
|
||||
|
||||
cpu = CPU()
|
||||
print(cpu)
|
||||
print(cpu.running)
|
||||
|
||||
prog = '04 01 14 01 00 00'
|
||||
b = bytes.fromhex(prog)
|
||||
cpu.load_memory(b)
|
||||
|
||||
cpu.step()
|
||||
cpu.step()
|
||||
cpu.step()
|
||||
Loading…
Reference in New Issue