Search
lxdream.org :: lxdream/src/bootstrap.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/bootstrap.c
changeset 502:c4ecae2b1b5e
prev437:2c259474b474
next561:533f6b478071
author nkeynes
date Thu Nov 08 11:54:16 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add sh4ptr_t type, start converting bare pointer refs to it
view annotate diff log raw
     1 /**
     2  * $Id: bootstrap.c,v 1.9 2007-11-08 11:54:16 nkeynes Exp $
     3  *
     4  * CD Bootstrap header parsing. Mostly for informational purposes.
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    19 #include "dream.h"
    20 #include "bootstrap.h"
    22 /**
    23  * Bootstrap header structure
    24  */
    25 typedef struct dc_bootstrap_head {
    26     char hardware_id[16]; /* must be "SEGA SEGAKATANA " */ 
    27     char maker_id[16];    /* ditto,  "SEGA ENTERPRISES" */
    28     char crc[4];
    29     char padding;         /* normally ascii space */
    30     char gdrom_id[6];
    31     char disc_no[5];
    32     char regions[8];
    33     char peripherals[8];
    34     char product_id[10];
    35     char product_ver[6];
    36     char product_date[16];
    37     char boot_file[16];
    38     char vendor_id[16];
    39     char product_name[128];
    40 } *dc_bootstrap_head_t;
    42 static uint32_t compute_crc16( dc_bootstrap_head_t h )
    43 {
    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++)
    48     {
    49         n ^= (data[i]<<8);
    50         for (c = 0; c < 8; c++)
    51             if (n & 0x8000)
    52                 n = (n << 1) ^ 4129;
    53             else
    54                 n = (n << 1);
    55     }
    56     return n & 0xffff;
    57 }
    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" };
    77 /* Expansion units */
    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
   103 /**
   104  * Dump the bootstrap info to the output log for infomational/debugging
   105  * purposes.
   106  * @param detail true to include a ful information dump, false for just
   107  *  the facts, maam.
   108  */
   109 void bootstrap_dump( void *data, gboolean detail )
   110 {
   111     struct dc_bootstrap_head *head;
   112     int i, got, periph, crc, hcrc;
   113     char *prot_symbols;
   114     char buf[512];
   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-- );
   121     buf[i] = '\0';
   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 );
   130     if( detail ) {
   131 	INFO( "  Header CRC:   %04X (Computed %04X)", hcrc, crc );
   132 	INFO( "  Boot File:    %-16.16s", head->boot_file );
   133 	INFO( "  Disc ID:      %-11.11s  Regions:      %-8.8s   Peripherals: %07X",
   134 	      head->gdrom_id, head->regions, periph );
   135 	strcpy( buf, "     Supports: " );
   136 	got = 0;
   137 	for( i=0; i<28; i++ ) {
   138 	    if( periph & (1<<i) ){
   139 		if( got ) strcat( buf, ", " );
   140 		strcat( buf, dc_peripherals[i] );
   141 		got = 1;
   142 	    }
   143 	    if( i == 11 ) i = 23; /* Skip 8-23 */
   144 	}
   145 	INFO( buf, NULL );
   146 	strcpy( buf, "     Requires: " );
   147 	got = 0;
   148 	for( i=12; i<24; i++ ) {
   149 	    if( periph & (1<<i) ) {
   150 		if( got ) strcat( buf, ", " );
   151 		strcat( buf, dc_peripherals[i] );
   152 		got = 1;
   153 	    }
   154 	}
   155 	INFO( buf, NULL );
   156     }
   157 }
.