diff --git a/c4emu.cpp b/c4emu.cpp index a7c009cb..65e0f553 100644 --- a/c4emu.cpp +++ b/c4emu.cpp @@ -1013,9 +1013,16 @@ void S9xSetC4 (uint8 byte, uint16 Address) printf("$7f4d=%02x, expected 02 for command 10 %02x\n", Memory.C4RAM[0x1f4d], Memory.C4RAM[0x1f4d]); #endif int32 tmp; - tmp = SAR((int32) READ_WORD(Memory.C4RAM + 0x1f83) * C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); + int32 r1; + r1 = READ_WORD(Memory.C4RAM + 0x1f83); + if (r1 & 0x8000) + r1 |= ~0x7fff; + else + r1 &= 0x7fff; + + tmp = SAR(r1 * C4CosTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); WRITE_3WORD(Memory.C4RAM + 0x1f86, tmp); - tmp = SAR((int32) READ_WORD(Memory.C4RAM + 0x1f83) * C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); + tmp = SAR(r1 * C4SinTable[READ_WORD(Memory.C4RAM + 0x1f80) & 0x1ff] * 2, 16); WRITE_3WORD(Memory.C4RAM + 0x1f89, (tmp - SAR(tmp, 6))); break; }