コード例 #1
0
ファイル: emu.c プロジェクト: geekmaster/fbgnuboy
void emu_run()
{
	void *timer = sys_timer();
	int delay;

	vid_begin();
	lcd_begin();
	for (;;)
	{
		cpu_emulate(2280);
		while (R_LY > 0 && R_LY < 144)
			emu_step();
		
		vid_end();
		rtc_tick();
		sound_mix();
		if (!pcm_submit())
		{
			delay = framelen - sys_elapsed(timer);
			sys_sleep(delay);
			sys_elapsed(timer);
		}
		doevents();
		vid_begin();
		if (framecount) { if (!--framecount) die("finished\n"); }
		
		if (!(R_LCDC & 0x80))
			cpu_emulate(32832);
		
		while (R_LY > 0) /* wait for next frame */
			emu_step();
	}
}
コード例 #2
0
ファイル: emu.c プロジェクト: animehunter/pokemon-bot
/*
	Time intervals throughout the code, unless otherwise noted, are
	specified in double-speed machine cycles (2MHz), each unit
	roughly corresponds to 0.477us.
	
	For CPU each cycle takes 2dsc (0.954us) in single-speed mode
	and 1dsc (0.477us) in double speed mode.
	
	Although hardware gbc LCDC would operate at completely different
	and fixed frequency, for emulation purposes timings for it are
	also specified in double-speed cycles.
	
	line = 228 dsc (109us)
	frame (154 lines) = 35112 dsc (16.7ms)
	of which
		visible lines x144 = 32832 dsc (15.66ms)
		vblank lines x10 = 2280 dsc (1.08ms)
*/
void emu_run()
{
	void *timer = sys_timer();
	int delay;

	vid_begin();
	lcd_begin();
	for (;;)
	{
		/* FRAME BEGIN */
		
		/* FIXME: djudging by the time specified this was intended
		to emulate through vblank phase which is handled at the
		end of the loop. */
		cpu_emulate(2280);
		
		/* FIXME: R_LY >= 0; comparsion to zero can also be removed
		altogether, R_LY is always 0 at this point */
		while (R_LY > 0 && R_LY < 144)
		{
			/* Step through visible line scanning phase */
			emu_step();
		}
		
		/* VBLANK BEGIN */
		
		vid_end();
		rtc_tick();
		sound_mix();
		/* pcm_submit() introduces delay, if it fails we use
		sys_sleep() instead */
		if (!pcm_submit())
		{
			delay = framelen - sys_elapsed(timer);
			sys_sleep(delay);
			sys_elapsed(timer);
		}
		doevents();
		vid_begin();
		if (framecount) { if (!--framecount) die("finished\n"); }
		
		if (!(R_LCDC & 0x80)) {
			/* LCDC operation stopped */
			/* FIXME: djudging by the time specified, this is
			intended to emulate through visible line scanning
			phase, even though we are already at vblank here */
			cpu_emulate(32832);
		}
		
		while (R_LY > 0) {
			/* Step through vblank phase */
			emu_step();
		}
		/* VBLANK END */
		/* FRAME END */
	}
}
コード例 #3
0
ファイル: bitbox_emu.c プロジェクト: makapuf/bitboy
//	void *timer = sys_timer();
//	int delay;
void emu_frame(void)
{
	/* FRAME BEGIN */
	
	/* FIXME: djudging by the time specified this was intended
	to emulate through vblank phase which is handled at the
	end of the loop. */
	cpu_emulate(2280);
	
	/* FIXME: R_LY >= 0; comparsion to zero can also be removed
	altogether, R_LY is always 0 at this point */
	while (R_LY > 0 && R_LY < 144)
	{
		/* Step through visible line scanning phase */
		emu_step();
	}
	
	/* VBLANK BEGIN */

	vid_end();
	rtc_tick();
	sound_mix();
	pcm_submit();

	/* pcm_submit() introduces delay, if it fails we use
	sys_sleep() instead */
	/* timebase is exclusively done with pcm submit. we shall sync with LCD ! 
	if (!pcm_submit())
	{
		delay = framelen - sys_elapsed(timer);
		sys_sleep(delay);
		sys_elapsed(timer);
	}*/
	// doevents(); // does not handle extra events
	gamepad_poll();
	vid_begin();
	
	if (!(R_LCDC & 0x80)) {
		/* LCDC operation stopped */
		/* FIXME: djudging by the time specified, this is
		intended to emulate through visible line scanning
		phase, even though we are already at vblank here */
		cpu_emulate(32832);
	}
	
	while (R_LY > 0) {
		/* Step through vblank phase */
		emu_step();
	}
	/* VBLANK END */
	/* FRAME END */


}
コード例 #4
0
ファイル: emu.c プロジェクト: milot-mirdita/PocketGnuBoy
void emu_do_frame()
{
        vid_start_frame();
        vid_begin();
        cpu_emulate();
        vid_end();
        joy_process();
        rtc_tick();
        sound_mix();
        pcm_submit();

        vid_end_frame();
}
コード例 #5
0
ファイル: app_iPhone.c プロジェクト: Garrant3/gameboy4iphone
static void AQBufferCallback(
    void *in,
    AudioQueueRef inQ,
    AudioQueueBufferRef outQB)
{
    AQCallbackStruct * inData;
    short *coreAudioBuffer;
    inData = (AQCallbackStruct *)in;
    coreAudioBuffer = (short*) outQB->mAudioData;

	if (inData->frameCount > 0) {
		AudioQueueSetParameter(inQ, kAudioQueueParam_Volume, __audioVolume);	
		sound_mix(coreAudioBuffer, (inData->frameCount * 4) / 2);
        outQB->mAudioDataByteSize = inData->frameCount * 4; //(inData->frameCount * 4 < (sndOutLen) ? inData->frameCount * 4 : (sndOutLen));
        AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
    }
}
コード例 #6
0
ファイル: audio.c プロジェクト: mrzzzrm/mooboy
static void handout_buf(void *_unused, Uint8 *stream, int length) {
    u16 requested_samples = length / (sys.sound_sample_size * 2);
    u16 available_samples;
    u16 served_samples;

    sys_lock_audiobuf();

    if(!sys.sound_on || (~moo.state & MOO_ROM_RUNNING_BIT)) {
        memset(stream, 0x00, length);
    }
    else {
#ifdef DEBUG
        if(get_available_samples() < requested_samples) {
      //      printf("WARNING: Sound buffer underrun\n");
        }
#endif

        while((available_samples = get_available_samples()) < requested_samples) {
            sound_mix();
        }

        if(sys.sound_buf_start > sys.sound_buf_end) {
            served_samples = sys.sound_buf_size - sys.sound_buf_start;
            if(served_samples >= requested_samples) {
                memcpy(stream, &sys.sound_buf[sys.sound_buf_start*2*2], length);
            }
            else {
                u16 bytes = served_samples * sys.sound_sample_size * 2;
                memcpy(&stream[0], &sys.sound_buf[sys.sound_buf_start*2*2], bytes);
                memcpy(&stream[bytes], &sys.sound_buf[0], (requested_samples - served_samples) * sys.sound_sample_size * 2);
            }
        }
        else {
            memcpy(stream, &sys.sound_buf[sys.sound_buf_start*2*2], length);
        }
    }

    sys.sound_buf_start += requested_samples;
    sys.sound_buf_start %= sys.sound_buf_size;

    sys_unlock_audiobuf();
}
コード例 #7
0
ファイル: qdgdf_audio_oss.c プロジェクト: angelortega/qdgdf
static void sound_daemon(int _pipe_read)
/* sound server main loop */
{
    int n;

    n = _open_device();

    if (n) {
        /* non-blocking mode */
        n = 1;
        ioctl(_pipe_read, FIONBIO, &n);
    }

    /* no sounds */
    memset(_sounds, '\0', sizeof(_sounds));

    for (;;) {
        if ((n =
             read(_pipe_read, msg + _msg_offset,
                  sizeof(msg) - _msg_offset)) <= 0) {
            if (errno != EWOULDBLOCK)
                break;
        }
        else {
            msg[n + _msg_offset] = '\0';

            if (!parse_sound_cmd(_pipe_read, msg))
                break;
        }

        if (_daemon_seq != -1)
            sound_mix();
    }

    if (_audio_fd != -1)
        close(_audio_fd);

    close(_pipe_read);

    exit(0);
}
コード例 #8
0
ファイル: emu.c プロジェクト: ProjectZeroSlackr/iBoy
void emu_run()
{
	int delta; // too much

#ifdef MEASUREMENT
	int cur_frame=0; //mitzahlen
	int time_hs;
	void *timer;
#endif

	delta = 0;			
	lcd_begin();
	//cop_begin();

	while(emu_running)
	{

		#ifdef MEASUREMENT
		if(cur_frame==MESS_START) {
			cop_end();
			err_msg("Measuring", 100);
			err_msg("Measuring.", 100);
			err_msg("Measuring..", 100);
			err_msg("Measuring...", 100);
			cop_begin();
			timer = sys_timer();
		}
		if(cur_frame==MESS_END) {
			time_hs = sys_elapsed(timer)/10000;
			emu_running = 0;
		}
		cur_frame++;
		#endif


		#ifdef USE_DEBUG
		if(delta >= 2280)
			printf("too much %6d\n", delta);
		else if(delta < 0)
			printf("delta is negative");
		#endif
		
	
		delta = -cpu_emulate(2280 - delta);

		while (R_LY > 0 && R_LY < 144) {
			if(cpu.lcdc > delta){
				delta = -cpu_emulate(cpu.lcdc-delta);
			}
			else{
				delta -= cpu.lcdc;
			}
		}

		rtc_tick();
		sound_mix();
		pcm_submit();
		kb_poll();
	
		if (!(R_LCDC & 0x80))
			delta = -cpu_emulate(32832 - delta);

		// wait for next frame
		while (R_LY > 0)  {
			if(cpu.lcdc > delta){
				delta = -cpu_emulate(cpu.lcdc-delta);
			}
			else{
				delta -= cpu.lcdc;
			}
		}
		
		/*cpu_emulate(2280-delta);

		while (R_LY > 0 && R_LY < 144)
				delta = -cpu_emulate(cpu.lcdc);

		rtc_tick();
		sound_mix();
		pcm_submit();
		kb_poll();
	

		if (!(R_LCDC & 0x80))
			delta = -cpu_emulate(32832);

		// wait for next frame
		while (R_LY > 0)
			delta = -cpu_emulate(cpu.lcdc);*/

	}


#ifdef MEASUREMENT
		cop_end();
		err_msg("%d hs", 3000, time_hs);
		enter_menu();
#endif
}