gameboy superoptimizer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
926 B

3 years ago
3 years ago
  1. from gbso.cpu.insn import *
  2. from gbso.cpu.regs import R8, R16
  3. from gbso.optimize import (
  4. DEFAULT_PROB_INSN,
  5. DEFAULT_PROB_INSN_UNUSED,
  6. DEFAULT_PROB_OPCODE,
  7. DEFAULT_PROB_OPERAND,
  8. DEFAULT_PROB_SWAP,
  9. optimize,
  10. )
  11. from gbso.program.program import Program
  12. from gbso.program.mutate import mutate_program
  13. rLCDC = 0xFF40
  14. rIE = 0xFFFF
  15. IEF_VBLANK = 1 << 0
  16. prgm = Program(
  17. insns=[
  18. LD_R_N8(R8.A, 12),
  19. LD_RR_NN(R16.HL, rLCDC),
  20. RES_N_HL(7),
  21. RES_N_HL(2),
  22. LD_RR_NN(R16.HL, rIE),
  23. LD_HL_N(IEF_VBLANK),
  24. ],
  25. )
  26. optimized_prgm = optimize(prgm)
  27. optimized_prgm.display()
  28. for _ in range(10):
  29. prgm = mutate_program(
  30. prgm,
  31. prob_opcode=DEFAULT_PROB_OPCODE,
  32. prob_operand=DEFAULT_PROB_OPERAND,
  33. prob_swap=DEFAULT_PROB_SWAP,
  34. prob_insn=DEFAULT_PROB_INSN,
  35. prob_insn_unused=DEFAULT_PROB_INSN_UNUSED,
  36. )
  37. prgm.display()