From 4062b919e3b1160ffe419c2964f73d55a1d0af44 Mon Sep 17 00:00:00 2001 From: "LGB (Gabor Lenart)" Date: Thu, 20 Jul 2023 12:55:06 +0200 Subject: [PATCH] MEGA65: hypervisor serial output file #352 --- targets/mega65/configdb.c | 3 ++- targets/mega65/configdb.h | 1 + targets/mega65/hypervisor.c | 36 ++++++++++++++++++++++++++++++++++++ targets/mega65/hypervisor.h | 2 ++ targets/mega65/mega65.c | 10 +++++----- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/targets/mega65/configdb.c b/targets/mega65/configdb.c index 5ce18db6..5f92852f 100644 --- a/targets/mega65/configdb.c +++ b/targets/mega65/configdb.c @@ -50,6 +50,7 @@ static const struct xemutools_configdef_str_st str_options[] = { { "extfreezer", NULL, "Use external initial memory content for the Freezer", &configdb.extfreezer }, { "hdosdir", NULL, "Set directory with HyppoDOS redirections", &configdb.hdosdir }, { "defaultdir", NULL, "Set initial default directory for most file selector UIs", &configdb.defaultdir }, + { "hyperserialfile", NULL, "Use a file to write serial output into (no ASCII conversion, not even with -hyperserialascii)", &configdb.hyperserialfile }, { "rom", NULL, "Override Hyppo's loaded ROM during booting.", &configdb.rom }, { "prg", NULL, "Load a PRG file directly into the memory (/w C64/65 auto-detection on load address)", &configdb.prg }, { "sdimg", SDCARD_NAME, "Override path of SD-image to be used (also see the -virtsd option!)", &configdb.sdimg }, @@ -142,7 +143,7 @@ static const struct xemutools_configdef_float_st float_options[] = { // etc), however if the user saves the config in Xemu when started this way, it would also save these // CLI-given options, which is not the thing he wants, 99.999999% of time, I guess ... -static const void *do_not_save_opts[] = { &configdb.prg, &configdb.autoload, &configdb.go64, NULL }; +static const void *do_not_save_opts[] = { &configdb.prg, &configdb.autoload, &configdb.go64, &configdb.hyperserialfile, NULL }; void configdb_define_emulator_options ( size_t size ) diff --git a/targets/mega65/configdb.h b/targets/mega65/configdb.h index 82493584..7932ad4c 100644 --- a/targets/mega65/configdb.h +++ b/targets/mega65/configdb.h @@ -81,6 +81,7 @@ struct configdb_st { int hyperdebug; int hyperdebugfreezer; int hyperserialascii; + char *hyperserialfile; int usestubrom; int useinitrom; int useutilmenu; diff --git a/targets/mega65/hypervisor.c b/targets/mega65/hypervisor.c index a21388bf..bde1d4a1 100644 --- a/targets/mega65/hypervisor.c +++ b/targets/mega65/hypervisor.c @@ -46,6 +46,8 @@ static int resolver_ok = 0; static char hypervisor_monout[0x10000]; static char *hypervisor_monout_p = hypervisor_monout; +static int hypervisor_serial_output_fd = -1; +static int hypervisor_serial_output_errors; static int hypervisor_serial_out_asciizer; @@ -368,8 +370,42 @@ void hypervisor_leave ( void ) } +void hypervisor_serial_monitor_open_file ( const char *fn ) +{ + if (!fn || !*fn) { + DEBUG("SERIAL: no need to open file (was not requested)" NL); + return; + } + hypervisor_serial_output_fd = xemu_open_file(fn, O_CREAT | O_TRUNC | O_WRONLY, NULL, NULL); + if (hypervisor_serial_output_fd < 0) { + ERROR_WINDOW("Could not open hypervisor serial output file %s", fn); + } else { + DEBUGPRINT("SERIAL: opened hypervisor serial output file: %s" NL, fn); + hypervisor_serial_output_errors = 0; + } +} + + +void hypervisor_serial_monitor_close_file ( const char *fn ) +{ + if (!fn || !*fn || hypervisor_serial_output_fd < 0) { + DEBUG("SERIAL: no need to close file (was not active)" NL); + return; + } + DEBUGPRINT("SERIAL: closing hypervisor serial output file %s" NL, fn); + close(hypervisor_serial_output_fd); + hypervisor_serial_output_fd = -1; + if (hypervisor_serial_output_errors) { + ERROR_WINDOW("SERIAL: deleting hypervisor serial output file %s, because write error(s) occured" NL, fn); + unlink(fn); + } +} + + void hypervisor_serial_monitor_push_char ( Uint8 chr ) { + if (hypervisor_serial_output_fd >= 0 && write(hypervisor_serial_output_fd, &chr, 1) != 1) + hypervisor_serial_output_errors++; if (hypervisor_monout_p >= hypervisor_monout - 1 + sizeof hypervisor_monout) return; int flush = (chr == 0x0A || chr == 0x0D || chr == 0x8A || chr == 0x8D); diff --git a/targets/mega65/hypervisor.h b/targets/mega65/hypervisor.h index c5921881..52721891 100644 --- a/targets/mega65/hypervisor.h +++ b/targets/mega65/hypervisor.h @@ -41,6 +41,8 @@ extern void hypervisor_start_machine ( void ); extern int hypervisor_level_reset ( void ); extern void hypervisor_leave ( void ); extern void hypervisor_serial_monitor_push_char ( Uint8 chr ); +extern void hypervisor_serial_monitor_open_file ( const char *fn ); +extern void hypervisor_serial_monitor_close_file ( const char *fn ); extern void hypervisor_debug_invalidate ( const char *reason ); extern void hypervisor_debug_late_enable ( void ); extern int hypervisor_hdos_virtualization_status ( const int set, const char **root_ptr ); // prototype is here, but it's implemented in hdos.c not in hypervisor.c diff --git a/targets/mega65/mega65.c b/targets/mega65/mega65.c index 365599b1..1587be3a 100644 --- a/targets/mega65/mega65.c +++ b/targets/mega65/mega65.c @@ -447,6 +447,7 @@ int dump_screen ( const char *fn ) static void shutdown_callback ( void ) { + hypervisor_serial_monitor_close_file(configdb.hyperserialfile); // Write out NVRAM if changed! if (memcmp(nvram, nvram_original, sizeof(nvram))) { DEBUGPRINT("NVRAM: changed, writing out on exit." NL); @@ -577,12 +578,10 @@ void m65mon_dumpmem28 ( int addr ) umon_printf("%02X", memory_debug_read_phys_addr(addr++)); } -void m65mon_setmem28( int addr, int cnt, Uint8* vals ) +void m65mon_setmem28 ( int addr, int cnt, Uint8* vals ) { - for (int k = 0; k < cnt; k++) - { - memory_debug_write_phys_addr(addr++, vals[k]); - } + while (--cnt >= 0) + memory_debug_write_phys_addr(addr++, *(vals++)); } void m65mon_set_trace ( int m ) @@ -853,6 +852,7 @@ int main ( int argc, char **argv ) xemu_set_full_screen(configdb.fullscreen_requested); if (!configdb.syscon) sysconsole_close(NULL); + hypervisor_serial_monitor_open_file(configdb.hyperserialfile); xemu_timekeeping_start(); emulation_is_running = 1; // FIXME: for emscripten (anyway it does not work too much currently) there should be 50 or 60 (PAL/NTSC) instead of (fixed, and wrong!) 25!!!!!!