2009-05-02 23:03:37 +02:00
|
|
|
/*
|
2009-05-03 00:28:34 +02:00
|
|
|
* Copyright (C) 2002-2007 The DOSBox Team
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* 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
|
2009-05-03 00:02:15 +02:00
|
|
|
* GNU General Public License for more details.
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
/* $Id: dos_devices.cpp,v 1.16 2007/01/13 08:35:49 qbix79 Exp $ */
|
2009-05-03 00:08:43 +02:00
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "dosbox.h"
|
|
|
|
#include "callback.h"
|
2009-05-02 23:43:00 +02:00
|
|
|
#include "regs.h"
|
2009-05-02 23:03:37 +02:00
|
|
|
#include "mem.h"
|
|
|
|
#include "bios.h"
|
|
|
|
#include "dos_inc.h"
|
|
|
|
#include "support.h"
|
2009-05-03 00:08:43 +02:00
|
|
|
#include "drives.h" //Wildcmp
|
2009-05-02 23:03:37 +02:00
|
|
|
/* Include all the devices */
|
|
|
|
|
|
|
|
#include "dev_con.h"
|
|
|
|
|
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
DOS_Device * Devices[DOS_DEVICES];
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
class device_NUL : public DOS_Device {
|
|
|
|
public:
|
2009-05-03 00:08:43 +02:00
|
|
|
device_NUL() { SetName("NUL"); };
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool Read(Bit8u * data,Bit16u * size) {
|
2009-05-03 00:02:15 +02:00
|
|
|
for(Bitu i = 0; i < *size;i++)
|
|
|
|
data[i]=0;
|
2009-05-03 00:28:34 +02:00
|
|
|
LOG(LOG_IOCTL,LOG_NORMAL)("%s:READ",GetName());
|
2009-05-03 00:02:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool Write(Bit8u * data,Bit16u * size) {
|
|
|
|
LOG(LOG_IOCTL,LOG_NORMAL)("%s:WRITE",GetName());
|
2009-05-03 00:02:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool Seek(Bit32u * pos,Bit32u type) {
|
|
|
|
LOG(LOG_IOCTL,LOG_NORMAL)("%s:SEEK",GetName());
|
2009-05-03 00:02:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool Close() { return true; }
|
|
|
|
virtual Bit16u GetInformation(void) { return 0x8084; }
|
|
|
|
virtual bool ReadFromControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode){return false;}
|
|
|
|
virtual bool WriteToControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode){return false;}
|
|
|
|
};
|
|
|
|
|
|
|
|
class device_LPT1 : public device_NUL {
|
|
|
|
public:
|
|
|
|
device_LPT1() { SetName("LPT1");}
|
|
|
|
Bit16u GetInformation(void) { return 0x80A0; }
|
2009-05-03 00:02:15 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
bool DOS_Device::ReadFromControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode) {
|
|
|
|
return Devices[devnum]->ReadFromControlChannel(bufptr,size,retcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DOS_Device::WriteToControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode) {
|
|
|
|
return Devices[devnum]->WriteToControlChannel(bufptr,size,retcode);
|
|
|
|
}
|
|
|
|
|
2009-05-03 00:08:43 +02:00
|
|
|
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) + 1];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) + 1];strcpy(name,orig.name);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
Bit8u DOS_FindDevice(char * name) {
|
2009-05-03 00:08:43 +02:00
|
|
|
/* should only check for the names before the dot and spacepadded */
|
2009-05-03 00:28:34 +02:00
|
|
|
// STDAUX is alias for COM1
|
|
|
|
// A bit of a hack, but no application will probably use stdaux to determine wether a directory exists
|
|
|
|
if (strcasecmp(name, "STDAUX") == 0) name = "COM1";
|
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
char temp[CROSS_LEN];//TODO
|
2009-05-03 00:08:43 +02:00
|
|
|
if(!name || !(*name)) return DOS_DEVICES;
|
|
|
|
strcpy(temp,name);
|
|
|
|
char* dot= strrchr(temp,'.');
|
2009-05-03 00:18:08 +02:00
|
|
|
if(dot && *dot) *dot=0; //no ext checking
|
2009-05-03 00:08:43 +02:00
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
char* leading = strrchr(temp,'\\');
|
|
|
|
if(leading) {
|
|
|
|
*leading = 0;
|
|
|
|
Bit8u drive;char fulldir[DOS_PATHLENGTH];
|
|
|
|
if (!DOS_MakeName(temp,fulldir,&drive)) return DOS_DEVICES;
|
|
|
|
if(!Drives[drive]->TestDir(fulldir)) return DOS_DEVICES;
|
|
|
|
*leading='\\';
|
|
|
|
}
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
/* loop through devices */
|
2009-05-03 00:18:08 +02:00
|
|
|
for(Bit8u index = 0;index < DOS_DEVICES;index++) {
|
2009-05-03 00:08:43 +02:00
|
|
|
if (Devices[index]) {
|
|
|
|
if (WildFileCmp(temp,Devices[index]->name)) return index;
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-03 00:08:43 +02:00
|
|
|
return DOS_DEVICES;
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DOS_AddDevice(DOS_Device * adddev) {
|
2009-05-03 00:18:08 +02:00
|
|
|
//Caller creates the device. We store a pointer to it
|
2009-05-02 23:03:37 +02:00
|
|
|
//TODO Give the Device a real handler in low memory that responds to calls
|
2009-05-03 00:18:08 +02:00
|
|
|
for(Bitu i = 0; i < DOS_DEVICES;i++) {
|
|
|
|
if(!Devices[i]){
|
|
|
|
Devices[i] = adddev;
|
|
|
|
Devices[i]->SetDeviceNumber(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
E_Exit("DOS:Too many devices added");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DOS_DelDevice(DOS_Device * dev) {
|
|
|
|
// We will destroy the device if we find it in our list.
|
|
|
|
// TODO:The file table is not checked to see the device is opened somewhere!
|
|
|
|
for (Bitu i = 0; i <DOS_DEVICES;i++) {
|
|
|
|
if(Devices[i] && !strcasecmp(Devices[i]->name,dev->name)){
|
|
|
|
delete Devices[i];
|
|
|
|
Devices[i] = 0;
|
|
|
|
return;
|
|
|
|
}
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DOS_SetupDevices(void) {
|
|
|
|
DOS_Device * newdev;
|
|
|
|
newdev=new device_CON();
|
|
|
|
DOS_AddDevice(newdev);
|
2009-05-03 00:08:43 +02:00
|
|
|
DOS_Device * newdev2;
|
2009-05-03 00:02:15 +02:00
|
|
|
newdev2=new device_NUL();
|
|
|
|
DOS_AddDevice(newdev2);
|
2009-05-03 00:28:34 +02:00
|
|
|
DOS_Device * newdev3;
|
|
|
|
newdev3=new device_LPT1();
|
|
|
|
DOS_AddDevice(newdev3);
|
2009-05-02 23:03:37 +02:00
|
|
|
}
|