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 "rc.h"
|
|
|
|
#include "sound.h"
|
2005-07-03 14:05:12 +00:00
|
|
|
#include "rtc-gb.h"
|
2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
static int framelen = 16743;
|
|
|
|
static int framecount;
|
|
|
|
|
|
|
|
rcvar_t emu_exports[] =
|
|
|
|
{
|
|
|
|
RCV_INT("framelen", &framelen),
|
|
|
|
RCV_INT("framecount", &framecount),
|
|
|
|
RCV_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void emu_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
hw_reset();
|
|
|
|
lcd_reset();
|
|
|
|
cpu_reset();
|
|
|
|
mbc_reset();
|
|
|
|
sound_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void emu_step(void)
|
|
|
|
{
|
|
|
|
cpu_emulate(cpu.lcdc);
|
|
|
|
}
|
|
|
|
|
2006-01-20 13:05:52 +00:00
|
|
|
struct options options;
|
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. */
|
2006-01-20 13:05:52 +00:00
|
|
|
//extern struct plugin_api* rb;
|
2005-03-02 23:49:38 +00:00
|
|
|
void emu_run(void)
|
|
|
|
{
|
2006-01-20 13:05:52 +00:00
|
|
|
// void *timer = sys_timer();
|
|
|
|
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
|
|
|
|
// int delay;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
vid_begin();
|
|
|
|
lcd_begin();
|
2005-03-03 13:11:45 +00:00
|
|
|
#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
|
|
|
|
rb->cpu_boost(true);
|
|
|
|
#endif
|
2006-01-10 21:55:56 +00:00
|
|
|
while(!shut)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
|
|
|
cpu_emulate(2280);
|
|
|
|
while (R_LY > 0 && R_LY < 144)
|
|
|
|
emu_step();
|
|
|
|
|
|
|
|
rtc_tick();
|
|
|
|
sound_mix();
|
|
|
|
if (!pcm_submit())
|
|
|
|
{
|
2006-01-20 13:05:52 +00:00
|
|
|
/* delay = framelen - sys_elapsed(timer);
|
2005-03-02 23:49:38 +00:00
|
|
|
sys_sleep(delay);
|
2006-01-20 13:05:52 +00:00
|
|
|
sys_elapsed(timer);*/
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
2005-03-02 23:49:38 +00:00
|
|
|
doevents();
|
|
|
|
vid_begin();
|
|
|
|
|
|
|
|
if (!(R_LCDC & 0x80))
|
|
|
|
cpu_emulate(32832);
|
|
|
|
|
|
|
|
while (R_LY > 0) /* wait for next frame */
|
|
|
|
emu_step();
|
|
|
|
rb->yield();
|
2006-01-20 13:05:52 +00:00
|
|
|
|
|
|
|
frames++;
|
|
|
|
framesin++;
|
|
|
|
|
|
|
|
if(*rb->current_tick-timeten>=20)
|
|
|
|
{
|
|
|
|
timeten=*rb->current_tick;
|
|
|
|
if(framesin<12) options.frameskip++;
|
|
|
|
if(framesin>12) options.frameskip--;
|
|
|
|
if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
|
|
|
|
if(options.frameskip<0) options.frameskip=0;
|
|
|
|
framesin=0;
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
2006-01-20 13:05:52 +00:00
|
|
|
|
|
|
|
if(options.showstats)
|
|
|
|
{
|
|
|
|
if(*rb->current_tick-timehun>=100) {
|
|
|
|
options.fps=frames;
|
|
|
|
frames=0;
|
|
|
|
timehun=*rb->current_tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-03 13:11:45 +00:00
|
|
|
#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|