diff options
Diffstat (limited to 'apps/plugins/rockboy/emu.c')
-rw-r--r-- | apps/plugins/rockboy/emu.c | 146 |
1 files changed, 57 insertions, 89 deletions
diff --git a/apps/plugins/rockboy/emu.c b/apps/plugins/rockboy/emu.c index b398bf497e..f639a62772 100644 --- a/apps/plugins/rockboy/emu.c +++ b/apps/plugins/rockboy/emu.c | |||
@@ -1,6 +1,3 @@ | |||
1 | |||
2 | |||
3 | |||
4 | #include "rockmacros.h" | 1 | #include "rockmacros.h" |
5 | #include "defs.h" | 2 | #include "defs.h" |
6 | #include "regs.h" | 3 | #include "regs.h" |
@@ -17,23 +14,15 @@ static int framecount; | |||
17 | 14 | ||
18 | rcvar_t emu_exports[] = | 15 | rcvar_t emu_exports[] = |
19 | { | 16 | { |
20 | RCV_INT("framelen", &framelen), | 17 | RCV_INT("framelen", &framelen), |
21 | RCV_INT("framecount", &framecount), | 18 | RCV_INT("framecount", &framecount), |
22 | RCV_END | 19 | RCV_END |
23 | }; | 20 | }; |
24 | 21 | ||
25 | |||
26 | |||
27 | |||
28 | |||
29 | |||
30 | |||
31 | void emu_init(void) | 22 | void emu_init(void) |
32 | { | 23 | { |
33 | |||
34 | } | 24 | } |
35 | 25 | ||
36 | |||
37 | /* | 26 | /* |
38 | * emu_reset is called to initialize the state of the emulated | 27 | * emu_reset is called to initialize the state of the emulated |
39 | * system. It should set cpu registers, hardware registers, etc. to | 28 | * system. It should set cpu registers, hardware registers, etc. to |
@@ -42,100 +31,79 @@ void emu_init(void) | |||
42 | 31 | ||
43 | void emu_reset(void) | 32 | void emu_reset(void) |
44 | { | 33 | { |
45 | hw_reset(); | 34 | hw_reset(); |
46 | lcd_reset(); | 35 | lcd_reset(); |
47 | cpu_reset(); | 36 | cpu_reset(); |
48 | mbc_reset(); | 37 | mbc_reset(); |
49 | sound_reset(); | 38 | sound_reset(); |
50 | } | 39 | } |
51 | 40 | ||
52 | |||
53 | |||
54 | |||
55 | |||
56 | void emu_step(void) | 41 | void emu_step(void) |
57 | { | 42 | { |
58 | cpu_emulate(cpu.lcdc); | 43 | cpu_emulate(cpu.lcdc); |
59 | } | 44 | } |
60 | 45 | ||
61 | struct options options; | ||
62 | |||
63 | /* This mess needs to be moved to another module; it's just here to | 46 | /* This mess needs to be moved to another module; it's just here to |
64 | * make things work in the mean time. */ | 47 | * make things work in the mean time. */ |
65 | //extern struct plugin_api* rb; | ||
66 | void emu_run(void) | 48 | void emu_run(void) |
67 | { | 49 | { |
68 | // void *timer = sys_timer(); | 50 | // void *timer = sys_timer(); |
69 | int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; | 51 | int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; |
70 | // int delay; | 52 | // int delay; |
71 | 53 | ||
72 | vid_begin(); | 54 | vid_begin(); |
73 | lcd_begin(); | 55 | lcd_begin(); |
74 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 56 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
75 | rb->cpu_boost(true); | 57 | rb->cpu_boost(true); |
76 | #endif | 58 | #endif |
77 | while(!shut) | 59 | while(!shut) |
78 | { | 60 | { |
79 | cpu_emulate(2280); | 61 | cpu_emulate(2280); |
80 | while (R_LY > 0 && R_LY < 144) | 62 | while (R_LY > 0 && R_LY < 144) |
81 | emu_step(); | 63 | emu_step(); |
82 | 64 | ||
83 | rtc_tick(); | 65 | rtc_tick(); |
84 | sound_mix(); | 66 | sound_mix(); |
85 | if (!pcm_submit()) | 67 | if (!pcm_submit()) |
86 | { | 68 | { |
87 | /* delay = framelen - sys_elapsed(timer); | 69 | /* delay = framelen - sys_elapsed(timer); |
88 | sys_sleep(delay); | 70 | sys_sleep(delay); |
89 | sys_elapsed(timer);*/ | 71 | sys_elapsed(timer);*/ |
90 | } | 72 | } |
91 | 73 | ||
92 | doevents(); | 74 | doevents(); |
93 | vid_begin(); | 75 | vid_begin(); |
94 | 76 | ||
95 | if (!(R_LCDC & 0x80)) | 77 | if (!(R_LCDC & 0x80)) |
96 | cpu_emulate(32832); | 78 | cpu_emulate(32832); |
97 | 79 | ||
98 | while (R_LY > 0) /* wait for next frame */ | 80 | while (R_LY > 0) /* wait for next frame */ |
99 | emu_step(); | 81 | emu_step(); |
100 | rb->yield(); | 82 | rb->yield(); |
101 | 83 | ||
102 | frames++; | 84 | frames++; |
103 | framesin++; | 85 | framesin++; |
104 | 86 | ||
105 | if(*rb->current_tick-timeten>=20) | 87 | if(*rb->current_tick-timeten>=20) |
106 | { | 88 | { |
107 | timeten=*rb->current_tick; | 89 | timeten=*rb->current_tick; |
108 | if(framesin<12) options.frameskip++; | 90 | if(framesin<12) options.frameskip++; |
109 | if(framesin>12) options.frameskip--; | 91 | if(framesin>12) options.frameskip--; |
110 | if(options.frameskip>options.maxskip) options.frameskip=options.maxskip; | 92 | if(options.frameskip>options.maxskip) options.frameskip=options.maxskip; |
111 | if(options.frameskip<0) options.frameskip=0; | 93 | if(options.frameskip<0) options.frameskip=0; |
112 | framesin=0; | 94 | framesin=0; |
113 | } | 95 | } |
114 | 96 | ||
115 | if(options.showstats) | 97 | if(options.showstats) |
116 | { | 98 | if(*rb->current_tick-timehun>=100) |
117 | if(*rb->current_tick-timehun>=100) { | 99 | { |
118 | options.fps=frames; | 100 | options.fps=frames; |
119 | frames=0; | 101 | frames=0; |
120 | timehun=*rb->current_tick; | 102 | timehun=*rb->current_tick; |
121 | } | 103 | } |
122 | } | 104 | } |
123 | |||
124 | } | ||
125 | 105 | ||
126 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 106 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
127 | rb->cpu_boost(false); | 107 | rb->cpu_boost(false); |
128 | #endif | 108 | #endif |
129 | } | 109 | } |
130 | |||
131 | |||
132 | |||
133 | |||
134 | |||
135 | |||
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||