Skip to content

Commit 61ffa92

Browse files
author
Daniel Noguerol
committed
Added XEX support.
1 parent 2564058 commit 61ffa92

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

SIO2Arduino.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ void changeDisk() {
194194
boolean isValidFilename(char *s) {
195195
return ( s[0] != '.' && // ignore hidden directories
196196
s[0] != '_' && ( // ignore bogus files created by OS X
197-
(s[8] == 'A' && s[9] == 'T' && s[10] == 'R') ||
198-
(s[8] == 'P' && s[9] == 'R' && s[10] == 'O') ||
199-
(s[8] == 'X' && s[9] == 'F' && s[10] == 'D')
197+
(s[8] == 'A' && s[9] == 'T' && s[10] == 'R')
198+
|| (s[8] == 'P' && s[9] == 'R' && s[10] == 'O')
199+
|| (s[8] == 'X' && s[9] == 'F' && s[10] == 'D')
200+
#ifdef XEX_IMAGES
201+
|| (s[8] == 'X' && s[9] == 'E' && s[10] == 'X')
202+
#endif
200203
#ifdef ATX_IMAGES
201-
|| (s[8] == 'A' && s[9] == 'T' && s[10] == 'X')
204+
|| (s[8] == 'A' && s[9] == 'T' && s[10] == 'X')
202205
#endif
203-
)
204-
);
206+
)
207+
);
205208
}
206209

