Skip to content

Instantly share code, notes, and snippets.

@Frank-Buss
Created November 25, 2019 23:33
Show Gist options
  • Save Frank-Buss/1cbe0d17d9507cc0329c5b6958ac08d8 to your computer and use it in GitHub Desktop.
Save Frank-Buss/1cbe0d17d9507cc0329c5b6958ac08d8 to your computer and use it in GitHub Desktop.
cycle counter hack for X16 emulator
diff --git a/cpu/instructions.h b/cpu/instructions.h
index 09757cc..38dd1f1 100644
--- a/cpu/instructions.h
+++ b/cpu/instructions.h
@@ -505,3 +505,14 @@ static void tya() {
zerocalc(a);
signcalc(a);
}
+
+#include <inttypes.h>
+static uint32_t cycles;
+
+static void in2() {
+ cycles = clockticks6502;
+}
+
+static void in3() {
+ printf("cycles: %"PRIu32"\n", clockticks6502 - cycles);
+}
diff --git a/cpu/tables.h b/cpu/tables.h
index 482d94e..4703525 100644
--- a/cpu/tables.h
+++ b/cpu/tables.h
@@ -22,7 +22,7 @@ static void (*addrtable[256])() = {
static void (*optable[256])() = {
/* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | */
-/* 0 */ brk, ora, nop, nop, tsb, ora, asl, nop, php, ora, asl, nop, tsb, ora, asl, nop, /* 0 */
+/* 0 */ brk, ora, in2, in3, tsb, ora, asl, nop, php, ora, asl, nop, tsb, ora, asl, nop, /* 0 */
/* 1 */ bpl, ora, ora, nop, trb, ora, asl, nop, clc, ora, inc, nop, trb, ora, asl, nop, /* 1 */
/* 2 */ jsr, and, nop, nop, bit, and, rol, nop, plp, and, rol, nop, bit, and, rol, nop, /* 2 */
/* 3 */ bmi, and, and, nop, bit, and, rol, nop, sec, and, dec, nop, bit, and, rol, nop, /* 3 */
@@ -42,7 +42,7 @@ static void (*optable[256])() = {
static const uint32_t ticktable[256] = {
/* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | */
-/* 0 */ 7, 6, 2, 2, 5, 3, 5, 2, 3, 2, 2, 2, 6, 4, 6, 2, /* 0 */
+/* 0 */ 7, 6, 0, 0, 5, 3, 5, 2, 3, 2, 2, 2, 6, 4, 6, 2, /* 0 */
/* 1 */ 2, 5, 5, 2, 5, 4, 6, 2, 2, 4, 2, 2, 6, 4, 7, 2, /* 1 */
/* 2 */ 6, 6, 2, 2, 3, 3, 5, 2, 4, 2, 2, 2, 4, 4, 6, 2, /* 2 */
/* 3 */ 2, 5, 5, 2, 4, 4, 6, 2, 2, 4, 2, 2, 4, 4, 7, 2, /* 3 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment