dosbox-wii/src/dos/dos_ioctl.cpp

131 lines
4.0 KiB
C++
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-02 23:35:44 +02:00
* Copyright (C) 2002-2003 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
* GNU Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2009-05-02 23:43:00 +02:00
/* $Id: dos_ioctl.cpp,v 1.16 2003/10/14 08:38:35 qbix79 Exp $ */
2009-05-02 23:03:37 +02:00
#include <string.h>
#include "dosbox.h"
#include "callback.h"
#include "mem.h"
2009-05-02 23:43:00 +02:00
#include "regs.h"
2009-05-02 23:03:37 +02:00
#include "dos_inc.h"
2009-05-02 23:20:05 +02:00
bool DOS_IOCTL(void) {
Bitu handle;Bit8u drive;
if (reg_al<8) { /* call 0-7 use a file handle */
handle=RealHandle(reg_bx);
if (handle>=DOS_FILES) {
DOS_SetError(DOSERR_INVALID_HANDLE);
return false;
}
if (!Files[handle]) {
DOS_SetError(DOSERR_INVALID_HANDLE);
return false;
}
}
2009-05-02 23:03:37 +02:00
switch(reg_al) {
case 0x00: /* Get Device Information */
reg_dx=Files[handle]->GetInformation();
return true;
2009-05-02 23:43:00 +02:00
case 0x06: /* Get Input Status */
if (Files[handle]->GetInformation() & 0x8000) { //Check for device
reg_al=(Files[handle]->GetInformation() & 0x40) ? 0x0 : 0xff;
} else { // FILE
Bit32u oldlocation=0;
Files[handle]->Seek(&oldlocation, DOS_SEEK_CUR);
Bit32u endlocation=0;
Files[handle]->Seek(&endlocation, DOS_SEEK_END);
if(oldlocation < endlocation){//Still data available
reg_al=0xff;
} else
{
reg_al=0x0; //EOF or beyond
}
Files[handle]->Seek(&oldlocation, DOS_SEEK_SET); //restore filelocation
LOG(LOG_IOCTL,LOG_NORMAL)("06:Used Get Input Status on regualar file with handle %d",handle);
}
return true;
2009-05-02 23:03:37 +02:00
case 0x07: /* Get Output Status */
2009-05-02 23:43:00 +02:00
LOG(LOG_IOCTL,LOG_NORMAL)("07:Fakes output status is ready for handle %d",handle);
2009-05-02 23:03:37 +02:00
reg_al=0xff;
return true;
2009-05-02 23:20:05 +02:00
case 0x08: /* Check if block device removable */
drive=reg_bl;if (!drive) drive=dos.current_drive;else drive--;
if (Drives[drive]) {
if (drive<2) reg_ax=0; /* Drive a,b are removable if mounted */
else reg_ax=1;
return true;
} else {
DOS_SetError(DOSERR_INVALID_DRIVE);
return false;
2009-05-02 23:12:18 +02:00
}
2009-05-02 23:43:00 +02:00
case 0x09: /* Check if block device remote */
drive=reg_bl;if (!drive) drive=dos.current_drive;else drive--;
if (Drives[drive]) {
reg_dx=0;
//TODO Cdrom drives are remote
//TODO Set bit 9 on drives that don't support direct I/O
return true;
} else {
DOS_SetError(DOSERR_INVALID_DRIVE);
return false;
}
2009-05-02 23:20:05 +02:00
case 0x0D: /* Generic block device request */
{
PhysPt ptr = SegPhys(ds)+reg_dx;
drive=reg_bl;if (!drive) drive=dos.current_drive;else drive--;
switch (reg_cl) {
case 0x60: /* Get Device parameters */
mem_writeb(ptr ,0x03); // special function
mem_writeb(ptr+1,(drive>=2)?0x05:0x14); // fixed disc(5), 1.44 floppy(14)
mem_writew(ptr+2,drive>=2); // nonremovable ?
mem_writew(ptr+4,0x0000); // num of cylinders
mem_writeb(ptr+6,0x00); // media type (00=other type)
break;
default :
2009-05-02 23:43:00 +02:00
LOG(LOG_IOCTL,LOG_ERROR)("DOS:IOCTL Call 0D:%2X Drive %2X unhandled",reg_cl,drive);
2009-05-02 23:20:05 +02:00
return false;
}
return true;
}
case 0xE: /* Get Logical Drive Map */
drive=reg_bl;if (!drive) drive=dos.current_drive;else drive--;
if (Drives[drive]) {
reg_al=0; /* Only 1 logical drive assigned */
return true;
} else {
DOS_SetError(DOSERR_INVALID_DRIVE);
return false;
2009-05-02 23:12:18 +02:00
}
2009-05-02 23:20:05 +02:00
break;
2009-05-02 23:03:37 +02:00
default:
2009-05-02 23:43:00 +02:00
LOG(LOG_DOSMISC,LOG_ERROR)("DOS:IOCTL Call %2X unhandled",reg_al);
2009-05-02 23:03:37 +02:00
return false;
};
return false;
};
bool DOS_GetSTDINStatus(void) {
Bit32u handle=RealHandle(STDIN);
2009-05-02 23:27:47 +02:00
if (handle==0xFF) return false;
if (Files[handle] && (Files[handle]->GetInformation() & 64)) return false;
2009-05-02 23:03:37 +02:00
return true;
};