Last active
August 30, 2017 08:36
-
-
Save pervognsen/76f2abd4485a7d2c40266f15cfc7f18b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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