new plugin: FS#10559 - lrcplayer: a plugin to view .lrc file.
[kugel-rb.git] / apps / plugins / rockboy / emu.c
blob57b82cfbb199fe65f68786b0ee40b9637376cfa0
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"
13 * emu_reset is called to initialize the state of the emulated
14 * system. It should set cpu registers, hardware registers, etc. to
15 * their appropriate values at powerup time.
18 void emu_reset(void)
20 hw_reset();
21 lcd_reset();
22 cpu_reset();
23 mbc_reset();
24 sound_reset();
27 static void emu_step(void)
29 cpu_emulate(cpu.lcdc);
32 /* This mess needs to be moved to another module; it's just here to
33 * make things work in the mean time. */
34 void emu_run(void)
36 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
38 setvidmode();
39 vid_begin();
40 lcd_begin();
41 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
42 rb->cpu_boost(true);
43 #endif
44 #ifdef HAVE_LCD_COLOR
45 set_pal();
46 #endif
48 while(!shut)
50 cpu_emulate(2280);
51 while (R_LY > 0 && R_LY < 144)
52 emu_step();
54 rtc_tick();
56 if (options.sound || !plugbuf)
58 sound_mix();
59 rockboy_pcm_submit();
62 doevents();
63 vid_begin();
65 if (!(R_LCDC & 0x80))
66 cpu_emulate(32832);
68 while (R_LY > 0) /* wait for next frame */
70 emu_step();
71 rb->yield();
74 frames++;
75 framesin++;
77 if(*rb->current_tick-timeten>=10)
79 timeten=*rb->current_tick;
80 if(framesin<6) options.frameskip++;
81 if(framesin>6) options.frameskip--;
82 if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
83 if(options.frameskip<0) options.frameskip=0;
84 framesin=0;
87 if(options.showstats)
88 if(*rb->current_tick-timehun>=100)
90 options.fps=frames;
91 frames=0;
92 timehun=*rb->current_tick;
96 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
97 rb->cpu_boost(false);
98 #endif