import sys, os, random sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from helpertest import * from objfmt import Obj def make(objfile, base=0x6000): o = Obj.parse(open(objfile, 'rb').read()) return Helper(o, base, {'C$HIGHMEM': 0xC000, 'C$ERROR': 0xFFF0}) def setup(seed, cpu): rnd = random.Random(seed) for i in range(0x0000, 0x0800): cpu.m[i] = rnd.randrange(256) for i in range(0x8000, 0x8400): cpu.m[i] = rnd.randrange(256) cpu.m[0xC000] = 0x00; cpu.m[0xC001] = 0xC0 # HIGHMEM = $C000 fp = 0x8000 + rnd.randrange(0, 0x100) # $14/15 frame pointer cpu.m[0x14] = fp & 255; cpu.m[0x15] = fp >> 8 sp1 = 0x9000 + rnd.randrange(1, 0x100) cpu.m[0x1A] = sp1 & 255; cpu.m[0x1B] = sp1 >> 8 cpu.m[sp1 - 1] = rnd.randrange(0, 8) * 2 # popped byte $FC cpu.m[0xFB] = rnd.choice([0, 2, 4, 6, 8, 10]) cpu.sp = 0xF0 cpu.a = rnd.choice([0, 2, 4, 6, 8, 12, 20]) # locals cpu.x = rnd.choice([0, 2, 4, 10]); cpu.y = rnd.choice([0, 0, 1]) # frame size return rnd if __name__ == '__main__': f = sys.argv[1] h = make(f) tot_p = tot_e = 0; N = 200 for seed in range(N): cpu = CPU(); h.install(cpu); setup(seed, cpu) a0,x0,y0=cpu.a,cpu.x,cpu.y c = cpu.call(h.addr('C$105')) tot_p += c # epilogue: A = locals, X,Y = frame size as in prolog (caller passes the same numbers) cpu.a, cpu.x, cpu.y = a0, x0, y0 c2 = cpu.call(h.addr('C$106')) tot_e += c2 print('prolog avg cycles %.0f epilogue avg cycles %.0f' % (tot_p / N, tot_e / N))