# HG changeset patch # User Mike Pavone # Date 1603147576 25200 # Node ID 4ace0fef6f8f44fcd2d8f54e7520c4875a9d9f19 # Parent a8e3e816a50dfd8797d1c13d29a4428f2a4e6174 Add support for the parts of the KMod debug ports used by SGDK diff -r a8e3e816a50d -r 4ace0fef6f8f vdp.c --- a/vdp.c Fri Oct 16 22:13:07 2020 -0700 +++ b/vdp.c Mon Oct 19 15:46:16 2020 -0700 @@ -10,6 +10,7 @@ #include "render.h" #include "util.h" #include "event_log.h" +#include "terminal.h" #define NTSC_INACTIVE_START 224 #define PAL_INACTIVE_START 240 @@ -3782,6 +3783,33 @@ if (reg == REG_MODE_1 || reg == REG_MODE_2 || reg == REG_MODE_4) { update_video_params(context); } + } else if (reg == REG_KMOD_CTRL) { + if (!(value & 0xFF)) { + context->system->enter_debugger = 1; + } + } else if (reg == REG_KMOD_MSG) { + char c = value; + if (c) { + context->kmod_buffer_length++; + if ((context->kmod_buffer_length + 1) > context->kmod_buffer_storage) { + context->kmod_buffer_storage = context->kmod_buffer_length ? 128 : context->kmod_buffer_length * 2; + context->kmod_msg_buffer = realloc(context->kmod_msg_buffer, context->kmod_buffer_storage); + } + context->kmod_msg_buffer[context->kmod_buffer_length - 1] = c; + } else if (context->kmod_buffer_length) { + context->kmod_msg_buffer[context->kmod_buffer_length] = 0; + init_terminal(); + printf("KDEBUG MESSAGE: %s\n", context->kmod_msg_buffer); + context->kmod_buffer_length = 0; + } + } else if (reg == REG_KMOD_TIMER) { + if (!(value & 0x80)) { + init_terminal(); + printf("KDEBUG TIMER: %d\n", (context->cycles - context->timer_start_cycle) / 7); + } + if (value & 0xC0) { + context->timer_start_cycle = context->cycles; + } } } else if (mode_5) { context->flags |= FLAG_PENDING; diff -r a8e3e816a50d -r 4ace0fef6f8f vdp.h --- a/vdp.h Fri Oct 16 22:13:07 2020 -0700 +++ b/vdp.h Mon Oct 19 15:46:16 2020 -0700 @@ -91,7 +91,10 @@ REG_DMALEN_H, REG_DMASRC_L, REG_DMASRC_M, - REG_DMASRC_H + REG_DMASRC_H, + REG_KMOD_CTRL=29, + REG_KMOD_MSG, + REG_KMOD_TIMER }; //Mode reg 1 @@ -168,6 +171,10 @@ uint32_t *fb; uint8_t *done_composite; uint32_t *debug_fbs[VDP_NUM_DEBUG_TYPES]; + char *kmod_msg_buffer; + uint32_t kmod_buffer_storage; + uint32_t kmod_buffer_length; + uint32_t timer_start_cycle; uint32_t output_pitch; uint32_t debug_fb_pitch[VDP_NUM_DEBUG_TYPES]; fifo_entry fifo[FIFO_SIZE];