filename | src/bootstrap.c |
changeset | 1:eea311cfd33e |
next | 10:c898b37506e0 |
author | nkeynes |
date | Sat Mar 13 00:03:32 2004 +0000 (18 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. |
view | annotate | diff | log | raw |
1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <assert.h>
9 #include <sys/stat.h>
10 #include <sys/mman.h>
11 #include "ipbin.h"
12 #include "gui.h"
14 static char *dc_peripherals[] = { "Uses WinCE", "Unknown (0x0000002)",
15 "Unknown (0x0000004)", "Unknown (0x0000008)",
16 "VGA Box", "Unknown (0x0000020)",
17 "Unknown (0x0000040)", "Unknown (0x0000080)",
18 "Other Expansions", "Puru Puru pack",
19 "Mike", "Memory card",
20 "Basic controller", "C button",
21 "D button", "X button",
22 "Y button", "Z button",
23 "Expanded direction buttons",
24 "Analog R trigger", "Analog L trigger",
25 "Analog horizontal", "Analog vertical",
26 "Expanded analog horizontal",
27 "Expanded analog vertical",
28 "Gun", "Keyboard", "Mouse" };
30 static uint32_t compute_crc16( dc_bootstrap_head_t h )
31 {
32 /* Note: Algorithm taken from http://mc.pp.se/dc/ip0000.bin.html */
33 uint32_t i, c, n = 0xffff;
34 char *data = h->product_id;
35 for (i = 0; i < 16; i++)
36 {
37 n ^= (data[i]<<8);
38 for (c = 0; c < 8; c++)
39 if (n & 0x8000)
40 n = (n << 1) ^ 4129;
41 else
42 n = (n << 1);
43 }
44 return n & 0xffff;
45 }
47 void parse_ipbin( char *data )
48 {
49 struct dc_bootstrap_head *head;
50 int i, got, periph, crc, hcrc;
51 char *prot_symbols;
52 char buf[512];
54 /* Dump out the bootstrap metadata table */
55 head = (struct dc_bootstrap_head *)data;
56 prot_symbols = ((char *)data) + 0x3700;
57 memcpy( buf, head->product_name, 128 );
58 for( i=127; i>0 && buf[i] == ' '; i-- );
59 buf[i] = '\0';
60 periph = strtol( head->peripherals, NULL, 16 );
61 INFO( "Bootstrap loaded, Name: %s Author: %-16.16s",
62 buf, head->vendor_id );
63 sprintf( buf, "%4.4s", head->crc );
64 crc = compute_crc16(head);
65 hcrc = strtol( buf, NULL, 16 );
66 emit( crc == hcrc ? EMIT_INFO : EMIT_WARN, MODULE_ID,
67 " Header CRC: %04X (Computed %04X)", hcrc, crc );
68 INFO( " Boot File: %-16.16s", head->boot_file );
69 INFO( " Product ID: %-10.10s Product Ver: %-6.6s Date: %-8.8s",
70 head->product_id, head->product_ver, head->product_date );
71 INFO( " Disc ID: %-11.11s Regions: %-8.8s Peripherals: %07X",
72 head->gdrom_id, head->regions, periph );
73 strcpy( buf, " Supports: " );
74 got = 0;
75 for( i=0; i<28; i++ ) {
76 if( periph & (1<<i) ){
77 if( got ) strcat( buf, ", " );
78 strcat( buf, dc_peripherals[i] );
79 got = 1;
80 }
81 if( i == 11 ) i = 23; /* Skip 8-23 */
82 }
83 INFO( buf, NULL );
84 strcpy( buf, " Requires: " );
85 got = 0;
86 for( i=12; i<24; i++ ) {
87 if( periph & (1<<i) ) {
88 if( got ) strcat( buf, ", " );
89 strcat( buf, dc_peripherals[i] );
90 got = 1;
91 }
92 }
93 INFO( buf, NULL );
94 #if 0
95 INFO( " Area protection symbols:", NULL );
96 for( i=0; i<8; i++ )
97 INFO( " %d: %28.28s", i, &prot_symbols[(i*32)+4] );
98 #endif
99 }
.