| 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: cdrom_ioctl_os2.cpp,v 1.4 2009-05-27 09:15:41 qbix79 Exp $ */ |
| 20 | |
| 21 | #include <string.h> |
| 22 | #include "dosbox.h" |
| 23 | #include "cdrom.h" |
| 24 | |
| 25 | #if defined (OS2) |
| 26 | #define INCL_DOSFILEMGR |
| 27 | #define INCL_DOSERRORS |
| 28 | #define INCL_DOSDEVICES |
| 29 | #define INCL_DOSDEVIOCTL |
| 30 | #include "os2.h" |
| 31 | |
| 32 | // Ripped from linux/cdrom.h |
| 33 | #define CD_FRAMESIZE_RAW 2352 |
| 34 | #define CD_FRAMESIZE 2048 |
| 35 | |
| 36 | CDROM_Interface_Ioctl::CDROM_Interface_Ioctl(void) : CDROM_Interface_SDL(){ |
| 37 | strcpy(device_name, ""); |
| 38 | } |
| 39 | |
| 40 | bool CDROM_Interface_Ioctl::GetUPC(unsigned char& attr, char* upc){ |
| 41 | HFILE cdrom_fd = 0; |
| 42 | ULONG ulAction = 0; |
| 43 | APIRET rc = DosOpen((unsigned char*)device_name, &cdrom_fd, &ulAction, 0L, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, |
| 44 | OPEN_FLAGS_DASD | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 0L); |
| 45 | if (rc != NO_ERROR) { |
| 46 | return false; |
| 47 | } |
| 48 | char data[50]; |
| 49 | ULONG len = sizeof(data); |
| 50 | char sig[] = {'C', 'D', '0', '1'}; |
| 51 | ULONG sigsize = 4; |
| 52 | rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_GETUPC, sig, sigsize, &sigsize, |
| 53 | data, len, &len); |
| 54 | if (rc != NO_ERROR) { |
| 55 | return false; |
| 56 | } |
| 57 | rc = DosClose(cdrom_fd); |
| 58 | return rc == NO_ERROR; |
| 59 | } |
| 60 | |
| 61 | bool CDROM_Interface_Ioctl::ReadSectors(PhysPt buffer, bool raw, unsigned long sector, unsigned long num){ |
| 62 | HFILE cdrom_fd = 0; |
| 63 | ULONG ulAction = 0; |
| 64 | APIRET rc = DosOpen((unsigned char*)device_name, &cdrom_fd, &ulAction, 0L, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, |
| 65 | OPEN_FLAGS_DASD | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 0L); |
| 66 | if (rc != NO_ERROR) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | Bitu buflen = raw ? num * CD_FRAMESIZE_RAW : num * CD_FRAMESIZE; |
| 71 | Bit8u* buf = new Bit8u[buflen]; |
| 72 | int ret = NO_ERROR; |
| 73 | |
| 74 | if (raw) { |
| 75 | struct paramseek { |
| 76 | UCHAR sig[4]; |
| 77 | UCHAR mode; |
| 78 | ULONG sec; |
| 79 | |
| 80 | paramseek(ULONG sector) |
| 81 | { |
| 82 | sig[0] = 'C'; sig[1] = 'D'; sig[2] = '0'; sig[3] = '1'; |
| 83 | sec = sector; |
| 84 | } |
| 85 | } param_seek(sector); |
| 86 | ULONG paramsize = sizeof (paramseek); |
| 87 | rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_SEEK, ¶m_seek, paramsize, ¶msize, |
| 88 | 0, 0, 0); |
| 89 | if (rc != NO_ERROR) { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | struct paramread { |
| 94 | UCHAR sig[4]; |
| 95 | UCHAR mode; |
| 96 | USHORT number; |
| 97 | BYTE sec; |
| 98 | BYTE reserved; |
| 99 | BYTE interleave; |
| 100 | |
| 101 | paramread(USHORT num) |
| 102 | { |
| 103 | sig[0] = 'C'; sig[1] = 'D'; sig[2] = '0'; sig[3] = '1'; |
| 104 | mode = 0; number = num; |
| 105 | sec = interleave = 0; |
| 106 | } |
| 107 | } param_read(num); |
| 108 | paramsize = sizeof (paramread); |
| 109 | ULONG len = buflen; |
| 110 | rc = DosDevIOCtl(cdrom_fd, IOCTL_CDROMDISK, CDROMDISK_READLONG, ¶m_read, paramsize, ¶msize, |
| 111 | buf, len, &len); |
| 112 | if (rc != NO_ERROR) { |
| 113 | return false; |
| 114 | } |
| 115 | } else { |
| 116 | ULONG pos = 0; |
| 117 | rc = DosSetFilePtr(cdrom_fd, sector * CD_FRAMESIZE, FILE_BEGIN, &pos); |
| 118 | if (rc != NO_ERROR) { |
| 119 | return false; |
| 120 | } |
| 121 | ULONG read = 0; |
| 122 | rc = DosRead(cdrom_fd, buf, buflen, &read); |
| 123 | if (rc != NO_ERROR || read != buflen) { |
| 124 | return false; |
| 125 | } |
| 126 | } |
| 127 | rc = DosClose(cdrom_fd); |
| 128 | MEM_BlockWrite(buffer, buf, buflen); |
| 129 | delete[] buf; |
| 130 | |
| 131 | return (ret == NO_ERROR); |
| 132 | } |
| 133 | |
| 134 | bool CDROM_Interface_Ioctl::SetDevice(char* path, int forceCD) { |
| 135 | bool success = CDROM_Interface_SDL::SetDevice(path, forceCD); |
| 136 | |
| 137 | if (success) { |
| 138 | char temp[3] = {0, 0, 0}; |
| 139 | if (path[1] == ':') { |
| 140 | temp[0] = path[0]; |
| 141 | temp[1] = path[1]; |
| 142 | temp[2] = 0; |
| 143 | } |
| 144 | strncpy(device_name, temp, 512); |
| 145 | } else { |
| 146 | strcpy(device_name, ""); |
| 147 | success = false; |
| 148 | } |
| 149 | |
| 150 | return success; |
| 151 | } |
| 152 | |
| 153 | #endif |