update README
[rofl0r-gnuboy.git] / emu.c
blob853852bdda9e7661f2795d87b4d016174257724e
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();
52 mem_mapbootrom();
59 void emu_step()
61 cpu_emulate(cpu.lcdc);
66 /* This mess needs to be moved to another module; it's just here to
67 * make things work in the mean time. */
69 void *sys_timer();
71 void emu_run()
73 void *timer = sys_timer();
74 int delay;
76 vid_begin();
77 lcd_begin();
78 for (;;)
80 cpu_emulate(2280);
81 while (R_LY > 0 && R_LY < 144)
82 emu_step();
84 vid_end();
85 rtc_tick();
86 sound_mix();
87 if (!pcm_submit())
89 delay = framelen - sys_elapsed(timer);
90 sys_sleep(delay);
91 sys_elapsed(timer);
93 doevents();
94 vid_begin();
95 if (framecount) { if (!--framecount) die("finished\n"); }
97 if (!(R_LCDC & 0x80))
98 cpu_emulate(32832);
100 while (R_LY > 0) /* wait for next frame */
101 emu_step();