/* * Copyright (C) 2002-2019 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include "dosbox.h" #include "mem.h" #include "dos_inc.h" #include "support.h" void DOS_ParamBlock::Clear(void) { memset(&exec,0,sizeof(exec)); memset(&overlay,0,sizeof(overlay)); } void DOS_ParamBlock::LoadData(void) { exec.envseg=(Bit16u)sGet(sExec,envseg); exec.cmdtail=sGet(sExec,cmdtail); exec.fcb1=sGet(sExec,fcb1); exec.fcb2=sGet(sExec,fcb2); exec.initsssp=sGet(sExec,initsssp); exec.initcsip=sGet(sExec,initcsip); overlay.loadseg=(Bit16u)sGet(sOverlay,loadseg); overlay.relocation=(Bit16u)sGet(sOverlay,relocation); } void DOS_ParamBlock::SaveData(void) { sSave(sExec,envseg,exec.envseg); sSave(sExec,cmdtail,exec.cmdtail); sSave(sExec,fcb1,exec.fcb1); sSave(sExec,fcb2,exec.fcb2); sSave(sExec,initsssp,exec.initsssp); sSave(sExec,initcsip,exec.initcsip); } void DOS_InfoBlock::SetLocation(Bit16u segment) { seg = segment; pt=PhysMake(seg,0); /* Clear the initial Block */ for(Bitu i=0;i=sGet(sPSP,max_files)) return 0xff; PhysPt files=Real2Phys(sGet(sPSP,file_table)); return mem_readb(files+index); } void DOS_PSP::SetFileHandle(Bit16u index, Bit8u handle) { if (indexGetFileHandle(i); if(createchildpsp) { //copy obeying not inherit flag.(but dont duplicate them) bool allowCopy = true;//(handle==0) || ((handle>0) && (FindEntryByHandle(handle)==0xff)); if((handleflags & DOS_NOT_INHERIT) && allowCopy) { Files[handle]->AddRef(); SetFileHandle(i,handle); } else { SetFileHandle(i,0xff); } } else { //normal copy so don't mind the inheritance SetFileHandle(i,handle); } } } void DOS_PSP::CloseFiles(void) { for (Bit16u i=0;i20) { // Allocate needed paragraphs fileNum+=2; // Add a few more files for safety Bit16u para = (fileNum/16)+((fileNum%16)>0); RealPt data = RealMake(DOS_GetMemory(para),0); sSave(sPSP,file_table,data); sSave(sPSP,max_files,fileNum); Bit16u i; for (i=0; i<20; i++) SetFileHandle(i,(Bit8u)sGet(sPSP,files[i])); for (i=20; i8) size=8; MEM_BlockWrite(pt+offsetof(sDTA,sname),pattern,size); find_ext++; MEM_BlockWrite(pt+offsetof(sDTA,sext),find_ext,(strlen(find_ext)>3) ? 3 : (Bitu)strlen(find_ext)); } else { MEM_BlockWrite(pt+offsetof(sDTA,sname),pattern,(strlen(pattern) > 8) ? 8 : (Bitu)strlen(pattern)); } } void DOS_DTA::SetResult(const char * _name,Bit32u _size,Bit16u _date,Bit16u _time,Bit8u _attr) { MEM_BlockWrite(pt+offsetof(sDTA,name),(void *)_name,strlen(_name)+1); sSave(sDTA,size,_size); sSave(sDTA,date,_date); sSave(sDTA,time,_time); sSave(sDTA,attr,_attr); } void DOS_DTA::GetResult(char * _name,Bit32u & _size,Bit16u & _date,Bit16u & _time,Bit8u & _attr) { MEM_BlockRead(pt+offsetof(sDTA,name),_name,DOS_NAMELENGTH_ASCII); _size=sGet(sDTA,size); _date=(Bit16u)sGet(sDTA,date); _time=(Bit16u)sGet(sDTA,time); _attr=(Bit8u)sGet(sDTA,attr); } Bit8u DOS_DTA::GetSearchDrive(void) { return (Bit8u)sGet(sDTA,sdrive); } void DOS_DTA::GetSearchParams(Bit8u & attr,char * pattern) { attr=(Bit8u)sGet(sDTA,sattr); char temp[11]; MEM_BlockRead(pt+offsetof(sDTA,sname),temp,11); memcpy(pattern,temp,8); pattern[8]='.'; memcpy(&pattern[9],&temp[8],3); pattern[12]=0; } DOS_FCB::DOS_FCB(Bit16u seg,Bit16u off,bool allow_extended) { SetPt(seg,off); real_pt=pt; extended=false; if (allow_extended) { if (sGet(sFCB,drive)==0xff) { pt+=7; extended=true; } } } bool DOS_FCB::Extended(void) { return extended; } void DOS_FCB::Create(bool _extended) { Bitu fill; if (_extended) fill=33+7; else fill=33; Bitu i; for (i=0;iSeek(&size,DOS_SEEK_END); sSave(sFCB,filesize,size); size = 0; Files[_fhandle]->Seek(&size,DOS_SEEK_SET); sSave(sFCB,time,Files[_fhandle]->time); sSave(sFCB,date,Files[_fhandle]->date); } bool DOS_FCB::Valid() { //Very simple check for Oubliette if(sGet(sFCB,filename[0]) == 0 && sGet(sFCB,file_handle) == 0) return false; return true; } void DOS_FCB::FileClose(Bit8u & _fhandle) { _fhandle=(Bit8u)sGet(sFCB,file_handle); sSave(sFCB,file_handle,0xff); } Bit8u DOS_FCB::GetDrive(void) { Bit8u drive=(Bit8u)sGet(sFCB,drive); if (!drive) return DOS_GetDefaultDrive(); else return drive-1; } void DOS_FCB::GetName(char * fillname) { fillname[0]=GetDrive()+'A'; fillname[1]=':'; MEM_BlockRead(pt+offsetof(sFCB,filename),&fillname[2],8); fillname[10]='.'; MEM_BlockRead(pt+offsetof(sFCB,ext),&fillname[11],3); fillname[14]=0; } void DOS_FCB::GetAttr(Bit8u& attr) { if(extended) attr=mem_readb(pt - 1); } void DOS_FCB::SetAttr(Bit8u attr) { if(extended) mem_writeb(pt - 1,attr); } void DOS_FCB::SetResult(Bit32u size,Bit16u date,Bit16u time,Bit8u attr) { mem_writed(pt + 0x1d,size); mem_writew(pt + 0x19,date); mem_writew(pt + 0x17,time); mem_writeb(pt + 0x0c,attr); } void DOS_SDA::Init() { /* Clear */ for(Bitu i=0;i