int run_game(int game) { running_machine *machine; int error = MAMERR_NONE; mame_private *mame; callback_item *cb; /* create the machine structure and driver */ machine = create_machine(game); mame = machine->mame_data; /* looooong term: remove this */ Machine = machine; /* start in the "pre-init phase" */ mame->current_phase = MAME_PHASE_PREINIT; /* perform validity checks before anything else */ if (mame_validitychecks(game) != 0) return MAMERR_FAILED_VALIDITY; /* loop across multiple hard resets */ mame->exit_pending = FALSE; while (error == 0 && !mame->exit_pending) { init_resource_tracking(); add_free_resources_callback(timer_free); add_free_resources_callback(state_save_free); /* use setjmp/longjmp for deep error recovery */ mame->fatal_error_jmpbuf_valid = TRUE; error = setjmp(mame->fatal_error_jmpbuf); if (error == 0) { int settingsloaded; /* move to the init phase */ mame->current_phase = MAME_PHASE_INIT; /* start tracking resources for real */ begin_resource_tracking(); /* if we have a logfile, set up the callback */ mame->logerror_callback_list = NULL; if (options.logfile) add_logerror_callback(machine, logfile_callback); /* then finish setting up our local machine */ init_machine(machine); /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); nvram_load(); /* display the startup screens */ ui_display_startup_screens(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; /* start resource tracking; note that soft_reset assumes it can */ /* call end_resource_tracking followed by begin_resource_tracking */ /* to clear out resources allocated between resets */ begin_resource_tracking(); /* perform a soft reset -- this takes us to the running phase */ soft_reset(0); /* run the CPUs until a reset or exit */ mame->hard_reset_pending = FALSE; while ((!mame->hard_reset_pending && !mame->exit_pending) || mame->saveload_pending_file != NULL) { profiler_mark(PROFILER_EXTRA); /* execute CPUs if not paused */ if (!mame->paused) cpuexec_timeslice(); /* otherwise, just pump video updates through */ else video_frame_update(); /* handle save/load */ if (mame->saveload_schedule_callback) (*mame->saveload_schedule_callback)(machine); profiler_mark(PROFILER_END); } /* and out via the exit phase */ mame->current_phase = MAME_PHASE_EXIT; /* stop tracking resources at this level */ end_resource_tracking(); /* save the NVRAM and configuration */ nvram_save(); config_save_settings(); } mame->fatal_error_jmpbuf_valid = FALSE; /* call all exit callbacks registered */ for (cb = mame->exit_callback_list; cb; cb = cb->next) (*cb->func.exit)(machine); /* close all inner resource tracking */ exit_resource_tracking(); /* free our callback lists */ free_callback_list(&mame->exit_callback_list); free_callback_list(&mame->reset_callback_list); free_callback_list(&mame->pause_callback_list); } /* destroy the machine */ destroy_machine(machine); /* return an error */ return error; }
int main(int argc, char* argv[]) { #ifdef FANCY_STARTMESG fprintf(stderr,"6502V %1d.%2d : Lightning Fast 6502 Virtual Machine\n",VMAJOR,VMINOR); fprintf(stderr,"Copyright © HK (David Hanefelt Kristensen) 2012\n"); fprintf(stderr,"http://github.com/dhkris/6502v\n"); #endif m6502* mach_instance = create_machine(); vm_state* vm = create_vm_state(argc,argv); fprintf(stderr, "Built for %s\n", ARCHSTR); fputc('\n',stderr); #ifndef INTERNAL_TEST if(argc < 2 ) exit(255); FILE* input = fopen(argv[1],"rb"); byte teststream[8192*8]; int tsi = 0; while( (teststream[tsi] = (byte)fgetc(input)) != 0xFF ) tsi++; #else /* TEST PROGRAM byte teststream[] = {op_LDA_imm, 0x43, op_STA_abs, 0xF0, 0x00, // Set up indirect jump! op_LDA_imm, 0x27, op_STA_abs, 0xCA, 0x11, op_CMP_imm, 0x41, op_BNE_rel, 0x09, op_LDA_imm, 0x21, op_LDA_imm, 0x21, op_STA_abs, 0xF0, 0x00, op_DIE, op_LDA_imm, 0x60, op_STA_abs, 0xF0, 0x00, op_INC_abs, 0xF0, 0x00, op_INX, op_JMP_ind, 0xCA, 0x11, op_LDA_imm, 0x59, op_STA_abs, 0xF0, 0x00, op_LDA_imm, 0x49, op_STA_abs, 0xF0, 0x00, op_DIE }; */ #endif #ifdef DEBUG fprintf(stderr," ==== PROGRAM PRINTOUT ====\n"); fprintf(stderr, "OPER@ | DESCRIPTION\n"); fprintf(stderr, "______|_________________________________________________________________________\n"); #endif int program_counter = xqt(mach_instance, teststream, 0); while( (program_counter = xqt(mach_instance, teststream, program_counter)) != 0xFFFF ) ; #ifdef DEBUG fprintf(stderr,"______I_________________________________________________________________________\n"); #endif fputc('\n',stderr); }
int run_game(int game) { callback_item *cb; int error = 0; /* start in the "pre-init phase" */ current_phase = MAME_PHASE_PREINIT; /* AdvanceMAME: Disable validity checks */ #if 0 /* perform validity checks before anything else */ if (mame_validitychecks(game) != 0) return 1; #endif /* loop across multiple hard resets */ exit_pending = FALSE; while (error == 0 && !exit_pending) { /* use setjmp/longjmp for deep error recovery */ fatal_error_jmpbuf_valid = TRUE; error = setjmp(fatal_error_jmpbuf); if (error == 0) { int settingsloaded; /* move to the init phase */ current_phase = MAME_PHASE_INIT; /* start tracking resources for real */ begin_resource_tracking(); /* if we have a logfile, set up the callback */ logerror_callback_list = NULL; if (options.logfile) add_logerror_callback(logfile_callback); /* create the Machine structure and driver */ create_machine(game); /* then finish setting up our local machine */ init_machine(); /* load the configuration settings and NVRAM */ settingsloaded = config_load_settings(); nvram_load(); /* initialize the UI and display the startup screens */ if (ui_init(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo) != 0) fatalerror("User cancelled"); /* ensure we don't show the opening screens on a reset */ options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE; /* start resource tracking; note that soft_reset assumes it can */ /* call end_resource_tracking followed by begin_resource_tracking */ /* to clear out resources allocated between resets */ begin_resource_tracking(); /* perform a soft reset -- this takes us to the running phase */ soft_reset(0); /* run the CPUs until a reset or exit */ hard_reset_pending = FALSE; while ((!hard_reset_pending && !exit_pending) || saveload_pending_file != NULL) { profiler_mark(PROFILER_EXTRA); /* execute CPUs if not paused */ if (!mame_paused) cpuexec_timeslice(); /* otherwise, just pump video updates through */ else { updatescreen(); reset_partial_updates(); } /* handle save/load */ if (saveload_schedule_callback) (*saveload_schedule_callback)(); profiler_mark(PROFILER_END); } /* and out via the exit phase */ current_phase = MAME_PHASE_EXIT; /* stop tracking resources at this level */ end_resource_tracking(); /* save the NVRAM and configuration */ nvram_save(); config_save_settings(); } fatal_error_jmpbuf_valid = FALSE; /* call all exit callbacks registered */ for (cb = exit_callback_list; cb; cb = cb->next) (*cb->func.exit)(); /* close all inner resource tracking */ while (resource_tracking_tag != 0) end_resource_tracking(); /* free our callback lists */ free_callback_list(&exit_callback_list); free_callback_list(&reset_callback_list); free_callback_list(&pause_callback_list); } /* return an error */ return error; }