WIP : WOZ loader.

This commit is contained in:
Jean-François DEL NERO
2023-12-24 16:51:16 +01:00
parent 028cc4c535
commit 38b169fcb4
2 changed files with 139 additions and 5 deletions
@@ -26,13 +26,56 @@
*/
#pragma pack(1)
// Chunk definitions
// v1
#define CHUNK_INFO 0x4F464E49
#define CHUNK_TMAP 0x50414D54
#define CHUNK_TRKS 0x534B5254
#define CHUNK_META 0x4154454D
// v2
#define CHUNK_WRIT 0x54495257
typedef struct woz_fileheader_
{
uint8_t headertag[3]; // "WOZ"
uint8_t version; // '1' or '2'
uint8_t pad; // 0xFF
uint8_t lfcrlf[3]; // 0x0A 0x0D 0x0A
uint32_t crc32; // crc32 of the remaining file content
uint8_t headertag[3]; // "WOZ"
uint8_t version; // '1' or '2'
uint8_t pad; // 0xFF
uint8_t lfcrlf[3]; // 0x0A 0x0D 0x0A
uint32_t crc32; // CRC32 of the remaining file content
}woz_fileheader;
typedef struct woz_chunk_
{
uint32_t id; // ID
uint32_t size; // Chunk data size
uint8_t data[]; // Data
}woz_chunk;
typedef struct woz_info_
{
// Rev 1,2 & 3
uint8_t version; // 1,2 or 3
uint8_t disk_type; // 1 = 5.25, 2 = 3.5
uint8_t write_protected;
uint8_t sync;
uint8_t cleaned;
uint8_t creator[32];
// Rev 2 & 3
uint8_t sides_count;
uint8_t boot_sector_format; // (1 = Contains boot sector for 16-sector, 2 = Contains boot sector for 13-sector, 3 = Contains boot sectors for both)
uint8_t bit_timing; // 125 increments. example : 8= 125*8 = 1uS
uint16_t compatible_hw; // 0x0001 = Apple ][, 0x0002 = Apple ][ Plus, 0x0004 = Apple //e (unenhanced), 0x0008 = Apple //c, 0x0010 = Apple //e Enhanced
// 0x0020 = Apple IIgs, 0x0040 = Apple //c Plus, 0x0080 = Apple ///, 0x0100 = Apple /// Plus
uint16_t required_ram; // In kB
uint16_t largest_track; // in 512 blocks number.
// Rev 3
uint16_t flux_block;
uint16_t largest_flux_track;
}woz_info;
#pragma pack()
@@ -106,13 +106,38 @@ int WOZ_libIsValidDiskFile( HXCFE_IMGLDR * imgldr_ctx, HXCFE_IMGLDR_FILEINFOS *
}
}
static int get_woz_chunk(unsigned char * buf, int buf_size, int offset, uint32_t chunk_id)
{
woz_chunk * chunk;
if( offset < sizeof(woz_fileheader))
offset = sizeof(woz_fileheader);
while( offset < buf_size)
{
chunk = (woz_chunk *) &buf[offset];
if (chunk->id == chunk_id)
{
return offset;
}
offset += (8 + chunk->size);
}
return -1;
}
int WOZ_libLoad_DiskFile(HXCFE_IMGLDR * imgldr_ctx,HXCFE_FLOPPY * floppydisk,char * imgfile,void * parameters)
{
FILE * f;
woz_fileheader fileheader;
woz_chunk * chunk;
int offset;
int filesize;
unsigned char * file_buffer;
uint32_t crc32;
char * tmp_str;
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"WOZ_libLoad_DiskFile %s",imgfile);
@@ -179,6 +204,72 @@ int WOZ_libLoad_DiskFile(HXCFE_IMGLDR * imgldr_ctx,HXCFE_FLOPPY * floppydisk,cha
return HXCFE_BADFILE;
}
// Get and print the metadatas if available...
offset = get_woz_chunk(file_buffer, filesize, 0, CHUNK_META);
if( offset > 0 )
{
chunk = (woz_chunk *)&file_buffer[offset];
if(chunk->size > 0 && chunk->size < 1*1024*1024 )
{
tmp_str = calloc( 1, chunk->size + 1);
if( tmp_str )
{
memcpy( tmp_str, chunk->data, chunk->size );
imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"%s",tmp_str);
free(tmp_str);
}
}
}
// Get the Info chunk
offset = get_woz_chunk(file_buffer, filesize, 0, CHUNK_INFO);
if( offset < 0 )
{
imgldr_ctx->hxcfe->hxc_printf(MSG_ERROR,"No INFO Chunk ?!");
free(file_buffer);
hxc_fclose(f);
return HXCFE_BADFILE;
}
/*
offset = sizeof(woz_fileheader);
while( offset < filesize)
{
switch(chunk->id)
{
case CHUNK_INFO:
printf("info chunk id :0x%.8X\n",chunk->id);
break;
case CHUNK_TMAP:
printf("tmap chunk id :0x%.8X\n",chunk->id);
break;
case CHUNK_TRKS:
printf("trks chunk id :0x%.8X\n",chunk->id);
break;
case CHUNK_META:
if(chunk->size > 0 && chunk->size < 1*1024*1024 )
{
tmp_str = calloc( 1, chunk->size + 1);
if( tmp_str )
{
memcpy( tmp_str, chunk->data, chunk->size );
imgldr_ctx->hxcfe->hxc_printf(MSG_INFO_1,"%s",tmp_str);
free(tmp_str);
}
}
break;
default:
imgldr_ctx->hxcfe->hxc_printf(MSG_DEBUG,"Unknown chunk id ! : 0x%.8X (size : %d)",chunk->id,chunk->size);
break;
}
offset += (8 + chunk->size);
}*/
free(file_buffer);
return HXCFE_INTERNALERROR;