/
drives.cpp
274 lines (234 loc) · 7.85 KB
/
drives.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Copyright (C) 2002-2015 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dosbox.h"
#include "dos_system.h"
#include "drives.h"
#include "setup.h"
#include "mapper.h"
#include "support.h"
#include "control.h"
bool WildFileCmp(const char * file, const char * wild)
{
char file_name[9];
char file_ext[4];
char wild_name[9];
char wild_ext[4];
const char * find_ext;
Bitu r;
strcpy(file_name," ");
strcpy(file_ext," ");
strcpy(wild_name," ");
strcpy(wild_ext," ");
find_ext=strrchr(file,'.');
if (find_ext) {
Bitu size=(Bitu)(find_ext-file);
if (size>8) size=8;
memcpy(file_name,file,size);
find_ext++;
memcpy(file_ext,find_ext,(strlen(find_ext)>3) ? 3 : strlen(find_ext));
} else {
memcpy(file_name,file,(strlen(file) > 8) ? 8 : strlen(file));
}
upcase(file_name);upcase(file_ext);
find_ext=strrchr(wild,'.');
if (find_ext) {
Bitu size=(Bitu)(find_ext-wild);
if (size>8) size=8;
memcpy(wild_name,wild,size);
find_ext++;
memcpy(wild_ext,find_ext,(strlen(find_ext)>3) ? 3 : strlen(find_ext));
} else {
memcpy(wild_name,wild,(strlen(wild) > 8) ? 8 : strlen(wild));
}
upcase(wild_name);upcase(wild_ext);
/* Names are right do some checking */
r=0;
while (r<8) {
if (wild_name[r]=='*') goto checkext;
if (wild_name[r]!='?' && wild_name[r]!=file_name[r]) return false;
r++;
}
checkext:
r=0;
while (r<3) {
if (wild_ext[r]=='*') return true;
if (wild_ext[r]!='?' && wild_ext[r]!=file_ext[r]) return false;
r++;
}
return true;
}
void Set_Label(char const * const input, char * const output, bool cdrom) {
Bitu togo = 8;
Bitu vnamePos = 0;
Bitu labelPos = 0;
bool point = false;
//spacepadding the filenamepart to include spaces after the terminating zero is more closely to the specs. (not doing this now)
// HELLO\0' '' '
while (togo > 0) {
if (input[vnamePos]==0) break;
if (!point && (input[vnamePos]=='.')) { togo=4; point=true; }
//another mscdex quirk. Label is not always uppercase. (Daggerfall)
output[labelPos] = (cdrom?input[vnamePos]:toupper(input[vnamePos]));
labelPos++; vnamePos++;
togo--;
if ((togo==0) && !point) {
if (input[vnamePos]=='.') vnamePos++;
output[labelPos]='.'; labelPos++; point=true; togo=3;
}
};
output[labelPos]=0;
//Remove trailing dot. except when on cdrom and filename is exactly 8 (9 including the dot) letters. MSCDEX feature/bug (fifa96 cdrom detection)
if((labelPos > 0) && (output[labelPos-1] == '.') && !(cdrom && labelPos ==9))
output[labelPos-1] = 0;
}
DOS_Drive::DOS_Drive() {
nocachedir=false;
readonly=false;
curdir[0]=0;
info[0]=0;
}
const char * DOS_Drive::GetInfo(void) {
return info;
}
// static members variables
int DriveManager::currentDrive;
DriveManager::DriveInfo DriveManager::driveInfos[26];
void DriveManager::AppendDisk(int drive, DOS_Drive* disk) {
driveInfos[drive].disks.push_back(disk);
}
void DriveManager::InitializeDrive(int drive) {
currentDrive = drive;
DriveInfo& driveInfo = driveInfos[currentDrive];
if (driveInfo.disks.size() > 0) {
driveInfo.currentDisk = 0;
DOS_Drive* disk = driveInfo.disks[driveInfo.currentDisk];
Drives[currentDrive] = disk;
disk->Activate();
}
}
/*
void DriveManager::CycleDrive(bool pressed) {
if (!pressed) return;
// do one round through all drives or stop at the next drive with multiple disks
int oldDrive = currentDrive;
do {
currentDrive = (currentDrive + 1) % DOS_DRIVES;
int numDisks = driveInfos[currentDrive].disks.size();
if (numDisks > 1) break;
} while (currentDrive != oldDrive);
}
void DriveManager::CycleDisk(bool pressed) {
if (!pressed) return;
int numDisks = driveInfos[currentDrive].disks.size();
if (numDisks > 1) {
// cycle disk
int currentDisk = driveInfos[currentDrive].currentDisk;
DOS_Drive* oldDisk = driveInfos[currentDrive].disks[currentDisk];
currentDisk = (currentDisk + 1) % numDisks;
DOS_Drive* newDisk = driveInfos[currentDrive].disks[currentDisk];
driveInfos[currentDrive].currentDisk = currentDisk;
// copy working directory, acquire system resources and finally switch to next drive
strcpy(newDisk->curdir, oldDisk->curdir);
newDisk->Activate();
Drives[currentDrive] = newDisk;
}
}
*/
void DriveManager::CycleAllDisks(void) {
for (int idrive=0; idrive<2; idrive++) { /* Cycle all DISKS meaning A: and B: */
int numDisks = (int)driveInfos[idrive].disks.size();
if (numDisks > 1) {
// cycle disk
int currentDisk = driveInfos[idrive].currentDisk;
DOS_Drive* oldDisk = driveInfos[idrive].disks[currentDisk];
currentDisk = (currentDisk + 1) % numDisks;
DOS_Drive* newDisk = driveInfos[idrive].disks[currentDisk];
driveInfos[idrive].currentDisk = currentDisk;
// copy working directory, acquire system resources and finally switch to next drive
strcpy(newDisk->curdir, oldDisk->curdir);
newDisk->Activate();
Drives[idrive] = newDisk;
LOG_MSG("Drive %c: disk %d of %d now active", 'A'+idrive, currentDisk+1, numDisks);
}
}
}
void DriveManager::CycleAllCDs(void) {
for (int idrive=2; idrive<DOS_DRIVES; idrive++) { /* Cycle all CDs in C: D: ... Z: */
int numDisks = (int)driveInfos[idrive].disks.size();
if (numDisks > 1) {
// cycle disk
int currentDisk = driveInfos[idrive].currentDisk;
DOS_Drive* oldDisk = driveInfos[idrive].disks[currentDisk];
currentDisk = (currentDisk + 1) % numDisks;
DOS_Drive* newDisk = driveInfos[idrive].disks[currentDisk];
driveInfos[idrive].currentDisk = currentDisk;
// copy working directory, acquire system resources and finally switch to next drive
strcpy(newDisk->curdir, oldDisk->curdir);
newDisk->Activate();
Drives[idrive] = newDisk;
LOG_MSG("Drive %c: disk %d of %d now active", 'A'+idrive, currentDisk+1, numDisks);
}
}
}
int DriveManager::UnmountDrive(int drive) {
int result = 0;
// unmanaged drive
if (driveInfos[drive].disks.size() == 0) {
result = Drives[drive]->UnMount();
} else {
// managed drive
int currentDisk = driveInfos[drive].currentDisk;
result = driveInfos[drive].disks[currentDisk]->UnMount();
// only delete on success, current disk set to NULL because of UnMount
if (result == 0) {
driveInfos[drive].disks[currentDisk] = NULL;
for (int i = 0; i < (int)driveInfos[drive].disks.size(); i++) {
delete driveInfos[drive].disks[i];
}
driveInfos[drive].disks.clear();
}
}
return result;
}
bool drivemanager_init = false;
bool int13_extensions_enable = true;
void DriveManager::Init(Section* s) {
Section_prop * section=static_cast<Section_prop *>(s);
drivemanager_init = true;
int13_extensions_enable = section->Get_bool("int 13 extensions");
// setup driveInfos structure
currentDrive = 0;
for(int i = 0; i < DOS_DRIVES; i++) {
driveInfos[i].currentDisk = 0;
}
// MAPPER_AddHandler(&CycleDisk, MK_f3, MMOD1, "cycledisk", "Cycle Disk");
// MAPPER_AddHandler(&CycleDrive, MK_f3, MMOD2, "cycledrive", "Cycle Drv");
}
void DRIVES_Startup(Section *s) {
if (!drivemanager_init) {
LOG(LOG_MISC,LOG_DEBUG)("Initializing drive system");
DriveManager::Init(control->GetSection("dos"));
}
}
void DRIVES_Init() {
LOG(LOG_MISC,LOG_DEBUG)("Initializing OOS drives");
// TODO: DOS kernel exit, reset, guest booting handler
}
char * DOS_Drive::GetBaseDir(void) {
return info + 16;
}