naive nib dispatch. should not be so complex.

This commit is contained in:
Loic Nageleisen 2012-04-08 18:26:17 +02:00
parent 060ed1662f
commit 3f559dcf32

View file

@ -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
try: if (word & 0xF) > 0:
op = opcode_map[(opcode,)] opcode = (word & 0xF,)
if c.debug: log(op.__name__)
except KeyError:
raise Exception('Invalid opcode %01X at PC=%04X' % (opcode, c.pc))
a = c._pointer(word >> 4 & 0x3F) a = c._pointer(word >> 4 & 0x3F)
b = c._pointer(word >> 10 & 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:
op = opcode_map[opcode]
if c.debug: log(op.__name__)
except KeyError:
raise Exception('Invalid opcode %s at PC=%04X' % (["%02X"%x for x in opcode], c.pc))
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):