From 39f6ddc3e27b80c17efe4f2d81ce99ed3a297b9a Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 24 Jun 2018 23:31:28 -0400 Subject: add gb_config_t, gb_disasm(), refactor logic, misc cleanups --- test.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 6 deletions(-) (limited to 'test.c') diff --git a/test.c b/test.c index f20301c..7a2ea70 100644 --- a/test.c +++ b/test.c @@ -11,7 +11,8 @@ #define NUM_FRAMES 600 // #define SKIP_STEPS 1000000 -#define NUM_STEPS 200000 +#define NUM_STEPS 300000 +#define UNUSED(a) ((void) (a)) static uint32_t file_size( @@ -62,6 +63,81 @@ load( // buffer for rendered frames static uint8_t frames[NUM_FRAMES * GB_FRAME_SIZE]; +static void +on_set_rom_bank( + const gb_t * const ctx, + const uint16_t bank +) { + printf("set rom bank: bank = %u, PC = %04x\n", bank, ctx->cpu.rs[5]); +} + +static void +on_set_ram_bank( + const gb_t * const ctx, + const uint16_t bank +) { + printf("set ram bank: bank = %u, PC = %04x\n", bank, ctx->cpu.rs[5]); +} + +static void +on_vblank( + const gb_t * const ctx +) { + printf("vblank: PC = %04x\n", ctx->cpu.rs[5]); +} + +static void +on_hblank( + const gb_t * const ctx +) { + printf("hblank: PC = %04x\n", ctx->cpu.rs[5]); +} + +static void +on_timer( + const gb_t * const ctx +) { + printf("timer: PC = %04x\n", ctx->cpu.rs[5]); +} + +/* + * static void + * on_gpu_step( + * const gb_t * const ctx + * ) { + * printf("gpu step: gpu clock = 0x%04x\n", ctx->gpu.clock); + * } + */ + +static void +on_gpu_set_mode( + const gb_t * const ctx, + const uint8_t mode +) { + UNUSED(ctx); + printf("gpu mode: %u, line = %u\n", mode, ctx->gpu.line); +} + +static void +on_set_cpu_state( + const gb_t * const ctx, + const gb_cpu_state_t state +) { + printf("cpu state: PC = %04x, state = %d\n", ctx->cpu.rs[5], state); +} + +static const gb_config_t +EXECUTE_CONFIG = { + .on_set_rom_bank = on_set_rom_bank, + .on_set_ram_bank = on_set_ram_bank, + .on_vblank = on_vblank, + .on_hblank = on_hblank, + .on_timer = on_timer, + // .on_gpu_step = on_gpu_step, + .on_gpu_set_mode = on_gpu_set_mode, + .on_set_cpu_state = on_set_cpu_state, +}; + static void test_render_frames( const char * const png_path, @@ -74,7 +150,7 @@ test_render_frames( // init context gb_t ctx; - gb_init(&ctx, rom_data, rom_size); + gb_init(&ctx, NULL, rom_data, rom_size); fprintf(stderr, "gb context initialized\n"); // render frames @@ -109,12 +185,19 @@ const char * const RWS[] = { static void gb_dump_context( - const gb_t * const ctx + gb_t * const ctx ) { for (int i = 0; RWS[i]; i++) { - printf("%s%s: 0x%04X", (!i) ? "" : ", ", RWS[i], ctx->cpu.rs[i]); + printf("%s:%04X ", RWS[i], ctx->cpu.rs[i]); + } + + char buf[128]; + size_t buf_len = sizeof(buf); + if (gb_disasm(ctx, buf, &buf_len)) { + printf("%s\n", buf); + } else { + printf("\n"); } - printf("\n"); } static void @@ -128,7 +211,7 @@ test_execute_steps( // init context gb_t ctx; - gb_init(&ctx, rom_data, rom_size); + gb_init(&ctx, &EXECUTE_CONFIG, rom_data, rom_size); fprintf(stderr, "gb context initialized\n"); #ifdef SKIP_STEPS -- cgit v1.2.3