Skip to content

Instantly share code, notes, and snippets.

@DaKnig
Last active September 8, 2024 21:45
Show Gist options
  • Save DaKnig/b400de5f6361a2b9ed3f496fec968bcd to your computer and use it in GitHub Desktop.
Save DaKnig/b400de5f6361a2b9ed3f496fec968bcd to your computer and use it in GitHub Desktop.
How to easily synthesize `inc a` for gameboy

Just write the following, compile with the right flags under clang, then call alive-tv synth.ll and see the result. It should say something like :

ERROR: Value mismatch

Example:
i8 noundef zeroext %#0 = #x3c (60)

0x3c is inc a

#include "cpu.c"
#define inline __attribute__((always_inline))
 
inline uint8_t gb(uint8_t a, uint8_t inst0) {
  struct SM83 cpu;
 
  cpu.mem[cpu.regs.pc] = inst0;
  cpu.regs.a = a;
  run_single_command(&cpu);
  return cpu.regs.a;
}
 
uint8_t target(uint8_t a) {
  return a+1;
}
 
// query for alive2
bool tgt(uint8_t inst0) {
  return target(43) != gb(43, inst0);
}
 
bool src(uint8_t) { return true; }

note that run_single_command and SM83 are from an emulator you can find here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment