Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

50 lignes
2.2KB

  1. import sys, os, glob, itertools, random
  2. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  3. from helpertest import *
  4. from objfmt import Obj, pn
  5. from cpu6502 import CPU
  6. OPS = {
  7. 'lt': lambda a,b: int(a<b), 'gt': lambda a,b: int(a>b), 'le': lambda a,b: int(a<=b), 'ge': lambda a,b: int(a>=b),
  8. 'eq': lambda a,b: int(a==b), 'ne': lambda a,b: int(a!=b),
  9. 'add': lambda a,b: (a+b)&0xFFFF, 'sub': lambda a,b: (a-b)&0xFFFF, 'and': lambda a,b: a&b, 'or': lambda a,b: a|b, 'xor': lambda a,b: a^b,
  10. 'mul': lambda a,b: (a*b)&0xFFFF,
  11. }
  12. def s16(v): return v-65536 if v>=32768 else v
  13. vals=[0,1,2,3,5,100,255,256,257,1000,32767,32768,40000,65535,65534,12345]
  14. def run(h, name, a, b):
  15. cpu = CPU(); h.install(cpu)
  16. cpu.m[0x14]=0; cpu.m[0x15]=0x80; cpu.sp=0xF0
  17. for i,v in enumerate((a&255,a>>8,b&255,b>>8)): cpu.m[0x33C+i]=v
  18. cpu.a=4; cpu.x=0; cpu.y=0
  19. cpu.call(h.addr(name))
  20. return cpu.m[0x33C]|cpu.m[0x33D]<<8, cpu
  21. for f in sorted(glob.glob('lib/c*.obj')):
  22. o = Obj.parse(open(f,'rb').read())
  23. if f.endswith('c105.obj') or 'cstart' in f or 'conv' in f or 'localdefs' in f: continue
  24. if any(bytes(n).startswith(b'C$') is False for n,k,off in o.defs): pass
  25. ext={}
  26. try:
  27. h = Helper(o, 0x6000, {nm.decode('latin1') if False else bytes(nm): 0xD000 for nm,k,off in o.refs})
  28. except Exception as ex:
  29. print(os.path.basename(f), 'load fail', ex); continue
  30. for nm,k,off in o.defs:
  31. if not bytes(nm).startswith(b'C$'): continue
  32. res = {}
  33. try:
  34. for signed in (False, True):
  35. match = {}
  36. for opn,fn in OPS.items():
  37. ok = True
  38. for a,b in itertools.product(vals, vals):
  39. r,_ = run(h, nm, a, b)
  40. A,B = (s16(a),s16(b)) if signed else (a,b)
  41. exp = fn(A,B)
  42. exp &= 0xFFFF
  43. if r != exp: ok = False; break
  44. if ok: match[opn]=True
  45. if match: res[signed] = list(match)
  46. except Exception as ex:
  47. res = 'ERR %s' % ex
  48. print('%-14s %-10s size %3d %s' % (os.path.basename(f), pn(nm), len(o.code), res))

Powered by TurnKey Linux.