Exemplo n.º 1
0
static int sid_snapshot_read_module_simple(snapshot_t *s)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    BYTE tmp[34];

    m = snapshot_module_open(s, snap_module_name_simple,
                             &major_version, &minor_version);
    if (m == NULL) {
        goto fail;
    }

    if (major_version > SNAP_MAJOR_SIMPLE
        || minor_version > SNAP_MINOR_SIMPLE) {
        log_error(LOG_DEFAULT,
                  "SID: Snapshot module version (%d.%d) newer than %d.%d.\n",
                  major_version, minor_version,
                  SNAP_MAJOR_SIMPLE, SNAP_MINOR_SIMPLE);
        snapshot_module_close(m);
        goto fail;
    }

    /* If more than 32 bytes are present then the resource "Sound" and
       "SidEngine" come first! If there is only one byte present, then
       sound is disabled. */
    if (SMR_BA(m, tmp, 34) < 0) {
        if (SMR_BA(m, tmp, 32) < 0) {
            if (SMR_BA(m, tmp, 1) < 0) {
                snapshot_module_close(m);
                goto fail;
            } else {
                sound_close();
            }
        } else {
            memcpy(sid_get_siddata(0), &tmp[0], 32);
        }
    } else {
        int res_sound = (int)(tmp[0]);
        int res_engine = (int)(tmp[1]);

        screenshot_prepare_reopen();
        sound_close();
        screenshot_try_reopen();
        resources_set_int("Sound", res_sound);
        if (res_sound) {
            resources_set_int("SidEngine", res_engine);
            /* FIXME: Only data for first SID read. */
            memcpy(sid_get_siddata(0), &tmp[2], 32);
            sound_open();
        }
    }

    return snapshot_module_close(m);

fail:
    log_error(LOG_DEFAULT, "Failed reading SID snapshot");
    return -1;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	SID sid;
	sound_open();
	sid.reset();
	if (fcntl(0, F_SETFL, O_NONBLOCK) != 0)
		fatal("fcntl failed: %d", errno);
	int i = 0;
	while (1) {
		int n = read(0, &in_buf[i], sizeof(in_buf) - i);
		if (n < 0) {
			if (errno != EAGAIN && errno != EWOULDBLOCK)
				fatal("read failed: %d", errno);
			sound_emit(sid, SID_CLOCK / LOOP_FREQ);
		} else if (n > 0) {
			n += i;
			for (i = 0; i < n; i += 2) {
				if (n - i >= 2)
					sid.write(in_buf[i], in_buf[i + 1]);
			}
			if (n & 1)
				i = 1;
		} else {
			break;
		}
	}
	sound_close();
}
Exemplo n.º 3
0
void sounds_close(void)
{
	sound_free(sound_burning);
	sound_free(sound_bulbul);
	sound_free(sound_sinked);
	sound_free(sound_missed);

	sound_close();
}
Exemplo n.º 4
0
void post_main(void)
{
	Replay::close();
	game.close();
	Carets::close();
	
	Graphics::close();
	input_close();
	font_close();
	sound_close();
	tsc_close();
	textbox.Deinit();
}
Exemplo n.º 5
0
void dgreed_close(void) {
    malka_states_end();
    malka_states_close();

    sprsheet_close();

    malka_close();

    mfx_close();
    particles_close();

    keyval_close();

    sound_close();
    video_close();
}
Exemplo n.º 6
0
/*
 * Close a WAVFILE
 */
