summaryrefslogtreecommitdiff
path: root/bus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bus.cpp')
-rw-r--r--bus.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/bus.cpp b/bus.cpp
index 835bb56..eb2c83b 100644
--- a/bus.cpp
+++ b/bus.cpp
@@ -4,6 +4,7 @@
#include "bus.hpp"
#include "musashi-m68k/m68k.h"
#include "utils.hpp"
+#include "vdp.hpp"
#include <cassert>
#include <cstdarg>
@@ -12,6 +13,10 @@
#include <cstdint>
#include <cstdlib>
+#if !defined(DEBUG_TRACE_VDP_ACCESS)
+# define DEBUG_TRACE_VDP_ACCESS 0
+#endif
+
namespace Adr {
static constexpr uint32_t kZ80BusReq = 0x00a11100;
}
@@ -22,9 +27,10 @@ unsigned char g_rom[ROM_SIZE] = {};
unsigned char g_ram[RAM_SIZE] = {};
unsigned char g_sound_ram[SOUND_RAM_SIZE] = {};
unsigned char g_io1[IO1_SIZE] = {};
-unsigned char g_io2[VDP_SIZE] = {};
std::vector<Breakpoint> code_bkpts{}, read_bkpts{}, write_bkpts{}, access_bkpts{};
+static VDP g_vdp(VDP_START);
+
static void exit_error(const char* fmt, ...)
{
static bool in_error = false;
@@ -69,13 +75,7 @@ static inline bool is_in_range(uint32_t value, uint32_t begin, uint32_t length)
return value >= begin && value <= begin + length;
}
-enum bitness {
- BITNESS_8 = 1,
- BITNESS_16 = 2,
- BITNESS_32 = 4,
-};
-
-struct read_result {
+struct ReadResult {
unsigned int result;
bool successful;
};
@@ -128,39 +128,38 @@ static inline void m68k_read_callback(const uint32_t address, const uint32_t siz
}
}
-static inline struct read_result memory_read(
+static inline ReadResult memory_read(
const enum bitness bitness,
const uint32_t address)
{
m68k_read_callback(address, bitness);
if (is_in_range(address, ROM_START, ROM_SIZE)) {
- return read_result{
+ return ReadResult{
memory_read_concrete(bitness, g_rom, address - ROM_START),
true,
};
} else if (is_in_range(address, RAM_START, RAM_SIZE)) {
- return read_result{
+ return ReadResult{
memory_read_concrete(bitness, g_ram, address - RAM_START),
true,
};
} else if (is_in_range(address, SOUND_RAM_START, SOUND_RAM_SIZE)) {
- return read_result{
+ return ReadResult{
memory_read_concrete(bitness, g_sound_ram, address - SOUND_RAM_START),
true,
};
} else if (is_in_range(address, IO1_START, IO1_SIZE)) {
- return read_result{
+ return ReadResult{
memory_read_concrete(bitness, g_io1, address - IO1_START),
true,
};
} else if (is_in_range(address, VDP_START, VDP_SIZE)) {
- printf("VDP read u%d 0x%0x\n", bitness * 8, address);
- return read_result{
- memory_read_concrete(bitness, g_io2, address - VDP_START),
+ return ReadResult{
+ g_vdp.Read(address - g_vdp.base_address, bitness),
true,
};
}
- return read_result{0, false};
+ return ReadResult{0, false};
}
static inline void memory_write_concrete(
@@ -232,8 +231,7 @@ static inline bool memory_write(
}
return true;
} else if (is_in_range(address, VDP_START, VDP_SIZE)) {
- printf("VDP write u%d 0x%0x\n", bitness * 8, address);
- memory_write_concrete(bitness, g_io2, address - VDP_START, value);
+ g_vdp.Write(address - g_vdp.base_address, bitness, value);
return true;
}
return false;
@@ -244,7 +242,7 @@ static inline bool memory_write(
unsigned int m68k_read_memory_8(const unsigned int address_a)
{
const uint32_t address = MASK_24(address_a);
- const struct read_result ret = memory_read(BITNESS_8, address);
+ const ReadResult ret = memory_read(BITNESS_8, address);
if (!ret.successful) {
report_error("Read error u8 @%08x", address);
m68k_breakpoint_callback();
@@ -255,7 +253,7 @@ unsigned int m68k_read_memory_8(const unsigned int address_a)
unsigned int m68k_read_memory_16(const unsigned int address_a)
{
const uint32_t address = MASK_24(address_a);
- const struct read_result ret = memory_read(BITNESS_16, address);
+ const ReadResult ret = memory_read(BITNESS_16, address);
if (!ret.successful) {
report_error("Read error u16 @%08x", address);
m68k_breakpoint_callback();
@@ -266,7 +264,7 @@ unsigned int m68k_read_memory_16(const unsigned int address_a)
unsigned int m68k_read_memory_32(const unsigned int address_a)
{
const uint32_t address = MASK_24(address_a);
- const struct read_result ret = memory_read(BITNESS_32, address);
+ const ReadResult ret = memory_read(BITNESS_32, address);
if (!ret.successful) {
report_error("Read error u32 @%08x", address);
m68k_breakpoint_callback();
@@ -277,7 +275,7 @@ unsigned int m68k_read_memory_32(const unsigned int address_a)
unsigned int m68k_read_disassembler_16(const unsigned int address_a)
{
const uint32_t address = MASK_24(address_a);
- const struct read_result ret = memory_read(BITNESS_16, address);
+ const ReadResult ret = memory_read(BITNESS_16, address);
if (0 && !ret.successful)
exit_error("Disasm read error u16 @0x%08x", address);
return ret.result;
@@ -286,7 +284,7 @@ unsigned int m68k_read_disassembler_16(const unsigned int address_a)
unsigned int m68k_read_disassembler_32(const unsigned int address_a)
{
const uint32_t address = MASK_24(address_a);
- const struct read_result ret = memory_read(BITNESS_32, address);
+ const ReadResult ret = memory_read(BITNESS_32, address);
if (0 && !ret.successful)
exit_error("Disasm read error u32 @0x%08x", address);
return ret.result;