Skip to content

Commit f43fc9b

Browse files
committed
Improved the handling of paths throughout the application
1 parent 59b0767 commit f43fc9b

File tree

11 files changed

+99
-70
lines changed

11 files changed

+99
-70
lines changed

components/odroid/odroid_display.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ void odroid_display_write(short left, short top, short width, short height, uint
7777
void odroid_display_clear(uint16_t colorLE);
7878
void odroid_display_show_hourglass();
7979

80-
#define ili9341_write_frame_rectangleLE odroid_display_write

components/odroid/odroid_overlay.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void odroid_overlay_draw_text(uint16_t x_pos, uint16_t y_pos, uint16_t width, ch
7070
x_offset += ODROID_FONT_WIDTH;
7171
}
7272

73-
ili9341_write_frame_rectangleLE(x_pos, y_pos, width, ODROID_FONT_HEIGHT, overlay_buffer);
73+
odroid_display_write(x_pos, y_pos, width, ODROID_FONT_HEIGHT, overlay_buffer);
7474
}
7575

7676
void odroid_overlay_draw_rect(int x, int y, int width, int height, int border, uint16_t color)
@@ -83,10 +83,10 @@ void odroid_overlay_draw_rect(int x, int y, int width, int height, int border, u
8383
{
8484
overlay_buffer[i] = color;
8585
}
86-
ili9341_write_frame_rectangleLE(x, y, width, border, overlay_buffer); // T
87-
ili9341_write_frame_rectangleLE(x, y + height - border, width, border, overlay_buffer); // B
88-
ili9341_write_frame_rectangleLE(x, y, border, height, overlay_buffer); // L
89-
ili9341_write_frame_rectangleLE(x + width - border, y, border, height, overlay_buffer); // R
86+
odroid_display_write(x, y, width, border, overlay_buffer); // T
87+
odroid_display_write(x, y + height - border, width, border, overlay_buffer); // B
88+
odroid_display_write(x, y, border, height, overlay_buffer); // L
89+
odroid_display_write(x + width - border, y, border, height, overlay_buffer); // R
9090
}
9191

9292
void odroid_overlay_draw_fill_rect(int x, int y, int width, int height, uint16_t color)
@@ -105,7 +105,7 @@ void odroid_overlay_draw_fill_rect(int x, int y, int width, int height, uint16_t
105105
while (y_pos < y_end)
106106
{
107107
int thickness = (y_end - y_pos >= 16) ? 16 : (y_end - y_pos);
108-
ili9341_write_frame_rectangleLE(x, y_pos, width, thickness, overlay_buffer);
108+
odroid_display_write(x, y_pos, width, thickness, overlay_buffer);
109109
y_pos += 16;
110110
}
111111
}

components/odroid/odroid_sdcard.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <unistd.h>
99
#include <sys/stat.h>
1010
#include <ctype.h>
11+
#include <errno.h>
1112

1213
#include "../miniz/miniz.h"
1314

