From 9f6a6bc5cffd972d30ed1f084b51296884a51169 Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Mon, 27 Oct 2003 13:19:19 +0000 Subject: [PATCH] New IO Functions Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1380 --- include/inout.h | 58 +++++++----- src/cpu/core_normal/prefix_0f.h | 14 +++ src/cpu/core_normal/prefix_66.h | 30 ++----- src/cpu/core_normal/prefix_none.h | 34 +++---- src/cpu/core_normal/string.h | 15 ++-- src/hardware/iohandler.cpp | 141 +++++++++++++++++++++--------- 6 files changed, 168 insertions(+), 124 deletions(-) diff --git a/include/inout.h b/include/inout.h index 91f00a81..9bf30192 100644 --- a/include/inout.h +++ b/include/inout.h @@ -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); +} diff --git a/src/cpu/core_normal/prefix_0f.h b/src/cpu/core_normal/prefix_0f.h index ad397e44..d4923ffb 100644 --- a/src/cpu/core_normal/prefix_0f.h +++ b/src/cpu/core_normal/prefix_0f.h @@ -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 { diff --git a/src/cpu/core_normal/prefix_66.h b/src/cpu/core_normal/prefix_66.h index 677a4391..b64b65c0 100644 --- a/src/cpu/core_normal/prefix_66.h +++ b/src/cpu/core_normal/prefix_66.h @@ -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) */ { diff --git a/src/cpu/core_normal/prefix_none.h b/src/cpu/core_normal/prefix_none.h index 78800206..fa097f1b 100644 --- a/src/cpu/core_normal/prefix_none.h +++ b/src/cpu/core_normal/prefix_none.h @@ -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; diff --git a/src/cpu/core_normal/string.h b/src/cpu/core_normal/string.h index 4fce8638..00d70c0c 100644 --- a/src/cpu/core_normal/string.h +++ b/src/cpu/core_normal/string.h @@ -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; diff --git a/src/hardware/iohandler.cpp b/src/hardware/iohandler.cpp index 6e2429eb..be213f39 100644 --- a/src/hardware/iohandler.cpp +++ b/src/hardware/iohandler.cpp @@ -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(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) 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) 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