Skip to content

Commit 97fa581

Browse files
committed
Fri 26 Jul 2019 17:13:21 EDT - File performance and '#14'
1 parent b4f3103 commit 97fa581

File tree

8 files changed

+125
-101
lines changed

8 files changed

+125
-101
lines changed

Assets/retro-esp32/folder.gif

1.1 KB
Loading

Assets/retro-esp32/folder.jpg

1.29 KB
Loading

Firmware/Bins/retro-esp32.bin

-48 Bytes
Binary file not shown.

Launchers/retro-esp32/main/includes/declarations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void draw_options();
5151
*/
5252
void get_files();
5353
void sort_files(char** files);
54-
void draw_files(char** files);
54+
void draw_files();
5555
void has_save_file(char *name);
5656

5757
/*

Launchers/retro-esp32/main/includes/definitions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@
2424
/*
2525
Emulator Count + 1 for Theme
2626
*/
27-
#define COUNT 11
27+
#define COUNT 11
28+
29+
/*
30+
31+
*/
32+
#define MAX_FILES 2048

Launchers/retro-esp32/main/includes/structures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ OFFSET ORIGIN = {16,48};
1818
// LIST
1919
typedef struct{
2020
int limit;
21-
int8_t offset;
21+
int16_t offset;
2222
int total;
2323
int pages;
2424
int page;

Launchers/retro-esp32/main/main.c

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
bool SAVED = false;
1717
int8_t USER;
1818
bool RESTART = false;
19+
char** FILES;
20+
DIR *directory;
21+
struct dirent *file;
1922
//}#pragma endregion Global
2023

2124
//{#pragma region Emulator and Directories
@@ -93,7 +96,10 @@
9396
odroid_input_gamepad_init();
9497

9598
// Battery
96-
odroid_input_battery_level_init();
99+
odroid_input_battery_level_init();
100+
101+
// SD
102+
odroid_sdcard_open("/sd");
97103

98104
// Theme
99105
get_theme();
@@ -158,8 +164,10 @@
158164
STEP = 0;
159165
}
160166
nvs_close(handle);
167+
printf("\nGet nvs_get_i8:%d\n", STEP);
161168
}
162169
void set_step_state() {
170+
printf("\nGet nvs_set_i8:%d\n", STEP);
163171
nvs_handle handle;
164172
nvs_open("storage", NVS_READWRITE, &handle);
165173
nvs_set_i8(handle, "STEP", STEP);
@@ -177,8 +185,7 @@
177185

178186
nvs_handle handle;
179187
err = nvs_open("storage", NVS_READWRITE, &handle);
180-
181-
err = nvs_get_i8(handle, "OFFSET", &ROMS.offset);
188+
err = nvs_get_i16(handle, "LAST", &ROMS.offset);
182189
switch (err) {
183190
case ESP_OK:
184191
break;
@@ -189,13 +196,16 @@
189196
ROMS.offset = 0;
190197
}
191198
nvs_close(handle);
199+
printf("\nGet nvs_get_i16:%d\n", ROMS.offset);
192200
}
193201
void set_list_state() {
202+
printf("\nSet nvs_set_i16:%d", ROMS.offset);
194203
nvs_handle handle;
195204
nvs_open("storage", NVS_READWRITE, &handle);
196-
nvs_set_i8(handle, "OFFSET", ROMS.offset);
205+
nvs_set_i16(handle, "LAST", ROMS.offset);
197206
nvs_commit(handle);
198207
nvs_close(handle);
208+
get_list_state();
199209
}
200210

