From 3f559dcf321ace32465b2aa7d2f1e7a5b587d14f Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Sun, 8 Apr 2012 18:26:17 +0200 Subject: [PATCH] naive nib dispatch. should not be so complex. --- dcpu_16.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dcpu_16.py b/dcpu_16.py index 0372c1e..3b25456 100644 --- a/dcpu_16.py +++ b/dcpu_16.py @@ -384,19 +384,27 @@ class CPU(object): def step(c): """start handling [PC]""" word = c.m[c.pc] - opcode = word & 0xF 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: - op = opcode_map[(opcode,)] + op = opcode_map[opcode] 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) - b = c._pointer(word >> 10 & 0x3F) + raise Exception('Invalid opcode %s at PC=%04X' % (["%02X"%x for x in opcode], c.pc)) if c.skip: c.skip = False else: - op(c, a, b) + op(c, *args) if c.debug: log(c.dump_r()) def dump_r(c):