From 42da652aefbf2efb90f6575c25960b36ab2c7e89 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 24 Jul 2025 08:37:20 +0200 Subject: [PATCH] =?UTF-8?q?-=20[NEW]=20Implementada=20decodificaci=C3=B3?= =?UTF-8?q?=20parcial=20dels=20ports,=20tal=20i=20com=20ho=20fa=20el=20spe?= =?UTF-8?q?ctrum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 2 +- z80.cpp | 74 ++++++++++++++++++++++++++++++++++++---------------- z80.h | 2 +- z80debug.cpp | 2 +- zx_mem.cpp | 2 +- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/main.cpp b/main.cpp index 15a97cc..a62752b 100644 --- a/main.cpp +++ b/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) z80dis::loadSymbols(); z80::reset(); - z80::connect_port(0xfe, zx_ula::port_in, zx_ula::port_out); + z80::connect_port(0xfe, 0x0001, zx_ula::port_in, zx_ula::port_out); SDL_Init(SDL_INIT_EVERYTHING); z80debug::init(); diff --git a/z80.cpp b/z80.cpp index e950d70..0a7170a 100644 --- a/z80.cpp +++ b/z80.cpp @@ -3,23 +3,27 @@ #include "zx_mem.h" //#include "zx_tape.h" #include +#include namespace z80 { - //static uint8_t *memory = nullptr; - //static uint8_t memtag[65536]; - //static uint8_t memtouched[65536]; + struct port_t + { + uint16_t value; + uint16_t mask; + int (*in)(int); + void (*out)(int, int); + }; + static uint32_t clock = 3500000; static uint32_t t = 0; static uint16_t current_opcode_address = 0; bool options[Z80_NUM_OPTIONS] = { true, false }; int calls_stacked = 0; - int (*in_ports[256])(int); - void (*out_ports[256])(int, int); - - //#define _rM16(a) (uint16_t*)&memory[a] - //#define rM16(a) *_rM16(a) + //int (*in_ports[256])(int); + //void (*out_ports[256])(int, int); + std::vector ports; #define fC 0b00000001 #define fN 0b00000010 @@ -991,16 +995,31 @@ namespace z80 port = (rA<<8) | port; } - if (in_ports[port&0xff]) { - const uint8_t val = (uint8_t)in_ports[port&0xff](port); - if (set_flags) { - KEEP_FLAGS(fC); - SET_PARITY_FLAG(val); - FLAGS_SZXY(val); + for (auto i: ports) { + if ( ((port ^ i.value) & i.mask) == 0 ) { + if (i.in) { + const uint8_t val = (uint8_t)i.in(port); + if (set_flags) { + KEEP_FLAGS(fC); + SET_PARITY_FLAG(val); + FLAGS_SZXY(val); + } + return val; + } } - return val; - } else - return 0xFF; + } + return 0xFF; + + //if (in_ports[port&0xff]) { + // const uint8_t val = (uint8_t)in_ports[port&0xff](port); + // if (set_flags) { + // KEEP_FLAGS(fC); + // SET_PARITY_FLAG(val); + // FLAGS_SZXY(val); + // } + // return val; + //} else + // return 0xFF; } void OUT(uint8_t val, int port = 0x10000) @@ -1011,7 +1030,13 @@ namespace z80 } else { port = (rA<<8) | port; } - if (out_ports[port&0xff]) out_ports[port&0xff](port, val); + for (auto i: ports) { + if ( ((port ^ i.value) & i.mask) == 0 ) { + if (i.out) i.out(port, val); + return; + } + } + //if (out_ports[port&0xff]) out_ports[port&0xff](port, val); } void INI() @@ -1122,8 +1147,9 @@ namespace z80 { for (int i=0; i<256; ++i) { - in_ports[i] = nullptr; - out_ports[i] = nullptr; + ports.clear(); + //in_ports[i] = nullptr; + //out_ports[i] = nullptr; } mem::reset(); @@ -1150,10 +1176,12 @@ namespace z80 void IY_INSTRUCTIONS(); void IY_BIT_INSTRUCTIONS(); - void connect_port(int num, int (*in_ptr)(int), void (*out_ptr)(int,int)) + void connect_port(uint16_t num, uint16_t mask, int (*in_ptr)(int), void (*out_ptr)(int,int)) { - if (in_ptr) in_ports[num] = in_ptr; - if (out_ptr) out_ports[num] = out_ptr; + port_t port {num, mask, in_ptr, out_ptr}; + ports.push_back(port); + //if (in_ptr) in_ports in_ptr; + //if (out_ptr) out_ports[num] = out_ptr; } bool opcode_ignored = false; diff --git a/z80.h b/z80.h index 77caeda..0fdcbce 100644 --- a/z80.h +++ b/z80.h @@ -14,7 +14,7 @@ namespace z80 uint32_t getClock(); //void reset(uint8_t* mem); - void connect_port(int num, int (*in_ptr)(int), void (*out_ptr)(int,int)); + void connect_port(uint16_t num, uint16_t mask, int (*in_ptr)(int), void (*out_ptr)(int,int)); void interrupt(); uint32_t step(); diff --git a/z80debug.cpp b/z80debug.cpp index 1c96f57..f68c96b 100644 --- a/z80debug.cpp +++ b/z80debug.cpp @@ -800,7 +800,7 @@ namespace z80debug z80analyze::refresh(); } else if (strcmp(cmd, "r")==0 || strcmp(cmd, "reset")==0) { z80::reset(); - z80::connect_port(0xfe, zx_ula::port_in, zx_ula::port_out); + z80::connect_port(0xfe, 0x0001, zx_ula::port_in, zx_ula::port_out); history::reset(); z80debug::refresh(); z80analyze::refresh(); diff --git a/zx_mem.cpp b/zx_mem.cpp index 59b0621..5500dd1 100644 --- a/zx_mem.cpp +++ b/zx_mem.cpp @@ -75,7 +75,7 @@ namespace mem writable[0] = writable[1] = false; for (int i=2;i<8;++i) writable[i] = true; - z80::connect_port(0xfd, nullptr, mem::zx_128_port_out); + z80::connect_port(0x7ffd, 0x8002, nullptr, mem::zx_128_port_out); break; } }