From f125cc7018ed32b7f919ff71ea3c7d9d2e6565de Mon Sep 17 00:00:00 2001 From: Oxore Date: Fri, 30 Sep 2022 01:21:52 +0300 Subject: Begin implementing VDP --- vdp.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 vdp.cpp (limited to 'vdp.cpp') diff --git a/vdp.cpp b/vdp.cpp new file mode 100644 index 0000000..632429d --- /dev/null +++ b/vdp.cpp @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: Unlicense + */ + +#include "vdp.hpp" + +uint32_t VDP::Read(const uint32_t offset, const enum bitness bitness) +{ + const uint32_t res{}; + if (DEBUG_TRACE_VDP_ACCESS) { + printf( + "VDP r%d%s @0x%08x 0x%0*x\n", + bitness * 8, + (bitness <= 1 ? " " : ""), + base_address + offset, + bitness * 2, + res); + } + if (bitness == BITNESS_32) { + // TODO + } else if (bitness == BITNESS_16) { + // TODO + } + // Ignore 8-bit reads for now + return 0; +} + +void VDP::Write(const uint32_t offset, const enum bitness bitness, const uint32_t value) +{ + if (DEBUG_TRACE_VDP_ACCESS) { + printf( + "VDP w%d%s @0x%08x 0x%0*x", + bitness * 8, + (bitness <= 1 ? " " : ""), + base_address + offset, + bitness * 2, + value); + } + if (bitness == BITNESS_32) { + if (offset == 4 || offset == 6) { + writeControl((value >> 16) & 0xffff); + writeControl(value & 0xffff); + } + } else if (bitness == BITNESS_16) { + if (offset == 4 || offset == 6) { + writeControl(value & 0xffff); + } + } + if (DEBUG_TRACE_VDP_ACCESS) { + printf("\n"); + } + // Ignore 8-bit writes for now +} + +void VDP::writeControl(const uint16_t value) +{ + if (((value >> 13) & 0x7) == 4) { + const uint8_t reg_num = (value >> 8) & 0x1f; + const uint8_t reg_val = value & 0xff; + if (DEBUG_TRACE_VDP_ACCESS) { + printf(": reg 0x%02x w 0x%02x", reg_num, reg_val); + } + _reg[reg_num] = reg_val; + } +} -- cgit v1.2.3