int WavClose(WAVFILE *wfile) 
{
	if ( wfile == NULL ) 
	{
		printf("WAVFILE pointer is NULL!\n");
		return -1;
	}

	if ( sound_close(wfile->fd) < 0 ) 
	{
		printf("Closing WAV file\n");
	}

	wavfile_free(wfile);			/* Release WAVFILE structure */

	return 0;				/* Successful exit */
}
Exemplo n.º 7
0
static UI_CALLBACK(run_c1541)
{
#ifdef HAVE_FULLSCREEN
    fullscreen_suspend(0);
#endif
    vsync_suspend_speed_eval();
    sound_close();
    switch (system("xterm -sb -e c1541 &")) {
    case 127:
        ui_error(_("Couldn't run /bin/sh???"));
        break;
    case -1:
        ui_error(_("Couldn't run xterm"));
        break;
    case 0:
        break;
    default:
        ui_error(_("Unknown error while running c1541"));
    }
}
Exemplo n.º 8
0
static UI_CALLBACK(run_c1541)
{
    int i = 0;
    char *terms[6] = {
        "x-terminal-emulator",
        "konsole",
        "gterm",
        "aterm",
        "xterm -sb -rightbar",
        NULL
    };
    int err = -1;
#ifdef HAVE_FULLSCREEN
    fullscreen_suspend(0);
#endif
    vsync_suspend_speed_eval();
    sound_close();

    /* try a couple of known terminal programs */
    while ((err != 0) && (terms[i])) {
        err = runc1541(terms[i]);
        i++;
    }
    switch (err) {
        case 127: /* If a shell could not be executed in the child process,
                     then the return value is as though the child shell
                     terminated by calling _exit(2) with the status 127 */
            ui_error(_("Couldn't run /bin/sh???"));
            break;
        case -1: /*  If a child process could not be created,
                     or its status could not be retrieved */
            ui_error(_("Couldn't run terminal"));
            break;
        case 0:
            break;
        default:
            ui_error(_("Unknown error while running c1541"));
    }
}
Exemplo n.º 9
0
int main()
{
    FILE *fp_file;		/* ファイル書き込み用ファイルポインタ */
    int count;

    /* 音声入力 */
    sound_open();
    fprintf(stderr, ";; Start recording\n");

    count = sound_read((char *) buf, BUFSIZE);
    fprintf(stderr, ";; %d byte are recorded\n", count);

    sound_close();

  /****************************/
    /*  音声ファイルの書き出し  */
  /****************************/

    /* ファイルを書きだし専用でオープンする */
    fp_file = fopen("test.raw", "wb");
    if (fp_file == NULL) {	/* エラー処理 */
	perror("file open failed");
	return 1;
    }

    /* 音声データを書き込む */
    count = fwrite(buf, sizeof(short), BUFSIZE / sizeof(short), fp_file);
    if (count != BUFSIZE / sizeof(short)) {	/* エラー処理 */
	fprintf(stderr,
		"read count = %d, BUFSIZE = %d, sizeof(buf) = %d\n", count,
		BUFSIZE, BUFSIZE / sizeof(short));
    }

    /* ファイルをクローズする */
    fclose(fp_file);


    return 1;
}
Exemplo n.º 10
0
int vic_snapshot_read_module(snapshot_t *s)
{
    WORD i;
    snapshot_module_t *m;
    BYTE major_version, minor_version;
    WORD w;
    BYTE b;

    sound_close();

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return -1;
    }

    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
        log_error(vic.log, "Snapshot module version (%d.%d) newer than %d.%d.",
                  major_version, minor_version,
                  SNAP_MAJOR, SNAP_MINOR);
        goto fail;
    }

    if (SMR_B(m, &b) < 0) {
        goto fail;
    }
    if (b != VIC_RASTER_CYCLE(maincpu_clk)) {
        log_error(vic.log, "Cycle value (%d) incorrect; should be %d.",
                  (int)b, VIC_RASTER_CYCLE(maincpu_clk));
        goto fail;
    }
    vic.raster_cycle = (unsigned int)b;

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    if (w != VIC_RASTER_Y(maincpu_clk)) {
          log_error(vic.log, "Raster line value (%d) incorrect; should be %d.",
                    (int)w, VIC_RASTER_Y(maincpu_clk));
        goto fail;
    }

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    vic.area = (vic_area_state_t)w;

    if (SMR_W(m, &w) < 0) {
        goto fail;
    }
    vic.fetch_state = (vic_fetch_state_t)w;

    if (0
        || (SMR_DW_UINT(m, &vic.raster_line) < 0)
        || (SMR_DW_UINT(m, &vic.text_cols) < 0)
        || (SMR_DW_UINT(m, &vic.text_lines) < 0)
        || (SMR_DW_UINT(m, &vic.pending_text_cols) < 0)
        || (SMR_DW_UINT(m, &vic.line_was_blank) < 0)
        || (SMR_DW_UINT(m, &vic.memptr) < 0)
        || (SMR_DW_UINT(m, &vic.memptr_inc) < 0)
        || (SMR_DW_UINT(m, &vic.row_counter) < 0)
        || (SMR_DW_UINT(m, &vic.buf_offset) < 0)
        || SMR_B_INT(m, &vic.light_pen.state) < 0
        || SMR_B_INT(m, &vic.light_pen.triggered) < 0
        || SMR_DW_INT(m, &vic.light_pen.x) < 0
        || SMR_DW_INT(m, &vic.light_pen.y) < 0
        || SMR_DW_INT(m, &vic.light_pen.x_extra_bits) < 0
        || SMR_DW(m, &vic.light_pen.trigger_cycle) < 0
        || (SMR_B(m, &vic.vbuf) < 0)) {
        goto fail;
    }

    /* Color RAM.  */
    if (SMR_BA(m, mem_ram + 0x9400, 0x400) < 0) {
        goto fail;
    }

    for (i = 0; i < 0x10; i++) {
        if (SMR_B(m, &b) < 0) {
            goto fail;
        }

        /* XXX: This assumes that there are no side effects.  */
        vic_store(i, b);
    }

    raster_force_repaint(&vic.raster);
    return snapshot_module_close(m);