@@ -136,7 +137,7 @@ size_t odroid_sdcard_copy_file_to_memory(const char* path, void* buf, size_t buf
136137
FILE* f = fopen(path, "rb");
137138
if (f == NULL)
138139
{
139-
printf("%s: fopen failed.\n", __func__);
140+
printf("%s: fopen failed. path='%s'\n", __func__, path);
140141
return 0;
141142
}
142143

@@ -204,28 +205,40 @@ const char* odroid_sdcard_get_extension(const char* path)
204205

205206
int odroid_sdcard_mkdir(char *dir)
206207
{
207-
if (!isOpen)
208+
int ret = mkdir(dir, 0777);
209+
210+
if (ret == -1)
208211
{
209-
printf("odroid_sdcard_mkdir: not open.\n");
210-
return 0;
211-
}
212+
if (errno == EEXIST)
213+
{
214+
printf("odroid_sdcard_mkdir: Folder exists %s\n", dir);
215+
return 0;
216+
}
212217

213-
char tmp[128];
214-
size_t len = strlen(tmp);
218+
char tmp[128];
219+
size_t len = strlen(tmp);
215220

216-
strcpy(tmp, dir);
217-
if (tmp[len - 1] == '/') {
218-
tmp[len - 1] = 0;
219-
}
221+
strcpy(tmp, dir);
222+
if (tmp[len - 1] == '/') {
223+
tmp[len - 1] = 0;
224+
}
220225

221-
for (char *p = tmp + strlen(SD_BASE_PATH) + 1; *p; p++) {
222-
if (*p == '/') {
223-
*p = 0;
224-
printf("odroid_sdcard_mkdir: Creating %s\n", tmp);
225-
mkdir(tmp, 0777);
226-
*p = '/';
226+
for (char *p = tmp + strlen(SD_BASE_PATH) + 1; *p; p++) {
227+
if (*p == '/') {
228+
*p = 0;
229+
printf("odroid_sdcard_mkdir: Creating %s\n", tmp);
230+
mkdir(tmp, 0777);
231+
*p = '/';
232+
}
227233
}
234+
235+
ret = mkdir(tmp, 0777);
228236
}
229237

230-
return mkdir(tmp, 0777);
238+
if (ret == 0)
239+
{
240+
printf("odroid_sdcard_mkdir: Folder created %s\n", dir);
241+
}
242+
243+
return ret;
231244
}

components/odroid/odroid_system.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,43 @@ void odroid_system_gpio_init()
126126

127127
char* odroid_system_get_path(char *_romPath, emu_path_type_t type)
128128
{
129-
const char* fileName = strstr(_romPath ?: romPath, "/roms/");
130-
char *buffer = malloc(strlen(fileName) + 32);
129+
char* fileName = strstr(_romPath ?: romPath, ODROID_BASE_PATH_ROMS);
130+
char *buffer = malloc(128); // Lazy arbitrary length...
131131

132132
if (!fileName)
133133
{
134134
printf("%s: Invalid rom path.\n", __func__);
135135
abort();
136136
}
137137

138-
strcpy(buffer, SD_BASE_PATH);
138+
fileName += strlen(ODROID_BASE_PATH_ROMS);
139139

140140
switch (type)
141141
{
142142
case ODROID_PATH_SAVE_STATE:
143143
case ODROID_PATH_SAVE_STATE_1:
144144
case ODROID_PATH_SAVE_STATE_2:
145145
case ODROID_PATH_SAVE_STATE_3:
146-
strcat(buffer, "/odroid/data/");
147-
strcat(buffer, fileName + 6);
146+
strcpy(buffer, ODROID_BASE_PATH_SAVES);
147+
strcat(buffer, fileName);
148148
strcat(buffer, ".sav");
149149
break;
150150

151151
case ODROID_PATH_SAVE_SRAM:
152-
strcat(buffer, "/odroid/data/");
153-
strcat(buffer, fileName + 6);
152+
strcpy(buffer, ODROID_BASE_PATH_SAVES);
153+
strcat(buffer, fileName);
154154
strcat(buffer, ".sram");
155155
break;
156156

157157
case ODROID_PATH_ROM_FILE:
158+
strcpy(buffer, ODROID_BASE_PATH_ROMS);
159+
strcat(buffer, fileName);
160+
break;
161+
162+
case ODROID_PATH_CRC_CACHE:
163+
strcpy(buffer, ODROID_BASE_PATH_CRC_CACHE);
158164
strcat(buffer, fileName);
165+
strcat(buffer, ".crc");
159166
break;
160167

161168
default:

components/odroid/odroid_system.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ typedef struct
2323
state_handler_t save;
2424
} emu_state_t;
2525

26+
#define ODROID_BASE_PATH_ROMS SD_BASE_PATH "/roms"
27+
#define ODROID_BASE_PATH_SAVES SD_BASE_PATH "/odroid/data"
28+
#define ODROID_BASE_PATH_ROMART SD_BASE_PATH "/romart"
29+
#define ODROID_BASE_PATH_CRC_CACHE SD_BASE_PATH "/odroid/cache/crc"
30+
2631
typedef enum
2732
{
2833
ODROID_PATH_SAVE_STATE = 0,
@@ -32,6 +37,7 @@ typedef enum
3237
ODROID_PATH_SAVE_SRAM,
3338
ODROID_PATH_ROM_FILE,
3439
ODROID_PATH_ART_FILE,
40+
ODROID_PATH_CRC_CACHE,
3541
} emu_path_type_t;
3642

3743
typedef enum

gnuboy-go/components/gnuboy/lcd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,6 @@ static void pal_detect_dmg()
696696
uint8_t palette = colorization_palette_info[infoIdx] & 0x1F;
697697
uint8_t flags = (colorization_palette_info[infoIdx] & 0xE0) >> 5;
698698

699-
printf("DETECTED PALETTE: %d\n", palette);
700-
701699
bgp = dmg_game_palettes[palette][2];
702700
obp0 = dmg_game_palettes[palette][(flags & 1) ? 0 : 1];
703701
obp1 = dmg_game_palettes[palette][(flags & 2) ? 0 : 1];
@@ -706,6 +704,8 @@ static void pal_detect_dmg()
706704
obp1 = dmg_game_palettes[palette][2];
707705
}
708706

707+
printf("pal_detect_dmg: Using GBC palette %d\n", palette);
708+
709709
memcpy(&dmg_pal[0], bgp, 8); // BGP
710710
memcpy(&dmg_pal[1], bgp, 8); // BGP
711711
memcpy(&dmg_pal[2], obp0, 8); // OBP0

gnuboy-go/components/gnuboy/loader.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,39 +296,47 @@ int rom_load()
296296

297297
int sram_load()
298298
{
299+
int ret = -1;
299300
FILE *f;
300301

301302
if (!mbc.batt || !sramfile || !*sramfile) return -1;
302303

304+
odroid_system_spi_lock_acquire(SPI_LOCK_SDCARD);
305+
303306
if ((f = fopen(sramfile, "rb")))
304307
{
305308
printf("sram_load: Loading SRAM\n");
306309
fread(ram.sbank, 8192, mbc.ramsize, f);
307310
rtc_load_internal(f); // Temporary hack, hopefully
308311
fclose(f);
309-
return 0;
312+
ret = 0;
310313
}
311314

312-
return -1;
315+
odroid_system_spi_lock_release(SPI_LOCK_SDCARD);
316+
return ret;
313317
}
314318

315319

316320
int sram_save()
317321
{
322+
int ret = -1;
318323
FILE *f;
319324

320325
if (!mbc.batt || !sramfile || !mbc.ramsize) return -1;
321326

327+
odroid_system_spi_lock_acquire(SPI_LOCK_SDCARD);
328+
322329
if ((f = fopen(sramfile, "wb")))
323330
{
324331
printf("sram_load: Saving SRAM\n");
325332
fwrite(ram.sbank, 8192, mbc.ramsize, f);
326333
rtc_save_internal(f); // Temporary hack, hopefully
327334
fclose(f);
328-
return 0;
335+
ret = 0;
329336
}
330337

331-
return -1;
338+
odroid_system_spi_lock_release(SPI_LOCK_SDCARD);
339+
return ret;
332340
}
333341

334342

gnuboy-go/main/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ void app_main(void)
330330

331331
if (sramSaveTimer > 0 && --sramSaveTimer == 0)
332332
{
333-
odroid_system_spi_lock_acquire(SPI_LOCK_SDCARD);
334333
sram_save();
335-
odroid_system_spi_lock_release(SPI_LOCK_SDCARD);
336334
}
337335
}
338336

retro-go/main/emulators.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,21 @@ void emulators_init_emu(retro_emulator_t *emu)
5454
return;
5555
}
5656