201211
void set_restore_states() {
@@ -348,24 +358,12 @@
348358
void draw_media(int x, int y, bool current) {
349359
int offset = (STEP-1) * 16;
350360
int i = 0;
351-
if(current) {
352-
for(int h = 0; h < 16; h++) {
353-
for(int w = offset; w < (offset+16); w++) {
354-
buffer[i] = media[h][w] == WHITE ? GUI.fg : GUI.bg;
355-
i++;
356-
}
357-
}
358-
ili9341_write_frame_rectangleLE(x+1, y+1, 16, 16, buffer);
359-
}
360-
i = 0;
361361
for(int h = 0; h < 16; h++) {
362362
for(int w = offset; w < (offset+16); w++) {
363363
buffer[i] = media[h][w] == WHITE ? current ? WHITE : GUI.fg : GUI.bg;
364364
i++;
365365
}
366366
}
367-
current ?
368-
ili9341_write_frame_rectangleLE(x-1, y-1, 16, 16, buffer) :
369367
ili9341_write_frame_rectangleLE(x, y, 16, 16, buffer);
370368
}
371369

@@ -491,65 +489,59 @@
491489
//}#pragma endregion GUI
492490

493491
//{#pragma region Files
494-
inline static void swap(char** a, char** b)
495-
{
496-
char* t = *a;
497-
*a = *b;
498-
*b = t;
499-
}
492+
//{#pragma region Sort
493+
inline static void swap(char** a, char** b) {
494+
char* t = *a;
495+
*a = *b;
496+
*b = t;
497+
}
500498

501-
static int strcicmp(char const *a, char const *b)
502-
{
503-
for (;; a++, b++)
504-
{
505-
int d = tolower((int)*a) - tolower((int)*b);
506-
if (d != 0 || !*a) return d;
507-
}
508-
}
499+
static int strcicmp(char const *a, char const *b) {
500+
for (;; a++, b++)
501+
{
502+
int d = tolower((int)*a) - tolower((int)*b);
503+
if (d != 0 || !*a) return d;
504+
}
505+
}
509506

510-
static int partition (char* arr[], int low, int high)
511-
{
512-
char* pivot = arr[high];
513-
int i = (low - 1);
514-
515-
for (int j = low; j <= high- 1; j++)
516-
{
517-
if (strcicmp(arr[j], pivot) < 0)
518-
{
519-
i++;
520-
swap(&arr[i], &arr[j]);
521-
}
522-
}
523-
swap(&arr[i + 1], &arr[high]);
524-
return (i + 1);
525-
}
526-
527-
void quick_sort(char* arr[], int low, int high)
528-
{
529-
if (low < high)
530-
{
531-
int pi = partition(arr, low, high);
507+
static int partition (char* arr[], int low, int high) {
508+
char* pivot = arr[high];
509+
int i = (low - 1);
532510

533-
quick_sort(arr, low, pi - 1);
534-
quick_sort(arr, pi + 1, high);
535-
}
536-
}
511+
for (int j = low; j <= high- 1; j++)
512+
{
513+
if (strcicmp(arr[j], pivot) < 0)
514+
{
515+
i++;
516+
swap(&arr[i], &arr[j]);
517+
}
518+
}
519+
swap(&arr[i + 1], &arr[high]);
520+
return (i + 1);
521+
}
522+
523+
void quick_sort(char* arr[], int low, int high) {
524+
if (low < high)
525+
{
526+
int pi = partition(arr, low, high);
537527

538-
void sort_files(char** files)
539-
{
540-
if (ROMS.total > 1)
541-
{
542-
quick_sort(files, 0, ROMS.total - 1);
543-
}
544-
}
528+
quick_sort(arr, low, pi - 1);
529+
quick_sort(arr, pi + 1, high);
530+
}
531+
}
545532

546-
void get_files() {
547-
odroid_sdcard_open("/sd");
548-
const int MAX_FILES = 1024;
549-
char** result = (char**)malloc(MAX_FILES * sizeof(void*));
533+
void sort_files(char** files)
534+
{
535+
if (ROMS.total > 1)
536+
{
537+
quick_sort(files, 0, ROMS.total - 1);
538+
}
539+
}
540+
//}#pragma endregion Sort
550541

551-
DIR *directory;
552-
struct dirent *file;
542+
void get_files() {
543+
FILES = (char**)malloc(MAX_FILES * sizeof(void*));
544+
553545
char path[256] = "/sd/roms/";
554546
strcat(&path[strlen(path) - 1], DIRECTORIES[STEP]);
555547
strcpy(ROM.path, path);
@@ -564,50 +556,53 @@
564556
bool extenstion = strcmp(&file->d_name[rom_length - ext_lext], EXTENSIONS[STEP]) == 0 && file->d_name[0] != '.';
565557
if(extenstion) {
566558
size_t len = strlen(file->d_name);
567-
result[ROMS.total] = (char*)malloc(len + 1);
568-
strcpy(result[ROMS.total], file->d_name);
559+
FILES[ROMS.total] = (char*)malloc(len + 1);
560+
strcpy(FILES[ROMS.total], file->d_name);
569561
ROMS.total++;
570562
}
571563
}
572564
ROMS.pages = ROMS.total/ROMS.limit;
573-
//printf("\nDIRECTORY:%s ROMS.page:%d ROMS.pages:%d\n", DIRECTORIES[STEP], ROMS.page, ROMS.pages);
574565
closedir(directory);
575566
}
576567

577568
if(ROMS.total > 0) {
578-
sort_files(result);
579-
draw_files(result);
580-
draw_numbers();
569+
sort_files(FILES);
570+
draw_files();
581571
} else {
582572
char message[100] = "no games available";
583573
int center = ceil((320/2)-((strlen(message)*5)/2));
584574
draw_text(center,134,message,false,false);
585575
}
586576
}
587577

588-
void draw_files(char** files) {
589-
578+
void draw_files() {
579+
printf("\n");
590580
int x = ORIGIN.x;
591581
int y = POS.y + 48;
592582
int game = ROMS.offset ;
593583
ROMS.page = ROMS.offset/ROMS.limit;
594584

585+
printf("\nROMS.offset:%d", ROMS.offset);
586+
printf("\nROMS.limit:%d", ROMS.limit);
587+
printf("\nROMS.total:%d", ROMS.total);
588+
printf("\nROMS.page:%d", ROMS.page);
589+
printf("\nROMS.pages:%d", ROMS.pages);
590+
595591
for (int i = 0; i < 4; i++) draw_mask(0, y+(i*40)-6, 320, 40);
596-
for(int n = 0; n < ROMS.total; n++) {
597-
if(game < (ROMS.limit+ROMS.offset) && n >= game && game < ROMS.total) {
598-
draw_media(x,y-6,game == ROMS.offset ? true : false);
599-
draw_text(x+24,y,files[n],true,game == ROMS.offset ? true : false);
600-
if(game == ROMS.offset) {
601-
strcpy(ROM.name, files[n]);
602-
int i = strlen(ROM.path); ROM.path[i] = '/';
603-
ROM.path[i + 1] = 0;
604-
strcat(ROM.path, ROM.name);
605-
ROM.ready = true;
606-
}
607-
y+=20;
608-
game++;
609-
}
592+
593+
int limit = (ROMS.offset + ROMS.limit) > ROMS.total ? ROMS.total : ROMS.offset + ROMS.limit;
594+
for(int n = ROMS.offset; n < limit; n++) {
595+
draw_text(x+24,y,FILES[n],true,n == ROMS.offset ? true : false);
596+
draw_media(x,y-6,n == ROMS.offset ? true : false);
597+
if(n == ROMS.offset) {
598+
strcpy(ROM.name, FILES[n]);
599+
ROM.ready = true;
600+
}
601+
y+=20;
610602
}
603+
604+
605+
draw_numbers();
611606
}
612607

613608
void has_save_file(char *name) {
@@ -777,7 +772,7 @@
777772
void rom_run(bool resume) {
778773

779774
set_restore_states();
780-
775+
781776
draw_background();
782777
char *message = !resume ? "loading..." : "hold start";
783778

@@ -798,6 +793,7 @@
798793
odroid_system_application_set(PROGRAMS[STEP-1]);
799794
usleep(10000);
800795
esp_restart();
796+
801797
}
802798

803799
void rom_resume() {
@@ -927,7 +923,7 @@
927923
if(STEP != 0) {
928924
ROMS.offset--;
929925
if( ROMS.offset < 0 ) { ROMS.offset = ROMS.total - 1; }
930-
get_files();
926+
draw_files();
931927
}
932928
} else {
933929
if(SAVED) {
@@ -952,7 +948,7 @@
952948
if(STEP != 0) {
953949
ROMS.offset++;
954950
if( ROMS.offset > ROMS.total - 1 ) { ROMS.offset = 0; }
955-
get_files();
951+
draw_files();
956952
}
957953
} else {
958954
if(SAVED) {
@@ -979,7 +975,7 @@
979975
ROMS.page++;
980976
if( ROMS.page > ROMS.pages ) { ROMS.page = 0; }
981977
ROMS.offset = ROMS.page * ROMS.limit;
982-
get_files();
978+
draw_files();
983979
}
984980
}
985981
//debounce(ODROID_INPUT_START);
@@ -994,7 +990,7 @@
994990
ROMS.page--;
995991
if( ROMS.page < 0 ) { ROMS.page = ROMS.pages; };
996992
ROMS.offset = ROMS.page * ROMS.limit;
997-
get_files();
993+
draw_files();
998994
}
999995
}
1000996
//debounce(ODROID_INPUT_SELECT);
@@ -1013,9 +1009,13 @@
10131009
if (ROM.ready && !LAUNCHER) {
10141010
OPTION = 0;
10151011
LAUNCHER = true;
1012+
1013+
char file_to_load[256] = "";
1014+
sprintf(file_to_load, "%s/%s", ROM.path, ROM.name);
1015+
odroid_settings_RomFilePath_set(file_to_load);
1016+
10161017
draw_launcher();
10171018
} else {
1018-
odroid_settings_RomFilePath_set(ROM.path);
10191019
switch(OPTION) {
10201020
case 0:
10211021
SAVED ? rom_resume() : rom_run(false);
@@ -1040,7 +1040,7 @@
10401040
draw_background();
10411041
draw_systems();
10421042
draw_text(16,16,EMULATORS[STEP],false,true);
1043-
STEP == 0 ? draw_themes() : get_files();
1043+
STEP == 0 ? draw_themes() : draw_files();
10441044
}
10451045
debounce(ODROID_INPUT_B);
10461046
}

0 commit comments

Comments
 (0)