file_io: remove obsolete functions.

This commit is contained in:
sorgelig
2019-02-05 16:01:36 +08:00
parent 0a89c2cd80
commit a6ac6708ae
4 changed files with 15 additions and 179 deletions

View File

@@ -231,7 +231,7 @@ int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute)
file->type = 0;
char *zip_path, *file_path;
if (FileIsZipped(full_path, &zip_path, &file_path))
if ((mode != -1) && FileIsZipped(full_path, &zip_path, &file_path))
{
if (mode & O_RDWR || mode & O_WRONLY)
{
@@ -350,33 +350,6 @@ int FileOpen(fileTYPE *file, const char *name, char mute)
return FileOpenEx(file, name, O_RDONLY, mute);
}
int FileNextSector(fileTYPE *file)
{
if (file->filp)
{
__off64_t newoff = fseeko64(file->filp, file->offset + 512, SEEK_SET);
if (newoff != file->offset + 512)
{
//printf("Fail to seek to next sector. File: %s.\n", file->name);
fseeko64(file->filp, file->offset, SEEK_SET);
return 0;
}
file->offset = newoff;
return 1;
}
else if (file->zip)
{
if (!FileSeek(file, file->offset + 512, SEEK_SET))
{
FileSeek(file, file->offset, SEEK_SET);
return 0;
}
return 1;
}
return 0;
}
int FileSeek(fileTYPE *file, __off64_t offset, int origin)
{
if (file->filp)
@@ -444,127 +417,6 @@ int FileSeekLBA(fileTYPE *file, uint32_t offset)
return FileSeek(file, off64, SEEK_SET);
}
// Read. MiST compatible. Avoid to use it.
int FileRead(fileTYPE *file, void *pBuffer)
{
return FileReadEx(file, pBuffer, 1);
}
int FileReadEx(fileTYPE *file, void *pBuffer, int nSize)
{
static uint8_t tmpbuff[512];
if (!FileSeek(file, file->offset, SEEK_SET))
{
printf("FileRead error(seek).\n");
return 0;
}
if (!pBuffer)
{
for (int i = 0; i < nSize; i++)
{
if (file->filp)
{
int ret = fread(tmpbuff, 1, 512, file->filp);
if (ret < 0)
{
printf("FileRead error(%d).\n", ret);
return 0;
}
i += ret;
}
else if (file->zip)
{
size_t ret = mz_zip_reader_extract_iter_read(file->zip->iter, tmpbuff, 512);
if (!ret)
{
printf("FileReadEx(mz_zip_reader_extract_iter_read) Failed to read, error:%s\n",
mz_zip_get_error_string(mz_zip_get_last_error(&file->zip->archive)));
return 0;
}
file->zip->offset += ret;
}
else
{
printf("FileRead error(unknown file type).\n");
return 0;
}
EnableDMode();
spi_block_write(tmpbuff, 0);
DisableDMode();
}
}
else
{
if (file->filp)
{
int ret = fread(pBuffer, 1, nSize*512, file->filp);
if (ret < 0)
{
printf("FileRead error(%d).\n", ret);
return 0;
}
}
else if (file->zip)
{
char *p = (char*)pBuffer;
for (int i = 0; i < nSize; i++)
{
size_t ret = mz_zip_reader_extract_iter_read(file->zip->iter, p, 512);
if (!ret)
{
printf("FileReadEx(mz_zip_reader_extract_iter_read) Failed to read, error:%s\n",
mz_zip_get_error_string(mz_zip_get_last_error(&file->zip->archive)));
return 0;
}
p += ret;
file->zip->offset += ret;
}
}
else
{
printf("FileRead error(unknown file type).\n");
return 0;
}
}
return 1;
}
// Write. MiST compatible. Avoid to use it.
int FileWrite(fileTYPE *file, void *pBuffer)
{
if (!FileSeek(file, file->offset, SEEK_SET))
{
printf("FileWrite error(seek).\n");
return 0;
}
if (file->filp)
{
int ret = fwrite(pBuffer, 1, 512, file->filp);
if (ret < 0)
{
printf("FileWrite error(%d).\n", ret);
return 0;
}
}
else if (file->zip)
{
printf("FileWrite error(not supported for zip).\n");
return 0;
}
else
{
printf("FileWrite error(unknown file type).\n");
return 0;
}
return 1;
}
// Read with offset advancing
int FileReadAdv(fileTYPE *file, void *pBuffer, int length)
{

View File

@@ -56,13 +56,6 @@ __off64_t FileGetSize(fileTYPE *file);
int FileSeek(fileTYPE *file, __off64_t offset, int origin);
int FileSeekLBA(fileTYPE *file, uint32_t offset);
//MiST compatible functions. Avoid to use them.
int FileRead(fileTYPE *file, void *pBuffer);
int FileReadEx(fileTYPE *file, void *pBuffer, int nSize);
int FileWrite(fileTYPE *file, void *pBuffer);
int FileNextSector(fileTYPE *file);
//New functions.
int FileReadAdv(fileTYPE *file, void *pBuffer, int length);
int FileReadSec(fileTYPE *file, void *pBuffer);
int FileWriteAdv(fileTYPE *file, void *pBuffer, int length);

View File

@@ -1528,8 +1528,6 @@ void sharpmz_send_file(romData_t &image, char *dirPrefix)
{
spi_write(sector_buffer, actualReadSize, 0);
// Still bytes to send, then read next sector.
if (actualReadSize == 512) FileNextSector(&file);
} else
{
// End of file, short file, so just move onto end.
@@ -1760,9 +1758,6 @@ short sharpmz_load_tape_to_ram(const char *tapeFile, unsigned char dstCMT)
{
// Write the sector (or part) to the fpga memory.
spi_write(sector_buffer, actualReadSize, 0);
// Move onto next sector of file.
FileNextSector(&file);
}
}
sharpmz_debugf("]\n");

View File

@@ -306,7 +306,7 @@ static void handle_acsi(unsigned char *buffer) {
DISKLED_ON;
while (length) {
FileSeekLBA(&hdd_image[target], lba++);
FileRead(&hdd_image[target], dma_buffer);
FileReadSec(&hdd_image[target], dma_buffer);
// hexdump(dma_buffer, 32, 0);
mist_memory_write_block(dma_buffer);
length--;
@@ -348,7 +348,7 @@ static void handle_acsi(unsigned char *buffer) {
while (length) {
mist_memory_read_block(dma_buffer);
FileSeekLBA(&hdd_image[target], lba++);
FileWrite(&hdd_image[target], dma_buffer);
FileWriteSec(&hdd_image[target], dma_buffer);
length--;
}
DISKLED_OFF;
@@ -474,7 +474,7 @@ static void handle_fdc(unsigned char *buffer) {
if ((fdc_cmd & 0xe0) == 0x80) {
// read from disk ...
FileRead(&fdd_image[drv_sel - 1].file, dma_buffer);
FileReadSec(&fdd_image[drv_sel - 1].file, dma_buffer);
// ... and copy to ram
mist_memory_write_block(dma_buffer);
}
@@ -482,7 +482,7 @@ static void handle_fdc(unsigned char *buffer) {
// read from ram ...
mist_memory_read_block(dma_buffer);
// ... and write to disk
FileWrite(&(fdd_image[drv_sel - 1].file), dma_buffer);
FileWriteSec(&(fdd_image[drv_sel - 1].file), dma_buffer);
}
DISKLED_OFF;
@@ -629,12 +629,13 @@ static void tos_font_load() {
if (file.size == 4096) {
int i;
for (i = 0; i<4; i++) {
FileRead(&file, font + i * 512);
FileNextSector(&file);
FileReadSec(&file, font + i * 512);
}
return;
}
FileClose(&file);
}
// if we couldn't load something, then just convert the
@@ -676,18 +677,17 @@ void tos_load_cartridge(const char *name)
DISKLED_ON;
for (i = 0; i<blocks; i++) {
FileRead(&file, buffer);
FileReadSec(&file, buffer);
if (!(i & 0x7f))
mist_memory_set_address(CART_BASE_ADDRESS + 512 * i, 128, 0);
mist_memory_write_block(buffer);
if (i != blocks - 1)
FileNextSector(&file);
}
DISKLED_OFF;
FileClose(&file);
tos_debugf("%s uploaded", config.cart_img);
return;
}
@@ -757,7 +757,7 @@ void tos_upload(const char *name)
tos_debugf("Uploading ...");
for (i = 0; i<blocks; i++) {
FileRead(&file, buffer);
FileReadSec(&file, buffer);
// copy first 8 bytes to address 0 as well
if (i == 0) {
@@ -776,9 +776,6 @@ void tos_upload(const char *name)
mist_memory_set_address(tos_base + i * 512, 128, 0);
mist_memory_write_block(buffer);
if (i != blocks - 1)
FileNextSector(&file);
}
#if 1
@@ -793,7 +790,7 @@ void tos_upload(const char *name)
if (!(i & 0x7f))
mist_memory_set_address(tos_base + i * 512, 128, 1);
FileRead(&file, b2);
FileReadSec(&file, b2);
mist_memory_read_block(buffer);
ok = -1;
@@ -829,9 +826,6 @@ void tos_upload(const char *name)
for (;;);
}
if (i != blocks - 1)
FileNextSector(&file);
}
printf("Verify: %s\n", ok ? "ok" : "failed");
}
@@ -841,6 +835,8 @@ void tos_upload(const char *name)
tos_debugf("TOS.IMG uploaded in %lu ms (%llu kB/s / %llu kBit/s)",
time >> 20, file.size / (time >> 20), 8 * file.size / (time >> 20));
FileClose(&file);
}
else {
tos_debugf("Unable to find tos.img");