[bus.c] Fix bus_read16

bus_read16 used to read the lsb as the msb and the msb as the lsb,
    fixed this by changing the read offsets for the addresses.

    This was only primarly used in the IND addressing mode only used by
    opcode 6C (JMP IND), which messed up on call, this fixes the issue,
    but we still have later JMP problems that look not related to the
    code, expect a further commit fixing JMP or any opcode causing the
    branch from the expected output.
 On branch main
main
Joaquin 3 years ago
parent 2cba251413
commit 6700e183e6
Signed by: puly
GPG Key ID: 9E9299CD96C65EC6
  1. 4
      bus.c
  2. 5
      cpu.c

@ -57,9 +57,9 @@ word bus_read8(word address){
}
word bus_read16(word address){
word d = bus_read8(address); //read msb
word d = bus_read8(address+1); //read msb
d <<= 8; //put msb in the msb section
d |= bus_read8(address+1); //read lsb
d |= bus_read8(address); //read lsb
return d; //return whole word
}

@ -97,6 +97,11 @@ busTransaction IND(CPU * __restrict__ cpu, word bytes){
busTransaction x;
x.address = bus_read16(bytes);
x.value = bus_read8(x.address);
#ifdef DEBUG
printf("\nIND: X>ADDRESS %04X | X>VALUE %04X | BYTES %04X | BUS_READ8(BYTES) %04X | BUS_READ16{BYTES} %04X | BUS_READ8(BYTES+1) %04X | BUS_READ8(BYTES-1) %04X | DEBUGREAD_BYTES+1 %04X\n", x.address, x.value, bytes, bus_read8(bytes), bus_read16(bytes), bus_read8(bytes + 1), bus_read8(bytes - 1), debug_read_do_not_use_pls(bytes+1));
#endif
return x;
}

Loading…
Cancel
Save