1
0
mirror of https://github.com/parasyte/alt64 synced 2024-11-02 08:15:07 -04:00

minor refactoring of memorypak

This commit is contained in:
Robin Jones 2017-10-20 16:31:32 +01:00
parent 3c2a57d057
commit a73b73c3d5
2 changed files with 52 additions and 53 deletions

View File

@ -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);

View File

@ -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,24 +117,18 @@ 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 (
result =
f_read (
&file, /* [IN] File object */ &file, /* [IN] File object */
&mempak_data_buff, /* [OUT] Buffer to store read data */ 4160 /* [IN] File read/write pointer */
36928, /* [IN] Number of bytes to read */
&bytesread /* [OUT] Number of bytes read */
); );
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
} }
else
{ TRACE(disp, "Z64 format");
printText("Z64 format", 9, -1, disp); memorypak_format = Z64;
result = result =
f_read ( f_read (
&file, /* [IN] File object */ &file, /* [IN] File object */
@ -136,7 +136,7 @@ void file_to_mpk(display_context_t disp, u8 *filename)
32768, /* [IN] Number of bytes to read */ 32768, /* [IN] Number of bytes to read */
&bytesread /* [OUT] Number of bytes 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,20 +172,13 @@ 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 =
f_read (
&file, /* [IN] File object */ &file, /* [IN] File object */
&mempak_data_buff, /* [OUT] Buffer to store read data */ 4160 /* [IN] File read/write pointer */
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 = result =
f_read ( f_read (
&file, /* [IN] File object */ &file, /* [IN] File object */
@ -187,11 +186,11 @@ void view_mpk_file(display_context_t disp, char *mpk_filename)
32768, /* [IN] Number of bytes to read */ 32768, /* [IN] Number of bytes to read */
&bytesread /* [OUT] Number of bytes 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;