summaryrefslogtreecommitdiff
path: root/vdp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vdp.cpp')
-rw-r--r--vdp.cpp64
1 files changed, 64 insertions, 0 deletions
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;
+ }
+}