Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
291 lines (229 loc) · 7.79 KB

File metadata and controls

291 lines (229 loc) · 7.79 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2010, Tom Charlesworth, Michael Pohoreski
AppleWin 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.
AppleWin 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 AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Description: Disk Image
*
* Author: Various
*/
#include "StdAfx.h"
#include "DiskImage.h"
#include "DiskImageHelper.h"
static CDiskImageHelper sg_DiskImageHelper;
static CHardDiskImageHelper sg_HardDiskImageHelper;
//===========================================================================
// Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert()
ImageError_e ImageOpen( LPCTSTR pszImageFilename,
ImageInfo** ppImageInfo,
bool* pWriteProtected,
const bool bCreateIfNecessary,
std::string& strFilenameInZip,
const bool bExpectFloppy /*=true*/)
{
if (bExpectFloppy && sg_DiskImageHelper.GetWorkBuffer() == NULL)
return eIMAGE_ERROR_BAD_POINTER;
if (! (pszImageFilename && ppImageInfo && pWriteProtected))
return eIMAGE_ERROR_BAD_POINTER;
// CREATE A RECORD FOR THE FILE
*ppImageInfo = (ImageInfo*) VirtualAlloc(NULL, sizeof(ImageInfo), MEM_COMMIT, PAGE_READWRITE);
if (*ppImageInfo == NULL)
return eIMAGE_ERROR_BAD_POINTER;
ZeroMemory(*ppImageInfo, sizeof(ImageInfo));
ImageInfo* pImageInfo = *ppImageInfo;
pImageInfo->bWriteProtected = *pWriteProtected;
if (bExpectFloppy) pImageInfo->pImageHelper = &sg_DiskImageHelper;
else pImageInfo->pImageHelper = &sg_HardDiskImageHelper;
ImageError_e Err = pImageInfo->pImageHelper->Open(pszImageFilename, pImageInfo, bCreateIfNecessary, strFilenameInZip);
if (Err != eIMAGE_ERROR_NONE)
{
ImageClose(*ppImageInfo, true);
*ppImageInfo = NULL;
return Err;
}
if (pImageInfo->pImageType && pImageInfo->pImageType->GetType() == eImageHDV)
{
if (bExpectFloppy)
Err = eIMAGE_ERROR_UNSUPPORTED_HDV;
return Err;
}
// THE FILE MATCHES A KNOWN FORMAT
_ASSERT(bExpectFloppy);
if (!bExpectFloppy)
return eIMAGE_ERROR_UNSUPPORTED;
pImageInfo->uNumTracks = sg_DiskImageHelper.GetNumTracksInImage(pImageInfo->pImageType);
for (UINT uTrack = 0; uTrack < pImageInfo->uNumTracks; uTrack++)
pImageInfo->ValidTrack[uTrack] = (pImageInfo->uImageSize > 0) ? 1 : 0;
*pWriteProtected = pImageInfo->bWriteProtected;
return eIMAGE_ERROR_NONE;
}
//===========================================================================
void ImageClose(ImageInfo* const pImageInfo, const bool bOpenError /*=false*/)
{
bool bDeleteFile = false;
if (!bOpenError)
{
for (UINT uTrack = 0; uTrack < pImageInfo->uNumTracks; uTrack++)
{
if (!pImageInfo->ValidTrack[uTrack])
{
// TODO: Comment using info from this URL:
// http://groups.google.de/group/comp.emulators.apple2/msg/7a1b9317e7905152
bDeleteFile = true;
break;
}
}
}
pImageInfo->pImageHelper->Close(pImageInfo, bDeleteFile);
VirtualFree(pImageInfo, 0, MEM_RELEASE);
}
//===========================================================================
BOOL ImageBoot(ImageInfo* const pImageInfo)
{
BOOL result = 0;
if (pImageInfo->pImageType->AllowBoot())
result = pImageInfo->pImageType->Boot(pImageInfo);
if (result)
pImageInfo->bWriteProtected = 1;
return result;
}
//===========================================================================
void ImageDestroy(void)
{
VirtualFree(sg_DiskImageHelper.GetWorkBuffer(), 0, MEM_RELEASE);
sg_DiskImageHelper.SetWorkBuffer(NULL);
}
//===========================================================================
void ImageInitialize(void)
{
LPBYTE pBuffer = (LPBYTE) VirtualAlloc(NULL, TRACK_DENIBBLIZED_SIZE*2, MEM_COMMIT, PAGE_READWRITE);
sg_DiskImageHelper.SetWorkBuffer(pBuffer);
}
//===========================================================================
void ImageReadTrack( ImageInfo* const pImageInfo,
const int nTrack,
const int nQuarterTrack,
LPBYTE pTrackImageBuffer,
int* pNibbles,
bool enhanceDisk)
{
_ASSERT(nTrack >= 0);
if (nTrack < 0)
return;
if (pImageInfo->pImageType->AllowRW() && pImageInfo->ValidTrack[nTrack])
{
pImageInfo->pImageType->Read(pImageInfo, nTrack, nQuarterTrack, pTrackImageBuffer, pNibbles, enhanceDisk);
}
else
{
for (*pNibbles = 0; *pNibbles < NIBBLES_PER_TRACK; (*pNibbles)++)
pTrackImageBuffer[*pNibbles] = (BYTE)(rand() & 0xFF);
}
}
//===========================================================================
void ImageWriteTrack( ImageInfo* const pImageInfo,
const int nTrack,
const int nQuarterTrack,
LPBYTE pTrackImage,
const int nNibbles)
{
_ASSERT(nTrack >= 0);
if (nTrack < 0)
return;
if (pImageInfo->pImageType->AllowRW() && !pImageInfo->bWriteProtected)
{
pImageInfo->pImageType->Write(pImageInfo, nTrack, nQuarterTrack, pTrackImage, nNibbles);
pImageInfo->ValidTrack[nTrack] = 1;
}
}
//===========================================================================
bool ImageReadBlock( ImageInfo* const pImageInfo,
UINT nBlock,
LPBYTE pBlockBuffer)
{
bool bRes = false;
if (pImageInfo->pImageType->AllowRW())
bRes = pImageInfo->pImageType->Read(pImageInfo, nBlock, pBlockBuffer);
return bRes;
}
//===========================================================================
bool ImageWriteBlock( ImageInfo* const pImageInfo,
UINT nBlock,
LPBYTE pBlockBuffer)
{
bool bRes = false;
if (pImageInfo->pImageType->AllowRW() && !pImageInfo->bWriteProtected)
bRes = pImageInfo->pImageType->Write(pImageInfo, nBlock, pBlockBuffer);
return bRes;
}
//===========================================================================
int ImageGetNumTracks(ImageInfo* const pImageInfo)
{
return pImageInfo ? pImageInfo->uNumTracks : 0;
}
bool ImageIsWriteProtected(ImageInfo* const pImageInfo)
{
return pImageInfo ? pImageInfo->bWriteProtected : true;
}
bool ImageIsMultiFileZip(ImageInfo* const pImageInfo)
{
return pImageInfo ? (pImageInfo->uNumEntriesInZip > 1) : false;
}
const char* ImageGetPathname(ImageInfo* const pImageInfo)
{
static const char* szEmpty = "";
return pImageInfo ? pImageInfo->szFilename : szEmpty;
}
UINT ImageGetImageSize(ImageInfo* const pImageInfo)
{
return pImageInfo ? pImageInfo->uImageSize : 0;
}
void GetImageTitle(LPCTSTR pPathname, TCHAR* pImageName, TCHAR* pFullName)
{
TCHAR imagetitle[ MAX_DISK_FULL_NAME+1 ];
LPCTSTR startpos = pPathname;
// imagetitle = <FILENAME.EXT>
if (_tcsrchr(startpos, TEXT('\\')))
startpos = _tcsrchr(startpos, TEXT('\\'))+1;
_tcsncpy(imagetitle, startpos, MAX_DISK_FULL_NAME);
imagetitle[MAX_DISK_FULL_NAME] = 0;
// if imagetitle contains a lowercase char, then found=1 (why?)
BOOL found = 0;
int loop = 0;
while (imagetitle[loop] && !found)
{
if (IsCharLower(imagetitle[loop]))
found = 1;
else
loop++;
}
if ((!found) && (loop > 2))
CharLowerBuff(imagetitle+1, _tcslen(imagetitle+1));
// pFullName = <FILENAME.EXT>
_tcsncpy( pFullName, imagetitle, MAX_DISK_FULL_NAME );
pFullName[ MAX_DISK_FULL_NAME ] = 0;
if (imagetitle[0])
{
LPTSTR dot = imagetitle;
if (_tcsrchr(dot, TEXT('.')))
dot = _tcsrchr(dot, TEXT('.'));
if (dot > imagetitle)
*dot = 0;
}
// pImageName = <FILENAME> (ie. no extension)
_tcsncpy( pImageName, imagetitle, MAX_DISK_IMAGE_NAME );
pImageName[ MAX_DISK_IMAGE_NAME ] = 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.