Skip to content

Commit

Permalink
MEGA65: hypervisor serial output file #352
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Jul 20, 2023
1 parent 5e9cf69 commit 4062b91
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
3 changes: 2 additions & 1 deletion targets/mega65/configdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions targets/mega65/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct configdb_st {
int hyperdebug;
int hyperdebugfreezer;
int hyperserialascii;
char *hyperserialfile;
int usestubrom;
int useinitrom;
int useutilmenu;
Expand Down
36 changes: 36 additions & 0 deletions targets/mega65/hypervisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions targets/mega65/hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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!!!!!!
Expand Down

0 comments on commit 4062b91

Please sign in to comment.