Bump version numbers for 3.13
[maemo-rb.git] / apps / plugins / rockboy / emu.c
blob2215c810b6656358e5b29d3f5d45117fb7fd1dbf
1 #include "rockmacros.h"
2 #include "defs.h"
3 #include "regs.h"
4 #include "hw.h"
5 #include "cpu-gb.h"
6 #include "mem.h"
7 #include "lcd-gb.h"
8 #include "sound.h"
9 #include "rtc-gb.h"
10 #include "pcm.h"
11 #include "emu.h"
14 * emu_reset is called to initialize the state of the emulated
15 * system. It should set cpu registers, hardware registers, etc. to
16 * their appropriate values at powerup time.
19 void emu_reset(void)
21 hw_reset();
22 lcd_reset();
23 cpu_reset();
24 mbc_reset();
25 sound_reset();
28 static void emu_step(void)
30 cpu_emulate(cpu.lcdc);
33 /* This mess needs to be moved to another module; it's just here to
34 * make things work in the mean time. */
35 void emu_run(void)
37 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
39 setvidmode();
40 vid_begin();
41 lcd_begin();
42 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
43 rb->cpu_boost(true);
44 #endif
45 #ifdef HAVE_LCD_COLOR
46 set_pal();
47 #endif
49 while(!shut)
51 cpu_emulate(2280);
52 while (R_LY > 0 && R_LY < 144)
53 emu_step();
55 rtc_tick();
57 if (options.sound || !plugbuf)
59 sound_mix();
60 rockboy_pcm_submit();
63 doevents();
64 vid_begin();
66 if (!(R_LCDC & 0x80))
67 cpu_emulate(32832);
69 while (R_LY > 0) /* wait for next frame */
71 emu_step();
72 rb->yield();
75 frames++;
76 framesin++;
78 if(*rb->current_tick-timeten>=10)
80 timeten=*rb->current_tick;
81 if(framesin<6) options.frameskip++;
82 if(framesin>6) options.frameskip--;
83 if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
84 if(options.frameskip<0) options.frameskip=0;
85 framesin=0;
88 if(options.showstats)
89 if(*rb->current_tick-timehun>=100)
91 options.fps=frames;
92 frames=0;
93 timehun=*rb->current_tick;
97 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
98 rb->cpu_boost(false);
99 #endif