| 1 | /* |
| 2 | * Copyright (C) 2002-2010 The DOSBox Team |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | /* $Id: dos_classes.cpp,v 1.58 2009-07-09 20:06:57 c2woody Exp $ */ |
| 20 | |
| 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
| 23 | #include "dosbox.h" |
| 24 | #include "mem.h" |
| 25 | #include "dos_inc.h" |
| 26 | #include "support.h" |
| 27 | |
| 28 | |
| 29 | void DOS_ParamBlock::Clear(void) { |
| 30 | memset(&exec,0,sizeof(exec)); |
| 31 | memset(&overlay,0,sizeof(overlay)); |
| 32 | } |
| 33 | |
| 34 | void DOS_ParamBlock::LoadData(void) { |
| 35 | exec.envseg=(Bit16u)sGet(sExec,envseg); |
| 36 | exec.cmdtail=sGet(sExec,cmdtail); |
| 37 | exec.fcb1=sGet(sExec,fcb1); |
| 38 | exec.fcb2=sGet(sExec,fcb2); |
| 39 | exec.initsssp=sGet(sExec,initsssp); |
| 40 | exec.initcsip=sGet(sExec,initcsip); |
| 41 | overlay.loadseg=(Bit16u)sGet(sOverlay,loadseg); |
| 42 | overlay.relocation=(Bit16u)sGet(sOverlay,relocation); |
| 43 | } |
| 44 | |
| 45 | void DOS_ParamBlock::SaveData(void) { |
| 46 | sSave(sExec,envseg,exec.envseg); |
| 47 | sSave(sExec,cmdtail,exec.cmdtail); |
| 48 | sSave(sExec,fcb1,exec.fcb1); |
| 49 | sSave(sExec,fcb2,exec.fcb2); |
| 50 | sSave(sExec,initsssp,exec.initsssp); |
| 51 | sSave(sExec,initcsip,exec.initcsip); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | void DOS_InfoBlock::SetLocation(Bit16u segment) { |
| 56 | seg = segment; |
| 57 | pt=PhysMake(seg,0); |
| 58 | /* Clear the initial Block */ |
| 59 | for(Bitu i=0;i<sizeof(sDIB);i++) mem_writeb(pt+i,0xff); |
| 60 | for(Bitu i=0;i<14;i++) mem_writeb(pt+i,0); |
| 61 | |
| 62 | sSave(sDIB,regCXfrom5e,(Bit16u)0); |
| 63 | sSave(sDIB,countLRUcache,(Bit16u)0); |
| 64 | sSave(sDIB,countLRUopens,(Bit16u)0); |
| 65 | |
| 66 | sSave(sDIB,protFCBs,(Bit16u)0); |
| 67 | sSave(sDIB,specialCodeSeg,(Bit16u)0); |
| 68 | sSave(sDIB,joindedDrives,(Bit8u)0); |
| 69 | sSave(sDIB,lastdrive,(Bit8u)0x01);//increase this if you add drives to cds-chain |
| 70 | |
| 71 | sSave(sDIB,diskInfoBuffer,RealMake(segment,offsetof(sDIB,diskBufferHeadPt))); |
| 72 | sSave(sDIB,setverPtr,(Bit32u)0); |
| 73 | |
| 74 | sSave(sDIB,a20FixOfs,(Bit16u)0); |
| 75 | sSave(sDIB,pspLastIfHMA,(Bit16u)0); |
| 76 | sSave(sDIB,blockDevices,(Bit8u)0); |
| 77 | |
| 78 | sSave(sDIB,bootDrive,(Bit8u)0); |
| 79 | sSave(sDIB,useDwordMov,(Bit8u)1); |
| 80 | sSave(sDIB,extendedSize,(Bit16u)(MEM_TotalPages()*4-1024)); |
| 81 | sSave(sDIB,magicWord,(Bit16u)0x0001); // dos5+ |
| 82 | |
| 83 | sSave(sDIB,sharingCount,(Bit16u)0); |
| 84 | sSave(sDIB,sharingDelay,(Bit16u)0); |
| 85 | sSave(sDIB,ptrCONinput,(Bit16u)0); // no unread input available |
| 86 | sSave(sDIB,maxSectorLength,(Bit16u)0x200); |
| 87 | |
| 88 | sSave(sDIB,dirtyDiskBuffers,(Bit16u)0); |
| 89 | sSave(sDIB,lookaheadBufPt,(Bit32u)0); |
| 90 | sSave(sDIB,lookaheadBufNumber,(Bit16u)0); |
| 91 | sSave(sDIB,bufferLocation,(Bit8u)0); // buffer in base memory, no workspace |
| 92 | sSave(sDIB,workspaceBuffer,(Bit32u)0); |
| 93 | |
| 94 | sSave(sDIB,minMemForExec,(Bit16u)0); |
| 95 | sSave(sDIB,memAllocScanStart,(Bit16u)DOS_MEM_START); |
| 96 | sSave(sDIB,startOfUMBChain,(Bit16u)0xffff); |
| 97 | sSave(sDIB,chainingUMB,(Bit8u)0); |
| 98 | |
| 99 | sSave(sDIB,nulNextDriver,(Bit32u)0xffffffff); |
| 100 | sSave(sDIB,nulAttributes,(Bit16u)0x8004); |
| 101 | sSave(sDIB,nulStrategy,(Bit32u)0x00000000); |
| 102 | sSave(sDIB,nulString[0],(Bit8u)0x4e); |
| 103 | sSave(sDIB,nulString[1],(Bit8u)0x55); |
| 104 | sSave(sDIB,nulString[2],(Bit8u)0x4c); |
| 105 | sSave(sDIB,nulString[3],(Bit8u)0x20); |
| 106 | sSave(sDIB,nulString[4],(Bit8u)0x20); |
| 107 | sSave(sDIB,nulString[5],(Bit8u)0x20); |
| 108 | sSave(sDIB,nulString[6],(Bit8u)0x20); |
| 109 | sSave(sDIB,nulString[7],(Bit8u)0x20); |
| 110 | |
| 111 | /* Create a fake SFT, so programs think there are 100 file handles */ |
| 112 | Bit16u sftOffset=offsetof(sDIB,firstFileTable)+0xa2; |
| 113 | sSave(sDIB,firstFileTable,RealMake(segment,sftOffset)); |
| 114 | real_writed(segment,sftOffset+0x00,RealMake(segment+0x26,0)); //Next File Table |
| 115 | real_writew(segment,sftOffset+0x04,100); //File Table supports 100 files |
| 116 | real_writed(segment+0x26,0x00,0xffffffff); //Last File Table |
| 117 | real_writew(segment+0x26,0x04,100); //File Table supports 100 files |
| 118 | } |
| 119 | |
| 120 | void DOS_InfoBlock::SetFirstMCB(Bit16u _firstmcb) { |
| 121 | sSave(sDIB,firstMCB,_firstmcb); //c2woody |
| 122 | } |
| 123 | |
| 124 | void DOS_InfoBlock::SetBuffers(Bit16u x,Bit16u y) { |
| 125 | sSave(sDIB,buffers_x,x); |
| 126 | sSave(sDIB,buffers_y,y); |
| 127 | } |
| 128 | |
| 129 | void DOS_InfoBlock::SetCurDirStruct(Bit32u _curdirstruct) { |
| 130 | sSave(sDIB,curDirStructure,_curdirstruct); |
| 131 | } |
| 132 | |
| 133 | void DOS_InfoBlock::SetFCBTable(Bit32u _fcbtable) { |
| 134 | sSave(sDIB,fcbTable,_fcbtable); |
| 135 | } |
| 136 | |
| 137 | void DOS_InfoBlock::SetDeviceChainStart(Bit32u _devchain) { |
| 138 | sSave(sDIB,nulNextDriver,_devchain); |
| 139 | } |
| 140 | |
| 141 | void DOS_InfoBlock::SetDiskBufferHeadPt(Bit32u _dbheadpt) { |
| 142 | sSave(sDIB,diskBufferHeadPt,_dbheadpt); |
| 143 | } |
| 144 | |
| 145 | Bit16u DOS_InfoBlock::GetStartOfUMBChain(void) { |
| 146 | return (Bit16u)sGet(sDIB,startOfUMBChain); |
| 147 | } |
| 148 | |
| 149 | void DOS_InfoBlock::SetStartOfUMBChain(Bit16u _umbstartseg) { |
| 150 | sSave(sDIB,startOfUMBChain,_umbstartseg); |
| 151 | } |
| 152 | |
| 153 | Bit8u DOS_InfoBlock::GetUMBChainState(void) { |
| 154 | return (Bit8u)sGet(sDIB,chainingUMB); |
| 155 | } |
| 156 | |
| 157 | void DOS_InfoBlock::SetUMBChainState(Bit8u _umbchaining) { |
| 158 | sSave(sDIB,chainingUMB,_umbchaining); |
| 159 | } |
| 160 | |
| 161 | RealPt DOS_InfoBlock::GetPointer(void) { |
| 162 | return RealMake(seg,offsetof(sDIB,firstDPB)); |
| 163 | } |
| 164 | |
| 165 | Bit32u DOS_InfoBlock::GetDeviceChain(void) { |
| 166 | return sGet(sDIB,nulNextDriver); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /* program Segment prefix */ |
| 171 | |
| 172 | Bit16u DOS_PSP::rootpsp = 0; |
| 173 | |
| 174 | void DOS_PSP::MakeNew(Bit16u mem_size) { |
| 175 | /* get previous */ |
| 176 | // DOS_PSP prevpsp(dos.psp()); |
| 177 | /* Clear it first */ |
| 178 | Bitu i; |
| 179 | for (i=0;i<sizeof(sPSP);i++) mem_writeb(pt+i,0); |
| 180 | // Set size |
| 181 | sSave(sPSP,next_seg,seg+mem_size); |
| 182 | /* far call opcode */ |
| 183 | sSave(sPSP,far_call,0xea); |
| 184 | // far call to interrupt 0x21 - faked for bill & ted |
| 185 | // lets hope nobody really uses this address |
| 186 | sSave(sPSP,cpm_entry,RealMake(0xDEAD,0xFFFF)); |
| 187 | /* Standard blocks,int 20 and int21 retf */ |
| 188 | sSave(sPSP,exit[0],0xcd); |
| 189 | sSave(sPSP,exit[1],0x20); |
| 190 | sSave(sPSP,service[0],0xcd); |
| 191 | sSave(sPSP,service[1],0x21); |
| 192 | sSave(sPSP,service[2],0xcb); |
| 193 | /* psp and psp-parent */ |
| 194 | sSave(sPSP,psp_parent,dos.psp()); |
| 195 | sSave(sPSP,prev_psp,0xffffffff); |
| 196 | sSave(sPSP,dos_version,0x0005); |
| 197 | /* terminate 22,break 23,crititcal error 24 address stored */ |
| 198 | SaveVectors(); |
| 199 | |
| 200 | /* FCBs are filled with 0 */ |
| 201 | // .... |
| 202 | /* Init file pointer and max_files */ |
| 203 | sSave(sPSP,file_table,RealMake(seg,offsetof(sPSP,files))); |
| 204 | sSave(sPSP,max_files,20); |
| 205 | for (Bit16u ct=0;ct<20;ct++) SetFileHandle(ct,0xff); |
| 206 | |
| 207 | /* User Stack pointer */ |
| 208 | // if (prevpsp.GetSegment()!=0) sSave(sPSP,stack,prevpsp.GetStack()); |
| 209 | |
| 210 | if (rootpsp==0) rootpsp = seg; |
| 211 | } |
| 212 | |
| 213 | Bit8u DOS_PSP::GetFileHandle(Bit16u index) { |
| 214 | if (index>=sGet(sPSP,max_files)) return 0xff; |
| 215 | PhysPt files=Real2Phys(sGet(sPSP,file_table)); |
| 216 | return mem_readb(files+index); |
| 217 | } |
| 218 | |
| 219 | void DOS_PSP::SetFileHandle(Bit16u index, Bit8u handle) { |
| 220 | if (index<sGet(sPSP,max_files)) { |
| 221 | PhysPt files=Real2Phys(sGet(sPSP,file_table)); |
| 222 | mem_writeb(files+index,handle); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | Bit16u DOS_PSP::FindFreeFileEntry(void) { |
| 227 | PhysPt files=Real2Phys(sGet(sPSP,file_table)); |
| 228 | for (Bit16u i=0;i<sGet(sPSP,max_files);i++) { |
| 229 | if (mem_readb(files+i)==0xff) return i; |
| 230 | } |
| 231 | return 0xff; |
| 232 | } |
| 233 | |
| 234 | Bit16u DOS_PSP::FindEntryByHandle(Bit8u handle) { |
| 235 | PhysPt files=Real2Phys(sGet(sPSP,file_table)); |
| 236 | for (Bit16u i=0;i<sGet(sPSP,max_files);i++) { |
| 237 | if (mem_readb(files+i)==handle) return i; |
| 238 | } |
| 239 | return 0xFF; |
| 240 | } |
| 241 | |
| 242 | void DOS_PSP::CopyFileTable(DOS_PSP* srcpsp,bool createchildpsp) { |
| 243 | /* Copy file table from calling process */ |
| 244 | for (Bit16u i=0;i<20;i++) { |
| 245 | Bit8u handle = srcpsp->GetFileHandle(i); |
| 246 | if(createchildpsp) |
| 247 | { //copy obeying not inherit flag.(but dont duplicate them) |
| 248 | bool allowCopy = true;//(handle==0) || ((handle>0) && (FindEntryByHandle(handle)==0xff)); |
| 249 | if((handle<DOS_FILES) && Files[handle] && !(Files[handle]->flags & DOS_NOT_INHERIT) && allowCopy) |
| 250 | { |
| 251 | Files[handle]->AddRef(); |
| 252 | SetFileHandle(i,handle); |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | SetFileHandle(i,0xff); |
| 257 | } |
| 258 | } |
| 259 | else |
| 260 | { //normal copy so don't mind the inheritance |
| 261 | SetFileHandle(i,handle); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | void DOS_PSP::CloseFiles(void) { |
| 267 | for (Bit16u i=0;i<sGet(sPSP,max_files);i++) { |
| 268 | DOS_CloseFile(i); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void DOS_PSP::SaveVectors(void) { |
| 273 | /* Save interrupt 22,23,24 */ |
| 274 | sSave(sPSP,int_22,RealGetVec(0x22)); |
| 275 | sSave(sPSP,int_23,RealGetVec(0x23)); |
| 276 | sSave(sPSP,int_24,RealGetVec(0x24)); |
| 277 | } |
| 278 | |
| 279 | void DOS_PSP::RestoreVectors(void) { |
| 280 | /* Restore interrupt 22,23,24 */ |
| 281 | RealSetVec(0x22,sGet(sPSP,int_22)); |
| 282 | RealSetVec(0x23,sGet(sPSP,int_23)); |
| 283 | RealSetVec(0x24,sGet(sPSP,int_24)); |
| 284 | } |
| 285 | |
| 286 | void DOS_PSP::SetCommandTail(RealPt src) { |
| 287 | if (src) { // valid source |
| 288 | MEM_BlockCopy(pt+offsetof(sPSP,cmdtail),Real2Phys(src),128); |
| 289 | } else { // empty |
| 290 | sSave(sPSP,cmdtail.count,0x00); |
| 291 | mem_writeb(pt+offsetof(sPSP,cmdtail.buffer),0x0d); |
| 292 | }; |
| 293 | } |
| 294 | |
| 295 | void DOS_PSP::SetFCB1(RealPt src) { |
| 296 | if (src) MEM_BlockCopy(PhysMake(seg,offsetof(sPSP,fcb1)),Real2Phys(src),16); |
| 297 | } |
| 298 | |
| 299 | void DOS_PSP::SetFCB2(RealPt src) { |
| 300 | if (src) MEM_BlockCopy(PhysMake(seg,offsetof(sPSP,fcb2)),Real2Phys(src),16); |
| 301 | } |
| 302 | |
| 303 | bool DOS_PSP::SetNumFiles(Bit16u fileNum) { |
| 304 | if (fileNum>20) { |
| 305 | // Allocate needed paragraphs |
| 306 | fileNum+=2; // Add a few more files for safety |
| 307 | Bit16u para = (fileNum/16)+((fileNum%16)>0); |
| 308 | RealPt data = RealMake(DOS_GetMemory(para),0); |
| 309 | sSave(sPSP,file_table,data); |
| 310 | sSave(sPSP,max_files,fileNum); |
| 311 | Bit16u i; |
| 312 | for (i=0; i<20; i++) SetFileHandle(i,(Bit8u)sGet(sPSP,files[i])); |
| 313 | for (i=20; i<fileNum; i++) SetFileHandle(i,0xFF); |
| 314 | } else { |
| 315 | sSave(sPSP,max_files,fileNum); |
| 316 | }; |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | void DOS_DTA::SetupSearch(Bit8u _sdrive,Bit8u _sattr,char * pattern) { |
| 322 | sSave(sDTA,sdrive,_sdrive); |
| 323 | sSave(sDTA,sattr,_sattr); |
| 324 | /* Fill with spaces */ |
| 325 | Bitu i; |
| 326 | for (i=0;i<11;i++) mem_writeb(pt+offsetof(sDTA,sname)+i,' '); |
| 327 | char * find_ext; |
| 328 | find_ext=strchr(pattern,'.'); |
| 329 | if (find_ext) { |
| 330 | Bitu size=(Bitu)(find_ext-pattern); |
| 331 | if (size>8) size=8; |
| 332 | MEM_BlockWrite(pt+offsetof(sDTA,sname),pattern,size); |
| 333 | find_ext++; |
| 334 | MEM_BlockWrite(pt+offsetof(sDTA,sext),find_ext,(strlen(find_ext)>3) ? 3 : (Bitu)strlen(find_ext)); |
| 335 | } else { |
| 336 | MEM_BlockWrite(pt+offsetof(sDTA,sname),pattern,(strlen(pattern) > 8) ? 8 : (Bitu)strlen(pattern)); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void DOS_DTA::SetResult(const char * _name,Bit32u _size,Bit16u _date,Bit16u _time,Bit8u _attr) { |
| 341 | MEM_BlockWrite(pt+offsetof(sDTA,name),(void *)_name,DOS_NAMELENGTH_ASCII); |
| 342 | sSave(sDTA,size,_size); |
| 343 | sSave(sDTA,date,_date); |
| 344 | sSave(sDTA,time,_time); |
| 345 | sSave(sDTA,attr,_attr); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | void DOS_DTA::GetResult(char * _name,Bit32u & _size,Bit16u & _date,Bit16u & _time,Bit8u & _attr) { |
| 350 | MEM_BlockRead(pt+offsetof(sDTA,name),_name,DOS_NAMELENGTH_ASCII); |
| 351 | _size=sGet(sDTA,size); |
| 352 | _date=(Bit16u)sGet(sDTA,date); |
| 353 | _time=(Bit16u)sGet(sDTA,time); |
| 354 | _attr=(Bit8u)sGet(sDTA,attr); |
| 355 | } |
| 356 | |
| 357 | Bit8u DOS_DTA::GetSearchDrive(void) { |
| 358 | return (Bit8u)sGet(sDTA,sdrive); |
| 359 | } |
| 360 | |
| 361 | void DOS_DTA::GetSearchParams(Bit8u & attr,char * pattern) { |
| 362 | attr=(Bit8u)sGet(sDTA,sattr); |
| 363 | char temp[11]; |
| 364 | MEM_BlockRead(pt+offsetof(sDTA,sname),temp,11); |
| 365 | memcpy(pattern,temp,8); |
| 366 | pattern[8]='.'; |
| 367 | memcpy(&pattern[9],&temp[8],3); |
| 368 | pattern[12]=0; |
| 369 | |
| 370 | } |
| 371 | |
| 372 | DOS_FCB::DOS_FCB(Bit16u seg,Bit16u off,bool allow_extended) { |
| 373 | SetPt(seg,off); |
| 374 | real_pt=pt; |
| 375 | extended=false; |
| 376 | if (allow_extended) { |
| 377 | if (sGet(sFCB,drive)==0xff) { |
| 378 | pt+=7; |
| 379 | extended=true; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | bool DOS_FCB::Extended(void) { |
| 385 | return extended; |
| 386 | } |
| 387 | |
| 388 | void DOS_FCB::Create(bool _extended) { |
| 389 | Bitu fill; |
| 390 | if (_extended) fill=36+7; |
| 391 | else fill=36; |
| 392 | Bitu i; |
| 393 | for (i=0;i<fill;i++) mem_writeb(real_pt+i,0); |
| 394 | pt=real_pt; |
| 395 | if (_extended) { |
| 396 | mem_writeb(real_pt,0xff); |
| 397 | pt+=7; |
| 398 | extended=true; |
| 399 | } else extended=false; |
| 400 | } |
| 401 | |
| 402 | void DOS_FCB::SetName(Bit8u _drive,char * _fname,char * _ext) { |
| 403 | sSave(sFCB,drive,_drive); |
| 404 | MEM_BlockWrite(pt+offsetof(sFCB,filename),_fname,8); |
| 405 | MEM_BlockWrite(pt+offsetof(sFCB,ext),_ext,3); |
| 406 | } |
| 407 | |
| 408 | void DOS_FCB::SetSizeDateTime(Bit32u _size,Bit16u _date,Bit16u _time) { |
| 409 | sSave(sFCB,filesize,_size); |
| 410 | sSave(sFCB,date,_date); |
| 411 | sSave(sFCB,time,_time); |
| 412 | } |
| 413 | |
| 414 | void DOS_FCB::GetSizeDateTime(Bit32u & _size,Bit16u & _date,Bit16u & _time) { |
| 415 | _size=sGet(sFCB,filesize); |
| 416 | _date=(Bit16u)sGet(sFCB,date); |
| 417 | _time=(Bit16u)sGet(sFCB,time); |
| 418 | } |
| 419 | |
| 420 | void DOS_FCB::GetRecord(Bit16u & _cur_block,Bit8u & _cur_rec) { |
| 421 | _cur_block=(Bit16u)sGet(sFCB,cur_block); |
| 422 | _cur_rec=(Bit8u)sGet(sFCB,cur_rec); |
| 423 | |
| 424 | } |
| 425 | |
| 426 | void DOS_FCB::SetRecord(Bit16u _cur_block,Bit8u _cur_rec) { |
| 427 | sSave(sFCB,cur_block,_cur_block); |
| 428 | sSave(sFCB,cur_rec,_cur_rec); |
| 429 | } |
| 430 | |
| 431 | void DOS_FCB::GetSeqData(Bit8u & _fhandle,Bit16u & _rec_size) { |
| 432 | _fhandle=(Bit8u)sGet(sFCB,file_handle); |
| 433 | _rec_size=(Bit16u)sGet(sFCB,rec_size); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | void DOS_FCB::GetRandom(Bit32u & _random) { |
| 438 | _random=sGet(sFCB,rndm); |
| 439 | } |
| 440 | |
| 441 | void DOS_FCB::SetRandom(Bit32u _random) { |
| 442 | sSave(sFCB,rndm,_random); |
| 443 | } |
| 444 | |
| 445 | void DOS_FCB::FileOpen(Bit8u _fhandle) { |
| 446 | sSave(sFCB,drive,GetDrive()+1); |
| 447 | sSave(sFCB,file_handle,_fhandle); |
| 448 | sSave(sFCB,cur_block,0); |
| 449 | sSave(sFCB,rec_size,128); |
| 450 | // sSave(sFCB,rndm,0); // breaks Jewels of darkness. |
| 451 | Bit8u temp = RealHandle(_fhandle); |
| 452 | Bit32u size = 0; |
| 453 | Files[temp]->Seek(&size,DOS_SEEK_END); |
| 454 | sSave(sFCB,filesize,size); |
| 455 | size = 0; |
| 456 | Files[temp]->Seek(&size,DOS_SEEK_SET); |
| 457 | sSave(sFCB,time,Files[temp]->time); |
| 458 | sSave(sFCB,date,Files[temp]->date); |
| 459 | } |
| 460 | |
| 461 | bool DOS_FCB::Valid() { |
| 462 | //Very simple check for Oubliette |
| 463 | if(sGet(sFCB,filename[0]) == 0 && sGet(sFCB,file_handle) == 0) return false; |
| 464 | return true; |
| 465 | } |
| 466 | |
| 467 | void DOS_FCB::FileClose(Bit8u & _fhandle) { |
| 468 | _fhandle=(Bit8u)sGet(sFCB,file_handle); |
| 469 | sSave(sFCB,file_handle,0xff); |
| 470 | } |
| 471 | |
| 472 | Bit8u DOS_FCB::GetDrive(void) { |
| 473 | Bit8u drive=(Bit8u)sGet(sFCB,drive); |
| 474 | if (!drive) return DOS_GetDefaultDrive(); |
| 475 | else return drive-1; |
| 476 | } |
| 477 | |
| 478 | void DOS_FCB::GetName(char * fillname) { |
| 479 | fillname[0]=GetDrive()+'A'; |
| 480 | fillname[1]=':'; |
| 481 | MEM_BlockRead(pt+offsetof(sFCB,filename),&fillname[2],8); |
| 482 | fillname[10]='.'; |
| 483 | MEM_BlockRead(pt+offsetof(sFCB,ext),&fillname[11],3); |
| 484 | fillname[14]=0; |
| 485 | } |
| 486 | |
| 487 | void DOS_FCB::GetAttr(Bit8u& attr) { |
| 488 | if(extended) attr=mem_readb(pt - 1); |
| 489 | } |
| 490 | |
| 491 | void DOS_FCB::SetAttr(Bit8u attr) { |
| 492 | if(extended) mem_writeb(pt - 1,attr); |
| 493 | } |
| 494 | |
| 495 | void DOS_SDA::Init() { |
| 496 | /* Clear */ |
| 497 | for(Bitu i=0;i<sizeof(sSDA);i++) mem_writeb(pt+i,0x00); |
| 498 | sSave(sSDA,drive_crit_error,0xff); |
| 499 | } |