57+
printf("emulators_init_emu: Initializing %s\n", emu->system_name);
58+
5759
emu->initialized = true;
5860

5961
char path[128];
6062

6163
odroid_system_spi_lock_acquire(SPI_LOCK_SDCARD);
6264

63-
sprintf(path, SAVE_PATH "/%s", emu->dirname);
65+
sprintf(path, ODROID_BASE_PATH_CRC_CACHE "/%s", emu->dirname);
66+
odroid_sdcard_mkdir(path);
67+
68+
sprintf(path, ODROID_BASE_PATH_SAVES "/%s", emu->dirname);
6469
odroid_sdcard_mkdir(path);
6570

66-
sprintf(path, ROM_PATH "/%s", emu->dirname);
71+
sprintf(path, ODROID_BASE_PATH_ROMS "/%s", emu->dirname);
6772
odroid_sdcard_mkdir(path);
6873

6974
DIR* dir = opendir(path);

retro-go/main/emulators.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
#include <stdint.h>
55
#include <stdbool.h>
66

7-
#define ROM_PATH SD_BASE_PATH "/roms"
8-
#define SAVE_PATH SD_BASE_PATH "/odroid/data"
9-
#define CACHE_PATH SD_BASE_PATH "/odroid/cache"
10-
#define ROMART_PATH SD_BASE_PATH "/romart"
11-
127
typedef struct {
13-
char name[64];
8+
char name[96];
149
char ext[8];
15-
char path[96];
10+
char path[128];
1611
uint32_t checksum;
1712
} retro_emulator_file_t;
1813

0 commit comments

Comments
 (0)