add info structure

could be worse!
This commit is contained in:
Robin Jones 2024-03-19 19:14:04 +00:00
parent d21328b491
commit ecd131b7a4
3 changed files with 36 additions and 5 deletions

View File

@ -14,7 +14,16 @@ cpak_err_t cpak_info_load(uint8_t port, cpak_info_t *cpak_info)
return CONTROLLER_PAK_ERR_INVALID;
}
// TODO: implementation.
for (int j = 0; j < 16; j++)
{
entry_structure_t entry;
get_mempak_entry(port, j, &entry);
cpak_info->entries[j] = entry;
}
cpak_info->free_space = get_mempak_free_space(port);
return CONTROLLER_PAK_OK;
}

View File

@ -20,8 +20,9 @@ typedef enum {
/** @brief Controller Pak Information Structure. */
typedef struct {
// header
// pages
entry_structure_t entries[16];
int free_space;
} cpak_info_t;
cpak_err_t cpak_info_load(uint8_t port, cpak_info_t *cpak_info);

View File

@ -2,6 +2,22 @@
#include "../cpak_handler.h"
static int accessory_is_cpak[4];
static cpak_info_t cpak_info;
static char *format_entries_info(entry_structure_t *entries) {
// for (int j = 0; j < 16; j++)
// {
// if (entries[j].valid)
// {
// sprintf(buffer + strlen(buffer), "%s - %d blocks\n", entries[j].name, entries[j].blocks);
// }
// else
// {
// sprintf(buffer + strlen(buffer), "(EMPTY)\n");
// }
// }
return " unknown.";
}
static void process (menu_t *menu) {
@ -10,6 +26,8 @@ static void process (menu_t *menu) {
accessory_is_cpak[port] = joypad_get_accessory_type(port) == JOYPAD_ACCESSORY_TYPE_CONTROLLER_PAK;
}
cpak_info_load(0, &cpak_info);
if (menu->actions.enter) {
// TODO: handle all ports
if (accessory_is_cpak[0]) {
@ -43,8 +61,11 @@ static void draw (menu_t *menu, surface_t *d) {
ALIGN_LEFT, VALIGN_TOP,
"\n"
"\n"
"Clone Controller Pak (1) to SD Card.\n"
"If it is available.\n"
"Controller Pak (1).\n"
"Free space: %d blocks"
"Entries: \n%s",
cpak_info.free_space,
format_entries_info(cpak_info.entries)
);
if (accessory_is_cpak[0]) {