This PR is the first of two PRs that replaces earlier PRs #2589 and #2590. Due to a git branching mishap it was decided to re-partition the new functionality in two sequential PRs that offer self-contained, new functionality to sim65. The functionality in this first PR extends the sim65 simulator in the following ways: (1) It provides tracing functionality, i.e., the possibility of printing one line of simulator state information per instruction executed. (2) It provides a memory mapped "sim65 control" peripheral that allows control of (a) the tracing functionality, and (b) the cpu mode. (3) It provides command-line options to sim65 to enable the tracing, and to override the CPU mode as specified in the program file header. More detailed information and some discussion can be found in the discussions with the (now retracted) PRs #2589 and #2590. This PR provides the technical infrastructure inside the sim65 simulator program itself. Once this PR is accepted, a follow-up PR will be posted that adds C and assembly-language support for the new tracing and peripheral features so they can be easily accessed from the CC65 compiler and the CA65 assembler; some examples; and the documentation for these features. The lack of the latter, in this pull request, will be addressed then.
90 lines
3.8 KiB
C
90 lines
3.8 KiB
C
/*****************************************************************************/
|
|
/* */
|
|
/* trace.h */
|
|
/* */
|
|
/* Instruction tracing functionality sim65 6502 simulator */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* (C) 2025, Sidney Cadot */
|
|
/* */
|
|
/* */
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
/* arising from the use of this software. */
|
|
/* */
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
/* freely, subject to the following restrictions: */
|
|
/* */
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
/* claim that you wrote the original software. If you use this software */
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
/* appreciated but is not required. */
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
/* be misrepresented as being the original software. */
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
/* distribution. */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
|
|
#ifndef TRACE_H
|
|
#define TRACE_H
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
#include "6502.h"
|
|
|
|
/* The trace mode is a bitfield that determines how trace lines are displayed.
|
|
*
|
|
* The value zero indicates that tracing is disabled (the default).
|
|
*
|
|
* In case TraceMode is not equal to zero, the value is interpreted as a bitfield:
|
|
*
|
|
* Bit Bit value Enables
|
|
* --- ----------- -------------------------------
|
|
* 6 0x40 ( 64) Print the instruction counter.
|
|
* 5 0x20 ( 32) Print the clock cycle counter.
|
|
* 4 0x10 ( 16) Print the PC (program counter).
|
|
* 3 0x08 ( 8) Print the instruction bytes.
|
|
* 2 0x04 ( 4) Print the instruction assembly.
|
|
* 1 0x02 ( 2) Print the CPU registers.
|
|
* 0 0x01 ( 1) Print the CC65 stack pointer.
|
|
*
|
|
*/
|
|
|
|
#define TRACE_FIELD_INSTR_COUNTER 0x40
|
|
#define TRACE_FIELD_CLOCK_COUNTER 0x20
|
|
#define TRACE_FIELD_PC 0x10
|
|
#define TRACE_FIELD_INSTR_BYTES 0x08
|
|
#define TRACE_FIELD_INSTR_ASSEMBLY 0x04
|
|
#define TRACE_FIELD_CPU_REGISTERS 0x02
|
|
#define TRACE_FIELD_CC65_SP 0x01
|
|
|
|
#define TRACE_DISABLED 0x00
|
|
#define TRACE_ENABLE_FULL 0x7f
|
|
|
|
/* Currently active tracing mode. */
|
|
extern uint8_t TraceMode;
|
|
|
|
void TraceInit (uint8_t SPAddr);
|
|
/* Initialize the trace subsystem. */
|
|
|
|
void PrintTraceNMI(void);
|
|
/* Print trace line for an NMI interrupt. */
|
|
|
|
void PrintTraceIRQ(void);
|
|
/* Print trace line for an IRQ interrupt. */
|
|
|
|
void PrintTraceInstruction (void);
|
|
/* Print trace line for the instruction at the currrent program counter. */
|
|
|
|
|
|
|
|
/* End of trace.h */
|
|
|
|
#endif
|