2005-03-02 23:49:38 +00:00
|
|
|
#include "rockmacros.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "regs.h"
|
|
|
|
#include "hw.h"
|
2005-07-03 14:05:12 +00:00
|
|
|
#include "cpu-gb.h"
|
2005-03-02 23:49:38 +00:00
|
|
|
#include "mem.h"
|
2005-07-03 14:05:12 +00:00
|
|
|
#include "lcd-gb.h"
|
2005-03-02 23:49:38 +00:00
|
|
|
#include "sound.h"
|
2005-07-03 14:05:12 +00:00
|
|
|
#include "rtc-gb.h"
|
2007-10-16 18:16:22 +00:00
|
|
|
#include "pcm.h"
|
2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* emu_reset is called to initialize the state of the emulated
|
|
|
|
* system. It should set cpu registers, hardware registers, etc. to
|
|
|
|
* their appropriate values at powerup time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void emu_reset(void)
|
|
|
|
{
|
2006-06-19 01:47:45 +00:00
|
|
|
hw_reset();
|
|
|
|
lcd_reset();
|
|
|
|
cpu_reset();
|
|
|
|
mbc_reset();
|
|
|
|
sound_reset();
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 18:16:22 +00:00
|
|
|
static void emu_step(void)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2006-06-19 01:47:45 +00:00
|
|
|
cpu_emulate(cpu.lcdc);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This mess needs to be moved to another module; it's just here to
|
|
|
|
* make things work in the mean time. */
|
|
|
|
void emu_run(void)
|
|
|
|
{
|
2006-06-19 01:47:45 +00:00
|
|
|
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
2007-06-24 16:00:55 +00:00
|
|
|
setvidmode();
|
2006-06-19 01:47:45 +00:00
|
|
|
vid_begin();
|
|
|
|
lcd_begin();
|
2006-04-09 15:00:30 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2006-06-19 01:47:45 +00:00
|
|
|
rb->cpu_boost(true);
|
2005-03-03 13:11:45 +00:00
|
|
|
#endif
|
2009-08-09 03:35:53 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-08-09 03:20:55 +00:00
|
|
|
set_pal();
|
2009-08-09 03:35:53 +00:00
|
|
|
#endif
|
2007-04-18 07:41:31 +00:00
|
|
|
|
2006-06-19 01:47:45 +00:00
|
|
|
while(!shut)
|
|
|
|
{
|
|
|
|
cpu_emulate(2280);
|
|
|
|
while (R_LY > 0 && R_LY < 144)
|
|
|
|
emu_step();
|
|
|
|
|
2007-07-30 05:19:05 +00:00
|
|
|
rtc_tick();
|
2007-06-24 16:00:55 +00:00
|
|
|
|
|
|
|
if (options.sound || !plugbuf)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
sound_mix();
|
2007-06-24 16:00:55 +00:00
|
|
|
pcm_submit();
|
|
|
|
}
|
2007-04-18 07:41:31 +00:00
|
|
|
|
2006-06-19 01:47:45 +00:00
|
|
|
doevents();
|
|
|
|
vid_begin();
|
2007-04-18 07:41:31 +00:00
|
|
|
|
2006-06-19 01:47:45 +00:00
|
|
|
if (!(R_LCDC & 0x80))
|
|
|
|
cpu_emulate(32832);
|
2007-02-06 21:41:08 +00:00
|
|
|
|
2006-06-19 01:47:45 +00:00
|
|
|
while (R_LY > 0) /* wait for next frame */
|
2007-02-06 21:41:08 +00:00
|
|
|
{
|
2006-06-19 01:47:45 +00:00
|
|
|
emu_step();
|
2007-02-06 21:41:08 +00:00
|
|
|
rb->yield();
|
|
|
|
}
|
2006-06-19 01:47:45 +00:00
|
|
|
|
|
|
|
frames++;
|
|
|
|
framesin++;
|
|
|
|
|
2007-04-18 07:41:31 +00:00
|
|
|
if(*rb->current_tick-timeten>=10)
|
2006-06-19 01:47:45 +00:00
|
|
|
{
|
|
|
|
timeten=*rb->current_tick;
|
2007-04-18 07:41:31 +00:00
|
|
|
if(framesin<6) options.frameskip++;
|
|
|
|
if(framesin>6) options.frameskip--;
|
2006-06-19 01:47:45 +00:00
|
|
|
if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
|
|
|
|
if(options.frameskip<0) options.frameskip=0;
|
|
|
|
framesin=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(options.showstats)
|
|
|
|
if(*rb->current_tick-timehun>=100)
|
|
|
|
{
|
|
|
|
options.fps=frames;
|
|
|
|
frames=0;
|
|
|
|
timehun=*rb->current_tick;
|
|
|
|
}
|
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
2006-04-09 15:00:30 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2005-03-03 13:11:45 +00:00
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|