BGPierce / VCC

Tandy Color Computer 3 Emulator
GNU General Public License v3.0
0 stars 0 forks source link

HD6309 'muld' instruction is incorrect #29

Closed jaggies closed 4 years ago

jaggies commented 5 years ago

According to the documentation, the HD6309 'muld' instruction is supposed to operate on signed integers. For example:

ldd #-1
muld BGPierce/VCC#1

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.

abathur8bit commented 5 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;
abathur8bit commented 5 years ago

Similar story of course in MULD_D, MULD_X, MULD_E.

BGPierce commented 5 years ago

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.

BGPierce commented 4 years ago

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 :-)