1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/bootstrap.c Sat Aug 21 06:15:49 2004 +0000
1.11 +#include <assert.h>
1.12 +#include <sys/stat.h>
1.13 +#include <sys/mman.h>
1.17 +static char *dc_peripherals[] = { "Uses WinCE", "Unknown (0x0000002)",
1.18 + "Unknown (0x0000004)", "Unknown (0x0000008)",
1.19 + "VGA Box", "Unknown (0x0000020)",
1.20 + "Unknown (0x0000040)", "Unknown (0x0000080)",
1.21 + "Other Expansions", "Puru Puru pack",
1.22 + "Mike", "Memory card",
1.23 + "Basic controller", "C button",
1.24 + "D button", "X button",
1.25 + "Y button", "Z button",
1.26 + "Expanded direction buttons",
1.27 + "Analog R trigger", "Analog L trigger",
1.28 + "Analog horizontal", "Analog vertical",
1.29 + "Expanded analog horizontal",
1.30 + "Expanded analog vertical",
1.31 + "Gun", "Keyboard", "Mouse" };
1.33 +static uint32_t compute_crc16( dc_bootstrap_head_t h )
1.35 + /* Note: Algorithm taken from http://mc.pp.se/dc/ip0000.bin.html */
1.36 + uint32_t i, c, n = 0xffff;
1.37 + char *data = h->product_id;
1.38 + for (i = 0; i < 16; i++)
1.40 + n ^= (data[i]<<8);
1.41 + for (c = 0; c < 8; c++)
1.43 + n = (n << 1) ^ 4129;
1.47 + return n & 0xffff;
1.50 +void parse_ipbin( char *data )
1.52 + struct dc_bootstrap_head *head;
1.53 + int i, got, periph, crc, hcrc;
1.54 + char *prot_symbols;
1.57 + /* Dump out the bootstrap metadata table */
1.58 + head = (struct dc_bootstrap_head *)data;
1.59 + prot_symbols = ((char *)data) + 0x3700;
1.60 + memcpy( buf, head->product_name, 128 );
1.61 + for( i=127; i>0 && buf[i] == ' '; i-- );
1.63 + periph = strtol( head->peripherals, NULL, 16 );
1.64 + INFO( "Bootstrap loaded, Name: %s Author: %-16.16s",
1.65 + buf, head->vendor_id );
1.66 + sprintf( buf, "%4.4s", head->crc );
1.67 + crc = compute_crc16(head);
1.68 + hcrc = strtol( buf, NULL, 16 );
1.69 + emit( crc == hcrc ? EMIT_INFO : EMIT_WARN, MODULE_ID,
1.70 + " Header CRC: %04X (Computed %04X)", hcrc, crc );
1.71 + INFO( " Boot File: %-16.16s", head->boot_file );
1.72 + INFO( " Product ID: %-10.10s Product Ver: %-6.6s Date: %-8.8s",
1.73 + head->product_id, head->product_ver, head->product_date );
1.74 + INFO( " Disc ID: %-11.11s Regions: %-8.8s Peripherals: %07X",
1.75 + head->gdrom_id, head->regions, periph );
1.76 + strcpy( buf, " Supports: " );
1.78 + for( i=0; i<28; i++ ) {
1.79 + if( periph & (1<<i) ){
1.80 + if( got ) strcat( buf, ", " );
1.81 + strcat( buf, dc_peripherals[i] );
1.84 + if( i == 11 ) i = 23; /* Skip 8-23 */
1.86 + INFO( buf, NULL );
1.87 + strcpy( buf, " Requires: " );
1.89 + for( i=12; i<24; i++ ) {
1.90 + if( periph & (1<<i) ) {
1.91 + if( got ) strcat( buf, ", " );
1.92 + strcat( buf, dc_peripherals[i] );
1.96 + INFO( buf, NULL );
1.98 + INFO( " Area protection symbols:", NULL );
1.99 + for( i=0; i<8; i++ )
1.100 + INFO( " %d: %28.28s", i, &prot_symbols[(i*32)+4] );