diff --git a/Z80/op_gen/gen_op.py b/Z80/op_gen/gen_op.py index eb7a49d..42e0512 100755 --- a/Z80/op_gen/gen_op.py +++ b/Z80/op_gen/gen_op.py @@ -137,12 +137,12 @@ def gen(): def main(): parse('opcodes_base.dat') - # parse('opcodes_cb.dat', 0xCB) + parse('opcodes_cb.dat', 0xCB) parse('opcodes_ed.dat', 0xED) - # parse('opcodes_ddfd.dat', 0xDD) - # parse('opcodes_ddfd.dat', 0xFD) - # parse('opcodes_ddfdcb.dat', 0xDDCB) - # parse('opcodes_ddfdcb.dat', 0xFDCB) + parse('opcodes_ddfd.dat', 0xDD) + parse('opcodes_ddfd.dat', 0xFD) + parse('opcodes_ddfdcb.dat', 0xDDCB) + parse('opcodes_ddfdcb.dat', 0xFDCB) gen() diff --git a/Z80/op_gen/opcodes.py b/Z80/op_gen/opcodes.py index e454a92..a657300 100644 --- a/Z80/op_gen/opcodes.py +++ b/Z80/op_gen/opcodes.py @@ -13,7 +13,7 @@ COND = ('c', 'z', 'm', 'pe',) NOTCOND = ('nc', 'nz', 'p', 'po',) ICOUNT = r"""%s -= %%d""" % state('icount') # TODO: what's faster a['foo'] or a.foo? -HEAD = r'''def %s(state):''' +HEAD = r'''def %s(z80):''' # globals GEN_DICT = {} diff --git a/Z80/op_gen/rw.py b/Z80/op_gen/rw.py index 55d8700..a6a5e3b 100644 --- a/Z80/op_gen/rw.py +++ b/Z80/op_gen/rw.py @@ -1,96 +1,27 @@ def state(what): - return 'state[\'%s\']' % what + return 'z80.%s' % what def state_ind(what): return state(what[1:-1]) -STATE_REG8 = ('a', 'f', 'b', 'c', 'd', 'e', 'r') - -# 16b regs stored as 2 * 8b -STATE_REG8_16 = ('af', 'bc', 'de') -STATE_REG8_16_HI = ('a', 'b', 'd') -STATE_REG8_16_LO = ('f', 'c', 'e') - -# 8b regs stored as pairs -STATE_REG16 = ('hl', 'ix', 'iy', 'pc', 'sp') -#STATE_REG16_8_HI = ('h', 'ixh', 'iyh') -#STATE_REG16_8_LO = ('l', 'ixl', 'iyl') -STATE_REG16_8 = { - 'h': 'hl', - 'l': 'hl', - 'ixh': 'ix', - 'ixl': 'ix', - 'iyh': 'iy', - 'iyl': 'iy', -} - - -def read_reg8(what): - assert what in STATE_REG8 or what in STATE_REG16_8, '%s' % where - if what in STATE_REG8: - return '(%s)' % state(what) - r16 = STATE_REG16_8[what] - r16r = state(r16) - if what == r16[0]: # hi - return '((%(r16r)s & 0xFF00) / 256)' % locals() - else: # lo - return '(%(r16r)s & 0xFF)' % locals() +# keep API separated +read_reg8 = read_flags = read_reg16 = state def write_flags(what): f = state['f'] return ['%(f) = (%(what)s & 0xFF)' % locals] -def read_flags(): - return state['f'] - def write_reg8(where, what, force=True): - assert where in STATE_REG8 or where in STATE_REG16_8, '%s' % where - if force: what = '((%s) & 0xFF)' % what - - if where in STATE_REG8: - where = state(where) - return ['%(where)s = %(what)s' % locals()] - - r16 = STATE_REG16_8[where] - r16r = state(r16) - if where == r16[0]: # hi - return [ - '# %(where)s write' % locals(), - '%(r16r)s = (%(r16r)s & 0xFF) + ((%(what)s) * 256)' % locals(), - ] - else: - return [ - '# %(where)s write' % locals(), - '%(r16r)s = (%(what)s) + (%(r16r)s & 0xFF00)' % locals(), - ] - assert False, '%s' % where - -def read_reg16(what): - assert what in STATE_REG16 or what in STATE_REG8_16, '%s' % what - if what in STATE_REG16: - return state(what) - lo = state(what[1]) - hi = state(what[0]) - return '((%(hi)s * 256) + %(lo)s)' % locals() + where = state(where) + return ['%(where)s = %(what)s' % locals()] def write_reg16(where, what, force=True): - assert where in STATE_REG16 or where in STATE_REG8_16, '%s' % where if force: what = '((%s) & 0xFFFF)' % what - - if where in STATE_REG16: - where = state(where) - return ['%(where)s = %(what)s' % locals()] - # reg 8 - lo = state(where[1]) - hi = state(where[0]) - return [ - '# %(where)s write' % locals(), - '%(lo)s = (%(what)s) & 0xFF' % locals(), - '%(hi)s = (%(what)s) / 256' % locals() - ] + where = state(where) + return ['%(where)s = %(what)s' % locals()] def read(what, mem=state('mem')): return '%(mem)s.read(%(what)s)' % locals()