- [NEW] Port function pointers now also receive port number as uint16_t

- [NEW] Implemented keyboard response to IN(0xfe), not working yet, DKW
This commit is contained in:
2024-04-15 14:32:18 +02:00
parent 2781a50228
commit 045a2238bd
4 changed files with 100 additions and 19 deletions

31
z80.cpp
View File

@@ -8,8 +8,8 @@ namespace z80
static uint8_t *memory = nullptr;
static uint32_t t = 0;
int (*in_ports[256])();
void (*out_ports[256])(int);
int (*in_ports[256])(int);
void (*out_ports[256])(int, int);
#define _rM16(a) (uint16_t*)&memory[a]
#define rM16(a) *_rM16(a)
@@ -811,28 +811,33 @@ namespace z80
}
}
const uint8_t IN(int port = 256)
const uint8_t IN(int port = 0x10000)
{
t+=4;
if (port == 256) {
port = rC;
if (port == 0x10000) {
port = rBC;
// [TODO] set flags acordingly
} else {
port = (rA<<8) | port;
// don't touch flags
}
if (in_ports[port])
return (uint8_t)in_ports[port]();
else
if (in_ports[port]) {
const uint8_t val = (uint8_t)in_ports[port&0xff](port);
if (val != 0xff)
return val;
else
return 0xff;
} else
return 0x00;
}
void OUT(uint8_t val, int port = 256)
void OUT(uint8_t val, int port = 0x10000)
{
t+=4;
if (port == 256) {
port = rC;
if (port == 0x10000) {
port = rBC;
}
if (out_ports[port]) out_ports[port](val);
if (out_ports[port&0xff]) out_ports[port&0xff](port, val);
}
void INI()
@@ -931,7 +936,7 @@ namespace z80
void IY_INSTRUCTIONS();
void IY_BIT_INSTRUCTIONS();
void connect_port(int num, int (*in_ptr)(), void (*out_ptr)(int))
void connect_port(int num, 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;