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0x03 ,0xad ,0x78 ,
41
+ 0x08 ,0x8d ,0x0b ,0x03 ,0x20 ,0x59 ,0xe4 ,0xad ,0x03 ,0x03 ,0xc9 ,0x02 ,0xb0 ,0x22 ,0xa0 ,0x00 ,0x8c ,0x79 ,0x08 ,0xb9 ,0x80 ,0x08 ,0xaa ,0xad ,
42
+ 0x09 ,0x07 ,0xd0 ,0x0b ,0xad ,0x0a ,0x07 ,0xd0 ,0x03 ,0xce ,0x0b ,0x07 ,0xce ,0x0a ,0x07 ,0xce ,0x09 ,0x07 ,0xee ,0x79 ,0x08 ,0x8a ,0x18 ,0x60 ,
43
+ 0xa0 ,0x01 ,0x8c ,0x76 ,0x08 ,0x38 ,0x60 ,0xa0 ,0x01 ,0x8c ,0x7a ,0x08 ,0x38 ,0x60 ,0x00 ,0x03 ,0x00 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
44
+ };
45
+ #endif
46
+
26
47
DiskImage::DiskImage () {
27
48
m_fileRef = NULL ;
28
49
}
@@ -56,6 +77,11 @@ SectorPacket* DiskImage::getSectorData(unsigned long sector) {
56
77
m_sectorBuffer.error = false ;
57
78
m_sectorBuffer.validStatusFrame = false ;
58
79
80
+ // delay if necessary
81
+ if (m_sectorReadDelay) {
82
+ delay (m_sectorReadDelay);
83
+ }
84
+
59
85
// seek to proper offset in file
60
86
if (m_type == TYPE_PRO) {
61
87
// if this is a PRO image, we seek based on the sector number + the sector header size (omitting the header)
@@ -80,6 +106,18 @@ SectorPacket* DiskImage::getSectorData(unsigned long sector) {
80
106
}
81
107
}
82
108
m_phantomFlip = !m_phantomFlip; // TODO: do bad sectors cause this to flip?
109
+ #ifdef XEX_IMAGES
110
+ } else if (m_type == TYPE_XEX) {
111
+ if (sector < 4 ) {
112
+ unsigned long ix = (sector - 1 ) * m_sectorSize;
113
+ for (int i=0 ; i < m_sectorSize; i++) {
114
+ m_sectorBuffer.data [i] = KBOOT_LOADER[ix+i];
115
+ }
116
+ return &m_sectorBuffer;
117
+ } else {
118
+ m_fileRef->seekSet ((sector - 4 ) * m_sectorSize);
119
+ }
120
+ #endif
83
121
#ifdef ATX_IMAGES
84
122
} else if (m_type == TYPE_ATX) {
85
123
int ix = -1 ;
@@ -120,11 +158,6 @@ SectorPacket* DiskImage::getSectorData(unsigned long sector) {
120
158
m_fileRef->seekSet (m_headerSize + ((sector - 1 ) * m_sectorSize));
121
159
}
122
160
123
- // delay if necessary
124
- if (m_sectorReadDelay) {
125
- delay (m_sectorReadDelay);
126
- }
127
-
128
161
// read sector data into buffer
129
162
for (int i=0 ; i < m_sectorSize; i++) {
130
163
m_sectorBuffer.data [i] = (byte)m_fileRef->read ();
@@ -340,11 +373,12 @@ boolean DiskImage::loadFile(SdFile *file) {
340
373
}
341
374
#endif
342
375
343
- // check if it's an XFD
344
- // (since an XFD is just a raw data dump, we can only determine this by file name and size)
345
376
file->getFilename ((char *)&filename);
346
377
int len = strlen (filename);
347
378
char *extension = filename + len - 4 ;
379
+
380
+ // check if it's an XFD
381
+ // (since an XFD is just a raw data dump, we can only determine this by file name and size)
348
382
if ((!strcmp (" .XFD" , extension) || !strcmp (" .xfd" , extension)) && (m_fileSize == FORMAT_SS_SD_40)) {
349
383
m_type = TYPE_XFD;
350
384
m_readOnly = false ;
@@ -353,8 +387,22 @@ boolean DiskImage::loadFile(SdFile *file) {
353
387
m_sectorReadDelay = 0 ;
354
388
355
389
LOG_MSG (" Loaded XFD with sector size 128: " );
390
+ return true ;
391
+ #ifdef XEX_IMAGES
392
+ } else if ((!strcmp (" .XEX" , extension) || !strcmp (" .xex" , extension))) {
393
+ m_type = TYPE_XEX;
394
+ m_readOnly = true ;
395
+ m_headerSize = 0 ;
396
+ m_sectorSize = SECTOR_SIZE_SD;
397
+ m_sectorReadDelay = 0 ;
356
398
399
+ // set the size of the XEX in the correct bootloader location
400
+ KBOOT_LOADER[9 ] = m_fileSize & 0xFF ;
401
+ KBOOT_LOADER[10 ] = m_fileSize >> 8 ;
402
+
403
+ LOG_MSG (" Loaded XEX with sector size 128: " );
357
404
return true ;
405
+ #endif
358
406
}
359
407
360
408
return false ;
0 commit comments