~swisschili/toolchain-6502

90db50ae7df0fa46ecf34fa4f4601a69eb746635 — swissChili 3 months ago 4bccd44
Fix bug with 'set' command, allow setting registers in GUI
2 files changed, 26 insertions(+), 6 deletions(-)

M dbg.c
M gui.c
M dbg.c => dbg.c +9 -6
@@ 65,18 65,21 @@ bool debug_stmt(cpu_t *cpu, char *input, bool *running)
		else if (sscanf(tok, "%s #$%hhx", reg_name, &val))
		{
			int reg = -1;
			if (!strcasecmp(tok, "A"))
			if (!strcasecmp(reg_name, "A"))
				reg = A;
			else if (!strcasecmp(tok, "X"))
			else if (!strcasecmp(reg_name, "X"))
				reg = X;
			else if (!strcasecmp(tok, "Y"))
			else if (!strcasecmp(reg_name, "Y"))
				reg = Y;
			else if (!strcasecmp(tok, "SP"))
			else if (!strcasecmp(reg_name, "SP"))
				reg = SP;
			else if (!strcasecmp(tok, "PC"))
			else if (!strcasecmp(reg_name, "PC"))
				cpu->pc = val;
			else if (!strcasecmp(tok, "SR"))
			else if (!strcasecmp(reg_name, "SR"))
				*(uint8_t *)&cpu->status = val;
			else
				printf("set command expected a register as the first argument, got %s\n",
					reg_name);

			if (reg != -1)
			{

M gui.c => gui.c +17 -0
@@ 35,6 35,12 @@ static void cmd(mqd_t mq, char *msg)
	mq_send(mq, msg, strlen(msg) + 1, 2);
}

#define cmdf(mq, buffer, pattern, args...) \
	{ \
		sprintf(buffer, pattern, ##args); \
		cmd(mq, buffer); \
	}

void gui(gui_arg_t *arg)
{
	cpu_t *cpu = arg->cpu;


@@ 118,6 124,17 @@ void gui(gui_arg_t *arg)
			uint8_t rega = nk_propertyi(ctx, "A", 0, cpu->regs[A], 0xFF, 1, 20.0f),
				regx = nk_propertyi(ctx, "X", 0, cpu->regs[X], 0xFF, 1, 20.0f),
				regy = nk_propertyi(ctx, "Y", 0, cpu->regs[Y], 0xFF, 1, 20.0f);

			char buffer[64];

			if (pc != cpu->pc)
				cmdf(mq, buffer, "set PC #$%x", pc);
			if (rega != cpu->regs[A])
				cmdf(mq, buffer, "set A #$%x", rega);
			if (regx != cpu->regs[X])
				cmdf(mq, buffer, "set X #$%x", regx);
			if (regy != cpu->regs[Y])
				cmdf(mq, buffer, "set Y #$%x", regy);
		}
		nk_end(ctx);