mirror of
https://github.com/parasyte/alt64
synced 2024-11-02 00:05:03 -04:00
minor refactoring of memorypak
This commit is contained in:
parent
3c2a57d057
commit
a73b73c3d5
@ -9,7 +9,7 @@
|
|||||||
//TODO: not sure if this is correct!!!
|
//TODO: not sure if this is correct!!!
|
||||||
extern char *mempak_path;
|
extern char *mempak_path;
|
||||||
|
|
||||||
void file_to_mpk(display_context_t disp, u8 *filename);
|
int file_to_mpk(display_context_t disp, u8 *filename);
|
||||||
void mpk_to_file(display_context_t disp, char *mpk_filename, int quick);
|
void mpk_to_file(display_context_t disp, char *mpk_filename, int quick);
|
||||||
void view_mpk_file(display_context_t disp, char *mpk_filename);
|
void view_mpk_file(display_context_t disp, char *mpk_filename);
|
||||||
void view_mpk(display_context_t disp);
|
void view_mpk(display_context_t disp);
|
||||||
|
103
src/memorypak.c
103
src/memorypak.c
@ -11,10 +11,18 @@
|
|||||||
#include "memorypak.h"
|
#include "memorypak.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "mem.h"
|
#include "debug.h"
|
||||||
#include "strlib.h"
|
#include "strlib.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum MemoryPakFormat
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
DexDrive,
|
||||||
|
Z64
|
||||||
|
};
|
||||||
|
|
||||||
static uint8_t mempak_data[128 * 256];
|
static uint8_t mempak_data[128 * 256];
|
||||||
char *mempak_path;
|
char *mempak_path;
|
||||||
|
|
||||||
@ -89,13 +97,11 @@ 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)
|
int file_to_mpk(display_context_t disp, u8 *filename)
|
||||||
{
|
{
|
||||||
|
enum MemoryPakFormat memorypak_format;
|
||||||
u8 buff[64];
|
u8 buff[64];
|
||||||
|
|
||||||
printText(filename, 9, -1, disp);
|
|
||||||
|
|
||||||
|
|
||||||
FRESULT result;
|
FRESULT result;
|
||||||
FIL file;
|
FIL file;
|
||||||
UINT bytesread;
|
UINT bytesread;
|
||||||
@ -111,32 +117,26 @@ void file_to_mpk(display_context_t disp, u8 *filename)
|
|||||||
|
|
||||||
if (strcmp(buff, "64") == 0)
|
if (strcmp(buff, "64") == 0)
|
||||||
{
|
{
|
||||||
printText("Dexdrive format", 9, -1, disp);
|
TRACE(disp, "Dexdrive format");
|
||||||
printText("skip header", 9, -1, disp);
|
memorypak_format = DexDrive;
|
||||||
|
//skip header
|
||||||
static uint8_t mempak_data_buff[36928];
|
result = f_lseek (
|
||||||
|
&file, /* [IN] File object */
|
||||||
result =
|
4160 /* [IN] File read/write pointer */
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printText("Z64 format", 9, -1, disp);
|
|
||||||
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 */
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACE(disp, "Z64 format");
|
||||||
|
memorypak_format = Z64;
|
||||||
|
|
||||||
|
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);
|
result = f_close(&file);
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@ -145,6 +145,12 @@ void file_to_mpk(display_context_t disp, u8 *filename)
|
|||||||
err |= write_mempak_sector(0, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]);
|
err |= write_mempak_sector(0, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memorypak_format = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)memorypak_format; //TODO: should return enum
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_mpk_file(display_context_t disp, char *mpk_filename)
|
void view_mpk_file(display_context_t disp, char *mpk_filename)
|
||||||
@ -166,32 +172,25 @@ void view_mpk_file(display_context_t disp, char *mpk_filename)
|
|||||||
|
|
||||||
if (strcmp(buff, "64") == 0) //DEXDRIVE format
|
if (strcmp(buff, "64") == 0) //DEXDRIVE format
|
||||||
{
|
{
|
||||||
static uint8_t mempak_data_buff[36928];
|
//skip header
|
||||||
|
result = f_lseek (
|
||||||
result =
|
&file, /* [IN] File object */
|
||||||
f_read (
|
4160 /* [IN] File read/write pointer */
|
||||||
&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);
|
|
||||||
}
|
|
||||||
else //Z64 format
|
|
||||||
{
|
|
||||||
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_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);
|
result = f_close(&file);
|
||||||
|
|
||||||
printText("File content:", 11, 5, disp);
|
printText("File contents:", 11, 5, disp);
|
||||||
printText(" ", 11, -1, disp);
|
printText(" ", 11, -1, disp);
|
||||||
|
|
||||||
int notes_c = 0;
|
int notes_c = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user