summaryrefslogtreecommitdiff
path: root/bus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bus.cpp')
-rw-r--r--bus.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/bus.cpp b/bus.cpp
index 9697c09..f611eba 100644
--- a/bus.cpp
+++ b/bus.cpp
@@ -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);
}