From cc30fe93d5624b1cd1d1fa42c9237345cabe9e2a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 21 Dec 2019 00:46:13 +0100 Subject: [PATCH] CPC_check_AMSDOS() now returns exec address --- src/cpcformats.c | 20 +++++++++++--------- src/oldies.c | 12 ++++++++---- src/oldies.h | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/cpcformats.c b/src/cpcformats.c index d21070e3..4dab3b03 100644 --- a/src/cpcformats.c +++ b/src/cpcformats.c @@ -67,10 +67,11 @@ void Test_SCR(T_IO_Context * context, FILE * file) unsigned long pal_size, file_size; byte mode, color_anim_flag; word loading_address = 0; + word exec_address = 0; File_error = 1; - if (CPC_check_AMSDOS(file, &loading_address, &file_size)) + if (CPC_check_AMSDOS(file, &loading_address, &exec_address, &file_size)) { if (loading_address == 0x170) // iMPdraw v2 { @@ -110,7 +111,7 @@ void Test_SCR(T_IO_Context * context, FILE * file) */ - if (CPC_check_AMSDOS(pal_file, NULL, &pal_size)) + if (CPC_check_AMSDOS(pal_file, NULL, NULL, &pal_size)) fseek(pal_file, 128, SEEK_SET); // right after AMSDOS header else { @@ -170,6 +171,7 @@ void Load_SCR(T_IO_Context * context) unsigned long real_file_size, file_size, amsdos_file_size = 0; word addr; word load_address = 0x4000; // default for OCP Art studio + word exec_address = 0; word display_start = 0x4000; byte mode, color_anim_flag, color_anim_delay; byte pal_data[236]; // 12 palettes of 16+1 colors + 16 excluded inks + 16 protected inks @@ -193,7 +195,7 @@ void Load_SCR(T_IO_Context * context) if (pal_file != NULL) { file_size = File_length_file(pal_file); - if (CPC_check_AMSDOS(pal_file, NULL, &file_size)) + if (CPC_check_AMSDOS(pal_file, NULL, NULL, &file_size)) fseek(pal_file, 128, SEEK_SET); // right after AMSDOS header else fseek(pal_file, 0, SEEK_SET); @@ -214,7 +216,7 @@ void Load_SCR(T_IO_Context * context) return; file_size = File_length_file(file); real_file_size = file_size; - if (CPC_check_AMSDOS(file, &load_address, &amsdos_file_size)) + if (CPC_check_AMSDOS(file, &load_address, &exec_address, &amsdos_file_size)) { display_start = load_address; if (file_size < (amsdos_file_size + 128)) @@ -677,7 +679,7 @@ void Test_GOS(T_IO_Context * context, FILE * file) FILE *file_oddeve; unsigned long file_size = 0; - if (!CPC_check_AMSDOS(file, NULL, &file_size)) + if (!CPC_check_AMSDOS(file, NULL, NULL, &file_size)) file_size = File_length_file(file); if (file_size < 16383 || file_size > 16384) { File_error = 1; @@ -689,7 +691,7 @@ void Test_GOS(T_IO_Context * context, FILE * file) File_error = 2; return; } - if (!CPC_check_AMSDOS(file_oddeve, NULL, &file_size)) + if (!CPC_check_AMSDOS(file_oddeve, NULL, NULL, &file_size)) file_size = File_length_file(file_oddeve); fclose(file_oddeve); if (file_size < 16383 || file_size > 16384) { @@ -718,7 +720,7 @@ void Load_GOS(T_IO_Context* context) return; } - if (CPC_check_AMSDOS(file, NULL, &file_size)) + if (CPC_check_AMSDOS(file, NULL, NULL, &file_size)) fseek(file, 128, SEEK_SET); // right after AMSDOS header else file_size = File_length_file(file); @@ -752,7 +754,7 @@ void Load_GOS(T_IO_Context* context) // load pixels from GO2 file = Open_file_read_with_alternate_ext(context, "GO2"); - if (CPC_check_AMSDOS(file, NULL, &file_size)) + if (CPC_check_AMSDOS(file, NULL, NULL, &file_size)) fseek(file, 128, SEEK_SET); // right after AMSDOS header Read_bytes(file, pixel_data, file_size); @@ -790,7 +792,7 @@ void Load_GOS(T_IO_Context* context) return; } - if (CPC_check_AMSDOS(file, NULL, &file_size)) { + if (CPC_check_AMSDOS(file, NULL, NULL, &file_size)) { fseek(file, 128, SEEK_SET); // right after AMSDOS header } else { file_size = File_length_file(file); diff --git a/src/oldies.c b/src/oldies.c index 83953ede..4cd8d689 100644 --- a/src/oldies.c +++ b/src/oldies.c @@ -733,7 +733,7 @@ void CPC_set_default_BASIC_palette(T_Components * palette) sizeof(T_Components)); } -int CPC_check_AMSDOS(FILE * file, word * loading_address, unsigned long * file_length) +int CPC_check_AMSDOS(FILE * file, word * loading_address, word * exec_address, unsigned long * file_length) { int i; byte data[128]; @@ -751,7 +751,9 @@ int CPC_check_AMSDOS(FILE * file, word * loading_address, unsigned long * file_l fseek(file, 0, SEEK_SET); for (i = 1; i <= 11; i++) // check filename and extension { - if (data[i] >= 0x10 && data[i] <= 0x19) // sometimes digits are stored as 0x10 to 0x19 + // sometimes digits are stored as 0x10 to 0x19 and '#' as 0x03 + // I suppose it is bad lowercase to uppercase conversion from a tool + if ((data[i] >= 0x10 && data[i] <= 0x19) || (data[i] == 0x03) || (data[i] == 0x0B)) continue; if (data[i] < ' ' || data[i] >= 0x7F) { GFX2_Log(GFX2_DEBUG, "Not an AMSDOS file: name is invalid\n"); @@ -768,7 +770,8 @@ int CPC_check_AMSDOS(FILE * file, word * loading_address, unsigned long * file_l } for (i = 1; i <= 11; i++) // check filename and extension { - if (data[i] >= 0x10 && data[i] <= 0x19) // sometimes digits are stored as 0x10 to 0x19 + // sometimes digits are stored as 0x10 to 0x19 + if (data[i] >= 0x01 && data[i] <= 0x19) data[i] += 0x20; } GFX2_Log(GFX2_DEBUG, "AMSDOS : user=%02X %.8s.%.3s %d %u(%u) bytes, load at $%04X exec $%04X checksum $%04X\n", @@ -779,7 +782,8 @@ int CPC_check_AMSDOS(FILE * file, word * loading_address, unsigned long * file_l data[26] | (data[27] << 8), checksum); if (loading_address) *loading_address = data[21] | (data[22] << 8); - // *exec_address = data[26] | (data[27] << 8); + if (exec_address) + *exec_address = data[26] | (data[27] << 8); if (file_length) *file_length = data[64] | (data[65] << 8) | (data[66] << 16); // 24bit size // *file_length = data[24] | (data[25] << 8); // 16bit size diff --git a/src/oldies.h b/src/oldies.h index bd3dd1fb..b9cf67ec 100644 --- a/src/oldies.h +++ b/src/oldies.h @@ -138,7 +138,7 @@ int CPC_compare_colors(T_Components * col1, T_Components * col2); * @return 0 if the file does not contain a valid AMSDOS header * @return 1 if it does. */ -int CPC_check_AMSDOS(FILE * file, word * loading_address, unsigned long * file_length); +int CPC_check_AMSDOS(FILE * file, word * loading_address, word * exec_address, unsigned long * file_length); /** @}*/