void initialize_system () { FILE *fconfig; fconfig = fopen ("config.sys", "r"); fscanf (fconfig, "%d\n", &Observe); fscanf (fconfig, "%d %d\n", &cpuQuantum, &idleQuantum); fscanf (fconfig, "%d %d %d %d\n", &pageSize, &memSize, &swapSize, &OSmemSize); fscanf (fconfig, "%d\n", &periodAgeScan); fscanf (fconfig, "%d\n", &spoolPsize); fclose (fconfig); OriginalPages= find_pages(memSize,pageSize); OriginalPages_swapspace = find_pages(swapSize,pageSize); rem_pages = OriginalPages; rem_pages_swapspace = OriginalPages_swapspace; #undef num_pages #define num_pages OriginalPages; OSpages= find_pages(OSmemSize,pageSize); printf("OS Size is %d , OS pages are %d\n", OSmemSize, OSpages); rem_pages= OriginalPages-OSpages; idlePages= find_pages(3, pageSize); /*printf("Idle Size is 256, Idle pages are %d, rem pages are %d \n", idlePages, rem_pages); rem_pages = rem_pages-idlePages;*/ printf("remaining pages are %d\n", rem_pages); #undef num_pages #define num_pages rem_pages; printf("Number of frames in Main memory is %d remaininng pages are %d\n", OriginalPages, rem_pages); initialize_cpu (); printf("initialized CPU \n"); initialize_swap_freelist(rem_pages_swapspace, OriginalPages_swapspace); printf("initialized Swap Space \n"); initialize_freelist(rem_pages, OriginalPages); printf("initialized Main Memory \n"); initialize_timer (); printf("initialized timer \n"); initialize_memory (); printf("initialized memory \n"); initialize_process (); printf("initialized process \n"); // initialize_memory (); // printf("initialized memory \n"); }
// sudo apt-get install libncurses5-dev // http://stackoverflow.com/questions/4025891/create-a-function-to-check-for-key-press-in-unix-using-ncurses // https://viget.com/extend/game-programming-in-c-with-the-ncurses-library int main(int argc, char **argv) { char *debug_filename = NULL; char *input_filename = NULL; int c; opterr = 0; while ((c = getopt(argc, argv, "d:p:")) != -1) { switch (c) { case 'd': debug_filename = optarg; break; case 'p': input_filename = optarg; break; case '?': fprintf(stderr, "Unknown option: %c\n", optopt); print_usage(); return 1; default: print_usage(); return 1; } } if (optind < argc || input_filename == NULL || (ends_with(input_filename, required_input_ext, 0) != 1)) { print_usage(); return 1; } FILE *input_file = fopen(input_filename, "rb"); if (!input_file) { fprintf(stderr, "Fatal error when opening input file: '%s'\n", argv[1]); exit(1); } FILE *debug_file = NULL; if (debug_filename) { debug_file = fopen(debug_filename, "w"); } chip_8_cpu cpu = initialize_cpu(); initialize_memory(cpu, input_file); fclose(input_file); execute_loop(cpu, debug_file); free_cpu(cpu); return EXIT_SUCCESS; }
int main(int args, char *argv[]) { char *save_file; ines_file *nes_rom; /* Print NOW everything :D */ #ifdef _MSC_VER setvbuf(stdout,NULL,_IONBF,0); setvbuf(stderr,NULL,_IONBF,0); #else setbuf(stdout,NULL); setbuf(stderr,NULL); #endif /* i18n stuff */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); /* Parse command line options */ initialize_configuration(); switch ( parse_options(args, argv) ) { case -1: usage(stderr,argv); exit(EXIT_FAILURE); case 0: exit(EXIT_SUCCESS); default: break; } load_user_configuration(); /* Initialize static data */ initialize_palette(); initialize_instruction_set(); initialize_playback(); initialize_apu(); initialize_cpu(); initialize_ppu(); initialize_clock(); initialize_pads(); /* Read the ines file and get all the ROM/VROM */ config.rom_file = argv[optind]; nes_rom = check_ines_file(config.rom_file); map_rom_memory(nes_rom); save_file = load_sram(config.rom_file); /* Init the graphics engine */ init_screen(); init_gui(); /* Main execution loop */ main_loop(); /* After finishing the emulation, save the SRAM if necessary */ save_sram(save_file); free(save_file); /* Free all the used resources */ mapper->end_mapper(); end_screen(); end_gui(); end_ppu(); end_cpu(); end_apu(); end_playback(); free_ines_file(nes_rom); return 0; }