int main() { init_curses(); const char *exit_msg = ""; srandom(time(NULL)); struct game_t game = {0}; int last_turn = game.turns; get_highscore_filepath(&game); load_highscore(&game); place_tile(&game); place_tile(&game); while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (getch()) { case 'h': case KEY_LEFT: case 'a': move_left(&game); break; case 'j': case KEY_DOWN: case 's': move_down(&game); break; case 'k': case KEY_UP: case 'w': move_up(&game); break; case 'l': case KEY_RIGHT: case 'd': move_right(&game);break; case 'q': exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: move(7, 0); printw("You lose! Press q to quit."); while (getch() != 'q'); end: endwin(); if(game.score > game.highscore) { game.highscore = game.score; save_highscore(&game); } printf("You %s after scoring %d points in %d turns, " "with largest tile %d. The local highscore is %d points.\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board), game.highscore); free(game.highscorefile); return 0; }
/* main() * Program entry point. Initializes everything and runs the main loop. * Times are calculated and the frame rate is controlled here. */ int main( int argc, char* argv[] ) { program_state_t* PS = &program_state; game_state_t* GS = &game_state; sounds_t* snd = &(GS->sounds); PS->program_start_us = get_time(); init_sdl( PS, GS ); // Create window, load sounds init_sound( PS, GS ); // Load music, sounds, set volume init_font( PS ); // Load font init_opengl( PS ); // Load textures play_music( snd->music ); load_highscore( GS ); PS->current_time_us = PS->frame_start_us = get_time(); // Make the following look nice in debug info PS->game_start_us = PS->pause_since_us = PS->program_start_us - 1; PS->tick_fraction_s = -1; PS->highest_frame_time = 0; PS->lowest_frame_time = 99999999; PS->run_mode = RM_INTRO; while (PS->run_mode != RM_EXIT) { PS->current_time_us = get_time(); // Calculate how much time we need to waste for target FPS PS->delay_until_us = PS->current_time_us + (1000000 / TARGET_FPS) ; // Keep track of game time (handling pause) if ( !(PS->run_mode & (RM_PAUSE | RM_MAIN_MENU)) ) { PS->game_time_us = PS->current_time_us - PS->game_start_us ; } // Show intro after main menu idles for a while if (PS->run_mode == RM_MAIN_MENU) { if (PS->main_menu_since_us + MAIN_MENU_INTRO_SWITCH_TIME < get_time()) { PS->run_mode = RM_INTRO; } } // Handle user input process_event_queue( PS, GS ); // Let the universe live for a short moment if (PS->run_mode & (RM_RUNNING | RM_AFTER_LIFE)) { advance_simulation( PS, GS ); } // Display the current world status as game scene draw_frame( PS, GS ); #if LIMIT_FPS // Waste time until the next frame needs to be drawn while (get_time() < PS->delay_until_us) { #if LIMIT_FPS_USING_SDL_DELAY SDL_Delay( 1 ); #endif } #endif // Keep track of how many FPS we actually achieved PS->frame_time_us = get_time() - PS->frame_start_us; PS->highest_frame_time = max( PS->highest_frame_time, PS->frame_time_us ); PS->lowest_frame_time = min( PS->lowest_frame_time, PS->frame_time_us ); PS->frame_start_us = get_time(); PS->tick_fraction_s = (real_t)PS->frame_time_us / 1000000.0; save_frame_time( PS ); // For average FPS PS->average_frame_time = average_frame_time( PS ); } save_highscore( PS, GS ); glDeleteTextures( 1, &(PS->textures.background) ); glDeleteTextures( 1, &(PS->textures.digits) ); Mix_FreeChunk( snd->laser ); Mix_FreeChunk( snd->hit ); Mix_FreeChunk( snd->punch ); Mix_FreeChunk( snd->blast ); Mix_FreeChunk( snd->denied ); Mix_FreeChunk( snd->alarm ); Mix_FreeChunk( snd->blub ); Mix_FreeChunk( snd->computer_autofire ); Mix_FreeChunk( snd->computer_doubleshot ); Mix_FreeChunk( snd->computer_roundshot ); Mix_FreeChunk( snd->computer_danger ); Mix_FreeChunk( snd->computer_weaponlost ); Mix_FreeMusic( snd->music ); SDL_Quit(); // Will (allegedly) also free screen . return 0; }
/********************* Main*/ int omain(int argc, char *argv[]){ int i, cnt, cntt, cnttt, way; static char file[MAXC], attr[MAXC], val[MAXC], *p, *binver; #if defined(ALLEGRO_WINDOWS) binver = "Windows binary"; #elif defined(ALLEGRO_DOS) binver = "DOS binary"; #elif defined(ALLEGRO_LINUX) binver = "Linux binary"; #elif defined(ALLEGRO_BEOS) binver = "BEOS binary"; #elif defined(ALLEGRO_QNX) binver = "QNX binary"; #elif defined(ALLEGRO_UNIX) binver = "UNIX binary"; #elif defined(ALLEGRO_MPW) binver = "MacOS binary"; #else binver = "Unknown binary"; #endif printf("%s %s\n","\nO2EM v" O2EM_VERSION " " RELEASE_DATE " - ", binver); printf("Free Odyssey2 / Videopac+ Emulator - http://o2em.sourceforge.net\n"); printf("Created by Daniel Boris (c)1996/1998\n"); printf("Developed by:\n"); printf(" Andre de la Rocha since version 0.80\n"); printf(" Arlindo M. de Oliveira since version 1.16\n"); printf("\n"); app_data.debug = 0; app_data.stick[0] = app_data.stick[1] = 1; app_data.sticknumber[0] = app_data.sticknumber[1] = 0; set_defjoykeys(0,0); set_defjoykeys(1,1); set_defsystemkeys(); app_data.bank = 0; app_data.limit = 1; app_data.sound_en = 1; app_data.speed = 100; app_data.wsize = 2; #ifdef ALLEGRO_DOS app_data.fullscreen = 1; #else app_data.fullscreen = 0; #endif app_data.scanlines = 0; app_data.voice = 1; app_data.window_title = "O2EM v" O2EM_VERSION; app_data.svolume = 100; app_data.vvolume = 100; app_data.filter = 0; app_data.exrom = 0; app_data.three_k = 0; app_data.crc = 0; app_data.scshot = scshot; app_data.statefile = statefile; app_data.euro = 0; app_data.openb = 0; app_data.vpp = 0; app_data.bios = 0; app_data.scoretype = 0; app_data.scoreaddress = 0; app_data.default_highscore = 0; app_data.breakpoint = 65535; app_data.megaxrom = 0; strcpy(file,""); strcpy(file_l,""); strcpy(bios_l,""); strcpy(bios,""); strcpy(scshot,""); strcpy(statefile,""); strcpy(xrom,""); strcpy(scorefile,"highscore.txt"); read_default_config(); if (argc >= 2){ for(i=1; i<argc; i++) { if (argv[i][0] != '-') { strncat(file,argv[i],MAXC-1); file[MAXC-1]=0; strcpy(file_v,file); } else { p=strtok(argv[i],"="); if (p){ strncpy(attr,p+1,MAXC-1); attr[MAXC-1]=0; } else strcpy(attr,""); p=strtok(NULL,"="); if (p){ strncpy(val,p,MAXC-1); val[MAXC-1]=0; if (!strcmp(attr,"romdir")||!strcmp(attr,"ROMDIR")) { strcpy(romdir,val); strcat(romdir,file); strcpy(file,romdir); strcpy(romdir,val); } if (!strcmp(attr,"biosdir")||!strcmp(attr,"BIOSDIR")) { strcpy(biosdir,val); } } else strcpy(val,""); strlwr(attr); if (!parse_option(attr, val)) exit(EXIT_FAILURE); } } if (helpflag) helpus(); if (strlen(file)==0) { fprintf(stderr,"Error: file name missing\n"); exit(EXIT_FAILURE); } #ifdef __LIBRETRO__ sprintf(statefile,"%s.state\0",file); #endif printf("Starting emulation ...\n"); #ifndef __LIBRETRO__ allegro_init(); install_timer(); #endif init_audio(); #ifndef __LIBRETRO__ printf("Using Allegro %s\n",allegro_id); #endif /********************** ROMs if Launcher running... */ k = strchr(romdir, '/'); launcher_flag_r = strchr(file, '\\'); if (k != 0) { strcpy (xrom,romdir); } else if (!launcher_flag_r) { strcpy(xrom,"roms/"); strcpy(romdir,file); #ifndef __LIBRETRO__ strcpy(file,xrom); strcat(file,romdir); #endif strcpy(romdir,xrom); } else { cnt = 0; cntt = 0; cnttt = 0; way = 0; for (cnt=0; file[cnt] != '\0'; cnt=cnt+1) { if ( file[cnt] == '\\' ) { cnttt = cnt; } } for (cnt=0; cnt<=cnttt; cnt++) { file_l[cnt] = file[cnt]; } strcpy (romdir,file_l); strcpy (xrom,romdir); } #ifdef __LIBRETRO__ #ifdef AND sprintf(xrom,"%s\0","/mnt/sdcard/O2EM/roms/"); strcpy(romdir,xrom); #else sprintf(xrom,"%s\0","./roms/"); strcpy(romdir,xrom); #endif #endif file_name(xrom); if (contax < 3) { printf("\nROMs directory empty!\n"); exit(EXIT_FAILURE); } app_data.crc = crc32_file(file); crcx = app_data.crc; suck_roms(); /********************** BIOSs if Launcher running... */ launcher_flag_b = strchr(bios, '\\'); if (!launcher_flag_b){ k = strchr(biosdir, '/'); if (k != 0) { strcpy (xbios,biosdir); } else { strcpy (xbios,"bios/"); strcpy (biosdir,xbios); } #ifdef __LIBRETRO__ #ifdef AND sprintf(xbios,"%s\0","/mnt/sdcard/O2EM/bios/"); strcpy (biosdir,xbios); #else sprintf(xbios,"%s\0","./bios/"); strcpy (biosdir,xbios); #endif #endif file_name(xbios); if (contax < 3) { printf("\nBIOS directory empty!\n"); exit(EXIT_FAILURE); } suck_bios(); c_j = strcmp(bios,"jopac"); if ((rom_f!=1) && (c_j!=0)) strcpy(bios,g7400); if ((!o2flag) && (!jopflag) && (!c52flag) && (!g74flag)) { printf("\ndir '%s' without BIOS !",biosdir); exit(EXIT_FAILURE); } printf("BIOS found:\n"); if (!strcmp(bios,"g7400")){ strcpy(bios,g7400); if (g74flag != 1) { printf("\nG7400 BIOS not found !"); exit(EXIT_FAILURE); } } if (g74flag) printf(" G7400 VP+\n"); if (!strcmp(bios,"c52")){ strcpy(bios,c52); if (c52flag != 1) { printf("\nC52 BIOS not found !"); exit(EXIT_FAILURE); } } if (c52flag) printf(" C52\n"); if (!strcmp(bios,"jopac")){ strcpy(bios,jopac); if (jopflag != 1) { printf("\nJOPAC BIOS not found !"); exit(EXIT_FAILURE); } } if (jopflag) printf(" JOPAC VP+\n"); if ((!strcmp(bios,"")) || (!strcmp(bios,"o2rom"))) { strcpy(bios,odyssey2); if ((!o2flag)&&(!c52flag)&&(rom_f)){ printf("Odyssey2 BIOS not found !\n"); exit(EXIT_FAILURE); } if ((!o2flag)&&(c52flag)&&(rom_f)){ printf("\nOdyssey2 BIOS not found !\n"); printf("Loading C52 BIOS ... "); strcpy(bios,c52); } } if (o2flag) printf(" Odyssey 2\n"); } if (launcher_flag_b) { identify_bios(bios); if (rom_f!=1) { if (!((g74flag)||(jopflag))) { fprintf(stderr,"\nError: ROM only VP+ BIOS"); exit(EXIT_FAILURE); } } } if (!launcher_flag_b) { if (rom_f!=1) { if (!((g74flag)||(jopflag))) { printf("\nROM only VP+ BIOS\n"); exit(EXIT_FAILURE); } if (!(g74flag)) { printf("\nVP+ G7400 BIOS not found !"); printf("\nLoading VP+ Jopac BIOS ..."); strcpy(bios,jopac); } } } load_bios(bios); load_cart(file); if (app_data.voice) load_voice_samples(path); init_display(); init_cpu(); init_system(); set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore); int stateError; if ((stateError=loadstate(app_data.statefile))==0) { printf("Savefile loaded."); } else if (stateError>=199) { if (stateError==199) fprintf(stderr,"Wrong ROM-File for Savefile."); else if (stateError==200+ROM_O2) fprintf(stderr,"Wrong BIOS for Savefile: O2ROM needed."); else if (stateError==200+ROM_G7400) fprintf(stderr,"Wrong BIOS for Savefile: G7400 ROM needed."); else if (stateError==200+ROM_C52) fprintf(stderr,"Wrong BIOS for Savefile: C52 ROM needed."); else if (stateError==200+ROM_JOPAC) fprintf(stderr,"Wrong BIOS for Savefile: JOPAC ROM needed."); else fprintf(stderr,"Wrong BIOS for Savefile: UNKNOWN ROM needed."); return(0); } if (app_data.debug) key_debug=1; #ifndef _DEBUG #ifdef ALLEGRO_WINDOWS FreeConsole(); #endif #endif #ifdef __LIBRETRO__ return 1; #endif run(); if (app_data.scoretype!=0) save_highscore(get_score(app_data.scoretype, app_data.scoreaddress), scorefile); exit(EXIT_SUCCESS); } if (!strcmp(attr,"help")||!strcmp(attr,"HELP")) helpus(); printf("type o2em -help"); exit(EXIT_SUCCESS); }