1.1 --- a/src/loader.c Sat Dec 24 03:33:08 2005 +0000
1.2 +++ b/src/loader.c Sat Dec 24 08:02:18 2005 +0000
1.6 + * $Id: loader.c,v 1.7 2005-12-24 08:02:14 nkeynes Exp $
1.8 + * File loading routines, mostly for loading demos without going through the
1.9 + * whole procedure of making a CD image for them.
1.11 + * Copyright (c) 2005 Nathan Keynes.
1.13 + * This program is free software; you can redistribute it and/or modify
1.14 + * it under the terms of the GNU General Public License as published by
1.15 + * the Free Software Foundation; either version 2 of the License, or
1.16 + * (at your option) any later version.
1.18 + * This program is distributed in the hope that it will be useful,
1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 + * GNU General Public License for more details.
1.26 #include <sys/stat.h>
1.27 -#include <sys/mman.h>
1.30 #include "gui/gui.h"
1.33 #include "sh4core.h"
1.36 +#include "bootstrap.h"
1.38 -char ip_bin_magic[32] = "SEGA SEGAKATANA SEGA ENTERPRISES";
1.39 +char bootstrap_magic[32] = "SEGA SEGAKATANA SEGA ENTERPRISES";
1.40 char iso_magic[6] = "\001CD001";
1.41 +char *file_loader_extensions[][2] = {
1.42 + { "sbi", "Self Boot Inducer" },
1.43 + { "bin", "SH4 Bin file" },
1.46 +#define BOOTSTRAP_LOAD_ADDR 0x8C008000
1.47 +#define BOOTSTRAP_SIZE 32768
1.49 +#define BINARY_LOAD_ADDR 0x8C010000
1.51 #define CDI_V2 0x80000004
1.52 #define CDI_V3 0x80000005
1.54 -int open_file( const gchar *filename )
1.55 +gboolean file_load_magic( const gchar *filename )
1.61 ERROR( "Unable to open file: '%s' (%s)", filename,
1.68 if( st.st_size < 32768 ) {
1.69 ERROR( "File '%s' too small to be a dreamcast image", filename );
1.76 if( read( fd, buf, 32 ) != 32 ) {
1.77 ERROR( "Unable to read from file '%s'", filename );
1.82 - if( memcmp( buf, ip_bin_magic, 32 ) == 0 ) {
1.83 + if( memcmp( buf, bootstrap_magic, 32 ) == 0 ) {
1.84 /* we have a DC bootstrap */
1.85 if( st.st_size == BOOTSTRAP_SIZE ) {
1.86 char *load = mem_get_region( BOOTSTRAP_LOAD_ADDR );
1.87 - /* Just the bootstrap, no image... */
1.88 - WARN( "File '%s' contains bootstrap only, loading anyway",
1.90 lseek( fd, 0, SEEK_SET );
1.91 read( fd, load, BOOTSTRAP_SIZE );
1.92 - parse_ipbin( load );
1.94 + bootstrap_dump( load );
1.95 sh4_set_pc( BOOTSTRAP_LOAD_ADDR + 0x300 );
1.96 set_disassembly_region( main_debug, BOOTSTRAP_LOAD_ADDR );
1.97 set_disassembly_pc( main_debug, sh4r.pc, TRUE );
1.102 + } else if( memcmp( buf, "PK\x03\x04", 4 ) == 0 ) {
1.103 + /* ZIP file, aka SBI file */
1.104 + WARN( "SBI files not supported yet" );
1.106 - /* check if it's a CDI file: */
1.107 - lseek( fd, -8, SEEK_END );
1.108 - read( fd, &tmpa, 8 );
1.109 - if( tmpa[0] == CDI_V2 || tmpa[0] == CDI_V3 ) {
1.111 - INFO( "Loading CDI file '%s'", filename );
1.113 - ERROR( "Don't know what to do with '%s'", filename );
1.116 + /* Assume raw binary */
1.117 + file_load_binary( filename );
1.124 -int load_bin_file( const gchar *filename ) {
1.125 - mem_load_block( filename, 0x8c010000, -1 );
1.126 - sh4_set_pc( 0x8c010000 );
1.127 - set_disassembly_region( main_debug, 0x8c010000 );
1.128 +int file_load_binary( const gchar *filename ) {
1.129 + mem_load_block( filename, BINARY_LOAD_ADDR, -1 );
1.130 + sh4_set_pc( BINARY_LOAD_ADDR );
1.131 + set_disassembly_region( main_debug, BINARY_LOAD_ADDR );
1.132 set_disassembly_pc( main_debug, sh4r.pc, TRUE );
1.133 - pvr2_set_base_address( 0x00025940 );