Search
lxdream.org :: lxdream/src/bootstrap.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/bootstrap.c
changeset 1:eea311cfd33e
next10:c898b37506e0
author nkeynes
date Sat Mar 13 00:03:32 2004 +0000 (16 years ago)
permissions -rw-r--r--
last change This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/bootstrap.c Sat Mar 13 00:03:32 2004 +0000
1.3 @@ -0,0 +1,99 @@
1.4 +#include <stdlib.h>
1.5 +#include <stdint.h>
1.6 +#include <string.h>
1.7 +#include <stdio.h>
1.8 +#include <unistd.h>
1.9 +#include <fcntl.h>
1.10 +#include <errno.h>
1.11 +#include <assert.h>
1.12 +#include <sys/stat.h>
1.13 +#include <sys/mman.h>
1.14 +#include "ipbin.h"
1.15 +#include "gui.h"
1.16 +
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.32 +
1.33 +static uint32_t compute_crc16( dc_bootstrap_head_t h )
1.34 +{
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.39 + {
1.40 + n ^= (data[i]<<8);
1.41 + for (c = 0; c < 8; c++)
1.42 + if (n & 0x8000)
1.43 + n = (n << 1) ^ 4129;
1.44 + else
1.45 + n = (n << 1);
1.46 + }
1.47 + return n & 0xffff;
1.48 +}
1.49 +
1.50 +void parse_ipbin( char *data )
1.51 +{
1.52 + struct dc_bootstrap_head *head;
1.53 + int i, got, periph, crc, hcrc;
1.54 + char *prot_symbols;
1.55 + char buf[512];
1.56 +
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.62 + buf[i] = '\0';
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.77 + got = 0;
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.82 + got = 1;
1.83 + }
1.84 + if( i == 11 ) i = 23; /* Skip 8-23 */
1.85 + }
1.86 + INFO( buf, NULL );
1.87 + strcpy( buf, " Requires: " );
1.88 + got = 0;
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.93 + got = 1;
1.94 + }
1.95 + }
1.96 + INFO( buf, NULL );
1.97 +#if 0
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] );
1.101 +#endif
1.102 +}
.