Search
lxdream.org :: lxdream/src/bootstrap.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/bootstrap.c
changeset 35:21a4be098304
prev26:ad258e3daaa5
next167:71c0cc416a64
author nkeynes
date Mon Dec 26 03:54:55 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Remove modules.h - move definitions into dream.h
Add source string to output list (taken from module name)
ARM Work in progress
view annotate diff log raw
     1 /**
     2  * $Id: bootstrap.c,v 1.5 2005-12-26 03:54:52 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  */
   107 void bootstrap_dump( char *data )
   108 {
   109     struct dc_bootstrap_head *head;
   110     int i, got, periph, crc, hcrc;
   111     char *prot_symbols;
   112     char buf[512];
   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-- );
   119     buf[i] = '\0';
   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: " );
   134     got = 0;
   135     for( i=0; i<28; i++ ) {
   136         if( periph & (1<<i) ){
   137             if( got ) strcat( buf, ", " );
   138             strcat( buf, dc_peripherals[i] );
   139             got = 1;
   140         }
   141         if( i == 11 ) i = 23; /* Skip 8-23 */
   142     }
   143     INFO( buf, NULL );
   144     strcpy( buf, "     Requires: " );
   145     got = 0;
   146     for( i=12; i<24; i++ ) {
   147         if( periph & (1<<i) ) {
   148             if( got ) strcat( buf, ", " );
   149             strcat( buf, dc_peripherals[i] );
   150             got = 1;
   151         }
   152     }
   153     INFO( buf, NULL );
   154 #if 0
   155     INFO( "  Area protection symbols:", NULL );
   156     for( i=0; i<8; i++ )
   157         INFO( "    %d: %28.28s", i, &prot_symbols[(i*32)+4] );
   158 #endif
   159 }
.