gnuboy: initial 1.0.3 import (last official release)
[rofl0r-gnuboy.git] / emu.c
blob544526d02174f823f811f07d7d4e2343791910e5
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"
13 static int framelen = 16743;
14 static int framecount;
16 rcvar_t emu_exports[] =
18 RCV_INT("framelen", &framelen),
19 RCV_INT("framecount", &framecount),
20 RCV_END
29 void emu_init()
36 * emu_reset is called to initialize the state of the emulated
37 * system. It should set cpu registers, hardware registers, etc. to
38 * their appropriate values at powerup time.
41 void emu_reset()
43 hw_reset();
44 lcd_reset();
45 cpu_reset();
46 mbc_reset();
47 sound_reset();
54 void emu_step()
56 cpu_emulate(cpu.lcdc);
61 /* This mess needs to be moved to another module; it's just here to
62 * make things work in the mean time. */
64 void *sys_timer();
66 void emu_run()
68 void *timer = sys_timer();
69 int delay;
71 vid_begin();
72 lcd_begin();
73 for (;;)
75 cpu_emulate(2280);
76 while (R_LY > 0 && R_LY < 144)
77 emu_step();
79 vid_end();
80 rtc_tick();
81 sound_mix();
82 if (!pcm_submit())
84 delay = framelen - sys_elapsed(timer);
85 sys_sleep(delay);
86 sys_elapsed(timer);
88 doevents();
89 vid_begin();
90 if (framecount) { if (!--framecount) die("finished\n"); }
92 if (!(R_LCDC & 0x80))
93 cpu_emulate(32832);
95 while (R_LY > 0) /* wait for next frame */
96 emu_step();