DOSBox-X
|
00001 /* 00002 * Copyright (C) 2002-2020 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 along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 00020 #include <string.h> 00021 #include "dosbox.h" 00022 #include "cdrom.h" 00023 00024 #if defined (OS2) 00025 #define INCL_DOSFILEMGR 00026 #define INCL_DOSERRORS 00027 #define INCL_DOSDEVICES 00028 #define INCL_DOSDEVIOCTL 00029 #include "os2.h" 00030 00031 // Ripped from linux/cdrom.h 00032 #define CD_FRAMESIZE_RAW 2352 00033 #define CD_FRAMESIZE 2048 00034 00035 CDROM_Interface_Ioctl::CDROM_Interface_Ioctl(void) : CDROM_Interface_SDL(){ 00036 strcpy(device_name, ""); 00037 } 00038 00039 bool CDROM_Interface_Ioctl::GetUPC(unsigned char& attr, char* upc){ 00040 HFILE cdrom_fd = 0; 00041 ULONG ulAction = 0; 00042 APIRET rc = DosOpen((unsigned char*)device_name, &cdrom_fd, &ulAction, 0L, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, 00043 OPEN_FLAGS_DASD | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 0L); 00044 if (rc != NO_ERROR) { 00045 return false; 00046 } 00047 char data[50]; 00048 ULONG len = sizeof(data); 00049 char sig[] = {'C', 'D', '0', '1'}; 00050 ULONG sigsize = 4; 00051 rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_GETUPC, sig, sigsize, &sigsize, 00052 data, len, &len); 00053 if (rc != NO_ERROR) { 00054 return false; 00055 } 00056 rc = DosClose(cdrom_fd); 00057 return rc == NO_ERROR; 00058 } 00059 00060 bool CDROM_Interface_Ioctl::ReadSectors(PhysPt buffer, bool raw, unsigned long sector, unsigned long num){ 00061 HFILE cdrom_fd = 0; 00062 ULONG ulAction = 0; 00063 APIRET rc = DosOpen((unsigned char*)device_name, &cdrom_fd, &ulAction, 0L, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, 00064 OPEN_FLAGS_DASD | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 0L); 00065 if (rc != NO_ERROR) { 00066 return false; 00067 } 00068 00069 Bitu buflen = raw ? num * CD_FRAMESIZE_RAW : num * CD_FRAMESIZE; 00070 Bit8u* buf = new Bit8u[buflen]; 00071 int ret = NO_ERROR; 00072 00073 if (raw) { 00074 struct paramseek { 00075 UCHAR sig[4]; 00076 UCHAR mode; 00077 ULONG sec; 00078 00079 paramseek(ULONG sector) 00080 { 00081 sig[0] = 'C'; sig[1] = 'D'; sig[2] = '0'; sig[3] = '1'; 00082 sec = sector; 00083 } 00084 } param_seek(sector); 00085 ULONG paramsize = sizeof (paramseek); 00086 rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_SEEK, ¶m_seek, paramsize, ¶msize, 00087 0, 0, 0); 00088 if (rc != NO_ERROR) { 00089 return false; 00090 } 00091 00092 struct paramread { 00093 UCHAR sig[4]; 00094 UCHAR mode; 00095 USHORT number; 00096 BYTE sec; 00097 BYTE reserved; 00098 BYTE interleave; 00099 00100 paramread(USHORT num) 00101 { 00102 sig[0] = 'C'; sig[1] = 'D'; sig[2] = '0'; sig[3] = '1'; 00103 mode = 0; number = num; 00104 sec = interleave = 0; 00105 } 00106 } param_read(num); 00107 paramsize = sizeof (paramread); 00108 ULONG len = buflen; 00109 rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_READLONG, ¶m_read, paramsize, ¶msize, 00110 buf, len, &len); 00111 if (rc != NO_ERROR) { 00112 return false; 00113 } 00114 } else { 00115 ULONG pos = 0; 00116 rc = DosSetFilePtr(cdrom_fd, sector * CD_FRAMESIZE, FILE_BEGIN, &pos); 00117 if (rc != NO_ERROR) { 00118 return false; 00119 } 00120 ULONG read = 0; 00121 rc = DosRead(cdrom_fd, buf, buflen, &read); 00122 if (rc != NO_ERROR || read != buflen) { 00123 return false; 00124 } 00125 } 00126 rc = DosClose(cdrom_fd); 00127 MEM_BlockWrite(buffer, buf, buflen); 00128 delete[] buf; 00129 00130 return (ret == NO_ERROR); 00131 } 00132 00133 bool CDROM_Interface_Ioctl::SetDevice(char* path, int forceCD) { 00134 bool success = CDROM_Interface_SDL::SetDevice(path, forceCD); 00135 00136 if (success) { 00137 char temp[3] = {0, 0, 0}; 00138 if (path[1] == ':') { 00139 temp[0] = path[0]; 00140 temp[1] = path[1]; 00141 temp[2] = 0; 00142 } 00143 strncpy(device_name, temp, 512); 00144 } else { 00145 strcpy(device_name, ""); 00146 success = false; 00147 } 00148 00149 return success; 00150 } 00151 00152 bool CDROM_Interface_Ioctl::ReadSectorsHost(void *buffer, bool raw, unsigned long sector, unsigned long num) 00153 { 00154 return false;/*TODO*/ 00155 }; 00156 00157 #endif