comparison analyze_olp.py @ 1146:3e24de8d8073

Add support for SMS controllers
author Michael Pavone <pavone@retrodev.com>
date Tue, 03 Jan 2017 21:18:52 -0800
parents b290343e5664
children 6854ab93d182
comparison
equal deleted inserted replaced
1145:494234e7e88f 1146:3e24de8d8073
16 return sample & mask 16 return sample & mask
17 17
18 def detect_low(sample, bit): 18 def detect_low(sample, bit):
19 mask = 1 << bit 19 mask = 1 << bit
20 return not sample & mask 20 return not sample & mask
21
22 def get_value(sample, bits):
23 value = 0
24 for i in xrange(0, len(bits)):
25 bit = bits[i]
26 value |= (sample >> bit & 1) << i
27 return value
28
29 def swizzle_mode4(row, col):
30 return (col & 1) | (row << 1) | (col << 8 & 0xFE00)
21 31
22 def analyze_delays(chanmap, datafile): 32 def analyze_delays(chanmap, datafile):
23 if 'M68K_CLK' in chanmap: 33 if 'M68K_CLK' in chanmap:
24 m68k_clk = chanmap['M68K CLK'] 34 m68k_clk = chanmap['M68K CLK']
25 elif 'CLK' in chanmap: 35 elif 'CLK' in chanmap:
81 print 'RAM refresh at ', clks 91 print 'RAM refresh at ', clks
82 else: 92 else:
83 print 'RAM refresh at', clks, 'delta since last:', clks-prevRefresh 93 print 'RAM refresh at', clks, 'delta since last:', clks-prevRefresh
84 prevRefresh = clks 94 prevRefresh = clks
85 last = sample 95 last = sample
86 96
97
98 table_start = 0x3800
99 table_end = table_start + 0x600
100 sat_start = 0x3F00 #0x3E00
101 sat_xname = sat_start + 0x80
102 sat_end = sat_start + 0x100
103
104
105 def analyze_vram(chanmap, datafile):
106 address_bits = [chanmap['AD{0}'.format(i)] for i in xrange(0, 8)]
107 ras = chanmap['!RAS']
108 cas = chanmap['!CAS']
109 hsync = chanmap['!HSYNC']
110 state = 'begin'
111 last = False
112 for line in datafile.readlines():
113 line = line.strip()
114 if line and not line.startswith(';'):
115 sample,_,num = line.partition('@')
116 sample = int(sample, 16)
117 if not (last is False):
118 if detect_fall(last, sample, hsync):
119 print 'HSYNC low @ {0}'.format(num)
120 elif detect_rise(last, sample, hsync):
121 print 'HSYNC high @ {0}'.format(num)
122 if state == 'begin':
123 if detect_fall(last, sample, ras):
124 state = 'ras'
125 row = get_value(sample, address_bits)
126 elif detect_fall(last, sample, cas):
127 state = 'cas'
128 elif state == 'ras':
129 if detect_fall(last, sample, cas):
130 col = get_value(sample, address_bits)
131 address = swizzle_mode4(row, col)
132
133 if address < table_end and address >= table_start:
134 offset = (address - table_start)/2
135 desc = 'Map Row {0} Col {1}'.format(offset / 32, offset & 31)
136 elif address >= sat_start and address < sat_xname:
137 offset = address - sat_start
138 desc = 'Sprite {0} Y Read'.format(offset)
139 elif address >= sat_xname and address < sat_end:
140 offset = address - sat_xname
141 desc = 'Sprite {0} X/Name Read'.format(offset / 2)
142 else:
143 desc = 'Tile {0} Row {1}'.format(address / 32, ((address / 4) & 7) + (0.5 if address & 2 else 0))
144 print '{0:02X}:{1:02X} - {2:04X} @ {3} - {4}'.format(row, col, address, num, desc)
145 state = 'begin'
146 elif state == 'cas':
147 if detect_fall(last, sample, ras):
148 print 'refresh @ {0}'.format(num)
149 state = 'begin'
150 last = sample
87 151
88 def main(args): 152 def main(args):
89 if len(args) < 2: 153 if len(args) < 2:
90 print 'Usage: analyze_olp.py filename' 154 print 'Usage: analyze_olp.py filename'
91 exit(1) 155 exit(1)
96 print channels 160 print channels
97 chanmap = {} 161 chanmap = {}
98 for i in xrange(0, len(channels)): 162 for i in xrange(0, len(channels)):
99 chanmap[channels[i]] = i 163 chanmap[channels[i]] = i
100 datafile = olpfile.open('data.ols') 164 datafile = olpfile.open('data.ols')
101 analyze_delays(chanmap, datafile) 165 #analyze_delays(chanmap, datafile)
166 analyze_vram(chanmap, datafile)
102 datafile.close() 167 datafile.close()
103 #datafile = olpfile.open('data.ols') 168 #datafile = olpfile.open('data.ols')
104 #analyze_refresh(chanmap, datafile) 169 #analyze_refresh(chanmap, datafile)
105 170
106 if __name__ == '__main__': 171 if __name__ == '__main__':