summaryrefslogtreecommitdiff
path: root/sources/meta/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'sources/meta/exec.c')
-rw-r--r--sources/meta/exec.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/sources/meta/exec.c b/sources/meta/exec.c
index b913390..a39aef2 100644
--- a/sources/meta/exec.c
+++ b/sources/meta/exec.c
@@ -1,11 +1,33 @@
-/* FIXME: add a one time init and deinit to generate macro */
-#define BEGIN \
-do{ \
- chip8* c8 = usrdat; \
- assert(c8);
-
+#define BEGIN do{
#define END }while(0)
+#define X_C8_PRELUDE \
+ chip8* c8 = usrdat; \
+ assert(c8); \
+\
+ if(c8->pc >= sizeof(c8->mem)) \
+ { \
+ report(ERR, "CHIP-8: PC(%04X) Overflow!\n", c8->pc); \
+ c8->running = false; \
+ } \
+\
+ if(c8->pc & 0x0001) \
+ { \
+ report(ERR, "CHIP-8: PC(%04X) is not aligned!\n", c8->pc); \
+ c8->running = false; \
+ }
+
+#define X_C8_EPILOGUE \
+BEGIN \
+ c8->cycles++; \
+ if((c8->cycles % C8_CYCLES_PER_FRAME) == 0) \
+ { \
+ if(c8->dt) c8->dt--; \
+ if(c8->st) c8->st--; \
+ } \
+ c8->pc += 2; \
+END
+
#define X_C8_ILL \
BEGIN \
c8->running = false; \