filenames are part of config
This commit is contained in:
parent
c1c8c44302
commit
69241a0838
6 changed files with 57 additions and 92 deletions
|
@ -15,6 +15,12 @@ Config config = {
|
||||||
.throttle = false,
|
.throttle = false,
|
||||||
.verbose = false,
|
.verbose = false,
|
||||||
.allow_shutdn = false,
|
.allow_shutdn = false,
|
||||||
|
|
||||||
|
.fn_rom = "rom",
|
||||||
|
.fn_ram = "ram",
|
||||||
|
.fn_port1 = "port1",
|
||||||
|
.fn_port2 = "port2",
|
||||||
|
.fn_state = "state",
|
||||||
};
|
};
|
||||||
|
|
||||||
void parse_args( int argc, char* argv[] )
|
void parse_args( int argc, char* argv[] )
|
||||||
|
|
|
@ -13,6 +13,12 @@ typedef struct {
|
||||||
bool throttle;
|
bool throttle;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool allow_shutdn;
|
bool allow_shutdn;
|
||||||
|
|
||||||
|
char* fn_rom;
|
||||||
|
char* fn_ram;
|
||||||
|
char* fn_port1;
|
||||||
|
char* fn_port2;
|
||||||
|
char* fn_state;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
extern Config config;
|
extern Config config;
|
||||||
|
|
|
@ -41,25 +41,23 @@ static int emulator_state = EMULATOR_RUN;
|
||||||
|
|
||||||
void emulator_set_state( int state ) { emulator_state = state; }
|
void emulator_set_state( int state ) { emulator_state = state; }
|
||||||
|
|
||||||
void emulator_init( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu )
|
void emulator_init()
|
||||||
{
|
{
|
||||||
get_absolute_working_dir_path( "hpemung" );
|
get_absolute_working_dir_path();
|
||||||
|
|
||||||
rom_init( fn_rom );
|
rom_init( config.fn_rom );
|
||||||
ram_init( fn_ram );
|
ram_init( config.fn_ram );
|
||||||
ports_init( fn_port1, fn_port2 );
|
ports_init( config.fn_port1, config.fn_port2 );
|
||||||
|
|
||||||
cpu_init( fn_cpu );
|
cpu_bus_init( config.fn_state );
|
||||||
bus_init( fn_bus );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emulator_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu )
|
void emulator_exit()
|
||||||
{
|
{
|
||||||
ports_exit( fn_port1, fn_port2 );
|
ports_exit( config.fn_port1, config.fn_port2 );
|
||||||
ram_exit( fn_ram );
|
ram_exit( config.fn_ram );
|
||||||
rom_exit();
|
rom_exit();
|
||||||
bus_exit( fn_bus );
|
cpu_bus_exit( config.fn_state );
|
||||||
cpu_exit( fn_cpu );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void throttle( bool is_needed )
|
static inline void throttle( bool is_needed )
|
||||||
|
|
|
@ -9,9 +9,9 @@ enum EmulatorStates { EMULATOR_STOP, EMULATOR_STEP, EMULATOR_RUN };
|
||||||
|
|
||||||
extern volatile bool please_exit;
|
extern volatile bool please_exit;
|
||||||
|
|
||||||
extern void emulator_init( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu );
|
extern void emulator_init();
|
||||||
extern void emulator_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu );
|
extern void emulator_exit();
|
||||||
extern bool emulator_run( void );
|
extern bool emulator_run();
|
||||||
|
|
||||||
extern void emulator_set_state( int state );
|
extern void emulator_set_state( int state );
|
||||||
|
|
||||||
|
|
|
@ -335,93 +335,50 @@ void load_file_on_stack( char* filename )
|
||||||
free( obj );
|
free( obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
void bus_init( char* filename )
|
void cpu_bus_init( char* filename )
|
||||||
{
|
{
|
||||||
bus_reset();
|
bus_reset();
|
||||||
|
|
||||||
char fullpath[ MAX_LENGTH_FILENAME ];
|
/* char fullpath[ MAX_LENGTH_FILENAME ]; */
|
||||||
get_absolute_working_dir_path();
|
/* get_absolute_working_dir_path(); */
|
||||||
sprintf( fullpath, "%s%s", absolute_working_dir_path, filename );
|
/* sprintf( fullpath, "%s%s", absolute_working_dir_path, filename ); */
|
||||||
|
|
||||||
int filesize = file_size( fullpath );
|
/* int filesize = file_size( fullpath ); */
|
||||||
|
|
||||||
if ( filesize ) {
|
/* if ( filesize ) { */
|
||||||
FILE* fp;
|
/* FILE* fp; */
|
||||||
/* BusInfo tmp_bus_info; */
|
/* /\* BusInfo tmp_bus_info; *\/ */
|
||||||
|
|
||||||
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
|
/* if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) { */
|
||||||
if ( config.verbose )
|
/* if ( config.verbose ) */
|
||||||
fprintf( stderr, "can\'t open %s\n", fullpath );
|
/* fprintf( stderr, "can\'t open %s\n", fullpath ); */
|
||||||
return;
|
/* return; */
|
||||||
}
|
/* } */
|
||||||
if ( config.verbose )
|
/* if ( config.verbose ) */
|
||||||
fprintf( stderr, "Loading bus_info from %s\n", fullpath );
|
/* fprintf( stderr, "Loading bus_info from %s\n", fullpath ); */
|
||||||
|
|
||||||
fread( &bus_info, sizeof( BusInfo ), 1, fp );
|
/* fread( &bus_info, sizeof( BusInfo ), 1, fp ); */
|
||||||
|
|
||||||
fclose( fp );
|
/* fclose( fp ); */
|
||||||
}
|
/* } */
|
||||||
}
|
}
|
||||||
void bus_exit( char* filename )
|
void cpu_bus_exit( char* filename )
|
||||||
{
|
{
|
||||||
char fullpath[ MAX_LENGTH_FILENAME ];
|
/* char fullpath[ MAX_LENGTH_FILENAME ]; */
|
||||||
get_absolute_working_dir_path();
|
/* get_absolute_working_dir_path(); */
|
||||||
sprintf( fullpath, "%s%s", absolute_working_dir_path, filename );
|
/* sprintf( fullpath, "%s%s", absolute_working_dir_path, filename ); */
|
||||||
|
|
||||||
FILE* fp;
|
/* FILE* fp; */
|
||||||
|
|
||||||
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
|
/* if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) { */
|
||||||
if ( config.verbose )
|
/* if ( config.verbose ) */
|
||||||
fprintf( stderr, "can\'t open %s\n", fullpath );
|
/* fprintf( stderr, "can\'t open %s\n", fullpath ); */
|
||||||
return;
|
/* return; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
fwrite( &bus_info, sizeof( BusInfo ), 1, fp );
|
/* fwrite( &bus_info, sizeof( BusInfo ), 1, fp ); */
|
||||||
|
|
||||||
fclose( fp );
|
/* fclose( fp ); */
|
||||||
}
|
|
||||||
|
|
||||||
void cpu_init( char* filename )
|
|
||||||
{
|
|
||||||
char fullpath[ MAX_LENGTH_FILENAME ];
|
|
||||||
get_absolute_working_dir_path();
|
|
||||||
sprintf( fullpath, "%s%s", absolute_working_dir_path, filename );
|
|
||||||
|
|
||||||
int filesize = file_size( fullpath );
|
|
||||||
|
|
||||||
if ( filesize ) {
|
|
||||||
FILE* fp;
|
|
||||||
|
|
||||||
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
|
|
||||||
if ( config.verbose )
|
|
||||||
fprintf( stderr, "can\'t open %s\n", fullpath );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ( config.verbose )
|
|
||||||
fprintf( stderr, "Loading cpu from %s\n", fullpath );
|
|
||||||
|
|
||||||
fread( &cpu, sizeof( Cpu ), 1, fp );
|
|
||||||
|
|
||||||
fclose( fp );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void cpu_exit( char* filename )
|
|
||||||
{
|
|
||||||
char fullpath[ MAX_LENGTH_FILENAME ];
|
|
||||||
get_absolute_working_dir_path();
|
|
||||||
sprintf( fullpath, "%s%s", absolute_working_dir_path, filename );
|
|
||||||
|
|
||||||
FILE* fp;
|
|
||||||
|
|
||||||
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
|
|
||||||
if ( config.verbose )
|
|
||||||
fprintf( stderr, "can\'t open %s\n", fullpath );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fwrite( &cpu, sizeof( Cpu ), 1, fp );
|
|
||||||
|
|
||||||
fclose( fp );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rom_init( char* filename )
|
void rom_init( char* filename )
|
||||||
|
|
|
@ -9,13 +9,11 @@ extern void load_file_on_stack( char* filename );
|
||||||
extern void rom_init( char* filename );
|
extern void rom_init( char* filename );
|
||||||
extern void ram_init( char* filename );
|
extern void ram_init( char* filename );
|
||||||
extern void ports_init( char* filename1, char* filename2 );
|
extern void ports_init( char* filename1, char* filename2 );
|
||||||
extern void cpu_init( char* filename );
|
extern void cpu_bus_init( char* filename );
|
||||||
extern void bus_init( char* filename );
|
|
||||||
|
|
||||||
extern void rom_exit();
|
extern void rom_exit();
|
||||||
extern void ram_exit( char* filename );
|
extern void ram_exit( char* filename );
|
||||||
extern void ports_exit( char* filename1, char* filename2 );
|
extern void ports_exit( char* filename1, char* filename2 );
|
||||||
extern void cpu_exit( char* filename );
|
extern void cpu_bus_exit( char* filename );
|
||||||
extern void bus_exit( char* filename );
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue