si: Fix Memory Pak initialization

Thanks to bryc for researching this issue and reviewing this fix
This commit is contained in:
Simon Eriksson 2021-02-19 20:45:45 +01:00 committed by Simon Eriksson
parent 6f9f5784bf
commit a54cbe042f
2 changed files with 12 additions and 8 deletions

View file

@ -109,9 +109,7 @@ uint8_t controller_pak_crc(uint8_t *data) {
}
void controller_pak_format(uint8_t *ptr) {
off_t pos;
static uint8_t init[] = {
static uint8_t init_id_area[] = {
0x81, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x1A, 0x5F, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -128,12 +126,16 @@ void controller_pak_format(uint8_t *ptr) {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xFF, 0x66, 0x25, 0x99, 0xCD,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x71, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
};
memcpy(ptr, init, sizeof(init));
for (pos = sizeof(init); pos < MEMPAK_SIZE; pos += 2) {
ptr[pos+0] = 0x00;
ptr[pos+1] = 0x03;
memset(ptr, 0, MEMPAK_SIZE);
memcpy(ptr, init_id_area, sizeof(init_id_area));
ptr[(MEMPAK_PAGE_SIZE * 1) + 1] = 0x71;
ptr[(MEMPAK_PAGE_SIZE * 2) + 1] = 0x71;
for (off_t i = 5; i < MEMPAK_NUM_PAGES; i++) {
ptr[(MEMPAK_PAGE_SIZE * 1) + (i * 2) + 1] = 0x03;
ptr[(MEMPAK_PAGE_SIZE * 2) + (i * 2) + 1] = 0x03;
}
}

View file

@ -16,6 +16,8 @@
#include "gb.h"
#define MEMPAK_SIZE 0x8000
#define MEMPAK_NUM_PAGES 128
#define MEMPAK_PAGE_SIZE (MEMPAK_SIZE / MEMPAK_NUM_PAGES)
enum pak_type {
PAK_NONE = 0,