New IO Functions
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1380
This commit is contained in:
parent
45c1f1c663
commit
9f6a6bc5cf
6 changed files with 168 additions and 124 deletions
|
@ -16,33 +16,43 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
typedef Bit8u (IO_ReadHandler)(Bit32u port);
|
||||
typedef void (IO_WriteHandler)(Bit32u port,Bit8u value);
|
||||
typedef Bit8u (IO_ReadBHandler)(Bit32u port);
|
||||
typedef Bit16u (IO_ReadWHandler)(Bit32u port);
|
||||
typedef Bit32u (IO_ReadDHandler)(Bit32u port);
|
||||
typedef void (IO_WriteBHandler)(Bit32u port,Bit8u value);
|
||||
typedef void (IO_WriteWHandler)(Bit32u port,Bit16u value);
|
||||
typedef void (IO_WriteDHandler)(Bit32u port,Bit32u value);
|
||||
|
||||
#define IO_MAX 1024
|
||||
void IO_RegisterReadBHandler(Bitu port,IO_ReadBHandler * handler);
|
||||
void IO_RegisterReadWHandler(Bitu port,IO_ReadWHandler * handler);
|
||||
void IO_RegisterReadDHandler(Bitu port,IO_ReadDHandler * handler);
|
||||
|
||||
struct IO_ReadBlock{
|
||||
IO_ReadHandler * handler;
|
||||
char * name;
|
||||
};
|
||||
void IO_RegisterWriteBHandler(Bitu port,IO_WriteBHandler * handler);
|
||||
void IO_RegisterWriteWHandler(Bitu port,IO_WriteWHandler * handler);
|
||||
void IO_RegisterWriteDHandler(Bitu port,IO_WriteDHandler * handler);
|
||||
|
||||
struct IO_WriteBlock{
|
||||
IO_WriteHandler * handler;
|
||||
char * name;
|
||||
};
|
||||
void IO_FreeReadHandler(Bitu port);
|
||||
void IO_FreeWriteHandler(Bitu port);
|
||||
|
||||
extern IO_ReadBlock IO_ReadTable[IO_MAX];
|
||||
extern IO_WriteBlock IO_WriteTable[IO_MAX];
|
||||
|
||||
|
||||
|
||||
void IO_Write(Bitu num,Bit8u val);
|
||||
Bit8u IO_Read(Bitu num);
|
||||
|
||||
void IO_RegisterReadHandler(Bit32u port,IO_ReadHandler * handler,char * name);
|
||||
void IO_RegisterWriteHandler(Bit32u port,IO_WriteHandler * handler,char * name);
|
||||
|
||||
void IO_FreeReadHandler(Bit32u port);
|
||||
void IO_FreeWriteHandler(Bit32u port);
|
||||
void IO_WriteB(Bitu port,Bit8u val);
|
||||
Bit8u IO_ReadB(Bitu port);
|
||||
void IO_WriteW(Bitu port,Bit16u val);
|
||||
Bit16u IO_ReadW(Bitu port);
|
||||
void IO_WriteD(Bitu port,Bit32u val);
|
||||
Bit32u IO_ReadD(Bitu port);
|
||||
|
||||
INLINE void IO_Write(Bitu port,Bit8u val) {
|
||||
IO_WriteB(port,val);
|
||||
}
|
||||
INLINE Bit8u IO_Read(Bitu port){
|
||||
return IO_ReadB(port);
|
||||
}
|
||||
|
||||
INLINE void IO_RegisterReadHandler(Bitu port,IO_ReadBHandler * handler,char * name) {
|
||||
IO_RegisterReadBHandler(port,handler);
|
||||
}
|
||||
INLINE void IO_RegisterWriteHandler(Bitu port,IO_WriteBHandler * handler,char * name) {
|
||||
IO_RegisterWriteBHandler(port,handler);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -138,6 +138,19 @@
|
|||
}
|
||||
}
|
||||
break;
|
||||
CASE_0F_B(0x21) /* MOV Rd,DRx */
|
||||
{
|
||||
GetRM;
|
||||
Bitu which=(rm >> 3) & 7;
|
||||
LOG_MSG("MOV REG,DR%d",which);
|
||||
if (rm >= 0xc0 ) {
|
||||
GetEArd;
|
||||
} else {
|
||||
GetEAa;
|
||||
LOG(LOG_CPU,LOG_ERROR)("MOV XXX,DR% with non-register",which);
|
||||
}
|
||||
}
|
||||
break;
|
||||
CASE_0F_B(0x22) /* MOV CRx,Rd */
|
||||
{
|
||||
GetRM;
|
||||
|
@ -155,6 +168,7 @@
|
|||
{
|
||||
GetRM;
|
||||
Bitu which=(rm >> 3) & 7;
|
||||
LOG_MSG("MOV DR%d,REG",which);
|
||||
if (rm >= 0xc0 ) {
|
||||
GetEArd;
|
||||
} else {
|
||||
|
|
|
@ -513,23 +513,11 @@
|
|||
CASE_D(0xd3) /* GRP2 Ed,CL */
|
||||
GRP2D(reg_cl);break;
|
||||
CASE_D(0xe5) /* IN EAX,Ib */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
reg_eax=IO_Read(port) |
|
||||
(IO_Read(port+1) << 8 ) |
|
||||
(IO_Read(port+2) << 16 ) |
|
||||
(IO_Read(port+3) << 24 );
|
||||
break;
|
||||
}
|
||||
reg_eax=IO_ReadD(Fetchb());
|
||||
break;
|
||||
CASE_D(0xe7) /* OUT Ib,EAX */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
IO_Write(port+0,(Bit8u)(reg_eax >> 0));
|
||||
IO_Write(port+1,(Bit8u)(reg_eax >> 8));
|
||||
IO_Write(port+2,(Bit8u)(reg_eax >> 16));
|
||||
IO_Write(port+3,(Bit8u)(reg_eax >> 24));
|
||||
break;
|
||||
}
|
||||
IO_WriteD(Fetchb(),reg_eax);
|
||||
break;
|
||||
CASE_D(0xe8) /* CALL Jd */
|
||||
{
|
||||
Bit32s newip=Fetchds();
|
||||
|
@ -553,16 +541,10 @@
|
|||
break;
|
||||
}
|
||||
CASE_D(0xed) /* IN EAX,DX */
|
||||
reg_eax=IO_Read(reg_dx) |
|
||||
(IO_Read(reg_dx+1) << 8) |
|
||||
(IO_Read(reg_dx+2) << 16) |
|
||||
(IO_Read(reg_dx+3) << 24);
|
||||
reg_eax=IO_ReadD(reg_dx);
|
||||
break;
|
||||
CASE_D(0xef) /* OUT DX,EAX */
|
||||
IO_Write(reg_dx,(Bit8u)(reg_eax>>0));
|
||||
IO_Write(reg_dx+1,(Bit8u)(reg_eax>>8));
|
||||
IO_Write(reg_dx+2,(Bit8u)(reg_eax>>16));
|
||||
IO_Write(reg_dx+3,(Bit8u)(reg_eax>>24));
|
||||
IO_WriteD(reg_dx,reg_eax);
|
||||
break;
|
||||
CASE_D(0xf7) /* GRP3 Ed(,Id) */
|
||||
{
|
||||
|
|
|
@ -901,31 +901,17 @@
|
|||
break;
|
||||
}
|
||||
CASE_B(0xe4) /* IN AL,Ib */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
reg_al=IO_Read(port);
|
||||
break;
|
||||
}
|
||||
reg_al=IO_ReadB(Fetchb());
|
||||
break;
|
||||
CASE_W(0xe5) /* IN AX,Ib */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
reg_al=IO_Read(port);
|
||||
reg_ah=IO_Read(port+1);
|
||||
break;
|
||||
}
|
||||
reg_ax=IO_ReadW(Fetchb());
|
||||
break;
|
||||
CASE_B(0xe6) /* OUT Ib,AL */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
IO_Write(port,reg_al);
|
||||
break;
|
||||
}
|
||||
IO_WriteB(Fetchb(),reg_al);
|
||||
break;
|
||||
CASE_W(0xe7) /* OUT Ib,AX */
|
||||
{
|
||||
Bit16u port=Fetchb();
|
||||
IO_Write(port,reg_al);
|
||||
IO_Write(port+1,reg_ah);
|
||||
break;
|
||||
}
|
||||
IO_WriteW(Fetchb(),reg_ax);
|
||||
break;
|
||||
CASE_W(0xe8) /* CALL Jw */
|
||||
{
|
||||
Bit16s newip=Fetchws();
|
||||
|
@ -956,9 +942,9 @@
|
|||
reg_al=IO_Read(reg_dx);reg_ah=IO_Read(reg_dx+1);
|
||||
break;
|
||||
CASE_B(0xee) /* OUT DX,AL */
|
||||
IO_Write(reg_dx,reg_al);break;
|
||||
IO_WriteB(reg_dx,reg_al);break;
|
||||
CASE_W(0xef) /* OUT DX,AX */
|
||||
IO_Write(reg_dx,reg_al);IO_Write(reg_dx+1,reg_ah);break;
|
||||
IO_WriteW(reg_dx,reg_ax);break;
|
||||
CASE_B(0xf0) /* LOCK */
|
||||
LOG(LOG_CPU,LOG_NORMAL)("CPU:LOCK");
|
||||
break;
|
||||
|
|
|
@ -50,39 +50,34 @@ static void DoString(STRING_OP type) {
|
|||
if (count) switch (type) {
|
||||
case R_OUTSB:
|
||||
for (;count>0;count--) {
|
||||
IO_Write(reg_dx,LoadMb(si_base+si_index));
|
||||
IO_WriteB(reg_dx,LoadMb(si_base+si_index));
|
||||
si_index=(si_index+add_index) & add_mask;
|
||||
}
|
||||
break;
|
||||
case R_OUTSW:
|
||||
add_index<<=1;
|
||||
for (;count>0;count--) {
|
||||
IO_Write(reg_dx,LoadMb(si_base+si_index));
|
||||
IO_Write(reg_dx+1,LoadMb(si_base+si_index+1));
|
||||
IO_WriteW(reg_dx,LoadMw(si_base+si_index));
|
||||
si_index=(si_index+add_index) & add_mask;
|
||||
}
|
||||
break;
|
||||
case R_OUTSD:
|
||||
add_index<<=2;
|
||||
for (;count>0;count--) {
|
||||
IO_Write(reg_dx,LoadMb(si_base+si_index));
|
||||
IO_Write(reg_dx+1,LoadMb(si_base+si_index+1));
|
||||
IO_Write(reg_dx+2,LoadMb(si_base+si_index+2));
|
||||
IO_Write(reg_dx+3,LoadMb(si_base+si_index+3));
|
||||
IO_WriteD(reg_dx,LoadMd(si_base+si_index));
|
||||
si_index=(si_index+add_index) & add_mask;
|
||||
}
|
||||
break;
|
||||
case R_INSB:
|
||||
for (;count>0;count--) {
|
||||
SaveMb(di_base+di_index,IO_Read(reg_dx));
|
||||
SaveMb(di_base+di_index,IO_ReadB(reg_dx));
|
||||
di_index=(di_index+add_index) & add_mask;
|
||||
}
|
||||
break;
|
||||
case R_INSW:
|
||||
add_index<<=1;
|
||||
for (;count>0;count--) {
|
||||
SaveMb(di_base+di_index,IO_Read(reg_dx));
|
||||
SaveMb(di_base+di_index+1,IO_Read(reg_dx+1));
|
||||
SaveMw(di_base+di_index,IO_ReadW(reg_dx));
|
||||
di_index=(di_index+add_index) & add_mask;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -19,71 +19,128 @@
|
|||
#include "dosbox.h"
|
||||
#include "inout.h"
|
||||
|
||||
IO_ReadBlock IO_ReadTable[IO_MAX];
|
||||
IO_WriteBlock IO_WriteTable[IO_MAX];
|
||||
#define IO_MAX 1024
|
||||
|
||||
void IO_Write(Bitu num,Bit8u val) {
|
||||
if (num<IO_MAX) IO_WriteTable[num].handler(num,val);
|
||||
else LOG(LOG_IO,LOG_WARN)("IO:Out or range write %X2 to port %4X",val,num);
|
||||
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);
|
||||
}
|
||||
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)) return io.write_d[port](port,val);
|
||||
else LOG(LOG_IO,LOG_WARN)("WriteD:Out or range write %X to port %4X",val,port);
|
||||
}
|
||||
|
||||
Bit8u IO_Read(Bitu num) {
|
||||
if (num<IO_MAX) return IO_ReadTable[num].handler(num);
|
||||
else LOG(LOG_IO,LOG_WARN)("IO:Out or range read from port %4X",num);
|
||||
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 Bit8u IO_ReadBlocked(Bit32u port) {
|
||||
static Bit8u IO_ReadBBlocked(Bit32u port) {
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
static void IO_WriteBlocked(Bit32u port,Bit8u val) {
|
||||
static void IO_WriteBBlocked(Bit32u port,Bit8u val) {
|
||||
}
|
||||
|
||||
static Bit8u IO_ReadDefault(Bit32u port) {
|
||||
static Bit8u IO_ReadDefaultB(Bit32u port) {
|
||||
LOG(LOG_IO,LOG_WARN)("Reading from undefined port %04X",port);
|
||||
IO_RegisterReadHandler(port,&IO_ReadBlocked,"Blocked Read");
|
||||
io.read_b[port]=IO_ReadBBlocked;
|
||||
return 0xff;
|
||||
}
|
||||
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_WriteDefault(Bit32u port,Bit8u val) {
|
||||
void IO_WriteDefaultB(Bit32u port,Bit8u val) {
|
||||
LOG(LOG_IO,LOG_WARN)("Writing %02X to undefined port %04X",static_cast<Bit32u>(val),port);
|
||||
IO_RegisterWriteHandler(port,&IO_WriteBlocked,"Blocked Write");
|
||||
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_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_RegisterReadHandler(Bit32u port,IO_ReadHandler * handler,char * name) {
|
||||
if (port<IO_MAX) {
|
||||
IO_ReadTable[port].handler=handler;
|
||||
IO_ReadTable[port].name=name;
|
||||
}
|
||||
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_RegisterWriteHandler(Bit32u port,IO_WriteHandler * handler,char * name) {
|
||||
if (port<IO_MAX) {
|
||||
IO_WriteTable[port].handler=handler;
|
||||
IO_WriteTable[port].name=name;
|
||||
}
|
||||
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_FreeReadHandler(Bit32u port) {
|
||||
if (port<IO_MAX) {
|
||||
IO_RegisterReadHandler(port,&IO_ReadDefault,"Default Read");
|
||||
}
|
||||
}
|
||||
void IO_FreeWriteHandler(Bit32u port) {
|
||||
if (port<IO_MAX) {
|
||||
IO_RegisterWriteHandler(port,&IO_WriteDefault,"Default Write");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IO_Init(Section * sect) {
|
||||
for (Bitu i=0;i<IO_MAX;i++) {
|
||||
IO_RegisterReadHandler(i,&IO_ReadDefault,"Default Read");
|
||||
IO_RegisterWriteHandler(i,&IO_WriteDefault,"Default Write");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue