|
33 | 33 | uint32_t currentDuty;
|
34 | 34 |
|
35 | 35 | char** FILES;
|
| 36 | + char** FAVORITES; |
| 37 | + char FAVORITE[256] = ""; |
| 38 | + |
36 | 39 | char folder_path[256] = "";
|
37 | 40 |
|
38 | 41 | DIR *directory;
|
|
130 | 133 |
|
131 | 134 | // SD
|
132 | 135 | odroid_sdcard_open("/sd");
|
133 |
| - has_fav_file(); |
| 136 | + create_favorites(); |
134 | 137 |
|
135 | 138 | // Theme
|
136 | 139 | get_theme();
|
|
906 | 909 |
|
907 | 910 | void draw_launcher_options() {
|
908 | 911 | has_save_file(ROM.name);
|
909 |
| - |
| 912 | + is_favorite(ROM.name); |
910 | 913 | int x = GAP/3 + 32;
|
911 | 914 | int y = POS.y + 48;
|
912 | 915 | int w = 5;
|
|
945 | 948 | i = 0;
|
946 | 949 | offset = 0;
|
947 | 950 | for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
|
948 |
| - buffer[i] = icons[r+offset][c] == WHITE ? WHITE : GUI.bg;i++; |
| 951 | + buffer[i] = icons[r+offset][c] == WHITE ? OPTION == 0 ? WHITE : GUI.fg : GUI.bg;i++; |
949 | 952 | }}
|
950 | 953 | ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
|
951 |
| - draw_text(x+10,y,"Run",false,true, false); |
| 954 | + draw_text(x+10,y,"Run",false,OPTION == 0?true:false, false); |
952 | 955 | }
|
| 956 | + |
| 957 | + // favorites |
| 958 | + y+=20; |
| 959 | + i = 0; |
| 960 | + offset = ROM.favorite?40:35; |
| 961 | + int option = SAVED ? 3 : 1; |
| 962 | + for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { |
| 963 | + buffer[i] = icons[r+offset][c] == WHITE ? OPTION == option ? WHITE : GUI.fg : GUI.bg;i++; |
| 964 | + }} |
| 965 | + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); |
| 966 | + draw_text(x+10,y,ROM.favorite?"Unfavorite":"Favorite",false,OPTION == option?true:false, false); |
953 | 967 | }
|
954 | 968 | //}#pragma endregion GUI
|
955 | 969 |
|
|
1225 | 1239 | //}#pragma endregion Files
|
1226 | 1240 |
|
1227 | 1241 | //{#pragma region Favorites
|
1228 |
| -void handle_line(char *line) { |
1229 |
| - printf("\n%s\n", line); |
1230 |
| -} |
1231 | 1242 |
|
1232 |
| - void has_fav_file() { |
1233 |
| - printf("\n----- %s -----\n", __func__); |
| 1243 | + void create_favorites() { |
| 1244 | + printf("\n----- %s START -----", __func__); |
1234 | 1245 | char file[256] = "/sd/odroid/data";
|
1235 |
| - sprintf(file, "%s/%s", file, "retro_esp32.txt"); |
| 1246 | + sprintf(file, "%s/%s", file, FAVFILE); |
1236 | 1247 |
|
1237 | 1248 | FILE *f;
|
1238 | 1249 | f = fopen(file, "rb");
|
1239 | 1250 | if(f == NULL) {
|
1240 |
| - f = fopen(file, "wb"); |
1241 |
| - fprintf(f, "Favorites List"); |
| 1251 | + f = fopen(file, "w+"); |
| 1252 | + printf("\nCREATING: %s", file); |
| 1253 | + /* |
| 1254 | + Castlevania Adventure, The (U).gb |
| 1255 | + Legend of Zelda, The - Oracle of Seasons (USA).gbc |
| 1256 | + Mega Man 2 (USA).nes |
| 1257 | + */ |
1242 | 1258 | } else {
|
| 1259 | + read_favorites(); |
| 1260 | + } |
| 1261 | + printf("\nCLOSING: %s", file); |
| 1262 | + fclose(f); |
| 1263 | + printf("\n----- %s END -----\n", __func__); |
| 1264 | + } |
| 1265 | + |
| 1266 | + void read_favorites() { |
| 1267 | + printf("\n----- %s START -----", __func__); |
| 1268 | + |
| 1269 | + char file[256] = "/sd/odroid/data"; |
| 1270 | + sprintf(file, "%s/%s", file, FAVFILE); |
| 1271 | + |
| 1272 | + FILE *f; |
| 1273 | + f = fopen(file, "rb"); |
| 1274 | + if(f) { |
| 1275 | + printf("\nREADING: %s\n", file); |
| 1276 | + char line[256]; |
| 1277 | + while (fgets(line, sizeof(line), f)) { |
| 1278 | + printf("%s", line); |
| 1279 | + } |
| 1280 | + } |
| 1281 | + fclose(f); |
| 1282 | + |
| 1283 | + printf("\n----- %s END -----\n", __func__); |
| 1284 | + } |
1243 | 1285 |
|
| 1286 | + void add_favorite(char *favorite) { |
| 1287 | + printf("\n----- %s START -----", __func__); |
| 1288 | + char file[256] = "/sd/odroid/data"; |
| 1289 | + sprintf(file, "%s/%s", file, FAVFILE); |
| 1290 | + |
| 1291 | + FILE *f; |
| 1292 | + f = fopen(file, "a+"); |
| 1293 | + if(f) { |
| 1294 | + printf("\nADDING: %s to %s", favorite, file); |
| 1295 | + fprintf(f, "%s\n", favorite); |
| 1296 | + } |
| 1297 | + fclose(f); |
| 1298 | + printf("\n----- %s END -----\n", __func__); |
| 1299 | + } |
| 1300 | + |
| 1301 | + void delete_favorite(char *favorite) { |
| 1302 | + printf("\n----- %s START -----", __func__); |
| 1303 | + printf("\n----- %s END -----\n", __func__); |
| 1304 | + } |
| 1305 | + |
| 1306 | + void is_favorite(char *favorite) { |
| 1307 | + printf("\n----- %s START -----", __func__); |
| 1308 | + ROM.favorite = false; |
| 1309 | + |
| 1310 | + char file[256] = "/sd/odroid/data"; |
| 1311 | + sprintf(file, "%s/%s", file, FAVFILE); |
| 1312 | + |
| 1313 | + |
| 1314 | + FILE *f; |
| 1315 | + f = fopen(file, "rb"); |
| 1316 | + if(f) { |
| 1317 | + printf("\nCHECKING: %s\n", favorite); |
| 1318 | + char line[256]; |
| 1319 | + while (fgets(line, sizeof(line), f)) { |
| 1320 | + char *ep = &line[strlen(line)-1]; |
| 1321 | + while (*ep == '\n' || *ep == '\r'){*ep-- = '\0';} |
| 1322 | + printf("\nfavorite:%s line:%s match:%d", favorite, line, strcmp(favorite, line)); |
| 1323 | + if(strcmp(favorite, line) == 0) { |
| 1324 | + ROM.favorite = true; |
| 1325 | + } |
| 1326 | + } |
1244 | 1327 | }
|
1245 | 1328 | fclose(f);
|
| 1329 | + printf("\n----- %s END -----\n", __func__); |
1246 | 1330 | }
|
1247 | 1331 | //}#pragma endregion Favorites
|
1248 | 1332 |
|
@@ -1717,9 +1801,10 @@ void handle_line(char *line) {
|
1717 | 1801 | seek_files();
|
1718 | 1802 | }
|
1719 | 1803 | } else {
|
| 1804 | + int min = SAVED ? 3 : 1; |
1720 | 1805 | if(SAVED) {
|
1721 | 1806 | OPTION--;
|
1722 |
| - if( OPTION < 0 ) { OPTION = 2; } |
| 1807 | + if( OPTION < 0 ) { OPTION = min; } |
1723 | 1808 | draw_launcher_options();
|
1724 | 1809 | }
|
1725 | 1810 | }
|
@@ -1750,11 +1835,10 @@ void handle_line(char *line) {
|
1750 | 1835 | seek_files();
|
1751 | 1836 | }
|
1752 | 1837 | } else {
|
1753 |
| - if(SAVED) { |
1754 |
| - OPTION++; |
1755 |
| - if( OPTION > 2 ) { OPTION = 0; } |
1756 |
| - draw_launcher_options(); |
1757 |
| - } |
| 1838 | + int max = SAVED ? 3 : 1; |
| 1839 | + OPTION++; |
| 1840 | + if( OPTION > max ) { OPTION = 0; } |
| 1841 | + draw_launcher_options(); |
1758 | 1842 | }
|
1759 | 1843 |
|
1760 | 1844 | usleep(200000);
|
@@ -1864,11 +1948,16 @@ void handle_line(char *line) {
|
1864 | 1948 | SAVED ? rom_resume() : rom_run(false);
|
1865 | 1949 | break;
|
1866 | 1950 | case 1:
|
1867 |
| - rom_run(true); |
| 1951 | + SAVED ? rom_run(true) : add_favorite(ROM.name); |
| 1952 | + if(!SAVED) {draw_launcher_options();} |
1868 | 1953 | break;
|
1869 | 1954 | case 2:
|
1870 | 1955 | rom_delete_save();
|
1871 | 1956 | break;
|
| 1957 | + case 3: |
| 1958 | + add_favorite(ROM.name); |
| 1959 | + draw_launcher_options(); |
| 1960 | + break; |
1872 | 1961 | }
|
1873 | 1962 | }
|
1874 | 1963 | }
|
|
0 commit comments