From cb7f668b0acbb79fe4360186b87206f582ca5c23 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 2 Oct 2022 13:04:14 +0300 Subject: Fix two-byte read and write in VDP --- vdp.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/vdp.cpp b/vdp.cpp index d870fce..0ac6e1b 100644 --- a/vdp.cpp +++ b/vdp.cpp @@ -17,7 +17,7 @@ uint32_t VDP::Read(const uint32_t offset, const enum bitness bitness) } if (bitness == BITNESS_32) { if (offset == 0) { - const auto ret = readData(_address_mode, _address & 0xfffe); + const uint16_t ret = readData(_address_mode, _address & 0xfffe); _address += _reg[static_cast(RegID::kAutoIncrement)]; return ret; } else if (offset == 4) { @@ -25,7 +25,7 @@ uint32_t VDP::Read(const uint32_t offset, const enum bitness bitness) } } else if (bitness == BITNESS_16) { if (offset == 0 || offset == 2) { - const auto ret = readData(_address_mode, _address & 0xfffe); + const uint16_t ret = readData(_address_mode, _address & 0xfffe); _address += _reg[static_cast(RegID::kAutoIncrement)]; return ret; } else if (offset == 4 || offset == 6) { @@ -101,7 +101,8 @@ void VDP::writeData(const uint8_t address_mode, const uint16_t address, const ui if (DEBUG_TRACE_VDP_ACCESS) { printf(": VRAM @0x%04x 0x%04x", address, value); } - _vram[address] = value; + _vram[address] = (value >> 8) & 0xff;; + _vram[address + 1] = value & 0xff;; return; case AddressMode::kCRAMWrite: if (address >= kCRAMSize) { @@ -113,7 +114,8 @@ void VDP::writeData(const uint8_t address_mode, const uint16_t address, const ui if (DEBUG_TRACE_VDP_ACCESS) { printf(": CRAM @0x%04x 0x%04x", address, value); } - _cram[address] = value; + _cram[address] = (value >> 8) & 0xff;; + _cram[address + 1] = value & 0xff;; return; case AddressMode::kVSRAMWrite: if (address >= kVSRAMSize) { @@ -125,7 +127,8 @@ void VDP::writeData(const uint8_t address_mode, const uint16_t address, const ui if (DEBUG_TRACE_VDP_ACCESS) { printf(": VSRAM @0x%04x 0x%04x", address, value); } - _vsram[address] = value; + _vsram[address] = (value >> 8) & 0xff;; + _vsram[address + 1] = value & 0xff;; return; case AddressMode::kVRAMRead: case AddressMode::kCRAMRead: @@ -194,7 +197,7 @@ uint16_t VDP::readData(const uint8_t address_mode, const uint16_t address) } return 0; } else { - const auto value = _vram[address]; + const uint16_t value = (_vram[address] << 8) | _vram[address + 1]; if (DEBUG_TRACE_VDP_ACCESS) { printf(": VRAM @0x%04x 0x%04x", address, value); } @@ -207,7 +210,7 @@ uint16_t VDP::readData(const uint8_t address_mode, const uint16_t address) } return 0; } else { - const auto value = _cram[address]; + const uint16_t value = (_cram[address] << 8) | _cram[address + 1]; if (DEBUG_TRACE_VDP_ACCESS) { printf(": CRAM @0x%04x 0x%04x", address, value); } @@ -220,7 +223,7 @@ uint16_t VDP::readData(const uint8_t address_mode, const uint16_t address) } return 0; } else { - const auto value = _vsram[address]; + const uint16_t value = (_vsram[address] << 8) | _vsram[address + 1]; if (DEBUG_TRACE_VDP_ACCESS) { printf(": VSRAM @0x%04x 0x%04x", address, value); } -- cgit v1.2.3