updated mpk file reads
This commit is contained in:
parent
e805617d99
commit
756fbc15ce
331
src/memorypak.c
331
src/memorypak.c
@ -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,185 +92,221 @@ 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);
|
|
||||||
|
FRESULT result;
|
||||||
|
FIL file;
|
||||||
|
UINT bytesread;
|
||||||
|
result = f_open(&file, filename, FA_READ);
|
||||||
|
|
||||||
u8 resp = 0;
|
if (result == FR_OK)
|
||||||
resp = fatOpenFileByName(filename, 0);
|
|
||||||
|
|
||||||
u8 *pch;
|
|
||||||
pch = strrchr(filename, '.');
|
|
||||||
sprintf(buff, "%s", (pch + 2));
|
|
||||||
|
|
||||||
if (strcmp(buff, "64") == 0)
|
|
||||||
{
|
{
|
||||||
printText("Dexdrive format", 9, -1, disp);
|
//int fsize = f_size(&file);
|
||||||
printText("skip header", 9, -1, disp);
|
|
||||||
|
|
||||||
static uint8_t mempak_data_buff[36928];
|
u8 *pch;
|
||||||
resp = fatReadFile(&mempak_data_buff, 36928 / 512);
|
pch = strrchr(filename, '.');
|
||||||
|
sprintf(buff, "%s", (pch + 2));
|
||||||
|
|
||||||
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
if (strcmp(buff, "64") == 0)
|
||||||
}
|
{
|
||||||
else
|
printText("Dexdrive format", 9, -1, disp);
|
||||||
{
|
printText("skip header", 9, -1, disp);
|
||||||
printText("Z64 format", 9, -1, disp);
|
|
||||||
resp = fatReadFile(&mempak_data, 32768 / 512);
|
|
||||||
}
|
|
||||||
|
|
||||||
int err = 0;
|
static uint8_t mempak_data_buff[36928];
|
||||||
for (int j = 0; j < 128; j++)
|
|
||||||
{
|
result =
|
||||||
err |= write_mempak_sector(0, j, &mempak_data[j * MEMPAK_BLOCK_SIZE]);
|
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 */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
result = f_close(&file);
|
||||||
|
|
||||||
|
int err = 0;
|
||||||
|
for (int j = 0; j < 128; j++)
|
||||||
|
{
|
||||||
|
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);
|
|
||||||
|
|
||||||
u8 *pch;
|
|
||||||
pch = strrchr(mpk_filename, '.');
|
|
||||||
sprintf(buff, "%s", (pch + 2));
|
|
||||||
|
|
||||||
if (strcmp(buff, "64") == 0)
|
|
||||||
{
|
{
|
||||||
static uint8_t mempak_data_buff[36928];
|
//int fsize = f_size(&file);
|
||||||
resp = fatReadFile(&mempak_data_buff, 36928 / 512);
|
|
||||||
memcpy(&mempak_data, mempak_data_buff + 4160, 32768);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resp = fatReadFile(&mempak_data, 32768 / 512);
|
|
||||||
}
|
|
||||||
|
|
||||||
printText("File content:", 11, 5, disp);
|
u8 *pch;
|
||||||
printText(" ", 11, -1, disp);
|
pch = strrchr(mpk_filename, '.');
|
||||||
|
sprintf(buff, "%s", (pch + 2));
|
||||||
|
|
||||||
int notes_c = 0;
|
if (strcmp(buff, "64") == 0) //DEXDRIVE format
|
||||||
|
|
||||||
char szBuffer[40],
|
|
||||||
cAppendix;
|
|
||||||
int bFirstChar;
|
|
||||||
|
|
||||||
int i = 0,
|
|
||||||
nNotes = 0,
|
|
||||||
iSum = 0,
|
|
||||||
iRemainingBlocks;
|
|
||||||
|
|
||||||
char aNoteSizes[16];
|
|
||||||
|
|
||||||
for (i = 0x10A; i < 0x200; i++)
|
|
||||||
iSum += mempak_data[i];
|
|
||||||
|
|
||||||
if (((iSum % 256) == mempak_data[0x101]))
|
|
||||||
{
|
|
||||||
iRemainingBlocks = ___CountBlocks(mempak_data, aNoteSizes);
|
|
||||||
|
|
||||||
if (iRemainingBlocks <= 123)
|
|
||||||
{
|
{
|
||||||
for (notes_c = 0; notes_c < 16; notes_c++)
|
static uint8_t mempak_data_buff[36928];
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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_close(&file);
|
||||||
|
|
||||||
|
printText("File content:", 11, 5, disp);
|
||||||
|
printText(" ", 11, -1, disp);
|
||||||
|
|
||||||
|
int notes_c = 0;
|
||||||
|
|
||||||
|
char szBuffer[40],
|
||||||
|
cAppendix;
|
||||||
|
int bFirstChar;
|
||||||
|
|
||||||
|
int i = 0,
|
||||||
|
nNotes = 0,
|
||||||
|
iSum = 0,
|
||||||
|
iRemainingBlocks;
|
||||||
|
|
||||||
|
char aNoteSizes[16];
|
||||||
|
|
||||||
|
for (i = 0x10A; i < 0x200; i++)
|
||||||
|
iSum += mempak_data[i];
|
||||||
|
|
||||||
|
if (((iSum % 256) == mempak_data[0x101]))
|
||||||
|
{
|
||||||
|
iRemainingBlocks = ___CountBlocks(mempak_data, aNoteSizes);
|
||||||
|
|
||||||
|
if (iRemainingBlocks <= 123)
|
||||||
{
|
{
|
||||||
if (mempak_data[0x300 + (notes_c * 32)] ||
|
for (notes_c = 0; notes_c < 16; notes_c++)
|
||||||
mempak_data[0x301 + (notes_c * 32)] ||
|
|
||||||
mempak_data[0x302 + (notes_c * 32)])
|
|
||||||
{
|
{
|
||||||
cAppendix = ___TranslateNotes(&mempak_data[0x300 + (notes_c * 32)], szBuffer);
|
if (mempak_data[0x300 + (notes_c * 32)] ||
|
||||||
|
mempak_data[0x301 + (notes_c * 32)] ||
|
||||||
if (cAppendix != '\0')
|
mempak_data[0x302 + (notes_c * 32)])
|
||||||
sprintf(szBuffer, "%s. %c", szBuffer, cAppendix);
|
|
||||||
|
|
||||||
bFirstChar = 1;
|
|
||||||
for (i = 0; i < (int)strlen(szBuffer); i++)
|
|
||||||
{
|
{
|
||||||
if (szBuffer[i] == ' ')
|
cAppendix = ___TranslateNotes(&mempak_data[0x300 + (notes_c * 32)], szBuffer);
|
||||||
bFirstChar = 1;
|
|
||||||
else
|
if (cAppendix != '\0')
|
||||||
|
sprintf(szBuffer, "%s. %c", szBuffer, cAppendix);
|
||||||
|
|
||||||
|
bFirstChar = 1;
|
||||||
|
for (i = 0; i < (int)strlen(szBuffer); i++)
|
||||||
{
|
{
|
||||||
if (bFirstChar && (szBuffer[i] >= 'a') && (szBuffer[i] <= 'z'))
|
if (szBuffer[i] == ' ')
|
||||||
|
bFirstChar = 1;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
bFirstChar = 0;
|
if (bFirstChar && (szBuffer[i] >= 'a') && (szBuffer[i] <= 'z'))
|
||||||
szBuffer[i] -= 0x20;
|
{
|
||||||
|
bFirstChar = 0;
|
||||||
|
szBuffer[i] -= 0x20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
printText(szBuffer, 11, -1, disp);
|
||||||
printText(szBuffer, 11, -1, disp);
|
|
||||||
|
|
||||||
switch (mempak_data[0x303 + (notes_c * 32)])
|
switch (mempak_data[0x303 + (notes_c * 32)])
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
sprintf(szBuffer, "None");
|
sprintf(szBuffer, "None");
|
||||||
break;
|
break;
|
||||||
case 0x37:
|
case 0x37:
|
||||||
sprintf(szBuffer, "Beta");
|
sprintf(szBuffer, "Beta");
|
||||||
break;
|
break;
|
||||||
case 0x41:
|
case 0x41:
|
||||||
sprintf(szBuffer, "NTSC");
|
sprintf(szBuffer, "NTSC");
|
||||||
break;
|
break;
|
||||||
case 0x44:
|
case 0x44:
|
||||||
sprintf(szBuffer, "Germany");
|
sprintf(szBuffer, "Germany");
|
||||||
break;
|
break;
|
||||||
case 0x45:
|
case 0x45:
|
||||||
sprintf(szBuffer, "USA");
|
sprintf(szBuffer, "USA");
|
||||||
break;
|
break;
|
||||||
case 0x46:
|
case 0x46:
|
||||||
sprintf(szBuffer, "France");
|
sprintf(szBuffer, "France");
|
||||||
break;
|
break;
|
||||||
case 0x49:
|
case 0x49:
|
||||||
sprintf(szBuffer, "Italy");
|
sprintf(szBuffer, "Italy");
|
||||||
break;
|
break;
|
||||||
case 0x4A:
|
case 0x4A:
|
||||||
sprintf(szBuffer, "Japan");
|
sprintf(szBuffer, "Japan");
|
||||||
break;
|
break;
|
||||||
case 0x50:
|
case 0x50:
|
||||||
sprintf(szBuffer, "Europe");
|
sprintf(szBuffer, "Europe");
|
||||||
break;
|
break;
|
||||||
case 0x53:
|
case 0x53:
|
||||||
sprintf(szBuffer, "Spain");
|
sprintf(szBuffer, "Spain");
|
||||||
break;
|
break;
|
||||||
case 0x55:
|
case 0x55:
|
||||||
sprintf(szBuffer, "Australia");
|
sprintf(szBuffer, "Australia");
|
||||||
break;
|
break;
|
||||||
case 0x58:
|
case 0x58:
|
||||||
case 0x59:
|
case 0x59:
|
||||||
sprintf(szBuffer, "PAL");
|
sprintf(szBuffer, "PAL");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf(szBuffer, "Unknown(%02X)", mempak_data[0x303 + (notes_c * 32)]);
|
sprintf(szBuffer, "Unknown(%02X)", mempak_data[0x303 + (notes_c * 32)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(szBuffer, "%i", aNoteSizes[notes_c]);
|
sprintf(szBuffer, "%i", aNoteSizes[notes_c]);
|
||||||
nNotes++;
|
nNotes++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int free_c = 0;
|
||||||
|
for (free_c = nNotes; free_c < 16; free_c++)
|
||||||
|
printText("[free]", 11, -1, disp);
|
||||||
|
|
||||||
|
char buff[512];
|
||||||
|
printText(" ", 11, -1, disp);
|
||||||
|
printText("Free space:", 11, -1, disp);
|
||||||
|
sprintf(buff, "%i blocks", iRemainingBlocks);
|
||||||
|
printText(buff, 11, -1, disp);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
int free_c = 0;
|
{
|
||||||
for (free_c = nNotes; free_c < 16; free_c++)
|
printText("empty", 11, -1, disp);
|
||||||
printText("[free]", 11, -1, disp);
|
}
|
||||||
|
|
||||||
char buff[512];
|
|
||||||
printText(" ", 11, -1, disp);
|
|
||||||
printText("Free space:", 11, -1, disp);
|
|
||||||
sprintf(buff, "%i blocks", iRemainingBlocks);
|
|
||||||
printText(buff, 11, -1, disp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printText("empty", 11, -1, disp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user