New io handler functions
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1758
This commit is contained in:
parent
d0e2bfa15f
commit
9cd769b878
23 changed files with 309 additions and 367 deletions
|
|
@ -19,130 +19,90 @@
|
|||
#include "dosbox.h"
|
||||
#include "inout.h"
|
||||
|
||||
#define IO_MAX 1024
|
||||
IO_WriteHandler * io_writehandlers[3][IO_MAX];
|
||||
IO_ReadHandler * io_readhandlers[3][IO_MAX];
|
||||
|
||||
static struct IO_Block {
|
||||
IO_WriteBHandler * write_b[IO_MAX];
|
||||
IO_WriteWHandler * write_w[IO_MAX];
|
||||
IO_WriteDHandler * write_d[IO_MAX];
|
||||
|
||||
IO_ReadBHandler * read_b[IO_MAX];
|
||||
IO_ReadWHandler * read_w[IO_MAX];
|
||||
IO_ReadDHandler * read_d[IO_MAX];
|
||||
} io;
|
||||
|
||||
void IO_WriteB(Bitu port,Bit8u val) {
|
||||
if (port<IO_MAX) io.write_b[port](port,val);
|
||||
else LOG(LOG_IO,LOG_WARN)("WriteB:Out or range write %X to port %4X",val,port);
|
||||
static Bitu IO_ReadBlocked(Bitu port,Bitu iolen) {
|
||||
return (Bitu)-1;
|
||||
}
|
||||
void IO_WriteW(Bitu port,Bit16u val) {
|
||||
if (port<(IO_MAX & ~1)) io.write_w[port](port,val);
|
||||
else LOG(LOG_IO,LOG_WARN)("WriteW:Out or range write %X to port %4X",val,port);
|
||||
}
|
||||
void IO_WriteD(Bitu port,Bit32u val) {
|
||||
if (port<(IO_MAX & ~3)) io.write_d[port](port,val);
|
||||
else LOG(LOG_IO,LOG_WARN)("WriteD:Out or range write %X to port %4X",val,port);
|
||||
static void IO_WriteBlocked(Bitu port,Bitu val,Bitu iolen) {
|
||||
}
|
||||
|
||||
Bit8u IO_ReadB(Bitu port) {
|
||||
if (port<IO_MAX) return io.read_b[port](port);
|
||||
else LOG(LOG_IO,LOG_WARN)("ReadB:Out or range read from port %4X",port);
|
||||
return 0xff;
|
||||
}
|
||||
Bit16u IO_ReadW(Bitu port) {
|
||||
if (port<(IO_MAX & ~1)) return io.read_w[port](port);
|
||||
else LOG(LOG_IO,LOG_WARN)("ReadW:Out or range read from port %4X",port);
|
||||
return 0xffff;
|
||||
}
|
||||
Bit32u IO_ReadD(Bitu port) {
|
||||
if (port<(IO_MAX & ~3)) return io.read_d[port](port);
|
||||
else LOG(LOG_IO,LOG_WARN)("ReadD:Out or range read from port %4X",port);
|
||||
return 0xffffffff;
|
||||
static Bitu IO_ReadDefault(Bitu port,Bitu iolen) {
|
||||
switch (iolen) {
|
||||
case 1:
|
||||
LOG(LOG_IO,LOG_WARN)("Read from port %04X",port);
|
||||
io_readhandlers[0][port]=IO_ReadBlocked;
|
||||
return 0xff;
|
||||
case 2:
|
||||
return
|
||||
(io_readhandlers[0][port+0](port+0,1) << 0) |
|
||||
(io_readhandlers[0][port+1](port+1,1) << 8);
|
||||
case 4:
|
||||
return
|
||||
(io_readhandlers[1][port+0](port+0,2) << 0) |
|
||||
(io_readhandlers[1][port+2](port+2,2) << 16);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Bit8u IO_ReadBBlocked(Bit32u port) {
|
||||
return 0xff;
|
||||
}
|
||||
static void IO_WriteBBlocked(Bit32u port,Bit8u val) {
|
||||
void IO_WriteDefault(Bitu port,Bitu val,Bitu iolen) {
|
||||
switch (iolen) {
|
||||
case 1:
|
||||
LOG(LOG_IO,LOG_WARN)("Writing %02X to port %04X",val,port);
|
||||
io_writehandlers[0][port]=IO_WriteBlocked;
|
||||
break;
|
||||
case 2:
|
||||
io_writehandlers[0][port+0](port+0,(val >> 0) & 0xff,1);
|
||||
io_writehandlers[0][port+1](port+1,(val >> 8) & 0xff,1);
|
||||
break;
|
||||
case 4:
|
||||
io_writehandlers[1][port+0](port+0,(val >> 0 ) & 0xffff,2);
|
||||
io_writehandlers[1][port+2](port+2,(val >> 16) & 0xffff,2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static Bit8u IO_ReadDefaultB(Bit32u port) {
|
||||
LOG(LOG_IO,LOG_WARN)("Reading from undefined port %04X",port);
|
||||
io.read_b[port]=IO_ReadBBlocked;
|
||||
return 0xff;
|
||||
void IO_RegisterReadHandler(Bitu port,IO_ReadHandler * handler,Bitu mask,Bitu range) {
|
||||
while (range--) {
|
||||
if (mask&IO_MB) io_readhandlers[0][port]=handler;
|
||||
if (mask&IO_MW) io_readhandlers[1][port]=handler;
|
||||
if (mask&IO_MD) io_readhandlers[2][port]=handler;
|
||||
port++;
|
||||
}
|
||||
}
|
||||
static Bit16u IO_ReadDefaultW(Bit32u port) {
|
||||
return io.read_b[port](port) | (io.read_b[port+1](port+1) << 8);
|
||||
}
|
||||
static Bit32u IO_ReadDefaultD(Bit32u port) {
|
||||
return io.read_b[port](port) | (io.read_b[port+1](port+1) << 8) |
|
||||
(io.read_b[port+2](port+2) << 16) | (io.read_b[port+3](port+3) << 24);
|
||||
void IO_RegisterWriteHandler(Bitu port,IO_WriteHandler * handler,Bitu mask,Bitu range) {
|
||||
while (range--) {
|
||||
if (mask&IO_MB) io_writehandlers[0][port]=handler;
|
||||
if (mask&IO_MW) io_writehandlers[1][port]=handler;
|
||||
if (mask&IO_MD) io_writehandlers[2][port]=handler;
|
||||
port++;
|
||||
}
|
||||
}
|
||||
|
||||
void IO_WriteDefaultB(Bit32u port,Bit8u val) {
|
||||
LOG(LOG_IO,LOG_WARN)("Writing %02X to undefined port %04X",static_cast<Bit32u>(val),port);
|
||||
io.write_b[port]=IO_WriteBBlocked;
|
||||
}
|
||||
void IO_WriteDefaultW(Bit32u port,Bit16u val) {
|
||||
io.write_b[port](port,(Bit8u)val);
|
||||
io.write_b[port+1](port+1,(Bit8u)(val>>8));
|
||||
}
|
||||
void IO_WriteDefaultD(Bit32u port,Bit32u val) {
|
||||
io.write_b[port](port,(Bit8u)val);
|
||||
io.write_b[port+1](port+1,(Bit8u)(val>>8));
|
||||
io.write_b[port+2](port+2,(Bit8u)(val>>16));
|
||||
io.write_b[port+3](port+3,(Bit8u)(val>>24));
|
||||
void IO_FreeReadHandler(Bitu port,Bitu mask,Bitu range) {
|
||||
while (range--) {
|
||||
if (mask&IO_MB) io_readhandlers[0][port]=IO_ReadDefault;
|
||||
if (mask&IO_MW) io_readhandlers[1][port]=IO_ReadDefault;
|
||||
if (mask&IO_MD) io_readhandlers[2][port]=IO_ReadDefault;
|
||||
port++;
|
||||
}
|
||||
}
|
||||
|
||||
void IO_RegisterReadBHandler(Bitu port,IO_ReadBHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.read_b[port]=handler;
|
||||
}
|
||||
void IO_RegisterReadWHandler(Bitu port,IO_ReadWHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.read_w[port]=handler;
|
||||
}
|
||||
void IO_RegisterReadDHandler(Bitu port,IO_ReadDHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.read_d[port]=handler;
|
||||
}
|
||||
void IO_RegisterWriteBHandler(Bitu port,IO_WriteBHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.write_b[port]=handler;
|
||||
}
|
||||
void IO_RegisterWriteWHandler(Bitu port,IO_WriteWHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.write_w[port]=handler;
|
||||
}
|
||||
void IO_RegisterWriteDHandler(Bitu port,IO_WriteDHandler * handler) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.write_d[port]=handler;
|
||||
}
|
||||
|
||||
|
||||
void IO_FreeReadHandler(Bitu port) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.read_b[port]=IO_ReadDefaultB;
|
||||
io.read_w[port]=IO_ReadDefaultW;
|
||||
io.read_d[port]=IO_ReadDefaultD;
|
||||
}
|
||||
void IO_FreeWriteHandler(Bitu port) {
|
||||
if (port>=IO_MAX) return;
|
||||
io.write_b[port]=IO_WriteDefaultB;
|
||||
io.write_w[port]=IO_WriteDefaultW;
|
||||
io.write_d[port]=IO_WriteDefaultD;
|
||||
}
|
||||
|
||||
void IO_Init(Section * sect) {
|
||||
for (Bitu i=0;i<IO_MAX;i++) {
|
||||
io.read_b[i]=IO_ReadDefaultB;
|
||||
io.read_w[i]=IO_ReadDefaultW;
|
||||
io.read_d[i]=IO_ReadDefaultD;
|
||||
io.write_b[i]=IO_WriteDefaultB;
|
||||
io.write_w[i]=IO_WriteDefaultW;
|
||||
io.write_d[i]=IO_WriteDefaultD;
|
||||
void IO_FreeWriteHandler(Bitu port,Bitu mask,Bitu range) {
|
||||
while (range--) {
|
||||
if (mask&IO_MB) io_writehandlers[0][port]=IO_WriteDefault;
|
||||
if (mask&IO_MW) io_writehandlers[1][port]=IO_WriteDefault;
|
||||
if (mask&IO_MD) io_writehandlers[2][port]=IO_WriteDefault;
|
||||
port++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IO_Init(Section * sect) {
|
||||
IO_FreeReadHandler(0,IO_MA,IO_MAX);
|
||||
IO_FreeWriteHandler(0,IO_MA,IO_MAX);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue