1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-10 14:29:30 +00:00

Relative address was not being calculated correctly.

The disassembler is using the correct approach, so I adapted it to the
execution code.
This commit is contained in:
Peter Evans 2018-01-09 15:57:37 -06:00
parent a267065059
commit d7148b88bf

View File

@ -202,20 +202,20 @@ DEFINE_ADDR(idy)
*/
DEFINE_ADDR(rel)
{
vm_16bit orig_pc;
vm_16bit reladdr;
orig_pc = cpu->PC;
ADDR_LO(cpu);
reladdr = cpu->PC + addr;
if (addr > 127) {
// e.g. if lo == 128, then cpu->PC + 127 - lo is the
// same as subtracting 1 from PC.
EFF_ADDR(orig_pc + 127 - addr);
return 0;
// If the address has the 8th bit high, then we treat the
// relative number as signed; we then subtract 256 from whatever
// the addition was with the operand (addr, in this case).
reladdr -= 256;
}
// Otherwise lo is a positive offset from PC
EFF_ADDR(orig_pc + addr);
// But if not, then we can let the addition done above stand.
EFF_ADDR(reladdr);
return 0;
}