]> git.ayabusa.dev Git - chipy-8.git/commitdiff
basic stuff working
authorayabusa <lebgpub@gmail.com>
Sat, 10 Jan 2026 18:01:54 +0000 (19:01 +0100)
committerayabusa <lebgpub@gmail.com>
Sat, 10 Jan 2026 18:01:54 +0000 (19:01 +0100)
Makefile
src/main.c
src/processor.c
src/processor.h
test.ch8 [new file with mode: 0644]

index f3947a6790108dfd028406cde650ff81480df734..c393e7b21888ad1a438bc0216b0078fbcb5a8788 100644 (file)
--- 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
 
index 36eff794253be41c8a53bf42433bc49c2cea8744..2620ad0de1e4a7911c44327111fa0138f0adeda4 100644 (file)
@@ -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;
index 3a76ab5941179e1f56940123c39a52839ac02f30..980c53eecd56825614abc63876b2111955a2ba80 100644 (file)
@@ -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);
index 9243eca2ca677624f8f5259db10b0d7bdfd13c43..d214f58d5d5d89b3dfdef25d503bbdb794535a3a 100644 (file)
@@ -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 (file)
index 0000000..e139d41
Binary files /dev/null and b/test.ch8 differ