2 * $Id: bootstrap.c,v 1.7 2007-10-06 08:59:42 nkeynes Exp $
4 * CD Bootstrap header parsing. Mostly for informational purposes.
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include "bootstrap.h"
23 * Bootstrap header structure
25 typedef struct dc_bootstrap_head {
26 char hardware_id[16]; /* must be "SEGA SEGAKATANA " */
27 char maker_id[16]; /* ditto, "SEGA ENTERPRISES" */
29 char padding; /* normally ascii space */
36 char product_date[16];
39 char product_name[128];
40 } *dc_bootstrap_head_t;
42 static uint32_t compute_crc16( dc_bootstrap_head_t h )
44 /* Note: Algorithm taken from http://mc.pp.se/dc/ip0000.bin.html */
45 uint32_t i, c, n = 0xffff;
46 char *data = h->product_id;
47 for (i = 0; i < 16; i++)
50 for (c = 0; c < 8; c++)
60 static char *dc_peripherals[] = { "Uses WinCE", "Unknown (0x0000002)",
61 "Unknown (0x0000004)", "Unknown (0x0000008)",
62 "VGA Box", "Unknown (0x0000020)",
63 "Unknown (0x0000040)", "Unknown (0x0000080)",
64 "Other Expansions", "Puru Puru pack",
65 "Mike", "Memory card",
66 "Basic controller", "C button",
67 "D button", "X button",
68 "Y button", "Z button",
69 "Expanded direction buttons",
70 "Analog R trigger", "Analog L trigger",
71 "Analog horizontal", "Analog vertical",
72 "Expanded analog horizontal",
73 "Expanded analog vertical",
74 "Gun", "Keyboard", "Mouse" };
78 #define DC_PERIPH_WINCE 0x0000001
79 #define DC_PERIPH_VGABOX 0x0000010
80 #define DC_PERIPH_OTHER 0x0000100
81 #define DC_PERIPH_PURUPURU 0x0000200
82 #define DC_PERIPH_MIKE 0x0000400
83 #define DC_PERIPH_MEMCARD 0x0000800
84 /* Basic requirements */
85 #define DC_PERIPH_BASIC 0x0001000 /* Basic controls - start, a, b, arrows */
86 #define DC_PERIPH_C_BUTTON 0x0002000
87 #define DC_PERIPH_D_BUTTON 0x0004000
88 #define DC_PERIPH_X_BUTTON 0x0008000
89 #define DC_PERIPH_Y_BUTTON 0x0010000
90 #define DC_PERIPH_Z_BUTTON 0x0020000
91 #define DC_PERIPH_EXP_DIR 0x0040000 /* Expanded direction buttons */
92 #define DC_PERIPH_ANALOG_R 0x0080000 /* Analog R trigger */
93 #define DC_PERIPH_ANALOG_L 0x0100000 /* Analog L trigger */
94 #define DC_PERIPH_ANALOG_H 0x0200000 /* Analog horizontal controller */
95 #define DC_PERIPH_ANALOG_V 0x0400000 /* Analog vertical controller */
96 #define DC_PERIPH_EXP_AH 0x0800000 /* Expanded analog horizontal (?) */
97 #define DC_PERIPH_EXP_AV 0x1000000 /* Expanded analog vertical (?) */
98 /* Optional peripherals */
99 #define DC_PERIPH_GUN 0x2000000
100 #define DC_PERIPH_KEYBOARD 0x4000000
101 #define DC_PERIPH_MOUSE 0x8000000
104 * Dump the bootstrap info to the output log for infomational/debugging
106 * @param detail true to include a ful information dump, false for just
109 void bootstrap_dump( unsigned char *data, gboolean detail )
111 struct dc_bootstrap_head *head;
112 int i, got, periph, crc, hcrc;
116 /* Dump out the bootstrap metadata table */
117 head = (struct dc_bootstrap_head *)data;
118 prot_symbols = ((char *)data) + 0x3700;
119 memcpy( buf, head->product_name, 128 );
120 for( i=127; i>0 && buf[i] == ' '; i-- );
122 periph = strtol( head->peripherals, NULL, 16 );
123 INFO( "Name: %s Author: %-16.16s",
124 buf, head->vendor_id );
125 sprintf( buf, "%4.4s", head->crc );
126 crc = compute_crc16(head);
127 hcrc = strtol( buf, NULL, 16 );
128 INFO( " Product ID: %-10.10s Product Ver: %-6.6s Date: %-8.8s",
129 head->product_id, head->product_ver, head->product_date );
131 emit( NULL, crc == hcrc ? EMIT_INFO : EMIT_WARN, "File",
132 " Header CRC: %04X (Computed %04X)", hcrc, crc );
133 INFO( " Boot File: %-16.16s", head->boot_file );
134 INFO( " Disc ID: %-11.11s Regions: %-8.8s Peripherals: %07X",
135 head->gdrom_id, head->regions, periph );
136 strcpy( buf, " Supports: " );
138 for( i=0; i<28; i++ ) {
139 if( periph & (1<<i) ){
140 if( got ) strcat( buf, ", " );
141 strcat( buf, dc_peripherals[i] );
144 if( i == 11 ) i = 23; /* Skip 8-23 */
147 strcpy( buf, " Requires: " );
149 for( i=12; i<24; i++ ) {
150 if( periph & (1<<i) ) {
151 if( got ) strcat( buf, ", " );
152 strcat( buf, dc_peripherals[i] );
.