diff options
author | Oxore <oxore@protonmail.com> | 2022-09-25 18:05:16 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2022-09-25 18:10:47 +0300 |
commit | 0dc9d15cdcc9cadffaeec9dfbc2b047fe064fee4 (patch) | |
tree | 47eeb86a142b4c74db702cab40015db0d5a8336d | |
parent | 3cd8c083c736cd95be8e575fa70535f9c8eab924 (diff) |
Add Z80 BUSREQ and sound RAM
-rw-r--r-- | bus.cpp | 33 | ||||
-rw-r--r-- | bus.hpp | 3 |
2 files changed, 33 insertions, 3 deletions
@@ -12,8 +12,13 @@ #include <cstdint> #include <cstdlib> +namespace Adr { +static constexpr uint32_t kZ80BusReq = 0x00a11100; +} + 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[IO2_SIZE] = {}; @@ -25,6 +30,13 @@ static void exit_error(const char* fmt, ...) va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); + static bool in_error = false; + if (in_error) + { + fprintf(stderr, "Nested error\n"); + return; + } + in_error = true; fprintf(stderr, "\n"); unsigned int pc = m68k_get_reg(NULL, M68K_REG_PPC); char buff[100]; @@ -82,6 +94,11 @@ static inline struct read_result memory_read( 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{ + 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{ memory_read_concrete(bitness, g_io1, address - IO1_START), @@ -130,8 +147,18 @@ static inline bool memory_write( } else if (is_in_range(address, RAM_START, RAM_SIZE)) { memory_write_concrete(bitness, g_ram, address - RAM_START, value); return true; + } else if (is_in_range(address, SOUND_RAM_START, SOUND_RAM_SIZE)) { + memory_write_concrete(bitness, g_sound_ram, address - SOUND_RAM_START, value); + return true; } else if (is_in_range(address, IO1_START, IO1_SIZE)) { memory_write_concrete(bitness, g_io1, address - IO1_START, value); + if (address == Adr::kZ80BusReq || address == Adr::kZ80BusReq + 1) { + if (g_io1[Adr::kZ80BusReq - IO1_START] == 1 && g_io1[Adr::kZ80BusReq - IO1_START + 1] == 0) { + // Acknowledge S80 BUSREQ + g_io1[Adr::kZ80BusReq - IO1_START + 0] = 0; + g_io1[Adr::kZ80BusReq - IO1_START + 1] = 0; + } + } return true; } else if (is_in_range(address, IO2_START, IO2_SIZE)) { memory_write_concrete(bitness, g_io2, address - IO2_START, value); @@ -199,7 +226,7 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) m68k_write_callback(address, 1); const bool successful = memory_write(BITNESS_8, address, value); if (!successful) - exit_error("Attempted to write %02x (u8) to address %08x", value&0xff, address); + exit_error("Attempted to write 0x%02x (u8) to address %08x", value&0xff, address); } void m68k_write_memory_16(unsigned int address, unsigned int value) @@ -208,7 +235,7 @@ void m68k_write_memory_16(unsigned int address, unsigned int value) m68k_write_callback(address, 2); const bool successful = memory_write(BITNESS_16, address, value); if (!successful) - exit_error("Attempted to write %04x (u16) to address %08x", value&0xffff, address); + exit_error("Attempted to write 0x%04x (u16) to address %08x", value&0xffff, address); } void m68k_write_memory_32(unsigned int address, unsigned int value) @@ -217,5 +244,5 @@ void m68k_write_memory_32(unsigned int address, unsigned int value) m68k_write_callback(address, 4); const bool successful = memory_write(BITNESS_16, address, value); if (!successful) - exit_error("Attempted to write %08x (u32) to address %08x", value, address); + exit_error("Attempted to write 0x%08x (u32) to address %08x", value, address); } @@ -11,6 +11,8 @@ #define ROM_SIZE (0x400000) #define RAM_START (0xFF0000) #define RAM_SIZE (0x10000) +#define SOUND_RAM_START (0xA00000) +#define SOUND_RAM_SIZE (0x2000) #define IO1_START (0xA10000) #define IO1_SIZE (0x4004) #define IO2_START (0xC00000) @@ -22,6 +24,7 @@ struct Breakpoint { extern unsigned char g_rom[ROM_SIZE]; extern unsigned char g_ram[RAM_SIZE]; +extern unsigned char g_sound_ram[SOUND_RAM_SIZE]; extern unsigned char g_io1[IO1_SIZE]; extern unsigned char g_io2[IO2_SIZE]; extern std::vector<Breakpoint> code_bkpts, read_bkpts, write_bkpts, access_bkpts; |