diff options
author | vin <git@vineetk.net> | 2024-06-09 12:56:13 +0530 |
---|---|---|
committer | vin <git@vineetk.net> | 2024-06-09 13:08:31 +0530 |
commit | 207c6903f57f2364770c466dbe9807581ef96dc5 (patch) | |
tree | 6e02fe40c7a404902bd8b578c3614c26a447cdc4 /converter.py | |
parent | 72e29b3d25bfe93810b3faf3133dfc3c15f15e14 (diff) |
programmatically create switch cases for opcodes based on opcode json
The JSON is from https://github.com/ericTheEchidna/65C02-JSON/ and
saved me a lot of time from writing the cases for each opcode by hand.
Diffstat (limited to 'converter.py')
-rw-r--r-- | converter.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/converter.py b/converter.py new file mode 100644 index 0000000..da9d8cd --- /dev/null +++ b/converter.py @@ -0,0 +1,39 @@ +import json + +address_mode_table = { + 'Implied': 'AM_ACC', + 'Immediate': 'AM_IMM', + 'Zero Page': 'AM_ZP', + 'Zero Page, X': 'AM_ZP_X', + 'Zero Page, Y': 'AM_ZP_Y', + 'Absolute': 'AM_ABS', + 'Absolute, X': 'AM_ABS_X', + 'Absolute, Y': 'AM_ABS_Y', + 'Indirect': 'AM_IND', + '(Indirect)': 'AM_IND', + '(Indirect, X)': 'AM_IND_X', + '(Indirect), Y': 'AM_IND_Y', +} + +# https://github.com/ericTheEchidna/65C02-JSON/ +j = json.load(open('opcodes_65c02.json', 'r')) + +#print(j) + +for i in j: + #print(i) + instruction = str.lower(i["instruction"]) + for op in i["opcodes"]: + address_mode = i["opcodes"][op]["address_mode"] + if "Bit " in address_mode: + am = 'AM_REL' + else: + am = address_mode_table[address_mode] + + bytes = i["opcodes"][op]["bytes"] + cycles = i["opcodes"][op]["cycles"] + + print(f'''case {op}: + {instruction}(opcode_arg({am})); + cycles += {cycles}; + break;''') |