2 * $Id: loader.c,v 1.8 2005-12-25 01:28:36 nkeynes Exp $
4 * File loading routines, mostly for loading demos without going through the
5 * whole procedure of making a CD image for them.
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
28 #include "bootstrap.h"
30 char bootstrap_magic[32] = "SEGA SEGAKATANA SEGA ENTERPRISES";
31 char iso_magic[6] = "\001CD001";
32 char *file_loader_extensions[][2] = {
33 { "sbi", "Self Boot Inducer" },
34 { "bin", "SH4 Bin file" },
37 #define BOOTSTRAP_LOAD_ADDR 0x8C008000
38 #define BOOTSTRAP_SIZE 32768
40 #define BINARY_LOAD_ADDR 0x8C010000
42 #define CDI_V2 0x80000004
43 #define CDI_V3 0x80000005
45 gboolean file_load_magic( const gchar *filename )
51 int fd = open( filename, O_RDONLY );
53 ERROR( "Unable to open file: '%s' (%s)", filename,
59 if( st.st_size < 32768 ) {
60 ERROR( "File '%s' too small to be a dreamcast image", filename );
66 if( read( fd, buf, 32 ) != 32 ) {
67 ERROR( "Unable to read from file '%s'", filename );
71 if( memcmp( buf, bootstrap_magic, 32 ) == 0 ) {
72 /* we have a DC bootstrap */
73 if( st.st_size == BOOTSTRAP_SIZE ) {
74 char *load = mem_get_region( BOOTSTRAP_LOAD_ADDR );
75 lseek( fd, 0, SEEK_SET );
76 read( fd, load, BOOTSTRAP_SIZE );
77 bootstrap_dump( load );
78 sh4_set_pc( BOOTSTRAP_LOAD_ADDR + 0x300 );
81 /* look for a valid ISO9660 header */
82 lseek( fd, 32768, SEEK_SET );
84 if( memcmp( buf, iso_magic, 6 ) == 0 ) {
86 INFO( "Loading ISO9660 filesystem from '%s'",
90 } else if( memcmp( buf, "PK\x03\x04", 4 ) == 0 ) {
91 /* ZIP file, aka SBI file */
92 WARN( "SBI files not supported yet" );
94 /* Assume raw binary */
95 file_load_binary( filename );
101 int file_load_binary( const gchar *filename ) {
102 mem_load_block( filename, BINARY_LOAD_ADDR, -1 );
103 sh4_set_pc( BINARY_LOAD_ADDR );
.