Minor corrections to the .colours file editing; added .colours to the list of support...
[kugel-rb.git] / apps / plugins / rockboy / emu.c
blob8b75211ab048619887eeab53702e7cdc5a1fe36e
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
45 while(!shut)
47 cpu_emulate(2280);
48 while (R_LY > 0 && R_LY < 144)
49 emu_step();
51 rtc_tick();
53 if (options.sound || !plugbuf)
55 sound_mix();
56 pcm_submit();
59 doevents();
60 vid_begin();
62 if (!(R_LCDC & 0x80))
63 cpu_emulate(32832);
65 while (R_LY > 0) /* wait for next frame */
67 emu_step();
68 rb->yield();
71 frames++;
72 framesin++;
74 if(*rb->current_tick-timeten>=10)
76 timeten=*rb->current_tick;
77 if(framesin<6) options.frameskip++;
78 if(framesin>6) options.frameskip--;
79 if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
80 if(options.frameskip<0) options.frameskip=0;
81 framesin=0;
84 if(options.showstats)
85 if(*rb->current_tick-timehun>=100)
87 options.fps=frames;
88 frames=0;
89 timehun=*rb->current_tick;
93 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
94 rb->cpu_boost(false);
95 #endif