Skip to content

Commit

Permalink
Improve select profile menu to display profiles from all CPLD variants
Browse files Browse the repository at this point in the history
  • Loading branch information
IanSB committed Feb 28, 2023
1 parent 833f8bf commit 0c875c0
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 67 deletions.
3 changes: 3 additions & 0 deletions src/cpld.h
Expand Up @@ -30,6 +30,9 @@ typedef struct {
// for the two different CPLD implementations
typedef struct {
const char *name;
const char *nameBBC;
const char *nameRGB;
const char *nameYUV;
const char *default_profile;
void (*init)(int cpld_version);
int (*get_version)();
Expand Down
3 changes: 3 additions & 0 deletions src/cpld_atom.c
Expand Up @@ -279,6 +279,9 @@ static void cpld_set_frontend(int value) {

cpld_t cpld_atom = {
.name = "Atom",
.nameBBC = "Atom",
.nameRGB = "Atom",
.nameYUV = "Atom",
.default_profile = "Acorn/Acorn_Atom",
.init = cpld_init,
.get_version = cpld_get_version,
Expand Down
15 changes: 15 additions & 0 deletions src/cpld_null.c
Expand Up @@ -92,6 +92,9 @@ static void cpld_set_frontend(int value)

cpld_t cpld_null_atom = {
.name = "Atom",
.nameBBC = "Atom",
.nameRGB = "Atom",
.nameYUV = "Atom",
.default_profile = "Acorn/Atom",
.init = cpld_init,
.get_version = cpld_get_version,
Expand All @@ -117,6 +120,9 @@ cpld_t cpld_null_atom = {

cpld_t cpld_null_3bit = {
.name = "3-12_BIT_BBC",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "3-12_BIT_BBC",
.nameYUV = "3-12_BIT_BBC",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init,
.get_version = cpld_get_version,
Expand All @@ -142,6 +148,9 @@ cpld_t cpld_null_3bit = {

cpld_t cpld_null_6bit = {
.name = "3-12_BIT_BBC",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "6-12_BIT_RGB",
.nameYUV = "6-12_BIT_YUV",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init,
.get_version = cpld_get_version,
Expand All @@ -167,6 +176,9 @@ cpld_t cpld_null_6bit = {

cpld_t cpld_null_simple = {
.name = "Simple",
.nameBBC = "Simple",
.nameRGB = "Simple",
.nameYUV = "Simple",
.default_profile = "Commodore/Amiga",
.init = cpld_init,
.get_version = cpld_get_version,
Expand All @@ -192,6 +204,9 @@ cpld_t cpld_null_simple = {

cpld_t cpld_null = {
.name = "3-12_BIT_BBC",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "6-12_BIT_RGB",
.nameYUV = "6-12_BIT_YUV",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init,
.get_version = cpld_get_version,
Expand Down
27 changes: 27 additions & 0 deletions src/cpld_rgb.c
Expand Up @@ -2194,6 +2194,9 @@ static int cpld_frontend_info_bbc() {

cpld_t cpld_bbc = {
.name = "3-12_BIT_BBC",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "3-12_BIT_BBC",
.nameYUV = "3-12_BIT_BBC",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init_bbc,
.get_version = cpld_get_version,
Expand All @@ -2219,6 +2222,9 @@ cpld_t cpld_bbc = {

cpld_t cpld_bbcv10v20 = {
.name = "Legacy_3_BIT",
.nameBBC = "Legacy_3_BIT",
.nameRGB = "Legacy_3_BIT",
.nameYUV = "Legacy_3_BIT",
.default_profile = "Acorn/BBC_Micro_v10-v20",
.init = cpld_init_bbc,
.get_version = cpld_get_version,
Expand All @@ -2244,6 +2250,9 @@ cpld_t cpld_bbcv10v20 = {

cpld_t cpld_bbcv21v23 = {
.name = "Legacy_3_BIT",
.nameBBC = "Legacy_3_BIT",
.nameRGB = "Legacy_3_BIT",
.nameYUV = "Legacy_3_BIT",
.default_profile = "Acorn/BBC_Micro_v21-v23",
.init = cpld_init_bbc,
.get_version = cpld_get_version,
Expand All @@ -2269,6 +2278,9 @@ cpld_t cpld_bbcv21v23 = {

cpld_t cpld_bbcv24 = {
.name = "Legacy_3_BIT",
.nameBBC = "Legacy_3_BIT",
.nameRGB = "Legacy_3_BIT",
.nameYUV = "Legacy_3_BIT",
.default_profile = "Acorn/BBC_Micro_v24",
.init = cpld_init_bbc,
.get_version = cpld_get_version,
Expand All @@ -2294,6 +2306,9 @@ cpld_t cpld_bbcv24 = {

cpld_t cpld_bbcv30v62 = {
.name = "Legacy_3_BIT",
.nameBBC = "Legacy_3_BIT",
.nameRGB = "Legacy_3_BIT",
.nameYUV = "Legacy_3_BIT",
.default_profile = "Acorn/BBC_Micro_v30-v62",
.init = cpld_init_bbc,
.get_version = cpld_get_version,
Expand Down Expand Up @@ -2333,6 +2348,9 @@ static int cpld_frontend_info_rgb_ttl() {

cpld_t cpld_rgb_ttl = {
.name = "6-12_BIT_RGB",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "6-12_BIT_RGB",
.nameYUV = "6-12_BIT_YUV",
.default_profile = "Acorn/Acorn_Electron",
.init = cpld_init_rgb_ttl,
.get_version = cpld_get_version,
Expand All @@ -2358,6 +2376,9 @@ cpld_t cpld_rgb_ttl = {

cpld_t cpld_rgb_ttl_24mhz = {
.name = "3-12_BIT_BBC",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "6-12_BIT_RGB",
.nameYUV = "6-12_BIT_YUV",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init_rgb_ttl,
.get_version = cpld_get_version,
Expand Down Expand Up @@ -2407,6 +2428,9 @@ static void cpld_set_frontend_rgb_analog(int value) {

cpld_t cpld_rgb_analog = {
.name = "6-12_BIT_RGB_Analog",
.nameBBC = "3-12_BIT_BBC_Analog",
.nameRGB = "6-12_BIT_RGB_Analog",
.nameYUV = "6-12_BIT_YUV_Analog",
.default_profile = "Amstrad/Amstrad_CPC",
.init = cpld_init_rgb_analog,
.get_version = cpld_get_version,
Expand All @@ -2433,6 +2457,9 @@ cpld_t cpld_rgb_analog = {

cpld_t cpld_rgb_analog_24mhz = {
.name = "3-12_BIT_BBC_Analog",
.nameBBC = "3-12_BIT_BBC_Analog",
.nameRGB = "6-12_BIT_RGB_Analog",
.nameYUV = "6-12_BIT_YUV_Analog",
.default_profile = "Acorn/BBC_Micro",
.init = cpld_init_rgb_analog,
.get_version = cpld_get_version,
Expand Down
3 changes: 3 additions & 0 deletions src/cpld_simple.c
Expand Up @@ -522,6 +522,9 @@ static void cpld_set_frontend(int value)

cpld_t cpld_simple = {
.name = "Simple",
.nameBBC = "Simple",
.nameRGB = "Simple",
.nameYUV = "Simple",
.default_profile = "Commodore/Amiga",
.init = cpld_init,
.get_version = cpld_get_version,
Expand Down
6 changes: 6 additions & 0 deletions src/cpld_yuv.c
Expand Up @@ -1427,6 +1427,9 @@ static void cpld_init_ttl(int value) {

cpld_t cpld_yuv_analog = {
.name = "6-12_BIT_YUV_Analog",
.nameBBC = "3-12_BIT_BBC_Analog",
.nameRGB = "6-12_BIT_RGB_Analog",
.nameYUV = "6-12_BIT_YUV_Analog",
.default_profile = "Apple/Apple_II",
.init = cpld_init_analog,
.get_version = cpld_get_version,
Expand All @@ -1451,6 +1454,9 @@ cpld_t cpld_yuv_analog = {

cpld_t cpld_yuv_ttl = {
.name = "6-12_BIT_YUV",
.nameBBC = "3-12_BIT_BBC",
.nameRGB = "6-12_BIT_RGB",
.nameYUV = "6-12_BIT_YUV",
.default_profile = "Apple/Apple_IIc_TTL",
.init = cpld_init_ttl,
.get_version = cpld_get_version,
Expand Down
5 changes: 5 additions & 0 deletions src/defs.h
Expand Up @@ -333,6 +333,11 @@ typedef struct {
#define FORCE_UPDATE_FILE_MESSAGE "Deleting this file will force a CPLD update check on the next reset\r\n"
#define BLANK_FILE "/cpld_firmware/recovery/blank/BLANK.xsvf"

#define BBC_CPLD_HEADER "(BBC) "
#define RGB_CPLD_HEADER "(RGB) "
#define YUV_CPLD_HEADER "(YUV) "
#define CPLD_HEADER_LENGTH 6

#define PAXHEADER "PaxHeader"

#define NTSC_SOFT 0x04
Expand Down
92 changes: 57 additions & 35 deletions src/filesystem.c
Expand Up @@ -466,23 +466,20 @@ void capture_screenshot(capture_info_t *capinfo, char *profile) {

}

unsigned int file_read_profile(char *profile_name, int saved_config_number, char *sub_profile_name, int updatecmd, char *command_string, unsigned int buffer_size) {
void write_profile_choice(char *profile_name, int saved_config_number, char *cpld_name) {
FRESULT result;
char path[MAX_STRING_SIZE];
char cmdline[100];
FIL file;
unsigned int bytes_read = 0;
unsigned int num_written = 0;
char path[MAX_STRING_SIZE];
char cmdline[MAX_STRING_SIZE];
init_filesystem();

if (updatecmd) {
char name[100];
sprintf(name, "/profile_%s.txt", cpld->name);
result = f_open(&file, name, FA_WRITE | FA_CREATE_ALWAYS);
sprintf(path, "/profile_%s.txt", cpld_name);
log_info("Writing: %s", path);
result = f_open(&file, path, FA_WRITE | FA_CREATE_ALWAYS);
if (result != FR_OK) {
log_warn("Failed to open %s (result = %d)", path, result);
close_filesystem();
return 0;
return;
} else {

sprintf(cmdline, "profile=%s\r\n", profile_name);
Expand All @@ -494,22 +491,34 @@ unsigned int file_read_profile(char *profile_name, int saved_config_number, char
if (result != FR_OK) {
log_warn("Failed to write %s (result = %d)", path, result);
close_filesystem();
return 0;
return;
} else if (num_written != cmdlength) {
log_warn("%s is incomplete (%d < %d bytes)", path, num_written, cmdlength);
close_filesystem();
return 0;
return;
}

result = f_close(&file);
if (result != FR_OK) {
log_warn("Failed to close %s (result = %d)", path, result);
close_filesystem();
return 0;
return;
}
}
close_filesystem();
}

unsigned int file_read_profile(char *profile_name, int saved_config_number, char *sub_profile_name, int updatecmd, char *command_string, unsigned int buffer_size) {
FRESULT result;
char path[MAX_STRING_SIZE];
FIL file;
unsigned int bytes_read = 0;
if (updatecmd) {
write_profile_choice(profile_name, saved_config_number, (char*)cpld->name);
}

init_filesystem();

if (saved_config_number == 0) {
if (sub_profile_name != NULL) {
sprintf(path, "%s/%s/%s/%s.txt", SAVED_PROFILE_BASE, cpld->name, profile_name, sub_profile_name);
Expand Down Expand Up @@ -604,7 +613,8 @@ void scan_cpld_filenames(char cpld_filenames[MAX_CPLD_FILENAMES][MAX_FILENAME_WI
close_filesystem();
}

void scan_profiles(char manufacturer_names[MAX_PROFILES][MAX_PROFILE_WIDTH], char profile_names[MAX_PROFILES][MAX_PROFILE_WIDTH], int has_sub_profiles[MAX_PROFILES], char *path, size_t *mcount, size_t *count) {
void scan_profiles(char prefix[MAX_PROFILE_WIDTH], char manufacturer_names[MAX_PROFILES][MAX_PROFILE_WIDTH], char profile_names[MAX_PROFILES][MAX_PROFILE_WIDTH], int has_sub_profiles[MAX_PROFILES], char *path, size_t *mcount, size_t *count) {
int initial_count = *count;
FRESULT res;
DIR dir;
FIL file;
Expand All @@ -618,54 +628,66 @@ void scan_profiles(char manufacturer_names[MAX_PROFILES][MAX_PROFILE_WIDTH], cha
if (res != FR_OK || fno.fname[0] == 0 || *mcount == MAX_PROFILES) break;
if (fno.fattrib & AM_DIR && strcmp(fno.fname, PAXHEADER) != 0) {
fno.fname[MAX_PROFILE_WIDTH - 1] = 0;
strcpy(manufacturer_names[*mcount], fno.fname);
log_info("manufname: %s", manufacturer_names[*mcount]);
(*mcount)++;
int duplicate = 0;
if (*mcount != 0) {
for (int k = 0; k < *mcount; k++) {
if (strcmp(fno.fname, manufacturer_names[k]) == 0) {
duplicate = 1;
break;
}
}
}

if (duplicate == 0) {
strcpy(manufacturer_names[*mcount], fno.fname);
(*mcount)++;
} else {
}
}
}
f_closedir(&dir);
qsort(manufacturer_names, *mcount, sizeof *manufacturer_names, string_compare);
for (int i = 0; i < *mcount; i++) {
sprintf(fpath, "%s/%s", path, manufacturer_names[i]);
log_info("scanning %s", fpath);
log_info("Scanning folder: %s", fpath);
res = f_opendir(&dir, fpath);
log_info("result %X", res);
//log_info("result %X", res);
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0 || *count == MAX_PROFILES) break;
if (fno.fattrib & AM_DIR && strcmp(fno.fname, PAXHEADER) != 0) {
fno.fname[MAX_PROFILE_WIDTH - 1] = 0;
sprintf(profile_names[*count], "%s/%s", manufacturer_names[i], fno.fname);
log_info("profiles: %s", profile_names[*count]);
sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname);
log_info("Found profile: %s", profile_names[*count]);
(*count)++;
} else {
if (fno.fname[0] != '.' && strlen(fno.fname) > 4 && strcmp(fno.fname, DEFAULTTXT_STRING) != 0) {
char* filetype = fno.fname + strlen(fno.fname)-4;
if (strcmp(filetype, ".txt") == 0) {
fno.fname[MAX_PROFILE_WIDTH - 1] = 0;
fno.fname[strlen(fno.fname) - 4] = 0;
sprintf(profile_names[*count], "%s/%s", manufacturer_names[i], fno.fname);
log_info("profiles: %s", profile_names[*count]);
sprintf(profile_names[*count], "%s%s/%s", prefix, manufacturer_names[i], fno.fname);
log_info("Found profile: %s", profile_names[*count]);
(*count)++;
}
}
}
}
f_closedir(&dir);
qsort(profile_names, *count, sizeof *profile_names, string_compare);
for (int i = 0; i < (*count); i++) {
sprintf(fpath, "%s/%s.txt", path, profile_names[i]);
res = f_open(&file, fpath, FA_READ);
if (res == FR_OK) {
f_close(&file);
has_sub_profiles[i] = 0;
} else {
has_sub_profiles[i] = 1;
}
}
}
}
if (*count > initial_count) {
qsort(profile_names[initial_count], (*count) - initial_count, sizeof *profile_names, string_compare);
}
for (int i = initial_count; i < (*count); i++) {
sprintf(fpath, "%s/%s.txt", path, profile_names[i]);
res = f_open(&file, fpath, FA_READ);
if (res == FR_OK) {
f_close(&file);
has_sub_profiles[i] = 0;
} else {
break;
has_sub_profiles[i] = 1;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/filesystem.h
Expand Up @@ -10,10 +10,10 @@ void capture_screenshot(capture_info_t *capinfo, char *profile);
void close_filesystem();

void scan_cpld_filenames(char cpld_filenames[MAX_CPLD_FILENAMES][MAX_FILENAME_WIDTH], char *path, int *count);
void scan_profiles(char manufacturer_names[MAX_PROFILES][MAX_PROFILE_WIDTH], char profile_names[MAX_PROFILES][MAX_PROFILE_WIDTH], int has_sub_profiles[MAX_PROFILES], char *path, size_t *mcount, size_t *count);
void scan_profiles(char prefix[MAX_PROFILE_WIDTH], char manufacturer_names[MAX_PROFILES][MAX_PROFILE_WIDTH], char profile_names[MAX_PROFILES][MAX_PROFILE_WIDTH], int has_sub_profiles[MAX_PROFILES], char *path, size_t *mcount, size_t *count);

void scan_sub_profiles(char sub_profile_names[MAX_SUB_PROFILES][MAX_PROFILE_WIDTH], char *sub_path, size_t *count);

void write_profile_choice(char *profile_name, int saved_config_number, char* cpld_name);
unsigned int file_read_profile(char *profile_name, int saved_config_number, char *sub_profile_name, int updatecmd, char *command_string, unsigned int buffer_size);
void scan_rnames(char names[MAX_NAMES][MAX_NAMES_WIDTH], char *path, char *type, int truncate, size_t *count);
int file_save_config(char *resolution_name, int refresh, int scaling, int filtering, int current_frontend, int current_hdmi_mode, char *auto_workaround_path);
Expand Down
2 changes: 1 addition & 1 deletion src/geometry.c
Expand Up @@ -861,7 +861,7 @@ void geometry_get_fb_params(capture_info_t *capinfo) {
}


if (get_startup_overscan() != 0) {
if (get_startup_overscan() != 0 && capinfo->mode7 == 0) {
int apparent_width = get_hdisplay();
int apparent_height = get_vdisplay();
double_width = (capinfo->sizex2 & SIZEX2_DOUBLE_WIDTH) >> 1;
Expand Down

0 comments on commit 0c875c0

Please sign in to comment.