Fix bug with 'set' command, allow setting registers in GUI
diff --git a/dbg.c b/dbg.c
index 2de4eb6..e2ee986 100644
--- a/dbg.c
+++ b/dbg.c
@@ -65,18 +65,21 @@
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)
{
diff --git a/gui.c b/gui.c
index ed34655..0837f69 100644
--- a/gui.c
+++ b/gui.c
@@ -35,6 +35,12 @@
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 @@
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);