Skip to content

Commit

Permalink
Merge branch 'master' of github.com:FujiNetWIFI/fujinet-platformio
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpiep committed Nov 10, 2023
2 parents b5650e3 + fbcd4df commit ed5d18a
Show file tree
Hide file tree
Showing 17 changed files with 437 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/workflows/autobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install setuptools
pip install --upgrade platformio
pip install Jinja2
pip install pyyaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install setuptools
pip install --upgrade platformio
pip install Jinja2
pip install pyyaml
Expand Down
Binary file modified data/webui/device_specific/BUILD_APPLE/autorun.po
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/FileSystem/fnFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ char * FileSystem::_make_fullpath(const char *path)
// Returns size of open file
long FileSystem::filesize(FILE *f)
{
if (f == nullptr)
return -1;
long curr = ftell(f);
fseek(f, 0, SEEK_END);
long end = ftell(f);
Expand Down
53 changes: 29 additions & 24 deletions lib/device/iwm/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ iwmDisk::iwmDisk()

mediatype_t iwmDisk::mount(FILE *f, const char *filename, uint32_t disksize, mediatype_t disk_type)
{
mediatype_t mt = disk_type;
uint8_t deviceSlot = data_buffer[0]; // from mount ctrl cmd
mediatype_t mt = MEDIATYPE_UNKNOWN;
Debug_printf("disk MOUNT %s\n", filename);

// Destroy any existing MediaType
Expand All @@ -515,66 +515,71 @@ mediatype_t iwmDisk::mount(FILE *f, const char *filename, uint32_t disksize, med
}

// Determine MediaType based on filename extension
if (disk_type == MEDIATYPE_UNKNOWN && filename != nullptr) {
disk_type = MediaType::discover_mediatype(filename);
if (disk_type == MEDIATYPE_DSK) {
// determine DO or PO based on file contents
disk_type = MediaType::discover_dsk_mediatype(f, disksize);
}
if (mt == MEDIATYPE_UNKNOWN && filename != nullptr) {
mt = MediaType::discover_mediatype(filename);
}

if (mt == MEDIATYPE_DSK) {
// determine DO or PO based on file contents
mt = MediaType::discover_dsk_mediatype(f, disksize);
}

if (deviceSlot < 4) // SP drive
{
switch (disk_type)
switch (mt)
{
case MEDIATYPE_DO:
Debug_printf("\r\nMedia Type DO");
_disk = new MediaTypeDO();
_disk->_media_host = host;
_disk->_mediatype = disk_type;
strcpy(_disk->_disk_filename, filename);
mt = _disk->mount(f, disksize);

device_active = true; //change status only after we are mounted
break;
case MEDIATYPE_PO:
Debug_printf("\r\nMedia Type PO");
_disk = new MediaTypePO();
break;
default:
Debug_printf("\r\nUnsupported Media Type for SmartPort");
mt = MEDIATYPE_UNKNOWN;
break;
}

if (mt != MEDIATYPE_UNKNOWN) {
_disk->_media_host = host;
_disk->_mediatype = disk_type;
_disk->_mediatype = mt;
strcpy(_disk->_disk_filename, filename);
mt = _disk->mount(f, disksize);
}

if (mt != MEDIATYPE_UNKNOWN) {
// firmware needs to believe a high score enabled disk is
// not write-protected. Otherwise it will skip write process
if (_disk->high_score_enabled)
readonly = false;

device_active = true; //change status only after we are mounted
break;
default:
Debug_printf("\r\nMedia Type UNKNOWN for SP Drive - no mount in disk.cpp");
device_active = false;
break;
}
}
else // DiskII drive
{
switch (disk_type)
switch (mt)
{
case MEDIATYPE_DO:
case MEDIATYPE_PO:
case MEDIATYPE_WOZ:
theFuji._fnDisk2s[deviceSlot - 4].init();
theFuji._fnDisk2s[deviceSlot - 4].mount(f, disk_type); // modulo to ensure device 0 or 1
mt = theFuji._fnDisk2s[deviceSlot - 4].mount(f, disksize, mt);
break;
default:
Debug_printf("\r\nMedia Type UNKNOWN for DiskII - no mount in disk.cpp");
device_active = false;
Debug_printf("\r\nUnsupported Media Type for DiskII");
mt = MEDIATYPE_UNKNOWN;
break;
}
}

if (mt == MEDIATYPE_UNKNOWN) {
Debug_printf("\r\nMedia Type UNKNOWN - no mount in disk.cpp");
device_active = false;
}

return mt;

}
Expand Down
15 changes: 9 additions & 6 deletions lib/device/iwm/disk2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void iwmDisk2::init()
device_active = false;
}

mediatype_t iwmDisk2::mount(FILE *f, mediatype_t disk_type)//, const char *filename), uint32_t disksize, mediatype_t disk_type)
mediatype_t iwmDisk2::mount(FILE *f, uint32_t disksize, mediatype_t disk_type)//, const char *filename), uint32_t disksize, mediatype_t disk_type)
{

mediatype_t mt = MEDIATYPE_UNKNOWN;
Expand All @@ -57,22 +57,25 @@ mediatype_t iwmDisk2::mount(FILE *f, mediatype_t disk_type)//, const char *filen
Debug_printf("\nMounting Media Type WOZ");
device_active = true;
_disk = new MediaTypeWOZ();
mt = ((MediaTypeWOZ *)_disk)->mount(f);
change_track(0); // initialize spi buffer
mt = ((MediaTypeWOZ *)_disk)->mount(f, disksize);
break;
case MEDIATYPE_DO:
case MEDIATYPE_PO:
Debug_printf("\nMounting Media Type DSK");
device_active = true;
_disk = new MediaTypeDSK();
_disk->_mediatype = disk_type;
mt = ((MediaTypeDSK *)_disk)->mount(f);
change_track(0); // initialize spi buffer
mt = ((MediaTypeDSK *)_disk)->mount(f, disksize);
break;
default:
break;
}

if (mt == MEDIATYPE_WOZ) {
change_track(0); // initialize spi buffer
} else {
Debug_printf("\nMedia Type UNKNOWN - no mount in disk2.cpp");
device_active = false;
break;
}

return mt;
Expand Down
2 changes: 1 addition & 1 deletion lib/device/iwm/disk2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class iwmDisk2 : public iwmDevice
public:
iwmDisk2();
void init();
mediatype_t mount(FILE *f, mediatype_t disk_type = MEDIATYPE_UNKNOWN);
mediatype_t mount(FILE *f, uint32_t disksize, mediatype_t disk_type = MEDIATYPE_UNKNOWN);
void unmount();
bool write_blank(FILE *f, uint16_t sectorSize, uint16_t numSectors);
int get_track_pos() { return track_pos; };
Expand Down
30 changes: 21 additions & 9 deletions lib/device/iwm/fuji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void iwmFuji::iwm_ctrl_unmount_host() // SP CTRL command
}

// Disk Image Mount
void iwmFuji::iwm_ctrl_disk_image_mount() // SP CTRL command
uint8_t iwmFuji::iwm_ctrl_disk_image_mount() // SP CTRL command
{
Debug_printf("\r\nFuji cmd: MOUNT IMAGE");

Expand All @@ -220,6 +220,12 @@ void iwmFuji::iwm_ctrl_disk_image_mount() // SP CTRL command
disk.disk_dev.host = &host;
disk.fileh = host.file_open(disk.filename, disk.filename, sizeof(disk.filename), flag);

if (disk.fileh == nullptr)
{
Debug_printf("\r\nFailed to open %s", disk.filename);
return SP_ERR_NODRIVE;
}

// We've gotten this far, so make sure our bootable CONFIG disk is disabled
boot_config = false;

Expand All @@ -234,6 +240,7 @@ void iwmFuji::iwm_ctrl_disk_image_mount() // SP CTRL command

if(options == DISK_ACCESS_MODE_WRITE) {disk.disk_dev.readonly = false;}

return SP_ERR_NOERROR;
}


Expand Down Expand Up @@ -507,10 +514,12 @@ void iwmFuji::shutdown()



void iwmFuji::iwm_ctrl_open_directory()
uint8_t iwmFuji::iwm_ctrl_open_directory()
{
Debug_printf("\r\nFuji cmd: OPEN DIRECTORY");

uint8_t err_result = SP_ERR_NOERROR;

int idx = 0;
uint8_t hostSlot = data_buffer[idx++];// adamnet_recv();

Expand Down Expand Up @@ -540,8 +549,7 @@ void iwmFuji::iwm_ctrl_open_directory()
if (_fnHosts[hostSlot].dir_open(dirpath, pattern, 0))
_current_open_directory_slot = hostSlot;
else
err_result = 0x30; // bad device specific error
// to do - error reutrn if cannot open directory?
err_result = SP_ERR_IOERROR;
}
// else
// {
Expand All @@ -551,6 +559,7 @@ void iwmFuji::iwm_ctrl_open_directory()
// }
// // to do - return false or true?
// response_len = 1;
return err_result;
}