fail:
    if (m != NULL)
        snapshot_module_close(m);
    return -1;
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
bool inhibit_loadfade = false;
bool error = false;
bool freshstart;
	
	SetLogFilename("debug.txt");
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
	{
		staterr("ack, sdl_init failed: %s.", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);
	
	// start up inputs first thing because settings_load may remap them
	input_init();
	
	// load settings, or at least get the defaults,
	// so we know the initial screen resolution.
	settings_load();
	
	if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; }
	if (font_init()) { staterr("Failed to load font."); return 1; }
	
	//speed_test();
	//return 1;
	
	#ifdef CONFIG_DATA_EXTRACTOR
	if (!settings->files_extracted)
	{
		if (extract_main())
		{
			Graphics::close();
			font_close();
			return 0;
		}
		else
		{
			settings->files_extracted = true;
			settings_save();
		}
	}
	#endif
	
	if (check_data_exists())
	{
		return 1;
	}
	
	Graphics::ShowLoadingScreen();
	if (sound_init()) { fatal("Failed to initialize sound."); return 1; }
	if (trig_init()) { fatal("Failed trig module init."); return 1; }
	
	if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; }
	if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; }
	if (Carets::init()) { fatal("Failed to initialize carets."); return 1; }
	
	if (game.init()) return 1;
	game.setmode(GM_NORMAL);
	// set null stage just to have something to do while we go to intro
	game.switchstage.mapno = 0;
	
	//#define REPLAY
	#ifdef REPLAY
		game.switchstage.mapno = START_REPLAY;
		//Replay::set_ffwd(6000);
		//Replay::set_stopat(3500);
		game.switchstage.param = 1;
	#else
		//game.switchstage.mapno = LOAD_GAME;
		//game.pause(GP_OPTIONS);
		
		if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot)))
			game.switchstage.mapno = LOAD_GAME;
		else
			game.setmode(GM_INTRO);
	#endif
	
	// for debug
	if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; }
	if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true;
	
	game.running = true;
	freshstart = true;
	
	stat("Entering main loop...");
	#ifdef __SDLSHIM__
		set_console_visible(false);
	#endif
	
	//speed_test();
	//return 1;
	
	while(game.running)
	{
		// SSS/SPS persists across stage transitions until explicitly
		// stopped, or you die & reload. It seems a bit risky to me,
		// but that's the spec.
		if (game.switchstage.mapno >= MAPNO_SPECIALS)
		{
			StopLoopSounds();
		}
		
		// enter next stage, whatever it may be
		if (game.switchstage.mapno == LOAD_GAME || \
			game.switchstage.mapno == LOAD_GAME_FROM_MENU)
		{
			if (game.switchstage.mapno == LOAD_GAME_FROM_MENU)
				freshstart = true;
			
			stat("= Loading game =");
			if (game_load(settings->last_save_slot))
			{
				fatal("savefile error");
				goto ingame_error;
			}
			
			Replay::OnGameStarting();
			
			if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER);
			else inhibit_loadfade = false;
		}
		else if (game.switchstage.mapno == START_REPLAY)
		{
			stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param));
			
			StopScripts();
			if (Replay::begin_playback(GetReplayName(game.switchstage.param)))
			{
				fatal("error starting playback");
				goto ingame_error;
			}
		}
		else
		{
			if (game.switchstage.mapno == NEW_GAME || \
				game.switchstage.mapno == NEW_GAME_FROM_MENU)
			{
				bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU);
				InitNewGame(show_intro);
			}
			
			// slide weapon bar on first intro to Start Point
			if (game.switchstage.mapno == STAGE_START_POINT && \
				game.switchstage.eventonentry == 91)
			{
				freshstart = true;
			}
			
			// switch maps
			if (load_stage(game.switchstage.mapno)) goto ingame_error;
			
			player->x = (game.switchstage.playerx * TILE_W) << CSF;
			player->y = (game.switchstage.playery * TILE_H) << CSF;
		}
		
		// start the level
		if (game.initlevel()) return 1;
		
		if (freshstart)
			weapon_introslide();
		
		gameloop();
		game.stageboss.OnMapExit();
		freshstart = false;
	}
	
shutdown: ;
	Replay::close();
	game.close();
	Carets::close();
	
	Graphics::close();
	input_close();
	font_close();
	sound_close();
	tsc_close();
	textbox.Deinit();
	return error;
	
