From 3602a06de90aca788633f7028f660fc5cedbf47b Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sun, 17 Oct 2004 14:45:00 +0000 Subject: [PATCH] Rewrote devices so they can be opened/closed/cloned. Fix Turbo pascal 7 saving bug(wd/mirek). Increase number of files to 127. Remove null device from default handles. Proper creation of the initial psp. (not hacked anymore). Quite some files= bugs should be fixed Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2025 --- include/dos_inc.h | 17 +++++--- include/dos_system.h | 21 +++++++-- src/dos/dev_con.h | 6 +-- src/dos/dos_classes.cpp | 4 +- src/dos/dos_devices.cpp | 96 +++++++++++++++++++++++++++++++---------- src/dos/dos_files.cpp | 92 ++++++++++++++++++++------------------- src/dos/dos_mscdex.cpp | 4 +- src/ints/ems.cpp | 4 +- src/shell/shell.cpp | 15 ++++--- 9 files changed, 165 insertions(+), 94 deletions(-) diff --git a/include/dos_inc.h b/include/dos_inc.h index a634119d..6f3bb3a5 100644 --- a/include/dos_inc.h +++ b/include/dos_inc.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_inc.h,v 1.48 2004-08-04 09:12:50 qbix79 Exp $ */ +/* $Id: dos_inc.h,v 1.49 2004-10-17 14:44:59 qbix79 Exp $ */ #ifndef DOS_H_ #define DOS_H_ @@ -68,13 +68,16 @@ union bootSector { enum { MCB_FREE=0x0000,MCB_DOS=0x0008 }; enum { RETURN_EXIT=0,RETURN_CTRLC=1,RETURN_ABORT=2,RETURN_TSR=3}; -#define DOS_FILES 50 +#define DOS_FILES 127 #define DOS_DRIVES 26 +#define DOS_DEVICES 10 /* internal Dos Tables */ extern DOS_File * Files[DOS_FILES]; extern DOS_Drive * Drives[DOS_DRIVES]; +extern DOS_Device * Devices[DOS_DEVICES]; + extern Bit8u dos_copybuf[0x10000]; @@ -82,7 +85,7 @@ void DOS_SetError(Bit16u code); /* File Handling Routines */ -enum { STDIN=0,STDOUT=1,STDERR=2,STDAUX=3,STDNUL=4,STDPRN=5}; +enum { STDIN=0,STDOUT=1,STDERR=2,STDAUX=3,STDPRN=4}; enum { HAND_NONE=0,HAND_FILE,HAND_DEVICE}; /* Routines for File Class */ @@ -285,10 +288,10 @@ private: Bit16u max_files; /* Maximum open files */ RealPt file_table; /* Pointer to File Table PSP:0x18 */ RealPt prev_psp; /* Pointer to previous PSP */ - Bit8u interim_flag; - Bit8u truename_flag; - Bit16u nn_flags; - Bit16u dos_version; + Bit8u interim_flag; + Bit8u truename_flag; + Bit16u nn_flags; + Bit16u dos_version; Bit8u fill_2[14]; /* Lot's of unused stuff i can't care aboue */ Bit8u service[3]; /* INT 0x21 Service call int 0x21;retf; */ Bit8u fill_3[9]; /* This has some blocks with FCB info */ diff --git a/include/dos_system.h b/include/dos_system.h index 1f273b8b..7cb770df 100644 --- a/include/dos_system.h +++ b/include/dos_system.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_system.h,v 1.24 2004-08-04 09:12:50 qbix79 Exp $ */ +/* $Id: dos_system.h,v 1.25 2004-10-17 14:44:59 qbix79 Exp $ */ #ifndef DOSSYSTEM_H_ #define DOSSYSTEM_H_ @@ -54,6 +54,8 @@ class DOS_DTA; class DOS_File { public: DOS_File():flags(0) { name=0; refCtr = 0; }; + DOS_File(const DOS_File& orig); + DOS_File & operator= (const DOS_File & orig); virtual ~DOS_File(){if(name) delete [] name;}; virtual bool Read(Bit8u * data,Bit16u * size)=0; virtual bool Write(Bit8u * data,Bit16u * size)=0; @@ -81,9 +83,20 @@ public: class DOS_Device : public DOS_File { public: -/* Some Device Specific Stuff */ - char * name; - Bit8u fhandle; + DOS_Device(const DOS_Device& orig):DOS_File(orig) {devnum=orig.devnum; } + DOS_Device & operator= (const DOS_Device & orig) { + DOS_File::operator=(orig); + devnum=orig.devnum; + } + DOS_Device():DOS_File(),devnum(0){}; + virtual bool Read(Bit8u * data,Bit16u * size); + virtual bool Write(Bit8u * data,Bit16u * size); + virtual bool Seek(Bit32u * pos,Bit32u type); + virtual bool Close(); + virtual Bit16u GetInformation(void); + void SetDeviceNumber(Bitu num) { devnum=num;} +private: + Bitu devnum; }; #define MAX_OPENDIRS 2048 diff --git a/src/dos/dev_con.h b/src/dos/dev_con.h index 8f2f9604..6a2bdd0b 100644 --- a/src/dos/dev_con.h +++ b/src/dos/dev_con.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dev_con.h,v 1.18 2004-08-26 19:41:20 qbix79 Exp $ */ +/* $Id: dev_con.h,v 1.19 2004-10-17 14:45:00 qbix79 Exp $ */ #include "dos_inc.h" #include "../ints/int10.h" @@ -345,7 +345,7 @@ bool device_CON::Seek(Bit32u * pos,Bit32u type) { } bool device_CON::Close() { - return false; + return true; } Bit16u device_CON::GetInformation(void) { @@ -357,7 +357,7 @@ Bit16u device_CON::GetInformation(void) { }; device_CON::device_CON() { - name="CON"; + SetName("CON"); cache=0; ansi.enabled=false; ansi.attr=0x7; diff --git a/src/dos/dos_classes.cpp b/src/dos/dos_classes.cpp index 8fd40fbb..14ba6ef7 100644 --- a/src/dos/dos_classes.cpp +++ b/src/dos/dos_classes.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_classes.cpp,v 1.41 2004-08-04 09:12:53 qbix79 Exp $ */ +/* $Id: dos_classes.cpp,v 1.42 2004-10-17 14:45:00 qbix79 Exp $ */ #include #include @@ -225,7 +225,7 @@ void DOS_PSP::CopyFileTable(DOS_PSP* srcpsp,bool createchildpsp) Bit8u handle = srcpsp->GetFileHandle(i); if(createchildpsp) { //copy obeying not inherit flag.(but dont duplicate them) - bool allowCopy = (handle==0) || ((handle>0) && (FindEntryByHandle(handle)==0xff)); + bool allowCopy = true;//(handle==0) || ((handle>0) && (FindEntryByHandle(handle)==0xff)); if((handleflags & DOS_NOT_INHERIT) && allowCopy) { Files[handle]->AddRef(); diff --git a/src/dos/dos_devices.cpp b/src/dos/dos_devices.cpp index a9dad893..d6eb1128 100644 --- a/src/dos/dos_devices.cpp +++ b/src/dos/dos_devices.cpp @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $Id: dos_devices.cpp,v 1.6 2004-10-17 14:45:00 qbix79 Exp $ */ + #include #include "dosbox.h" #include "callback.h" @@ -24,19 +26,18 @@ #include "bios.h" #include "dos_inc.h" #include "support.h" - -#define MAX_DEVICES 10 +#include "drives.h" //Wildcmp /* Include all the devices */ #include "dev_con.h" -static DOS_Device * devices[MAX_DEVICES]; -static Bit32u device_count; +DOS_Device * Devices[DOS_DEVICES]; +static Bitu device_count; class device_NUL : public DOS_Device { public: - device_NUL() { name="NUL"; }; + device_NUL() { SetName("NUL"); }; bool Read(Bit8u * data,Bit16u * size) { for(Bitu i = 0; i < *size;i++) data[i]=0; @@ -52,38 +53,87 @@ public: return true; } bool Close() { return true; } - Bit16u GetInformation(void) { return 0x8004; } + Bit16u GetInformation(void) { return 0x8084; } }; +bool DOS_Device::Read(Bit8u * data,Bit16u * size) { + return Devices[devnum]->Read(data,size); +} + +bool DOS_Device::Write(Bit8u * data,Bit16u * size) { + return Devices[devnum]->Write(data,size); +} + +bool DOS_Device::Seek(Bit32u * pos,Bit32u type) { + return Devices[devnum]->Seek(pos,type); +} + +bool DOS_Device::Close() { + return Devices[devnum]->Close(); +} + +Bit16u DOS_Device::GetInformation(void) { + return Devices[devnum]->GetInformation(); +} + +DOS_File::DOS_File(const DOS_File& orig) { + type=orig.type; + flags=orig.flags; + time=orig.time; + date=orig.date; + attr=orig.attr; + size=orig.size; + refCtr=orig.refCtr; + open=orig.open; + name=0; + if(orig.name) { + name=new char [strlen(orig.name)];strcpy(name,orig.name); + } +} + +DOS_File & DOS_File::operator= (const DOS_File & orig) { + type=orig.type; + flags=orig.flags; + time=orig.time; + date=orig.date; + attr=orig.attr; + size=orig.size; + refCtr=orig.refCtr; + open=orig.open; + if(name) { + delete [] name; name=0; + } + if(orig.name) { + name=new char [strlen(orig.name)];strcpy(name,orig.name); + } +} + Bit8u DOS_FindDevice(char * name) { + /* should only check for the names before the dot and spacepadded */ + char temp[CROSS_LEN];//TODOD + if(!(*name)) return DOS_DEVICES; + strcpy(temp,name); + char* dot= strrchr(temp,'.'); + if(dot && *dot) dot=0; //no ext checking + /* loop through devices */ Bit8u index=0; while (indexname)==0) return index; + if (Devices[index]) { + if (WildFileCmp(temp,Devices[index]->name)) return index; } index++; } - return 255; + return DOS_DEVICES; } void DOS_AddDevice(DOS_Device * adddev) { //TODO Give the Device a real handler in low memory that responds to calls - if (device_countSetDeviceNumber(device_count); device_count++; - /* Add the device in the main file Table */ - Bit8u handle=DOS_FILES;Bit8u i; - for (i=0;ifhandle=handle; } else { E_Exit("DOS:Too many devices added"); } @@ -94,7 +144,7 @@ void DOS_SetupDevices(void) { DOS_Device * newdev; newdev=new device_CON(); DOS_AddDevice(newdev); - DOS_Device * newdev2; + DOS_Device * newdev2; newdev2=new device_NUL(); DOS_AddDevice(newdev2); } diff --git a/src/dos/dos_files.cpp b/src/dos/dos_files.cpp index 6bff5047..65953a70 100644 --- a/src/dos/dos_files.cpp +++ b/src/dos/dos_files.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_files.cpp,v 1.57 2004-08-04 09:12:53 qbix79 Exp $ */ +/* $Id: dos_files.cpp,v 1.58 2004-10-17 14:45:00 qbix79 Exp $ */ #include #include @@ -57,7 +57,7 @@ bool DOS_MakeName(char * name,char * fullname,Bit8u * drive) { DOS_SetError(DOSERR_FILE_NOT_FOUND); return false; } - + char tempdir[DOS_PATHLENGTH]; char upname[DOS_PATHLENGTH]; Bitu r,w; @@ -232,7 +232,12 @@ bool DOS_FindFirst(char * search,Bit16u attr,bool fcb_findfirst) { *find_last=0; strcpy(pattern,find_last+1); strcpy(dir,fullsearch); - } + } +//check for devices. first part of filename before the dot +//can be the name of a device. like con.1 +//if(findDevice(pattern) blah blah +// but leading subdirs must exist.... +// dta.SetupSearch(drive,(Bit8u)attr,pattern); if (Drives[drive]->FindFirst(dir,dta,fcb_findfirst)) return true; @@ -315,15 +320,12 @@ bool DOS_CloseFile(Bit16u entry) { DOS_SetError(DOSERR_INVALID_HANDLE); return false; }; - /* Devices won't allow themselves to be closed or killed */ - if (Files[handle]->Close()) - { //if close succesfull => delete file/update psp - DOS_PSP psp(dos.psp()); - psp.SetFileHandle(entry,0xff); - if (Files[handle]->RemoveRef()<=0) { - delete Files[handle]; - Files[handle]=0; - } + Files[handle]->Close(); + DOS_PSP psp(dos.psp()); + psp.SetFileHandle(entry,0xff); + if (Files[handle]->RemoveRef()<=0) { + delete Files[handle]; + Files[handle]=0; } return true; } @@ -331,7 +333,7 @@ bool DOS_CloseFile(Bit16u entry) { bool DOS_CreateFile(char * name,Bit16u attributes,Bit16u * entry) { // Creation of a device is the same as opening it // Tc201 installer - if (DOS_FindDevice(name) != 255) + if (DOS_FindDevice(name) != DOS_DEVICES) return DOS_OpenFile(name, 0, entry); char fullname[DOS_PATHLENGTH];Bit8u drive; @@ -370,7 +372,7 @@ bool DOS_OpenFile(char * name,Bit8u flags,Bit16u * entry) { if (flags>2) LOG(LOG_FILES,LOG_ERROR)("Special file open command %X file %s",flags,name); else LOG(LOG_FILES,LOG_NORMAL)("file open command %X file %s",flags,name); - Bit16u attr; + Bit16u attr = 0; if(DOS_GetFileAttr(name,&attr)){ //DON'T ALLOW directories to be openened if((attr & DOS_ATTR_DIRECTORY) || (attr & DOS_ATTR_VOLUME)){ DOS_SetError(DOSERR_ACCESS_DENIED); @@ -379,40 +381,39 @@ bool DOS_OpenFile(char * name,Bit8u flags,Bit16u * entry) { } DOS_PSP psp(dos.psp()); - Bit8u handle=DOS_FindDevice((char *)name); - bool device=false;char fullname[DOS_PATHLENGTH];Bit8u drive;Bit8u i; - if (handle!=255) { - device=true; - } else { + Bit8u devnum=DOS_DEVICES; + devnum=DOS_FindDevice((char *)name); + bool device=(devnum!=DOS_DEVICES); + char fullname[DOS_PATHLENGTH];Bit8u drive;Bit8u i; + /* First check if the name is correct */ - if (!DOS_MakeName(name,fullname,&drive)) return false; - - /* Check for a free file handle */ - for (i=0;iFileOpen(&Files[handle],fullname,flags); + if (device) { + Files[handle]=new DOS_Device(*Devices[devnum]); + } else { + exists=Drives[drive]->FileOpen(&Files[handle],fullname,flags); + } if (exists || device ) { - // devices can only be opened once - if (device && (psp.FindEntryByHandle(handle)!=0xff)) { - *entry=psp.FindEntryByHandle(handle); - return true; - } Files[handle]->AddRef(); psp.SetFileHandle(*entry,handle); return true; @@ -451,7 +452,12 @@ bool DOS_OpenFileExtended(char *name, Bit16u flags, Bit16u createAttr, Bit16u ac bool DOS_UnlinkFile(char * name) { char fullname[DOS_PATHLENGTH];Bit8u drive; if (!DOS_MakeName(name,fullname,&drive)) return false; - return Drives[drive]->FileUnlink(fullname); + if(Drives[drive]->FileUnlink(fullname)){ + return true; + } else { + DOS_SetError(DOSERR_FILE_NOT_FOUND); + return false; + } } bool DOS_GetFileAttr(char * name,Bit16u * attr) { @@ -503,13 +509,12 @@ bool DOS_GetFreeDiskSpace(Bit8u drive,Bit16u * bytes,Bit8u * sectors,Bit16u * cl } bool DOS_DuplicateEntry(Bit16u entry,Bit16u * newentry) { - // Dont duplicate console handles - if (entry<=STDPRN) { +/* if (entry<=STDPRN) { *newentry = entry; return true; }; - +*/ Bit8u handle=RealHandle(entry); if (handle>=DOS_FILES) { DOS_SetError(DOSERR_INVALID_HANDLE); @@ -531,13 +536,12 @@ bool DOS_DuplicateEntry(Bit16u entry,Bit16u * newentry) { }; bool DOS_ForceDuplicateEntry(Bit16u entry,Bit16u newentry) { - // Dont duplicate console handles - if (entry<=STDPRN) { +/* if (entry<=STDPRN) { newentry = entry; return true; }; - +*/ Bit8u orig=RealHandle(entry); if (orig>=DOS_FILES) { DOS_SetError(DOSERR_INVALID_HANDLE); diff --git a/src/dos/dos_mscdex.cpp b/src/dos/dos_mscdex.cpp index 18e5780f..217f96d8 100644 --- a/src/dos/dos_mscdex.cpp +++ b/src/dos/dos_mscdex.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_mscdex.cpp,v 1.25 2004-10-05 19:45:27 qbix79 Exp $ */ +/* $Id: dos_mscdex.cpp,v 1.26 2004-10-17 14:45:00 qbix79 Exp $ */ #include #include @@ -1005,7 +1005,7 @@ static bool MSCDEX_Handler(void) class device_MSCDEX : public DOS_Device { public: - device_MSCDEX() { name="MSCD001"; } + device_MSCDEX() { SetName("MSCD001"); } bool Read (Bit8u * data,Bit16u * size) { return false;} bool Write(Bit8u * data,Bit16u * size) { LOG(LOG_ALL,LOG_NORMAL)("Write to mscdex device"); diff --git a/src/ints/ems.cpp b/src/ints/ems.cpp index 6ce72413..c0faac71 100644 --- a/src/ints/ems.cpp +++ b/src/ints/ems.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: ems.cpp,v 1.34 2004-08-04 09:12:56 qbix79 Exp $ */ +/* $Id: ems.cpp,v 1.35 2004-10-17 14:45:00 qbix79 Exp $ */ #include #include @@ -65,7 +65,7 @@ class device_EMM : public DOS_Device { public: - device_EMM(){name="EMMXXXX0";} + device_EMM(){SetName("EMMXXXX0");} bool Read(Bit8u * data,Bit16u * size) { return false;} bool Write(Bit8u * data,Bit16u * size){ LOG(LOG_IOCTL,LOG_NORMAL)("EMS:Write to device"); diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 097dcf43..4d38efc5 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: shell.cpp,v 1.49 2004-09-28 15:31:21 qbix79 Exp $ */ +/* $Id: shell.cpp,v 1.50 2004-10-17 14:45:00 qbix79 Exp $ */ #include #include @@ -373,12 +373,13 @@ void SHELL_Init() { DOS_PSP psp(psp_seg); psp.MakeNew(0); - psp.SetFileHandle(STDIN ,DOS_FindDevice("CON")); - psp.SetFileHandle(STDOUT,DOS_FindDevice("CON")); - psp.SetFileHandle(STDERR,DOS_FindDevice("CON")); - psp.SetFileHandle(STDAUX,DOS_FindDevice("CON")); - psp.SetFileHandle(STDNUL,DOS_FindDevice("CON")); - psp.SetFileHandle(STDPRN,DOS_FindDevice("CON")); + dos.psp(psp_seg); + Bit16u dummy=0; + DOS_OpenFile("CON",2,&dummy);/* STDIN */ + DOS_OpenFile("CON",2,&dummy);/* STDOUT */ + DOS_OpenFile("CON",2,&dummy);/* STDERR */ + DOS_OpenFile("CON",2,&dummy);/* STDAUX */ + DOS_OpenFile("CON",2,&dummy);/* STDPRN */ psp.SetParent(psp_seg); /* Set the environment */ psp.SetEnvironment(env_seg);