Skip to content

Commit

Permalink
Merge pull request #694 from juzzas/dev/add_disk_size
Browse files Browse the repository at this point in the history
rc2014: disk: add command for number of sectors
  • Loading branch information
tschak909 authored Jan 21, 2024
2 parents 1944661 + 276e9fc commit 242858d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/device/rc2014/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define RC2014_DISKCMD_READ 0x52
#define RC2014_DISKCMD_STATUS 0x53
#define RC2014_DISKCMD_WRITE 0x57
#define RC2014_DISKCMD_SIZE 0x5A // 0x5A = 'Z'

rc2014Disk::rc2014Disk()
{
Expand Down Expand Up @@ -209,6 +210,29 @@ void rc2014Disk::unmount()
}
}

void rc2014Disk::get_size()
{
Debug_print("disk SIZE\n");
rc2014_send_ack();

uint32_t disk_size = 0;
if (_media != nullptr)
disk_size = _media->num_sectors();

uint8_t sectors[4];
sectors[0] = disk_size & 0xFF;
sectors[1] = (disk_size >> 8) & 0xFF;
sectors[2] = (disk_size >> 16) & 0xFF;
sectors[3] = (disk_size >> 24) & 0xFF;

Debug_printf("number of sectors: %d\n", disk_size);

rc2014_send_buffer(sectors, sizeof(sectors));
rc2014_flush();

rc2014_send_complete();
}

// Create blank disk
bool rc2014Disk::write_blank(FILE *f, uint16_t sectorSize, uint16_t numSectors)
{
Expand All @@ -217,7 +241,6 @@ bool rc2014Disk::write_blank(FILE *f, uint16_t sectorSize, uint16_t numSectors)
return true; //MediaTypeImg::create(f, sectorSize, numSectors);
}


void rc2014Disk::rc2014_process(uint32_t commanddata, uint8_t checksum)
{
cmdFrame.commanddata = commanddata;
Expand All @@ -243,6 +266,9 @@ void rc2014Disk::rc2014_process(uint32_t commanddata, uint8_t checksum)
case RC2014_DISKCMD_FORMAT_MEDIUM:
format();
return;
case RC2014_DISKCMD_SIZE:
get_size();
return;
default:
Debug_printf("rc2014_process() command not implemented. Cmd received: %02x\n", cmdFrame.comnd);
rc2014_send_nak();
Expand Down
1 change: 1 addition & 0 deletions lib/device/rc2014/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class rc2014Disk : public virtualDevice
void write(bool verify);
void format();
void status();
void get_size();

bool write_blank(FILE *f, uint16_t sectorSize, uint16_t numSectors);

Expand Down
4 changes: 4 additions & 0 deletions lib/media/rc2014/mediaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ uint16_t MediaType::sector_size(uint16_t sector)
return DISK_BYTES_PER_SECTOR_SINGLE;
}

uint32_t MediaType::num_sectors() {
return _media_num_sectors;
}

#endif // NEW_TARGET
1 change: 1 addition & 0 deletions lib/media/rc2014/mediaType.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MediaType

static mediatype_t discover_mediatype(const char *filename, uint32_t disksize);
uint16_t sector_size(uint16_t sector);
uint32_t num_sectors();

virtual ~MediaType();
};
Expand Down

0 comments on commit 242858d

Please sign in to comment.