DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/dos_inc.h
00001 /*
00002  *  Copyright (C) 2002-2015  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #ifndef DOSBOX_DOS_INC_H
00021 #define DOSBOX_DOS_INC_H
00022 
00023 #include <stddef.h>
00024 
00025 #ifndef DOSBOX_DOS_SYSTEM_H
00026 #include "dos_system.h"
00027 #endif
00028 #ifndef DOSBOX_MEM_H
00029 #include "mem.h"
00030 #endif
00031 
00032 #include <stddef.h> //for offsetof
00033 
00034 #ifdef _MSC_VER
00035 #pragma pack (1)
00036 #endif
00037 struct CommandTail{
00038   Bit8u count;                          /* number of bytes returned */
00039   char buffer[127];                      /* the buffer itself */
00040 } GCC_ATTRIBUTE(packed);
00041 #ifdef _MSC_VER
00042 #pragma pack ()
00043 #endif
00044 
00045 extern Bit16u first_umb_seg;
00046 extern Bit16u first_umb_size;
00047 
00048 bool MEM_unmap_physmem(Bitu start,Bitu end);
00049 bool MEM_map_RAM_physmem(Bitu start,Bitu end);
00050 
00051 struct BuiltinFileBlob {
00052         const char              *recommended_file_name;
00053         const unsigned char     *data;
00054         size_t                  length;
00055 };
00056 
00057 struct DOS_Date {
00058         Bit16u year;
00059         Bit8u month;
00060         Bit8u day;
00061 };
00062 
00063 struct DOS_Version {
00064         Bit8u major,minor,revision;
00065 };
00066 
00067 #ifndef MACOSX
00068 #if defined (__APPLE__)
00069 #define MACOSX 1
00070 #endif
00071 #endif
00072 
00073 #ifdef __cplusplus
00074 extern "C" {
00075 #endif
00076 
00077 typedef signed char         INT8, *PINT8;
00078 typedef signed short        INT16, *PINT16;
00079 typedef signed int          INT32, *PINT32;
00080 //typedef signed __int64      INT64, *PINT64;
00081 typedef unsigned char       UINT8, *PUINT8;
00082 typedef unsigned short      UINT16, *PUINT16;
00083 typedef unsigned int        UINT32, *PUINT32;
00084 //typedef unsigned __int64    UINT64, *PUINT64;
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 
00089 #define SECTOR_SIZE_MAX     1024
00090 
00091 #ifdef _MSC_VER
00092 #pragma pack (1)
00093 #endif
00094 union bootSector {
00095         struct entries {
00096                 Bit8u jump[3];
00097                 Bit8u oem_name[8];
00098                 Bit16u bytesect;
00099                 Bit8u sectclust;
00100                 Bit16u reserve_sect;
00101         } bootdata;
00102         Bit8u rawdata[SECTOR_SIZE_MAX];
00103 } GCC_ATTRIBUTE(packed);
00104 #ifdef _MSC_VER
00105 #pragma pack ()
00106 #endif
00107 
00108 
00109 enum { MCB_FREE=0x0000,MCB_DOS=0x0008 };
00110 enum { RETURN_EXIT=0,RETURN_CTRLC=1,RETURN_ABORT=2,RETURN_TSR=3};
00111 
00112 extern Bitu DOS_FILES;
00113 
00114 #define DOS_DRIVES 26
00115 #define DOS_DEVICES 10
00116 
00117 
00118 #if 0 /* ORIGINAL DEFINES FOR REFERENCE */
00119 // dos swappable area is 0x320 bytes beyond the sysvars table
00120 // device driver chain is inside sysvars
00121 #define DOS_INFOBLOCK_SEG 0x80  // sysvars (list of lists)
00122 #define DOS_CONDRV_SEG 0xa0
00123 #define DOS_CONSTRING_SEG 0xa8
00124 #define DOS_SDA_SEG 0xb2                // dos swappable area
00125 #define DOS_SDA_OFS 0
00126 #define DOS_CDS_SEG 0x108
00127 #define DOS_MEM_START 0x158      // regression to r3437 fixes nascar 2 colors
00128 //#define DOS_MEM_START 0x16f           //First Segment that DOS can use 
00129 
00130 #define DOS_PRIVATE_SEGMENT 0xc800
00131 #define DOS_PRIVATE_SEGMENT_END 0xd000
00132 #endif
00133 
00134 // dos swappable area is 0x320 bytes beyond the sysvars table
00135 // device driver chain is inside sysvars
00136 extern Bit16u DOS_INFOBLOCK_SEG;// 0x80 // sysvars (list of lists)
00137 extern Bit16u DOS_CONDRV_SEG;// 0xa0
00138 extern Bit16u DOS_CONSTRING_SEG;// 0xa8
00139 extern Bit16u DOS_SDA_SEG;// 0xb2               // dos swappable area
00140 extern Bit16u DOS_SDA_SEG_SIZE;
00141 extern Bit16u DOS_SDA_OFS;// 0
00142 extern Bit16u DOS_CDS_SEG;// 0x108
00143 extern Bit16u DOS_MEM_START;// 0x158     // regression to r3437 fixes nascar 2 colors
00144 
00145 extern Bit16u DOS_PRIVATE_SEGMENT;// 0xc800
00146 extern Bit16u DOS_PRIVATE_SEGMENT_END;// 0xd000
00147 
00148 /* internal Dos Tables */
00149 
00150 extern DOS_File ** Files;
00151 extern DOS_Drive * Drives[DOS_DRIVES];
00152 extern DOS_Device * Devices[DOS_DEVICES];
00153 
00154 extern Bit8u dos_copybuf[0x10000];
00155 
00156 
00157 void DOS_SetError(Bit16u code);
00158 
00159 /* File Handling Routines */
00160 
00161 enum { STDIN=0,STDOUT=1,STDERR=2,STDAUX=3,STDPRN=4};
00162 enum { HAND_NONE=0,HAND_FILE,HAND_DEVICE};
00163 
00164 /* Routines for File Class */
00165 void DOS_SetupFiles (void);
00166 bool DOS_ReadFile(Bit16u handle,Bit8u * data,Bit16u * amount);
00167 bool DOS_WriteFile(Bit16u handle,Bit8u * data,Bit16u * amount);
00168 bool DOS_SeekFile(Bit16u handle,Bit32u * pos,Bit32u type);
00169 /* ert, 20100711: Locking extensions */
00170 bool DOS_LockFile(Bit16u entry,Bit8u mode,Bit32u pos,Bit32u size);
00171 bool DOS_CloseFile(Bit16u handle);
00172 bool DOS_FlushFile(Bit16u handle);
00173 bool DOS_DuplicateEntry(Bit16u entry,Bit16u * newentry);
00174 bool DOS_ForceDuplicateEntry(Bit16u entry,Bit16u newentry);
00175 bool DOS_GetFileDate(Bit16u entry, Bit16u* otime, Bit16u* odate);
00176 bool DOS_SetFileDate(Bit16u entry, Bit16u ntime, Bit16u ndate);
00177 
00178 /* Routines for Drive Class */
00179 bool DOS_OpenFile(char const * name,Bit8u flags,Bit16u * entry);
00180 bool DOS_OpenFileExtended(char const * name, Bit16u flags, Bit16u createAttr, Bit16u action, Bit16u *entry, Bit16u* status);
00181 bool DOS_CreateFile(char const * name,Bit16u attribute,Bit16u * entry);
00182 bool DOS_UnlinkFile(char const * const name);
00183 bool DOS_FindFirst(char *search,Bit16u attr,bool fcb_findfirst=false);
00184 bool DOS_FindNext(void);
00185 bool DOS_Canonicalize(char const * const name,char * const big);
00186 bool DOS_CreateTempFile(char * const name,Bit16u * entry);
00187 bool DOS_FileExists(char const * const name);
00188 
00189 /* Helper Functions */
00190 bool DOS_MakeName(char const * const name,char * const fullname,Bit8u * drive);
00191 /* Drive Handing Routines */
00192 Bit8u DOS_GetDefaultDrive(void);
00193 void DOS_SetDefaultDrive(Bit8u drive);
00194 bool DOS_SetDrive(Bit8u drive);
00195 bool DOS_GetCurrentDir(Bit8u drive,char * const buffer);
00196 bool DOS_ChangeDir(char const * const dir);
00197 bool DOS_MakeDir(char const * const dir);
00198 bool DOS_RemoveDir(char const * const dir);
00199 bool DOS_Rename(char const * const oldname,char const * const newname);
00200 bool DOS_GetFreeDiskSpace(Bit8u drive,Bit16u * bytes,Bit8u * sectors,Bit16u * clusters,Bit16u * free);
00201 bool DOS_GetFileAttr(char const * const name,Bit16u * attr);
00202 bool DOS_SetFileAttr(char const * const name,Bit16u attr);
00203 
00204 /* IOCTL Stuff */
00205 bool DOS_IOCTL(void);
00206 bool DOS_GetSTDINStatus();
00207 Bit8u DOS_FindDevice(char const * name);
00208 void DOS_SetupDevices(void);
00209 
00210 /* Execute and new process creation */
00211 bool DOS_NewPSP(Bit16u pspseg,Bit16u size);
00212 bool DOS_ChildPSP(Bit16u pspseg,Bit16u size);
00213 bool DOS_Execute(char * name,PhysPt block,Bit8u flags);
00214 void DOS_Terminate(Bit16u pspseg,bool tsr,Bit8u exitcode);
00215 
00216 /* Memory Handling Routines */
00217 void DOS_SetupMemory(void);
00218 bool DOS_AllocateMemory(Bit16u * segment,Bit16u * blocks);
00219 bool DOS_ResizeMemory(Bit16u segment,Bit16u * blocks);
00220 bool DOS_FreeMemory(Bit16u segment);
00221 void DOS_FreeProcessMemory(Bit16u pspseg);
00222 Bit16u BIOS_GetMemory(Bit16u pages,const char *who=NULL);
00223 Bit16u DOS_GetMemory(Bit16u pages,const char *who=NULL);
00224 bool DOS_SetMemAllocStrategy(Bit16u strat);
00225 Bit16u DOS_GetMemAllocStrategy(void);
00226 void DOS_BuildUMBChain(bool umb_active,bool ems_active);
00227 bool DOS_LinkUMBsToMemChain(Bit16u linkstate);
00228 
00229 /* FCB stuff */
00230 bool DOS_FCBOpen(Bit16u seg,Bit16u offset);
00231 bool DOS_FCBCreate(Bit16u seg,Bit16u offset);
00232 bool DOS_FCBClose(Bit16u seg,Bit16u offset);
00233 bool DOS_FCBFindFirst(Bit16u seg,Bit16u offset);
00234 bool DOS_FCBFindNext(Bit16u seg,Bit16u offset);
00235 Bit8u DOS_FCBRead(Bit16u seg,Bit16u offset, Bit16u numBlocks);
00236 Bit8u DOS_FCBWrite(Bit16u seg,Bit16u offset,Bit16u numBlocks);
00237 Bit8u DOS_FCBRandomRead(Bit16u seg,Bit16u offset,Bit16u * numRec,bool restore);
00238 Bit8u DOS_FCBRandomWrite(Bit16u seg,Bit16u offset,Bit16u * numRec,bool restore);
00239 bool DOS_FCBGetFileSize(Bit16u seg,Bit16u offset);
00240 bool DOS_FCBDeleteFile(Bit16u seg,Bit16u offset);
00241 bool DOS_FCBRenameFile(Bit16u seg, Bit16u offset);
00242 void DOS_FCBSetRandomRecord(Bit16u seg, Bit16u offset);
00243 Bit8u FCB_Parsename(Bit16u seg,Bit16u offset,Bit8u parser ,char *string, Bit8u *change);
00244 bool DOS_GetAllocationInfo(Bit8u drive,Bit16u * _bytes_sector,Bit8u * _sectors_cluster,Bit16u * _total_clusters);
00245 
00246 /* Extra DOS Interrupts */
00247 void DOS_SetupMisc(void);
00248 
00249 /* The DOS Tables */
00250 void DOS_SetupTables(void);
00251 
00252 /* Internal DOS Setup Programs */
00253 void DOS_SetupPrograms(void);
00254 
00255 /* Initialize Keyboard Layout */
00256 void DOS_KeyboardLayout_Init(Section* sec);
00257 
00258 bool DOS_LayoutKey(Bitu key, Bit8u flags1, Bit8u flags2, Bit8u flags3);
00259 
00260 enum {
00261         KEYB_NOERROR=0,
00262         KEYB_FILENOTFOUND,
00263         KEYB_INVALIDFILE,
00264         KEYB_LAYOUTNOTFOUND,
00265         KEYB_INVALIDCPFILE
00266 };
00267 
00268 
00269 static INLINE Bit16u long2para(Bit32u size) {
00270         if (size>0xFFFF0) return 0xffff;
00271         if (size&0xf) return (Bit16u)((size>>4)+1);
00272         else return (Bit16u)(size>>4);
00273 }
00274 
00275 
00276 static INLINE Bit16u DOS_PackTime(Bit16u hour,Bit16u min,Bit16u sec) {
00277         return (hour&0x1f)<<11 | (min&0x3f) << 5 | ((sec/2)&0x1f);
00278 }
00279 
00280 static INLINE Bit16u DOS_PackDate(Bit16u year,Bit16u mon,Bit16u day) {
00281         return ((year-1980)&0x7f)<<9 | (mon&0x3f) << 5 | (day&0x1f);
00282 }
00283 
00284 /* fopen64, ftello64, fseeko64 */
00285 #if defined(__APPLE__) || defined(__MINGW32__)
00286  #define fopen64 fopen
00287  #define ftello64 ftell
00288  #define fseeko64 fseek
00289 #elif defined (_MSC_VER)
00290  #define fopen64 fopen
00291  #if (_MSC_VER >= 1400)
00292   #define ftello64 _ftelli64
00293   #define fseeko64 _fseeki64
00294  #else
00295   #define ftello64 ftell
00296   #define fseeko64 fseek
00297  #endif
00298 #endif
00299 
00300 /* Dos Error Codes */
00301 #define DOSERR_NONE 0
00302 #define DOSERR_FUNCTION_NUMBER_INVALID 1
00303 #define DOSERR_FILE_NOT_FOUND 2
00304 #define DOSERR_PATH_NOT_FOUND 3
00305 #define DOSERR_TOO_MANY_OPEN_FILES 4
00306 #define DOSERR_ACCESS_DENIED 5
00307 #define DOSERR_INVALID_HANDLE 6
00308 #define DOSERR_MCB_DESTROYED 7
00309 #define DOSERR_INSUFFICIENT_MEMORY 8
00310 #define DOSERR_MB_ADDRESS_INVALID 9
00311 #define DOSERR_ENVIRONMENT_INVALID 10
00312 #define DOSERR_FORMAT_INVALID 11
00313 #define DOSERR_ACCESS_CODE_INVALID 12
00314 #define DOSERR_DATA_INVALID 13
00315 #define DOSERR_RESERVED 14
00316 #define DOSERR_FIXUP_OVERFLOW 14
00317 #define DOSERR_INVALID_DRIVE 15
00318 #define DOSERR_REMOVE_CURRENT_DIRECTORY 16
00319 #define DOSERR_NOT_SAME_DEVICE 17
00320 #define DOSERR_NO_MORE_FILES 18
00321 #define DOSERR_WRITE_PROTECTED 19
00322 #define DOSERR_FILE_ALREADY_EXISTS 80
00323 
00324 
00325 /* Remains some classes used to access certain things */
00326 #define sOffset(s,m) ((char*)&(((s*)NULL)->m)-(char*)NULL)
00327 #define sGet(s,m) GetIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m))
00328 #define sSave(s,m,val) SaveIt(sizeof(((s *)&pt)->m),(PhysPt)sOffset(s,m),val)
00329 
00330 class MemStruct {
00331 public:
00332         Bitu GetIt(Bitu size,PhysPt addr) {
00333                 switch (size) {
00334                 case 1:return mem_readb(pt+addr);
00335                 case 2:return mem_readw(pt+addr);
00336                 case 4:return mem_readd(pt+addr);
00337                 }
00338                 return 0;
00339         }
00340         void SaveIt(Bitu size,PhysPt addr,Bitu val) {
00341                 switch (size) {
00342                 case 1:mem_writeb(pt+addr,(Bit8u)val);break;
00343                 case 2:mem_writew(pt+addr,(Bit16u)val);break;
00344                 case 4:mem_writed(pt+addr,(Bit32u)val);break;
00345                 }
00346         }
00347         void SetPt(Bit16u seg) { pt=PhysMake(seg,0);}
00348         void SetPt(Bit16u seg,Bit16u off) { pt=PhysMake(seg,off);}
00349         void SetPt(RealPt addr) { pt=Real2Phys(addr);}
00350 protected:
00351         PhysPt pt;
00352 };
00353 
00354 class DOS_PSP :public MemStruct {
00355 public:
00356         DOS_PSP                                         (Bit16u segment)                { SetPt(segment);seg=segment;};
00357         void    MakeNew                         (Bit16u memSize);
00358         void    CopyFileTable           (DOS_PSP* srcpsp,bool createchildpsp);
00359         Bit16u  FindFreeFileEntry       (void);
00360         void    CloseFiles                      (void);
00361 
00362         void    SaveVectors                     (void);
00363         void    RestoreVectors          (void);
00364         void    SetSize                         (Bit16u size)                   { sSave(sPSP,next_seg,size);            };
00365         Bit16u  GetSize                         (void)                                  { return (Bit16u)sGet(sPSP,next_seg);           };
00366         void    SetEnvironment          (Bit16u envseg)                 { sSave(sPSP,environment,envseg);       };
00367         Bit16u  GetEnvironment          (void)                                  { return (Bit16u)sGet(sPSP,environment);        };
00368         Bit16u  GetSegment                      (void)                                  { return seg;                                           };
00369         void    SetFileHandle           (Bit16u index, Bit8u handle);
00370         Bit8u   GetFileHandle           (Bit16u index);
00371         void    SetParent                       (Bit16u parent)                 { sSave(sPSP,psp_parent,parent);        };
00372         Bit16u  GetParent                       (void)                                  { return (Bit16u)sGet(sPSP,psp_parent);         };
00373         void    SetStack                        (RealPt stackpt)                { sSave(sPSP,stack,stackpt);            };
00374         RealPt  GetStack                        (void)                                  { return sGet(sPSP,stack);                      };
00375         void    SetInt22                        (RealPt int22pt)                { sSave(sPSP,int_22,int22pt);           };
00376         RealPt  GetInt22                        (void)                                  { return sGet(sPSP,int_22);                     };
00377         void    SetFCB1                         (RealPt src);
00378         void    SetFCB2                         (RealPt src);
00379         void    SetCommandTail          (RealPt src);   
00380         bool    SetNumFiles                     (Bit16u fileNum);
00381         Bit16u  FindEntryByHandle       (Bit8u handle);
00382                         
00383 private:
00384         #ifdef _MSC_VER
00385         #pragma pack(1)
00386         #endif
00387         struct sPSP {
00388                 Bit8u   exit[2];                        /* CP/M-like exit poimt */
00389                 Bit16u  next_seg;                       /* Segment of first byte beyond memory allocated or program */
00390                 Bit8u   fill_1;                         /* single char fill */
00391                 Bit8u   far_call;                       /* far call opcode */
00392                 RealPt  cpm_entry;                      /* CPM Service Request address*/
00393                 RealPt  int_22;                         /* Terminate Address */
00394                 RealPt  int_23;                         /* Break Address */
00395                 RealPt  int_24;                         /* Critical Error Address */
00396                 Bit16u  psp_parent;                     /* Parent PSP Segment */
00397                 Bit8u   files[20];                      /* File Table - 0xff is unused */
00398                 Bit16u  environment;            /* Segment of evironment table */
00399                 RealPt  stack;                          /* SS:SP Save point for int 0x21 calls */
00400                 Bit16u  max_files;                      /* Maximum open files */
00401                 RealPt  file_table;                     /* Pointer to File Table PSP:0x18 */
00402                 RealPt  prev_psp;                       /* Pointer to previous PSP */
00403                 Bit8u interim_flag;
00404                 Bit8u truename_flag;
00405                 Bit16u nn_flags;
00406                 Bit16u dos_version;
00407                 Bit8u   fill_2[14];                     /* Lot's of unused stuff i can't care aboue */
00408                 Bit8u   service[3];                     /* INT 0x21 Service call int 0x21;retf; */
00409                 Bit8u   fill_3[9];                      /* This has some blocks with FCB info */
00410                 Bit8u   fcb1[16];                       /* first FCB */
00411                 Bit8u   fcb2[16];                       /* second FCB */
00412                 Bit8u   fill_4[4];                      /* unused */
00413                 CommandTail cmdtail;            
00414         } GCC_ATTRIBUTE(packed);
00415         #ifdef _MSC_VER
00416         #pragma pack()
00417         #endif
00418         Bit16u  seg;
00419 public:
00420         static  Bit16u rootpsp;
00421 };
00422 
00423 class DOS_ParamBlock:public MemStruct {
00424 public:
00425         DOS_ParamBlock(PhysPt addr) {pt=addr;}
00426         void Clear(void);
00427         void LoadData(void);
00428         void SaveData(void);            /* Save it as an exec block */
00429         #ifdef _MSC_VER
00430         #pragma pack (1)
00431         #endif
00432         struct sOverlay {
00433                 Bit16u loadseg;
00434                 Bit16u relocation;
00435         } GCC_ATTRIBUTE(packed);
00436         struct sExec {
00437                 Bit16u envseg;
00438                 RealPt cmdtail;
00439                 RealPt fcb1;
00440                 RealPt fcb2;
00441                 RealPt initsssp;
00442                 RealPt initcsip;
00443         }GCC_ATTRIBUTE(packed);
00444         #ifdef _MSC_VER
00445         #pragma pack()
00446         #endif
00447         sExec exec;
00448         sOverlay overlay;
00449 };
00450 
00451 class DOS_InfoBlock:public MemStruct {
00452 public:
00453         DOS_InfoBlock                   () {};
00454         void SetLocation(Bit16u  seg);
00455         void SetFirstMCB(Bit16u _first_mcb);
00456         void SetBuffers(Bit16u x,Bit16u y);
00457         void SetCurDirStruct(Bit32u _curdirstruct);
00458         void SetFCBTable(Bit32u _fcbtable);
00459         void SetDeviceChainStart(Bit32u _devchain);
00460         void SetDiskBufferHeadPt(Bit32u _dbheadpt);
00461         void SetStartOfUMBChain(Bit16u _umbstartseg);
00462         void SetUMBChainState(Bit8u _umbchaining);
00463         Bit16u  GetStartOfUMBChain(void);
00464         Bit8u   GetUMBChainState(void);
00465         RealPt  GetPointer(void);
00466         Bit32u GetDeviceChain(void);
00467 
00468         #ifdef _MSC_VER
00469         #pragma pack(1)
00470         #endif
00471         struct sDIB {           
00472                 Bit8u   unknown1[4];
00473                 Bit16u  magicWord;                      // -0x22 needs to be 1
00474                 Bit8u   unknown2[8];
00475                 Bit16u  regCXfrom5e;            // -0x18 CX from last int21/ah=5e
00476                 Bit16u  countLRUcache;          // -0x16 LRU counter for FCB caching
00477                 Bit16u  countLRUopens;          // -0x14 LRU counter for FCB openings
00478                 Bit8u   stuff[6];               // -0x12 some stuff, hopefully never used....
00479                 Bit16u  sharingCount;           // -0x0c sharing retry count
00480                 Bit16u  sharingDelay;           // -0x0a sharing retry delay
00481                 RealPt  diskBufPtr;             // -0x08 pointer to disk buffer
00482                 Bit16u  ptrCONinput;            // -0x04 pointer to con input
00483                 Bit16u  firstMCB;               // -0x02 first memory control block
00484                 RealPt  firstDPB;               //  0x00 first drive parameter block
00485                 RealPt  firstFileTable;         //  0x04 first system file table
00486                 RealPt  activeClock;            //  0x08 active clock device header
00487                 RealPt  activeCon;              //  0x0c active console device header
00488                 Bit16u  maxSectorLength;        //  0x10 maximum bytes per sector of any block device;
00489                 RealPt  diskInfoBuffer;         //  0x12 pointer to disk info buffer
00490                 RealPt  curDirStructure;        //  0x16 pointer to current array of directory structure
00491                 RealPt  fcbTable;               //  0x1a pointer to system FCB table
00492                 Bit16u  protFCBs;               //  0x1e protected fcbs
00493                 Bit8u   blockDevices;           //  0x20 installed block devices
00494                 Bit8u   lastdrive;              //  0x21 lastdrive
00495                 Bit32u  nulNextDriver;  //  0x22 NUL driver next pointer
00496                 Bit16u  nulAttributes;  //  0x26 NUL driver aattributes
00497         Bit16u  nulStrategy;    //  0x28 NUL driver strategy routine
00498         Bit16u  nulInterrupt;   //  0x2A NUL driver interrupt routine
00499                 Bit8u   nulString[8];   //  0x2c NUL driver name string
00500                 Bit8u   joindedDrives;          //  0x34 joined drives
00501                 Bit16u  specialCodeSeg;         //  0x35 special code segment
00502                 RealPt  setverPtr;              //  0x37 pointer to setver
00503                 Bit16u  a20FixOfs;              //  0x3b a20 fix routine offset
00504                 Bit16u  pspLastIfHMA;           //  0x3d psp of last program (if dos in hma)
00505                 Bit16u  buffers_x;              //  0x3f x in BUFFERS x,y
00506                 Bit16u  buffers_y;              //  0x41 y in BUFFERS x,y
00507                 Bit8u   bootDrive;              //  0x43 boot drive
00508                 Bit8u   useDwordMov;            //  0x44 use dword moves
00509                 Bit16u  extendedSize;           //  0x45 size of extended memory
00510                 Bit32u  diskBufferHeadPt;       //  0x47 pointer to least-recently used buffer header
00511                 Bit16u  dirtyDiskBuffers;       //  0x4b number of dirty disk buffers
00512                 Bit32u  lookaheadBufPt;         //  0x4d pointer to lookahead buffer
00513                 Bit16u  lookaheadBufNumber;             //  0x51 number of lookahead buffers
00514                 Bit8u   bufferLocation;                 //  0x53 workspace buffer location
00515                 Bit32u  workspaceBuffer;                //  0x54 pointer to workspace buffer
00516                 Bit8u   unknown3[11];                   //  0x58
00517                 Bit8u   chainingUMB;                    //  0x63 bit0: UMB chain linked to MCB chain
00518                 Bit16u  minMemForExec;                  //  0x64 minimum paragraphs needed for current program
00519                 Bit16u  startOfUMBChain;                //  0x66 segment of first UMB-MCB
00520                 Bit16u  memAllocScanStart;              //  0x68 start paragraph for memory allocation
00521         } GCC_ATTRIBUTE(packed);
00522         #ifdef _MSC_VER
00523         #pragma pack ()
00524         #endif
00525         Bit16u  seg;
00526 };
00527 
00528 class DOS_DTA:public MemStruct{
00529 public:
00530         DOS_DTA(RealPt addr) { SetPt(addr); }
00531 
00532         void SetupSearch(Bit8u _sdrive,Bit8u _sattr,char * _pattern);
00533         void SetResult(const char * _name,Bit32u _size,Bit16u _date,Bit16u _time,Bit8u _attr);
00534         
00535         Bit8u GetSearchDrive(void);
00536         void GetSearchParams(Bit8u & _sattr,char * _spattern);
00537         void GetResult(char * _name,Bit32u & _size,Bit16u & _date,Bit16u & _time,Bit8u & _attr);
00538 
00539         void    SetDirID(Bit16u entry)                  { sSave(sDTA,dirID,entry); };
00540         void    SetDirIDCluster(Bit16u entry)   { sSave(sDTA,dirCluster,entry); };
00541         Bit16u  GetDirID(void)                          { return (Bit16u)sGet(sDTA,dirID); };
00542         Bit16u  GetDirIDCluster(void)           { return (Bit16u)sGet(sDTA,dirCluster); };
00543 private:
00544         #ifdef _MSC_VER
00545         #pragma pack(1)
00546         #endif
00547         struct sDTA {
00548                 Bit8u sdrive;                                           /* The Drive the search is taking place */
00549                 Bit8u sname[8];                                         /* The Search pattern for the filename */               
00550                 Bit8u sext[3];                                          /* The Search pattern for the extenstion */
00551                 Bit8u sattr;                                            /* The Attributes that need to be found */
00552                 Bit16u dirID;                                           /* custom: dir-search ID for multiple searches at the same time */
00553                 Bit16u dirCluster;                                      /* custom (drive_fat only): cluster number for multiple searches at the same time */
00554                 Bit8u fill[4];
00555                 Bit8u attr;
00556                 Bit16u time;
00557                 Bit16u date;
00558                 Bit32u size;
00559                 char name[DOS_NAMELENGTH_ASCII];
00560         } GCC_ATTRIBUTE(packed);
00561         #ifdef _MSC_VER
00562         #pragma pack()
00563         #endif
00564 };
00565 
00566 class DOS_FCB: public MemStruct {
00567 public:
00568         DOS_FCB(Bit16u seg,Bit16u off,bool allow_extended=true);
00569         void Create(bool _extended);
00570         void SetName(Bit8u _drive,char * _fname,char * _ext);
00571         void SetSizeDateTime(Bit32u _size,Bit16u _date,Bit16u _time);
00572         void GetSizeDateTime(Bit32u & _size,Bit16u & _date,Bit16u & _time);
00573         void GetName(char * fillname);
00574         void FileOpen(Bit8u _fhandle);
00575         void FileClose(Bit8u & _fhandle);
00576         void GetRecord(Bit16u & _cur_block,Bit8u & _cur_rec);
00577         void SetRecord(Bit16u _cur_block,Bit8u _cur_rec);
00578         void GetSeqData(Bit8u & _fhandle,Bit16u & _rec_size);
00579         void GetRandom(Bit32u & _random);
00580         void SetRandom(Bit32u  _random);
00581         Bit8u GetDrive(void);
00582         bool Extended(void);
00583         void GetAttr(Bit8u & attr);
00584         void SetAttr(Bit8u attr);
00585         void SetResultAttr(Bit8u attr);
00586         bool Valid(void);
00587 private:
00588         bool extended;
00589         PhysPt real_pt;
00590         #ifdef _MSC_VER
00591         #pragma pack (1)
00592         #endif
00593         struct sFCB {
00594                 Bit8u drive;                    /* Drive number 0=default, 1=A, etc */
00595                 Bit8u filename[8];              /* Space padded name */
00596                 Bit8u ext[3];                   /* Space padded extension */
00597                 Bit16u cur_block;               /* Current Block */
00598                 Bit16u rec_size;                /* Logical record size */
00599                 Bit32u filesize;                /* File Size */
00600                 Bit16u date;
00601                 Bit16u time;
00602                 /* Reserved Block should be 8 bytes */
00603                 Bit8u sft_entries;
00604                 Bit8u share_attributes;
00605                 Bit8u extra_info;
00606                 Bit8u file_handle;
00607                 Bit8u reserved[4];
00608                 /* end */
00609                 Bit8u  cur_rec;                 /* Current record in current block */
00610                 Bit32u rndm;                    /* Current relative record number */
00611         } GCC_ATTRIBUTE(packed);
00612         #ifdef _MSC_VER
00613         #pragma pack ()
00614         #endif
00615 };
00616 
00617 class DOS_MCB : public MemStruct{
00618 public:
00619         DOS_MCB(Bit16u seg) { SetPt(seg); }
00620         void SetFileName(const char * const _name) { MEM_BlockWrite(pt+offsetof(sMCB,filename),_name,8); }
00621         void GetFileName(char * const _name) { MEM_BlockRead(pt+offsetof(sMCB,filename),_name,8);_name[8]=0;}
00622         void SetType(Bit8u _type) { sSave(sMCB,type,_type);}
00623         void SetSize(Bit16u _size) { sSave(sMCB,size,_size);}
00624         void SetPSPSeg(Bit16u _pspseg) { sSave(sMCB,psp_segment,_pspseg);}
00625         Bit8u GetType(void) { return (Bit8u)sGet(sMCB,type);}
00626         Bit16u GetSize(void) { return (Bit16u)sGet(sMCB,size);}
00627         Bit16u GetPSPSeg(void) { return (Bit16u)sGet(sMCB,psp_segment);}
00628 private:
00629         #ifdef _MSC_VER
00630         #pragma pack (1)
00631         #endif
00632         struct sMCB {
00633                 Bit8u type;
00634                 Bit16u psp_segment;
00635                 Bit16u size;    
00636                 Bit8u unused[3];
00637                 Bit8u filename[8];
00638         } GCC_ATTRIBUTE(packed);
00639         #ifdef _MSC_VER
00640         #pragma pack ()
00641         #endif
00642 };
00643 
00644 class DOS_SDA : public MemStruct {
00645 public:
00646         DOS_SDA(Bit16u _seg,Bit16u _offs) { SetPt(_seg,_offs); }
00647         void Init();   
00648         void SetDrive(Bit8u _drive) { sSave(sSDA,current_drive, _drive); }
00649         void SetDTA(Bit32u _dta) { sSave(sSDA,current_dta, _dta); }
00650         void SetPSP(Bit16u _psp) { sSave(sSDA,current_psp, _psp); }
00651         Bit8u GetDrive(void) { return (Bit8u)sGet(sSDA,current_drive); }
00652         Bit16u GetPSP(void) { return (Bit16u)sGet(sSDA,current_psp); }
00653         Bit32u GetDTA(void) { return (Bit32u)sGet(sSDA,current_dta); }
00654         
00655         
00656 private:
00657         #ifdef _MSC_VER
00658         #pragma pack (1)
00659         #endif
00660         struct sSDA {
00661                 Bit8u crit_error_flag;          /* 0x00 Critical Error Flag */
00662                 Bit8u inDOS_flag;               /* 0x01 InDOS flag (count of active INT 21 calls) */
00663                 Bit8u drive_crit_error;         /* 0x02 Drive on which current critical error occurred or FFh */
00664                 Bit8u locus_of_last_error;      /* 0x03 locus of last error */
00665                 Bit16u extended_error_code;     /* 0x04 extended error code of last error */
00666                 Bit8u suggested_action;         /* 0x06 suggested action for last error */
00667                 Bit8u error_class;              /* 0x07 class of last error*/
00668                 Bit32u last_error_pointer;      /* 0x08 ES:DI pointer for last error */
00669                 Bit32u current_dta;             /* 0x0C current DTA (Disk Transfer Address) */
00670                 Bit16u current_psp;             /* 0x10 current PSP */
00671                 Bit16u sp_int_23;               /* 0x12 stores SP across an INT 23 */
00672                 Bit16u return_code;             /* 0x14 return code from last process termination (zerod after reading with AH=4Dh) */
00673                 Bit8u current_drive;            /* 0x16 current drive */
00674                 Bit8u extended_break_flag;      /* 0x17 extended break flag */
00675                 Bit8u fill[2];                  /* 0x18 flag: code page switching || flag: copy of previous byte in case of INT 24 Abort*/
00676         } GCC_ATTRIBUTE(packed);
00677         #ifdef _MSC_VER
00678         #pragma pack()
00679         #endif
00680 };
00681 extern DOS_InfoBlock dos_infoblock;
00682 
00683 struct DOS_Block {
00684         DOS_Date date;
00685         bool hostdate;
00686         DOS_Version version;
00687         Bit16u firstMCB;
00688         Bit16u errorcode;
00689         Bit16u psp();//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetPSP();};
00690         void psp(Bit16u _seg);//{ DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetPSP(_seg);};
00691         Bit16u env;
00692         RealPt cpmentry;
00693         RealPt dta();//{return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDTA();};
00694         void dta(RealPt _dta);//{DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDTA(_dta);};
00695         Bit8u return_code,return_mode;
00696         
00697         Bit8u current_drive;
00698         bool verify;
00699         bool breakcheck;
00700         bool echo;          // if set to true dev_con::read will echo input 
00701         struct  {
00702                 RealPt mediaid;
00703                 RealPt tempdta;
00704                 RealPt tempdta_fcbdelete;
00705                 RealPt dbcs;
00706                 RealPt filenamechar;
00707                 RealPt collatingseq;
00708                 RealPt upcase;
00709                 Bit8u* country;//Will be copied to dos memory. resides in real mem
00710                 Bit16u dpb; //Fake Disk parameter system using only the first entry so the drive letter matches
00711         } tables;
00712         Bit16u loaded_codepage;
00713 };
00714 
00715 extern DOS_Block dos;
00716 
00717 static INLINE Bit8u RealHandle(Bit16u handle) {
00718         DOS_PSP psp(dos.psp()); 
00719         return psp.GetFileHandle(handle);
00720 }
00721 
00722 struct DOS_GetMemLog_Entry {
00723     Bit16u      segbase;
00724     Bit16u      pages;
00725     std::string who;
00726 };
00727 
00728 extern std::list<DOS_GetMemLog_Entry> DOS_GetMemLog;
00729 
00730 #endif