summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2025-03-26 17:31:51 +0200
committerdweller <dweller@cabin.digital>2025-03-26 17:31:51 +0200
commit76d89eb9973671726dc7fffaf22b06a7a77be550 (patch)
treec0c3c6fb20d905b8f9b3bde2c1546d481b66e280 /main.c
parent5bf658d3a940e536e232d8fcd6e2ae431e5afdd7 (diff)
build ''system''; decode metaprog; disasm
Diffstat (limited to '')
-rw-r--r--sources/main.c (renamed from main.c)23
1 files changed, 15 insertions, 8 deletions
diff --git a/main.c b/sources/main.c
index c082914..56630df 100644
--- a/main.c
+++ b/sources/main.c
@@ -281,13 +281,11 @@ void _c8_loop(chip8* c8, bool disasm, u16 from, u16 len)
if(disasm) c8->pc = pc;
}
-void c8_disam(chip8* c8, u16 from, u16 len) { _c8_loop(c8, true, from, len); }
-void c8_loop(chip8* c8) { _c8_loop(c8, false, 0, 0); }
-
int main(int argc, char** argv)
{
- FILE* f = NULL;
+ u64 sz = 0;
+ FILE* f = NULL;
chip8 c8 = {0};
srand(time(NULL));
@@ -296,7 +294,7 @@ int main(int argc, char** argv)
if(argc > 1)
{
- u64 sz, got = 0;
+ u64 got = 0;
f = fopen(argv[1], "r");
if(!f) return 1;
@@ -331,13 +329,22 @@ int main(int argc, char** argv)
c8.RAM[C8_RESET_VECTOR + iota] = 0x12;
c8.RAM[C8_RESET_VECTOR + iota] = 0x04;
+
+ sz = iota;
}
printf("Disasm:\n");
- c8_disam(&c8, C8_RESET_VECTOR, 32);
+ {
+ u64 i;
+ char buf[512] = {0};
- printf("\nExec:\n");
- c8_loop(&c8);
+ for(i = 0; i < sz; i += 2)
+ {
+ u16 pc = C8_RESET_VECTOR + i;
+ c8_disasm(c8.RAM, pc, buf);
+ printf("%04X: %s\n", pc, buf);
+ }
+ }
return 0;
}