OXYGENHUB
◆ rrdc-perf enhanced-x16-emulator / src / cpu / extract.py
1.5 KiB · Python · last changed chore(): initial commit 25 days ago source blame history raw
9120e874 Andy McCall 1
# *******************************************************************************************
2
# *******************************************************************************************
3
#
4
#		File:		extract.py
5
#		Date:		3rd September 2019
6
#		Purpose:	Extract opcode descriptions from tables.h.org
7
#		Author:		Paul Robson ([email protected])
8
#
9
# *******************************************************************************************
10
# *******************************************************************************************
11
12
import re
13
#
14
#							Get one element from one table.
15
#
16
def extract(opc,n):
17
	line = opc[n >> 4]
18
	m = re.match("^\\/\\*\\s+[0-9A-Fa-f]\\s+\\*\\/(.*)\\s*\\/\\*\\s*[0-9A-Fa-f]\\s*\\*\\/$",line)
19
	assert m is not None,line
20
	return m.group(1).replace(" ","").split(",")[n % 16]
21
22
#
23
#						Convert a tables.h type file to a list of opcodes
24
#
25
def convert(src,tgt):
26
	src = [x.strip() for x in open(src).readlines()]
27
	#
28
	#		Pull out data.
29
	#
30
	eac = src[3:3+16]
31
	opcodes = src[23:23+16]
32
	cycles = src[43:43+16]
33
	h = open(tgt,"w")
34
	for n in range(0,256):
35
		action = extract(opcodes,n)
36
		if action != "nop":
37
			amode = extract(eac,n)
38
			icycles = extract(cycles,n)
39
			h.write("{1:3} {2:4} {3} ${0:02x}\n".format(n,action,amode,icycles))
40
	h.close()
41
#
42
#		Stop it being overwritten accidentally. Should be no reason to regenerate 6502.opcodes
43
#		The pair is so you can compare the two sets of opcodes. (dis-include the 65c02.opcodes
44
#		extensions first.)
45
#
46
#convert("tables.h.org","6502.opcodes")
47
#convert("tables.h","/tmp/6502.opcodes")