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