#include <stddef.h>
#include <stdio.h>
+#define JUMPNRUN_PATH "/hackio"
+
typedef struct jumpnrun_level_header {
uint16_t tile_count;
uint16_t item_count;
#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \
memset(&(lv), 0, sizeof(lv)); \
FIL fd; \
- if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \
+ if(FR_OK != f_chdir(JUMPNRUN_PATH) || \
+ FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \
return JUMPNRUN_ERROR; \
} \
if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \
uint8_t progress = 0;
FIL fd;
- if(FR_OK == f_open(&fd, PROGRESS_FNAME, FA_OPEN_EXISTING | FA_READ)) {
+
+ if(FR_OK == f_chdir(JUMPNRUN_PATH) &&
+ FR_OK == f_open(&fd, PROGRESS_FNAME, FA_OPEN_EXISTING | FA_READ)) {
UINT bytes;
f_read(&fd, &progress, sizeof(progress), &bytes);
f_close(&fd);
static void jumpnrun_save_progress(uint8_t progress) {
FIL fd;
- if(FR_OK == f_open(&fd, PROGRESS_FNAME, FA_CREATE_ALWAYS | FA_WRITE)) {
+ if(FR_OK == f_chdir(JUMPNRUN_PATH) &&
+ FR_OK == f_open(&fd, PROGRESS_FNAME, FA_CREATE_ALWAYS | FA_WRITE)) {
UINT bytes;
f_write(&fd, &progress, sizeof(progress), &bytes);
f_close(&fd);
static uint8_t jumpnrun_pick_level(char *buf, size_t *first_visible, size_t *selected, uint8_t progress) {
FIL fd;
- if(FR_OK != f_open(&fd, "levels.lst", FA_OPEN_EXISTING | FA_READ)) {
+ if(FR_OK != f_chdir(JUMPNRUN_PATH) ||
+ FR_OK != f_open(&fd, "levels.lst", FA_OPEN_EXISTING | FA_READ)) {
return JUMPNRUN_ERROR;
}