ingame_error: ;
	stat("");
	stat(" ************************************************");
	stat(" * An in-game error occurred. Game shutting down.");
	stat(" ************************************************");
	error = true;
	goto shutdown;
}
Exemplo n.º 12
0
void machine_shutdown(void)
{
    file_system_detach_disk_shutdown();

    machine_specific_shutdown();

    autostart_shutdown();

#ifdef HAS_JOYSTICK
    joystick_close();
#endif

    sound_close();

    printer_shutdown();
    gfxoutput_shutdown();

    fliplist_shutdown();
    file_system_shutdown();
    fsdevice_shutdown();

    tape_shutdown();

    traps_shutdown();

    kbdbuf_shutdown();
    keyboard_shutdown();

    monitor_shutdown();

    console_close_all();

    cmdline_shutdown();

    resources_shutdown();

    drive_shutdown();

    machine_maincpu_shutdown();

    video_shutdown();

    ui_shutdown();

    sysfile_shutdown();

    log_close_all();

    event_shutdown();

    network_shutdown();

    autostart_resources_shutdown();
    fsdevice_resources_shutdown();
    disk_image_resources_shutdown();
    machine_resources_shutdown();
    sysfile_resources_shutdown();
    zfile_shutdown();
    ui_resources_shutdown();
    log_resources_shutdown();
    fliplist_resources_shutdown();
    romset_resources_shutdown();
#ifdef HAVE_NETWORK
    monitor_network_resources_shutdown();
#endif
    archdep_shutdown();

    lib_debug_check();
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
    int     wpm  = WPM;
    int     freq = FREQ;
    int     rate = RATE;
    int     ampl = AMPL;
    int     atta = ATTA;
    int     deca = DECA;

    /* Get any optional command line args (start with -) */
    while (argc > 1 && *argv[1] == '-') {
        if (!strcmp(argv[1], "-w")) { 
            wpm = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-o")) {
            if (!strcmp(argv[2], "alsa"))
                outp = ALSA;
            else if (!strcmp(argv[2], "dsp"))
                outp = DSP;
            else if (!strcmp(argv[2], "alsa"))
                outp = STDOUT;
            else
                outp = 0;
        }
        if (!strcmp(argv[1], "-f")) { 
            freq = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-r")) { 
            rate = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-a")) { 
            ampl = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-da")) { 
            atta = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-dd")) { 
            deca = atoi(argv[2]); 
        }
        if (!strcmp(argv[1], "-h")) { 
            fprintf(stderr, usage, MAXTONES);
            return -1;
        }
        if (!strcmp(argv[1], "-v")) { 
            verbose = 1; 
            ++argc;     /* Offset for lack of value */
            --argv;     /* Needs to be last test!   */
        }
        argc -= 2;
        argv += 2;
    }

    /* Make sure we have more following */
    if (!(argc > 1)) {
        fprintf(stderr, "No text given\n");
        return -1;
    }

    /* Sanity check of values */
    if (wpm < MINWPM || wpm > MAXWPM) {
        fprintf(stderr, "Support %d to %d word per minute range\n",
                MINWPM, MAXWPM);
        return -1;
    }
    if (outp < 1) {
        fprintf(stderr, "Output format needs to be alsa, dsp, or stdout\n");
        return -1;
    }
    if (rate < 2 * freq) {
        fprintf(stderr, "Sample rate must be more then twice the frequency\n");
        return -1;
    }
    if (freq < MINFREQ || freq > MAXFREQ) {
        fprintf(stderr, "Support %d to %d Hz frequency range\n",
                MINFREQ, MAXFREQ);
        return -1;
    }
    if (rate < MINRATE || rate > MAXRATE) {
        fprintf(stderr, "Support %d to %d samples per second\n",
                MINRATE, MAXRATE);
        return -1;
    }
    if (ampl < MINAMPL || ampl > MAXAMPL) {
        fprintf(stderr, "Support %d to %d amplitude\n", MINAMPL, MAXAMPL);
        return -1;
    }

    /* Generate waveforms */
    if (mktones(wpm, freq, rate, ampl, atta, deca)) {
        return -1;
    }

    /* Setup DSP device */
    sound_open(outp);
    sound_setup(rate, outp);

    if (verbose) fprintf(stderr, "Morse code: "); 

    /* Disect remaining argv into letters */
    while (argc > 1) {
        text2code(argv[1]);
        argc--;
        argv++;
    }

    if (verbose) fprintf(stderr, "\n"); 

    /* Exit clean */
    free(ditbf);
    free(dahbf);
    free(sgapbf);
    free(lgapbf);
    sound_close(outp);
    return 0;
}