#include "emul.h" #include "6502.h" #include "memory.h" #include "6522.h" #include "7seg.h" #include #include "options.h" #include "version.h" static int parse_options_and_arguments( int argc, char *argv[], struct gengetopt_args_info *args_info ) { cmdline_parser_init( args_info ); if( cmdline_parser2( argc, argv, args_info, 1, 0, 1 ) != 0 ) { cmdline_parser_free( args_info ); return 1; } return 0; } int main( int argc, char *argv[] ) { struct gengetopt_args_info args_info; emul_t emul; bus_t bus; memory_t rom; memory_t ram; via_6522_t via; seg7_t seg7; cpu_6502_t cpu; if( parse_options_and_arguments( argc, argv, &args_info ) != 0 ) { exit( EXIT_FAILURE ); } if( args_info.long_version_given ) { printf( "emu version: %s, Copyright (c) 2020, GPLv3, Andreas Baumann \n", EMU_VERSION ); exit( EXIT_SUCCESS ); } bus_init( &bus ); memory_init( &rom, MEMORY_ROM, ROM_START, ROM_SIZE, args_info.initialize_given ); memory_load( &rom, args_info.rom_arg ); bus_register( &bus, &rom.base, ROM_START, ROM_END ); memory_init( &ram, MEMORY_RAM, RAM_START, RAM_SIZE, args_info.initialize_given ); bus_register( &bus, &ram.base, RAM_START, RAM_END ); via_6522_init( &via, VIA_START, args_info.initialize_given ); bus_register( &bus, &via.base, VIA_START, VIA_END ); seg7_init( &seg7, args_info.initialize_given ); via_6522_register( &via, &seg7.base ); cpu_6502_init( &cpu, &bus, args_info.initialize_given ); if( args_info.debug_given ) { if( args_info.print_cpu_given ) { cpu.debug_flags |= DEBUG_STATUS; } if( args_info.print_zero_page_given ) { cpu.debug_flags |= DEBUG_ZERO_PAGE; } if( args_info.print_stack_given ) { cpu.debug_flags |= DEBUG_STACK; } if( args_info.print_7seg_given ) { seg7.debug = true; } } emul_init( &emul, &cpu, &bus, args_info.width_arg, args_info.height_arg ); if( args_info.gui_given ) { emul.gui = true; } if( args_info.debug_given ) { emul.debug = true; } if( args_info.start_paused_given ) { emul.paused = true; emul.speed = 25; } emul_start( &emul ); cpu_6502_reset( &cpu ); emul_run( &emul, args_info.steps_arg ); bus_deinit( &bus ); emul_free( &emul ); cmdline_parser_free( &args_info ); exit( EXIT_SUCCESS ); }