Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active August 30, 2017 08:36
Show Gist options
  • Save pervognsen/76f2abd4485a7d2c40266f15cfc7f18b to your computer and use it in GitHub Desktop.
Save pervognsen/76f2abd4485a7d2c40266f15cfc7f18b to your computer and use it in GitHub Desktop.
#define INSTRUCTIONS \
_(0x7D, ADC, ABSOLUTE_X)
// ...
// Execution
#define _(byte, operation, mode) \
case byte: \
mode \
b = READ8(address); \
operation \
break;
#define ABSOLUTE_X \
{ \
address = READ16(pc + 1) + x; \
pc += 3; \
}
#define ADC \
{ \
int sum = (int)a + (int)b + (int)c; \
SET_CV(a, b, sum); \
a = (uint8_t)sum; \
SET_ZN(a); \
}
void execute() {
// ...
switch (instruction) {
INSTRUCTIONS
}
}
#undef ABSOLUTE_X
#undef ADC
#undef _
// Disassembly
#define _(byte, operation, mode) \
case byte: \
printf(#operation); \
mode \
printf("\n"); \
break;
#define ABSOLUTE_X \
printf(" ($%04x,x)", code[1] | (code[2] << 8)); \
code += 3;
void disassemble(uint8_t *code) {
switch (code[0]) {
INSTRUCTIONS
}
}
#undef ABSOLUTE_X
#undef ADC
#undef _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment