diff --git a/Components/go-play/odroid-go-common/components/odroid/odroid_hud.c b/Components/go-play/odroid-go-common/components/odroid/odroid_hud.c index df05dad8..25cc92f6 100644 --- a/Components/go-play/odroid-go-common/components/odroid/odroid_hud.c +++ b/Components/go-play/odroid-go-common/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,28 +244,28 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { char * dir = strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir+1); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir+1); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -278,14 +278,14 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); + printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -346,7 +346,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -360,10 +360,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -376,18 +376,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -397,19 +397,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -417,12 +417,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -430,55 +430,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -488,10 +491,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -500,13 +503,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -516,7 +519,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -530,16 +533,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/handy-go/components/odroid/odroid_hud.c b/Components/handy-go/components/odroid/odroid_hud.c index 0fd86fea..bfef876b 100644 --- a/Components/handy-go/components/odroid/odroid_hud.c +++ b/Components/handy-go/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,30 +244,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "lynx";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -280,15 +280,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -349,7 +349,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -363,10 +363,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -379,18 +379,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -400,19 +400,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -420,12 +420,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -433,55 +433,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -491,10 +494,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -503,13 +506,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -519,7 +522,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -533,16 +536,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/odroid-go-handy/handy-go/main/main.c b/Components/odroid-go-handy/handy-go/main/main.c new file mode 100644 index 00000000..2e5342e2 --- /dev/null +++ b/Components/odroid-go-handy/handy-go/main/main.c @@ -0,0 +1,969 @@ +#include "freertos/FreeRTOS.h" +#include "esp_system.h" +#include "esp_event.h" +#include "nvs_flash.h" +#include "esp_partition.h" +#include "driver/i2s.h" +#include "esp_spiffs.h" +#include "nvs_flash.h" +#include "esp_sleep.h" +#include "driver/rtc_io.h" +#include "esp_ota_ops.h" + +typedef unsigned char uint8; +typedef unsigned short int uint16; +typedef unsigned long int uint32; + +#include "../components/lynx/handy.h" +#include "../components/lynx/myadd.h" + +#include "../components/odroid/odroid_settings.h" +#include "../components/odroid/odroid_audio.h" +#include "../components/odroid/odroid_input.h" +#include "../components/odroid/odroid_system.h" +#include "../components/odroid/odroid_display.h" +#include "../components/odroid/odroid_sdcard.h" +#include "../components/odroid/odroid_ui.h" +#include "../components/odroid/odroid_ui_choosefile.h" + +#include +#include +#include +#include +#include + +#ifdef CONFIG_IN_GAME_MENU_YES + #include + #include "../components/odroid/odroid_hud.h" + int ACTION; +#endif + +#define NOINLINE __attribute__ ((noinline)) + +#define MY_LYNX_INCLUDE_SAVE_TO_SD + +#define PALETTE_SIZE 256 + +const char* SD_BASE_PATH = "/sd"; + +//#define AUDIO_SAMPLE_RATE (32000) +#define AUDIO_SAMPLE_RATE (22050) + +#define AUDIO_BUFFER_SIZE 2756 + +uint32_t *lynx_mColourMap; +//uint16 palette[PALETTE_SIZE]; +uint16 *palette = NULL; +uint16_t* framebuffer[2]; // uint8_t* +int currentFramebuffer = 0; + +#ifdef MY_AUDIO_MODE_V1 +struct audio_meta { + //uint8_t *buffer; + short *buffer; + int length; +}; + +extern short *gAudioBuffer; +extern short *gAudioBufferPointer2; + +struct audio_meta audio_update1 = {0,}; +struct audio_meta audio_update2 = {0,}; +struct audio_meta *audio_update = &audio_update1; +QueueHandle_t audioQueue; +TaskHandle_t audioTaskHandle; +#endif + +spi_flash_mmap_handle_t hrom; + +QueueHandle_t vidQueue; +TaskHandle_t videoTaskHandle; + +odroid_volume_level Volume; +odroid_battery_state battery; + +bool scaling_enabled = true; +bool config_ui_stats = false; +int8_t filtering = 0; +bool previous_scaling_enabled = true; +uint8_t previous_rotate = 0; +uint8_t previous_filtering = 0; + +volatile bool videoTaskIsRunning = false; + +const char *odroidgo_rom_path = "/sd/roms/lynx"; +retro_pixel_format odroidgo_fmt = RETRO_PIXEL_FORMAT_RGB565; +retro_game_info odroid_game; +retro_system_info retro_info; +int16_t retrolib_input_state_t = 0; + +uint startTime; +uint stopTime; +uint totalElapsedTime; +int frame; +volatile float fps_ui = 0; +uint8_t rotate = 0; + +typedef void (ODROID_UI_CALLCONV *odroid_display_func_def)(uint8_t* buffer, uint32_t* myPalette); + +bool display_func_change = false; +odroid_display_func_def odroid_display_func; + +// functions +extern void SaveState(); +extern void LoadState(); + + +void update_display_func() { + previous_scaling_enabled = scaling_enabled; + previous_filtering = filtering; + previous_rotate = rotate; + + if (!scaling_enabled) { + odroid_display_func = ili9341_write_frame_lynx_v2_original; + } else { + switch (filtering) { + case 0: + odroid_display_func = ili9341_write_frame_lynx_v2_mode0; + break; + case 1: + odroid_display_func = ili9341_write_frame_lynx_v2_mode1; + break; + case 2: + odroid_display_func = ili9341_write_frame_lynx_v2_mode2; + break; + case 3: + odroid_display_func = ili9341_write_frame_lynx_v2_mode3; + break; + } + } + display_func_change = false; +} + +#define TASK_BREAK (void*)1 + +#ifdef MY_VIDEO_MODE_V1 + +#define VID_TASK(func) \ + uint8_t* param; \ + videoTaskIsRunning = true; \ + printf("%s: STARTED\n", __func__); \ + \ + while(1) \ + { \ + xQueuePeek(vidQueue, ¶m, portMAX_DELAY); \ + \ + if (param == TASK_BREAK) \ + break; \ + \ + odroid_display_lock(); \ + func(param, lynx_mColourMap); \ + odroid_display_unlock(); \ + /* odroid_input_battery_level_read(&battery);*/ \ + xQueueReceive(vidQueue, ¶m, portMAX_DELAY); \ + } \ + xQueueReceive(vidQueue, ¶m, portMAX_DELAY); \ + /*odroid_display_lock();*/ \ + /*odroid_display_show_hourglass();*/ \ + /*odroid_display_unlock();*/ \ + videoTaskIsRunning = false; \ + printf("%s: FINISHED\n", __func__); \ + vTaskDelete(NULL); \ + while (1) {} + + +void videoTask_mode0(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode0) } +void videoTask_mode1(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode1) } +void videoTask_mode2(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode2) } +void videoTask_mode3(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode3) } +void videoTask_mode_original(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_original) } +void videoTask_mode_original_rotate_R(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_original_rotate_R) } +void videoTask_mode_original_rotate_L(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_original_rotate_L) } +void videoTask_mode_original_mode0_rotate_R(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode0_rotate_R) } +void videoTask_mode_original_mode0_rotate_L(void *arg) { VID_TASK(ili9341_write_frame_lynx_v2_mode0_rotate_L) } + +#endif + +NOINLINE void update_display_task() +{ + printf("%s: Step #001\n", __func__); + if (videoTaskIsRunning) + { + printf("VIDEO: Task: Stop\n"); + uint16_t* param = TASK_BREAK; + xQueueSend(vidQueue, ¶m, portMAX_DELAY); + while (videoTaskIsRunning) { vTaskDelay(1); } + printf("VIDEO: Task: Stop done\n"); + + printf("VIDEO: Clear display\n"); + //odroid_display_lock(); + ili9341_write_frame_lynx(NULL, NULL, false); + //odroid_display_unlock(); + } + printf("%s: Step #002\n", __func__); + TaskFunction_t taskFunc = &videoTask_mode0; + + previous_scaling_enabled = scaling_enabled; + previous_filtering = filtering; + previous_rotate = rotate; + + my_setbutton_mapping(rotate); + + if (!scaling_enabled) { + switch (rotate) { + case 0: taskFunc = &videoTask_mode_original; break; + case 1: taskFunc = &videoTask_mode_original_rotate_R; break; + case 2: taskFunc = &videoTask_mode_original_rotate_L; break; + } + } else { + if (rotate) { + switch (rotate) { + case 0: taskFunc = &videoTask_mode_original; break; + case 1: taskFunc = &videoTask_mode_original_mode0_rotate_R; break; + case 2: taskFunc = &videoTask_mode_original_mode0_rotate_L; break; + } + } else { + // filtering; + switch (filtering) { + case 0: + taskFunc = &videoTask_mode0; + break; + case 1: + taskFunc = &videoTask_mode1; + break; + case 2: + taskFunc = &videoTask_mode2; + break; + case 3: + taskFunc = &videoTask_mode3; + break; + default: + taskFunc = &videoTask_mode0; + break; + } + } + } + printf("%s: Step #003\n", __func__); + + printf("VIDEO: Task: Start\n"); + xTaskCreatePinnedToCore(taskFunc, "videoTask", 1024 * 4, NULL, 5, &videoTaskHandle, 1); + while (!videoTaskIsRunning) { vTaskDelay(1); } + printf("VIDEO: Task: Start done\n"); +} + +#ifdef MY_AUDIO_MODE_V1 +volatile bool AudioTaskIsRunning = false; +void audioTask(void* arg) +{ + // sound + struct audio_meta* param; + + AudioTaskIsRunning = true; + while(1) + { + xQueuePeek(audioQueue, ¶m, portMAX_DELAY); + + if (param == NULL) + { + break; + } + else + { + odroid_audio_submit((short*)param->buffer, param->length - 1); + } + xQueueReceive(audioQueue, ¶m, portMAX_DELAY); + } + printf("audioTask: exiting.\n"); + odroid_audio_terminate(); + AudioTaskIsRunning = false; + vTaskDelete(NULL); + + while (1) {} +} +#endif + +//Read an unaligned byte. +char unalChar(const unsigned char *adr) { + //See if the byte is in memory that can be read unaligned anyway. + if (!(((int)adr)&0x40000000)) return *adr; + //Nope: grab a word and distill the byte. + int *p=(int *)((int)adr&0xfffffffc); + int v=*p; + int w=((int)adr&3); + if (w==0) return ((v>>0)&0xff); + if (w==1) return ((v>>8)&0xff); + if (w==2) return ((v>>16)&0xff); + if (w==3) return ((v>>24)&0xff); + + abort(); + return 0; +} + +NOINLINE void DoMenuHome(bool save) +{ + uint16_t* param = TASK_BREAK; + void *exitAudioTask = NULL; + + #ifdef CONFIG_IN_GAME_MENU_YES + odroid_display_lock(); + hud_menu(); + printf("\nACTION:%d\n", ACTION); + switch(ACTION) { + case 3: + case 4: + hud_progress("Saving...", true); + hud_deinit(); + odroid_display_unlock(); + //xQueueSend(audioQueue, &exitAudioTask, portMAX_DELAY); + //while (AudioTaskIsRunning) {} + //xQueueSend(vidQueue, ¶m, portMAX_DELAY); + //while (videoTaskIsRunning) { vTaskDelay(1); } + SaveState(); + ili9341_clear(0); + esp_restart(); + break; + case 5: + printf("\nDELETE ROM\n"); + break; + } + ili9341_clear(0); + odroid_display_unlock(); + #else + // Clear audio to prevent studdering + printf("PowerDown: stopping audio.\n"); + #ifdef MY_AUDIO_MODE_V1 + xQueueSend(audioQueue, &exitAudioTask, portMAX_DELAY); + while (AudioTaskIsRunning) {} + #else + odroid_audio_terminate(); + #endif + + // Stop tasks + printf("PowerDown: stopping tasks.\n"); + + xQueueSend(vidQueue, ¶m, portMAX_DELAY); + while (videoTaskIsRunning) { vTaskDelay(1); } + + odroid_settings_ForceInternalGameSelect_set(1); + DoReboot(save); + #endif +} + +extern uint32 *gAudioEnabledPointer; + +void menu_lynx_audio_update(odroid_ui_entry *entry) { + if (*gAudioEnabledPointer) { + sprintf(entry->text, "%-9s: %s", "audio", "on"); + } else { + sprintf(entry->text, "%-9s: %s", "audio", "off"); + } +} + +odroid_ui_func_toggle_rc menu_lynx_audio_toggle(odroid_ui_entry *entry, odroid_gamepad_state *joystick) { + *gAudioEnabledPointer = !(*gAudioEnabledPointer); + return ODROID_UI_FUNC_TOGGLE_RC_CHANGED; +} + +#define FRAMESKIP_MAX 6 +uint8_t frameskip = 2; + +void menu_lynx_frameskip_update(odroid_ui_entry *entry) { + sprintf(entry->text, "%-9s: %d", "frameskip", frameskip - 1); +} + +odroid_ui_func_toggle_rc menu_lynx_frameskip_toggle(odroid_ui_entry *entry, odroid_gamepad_state *joystick) { + if (joystick->values[ODROID_INPUT_A] || joystick->values[ODROID_INPUT_RIGHT]) { + if (frameskipvalues[ODROID_INPUT_LEFT]) { + if (frameskip>2) frameskip--; + } + return ODROID_UI_FUNC_TOGGLE_RC_CHANGED; +} + +void menu_lynx_rotate_update(odroid_ui_entry *entry) { + switch (rotate) + { + case 0: sprintf(entry->text, "%-9s: %s", "rotate", "off"); break; + case 1: sprintf(entry->text, "%-9s: %s", "rotate", "right"); break; + case 2: sprintf(entry->text, "%-9s: %s", "rotate", "left"); break; + } +} + +odroid_ui_func_toggle_rc menu_lynx_rotate_toggle(odroid_ui_entry *entry, odroid_gamepad_state *joystick) { + rotate = (rotate+1)%3; + return ODROID_UI_FUNC_TOGGLE_RC_CHANGED; +} + +void menu_lynx_filtering_update(odroid_ui_entry *entry) { + switch(filtering) { + case 0: + sprintf(entry->text, "%-9s: %s", "filter", "none"); + break; + case 1: + sprintf(entry->text, "%-9s: %s", "filter", "H"); + break; + case 2: + sprintf(entry->text, "%-9s: %s", "filter", "V"); + break; + case 3: + sprintf(entry->text, "%-9s: %s", "filter", "HV"); + break; + } +} + +odroid_ui_func_toggle_rc menu_lynx_filtering_toggle(odroid_ui_entry *entry, odroid_gamepad_state *joystick) { + if (joystick->values[ODROID_INPUT_A] || joystick->values[ODROID_INPUT_RIGHT]) { + if (++filtering>3) filtering = 0; + } else if (joystick->values[ODROID_INPUT_LEFT]) { + if (filtering--==0) filtering = 3; + } + return ODROID_UI_FUNC_TOGGLE_RC_CHANGED; +} + +void menu_lynx_init(odroid_ui_window *window) { + odroid_ui_create_entry(window, &menu_lynx_audio_update, &menu_lynx_audio_toggle); + odroid_ui_create_entry(window, &menu_lynx_rotate_update, &menu_lynx_rotate_toggle); + odroid_ui_create_entry(window, &menu_lynx_filtering_update, &menu_lynx_filtering_toggle); + odroid_ui_create_entry(window, &menu_lynx_frameskip_update, &menu_lynx_frameskip_toggle); +} + +inline void update_ui_fps() { + stopTime = xthal_get_ccount(); + int elapsedTime; + if (stopTime > startTime) + elapsedTime = (stopTime - startTime); + else + elapsedTime = ((uint64_t)stopTime + (uint64_t)0xffffffff) - (startTime); + + totalElapsedTime += elapsedTime; + ++frame; + + if (frame == 60) + { + float seconds = totalElapsedTime / (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000.0f); + float fps = frame / seconds; + fps_ui = fps; + printf("FPS:%f, BATTERY:%d [%d]\n", fps, battery.millivolts, battery.percentage); + + //printf("HEAP:0x%x, FPS:%f, BATTERY:%d [%d]\n", esp_get_free_heap_size(), fps, battery.millivolts, battery.percentage); + + //vTaskGetRunTimeStats(pmem); + //printf(pmem); + + frame = 0; + totalElapsedTime = 0; + /*if (config_ui_stats) { + update_ui_fps_text(fps); + }*/ +#ifdef ODROID_DEBUG_PERF_USE + odroid_debug_perf_log_specific(ODROID_DEBUG_PERF_TOTAL, 269334479); + odroid_debug_perf_log_specific(ODROID_DEBUG_PERF_CPU, 230473555); + odroid_debug_perf_log_specific(ODROID_DEBUG_PERF_SUSIE_PAINTSPRITES, 144456221); + odroid_debug_perf_log_specific(ODROID_DEBUG_PERF_SUSIE_PAINTSPRITES_VLOOP, 135921297); +#endif +ODROID_DEBUG_PERF_LOG() + } + startTime = stopTime; +} + + +void odroid_retro_log(retro_log_level level, + const char *fmt, ...) { + va_list(args); + switch(level) { + case RETRO_LOG_DEBUG: + printf("DEBUG - "); + break; + case RETRO_LOG_INFO: + printf("INFO - "); + break; + case RETRO_LOG_WARN: + printf("WARN - "); + break; + case RETRO_LOG_ERROR: + printf("ERROR - "); + break; + default: + printf("LOG%d - ", level); + break; + }; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + printf("\n"); +} + +//expected 'retro_environment_t {aka _Bool (*)(unsigned int, void *)}' +//but argument is of type '_Bool (*)(unsigned int, void **)' RETRO_API void retro_set_environment(retro_environment_t); + +bool odroidgo_env(unsigned int cmd, void *_data) { + void **data = (void**)_data; + if (!data) { + printf("CMD '%d'. Data is null!\n", cmd); + } + switch(cmd) { + case RETRO_ENVIRONMENT_GET_LOG_INTERFACE: + { + retro_log_callback *log = (retro_log_callback *)data; + log->log = &odroid_retro_log; + } + break; + case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT: + *data = &odroidgo_fmt; + break; + case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY: + *data = (char*)odroidgo_rom_path; + break; + case RETRO_ENVIRONMENT_SET_VARIABLES: + // VARs from lynx emu + break; + case RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS: + // serialization_quirks + break; + case RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS: + // + break; + case RETRO_ENVIRONMENT_GET_VARIABLE: + *data = NULL; + return false; + case RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE: + return false; + default: + data = NULL; + printf("No data for '%d'!\n", cmd); + abort(); + return false; + }; + return true; +} + +void odroid_retro_input_poll_t() { + // +} + +void odroid_retro_audio_sample_t(int16_t left, int16_t right) { + printf("odroid_retro_audio_sample_t\n"); +} + +size_t odroid_retro_audio_sample_batch_t(const int16_t *data, size_t frames) { + // Process audio +#ifdef MY_AUDIO_MODE_V1 + //printf("Audio: Frames: %u\n", frames); + audio_update->length = frames; + // xQueueSend(audioQueue, &audio_update, portMAX_DELAY); + // *** odroid_audio_submit(audio_update->buffer, audio_update->length - 1); + + odroid_audio_submit(audio_update->buffer, audio_update->length - 1); + + audio_update = (audio_update==&audio_update1)?&audio_update2:&audio_update1; + gAudioBuffer = audio_update->buffer; +#else + odroid_audio_submit((short*)data, frames - 1); +#endif + return 0; +} + + uint16_t menuButtonFrameCount; + odroid_gamepad_state previousState; + bool ignoreMenuButton, menu_restart; + +bool odroid_ui_menu_lynx(bool mr) +{ + mr = odroid_ui_menu_ext(mr, &menu_lynx_init); + if (previous_scaling_enabled != scaling_enabled || + previous_filtering != filtering || + previous_rotate != rotate) { + if (!mr) + { + update_display_task(); + } + + // display_func_change = true; + //odroid_display_lock(); + //ili9341_write_frame_lynx(NULL, NULL, false); + //update_display_func(); + //odroid_display_unlock(); + } + return mr; +} + +void process_keys(odroid_gamepad_state *joystick) +{ +#ifndef MY_KEYS_IN_CALLBACK + retrolib_input_state_t = 0; + if (joystick->values[ODROID_INPUT_A]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_A; + } + if (joystick->values[ODROID_INPUT_B]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_B; + } + if (joystick->values[ODROID_INPUT_LEFT]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_LEFT; + } + if (joystick->values[ODROID_INPUT_RIGHT]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_RIGHT; + } + if (joystick->values[ODROID_INPUT_UP]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_UP; + } + if (joystick->values[ODROID_INPUT_DOWN]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_DOWN; + } + if (joystick->values[ODROID_INPUT_START]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_START; + } + if (joystick->values[ODROID_INPUT_SELECT]) { + retrolib_input_state_t |= 1 << RETRO_DEVICE_ID_JOYPAD_L; + } + // { RETRO_DEVICE_ID_JOYPAD_R, BUTTON_OPT2 }, +#endif + ODROID_UI_MENU_HANDLER_LOOP_V1(previousState, (*joystick), DoMenuHome, odroid_ui_menu_lynx) +} + +#ifdef MY_KEYS_IN_CALLBACK +int16_t odroid_retro_input_state_t(unsigned port, unsigned device, + unsigned index, unsigned id) { + int16_t rc; + switch(id) { + case RETRO_DEVICE_ID_JOYPAD_A: + rc = previousState.values[ODROID_INPUT_A]; + break; + case RETRO_DEVICE_ID_JOYPAD_B: + rc = previousState.values[ODROID_INPUT_B]; + break; + case RETRO_DEVICE_ID_JOYPAD_LEFT: + rc = previousState.values[ODROID_INPUT_LEFT]; + break; + case RETRO_DEVICE_ID_JOYPAD_RIGHT: + rc = previousState.values[ODROID_INPUT_RIGHT]; + break; + case RETRO_DEVICE_ID_JOYPAD_UP: + rc = previousState.values[ODROID_INPUT_UP]; + break; + case RETRO_DEVICE_ID_JOYPAD_DOWN: + rc = previousState.values[ODROID_INPUT_DOWN]; + break; + case RETRO_DEVICE_ID_JOYPAD_START: + rc = previousState.values[ODROID_INPUT_START]; + break; + case RETRO_DEVICE_ID_JOYPAD_L: + rc = previousState.values[ODROID_INPUT_SELECT]; + break; + // { RETRO_DEVICE_ID_JOYPAD_R, BUTTON_OPT2 }, + default: + rc = 0; + break; + } + return rc; +} +#else +int16_t odroid_retro_input_state_t(unsigned port, unsigned device, + unsigned index, unsigned id) { + return (1<> 8); +} +#endif + + + +bool skipNextFrame = true; +void odroid_retro_video_refresh_t(const void *data) { + if ((frame%frameskip)==1) { + xQueueSend(vidQueue, &data, portMAX_DELAY); + skipNextFrame = true; + } else if ((frame%frameskip)==0) { + skipNextFrame = false; + } else { + skipNextFrame = true; + } + update_ui_fps(); + +#ifdef MY_KEYS_IN_VIDEO + odroid_gamepad_state joystick; + odroid_input_gamepad_read(&joystick); + + process_keys(&joystick); + previousState = joystick; +#endif +} + +void odroidgo_retro_init(void) { + printf("odroidgo_init\n"); + odroid_display_unlock(); + char *rc = odroid_ui_choose_file("/sd/roms/lynx", "lnx"); + odroid_display_lock(); + if (rc) { + printf("File: %s\n", rc); + odroid_game.path = rc; + } else { + printf("File: ---\n"); + odroid_game.path = "/sd/roms/lynx/_debug.lnx"; + } + + odroid_game.data = NULL; + odroid_game.size = 0; + odroid_game.meta = "dummy"; + + retro_set_environment(&odroidgo_env); + retro_set_audio_sample(&odroid_retro_audio_sample_t); + retro_set_video_refresh(&odroid_retro_video_refresh_t); + retro_set_audio_sample_batch(&odroid_retro_audio_sample_batch_t); + // retro_set_controller_port_device(); +} + +void odroidgo_retro_init_post() { + retro_set_input_poll(&odroid_retro_input_poll_t); + retro_set_input_state(&odroid_retro_input_state_t); +} + +/* +#include "esp_heap_trace.h" +#define NUM_RECORDS 1000 +static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM +*/ + +void dump_heap_info_short() { + printf("LARGEST: 8BIT: %u\n", heap_caps_get_largest_free_block( MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT )); + printf("LARGEST: 32BIT: %u\n", heap_caps_get_largest_free_block( MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT )); + printf("LARGEST: MALLOC_CAP_INTERNAL: %u\n", heap_caps_get_largest_free_block( MALLOC_CAP_INTERNAL )); + printf("LARGEST: MALLOC_CAP_DEFAULT: %u\n", heap_caps_get_largest_free_block( MALLOC_CAP_DEFAULT )); +} + +void app_loop(void) +{ + menuButtonFrameCount = 0; + menu_restart = false; + odroid_input_gamepad_read(&previousState); + ignoreMenuButton = previousState.values[ODROID_INPUT_MENU]; + +#ifdef MY_RETRO_LOOP + retro_run_endless(); +#else + while (true) + { +#ifndef MY_KEYS_IN_VIDEO + odroid_gamepad_state joystick; + odroid_input_gamepad_read(&joystick); + process_keys(&joystick); +#endif + retro_run(); +#ifndef MY_KEYS_IN_VIDEO + previousState = joystick; +#endif + } +#endif +} + +//#define VID_BUF_SIZE (160*102*2) +#define VID_BUF_SIZE ((160/2+64)*102) + +NOINLINE void app_init(void) +{ +printf("lynx-handy (%s-%s).\n", COMPILEDATE, GITREV); + // ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) ); + + framebuffer[0] = heap_caps_malloc(VID_BUF_SIZE, MALLOC_CAP_8BIT | MALLOC_CAP_DMA); + //framebuffer[0] = MY_MEM_ALLOC_SLOW_EXT(uint16_t, VID_BUF_SIZE, 1); // slower + if (!framebuffer[0]) abort(); + printf("app_main: framebuffer[0]=%p\n", framebuffer[0]); + + framebuffer[1] = heap_caps_malloc(VID_BUF_SIZE, MALLOC_CAP_8BIT | MALLOC_CAP_DMA); + //framebuffer[1] = MY_MEM_ALLOC_SLOW_EXT(uint16_t, VID_BUF_SIZE, 1); // slower + if (!framebuffer[1]) abort(); + printf("app_main: framebuffer[1]=%p\n", framebuffer[1]); + + +#ifdef MY_AUDIO_MODE_V1 + audio_update1.buffer = MY_MEM_ALLOC_SLOW_EXT(short, AUDIO_BUFFER_SIZE, 1); + //audio_update1.buffer = heap_caps_malloc(AUDIO_BUFFER_SIZE, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); // slower? + if (!audio_update1.buffer) abort(); + + audio_update2.buffer = MY_MEM_ALLOC_SLOW_EXT(short, AUDIO_BUFFER_SIZE, 1); + //audio_update2.buffer = heap_caps_malloc(AUDIO_BUFFER_SIZE, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); // slower? + if (!audio_update2.buffer) abort(); + + gAudioBuffer = audio_update1.buffer; + gAudioBufferPointer2 = gAudioBuffer; +#endif + + QuickSaveSetBuffer( MY_MEM_ALLOC_SLOW(void, 512*1024) ); + + // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); + + nvs_flash_init(); + + odroid_system_init(); + + // Joystick. + odroid_input_gamepad_init(); + odroid_input_battery_level_init(); + ili9341_prepare(); + + // Disable LCD CD to prevent garbage + const gpio_num_t LCD_PIN_NUM_CS = GPIO_NUM_5; + + gpio_config_t io_conf = { 0 }; + io_conf.intr_type = GPIO_PIN_INTR_DISABLE; + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = (1ULL << LCD_PIN_NUM_CS); + io_conf.pull_down_en = 0; + io_conf.pull_up_en = 0; + + gpio_config(&io_conf); + gpio_set_level(LCD_PIN_NUM_CS, 1); + + check_boot_cause(); + + ili9341_init(); + + char* cartName = odroid_settings_RomFilePath_get(); + printf("%s: filename='%s'\n", __func__, cartName); + + ili9341_write_frame_lynx(NULL, NULL, false); + + odroid_audio_init(odroid_settings_AudioSink_get(), AUDIO_SAMPLE_RATE); + + vidQueue = xQueueCreate(1, sizeof(uint16_t*)); + //xTaskCreatePinnedToCore(&videoTask, "videoTask", 1024 * 4, NULL, 5, &videoTaskHandle, 1); +#ifdef MY_AUDIO_MODE_V1 + audioQueue = xQueueCreate(1, sizeof(uint16_t*)); + xTaskCreatePinnedToCore(&audioTask, "audioTask", 2048, NULL, 5, NULL, 1); //768 +#endif + + esp_err_t r = odroid_sdcard_open(SD_BASE_PATH); + if (r != ESP_OK) + { + odroid_display_show_sderr(ODROID_SD_ERR_NOCARD); + abort(); + } + #ifdef CONFIG_IN_GAME_MENU_YES + hud_debug(odroid_util_GetFileName(cartName)); + char* save_name = odroid_util_GetFileName(cartName); + hud_check_saves(odroid_util_GetFileName(cartName)); + #endif + + odroid_display_lock(); + odroid_display_drain_spi(); + + // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); + printf("LYNX-hande: 001\n"); + printf("Version: %d; %d\n", RETRO_API_VERSION, RETRO_MEMORY_VIDEO_RAM); + odroidgo_retro_init(); + retro_init(); + printf("LYNX-hande: 002\n"); + + printf("Retro: API: %d\n", retro_api_version()); + retro_get_system_info(&retro_info); + printf("Retro: Info.library_name : %s\n", retro_info.library_name); + printf("Retro: Info.library_version : %s\n", retro_info.library_version); + printf("Retro: Info.need_fullpath : %d\n", retro_info.need_fullpath); + printf("Retro: Info.valid_extensions : %s\n", retro_info.valid_extensions); + printf("Retro: Info.block_extract : %d\n", retro_info.block_extract); + + odroid_display_unlock(); + + if (!retro_load_game(&odroid_game)) { + printf("LYNX-handy: 003 Gameload: Error\n"); + } else { + printf("LYNX-handy: 003 Gameload: Ok\n"); + } + + printf("LYNX-handy: 003\n"); + + // FIXME: Do some EMU stuff + // system_reset(); + + // Restore state + //LoadState(cartName); + + if (forceConsoleReset) + { + // Reset emulator if button held at startup to + // override save state + printf("%s: forceConsoleReset=true\n", __func__); + // system_reset(); + } + odroidgo_retro_init_post(); + + // ESP_ERROR_CHECK( heap_trace_stop() ); + // heap_trace_dump(); + + odroid_gamepad_state previousState; + odroid_input_gamepad_read(&previousState); + + totalElapsedTime = 0; + frame = 0; + scaling_enabled = odroid_settings_ScaleDisabled_get(ODROID_SCALE_DISABLE_SMS) ? false : true; + + odroid_ui_enter_loop(); +#ifdef ODROID_DEBUG_PERF_USE + printf("heap_caps metadata test\n"); + heap_caps_print_heap_info(MALLOC_CAP_8BIT); + heap_caps_print_heap_info(MALLOC_CAP_32BIT); + heap_caps_print_heap_info(MALLOC_CAP_INTERNAL); +#endif + + startTime = xthal_get_ccount(); + + dump_heap_info_short(); + printf("unsigned char : %u\n", sizeof(unsigned char)); + printf("unsigned int : %u\n", sizeof(unsigned int)); + printf("unsigned long : %u\n", sizeof(unsigned long)); + + /* + uint32_t caps = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT; + for (int i = 0; i < 64; i++) { + void *tmp = heap_caps_malloc(1024, caps);// MALLOC_CAP_SPIRAM + if (!tmp) { + printf("PRE-ALLOC failed #%d\n", i+1); + odroid_ui_debug_enter_loop(); + printf("LARGEST: %u\n", heap_caps_get_largest_free_block( caps )); + abort(); + } + printf("PRE-ALLOC test #%d: OK: %p\n", i+1, tmp); + printf("LARGEST: %u\n", heap_caps_get_largest_free_block( caps )); + } + */ + if (!forceConsoleReset) + { + LoadState(cartName); + } + + update_display_task(); +} + +void app_main(void) +{ + app_init(); + app_loop(); +} + +void *my_special_alloc(unsigned char speed, unsigned char bytes, unsigned long size) { + // if (size==16384) speed = 1; + + uint32_t caps = (speed?MALLOC_CAP_INTERNAL:MALLOC_CAP_SPIRAM) | + ( bytes==1?MALLOC_CAP_8BIT:MALLOC_CAP_32BIT); + /* + if (speed) { + uint32_t max = heap_caps_get_largest_free_block(caps); + if (max < size) { + printf("ALLOC: Size: %u; Max FREE for internal is '%u'. Allocating in SPI RAM\n", (unsigned int)size, max); + caps = MALLOC_CAP_SPIRAM | ( size==1?MALLOC_CAP_8BIT:MALLOC_CAP_32BIT); + } + } else { + caps = MALLOC_CAP_SPIRAM | MALLOC_CAP_32BIT; + } + */ + if (!speed) caps = MALLOC_CAP_SPIRAM | MALLOC_CAP_32BIT; + //if (!speed || size!=65536) caps = MALLOC_CAP_SPIRAM | MALLOC_CAP_32BIT; // only RAM + void *rc = heap_caps_malloc(size, caps); + printf("ALLOC: Size: %-10u; SPI: %u; 32BIT: %u; RC: %p\n", (unsigned int)size, (caps&MALLOC_CAP_SPIRAM)!=0, (caps&MALLOC_CAP_32BIT)!=0, rc); + if (!rc) { dump_heap_info_short(); abort(); } + return rc; +} + +void my_special_alloc_free(void *p) { + printf("FREE: Size: -; RC: %p\n", p); + if (p) heap_caps_free(p); +} diff --git a/Components/odroid-go-handy/odroid-go-common/components/odroid/odroid_hud.c b/Components/odroid-go-handy/odroid-go-common/components/odroid/odroid_hud.c index c4694623..b438cdcf 100644 --- a/Components/odroid-go-handy/odroid-go-common/components/odroid/odroid_hud.c +++ b/Components/odroid-go-handy/odroid-go-common/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,30 +244,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "lynx";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -280,15 +280,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -349,7 +349,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -363,10 +363,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -379,18 +379,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -400,19 +400,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -420,12 +420,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -433,55 +433,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -491,10 +494,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -503,13 +506,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -519,7 +522,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -533,16 +536,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); //ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/odroid-go-pcengine-huexpress/odroid-go-common/components/odroid/odroid_hud.c b/Components/odroid-go-pcengine-huexpress/odroid-go-common/components/odroid/odroid_hud.c index 94fb1e22..4948067a 100644 --- a/Components/odroid-go-pcengine-huexpress/odroid-go-common/components/odroid/odroid_hud.c +++ b/Components/odroid-go-pcengine-huexpress/odroid-go-common/components/odroid/odroid_hud.c @@ -484,6 +484,9 @@ //{#pragma region Menu void hud_menu(void) { int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); hud_init(); hud_debug("HUD - MENU"); diff --git a/Components/odroid-go-spectrum-emulator/components/odroid/odroid_hud.c b/Components/odroid-go-spectrum-emulator/components/odroid/odroid_hud.c index 238533f7..70c0b263 100644 --- a/Components/odroid-go-spectrum-emulator/components/odroid/odroid_hud.c +++ b/Components/odroid-go-spectrum-emulator/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void hud_debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,30 +244,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "spectrum";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -280,15 +280,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp:%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp:%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -349,7 +349,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -363,10 +363,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -379,18 +379,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -400,19 +400,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -420,12 +420,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -433,55 +433,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 10 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //hud_debounce(ODROID_INPUT_UP); @@ -491,10 +494,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //hud_debounce(ODROID_INPUT_DOWN); + //hud_debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -503,13 +506,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; hud_debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -519,7 +522,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -533,16 +536,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } hud_debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/pitpo/odroid-go-common/components/odroid/odroid_hud.c b/Components/pitpo/odroid-go-common/components/odroid/odroid_hud.c index df05dad8..25cc92f6 100644 --- a/Components/pitpo/odroid-go-common/components/odroid/odroid_hud.c +++ b/Components/pitpo/odroid-go-common/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,28 +244,28 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { char * dir = strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir+1); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir+1); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -278,14 +278,14 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); + printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -346,7 +346,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -360,10 +360,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -376,18 +376,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -397,19 +397,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -417,12 +417,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -430,55 +430,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -488,10 +491,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -500,13 +503,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -516,7 +519,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -530,16 +533,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/prosystem-odroid-go/components/odroid/odroid_hud.c b/Components/prosystem-odroid-go/components/odroid/odroid_hud.c index b910b45e..5e86cb00 100644 --- a/Components/prosystem-odroid-go/components/odroid/odroid_hud.c +++ b/Components/prosystem-odroid-go/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; int OPTIONS = 3; extern int ACTION = 0; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -90,9 +90,9 @@ STATES WITHOUTSAVE[3] = { {"Resume Game",0, 0}, {"Restart Game",1, 10}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -124,7 +124,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -205,7 +205,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -216,12 +216,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -230,7 +230,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -243,30 +243,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "lynx";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -279,15 +279,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -348,7 +348,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -362,10 +362,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -378,18 +378,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -399,19 +399,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -419,12 +419,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -432,44 +432,47 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 3; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; hud_debug("HUD - INIT"); - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; hud_debug("HUD - DEINIT"); } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); //hud_background(); //hud_logo(); @@ -479,13 +482,13 @@ const uint16_t FONT_5x7[7][250] = { hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -495,10 +498,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -508,13 +511,13 @@ const uint16_t FONT_5x7[7][250] = { ili9341_clear(0); debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -524,7 +527,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" //odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -538,16 +541,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/retro-go/components/odroid/odroid_hud.c b/Components/retro-go/components/odroid/odroid_hud.c index 2fab846b..325300c3 100644 --- a/Components/retro-go/components/odroid/odroid_hud.c +++ b/Components/retro-go/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,28 +244,28 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { char * dir = strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir+1); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir+1); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -278,14 +278,14 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); + printf("\n******\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n******\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -346,7 +346,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -360,10 +360,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -376,18 +376,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -397,19 +397,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -417,12 +417,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -430,55 +430,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -488,10 +491,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -500,13 +503,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -516,7 +519,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -528,17 +531,16 @@ const uint16_t FONT_5x7[7][250] = { case 5: // "Delete Save" hud_progress("Deleting...", true); hud_prepare_delete(1); - ili9341_blank_screen(); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/stella-odroid-go/components/odroid/odroid_hud.c b/Components/stella-odroid-go/components/odroid/odroid_hud.c index 3f0d3541..73155281 100644 --- a/Components/stella-odroid-go/components/odroid/odroid_hud.c +++ b/Components/stella-odroid-go/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; int OPTIONS = 3; int ACTION; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -90,9 +90,9 @@ STATES WITHOUTSAVE[3] = { {"Resume Game",0, 0}, {"Restart Game",1, 10}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -124,7 +124,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -205,7 +205,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -216,12 +216,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -230,7 +230,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -243,30 +243,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "lynx";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -279,15 +279,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -348,7 +348,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -362,10 +362,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -378,18 +378,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -399,19 +399,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -419,12 +419,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -432,44 +432,47 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 3; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; hud_debug("HUD - INIT"); - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; hud_debug("HUD - DEINIT"); } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); //hud_background(); //hud_logo(); @@ -479,13 +482,13 @@ const uint16_t FONT_5x7[7][250] = { hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -495,10 +498,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -508,13 +511,13 @@ const uint16_t FONT_5x7[7][250] = { ili9341_clear(0); debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -524,7 +527,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" //odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -538,16 +541,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Components/super-go-play/odroid-go-common/components/odroid/odroid_hud.c b/Components/super-go-play/odroid-go-common/components/odroid/odroid_hud.c index 68f25af3..b7604aaa 100644 --- a/Components/super-go-play/odroid-go-common/components/odroid/odroid_hud.c +++ b/Components/super-go-play/odroid-go-common/components/odroid/odroid_hud.c @@ -464,6 +464,9 @@ //{#pragma region Menu void hud_menu(void) { int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); hud_init(); hud_debug("HUD - MENU"); diff --git a/Emulators/handy-go/components/odroid/odroid_hud.c b/Emulators/handy-go/components/odroid/odroid_hud.c index 0fd86fea..bfef876b 100644 --- a/Emulators/handy-go/components/odroid/odroid_hud.c +++ b/Emulators/handy-go/components/odroid/odroid_hud.c @@ -7,12 +7,12 @@ #include #include #include - #include - #include + #include + #include /* General - */ + */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "nvs_flash.h" @@ -52,7 +52,7 @@ //{#pragma region Globals #define WHITE 65535 - #define BLACK 0 + #define BLACK 0 int OPTION = 0; extern int ACTION = 0; int OPTIONS = 3; @@ -61,7 +61,7 @@ int x, y, w, h, i, size; uint16_t *buffer; bool INIT = false; - bool SAVED = false; + bool SAVED = false; bool forceConsoleReset; //}#pragma endregion Globals @@ -72,7 +72,7 @@ int w; int h; } SCR; - SCR SCREEN = {0,0,320,240}; + SCR SCREEN = {0,0,320,240}; typedef struct{ char label[20]; @@ -91,9 +91,9 @@ {"Resume Game",0, 0}, {"Restart Game",1, 10}, {"Save Game",3, 25}, - {"Exit Game",6, 20} - }; - STATES STATE; + {"Exit Game",6, 20} + }; + STATES STATE; typedef struct{ int bg; @@ -125,7 +125,7 @@ {29614,52857,"light"} }; THEME GUI; -//}#pragma endregion Structs +//}#pragma endregion Structs //{#pragma region Sprites const uint16_t FONT_5x7[7][250] = { @@ -206,7 +206,7 @@ const uint16_t FONT_5x7[7][250] = { //{#pragma region Debounce void debounce(int key) { - while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); + while (gamepad.values[key]) odroid_input_gamepad_read(&gamepad); } //}#pragma endregion Debounce @@ -217,12 +217,12 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; nvs_open("storage", NVS_READWRITE, &handle); nvs_set_i8(handle, "DELETE_SAVE", del); - nvs_commit(handle); - nvs_close(handle); + nvs_commit(handle); + nvs_close(handle); } void hud_delete_save(char *file_to_delete) { @@ -231,7 +231,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -244,30 +244,30 @@ const uint16_t FONT_5x7[7][250] = { break; default : DELETE_SAVE = 0; - } - nvs_close(handle); - printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); + } + nvs_close(handle); + printf("\nDELETE_SAVE:%d\n\n", DELETE_SAVE); if(DELETE_SAVE == 1) { hud_prepare_delete(0); struct stat st; - if (stat(file_to_delete, &st) == 0) { + if (stat(file_to_delete, &st) == 0) { unlink(file_to_delete); esp_restart(); - } - } - } + } + } + } void hud_check_saves(char *save_name) { hud_debug("hud_check_saves START"); char * dir = "lynx";//strrchr(save_name, '.'); char save_dir[256] = "/sd/odroid/data/"; - strcat(&save_dir[strlen(save_dir) - 1], dir); - char file_to_delete[256] = ""; + strcat(&save_dir[strlen(save_dir) - 1], dir); + char file_to_delete[256] = ""; sprintf(file_to_delete, "%s/%s", save_dir, save_name); - strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); - printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); - DIR *directory; - directory = opendir(save_dir); + strcat(&file_to_delete[strlen(file_to_delete) - 1], ".sav"); + printf("\nSEARCH\nfile_to_delete:%s\nsave_dir:%s\n", file_to_delete, save_dir); + DIR *directory; + directory = opendir(save_dir); if(directory == NULL) { perror("opendir() error"); } else { @@ -280,15 +280,15 @@ const uint16_t FONT_5x7[7][250] = { gets(tmp); if(strcmp(save_name, tmp) == 0) { SAVED = true; - printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); + printf("\nFOUND\nfile_to_delete:%s\nsave_name:%s\ntmp%s\n", file_to_delete, save_name, tmp); hud_delete_save(file_to_delete); } - } + } closedir(directory); } hud_debug("hud_check_saves END"); } -//}#pragma endregion Files +//}#pragma endregion Files //{#pragma region Text int hud_letter(char letter) { @@ -349,7 +349,7 @@ const uint16_t FONT_5x7[7][250] = { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } - ESP_ERROR_CHECK( err ); + ESP_ERROR_CHECK( err ); nvs_handle handle; err = nvs_open("storage", NVS_READWRITE, &handle); @@ -363,10 +363,10 @@ const uint16_t FONT_5x7[7][250] = { break; default : USER = 0; - } + } nvs_close(handle); } -//}#pragma endregion Theme +//}#pragma endregion Theme //{#pragma region Display void hud_logo() { @@ -379,18 +379,18 @@ const uint16_t FONT_5x7[7][250] = { for(int c = 0; c < w; c++) { buffer[i] = logo[r][c] == 0 ? GUI.bg : GUI.fg; i++; - } - } - ili9341_write_frame_rectangleLE(x, y, w, h, buffer); + } + } + ili9341_write_frame_rectangleLE(x, y, w, h, buffer); //hud_text(x,y+18,"In Game Menu",false,false); - } + } void hud_progress(char *string, bool bar) { hud_background(); - hud_logo(); + hud_logo(); w = strlen(string)*5; x = (SCREEN.w/2)-(w/2); - y = (SCREEN.h/2)-(h/2); + y = (SCREEN.h/2)-(h/2); hud_text(x,y,string,false,false); if(bar) { y+=10; @@ -400,19 +400,19 @@ const uint16_t FONT_5x7[7][250] = { } ili9341_write_frame_rectangleLE(x+n, y, 1, 5, buffer); usleep(15000); - } + } } - } + } void hud_options() { x = 16; - y = 28; + y = 28; w = 5; h = 5; i = 0; int n; if(OPTIONS == 6) { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -420,12 +420,12 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); i = 0; } STATE = WITHSAVE[OPTION]; } else { - for(n = 0; n < OPTIONS; n++) { + for(n = 0; n < OPTIONS; n++) { STATE = WITHOUTSAVE[n]; y+=20; for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) { @@ -433,55 +433,58 @@ const uint16_t FONT_5x7[7][250] = { }} if(n == OPTIONS-1) {y = 216;} ili9341_write_frame_rectangleLE(x, y, w, h, buffer); - hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); - i = 0; - } - STATE = WITHOUTSAVE[OPTION]; + hud_text(x+10,y,STATE.label,false,OPTION == n?true:false); + i = 0; + } + STATE = WITHOUTSAVE[OPTION]; } } -//}#pragma endregion Display +//}#pragma endregion Display //{#pragma region Init - void hud_init() { + void hud_init() { if(!INIT) { size = 320 * 30 * sizeof(uint16_t); - buffer = (uint16_t *)malloc(size); - if (!buffer) abort(); - OPTION = 0; + buffer = (uint16_t *)malloc(size); + if (!buffer) abort(); + OPTION = 0; OPTIONS = SAVED ? 6 : 4; hud_theme(); GUI = THEMES[USER]; - STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; + STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION]; INIT = true; - } + } } void hud_deinit() { size = 0; - buffer = realloc(buffer, size); + buffer = realloc(buffer, size); free(buffer); INIT = false; } -//}#pragma endregion Init +//}#pragma endregion Init //{#pragma region Menu void hud_menu(void) { - int volume = odroid_audio_volume_get(); + int volume = odroid_audio_volume_get(); + #ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32 + volume = 4; + #endif odroid_audio_terminate(); - hud_init(); + hud_init(); hud_debug("HUD - MENU"); hud_background(); hud_logo(); hud_options(); while(1) { - odroid_input_gamepad_read(&gamepad); + odroid_input_gamepad_read(&gamepad); /* UP */ if (gamepad.values[ODROID_INPUT_UP]) { OPTION--; - if( OPTION < 0 ) { OPTION = OPTIONS-1; } + if( OPTION < 0 ) { OPTION = OPTIONS-1; } hud_options(); usleep(200000); //debounce(ODROID_INPUT_UP); @@ -491,10 +494,10 @@ const uint16_t FONT_5x7[7][250] = { */ if (gamepad.values[ODROID_INPUT_DOWN]) { OPTION++; - if( OPTION >= OPTIONS ) { OPTION = 0; } + if( OPTION >= OPTIONS ) { OPTION = 0; } hud_options(); usleep(200000); - //debounce(ODROID_INPUT_DOWN); + //debounce(ODROID_INPUT_DOWN); } /* BUTTON B @@ -503,13 +506,13 @@ const uint16_t FONT_5x7[7][250] = { ACTION = 0; debounce(ODROID_INPUT_B); return 0; - } + } /* BUTTON A */ if (gamepad.values[ODROID_INPUT_A]) { - odroid_audio_volume_set(volume); - hud_debug(STATE.label); + odroid_audio_volume_set(volume); + hud_debug(STATE.label); ACTION = STATE.action; switch(ACTION) { case 0: // "Resume Game" @@ -519,7 +522,7 @@ const uint16_t FONT_5x7[7][250] = { case 1: // "Restart Game" odroid_settings_StartAction_set(1); forceConsoleReset = true; - esp_restart(); + esp_restart(); break; case 2: // "Reload Game" esp_restart(); @@ -533,16 +536,16 @@ const uint16_t FONT_5x7[7][250] = { hud_progress("Deleting...", true); hud_prepare_delete(1); ili9341_clear(0); - esp_restart(); + esp_restart(); //return 0; break; case 6: // "Exit Game" odroid_system_application_set(0); - esp_restart(); - break; + esp_restart(); + break; } debounce(ODROID_INPUT_A); } } } -//}#pragma endregion Menu \ No newline at end of file +//}#pragma endregion Menu diff --git a/Launchers/retro-esp32/main/includes/definitions.h b/Launchers/retro-esp32/main/includes/definitions.h index 7de5eecd..781d5681 100644 --- a/Launchers/retro-esp32/main/includes/definitions.h +++ b/Launchers/retro-esp32/main/includes/definitions.h @@ -35,7 +35,7 @@ /* */ -#define BUILD "Version 2 Build 0 (v.2.0)" +#define BUILD "Version 2 Build 1 (v.2.1)" #define _GNU_SOURCE diff --git a/Odroid/odroid-go-firmware b/Odroid/odroid-go-firmware index 8f556849..296aa5b8 160000 --- a/Odroid/odroid-go-firmware +++ b/Odroid/odroid-go-firmware @@ -1 +1 @@ -Subproject commit 8f5568498f5429686637ee5765784e2464836ca0 +Subproject commit 296aa5b81d96248bcb658adbb5a7c855ab523364 diff --git a/Scripts/helpers/process b/Scripts/helpers/process index d3933014..642deed2 100755 --- a/Scripts/helpers/process +++ b/Scripts/helpers/process @@ -17,53 +17,65 @@ BIN="" TILE="" NAME="" -# set_handy_option -set_handy_option() { - clear - HANDY="n" - OPTION="${bomb} Would you like to use ${magenta}'Odroid Go Handy'? ${nc}[y/${bold}N${nc}]" +HANDY_OPTION_PATH="" +NES_OPTION_PATH="" + +# set_nes_path +set_nes_path() { + NES=("go-play" "super-go-play" "retro-go") + OPTION="${monkey} ${red}Please Select ${cyan}NES Emulator${nc}" echo "--------------------------------------------------------------------------" echo -e "${OPTION}" echo "--------------------------------------------------------------------------" - read -n 1 -r response - if [[ "$response" = "y" ]] - then - HANDY="y" - fi - clear -} - -# get_handy_option -get_handy_option() { - if [[ "$HANDY" = "y" ]] - then - cd $HANDY_PATH - fi + select EMU in "${NES[@]}" + do + case $EMU in + * ) + if [[ $EMU[0,1] ]] + then + clear + echo "--------------------------------------------------------------------------" + echo -e "${squid} ${green}Selected ${cyan}${EMU#*.}${nc} as NES Emulator" + echo "--------------------------------------------------------------------------" + NES_OPTION_PATH="$REPO/Emulators/${EMU#*.}" + sleep 1 + clear + break + else + set_nes_path + fi + esac + done } -# set_nes_option -set_nes_option() { - clear - SUPER="n" - OPTION="${bomb} Would you like to use ${magenta}'Super Go Play'? ${nc}[y/${bold}N${nc}]" +# set_handy_path +set_handy_path() { + NES=("handy-go" "odroid-go-handy/handy-go") + OPTION="${monkey} ${red}Please Select ${cyan}LYNX Emulator${nc}" echo "--------------------------------------------------------------------------" echo -e "${OPTION}" echo "--------------------------------------------------------------------------" - read -n 1 -r response - if [[ "$response" = "y" ]] - then - SUPER="y" - fi - clear + select EMU in "${NES[@]}" + do + case $EMU in + * ) + if [[ $EMU[0,1] ]] + then + clear + echo "--------------------------------------------------------------------------" + echo -e "${squid} ${green}Selected ${cyan}${EMU#*.}${nc} as LYNX Emulator" + echo "--------------------------------------------------------------------------" + HANDY_OPTION_PATH="$REPO/Emulators/${EMU#*.}" + sleep 1 + clear + break + else + set_handy_path + fi + esac + done } -# get_nes_option -get_nes_option() { - if [[ "$SUPER" = "y" ]] - then - cd $SUPER_GOPLAY_PATH - fi -} # set_config_option set_config_option() { @@ -182,7 +194,7 @@ then cd $LAUNCHER_PATH get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/bootloader/bootloader.bin $FIRMWARE_PATH/Bins/ cp ./build/partitions.bin $FIRMWARE_PATH/Bins/ @@ -211,8 +223,9 @@ if [[ "$response" = "y" ]] then set_clean_option set_config_option - set_nes_option - set_handy_option + + set_nes_path + set_handy_path cd $SUPER_GOPLAY_PATH @@ -223,12 +236,10 @@ then cd gnuboy-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/gnuboy-go.bin $FIRMWARE_PATH/Bins/ - cd $GOPLAY_PATH - #cd $SUPER_GOPLAY_PATH - get_nes_option + cd $NES_OPTION_PATH clear echo "--------------------------------------------------------------------------" echo -e "${game} ${green}Compiling ${cyan}nesemu-go${nc}" @@ -236,7 +247,7 @@ then cd nesemu-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/nesemu-go.bin $FIRMWARE_PATH/Bins/ cd $GOPLAY_PATH @@ -248,7 +259,7 @@ then cd smsplusgx-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/smsplusgx-go.bin $FIRMWARE_PATH/Bins/ @@ -260,7 +271,7 @@ then cd prosystem-odroid-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/prosystem-go.bin $FIRMWARE_PATH/Bins/ clear @@ -271,19 +282,18 @@ then cd stella-odroid-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/stella-go.bin $FIRMWARE_PATH/Bins/ clear echo "--------------------------------------------------------------------------" echo -e "${game} ${green}Compiling ${cyan}handy-go${nc}" echo "--------------------------------------------------------------------------" - cd $EMULATOR_PATH - get_handy_option + cd $HANDY_OPTION_PATH cd handy-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/handy-go.bin $FIRMWARE_PATH/Bins/ clear @@ -294,7 +304,7 @@ then cd odroid-go-pcengine-huexpress/pcengine-go get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/pcengine-go.bin $FIRMWARE_PATH/Bins/ clear @@ -305,7 +315,7 @@ then cd odroid-go-spectrum-emulator get_clean_option get_config_option - make -j8 + make -j8 -s cp ./build/spectrum.bin $FIRMWARE_PATH/Bins/ fi diff --git a/Scripts/ota b/Scripts/ota index 43b318c4..4bc5b61b 100755 --- a/Scripts/ota +++ b/Scripts/ota @@ -33,33 +33,106 @@ source helpers/bauds #--------------------------------- source helpers/eraser - clear echo "--------------------------------------------------------------------------" -echo -e "${game} ${green}Flashing Device ${nc} - Hang Tight" +echo -e "${game} ${green}Single Flash or By Address ${nc}" +echo -e "\t Single Flash? [y/${bold}N${nc}]" echo "--------------------------------------------------------------------------" +read -n 1 -r response +clear +if [[ "$response" = "y" ]] +then + echo "--------------------------------------------------------------------------" + echo -e "${game} ${green}Flashing Device ${nc} - Hang Tight" + echo "--------------------------------------------------------------------------" + esptool.py \ + --chip esp32 \ + --port ${PORT} \ + --baud ${BAUD} \ + --before default_reset \ + --after hard_reset write_flash -z \ + --flash_mode dio \ + --flash_freq 80m \ + --flash_size detect \ + 0x1000 $FIRMWARE_PATH/Bins/bootloader.bin \ + 0x8000 $FIRMWARE_PATH/Bins/partitions.bin \ + 0x10000 $FIRMWARE_PATH/Bins/${BIN}.bin \ + 0x200000 $FIRMWARE_PATH/Bins/${BIN}.bin \ + 0x280000 $FIRMWARE_PATH/Bins/nesemu-go.bin \ + 0x340000 $FIRMWARE_PATH/Bins/gnuboy-go.bin \ + 0x3F0000 $FIRMWARE_PATH/Bins/smsplusgx-go.bin \ + 0x550000 $FIRMWARE_PATH/Bins/spectrum.bin \ + 0x5E0000 $FIRMWARE_PATH/Bins/stella-go.bin \ + 0x780000 $FIRMWARE_PATH/Bins/prosystem-go.bin \ + 0x840000 $FIRMWARE_PATH/Bins/handy-go.bin \ + 0x930000 $FIRMWARE_PATH/Bins/pcengine-go.bin +else + ADDRESSES=( + "0x1000" + "0x8000" + "0x10000" + "0x200000" + "0x280000" + "0x340000" + "0x3F0000" + "0x550000" + "0x5E0000" + "0x780000" + "0x840000" + "0x930000" + ) + + NAMES=( + "bootloader" + "partitions" + "${BIN}" + "${BIN}" + "nesemu-go" + "gnuboy-go" + "smsplusgx-go" + "spectrum" + "stella-go" + "prosystem-go" + "handy-go" + "pcengine-go" + ) + + BINS=( + "$FIRMWARE_PATH/Bins/bootloader.bin" + "$FIRMWARE_PATH/Bins/partitions.bin" + "$FIRMWARE_PATH/Bins/${BIN}.bin" + "$FIRMWARE_PATH/Bins/${BIN}.bin" + "$FIRMWARE_PATH/Bins/nesemu-go.bin" + "$FIRMWARE_PATH/Bins/gnuboy-go.bin" + "$FIRMWARE_PATH/Bins/smsplusgx-go.bin" + "$FIRMWARE_PATH/Bins/spectrum.bin" + "$FIRMWARE_PATH/Bins/stella-go.bin" + "$FIRMWARE_PATH/Bins/prosystem-go.bin" + "$FIRMWARE_PATH/Bins/handy-go.bin" + "$FIRMWARE_PATH/Bins/pcengine-go.bin" + ) + + clear + for i in "${!ADDRESSES[@]}" + do + echo "--------------------------------------------------------------------------" + echo -e "${game} Writing ${cyan}${NAMES[i]}${nc} to ${green}${ADDRESSES[i]}${nc}" + echo "--------------------------------------------------------------------------" + esptool.py \ + --chip esp32 \ + --port ${PORT} \ + --baud ${BAUD} \ + --before default_reset \ + --after hard_reset write_flash -z \ + --flash_mode dio \ + --flash_freq 80m \ + --flash_size detect \ + --no-progress \ + ${ADDRESSES[i]} ${BINS[i]} -esptool.py \ ---chip esp32 \ ---port ${PORT} \ ---baud ${BAUD} \ ---before default_reset \ ---after hard_reset write_flash -z \ ---flash_mode dio \ ---flash_freq 80m \ ---flash_size detect \ -0x1000 $FIRMWARE_PATH/Bins/bootloader.bin \ -0x8000 $FIRMWARE_PATH/Bins/partitions.bin \ -0x10000 $FIRMWARE_PATH/Bins/${BIN}.bin \ -0x200000 $FIRMWARE_PATH/Bins/${BIN}.bin \ -0x280000 $FIRMWARE_PATH/Bins/nesemu-go.bin \ -0x340000 $FIRMWARE_PATH/Bins/gnuboy-go.bin \ -0x3F0000 $FIRMWARE_PATH/Bins/smsplusgx-go.bin \ -0x550000 $FIRMWARE_PATH/Bins/spectrum.bin \ -0x5E0000 $FIRMWARE_PATH/Bins/stella-go.bin \ -0x780000 $FIRMWARE_PATH/Bins/prosystem-go.bin \ -0x840000 $FIRMWARE_PATH/Bins/handy-go.bin \ -0x930000 $FIRMWARE_PATH/Bins/pcengine-go.bin + clear + done +fi #--------------------------------- # Goodbye