Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    program_name = argv[0] ? argv[0] : "nesalizer";
#ifndef RUN_TESTS
    if (argc != 2) {
        fprintf(stderr, "usage: %s <rom file>\n", program_name);
        exit(EXIT_FAILURE);
    }
#else
    (void)argc; // Suppress warning
#endif

    install_fatal_signal_handlers();

    // One-time initialization of various components
    init_apu();
    init_input();
    init_mappers();

#ifndef RUN_TESTS
    load_rom(argv[1], true);
#endif

    // Create a separate emulation thread and use this thread as the rendering
    // thread

    init_sdl();
    SDL_Thread *emu_thread;
    fail_if(!(emu_thread = SDL_CreateThread(emulation_thread, "emulation", 0)),
            "failed to create emulation thread: %s", SDL_GetError());
    sdl_thread();
    SDL_WaitThread(emu_thread, 0);
    deinit_sdl();

#ifndef RUN_TESTS
    unload_rom();
#endif

    puts("Shut down cleanly");
}
Exemplo n.º 2
0
/* Intialize emulator with given ROM file, and
 * specify whether or not debug mode is active
 * (0 for OFF, any other value is on)
 *
 * returns 1 if successfully initialized, 0
 * otherwise */
int init_emu(const char *file_path, int debugger, int dmg_mode, ClientOrServer cs) {

    uint8_t rom_header[0x50];
    
    //Start logger
    set_log_level(LOG_INFO);

    log_message(LOG_INFO, "About to open file %s\n", file_path);
    FILE *file;
    if (!(file = PB_FOPEN(file_path,"rb"))) {
        log_message(LOG_ERROR, "Error opening file %s\n", file_path);
        return 0;
    }

    if ((PB_FSEEK(file, 0x100, SEEK_SET) != 0) 
        || (PB_FREAD(rom_header, 1, sizeof(rom_header), file) != sizeof(rom_header))) {
        log_message(LOG_ERROR, "Error reading ROM header info\n");
        fclose(file);
        return 0;    
    };
    PB_FCLOSE(file);

	log_message(LOG_INFO, "ROM Header loaded %s\n", file_path);
    if (!load_rom(file_path, rom_header, dmg_mode)) {
        log_message(LOG_ERROR, "failed to initialize GB memory\n");
        return 0;
    }

    if (!init_gfx()) {
        log_message(LOG_ERROR, "Failed to initialize graphics\n");
        return 0;
    }

    if (!setup_serial_io(cs, 5000)) {
        log_message(LOG_INFO, "No client or server created\n");
    }
    init_joypad();
    init_apu(); // Initialize sound
    reset_cpu();

    if (debugger) {
        debug = 1;
    }

    cgb_features = is_colour_compatible() || is_colour_only();

    //Log ROM info
    char name_buf[100];
    int i;
    for(i = ROM_NAME_START; i <= ROM_NAME_END; i++) {
        name_buf[i - ROM_NAME_START] = get_mem(i);
    }
    name_buf[i - ROM_NAME_START] = '\0';

    log_message(LOG_INFO,"Game Title: %s\n", name_buf);
    log_message(LOG_INFO,"Licensee: %s\n", get_licensee());
    log_message(LOG_INFO,"Destination: %s\n", get_destination_code());
    log_message(LOG_INFO,"ROM size: %dKB\n",get_rom_size());
    log_message(LOG_INFO,"RAM save size: %dKB\n",get_ram_save_size());

    const char *c_type = get_cartridge_type();
    log_message(LOG_INFO,"Cartridge Type: %s\n",c_type != NULL ? c_type : "Unknown");


    log_message(LOG_INFO, "Has Gameboy Color features: %s\n", is_colour_compatible() || is_colour_only() ? "Yes":"No");
    log_message(LOG_INFO,"Gameboy Color Only Game:%s\n", is_colour_only() ? "Yes":"No");
    log_message(LOG_INFO,"Super Gameboy Features:%s\n", has_sgb_features() ? "Yes":"No");

	
    return 1;
}