CPC_check_AMSDOS() now returns exec address

This commit is contained in:
Thomas Bernard 2019-12-21 00:46:13 +01:00
parent 2576bda4ed
commit cc30fe93d5
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 20 additions and 14 deletions

View File

@ -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);

View File

@ -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

View File

@ -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);
/** @}*/