Search
lxdream.org :: lxdream/src/loader.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/loader.c
changeset 26:ad258e3daaa5
prev25:fa2d21d57942
next27:1ef09a52cd1e
author nkeynes
date Sat Dec 24 08:02:18 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change More structure reorgs/fixes
file annotate diff log raw
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.3 @@ -1,26 +1,48 @@
1.4 -/*
1.5 +/**
1.6 + * $Id: loader.c,v 1.7 2005-12-24 08:02:14 nkeynes Exp $
1.7 *
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.10 + *
1.11 + * Copyright (c) 2005 Nathan Keynes.
1.12 + *
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.17 + *
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.22 */
1.23
1.24 #include <stdio.h>
1.25 #include <fcntl.h>
1.26 #include <sys/stat.h>
1.27 -#include <sys/mman.h>
1.28 #include <errno.h>
1.29 #include <stdint.h>
1.30 #include "gui/gui.h"
1.31 -#include "ipbin.h"
1.32 +#include "mem.h"
1.33 #include "sh4core.h"
1.34 -#include "pvr2.h"
1.35 -#include "mem.h"
1.36 +#include "bootstrap.h"
1.37
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.44 + { NULL, NULL } };
1.45 +
1.46 +#define BOOTSTRAP_LOAD_ADDR 0x8C008000
1.47 +#define BOOTSTRAP_SIZE 32768
1.48 +
1.49 +#define BINARY_LOAD_ADDR 0x8C010000
1.50
1.51 #define CDI_V2 0x80000004
1.52 #define CDI_V3 0x80000005
1.53
1.54 -int open_file( const gchar *filename )
1.55 +gboolean file_load_magic( const gchar *filename )
1.56 {
1.57 char buf[32];
1.58 uint32_t tmpa[2];
1.59 @@ -30,33 +52,29 @@
1.60 if( fd == -1 ) {
1.61 ERROR( "Unable to open file: '%s' (%s)", filename,
1.62 strerror(errno) );
1.63 - return;
1.64 + return FALSE;
1.65 }
1.66
1.67 fstat( fd, &st );
1.68 if( st.st_size < 32768 ) {
1.69 ERROR( "File '%s' too small to be a dreamcast image", filename );
1.70 close(fd);
1.71 - return;
1.72 + return FALSE;
1.73 }
1.74
1.75 /* begin magic */
1.76 if( read( fd, buf, 32 ) != 32 ) {
1.77 ERROR( "Unable to read from file '%s'", filename );
1.78 close(fd);
1.79 - return;
1.80 + return FALSE;
1.81 }
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.89 - filename );
1.90 lseek( fd, 0, SEEK_SET );
1.91 read( fd, load, BOOTSTRAP_SIZE );
1.92 - parse_ipbin( load );
1.93 - sh4_reset();
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.98 @@ -71,26 +89,21 @@
1.99 filename );
1.100 }
1.101 }
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.105 } else {
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.110 - /* Yup, it is */
1.111 - INFO( "Loading CDI file '%s'", filename );
1.112 - } else {
1.113 - ERROR( "Don't know what to do with '%s'", filename );
1.114 - }
1.115 - }
1.116 + /* Assume raw binary */
1.117 + file_load_binary( filename );
1.118 + }
1.119 close(fd);
1.120 - return 0;
1.121 + return TRUE;
1.122 }
1.123
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 );
1.134 update_gui();
1.135 }
.