Closed jaggies closed 4 years ago
Nice catch. That is in fact what is happening. D_REG and IMMADDRESS are unsigned.
From hd6309.c:
case MULD_M: //118F Phase 5 6309
p6309->Q_REG= p6309->D_REG * IMMADDRESS(p6309,p6309->PC_REG);
p6309->cc[C] = 0;
p6309->cc[Z] = ZTEST(p6309->D_REG);
p6309->cc[V] = 0;
p6309->cc[N] = NTEST16(p6309->D_REG);
p6309->PC_REG+=2;
p6309->cpu.CycleCounter+=28;
Similar story of course in MULD_D, MULD_X, MULD_E.
I think if you investigate, you'll find a lot of the 6309 instructions are not complete. I don't think Joseph ever finished them in the original sources.
These (and more) 6309 bugs have been resolved in the latest release. If you find any more 6309 related bugs, please report them here. Thanks :-)
According to the documentation, the HD6309 'muld' instruction is supposed to operate on signed integers. For example:
Yields 0x0000ffff on the emulator and 0xffffffff on real hardware.
It looks to me like the code is doing an unsigned multiply, which explains this result.