filenames are part of config

This commit is contained in:
Gwenhael Le Moine 2024-04-18 15:38:56 +02:00
parent c1c8c44302
commit 69241a0838
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 57 additions and 92 deletions

View file

@ -15,6 +15,12 @@ Config config = {
.throttle = false,
.verbose = 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[] )

View file

@ -13,6 +13,12 @@ typedef struct {
bool throttle;
bool verbose;
bool allow_shutdn;
char* fn_rom;
char* fn_ram;
char* fn_port1;
char* fn_port2;
char* fn_state;
} Config;
extern Config config;

View file

@ -41,25 +41,23 @@ static int emulator_state = EMULATOR_RUN;
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 );
ram_init( fn_ram );
ports_init( fn_port1, fn_port2 );
rom_init( config.fn_rom );
ram_init( config.fn_ram );
ports_init( config.fn_port1, config.fn_port2 );
cpu_init( fn_cpu );
bus_init( fn_bus );
cpu_bus_init( config.fn_state );
}
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 );
ram_exit( fn_ram );
ports_exit( config.fn_port1, config.fn_port2 );
ram_exit( config.fn_ram );
rom_exit();
bus_exit( fn_bus );
cpu_exit( fn_cpu );
cpu_bus_exit( config.fn_state );
}
static inline void throttle( bool is_needed )

View file

@ -9,9 +9,9 @@ enum EmulatorStates { EMULATOR_STOP, EMULATOR_STEP, EMULATOR_RUN };
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_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu );
extern bool emulator_run( void );
extern void emulator_init();
extern void emulator_exit();
extern bool emulator_run();
extern void emulator_set_state( int state );

View file

@ -335,93 +335,50 @@ void load_file_on_stack( char* filename )
free( obj );
}
void bus_init( char* filename )
void cpu_bus_init( char* filename )
{
bus_reset();
char fullpath[ MAX_LENGTH_FILENAME ];
get_absolute_working_dir_path();
sprintf( fullpath, "%s%s", absolute_working_dir_path, 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 );
/* int filesize = file_size( fullpath ); */
if ( filesize ) {
FILE* fp;
/* BusInfo tmp_bus_info; */
/* if ( filesize ) { */
/* FILE* fp; */
/* /\* BusInfo tmp_bus_info; *\/ */
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
if ( config.verbose )
fprintf( stderr, "can\'t open %s\n", fullpath );
return;
}
if ( config.verbose )
fprintf( stderr, "Loading bus_info from %s\n", fullpath );
/* if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) { */
/* if ( config.verbose ) */
/* fprintf( stderr, "can\'t open %s\n", fullpath ); */
/* return; */
/* } */
/* if ( config.verbose ) */
/* 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 ];
get_absolute_working_dir_path();
sprintf( fullpath, "%s%s", absolute_working_dir_path, filename );
/* char fullpath[ MAX_LENGTH_FILENAME ]; */
/* get_absolute_working_dir_path(); */
/* sprintf( fullpath, "%s%s", absolute_working_dir_path, filename ); */
FILE* fp;
/* FILE* fp; */
if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) {
if ( config.verbose )
fprintf( stderr, "can\'t open %s\n", fullpath );
return;
}
/* if ( NULL == ( fp = fopen( fullpath, "w" ) ) ) { */
/* if ( config.verbose ) */
/* fprintf( stderr, "can\'t open %s\n", fullpath ); */
/* return; */
/* } */
fwrite( &bus_info, sizeof( BusInfo ), 1, fp );
/* fwrite( &bus_info, sizeof( BusInfo ), 1, 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 );
/* fclose( fp ); */
}
void rom_init( char* filename )

View file

@ -9,13 +9,11 @@ extern void load_file_on_stack( char* filename );
extern void rom_init( char* filename );
extern void ram_init( char* filename );
extern void ports_init( char* filename1, char* filename2 );
extern void cpu_init( char* filename );
extern void bus_init( char* filename );
extern void cpu_bus_init( char* filename );
extern void rom_exit();
extern void ram_exit( char* filename );
extern void ports_exit( char* filename1, char* filename2 );
extern void cpu_exit( char* filename );
extern void bus_exit( char* filename );
extern void cpu_bus_exit( char* filename );
#endif