void _set_additional_direntry_details(fsdir_entry_t *f, uint8_t *dest, uint8_t maxlen)
Expand Down Expand Up @@ -1081,12 +1090,12 @@ void iwmFuji::setup(iwmBus *iwmbus)
if (Config.get_general_boot_mode() == 0)
{
FILE *f = fsFlash.file_open("/autorun.po");
_fnDisks[0].disk_dev.mount(f, "/autorun.po", 512*256, MEDIATYPE_PO);
_fnDisks[0].disk_dev.mount(f, "/autorun.po", 140 * 1024, MEDIATYPE_PO);
}
else
{
FILE *f = fsFlash.file_open("/mount-and-boot.po");
_fnDisks[0].disk_dev.mount(f, "/mount-and-boot.po", 512*256, MEDIATYPE_PO);
_fnDisks[0].disk_dev.mount(f, "/mount-and-boot.po", 140 * 1024, MEDIATYPE_PO);
}

// theNetwork = new adamNetwork();
Expand Down Expand Up @@ -1288,7 +1297,7 @@ void iwmFuji::iwm_status(iwm_decoded_cmd_t cmd)

void iwmFuji::iwm_ctrl(iwm_decoded_cmd_t cmd)
{
err_result = SP_ERR_NOERROR;
uint8_t err_result = SP_ERR_NOERROR;

// uint8_t source = cmd.dest; // we are the destination and will become the source // data_buffer[6];
uint8_t control_code = get_status_code(cmd); // (cmd.g7byte3 & 0x7f) | ((cmd.grp7msb << 3) & 0x80); // ctrl codes 00-FF
Expand All @@ -1312,6 +1321,9 @@ void iwmFuji::iwm_ctrl(iwm_decoded_cmd_t cmd)
send_reply_packet(err_result);
iwm_ctrl_reset_fujinet();
break;



// case FUJICMD_GET_SSID: // 0xFE
// case FUJICMD_SCAN_NETWORKS: // 0xFD
case FUJICMD_GET_SCAN_RESULT: // 0xFC
Expand All @@ -1325,11 +1337,11 @@ void iwmFuji::iwm_ctrl(iwm_decoded_cmd_t cmd)
iwm_ctrl_mount_host();
break;
case FUJICMD_MOUNT_IMAGE: // 0xF8
iwm_ctrl_disk_image_mount();
err_result = iwm_ctrl_disk_image_mount();
break;
case FUJICMD_OPEN_DIRECTORY: // 0xF7
// print_packet((uint8_t *)data_buffer, 512);
iwm_ctrl_open_directory();
err_result = iwm_ctrl_open_directory();
break;
case FUJICMD_READ_DIR_ENTRY: // 0xF6
iwm_ctrl_read_directory_entry();
Expand Down
5 changes: 2 additions & 3 deletions lib/device/iwm/fuji.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class iwmFuji : public iwmDevice
bool scanStarted = false;
bool hostMounted[MAX_HOSTS];
bool setSSIDStarted = false;
uint8_t err_result = SP_ERR_NOERROR;

//uint8_t response[1024]; // use packet_buffer instead
//uint16_t response_len;
Expand Down Expand Up @@ -116,8 +115,8 @@ class iwmFuji : public iwmDevice
void iwm_ctrl_net_set_ssid(); // control 0xFB
void iwm_stat_net_get_wifi_status(); // status 0xFA
void iwm_ctrl_mount_host(); // 0xF9
void iwm_ctrl_disk_image_mount(); // 0xF8
void iwm_ctrl_open_directory(); // 0xF7
uint8_t iwm_ctrl_disk_image_mount(); // 0xF8
uint8_t iwm_ctrl_open_directory(); // 0xF7
void iwm_ctrl_read_directory_entry(); // 0xF6
void iwm_stat_read_directory_entry(); // 0xF6

Expand Down
3 changes: 2 additions & 1 deletion lib/device/sio/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ void sioDisk::sio_process(uint32_t commanddata, uint8_t checksum)
if (_disk == nullptr || _disk->_disktype == MEDIATYPE_UNKNOWN)
return;

if (device_active == false)
if ((device_active == false && cmdFrame.device != SIO_DEVICEID_DISK) || // not active and not D1
(device_active == false && theFuji.boot_config == false)) // not active and not config boot
return;

Debug_printf("disk sio_process(), baud: %d\n", SIO.getBaudrate());
Expand Down
11 changes: 11 additions & 0 deletions lib/media/apple/mediaTypeDO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ bool MediaTypeDO::format(uint16_t *respopnsesize)

mediatype_t MediaTypeDO::mount(FILE *f, uint32_t disksize)
{
switch (disksize) {
case 35 * BYTES_PER_TRACK:
case 36 * BYTES_PER_TRACK:
case 40 * BYTES_PER_TRACK:
// 35, 36, and 40 tracks are supported (same as Applesauce)
break;
default:
Debug_printf("\nMediaTypeDO error: unsupported disk image size %ld", disksize);
return MEDIATYPE_UNKNOWN;
}

diskiiemulation = false;
_media_fileh = f;
num_blocks = disksize / BYTES_PER_BLOCK;
Expand Down
21 changes: 17 additions & 4 deletions lib/media/apple/mediaTypeDSK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// #include <stdint.h>
// #include <string.h>

#define BYTES_PER_TRACK 4096

// routines to convert DSK to WOZ stolen from DSK2WOZ by Tom Harte
// https://github.com/TomHarte/dsk2woz
Expand All @@ -19,11 +20,23 @@ static void serialise_track(uint8_t *dest, const uint8_t *src, uint8_t track_num

mediatype_t MediaTypeDSK::mount(FILE *f, uint32_t disksize)
{
switch (disksize) {
case 35 * BYTES_PER_TRACK:
case 36 * BYTES_PER_TRACK:
case 40 * BYTES_PER_TRACK:
// 35, 36, and 40 tracks are supported (same as Applesauce)
break;
default:
Debug_printf("\nMediaTypeDSK error: unsupported disk image size %ld", disksize);
return MEDIATYPE_UNKNOWN;
}

_media_fileh = f;
diskiiemulation = true;
num_tracks = disksize / BYTES_PER_TRACK;

// allocated SPRAM
const size_t dsk_image_size = 35 * 16 * 256;
const size_t dsk_image_size = num_tracks * BYTES_PER_TRACK;
uint8_t *dsk = (uint8_t*)heap_caps_malloc(dsk_image_size, MALLOC_CAP_SPIRAM);
if (fseek(f, 0, SEEK_SET) != 0)
return MEDIATYPE_UNKNOWN;
Expand Down Expand Up @@ -59,7 +72,7 @@ void MediaTypeDSK::dsk2woz_tmap()
// Let's start by filling the entire TMAP with empty tracks.
memset(tmap, 0xff, 160);
// Then we will add in the mappings.
for(size_t c = 0; c < 35; ++c)
for(size_t c = 0; c < num_tracks; ++c)
{
size_t track_position = c << 2;
if (c > 0)
Expand Down Expand Up @@ -91,8 +104,8 @@ bool MediaTypeDSK::dsk2woz_tracks(uint8_t *dsk)
Debug_printf("\nMediaTypeDSK is_prodos: %s", _mediatype == MEDIATYPE_PO ? "Y" : "N");

// TODO: adapt this to that
// Write out all 35 tracks.
for (size_t c = 0; c < 35; c++)
// Write out all tracks.
for (size_t c = 0; c < num_tracks; c++)
{
uint16_t bytes_used;
uint16_t bit_count;
Expand Down
Loading

0 comments on commit ed5d18a

Please sign in to comment.