2 * $Id: bootstrap.c,v 1.5 2005-12-26 03:54:52 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
107 void bootstrap_dump( char *data )
109 struct dc_bootstrap_head *head;
110 int i, got, periph, crc, hcrc;
114 /* Dump out the bootstrap metadata table */
115 head = (struct dc_bootstrap_head *)data;
116 prot_symbols = ((char *)data) + 0x3700;
117 memcpy( buf, head->product_name, 128 );
118 for( i=127; i>0 && buf[i] == ' '; i-- );
120 periph = strtol( head->peripherals, NULL, 16 );
121 INFO( "Bootstrap Name: %s Author: %-16.16s",
122 buf, head->vendor_id );
123 sprintf( buf, "%4.4s", head->crc );
124 crc = compute_crc16(head);
125 hcrc = strtol( buf, NULL, 16 );
126 emit( NULL, crc == hcrc ? EMIT_INFO : EMIT_WARN, "File",
127 " Header CRC: %04X (Computed %04X)", hcrc, crc );
128 INFO( " Boot File: %-16.16s", head->boot_file );
129 INFO( " Product ID: %-10.10s Product Ver: %-6.6s Date: %-8.8s",
130 head->product_id, head->product_ver, head->product_date );
131 INFO( " Disc ID: %-11.11s Regions: %-8.8s Peripherals: %07X",
132 head->gdrom_id, head->regions, periph );
133 strcpy( buf, " Supports: " );
135 for( i=0; i<28; i++ ) {
136 if( periph & (1<<i) ){
137 if( got ) strcat( buf, ", " );
138 strcat( buf, dc_peripherals[i] );
141 if( i == 11 ) i = 23; /* Skip 8-23 */
144 strcpy( buf, " Requires: " );
146 for( i=12; i<24; i++ ) {
147 if( periph & (1<<i) ) {
148 if( got ) strcat( buf, ", " );
149 strcat( buf, dc_peripherals[i] );
155 INFO( " Area protection symbols:", NULL );
157 INFO( " %d: %28.28s", i, &prot_symbols[(i*32)+4] );
.