Skip to content

Commit

Permalink
Merge pull request #447 from FujiNetWIFI:add-512-byte-sector-support
Browse files Browse the repository at this point in the history
add-512-byte-sector-support
  • Loading branch information
tschak909 authored Apr 25, 2021
2 parents c93066c + 17982d9 commit fe61645
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 44 deletions.
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define FN_VERSION_MAJOR 0
#define FN_VERSION_MINOR 5

#define FN_VERSION_BUILD "be0c875e"
#define FN_VERSION_BUILD "570061a6"

#define FN_VERSION_DATE "2021-04-21 04:21:51"
#define FN_VERSION_DATE "2021-04-25 00:00:38"

#define FN_VERSION_FULL "0.5.be0c875e"
#define FN_VERSION_FULL "0.5.570061a6"
34 changes: 25 additions & 9 deletions lib/sio/diskType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// SectorNum is 1-based
uint16_t DiskType::sector_size(uint16_t sectornum)
{
return sectornum <= 3 ? 128 : _disk_sector_size;
if (_disk_sector_size == 512)
return 512;
else
return sectornum <= 3 ? 128 : _disk_sector_size;
}

// Default WRITE is not implemented
Expand Down Expand Up @@ -139,23 +142,36 @@ void DiskType::unmount()
disktype_t DiskType::discover_disktype(const char *filename)
{
int l = strlen(filename);
if(l > 4 && filename[l - 4] == '.')
if (l > 4 && filename[l - 4] == '.')
{
// Check the last 3 characters of the string
const char *ext = filename + l - 3;
if(strcasecmp(ext, "XEX") == 0) {
if (strcasecmp(ext, "XEX") == 0)
{
return DISKTYPE_XEX;
} else if(strcasecmp(ext, "COM") == 0) {
}
else if (strcasecmp(ext, "COM") == 0)
{
return DISKTYPE_XEX;
} else if(strcasecmp(ext, "BIN") == 0) {
}
else if (strcasecmp(ext, "BIN") == 0)
{
return DISKTYPE_XEX;
} else if(strcasecmp(ext, "ATR") == 0) {
}
else if (strcasecmp(ext, "ATR") == 0)
{
return DISKTYPE_ATR;
} else if(strcasecmp(ext, "ATX") == 0) {
}
else if (strcasecmp(ext, "ATX") == 0)
{
return DISKTYPE_ATX;
} else if(strcasecmp(ext, "CAS") == 0) {
}
else if (strcasecmp(ext, "CAS") == 0)
{
return DISKTYPE_CAS;
} else if(strcasecmp(ext, "WAV") == 0) {
}
else if (strcasecmp(ext, "WAV") == 0)
{
return DISKTYPE_WAV;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/sio/diskType.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

#define INVALID_SECTOR_VALUE 65536

#define DISK_SECTORBUF_SIZE 256
#define DISK_SECTORBUF_SIZE 512

#define DISK_BYTES_PER_SECTOR_SINGLE 128
#define DISK_BYTES_PER_SECTOR_DOUBLE 256
#define DISK_BYTES_PER_SECTOR_DOUBLE_DOUBLE 512

#define DISK_CTRL_STATUS_CLEAR 0x00
#define DISK_CTRL_STATUS_BUSY 0x01
Expand Down
73 changes: 42 additions & 31 deletions lib/sio/diskTypeAtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ uint32_t DiskTypeATR::_sector_to_offset(uint16_t sectorNum)

switch (sectorNum)
{
case 1:
offset=16;
break;
case 2:
offset=144;
break;
case 3:
offset=272;
break;
default:
if (_disk_sector_size == 256)
offset=((sectorNum-3)*256)+16+128;
else
offset=((sectorNum-1)*128)+16;

break;
case 1:
offset = 16;
break;
case 2:
if (_disk_sector_size == 512)
offset = 528;
else
offset = 144;
break;
case 3:
if (_disk_sector_size == 512)
offset = 1040;
else
offset = 272;
break;
default:
if (_disk_sector_size == 256)
offset = ((sectorNum - 3) * 256) + 16 + 128;
else if (_disk_sector_size == 512)
offset = (sectorNum * 512) + 16;
else
offset = ((sectorNum - 1) * 128) + 16;
break;
}

return offset;
Expand All @@ -47,9 +54,9 @@ bool DiskTypeATR::read(uint16_t sectornum, uint16_t *readcount)
*readcount = 0;

// Return an error if we're trying to read beyond the end of the disk
if(sectornum > _disk_num_sectors)
if (sectornum > _disk_num_sectors)
{
Debug_printf("::read sector %d > %d\n", sectornum, _disk_num_sectors);
Debug_printf("::read sector %d > %d\n", sectornum, _disk_num_sectors);
return true;
}

Expand Down Expand Up @@ -84,7 +91,7 @@ bool DiskTypeATR::write(uint16_t sectornum, bool verify)
Debug_printf("ATR WRITE\n", sectornum, _disk_num_sectors);

// Return an error if we're trying to write beyond the end of the disk
if(sectornum > _disk_num_sectors)
if (sectornum > _disk_num_sectors)
{
Debug_printf("::write sector %d > %d\n", sectornum, _disk_num_sectors);
return true;
Expand Down Expand Up @@ -127,7 +134,7 @@ void DiskTypeATR::status(uint8_t statusbuff[4])
{
statusbuff[0] = DISK_DRIVE_STATUS_CLEAR;

if (_disk_sector_size == 256)
if (_disk_sector_size > 128)
statusbuff[0] |= DISK_DRIVE_STATUS_DOUBLE_DENSITY;

if (_percomBlock.num_sides == 1)
Expand All @@ -136,7 +143,7 @@ void DiskTypeATR::status(uint8_t statusbuff[4])
if (_percomBlock.sectors_per_trackL == 26)
statusbuff[0] |= DISK_DRIVE_STATUS_ENHANCED_DENSITY;

statusbuff[1] = ~ _disk_controller_status; // Negate the controller status
statusbuff[1] = ~_disk_controller_status; // Negate the controller status
}

/*
Expand Down Expand Up @@ -257,7 +264,8 @@ bool DiskTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors)

uint32_t total_size = numSectors * sectorSize;
// Adjust for first 3 sectors always being single-density (we lose 384 bytes)
if (sectorSize > 128)
// we don't do this for 512 byte sectors
if (sectorSize == 256)
total_size -= 384; // 3 * 128

uint32_t num_paragraphs = total_size / 16;
Expand All @@ -274,23 +282,26 @@ bool DiskTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors)
atrHeader.secsizeH = HIBYTE_FROM_UINT16(sectorSize);

Debug_printf("Write header to ATR: sec_size=%d, sectors=%d, paragraphs=%d, bytes=%d\n",
sectorSize, numSectors, num_paragraphs, total_size);
sectorSize, numSectors, num_paragraphs, total_size);

uint32_t offset = fwrite(&atrHeader, 1, sizeof(atrHeader), f);

// Write first three 128 uint8_t sectors
uint8_t blank[256] = {0};
uint8_t blank[512] = {0};

for (int i = 0; i < 3; i++)
if (sectorSize < 512)
{
size_t out = fwrite(blank, 1, 128, f);
if (out != 128)
for (int i = 0; i < 3; i++)
{
Debug_printf("Error writing sector %hhu\n", i);
return false;
size_t out = fwrite(blank, 1, 128, f);
if (out != 128)
{
Debug_printf("Error writing sector %hhu\n", i);
return false;
}
offset += 128;
numSectors--;
}
offset += 128;
numSectors--;
}

// Write the rest of the sectors via sparse seek to the last sector
Expand Down

0 comments on commit fe61645

Please sign in to comment.