From f125cc7018ed32b7f919ff71ea3c7d9d2e6565de Mon Sep 17 00:00:00 2001 From: Oxore Date: Fri, 30 Sep 2022 01:21:52 +0300 Subject: Begin implementing VDP --- bus.cpp | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'bus.cpp') 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 #include @@ -12,6 +13,10 @@ #include #include +#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 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; -- cgit v1.2.3