mirror of
https://github.com/lloeki/python-dcpu_16.git
synced 2025-12-06 18:04:38 +01:00
naive nib dispatch. should not be so complex.
This commit is contained in:
parent
060ed1662f
commit
c44911a41d
1 changed files with 14 additions and 6 deletions
20
dcpu_16.py
20
dcpu_16.py
|
|
@ -384,19 +384,27 @@ class CPU(object):
|
||||||
def step(c):
|
def step(c):
|
||||||
"""start handling [PC]"""
|
"""start handling [PC]"""
|
||||||
word = c.m[c.pc]
|
word = c.m[c.pc]
|
||||||
opcode = word & 0xF
|
|
||||||
c.pc = (c.pc + 1) & wmask
|
c.pc = (c.pc + 1) & wmask
|
||||||
|
if (word & 0xF) > 0:
|
||||||
|
opcode = (word & 0xF,)
|
||||||
|
a = c._pointer(word >> 4 & 0x3F)
|
||||||
|
b = c._pointer(word >> 10 & 0x3F)
|
||||||
|
args = (a, b)
|
||||||
|
elif (word >> 4 & 0x3F) > 0:
|
||||||
|
opcode = (0x0, word >> 4 & 0x3F)
|
||||||
|
a = c._pointer(word >> 10 & 0x3F)
|
||||||
|
args = (a, )
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid opcode %s at PC=%04X' % (["%02X"%x for x in opcode], c.pc))
|
||||||
try:
|
try:
|
||||||
op = opcode_map[(opcode,)]
|
op = opcode_map[opcode]
|
||||||
if c.debug: log(op.__name__)
|
if c.debug: log(op.__name__)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise Exception('Invalid opcode %01X at PC=%04X' % (opcode, c.pc))
|
raise Exception('Invalid opcode %s at PC=%04X' % (["%02X"%x for x in opcode], c.pc))
|
||||||
a = c._pointer(word >> 4 & 0x3F)
|
|
||||||
b = c._pointer(word >> 10 & 0x3F)
|
|
||||||
if c.skip:
|
if c.skip:
|
||||||
c.skip = False
|
c.skip = False
|
||||||
else:
|
else:
|
||||||
op(c, a, b)
|
op(c, *args)
|
||||||
if c.debug: log(c.dump_r())
|
if c.debug: log(c.dump_r())
|
||||||
|
|
||||||
def dump_r(c):
|
def dump_r(c):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue