- [NEW] Implementada decodificació parcial dels ports, tal i com ho fa el spectrum
This commit is contained in:
2
main.cpp
2
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();
|
||||
|
||||
74
z80.cpp
74
z80.cpp
@@ -3,23 +3,27 @@
|
||||
#include "zx_mem.h"
|
||||
//#include "zx_tape.h"
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
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<port_t> 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;
|
||||
|
||||
2
z80.h
2
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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user