207210
void createFilename(char* filename, char* name) {

config.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
// Uncomment this line if you are using a hardware button for image selection
4040
#define SELECTOR_BUTTON
4141

42-
// uncomment if using an Ethernet sheild for SD capabilities
42+
// uncomment if using an Ethernet shield for SD capabilities
4343
//#define ETHERNET_SHIELD
4444

4545
// uncomment for ATX image format support (Mega 2560 only)
4646
//#define ATX_IMAGES
4747

48+
// uncomment for XEX "image" support
49+
#define XEX_IMAGES
50+
4851
// uncomment this to enable debug logging -- make sure the HARDWARE_UART isn't the same as
4952
// the LOGGING_UART defined at the bottom of the file
5053
#define DEBUG

disk_image.cpp

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323
#include "disk_image.h"
2424
#include "config.h"
2525

26+
#ifdef XEX_IMAGES
27+
byte KBOOT_LOADER[] = {
28+
0x00,0x03,0x00,0x07,0x14,0x07,0x4c,0x14,0x07,0xAA,0xBB,0x00,0x00,0xa9,0x46,0x8d,0xc6,0x02,0xd0,0xfe,0xa0,0x00,0xa9,0x6b,
29+
0x91,0x58,0x20,0xd9,0x07,0xb0,0xee,0x20,0xc4,0x07,0xad,0x7a,0x08,0x0d,0x76,0x08,0xd0,0xe3,0xa5,0x80,0x8d,0xe0,0x02,0xa5,
30+
0x81,0x8d,0xe1,0x02,0xa9,0x00,0x8d,0xe2,0x02,0x8d,0xe3,0x02,0x20,0xeb,0x07,0xb0,0xcc,0xa0,0x00,0x91,0x80,0xa5,0x80,0xc5,
31+
0x82,0xd0,0x06,0xa5,0x81,0xc5,0x83,0xf0,0x08,0xe6,0x80,0xd0,0x02,0xe6,0x81,0xd0,0xe3,0xad,0x76,0x08,0xd0,0xaf,0xad,0xe2,
32+
0x02,0x8d,0x70,0x07,0x0d,0xe3,0x02,0xf0,0x0e,0xad,0xe3,0x02,0x8d,0x71,0x07,0x20,0xff,0xff,0xad,0x7a,0x08,0xd0,0x13,0xa9,
33+
0x00,0x8d,0xe2,0x02,0x8d,0xe3,0x02,0x20,0xae,0x07,0xad,0x7a,0x08,0xd0,0x03,0x4c,0x3c,0x07,0xa9,0x00,0x85,0x80,0x85,0x81,
34+
0x85,0x82,0x85,0x83,0xad,0xe0,0x02,0x85,0x0a,0x85,0x0c,0xad,0xe1,0x02,0x85,0x0b,0x85,0x0d,0xa9,0x01,0x85,0x09,0xa9,0x00,
35+
0x8d,0x44,0x02,0x6c,0xe0,0x02,0x20,0xeb,0x07,0x85,0x80,0x20,0xeb,0x07,0x85,0x81,0xa5,0x80,0xc9,0xff,0xd0,0x10,0xa5,0x81,
36+
0xc9,0xff,0xd0,0x0a,0x20,0xeb,0x07,0x85,0x80,0x20,0xeb,0x07,0x85,0x81,0x20,0xeb,0x07,0x85,0x82,0x20,0xeb,0x07,0x85,0x83,
37+
0x60,0x20,0xeb,0x07,0xc9,0xff,0xd0,0x09,0x20,0xeb,0x07,0xc9,0xff,0xd0,0x02,0x18,0x60,0x38,0x60,0xad,0x09,0x07,0x0d,0x0a,
38+
0x07,0x0d,0x0b,0x07,0xf0,0x79,0xac,0x79,0x08,0x10,0x50,0xee,0x77,0x08,0xd0,0x03,0xee,0x78,0x08,0xa9,0x31,0x8d,0x00,0x03,
39+
0xa9,0x01,0x8d,0x01,0x03,0xa9,0x52,0x8d,0x02,0x03,0xa9,0x40,0x8d,0x03,0x03,0xa9,0x80,0x8d,0x04,0x03,0xa9,0x08,0x8d,0x05,
40+
0x03,0xa9,0x1f,0x8d,0x06,0x03,0xa9,0x80,0x8d,0x08,0x03,0xa9,0x00,0x8d,0x09,0x03,0xad,0x77,0x08,0x8d,0x0a,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+
2647
DiskImage::DiskImage() {
2748
m_fileRef = NULL;
2849
}
@@ -56,6 +77,11 @@ SectorPacket* DiskImage::getSectorData(unsigned long sector) {
5677
m_sectorBuffer.error = false;
5778
m_sectorBuffer.validStatusFrame = false;
5879

80+
// delay if necessary
81+
if (m_sectorReadDelay) {
82+
delay(m_sectorReadDelay);
83+
}
84+
5985
// seek to proper offset in file
6086
if (m_type == TYPE_PRO) {
6187
// 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) {
80106
}
81107
}
82108
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
83121
#ifdef ATX_IMAGES
84122
} else if (m_type == TYPE_ATX) {
85123
int ix = -1;
@@ -120,11 +158,6 @@ SectorPacket* DiskImage::getSectorData(unsigned long sector) {
120158
m_fileRef->seekSet(m_headerSize + ((sector - 1) * m_sectorSize));
121159
}
122160

123-
// delay if necessary
124-
if (m_sectorReadDelay) {
125-
delay(m_sectorReadDelay);
126-
}
127-
128161
// read sector data into buffer
129162
for (int i=0; i < m_sectorSize; i++) {
130163
m_sectorBuffer.data[i] = (byte)m_fileRef->read();
@@ -340,11 +373,12 @@ boolean DiskImage::loadFile(SdFile *file) {
340373
}
341374
#endif
342375

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)
345376
file->getFilename((char*)&filename);
346377
int len = strlen(filename);
347378
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)
348382
if ((!strcmp(".XFD", extension) || !strcmp(".xfd", extension)) && (m_fileSize == FORMAT_SS_SD_40)) {
349383
m_type = TYPE_XFD;
350384
m_readOnly = false;
@@ -353,8 +387,22 @@ boolean DiskImage::loadFile(SdFile *file) {
353387
m_sectorReadDelay = 0;
354388

355389
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;
356398

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: ");
357404
return true;
405+
#endif
358406
}
359407

360408
return false;

disk_image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const byte TYPE_ATR = 1;
1111
const byte TYPE_XFD = 2;
1212
const byte TYPE_PRO = 3;
1313
const byte TYPE_ATX = 4;
14+
const byte TYPE_XEX = 5;
1415

1516
const unsigned long SECTOR_SIZE_SD = 128;
1617

0 commit comments

Comments
 (0)