From 6700e183e60e6ae72c94de33ea35eba22bbd3614 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Sat, 3 Dec 2022 13:57:16 +0200 Subject: [PATCH] [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 --- bus.c | 4 ++-- cpu.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bus.c b/bus.c index ac3a970..60aedb2 100644 --- a/bus.c +++ b/bus.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 } diff --git a/cpu.c b/cpu.c index 777624c..b33ec53 100644 --- a/cpu.c +++ b/cpu.c @@ -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; }