mirror of
https://github.com/parasyte/alt64
synced 2025-02-28 09:21:46 -05:00
updated mpk file reads
This commit is contained in:
parent
e805617d99
commit
756fbc15ce
@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "memorypak.h"
|
#include "memorypak.h"
|
||||||
|
#include "ff.h"
|
||||||
#include "fat_old.h"
|
#include "fat_old.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
@ -91,16 +92,19 @@ char ___CountBlocks(char *bMemPakBinary, char *aNoteSizes)
|
|||||||
//old method to write a file to the mempak at controller 1
|
//old method to write a file to the mempak at controller 1
|
||||||
void file_to_mpk(display_context_t disp, u8 *filename)
|
void file_to_mpk(display_context_t disp, u8 *filename)
|
||||||
{
|
{
|
||||||
u8 tmp[32];
|
|
||||||
u8 buff[64];
|
u8 buff[64];
|
||||||
u8 ok = 0;
|
|
||||||
|
|
||||||
printText(filename, 9, -1, disp);
|
printText(filename, 9, -1, disp);
|
||||||
FatRecord rec_tmpf;
|
|
||||||
ok = fatFindRecord(filename, &rec_tmpf, 0);
|
|
||||||
|
|
||||||
u8 resp = 0;
|
|
||||||
resp = fatOpenFileByName(filename, 0);
|
FRESULT result;
|
||||||
|
FIL file;
|
||||||
|
UINT bytesread;
|
||||||
|
result = f_open(&file, filename, FA_READ);
|
||||||
|
|
||||||
|
if (result == FR_OK)
|
||||||
|
{
|
||||||
|
//int fsize = f_size(&file);
|
||||||
|
|
||||||
u8 *pch;
|
u8 *pch;
|
||||||
pch = strrchr(filename, '.');
|
pch = strrchr(filename, '.');
|
||||||
@ -112,50 +116,82 @@ void file_to_mpk(display_context_t disp, u8 *filename)
|
|||||||
printText("skip header", 9, -1, disp);
|
printText("skip header", 9, -1, disp);
|
||||||
|
|
||||||
static uint8_t mempak_data_buff[36928];
|
static uint8_t mempak_data_buff[36928];
|
||||||
resp = fatReadFile(&mempak_data_buff, 36928 / 512);
|
|
||||||
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
&mempak_data_buff, /* [OUT] Buffer to store read data */
|
||||||
|
36928, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
|
|
||||||
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printText("Z64 format", 9, -1, disp);
|
printText("Z64 format", 9, -1, disp);
|
||||||
resp = fatReadFile(&mempak_data, 32768 / 512);
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
&mempak_data, /* [OUT] Buffer to store read data */
|
||||||
|
32768, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
result = f_close(&file);
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
for (int j = 0; j < 128; j++)
|
for (int j = 0; j < 128; j++)
|
||||||
{
|
{
|
||||||
err |= write_mempak_sector(0, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]);
|
err |= write_mempak_sector(0, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_mpk_file(display_context_t disp, char *mpk_filename)
|
void view_mpk_file(display_context_t disp, char *mpk_filename)
|
||||||
{
|
{
|
||||||
u8 tmp[32];
|
|
||||||
u8 buff[64];
|
u8 buff[64];
|
||||||
u8 ok = 0;
|
|
||||||
|
|
||||||
FatRecord rec_tmpf;
|
FRESULT result;
|
||||||
ok = fatFindRecord(mpk_filename, &rec_tmpf, 0);
|
FIL file;
|
||||||
|
UINT bytesread;
|
||||||
|
result = f_open(&file, mpk_filename, FA_READ);
|
||||||
|
|
||||||
u8 resp = 0;
|
if (result == FR_OK)
|
||||||
resp = fatOpenFileByName(mpk_filename, 0);
|
{
|
||||||
|
//int fsize = f_size(&file);
|
||||||
|
|
||||||
u8 *pch;
|
u8 *pch;
|
||||||
pch = strrchr(mpk_filename, '.');
|
pch = strrchr(mpk_filename, '.');
|
||||||
sprintf(buff, "%s", (pch + 2));
|
sprintf(buff, "%s", (pch + 2));
|
||||||
|
|
||||||
if (strcmp(buff, "64") == 0)
|
if (strcmp(buff, "64") == 0) //DEXDRIVE format
|
||||||
{
|
{
|
||||||
static uint8_t mempak_data_buff[36928];
|
static uint8_t mempak_data_buff[36928];
|
||||||
resp = fatReadFile(&mempak_data_buff, 36928 / 512);
|
|
||||||
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
&mempak_data_buff, /* [OUT] Buffer to store read data */
|
||||||
|
36928, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
|
|
||||||
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
||||||
}
|
}
|
||||||
else
|
else //Z64 format
|
||||||
{
|
{
|
||||||
resp = fatReadFile(&mempak_data, 32768 / 512);
|
result =
|
||||||
|
f_read (
|
||||||
|
&file, /* [IN] File object */
|
||||||
|
&mempak_data, /* [OUT] Buffer to store read data */
|
||||||
|
32768, /* [IN] Number of bytes to read */
|
||||||
|
&bytesread /* [OUT] Number of bytes read */
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = f_close(&file);
|
||||||
|
|
||||||
printText("File content:", 11, 5, disp);
|
printText("File content:", 11, 5, disp);
|
||||||
printText(" ", 11, -1, disp);
|
printText(" ", 11, -1, disp);
|
||||||
|
|
||||||
@ -271,6 +307,7 @@ void view_mpk_file(display_context_t disp, char *mpk_filename)
|
|||||||
{
|
{
|
||||||
printText("empty", 11, -1, disp);
|
printText("empty", 11, -1, disp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_mpk(display_context_t disp)
|
void view_mpk(display_context_t disp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user