From 340c0f0c561e08e16b34d2a9d37615741c12cb21 Mon Sep 17 00:00:00 2001 From: ayabusa Date: Sat, 10 Jan 2026 19:01:54 +0100 Subject: [PATCH] basic stuff working --- Makefile | 2 +- src/main.c | 6 +++++- src/processor.c | 16 ++++++++++++++++ src/processor.h | 4 ++++ test.ch8 | Bin 0 -> 16 bytes 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test.ch8 diff --git a/Makefile b/Makefile index f3947a6..c393e7b 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ flags = -g -Wall -Wextra -fsanitize=address src = src/*.c inc = src/ out = build/chipy8 -rom = game.ch8 +rom = test.ch8 all: clean comp run diff --git a/src/main.c b/src/main.c index 36eff79..2620ad0 100644 --- a/src/main.c +++ b/src/main.c @@ -44,8 +44,12 @@ int main(int argc, char * argv[]){ } 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; diff --git a/src/processor.c b/src/processor.c index 3a76ab5..980c53e 100644 --- a/src/processor.c +++ b/src/processor.c @@ -159,6 +159,22 @@ void ins_LD_V_I(ch8_ctx * ctx, uint8_t x){ 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); diff --git a/src/processor.h b/src/processor.h index 9243eca..d214f58 100644 --- a/src/processor.h +++ b/src/processor.h @@ -25,4 +25,8 @@ uint8_t SP; uint16_t STACK[16]; } ch8_ctx; +void execute_instruction(ch8_ctx * ctx); + +void print_ctx(ch8_ctx * ctx); + #endif diff --git a/test.ch8 b/test.ch8 new file mode 100644 index 0000000000000000000000000000000000000000..e139d411130900c0812af45a0fe3326029a18941 GIT binary patch literal 16 XcmYdbNMxQMAjDI^D8!PiCBy>&8dd_e literal 0 HcmV?d00001 -- 2.43.0