diff --git a/fujinet_pc.cmake b/fujinet_pc.cmake index 5e96ba516..eda531d2b 100644 --- a/fujinet_pc.cmake +++ b/fujinet_pc.cmake @@ -208,10 +208,10 @@ set(SOURCES # lib/media/apple/mediaTypeDSK.h lib/media/apple/mediaTypeDSK.cpp # lib/media/apple/mediaTypePO.h lib/media/apple/mediaTypePO.cpp # lib/media/apple/mediaTypeWOZ.h lib/media/apple/mediaTypeWOZ.cpp -# lib/media/atari/diskType.h lib/media/atari/diskType.cpp -# lib/media/atari/diskTypeAtr.h lib/media/atari/diskTypeAtr.cpp -# lib/media/atari/diskTypeAtx.h -# lib/media/atari/diskTypeXex.h lib/media/atari/diskTypeXex.cpp + lib/media/atari/diskType.h lib/media/atari/diskType.cpp + lib/media/atari/diskTypeAtr.h lib/media/atari/diskTypeAtr.cpp + lib/media/atari/diskTypeAtx.h + lib/media/atari/diskTypeXex.h lib/media/atari/diskTypeXex.cpp lib/base64/base64.h lib/base64/base64.c lib/encrypt/crypt.h lib/encrypt/crypt.cpp lib/compat/compat_inet.c diff --git a/lib/media/atari/diskType.cpp b/lib/media/atari/diskType.cpp index f9d5bc956..867334d36 100755 --- a/lib/media/atari/diskType.cpp +++ b/lib/media/atari/diskType.cpp @@ -138,7 +138,11 @@ void MediaType::unmount() { if (_disk_fileh != nullptr) { +#ifdef ESP_PLATFORM fclose(_disk_fileh); +#else + _disk_fileh->close(); +#endif _disk_fileh = nullptr; } } diff --git a/lib/media/atari/diskType.h b/lib/media/atari/diskType.h index 2a1c57665..902a984cf 100755 --- a/lib/media/atari/diskType.h +++ b/lib/media/atari/diskType.h @@ -1,11 +1,15 @@ #ifndef _MEDIATYPE_ #define _MEDIATYPE_ -// #include -#include #include +#ifdef ESP_PLATFORM +#include +#else #include "fnFile.h" +#endif + +#include "fujiHost.h" #define INVALID_SECTOR_VALUE 65536 diff --git a/lib/media/atari/diskTypeAtr.cpp b/lib/media/atari/diskTypeAtr.cpp index 58eb8cbc1..bef0205c0 100755 --- a/lib/media/atari/diskTypeAtr.cpp +++ b/lib/media/atari/diskTypeAtr.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include "../../include/debug.h" @@ -52,7 +54,7 @@ uint32_t MediaTypeATR::_sector_to_offset(uint16_t sectorNum) // Returns TRUE if an error condition occurred bool MediaTypeATR::read(uint16_t sectornum, uint16_t *readcount) { - Debug_print("ATR READ\r\n"); + Debug_printf("ATR READ %d / %d\r\n", sectornum, _disk_num_sectors); *readcount = 0; @@ -72,11 +74,19 @@ bool MediaTypeATR::read(uint16_t sectornum, uint16_t *readcount) if (sectornum != _disk_last_sector + 1) { uint32_t offset = _sector_to_offset(sectornum); +#ifdef ESP_PLATFORM err = fseek(_disk_fileh, offset, SEEK_SET) != 0; +#else + err = _disk_fileh->seek(offset, SEEK_SET) != 0; +#endif } if (err == false) +#ifdef ESP_PLATFORM err = fread(_disk_sectorbuff, 1, sectorSize, _disk_fileh) != sectorSize; +#else + err = _disk_fileh->read(_disk_sectorbuff, 1, sectorSize) != sectorSize; +#endif if (err == false) _disk_last_sector = sectornum; @@ -96,12 +106,16 @@ bool inHighScoreRange(int minimum, int maximum, int val) // Returns TRUE if an error condition occurred bool MediaTypeATR::write(uint16_t sectornum, bool verify) { +#ifdef ESP_PLATFORM FILE *oldFileh, *hsFileh; +#else + FileHandler *oldFileh, *hsFileh; +#endif oldFileh = nullptr; hsFileh = nullptr; - Debug_printf("ATR WRITE\r\n", sectornum, _disk_num_sectors); + Debug_printf("ATR WRITE %d / %d\r\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) @@ -120,7 +134,11 @@ bool MediaTypeATR::write(uint16_t sectornum, bool verify) else { oldFileh = _disk_fileh; +#ifdef ESP_PLATFORM hsFileh = _disk_host->file_open(_disk_filename, _disk_filename, strlen(_disk_filename) + 1, "r+"); +#else + hsFileh = _disk_host->filehandler_open(_disk_filename, _disk_filename, strlen(_disk_filename) + 1, "rb+"); +#endif _disk_fileh = hsFileh; } } @@ -133,7 +151,11 @@ bool MediaTypeATR::write(uint16_t sectornum, bool verify) int e; if (sectornum != _disk_last_sector + 1) { +#ifdef ESP_PLATFORM e = fseek(_disk_fileh, offset, SEEK_SET); +#else + e = _disk_fileh->seek(offset, SEEK_SET); +#endif if (e != 0) { Debug_printf("::write seek error %d\r\n", e); @@ -141,15 +163,23 @@ bool MediaTypeATR::write(uint16_t sectornum, bool verify) } } // Write the data +#ifdef ESP_PLATFORM e = fwrite(_disk_sectorbuff, 1, sectorSize, _disk_fileh); +#else + e = _disk_fileh->write(_disk_sectorbuff, 1, sectorSize); +#endif if (e != sectorSize) { Debug_printf("::write error %d, %d\r\n", e, errno); return true; } +#ifdef ESP_PLATFORM int ret = fflush(_disk_fileh); // This doesn't seem to be connected to anything in ESP-IDF VF, so it may not do anything ret = fsync(fileno(_disk_fileh)); // Since we might get reset at any moment, go ahead and sync the file (not clear if fflush does this) +#else + int ret = _disk_fileh->flush(); +#endif Debug_printf("ATR::write fsync:%d\r\n", ret); if (_high_score_sector != 0) @@ -157,7 +187,11 @@ bool MediaTypeATR::write(uint16_t sectornum, bool verify) Debug_printf("Closing high score sector.\r\n"); if (hsFileh != nullptr) +#ifdef ESP_PLATFORM fclose(hsFileh); +#else + hsFileh->close(); +#endif _disk_fileh = oldFileh; _disk_last_sector = INVALID_SECTOR_VALUE; // force a cache invalidate. @@ -218,7 +252,11 @@ bool MediaTypeATR::format(uint16_t *responsesize) 07-0F have two possible interpretations but are no critical for our use */ +#ifdef ESP_PLATFORM mediatype_t MediaTypeATR::mount(FILE *f, uint32_t disksize) +#else +mediatype_t MediaTypeATR::mount(FileHandler *f, uint32_t disksize) +#endif { Debug_print("ATR MOUNT\r\n"); @@ -230,12 +268,20 @@ mediatype_t MediaTypeATR::mount(FILE *f, uint32_t disksize) // Get file and sector size from header int i; +#ifdef ESP_PLATFORM if ((i = fseek(f, 0, SEEK_SET)) < 0) +#else + if ((i = f->seek(0, SEEK_SET)) < 0) +#endif { Debug_printf("failed seeking to header on disk image (%d, %d)\r\n", i, errno); return _disktype; } +#ifdef ESP_PLATFORM if ((i = fread(buf, 1, sizeof(buf), f)) != sizeof(buf)) +#else + if ((i = f->read(buf, 1, sizeof(buf))) != sizeof(buf)) +#endif { Debug_printf("failed reading header bytes (%d, %d)\r\n", i, errno); return _disktype; @@ -280,7 +326,11 @@ mediatype_t MediaTypeATR::mount(FILE *f, uint32_t disksize) } // Returns FALSE on error +#ifdef ESP_PLATFORM bool MediaTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors) +#else +bool MediaTypeATR::create(FileHandler *f, uint16_t sectorSize, uint16_t numSectors) +#endif { Debug_print("ATR CREATE\r\n"); @@ -328,7 +378,11 @@ bool MediaTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors) Debug_printf("Write header to ATR: sec_size=%d, sectors=%d, paragraphs=%d, bytes=%d\r\n", sectorSize, numSectors, num_paragraphs, total_size); +#ifdef ESP_PLATFORM uint32_t offset = fwrite(&atrHeader, 1, sizeof(atrHeader), f); +#else + uint32_t offset = f->write(&atrHeader, 1, sizeof(atrHeader)); +#endif // Write first three 128 uint8_t sectors uint8_t blank[512] = {0}; @@ -337,10 +391,14 @@ bool MediaTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors) { for (int i = 0; i < 3; i++) { +#ifdef ESP_PLATFORM size_t out = fwrite(blank, 1, 128, f); +#else + size_t out = f->write(blank, 1, 128); +#endif if (out != 128) { - Debug_printf("Error writing sector %hhu\r\n", i); + Debug_printf("Error writing sector %d\r\n", i); return false; } offset += 128; @@ -350,8 +408,13 @@ bool MediaTypeATR::create(FILE *f, uint16_t sectorSize, uint16_t numSectors) // Write the rest of the sectors via sparse seek to the last sector offset += (numSectors * sectorSize) - sectorSize; +#ifdef ESP_PLATFORM fseek(f, offset, SEEK_SET); size_t out = fwrite(blank, 1, sectorSize, f); +#else + f->seek(offset, SEEK_SET); + size_t out = f->write(blank, 1, sectorSize); +#endif if (out != sectorSize) { diff --git a/lib/media/atari/diskTypeXex.cpp b/lib/media/atari/diskTypeXex.cpp index 762b86c69..5b8679035 100755 --- a/lib/media/atari/diskTypeXex.cpp +++ b/lib/media/atari/diskTypeXex.cpp @@ -3,6 +3,8 @@ #include "diskTypeXex.h" #include +#include +#include #include "../../include/debug.h" @@ -174,13 +176,21 @@ bool MediaTypeXEX::read(uint16_t sectornum, uint16_t *readcount) if (sectornum != _disk_last_sector + 1) { Debug_printf("seeking to offset %d in XEX\r\n", xex_offset); +#ifdef ESP_PLATFORM err = fseek(_disk_fileh, xex_offset, SEEK_SET) != 0; +#else + err = _disk_fileh->seek(xex_offset, SEEK_SET) != 0; +#endif } if (err == false) { Debug_printf("requesting %d bytes from XEX\r\n", data_bytes); +#ifdef ESP_PLATFORM int read = fread(_disk_sectorbuff, 1, data_bytes, _disk_fileh); +#else + int read = _disk_fileh->read(_disk_sectorbuff, 1, data_bytes); +#endif Debug_printf("received %d bytes\r\n", read); // Fill in the sector link data pointing to the next sector @@ -225,7 +235,11 @@ MediaTypeXEX::~MediaTypeXEX() unmount(); } +#ifdef ESP_PLATFORM mediatype_t MediaTypeXEX::mount(FILE *f, uint32_t disksize) +#else +mediatype_t MediaTypeXEX::mount(FileHandler *f, uint32_t disksize) +#endif { Debug_print("XEX MOUNT\r\n"); diff --git a/pc_merge_notes.md b/pc_merge_notes.md index 9cbd0a9f2..34bb5450b 100644 --- a/pc_merge_notes.md +++ b/pc_merge_notes.md @@ -292,19 +292,13 @@ - TODO: lib/media/apple/mediaTypeWOZ.h lib/media/apple/mediaTypeWOZ.cpp -- **WIP**: lib/media/atari/diskType.h lib/media/atari/diskType.cpp +- **DONE** / merge: lib/media/atari/diskType.h lib/media/atari/diskType.cpp - diskType.h - -- **WIP**: lib/media/atari/diskTypeAtr.h lib/media/atari/diskTypeAtr.cpp - - diskTypeAtr.h +- **DONE** / merge: lib/media/atari/diskTypeAtr.h lib/media/atari/diskTypeAtr.cpp - **DONE** / merge: lib/media/atari/diskTypeAtx.h -- **WIP**: lib/media/atari/diskTypeXex.h lib/media/atari/diskTypeXex.cpp - - diskTypeXex.h +- **DONE** / merge: lib/media/atari/diskTypeXex.h lib/media/atari/diskTypeXex.cpp - **DONE** / identical: lib/base64/base64.h lib/base64/base64.c