lcd: prevent from using a scale level that isn't actually supported
[rofl0r-gnuboy.git] / emu.c
blobbc015f02c779c7c380394af450857c9740549904
4 #include "defs.h"
5 #include "regs.h"
6 #include "hw.h"
7 #include "cpu.h"
8 #include "mem.h"
9 #include "lcd.h"
10 #include "rc.h"
11 #include "rtc.h"
12 #include "sys.h"
13 #include "sound.h"
14 #include "cpu.h"
17 static int framelen = 16743;
18 static int framecount;
20 rcvar_t emu_exports[] =
22 RCV_INT("framelen", &framelen),
23 RCV_INT("framecount", &framecount),
24 RCV_END
33 void emu_init()
40 * emu_reset is called to initialize the state of the emulated
41 * system. It should set cpu registers, hardware registers, etc. to
42 * their appropriate values at powerup time.
45 void emu_reset()
47 hw_reset();
48 lcd_reset();
49 cpu_reset();
50 mbc_reset();
51 sound_reset();
58 void emu_step()
60 cpu_emulate(cpu.lcdc);
65 /* This mess needs to be moved to another module; it's just here to
66 * make things work in the mean time. */
68 void *sys_timer();
70 void emu_run()
72 void *timer = sys_timer();
73 int delay;
75 vid_begin();
76 lcd_begin();
77 for (;;)
79 cpu_emulate(2280);
80 while (R_LY > 0 && R_LY < 144)
81 emu_step();
83 vid_end();
84 rtc_tick();
85 sound_mix();
86 if (!pcm_submit())
88 delay = framelen - sys_elapsed(timer);
89 sys_sleep(delay);
90 sys_elapsed(timer);
92 doevents();
93 vid_begin();
94 if (framecount) { if (!--framecount) die("finished\n"); }
96 if (!(R_LCDC & 0x80))
97 cpu_emulate(32832);
99 while (R_LY > 0) /* wait for next frame */
100 emu_step();