Exemplo n.º 1
0
int init_sdl_audio(void)
{
	if (sound_initialize==GN_TRUE)
		close_sdl_audio();
	sound_initialize=GN_TRUE;
    SDL_InitSubSystem(SDL_INIT_AUDIO);

    desired = (SDL_AudioSpec *) malloc(sizeof(SDL_AudioSpec));
    obtain = (SDL_AudioSpec *) malloc(sizeof(SDL_AudioSpec));
    audio_sample_rate = conf.sample_rate;
    desired->freq = conf.sample_rate;
    desired->samples = NB_SAMPLES;
    
#ifdef WORDS_BIGENDIAN
    desired->format = AUDIO_S16MSB;
#else	/* */
    desired->format = AUDIO_S16;
#endif	/* */
    desired->channels = 2;
    desired->callback = update_sdl_stream;
	 
	//desired->callback = NULL;
    desired->userdata = NULL;
    //SDL_OpenAudio(desired, NULL);
    SDL_OpenAudio(desired, obtain);
    printf("Obtained sample rate: %d\n",obtain->freq);
    conf.sample_rate=obtain->freq;
    return GN_TRUE;
}
Exemplo n.º 2
0
/* sound */
static int toggle_sound(CHECK_BUTTON *self) {
    if (conf.sound) {
	conf.sound=0;
	close_sdl_audio();
    } else {
	conf.sound=1;
	init_sdl_audio();
    }
    return TAKE_EVENT;
}
Exemplo n.º 3
0
SDL_bool init_game(char *rom_name) {
    DRIVER *dr;
    char *drconf,*gpath;
    dr=dr_get_by_name(rom_name);
    if (!dr) {
#ifdef USE_GUI
	gui_error_box(20,80,264,60,
		      "Error!","No valid romset found for\n%s\n",
		      file_basename(rom_name));
#else
	printf("No valid romset found for %s\n",rom_name);
#endif
	return SDL_FALSE;
    }

    if (conf.game!=NULL) {
	save_nvram(conf.game);
	if (conf.sound) {
	    close_sdl_audio();
	    YM2610_sh_stop();
	    streams_sh_stop();
	}
	free_game_memory();
    }


    /* open transpack if need */
    trans_pack_open(CF_STR(cf_get_item_by_name("transpack")));

    //open_rom(rom_name);
    if (dr_load_game(dr,rom_name)==SDL_FALSE) {
#ifdef USE_GUI
	gui_error_box(20,80,264,60,
		      "Error!","Couldn't load\n%s\n",
		      file_basename(rom_name));
#else
	printf("Can't load %s\n",rom_name);
#endif
	return SDL_FALSE;
    }
    /* per game config */
    gpath=get_gngeo_dir();
    drconf=alloca(strlen(gpath)+strlen(dr->name)+strlen(".cf")+1);
    sprintf(drconf,"%s%s.cf",gpath,dr->name);
    cf_open_file(drconf);
    open_bios();
    open_nvram(conf.game);
    init_sdl();
    sdl_set_title(conf.game);
    init_neo(conf.game);
    if (conf.sound) 
	init_sdl_audio();
    return SDL_TRUE;
}
Exemplo n.º 4
0
static void gngeo_quit(void) {
    if (conf.sound)
	close_sdl_audio();
}
Exemplo n.º 5
0
bool load_state(char *game,int slot) {
    char *st_name;
//    char *st_name_len;
	char *gngeo_dir=DATA_DIRECTORY"/save/";

#ifdef WORDS_BIGENDIAN
    Uint8  my_endian=1;
#else
    Uint8  my_endian=0;
#endif

    int i;
    gzFile *gzf;
    char string[20];
    Uint8 a,num;
    ST_DATA_TYPE type;
    void *data;
    Uint32 len;

    Uint8  endian;
    Uint32 rate;

    st_name=(char*)alloca(strlen(gngeo_dir)+strlen(game)+5);
    sprintf(st_name,"%s%s.%03d",gngeo_dir,game,slot);

    if ((gzf=gzopen(st_name,"rb"))==NULL) {
		printf("%s not found\n",st_name);
		return false;
    }

    memset(string,0,20);
    gzread(gzf,string,6);

    if (strcmp(string,"GNGST1")) {
		printf("%s is not a valid gngeo st file\n",st_name);
		gzclose(gzf);
		return false; 
    }


    gzread(gzf,&endian,1);

    if (my_endian!=endian) {
		printf("This save state comme from a different endian architecture.\n"
		       "This is not currently supported :(\n");
		return false;
    }

    gzread(gzf,&rate,4);
    swap_buf32_if_need(endian,&rate,1);


    if (rate==0 && conf.sound) {
		/* disable sound */
		conf.sound=0;
		SDL_PauseAudio(1);
		close_sdl_audio();
    } else if (rate!=0 && conf.sound==0) {
		/* enable sound */
		conf.sound=1;
		conf.sample_rate=rate;
		if (!conf.snd_st_reg_create) {
		    cpu_z80_init();
		    init_sdl_audio();
		    streams_sh_start();
		    YM2610_sh_start();
		    conf.snd_st_reg_create=1;
		} else 
		    init_sdl_audio();
		SDL_PauseAudio(0);
    } else if (rate!=conf.sample_rate && conf.sound) {
		conf.sample_rate=rate;
		close_sdl_audio();
		init_sdl_audio();
    }

    gzread(gzf,state_img->pixels,304*224*2);
    swap_buf16_if_need(endian,state_img->pixels,304*224);

    

    while(!gzeof(gzf)) {
	gzread(gzf,&a,1); /* name size */
	memset(string,0,20);
	gzread(gzf,string,a); /* regname */
	gzread(gzf,&num,1); /* regname num */
	gzread(gzf,&a,1); /* module id */
	gzread(gzf,&len,4);
	gzread(gzf,&type,1);
	data=find_data_by_name(a,num,string);
	if (data) {
	    gzread(gzf,data,len);
	    switch(type) {
	    case REG_UINT16:
	    case REG_INT16:
		swap_buf16_if_need(endian,data,len>>1);
		break;
	    case REG_UINT32:
	    case REG_INT32:
		swap_buf32_if_need(endian,data,len>>2);
		break;
	    case REG_INT8:
	    case REG_UINT8:
		/* nothing */
		break;
	    }
	} else {
	    /* unknow reg, ignore it*/
	    printf("skeeping unknow reg %s\n",string);
	    gzseek(gzf,len,SEEK_CUR);
	}
    
    
	// /*if (a==ST_68k)*/ printf("LO %02d %20s %02x %08x \n",a,string,num,len/*,*(Uint32*)data*/);
    }