1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2026-03-11 03:16:11 +00:00
Files
rk65c02/examples/stepper.c
Radosław Kujawa a73ebc3024 examples: add interrupts, hello_serial, stepper, jit_bench, breakpoints
- interrupts: IRQ vector at $FFFE, vector device at $FFFC, idle_wait + assert_irq
- hello_serial: custom bus device at $DE00, guest writes host prints
- stepper: rk65c02_step(1) loop with regs and disassembly
- jit_bench: min3.rom interpreter vs JIT wall time
- breakpoints: debug_breakpoint_add at min3 entry, inspect then continue
- README: document new examples, run from examples/ or make run-<name>
- Makefile: EXAMPLES and run-* targets for all five

Made-with: Cursor
2026-03-07 15:16:18 +01:00

51 lines
1.3 KiB
C

/*
* Stepper example — step-by-step execution and state inspection.
*
* Build: make stepper stepper.rom
* Run: ./stepper
*
* Demonstrates: rk65c02_step(e, 1) in a loop, reading regs and disassembling
* the current instruction after each step. Stops when not STEPPED or after
* a bounded number of steps.
* Expected: trace of PC and disassembly for each step, then STP; PASS.
*/
#include <stdint.h>
#include <stdio.h>
#include "bus.h"
#include "instruction.h"
#include "rk65c02.h"
static const uint16_t load_addr = 0xC000;
#define MAX_STEPS 25
int
main(void)
{
rk65c02emu_t e;
uint16_t steps;
e = rk65c02_load_rom("stepper.rom", load_addr, NULL);
e.regs.SP = 0xFF;
e.regs.PC = load_addr;
printf("Stepping (max %d steps):\n", MAX_STEPS);
for (steps = 0; steps < MAX_STEPS; steps++) {
rk65c02_step(&e, 1);
printf(" step %u PC=$%04X A=$%02X X=$%02X Y=$%02X SP=$%02X ",
(unsigned)steps + 1, e.regs.PC, e.regs.A, e.regs.X, e.regs.Y, e.regs.SP);
disassemble(e.bus, e.regs.PC);
if (e.stopreason != STEPPED)
break;
}
printf("Stop reason: %s\n", rk65c02_stop_reason_string(e.stopreason));
if (e.stopreason != STP) {
fprintf(stderr, "FAIL: expected STP, got %s\n",
rk65c02_stop_reason_string(e.stopreason));
return 1;
}
printf("PASS: stepped to STP.\n");
return 0;
}