diff --git a/src/bus.c b/src/bus.c index 045ca55..043b343 100644 --- a/src/bus.c +++ b/src/bus.c @@ -57,10 +57,6 @@ static address hdw_seg; word crc; -void bus_init( void ) { bus_reset(); } - -void bus_exit( void ) {} - static inline void update_crc( byte nibble ) { crc = ( crc >> 4 ) ^ ( ( ( crc ^ nibble ) & 0xF ) * 0x1081 ); } void bus_read( byte* buf, address adr, address len ) diff --git a/src/bus.h b/src/bus.h index af86006..82d6f5b 100644 --- a/src/bus.h +++ b/src/bus.h @@ -50,8 +50,8 @@ extern word crc; // FAST_PEEK_MAX must not be greater than the size of the hdw registers (64) #define FAST_PEEK_MAX 64 -extern void bus_init( void ); -extern void bus_exit( void ); +/* extern void bus_init( void ); */ +/* extern void bus_exit( void ); */ extern void bus_read( byte* buf, address adr, address len ); extern void bus_write( byte* buf, address adr, address len ); diff --git a/src/emulator.c b/src/emulator.c index a1335a9..1ee23eb 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -41,26 +41,25 @@ 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 ) +void emulator_init( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu ) { - static bool locked = false; - get_absolute_working_dir_path( "hpemung" ); + rom_init( fn_rom ); ram_init( fn_ram ); ports_init( fn_port1, fn_port2 ); - bus_init(); - if ( !locked ) - locked = true; + cpu_init( fn_cpu ); + bus_init( fn_bus ); } -void emulator_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2 ) +void emulator_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2, char* fn_bus, char* fn_cpu ) { - rom_exit(); - ram_exit( fn_ram ); ports_exit( fn_port1, fn_port2 ); - bus_exit(); + ram_exit( fn_ram ); + rom_exit(); + bus_exit( fn_bus ); + cpu_exit( fn_cpu ); } static inline void throttle( bool is_needed ) diff --git a/src/emulator.h b/src/emulator.h index ec8a0b3..ed3d5ae 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -9,8 +9,8 @@ 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 ); -extern void emulator_exit( char* fn_rom, char* fn_ram, char* fn_port1, char* fn_port2 ); +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_set_state( int state ); diff --git a/src/files.c b/src/files.c index 087a41e..893f19f 100644 --- a/src/files.c +++ b/src/files.c @@ -10,6 +10,7 @@ #include "rpl.h" #include "bus.h" +#include "cpu.h" #include "config.h" #include "types.h" @@ -271,6 +272,9 @@ int write_mem_file( char* absolute_filename, nibble* mem, int size ) return 1; } +/********************/ +/* PUBLIC FUNCTIONS */ +/********************/ void load_file_on_stack( char* filename ) { FILE* f; @@ -331,6 +335,97 @@ void load_file_on_stack( char* filename ) free( obj ); } +void bus_init( char* filename ) +{ + char fullpath[ MAX_LENGTH_FILENAME ]; + get_absolute_working_dir_path(); + sprintf( fullpath, "%s%s", absolute_working_dir_path, filename ); + if ( config.verbose ) + fprintf( stderr, "fullpath = %s\n", fullpath ); + + 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; */ + /* } */ + + /* fwrite( &bus_info, sizeof( BusInfo ), 1, fp ); */ + + /* fclose( fp ); */ + /* } else */ + bus_reset(); +} +void bus_exit( char* filename ) +{ + char fullpath[ MAX_LENGTH_FILENAME ]; + get_absolute_working_dir_path(); + sprintf( fullpath, "%s%s", absolute_working_dir_path, filename ); + if ( config.verbose ) + fprintf( stderr, "fullpath = %s\n", fullpath ); + + FILE* fp; + + 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 ); + + 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 ); + if ( config.verbose ) + fprintf( stderr, "fullpath = %s\n", fullpath ); + + 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; */ + /* } */ + + /* fwrite( &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 ); + if ( config.verbose ) + fprintf( stderr, "fullpath = %s\n", fullpath ); + + 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 ) { int size; @@ -430,7 +525,6 @@ void ram_init( char* filename ) bus_info.ram_mask = ram_size - 1; } - void ram_exit( char* filename ) { fprintf( stderr, "\n\nfilename = %s\n", filename ); @@ -492,7 +586,6 @@ void ports_init( char* filename1, char* filename2 ) bus_info.ben = false; current_bank = 0; } - void ports_exit( char* filename1, char* filename2 ) { char fullpath1[ MAX_LENGTH_FILENAME ]; diff --git a/src/files.h b/src/files.h index 355aebf..5240fd7 100644 --- a/src/files.h +++ b/src/files.h @@ -7,12 +7,15 @@ extern int file_size( char* filename ); extern void load_file_on_stack( char* filename ); extern void rom_init( char* filename ); -extern void rom_exit(); - extern void ram_init( char* filename ); -extern void ram_exit( char* filename ); - extern void ports_init( char* filename1, char* filename2 ); +extern void cpu_init( char* filename ); +extern void 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 ); #endif diff --git a/src/main.c b/src/main.c index b16f2ee..c63a306 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,7 @@ int main( int argc, char* argv[] ) if ( !gui_init() ) exit( EXIT_FAILURE ); - emulator_init( "rom", "ram", "port1", "port2" ); + emulator_init( "rom", "ram", "port1", "port2", "bus", "cpu" ); while ( !please_exit ) { if ( please_exit ) @@ -49,7 +49,7 @@ int main( int argc, char* argv[] ) break; } - emulator_exit( "rom", "ram", "port1", "port2" ); + emulator_exit( "rom", "ram", "port1", "port2", "bus", "cpu" ); gui_exit(); return 0;