/*************************************************************************** Run the emulation. Start the various subsystems and the CPU emulation. Returns non zero in case of error. ***************************************************************************/ int run_machine(void) { int res = 1; if (vh_open() == 0) { tilemap_init(); sprite_init(); gfxobj_init(); if (drv->vh_start == 0 || (*drv->vh_start)() == 0) /* start the video hardware */ { if (sound_start() == 0) /* start the audio hardware */ { int region; real_scrbitmap = artwork_overlay ? overlay_real_scrbitmap : Machine->scrbitmap; /* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */ for (region = 0; region < MAX_MEMORY_REGIONS; region++) { if (Machine->memory_region_type[region] & REGIONFLAG_DISPOSE) { int i; /* invalidate contents to avoid subtle bugs */ for (i = 0;i < memory_region_length(region);i++) memory_region(region)[i] = rand(); free(Machine->memory_region[region]); Machine->memory_region[region] = 0; } } if (settingsloaded == 0) { /* if there is no saved config, it must be first time we run this game, */ /* so show the disclaimer. */ //sq if (showcopyright(real_scrbitmap)) goto userquit; } //sq if (showgamewarnings(real_scrbitmap) == 0) /* show info about incorrect behaviour (wrong colors etc.) */ { /* shut down the leds (work around Allegro hanging bug in the DOS port) */ osd_led_w(0,1); osd_led_w(1,1); osd_led_w(2,1); osd_led_w(3,1); osd_led_w(0,0); osd_led_w(1,0); osd_led_w(2,0); osd_led_w(3,0); init_user_interface(); /* disable cheat if no roms */ if (!gamedrv->rom) options.cheat = 0; if (options.cheat) InitCheat(); if (drv->nvram_handler) { void *f; f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,0); (*drv->nvram_handler)(f,0); if (f) osd_fclose(f); } cpu_run(); /* run the emulation! */ if (drv->nvram_handler) { void *f; if ((f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,1)) != 0) { (*drv->nvram_handler)(f,1); osd_fclose(f); } } if (options.cheat) StopCheat(); /* save input ports settings */ save_input_port_settings(); } userquit: /* the following MUST be done after hiscore_save() otherwise */ /* some 68000 games will not work */ sound_stop(); if (drv->vh_stop) (*drv->vh_stop)(); overlay_free(); backdrop_free(); res = 0; } else if (!bailing) { bailing = 1; printf("Unable to start audio emulation\n"); } } else if (!bailing) { bailing = 1; printf("Unable to start video emulation\n"); } gfxobj_close(); sprite_close(); tilemap_close(); vh_close(); } else if (!bailing) { bailing = 1; printf("Unable to start video emulation\n"); } return res; }
/*************************************************************************** Run the emulation. Start the various subsystems and the CPU emulation. Returns non zero in case of error. ***************************************************************************/ int run_machine(const char *gamename) { int res = 1; if (vh_open() == 0) { if (*drv->vh_start == 0 || (*drv->vh_start)() == 0) /* start the video hardware */ { if (*drv->sh_start == 0 || (*drv->sh_start)() == 0) /* start the audio hardware */ { FILE *f; char name[100]; int i,incount, keycount; incount = 0; while (gamedrv->input_ports[incount].default_value != -1) incount++; /* read dipswitch settings from disk */ sprintf(name,"%s/%s.dsw",gamename,gamename); if ((f = fopen(name,"rb")) != 0) { /* use name as temporary buffer */ if (fread(name,1,incount,f) == incount) { for (i = 0;i < incount;i++) gamedrv->input_ports[i].default_value = ((unsigned char)name[i]); } fclose(f); } keycount = 0; while (gamedrv->keysettings[keycount].num != -1) keycount++; /* read dipswitch settings from disk */ sprintf(name,"%s/%s.key",gamename,gamename); if ((f = fopen(name,"rb")) != 0) { /* use name as temporary buffer */ if (fread(name,1,keycount,f) == keycount) { for (i = 0;i < keycount;i++) gamedrv->input_ports[ gamedrv->keysettings[i].num ].keyboard[ gamedrv->keysettings[i].mask ] = ((unsigned char)name[i]); } fclose(f); } /* we have to load the hi scores, but this will be done while */ /* the game is running */ hiscoreloaded = 0; sprintf(hiscorename,"%s/%s.hi",gamename,gamename); cpu_run(); /* run the emulation! */ if (*drv->sh_stop) (*drv->sh_stop)(); if (*drv->vh_stop) (*drv->vh_stop)(); /* write hi scores to disk */ if (hiscoreloaded != 0 && *gamedrv->hiscore_save) (*gamedrv->hiscore_save)(hiscorename); /* write dipswitch settings to disk */ sprintf(name,"%s/%s.dsw",gamename,gamename); if ((f = fopen(name,"wb")) != 0) { /* use name as temporary buffer */ for (i = 0;i < incount;i++) name[i] = gamedrv->input_ports[i].default_value; fwrite(name,1,incount,f); fclose(f); } /* write key settings to disk */ sprintf(name,"%s/%s.key",gamename,gamename); if ((f = fopen(name,"wb")) != 0) { /* use name as temporary buffer */ for (i = 0;i < keycount;i++) name[i] = gamedrv->input_ports[ gamedrv->keysettings[i].num ].keyboard[ gamedrv->keysettings[i].mask ]; fwrite(name,1,keycount,f); fclose(f); } res = 0; } else printf("Unable to start audio emulation\n"); } else printf("Unable to start video emulation\n"); vh_close(); } else printf("Unable to initialize display\n"); return res; }