}
int running = 1;
srand( time( NULL ) );
+ char placeholder;
while (running){
- ;
+ execute_instruction(&context);
+ print_ctx(&context);
+ printf("Press enter to resume");
+ scanf("%c", &placeholder);
}
free(context.RAM);
return 0;
ctx->REGS[i] = ctx->RAM[ctx->I + i];
}
+void print_ctx(ch8_ctx * ctx){
+ printf("PC: %hu \nSP: %hhu \nDT: %hhu \nST: %hhu \nRegisters:\nI: %hu\n", ctx->PC, ctx->SP, ctx->DT, ctx->ST, ctx->I);
+ for(uint8_t x=0; x<=0xF; x++){
+ printf("V%hhu: %hhu\n", x, ctx->REGS[x]);
+ }
+ printf("Stack:\n");
+ int started = 0;
+ for(int s=15; s>=0; s--){
+ if(!started && ctx->STACK[s]==0);
+ else{
+ started=1;
+ printf("0x%x: 0x%hx\n", s, ctx->STACK[s]);
+ }
+ }
+}
+
void execute_instruction(ch8_ctx * ctx){
// The two instruction bytes
uint8_t b1=*(ctx->RAM + ctx->PC), b2=*(ctx->RAM + ctx->PC + 1);