Add -D option to specifiy file to receive trace output.
Add -D option to specifiy file to receive trace output, though the default is still stderr. While redirection of stderr could be used without this change, the intent here is to allow stderr to be used for only error conditions. It is possible that some such output should go to both stderr and the trace file, though this commit does not do that.
Makes a lot of sense. Will have a think about how best to handle this.
I didn't expect that you'd necessarily want to accept this PR as-is.
On some projects, I've used something like this:
typdef uint32_t trace_source_t;
#define TRACE_MEM 0x000001
#define TRACE_IO 0x000002
#define TRACE_ROM 0x000004
...
static trace_source_t trace_mask = 0;
static FILE *trace_file = 0; /* stderr may not be statically defined, so
initialize to stderr in main() */
static int trace_vprintf(trace_source_t source, const char *format, va_list arg)
{
if (! source & trace_mask)
return 0;
vfprintf(trace_file, format, arg);
}
static int trace_printf(trace_source_t source, const char *format, ...)
{
va_list ap;
va_start(ap, format);
trace_vprintf(source, fmt, ap);
va_end(ap);
}
...
static uint8_t mem_read0(uint16_t addr)
{
if (bankenable) {
unsigned int bank = (addr & 0xC000) >> 14;
trace_printf(TRACE_MEM, "R %04x[%02X] = %02X\n", addr, (unsigned int) bankreg[bank], (unsigned int) ramrom[(bankreg[bank] << 14) + (addr & 0x3FFF)]);
That has the drawback of requiring a function call even if the trace is masked, which is OK for some things but probably not anything in the core of a simulator. A macro could be used instead, though I'm not a huge fan of macros.
I don't think you really need this. I use
./emulator -flags 2> /tmp/stderr
I use a Mac but it looks like the almost identical syntax works on Windows as well.