-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathLJP-GBmain.c
205 lines (157 loc) · 4.14 KB
/
LJP-GBmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "palmdep.h"
#include "endianutils.h"
#include "pnobridge.h"
#include "oscompat.h"
#include "endianutils.h"
#include "ljPRsc.h"
#ifdef __PACE__
#include "PACEInterface.h"
#else
#include "palmos5.h"
#endif
#include "PNOMain.h"
#include "palmport.h"
#include "App_Cst.h"
#include "save.h"
#include "rtc.h"
unsigned int g_translateBtn[20]=
{KEY_A,KEY_B,KEY_START,KEY_SELECT,
KEY_UP,KEY_DOWN,KEY_LEFT,KEY_RIGHT,
KEY_QUICKLOAD,KEY_QUICKSAVE,KEY_FRAMESKIP,
KEY_SCREENMODE,KEY_TURBO,KEY_PANIC,0,0,0,0,0,0};
extern unsigned int g_confinput[20];
extern unsigned int g_confinput_treo[20][3];
int fgbZ_ShowMenu(void);
void fgbZ_pause(int pause);
void ClearScreen(void);
UInt32 mStopEmulation=0;
extern UInt32 ljp_showFPS,ljp_showBeltbar,ljp_showBattMode,ljp_isLowRes,ljp_confirmOW,ljp_confirmSL;
extern UInt32 fgbZ_renderingmode;
extern UInt16 *fgbZ_zodvram;
extern UInt32 device_type;
extern char ljp_RomPath[256];
unsigned long Run()
{
Int32 lastTick;
UInt32 pollcpt=0;
UInt32 keys,keyval;
Int16 penX,penY;
Boolean penDown;
//Read the key config
UInt32 *ftrptr;
char text[16];
Int32 framerate = 0;
Int32 timecpt,framecpt = 0;
//Load the Rom
mStopEmulation=fgbZ_loadrom();
if (device_type & BF_ZODIAC) {
fgbZ_zodvram=(UInt16*) stubzodiacblit ( 0,0,0,0 );
if (!fgbZ_zodvram) menu_info("Zodiac VRAM NULL ptr!!");
}
ClearScreen();
//
//Main Loop
//autoload?
if (g_pnobridge->game_rom){
state_load(g_pnobridge->game_rom-1,0);
}
//init rtc
/*if (rtc)*/ {
DateTimeType date_time;
UInt32 seconds,i;
//february is always 28,....
UInt32 month_len[12]={31,28,31,30,31,30,31,31,30,31,30,31};
seconds=TimGetSeconds();
TimSecondsToDateTime(seconds,&date_time);
rtc.d=(int)date_time.day;
for (i=0;i<date_time.month-1;i++) {
rtc.d+=month_len[i];
}
rtc.h=(int)date_time.hour;
rtc.m=(int)date_time.minute;
rtc.s=(int)date_time.second;
rtc.t=(int)0;
/* {
char tmp[16];
sprintf(tmp,"%d-%d-%d-%d-%d",rtc.d,rtc.h,rtc.m,rtc.s,rtc.t);
menu_inform(tmp);
}*/
}
timecpt=GetTickCount();
while (!mStopEmulation)
{
//Read key state
keys = KeyCurrentState();
keyval=0;
//check pen
if (!(pollcpt&3)) LJP_CHECK_MENU_ACCESS(fgbZ_ShowMenu,fgbZ_renderingmode>=2)
//handle sys event
if (!(pollcpt&31)) LJP_HANDLE_EVENT(fgbZ_pause)
//avoid autoff
//every 1024 frame =>
if (!(pollcpt&1023)) EvtResetAutoOffTimer();
LJP_UPDATE_KEYS
fgbZ_updatevpad(keyval);
if (keyval&KEY_FRAMESKIP)
{
fgbZ_changefskip();
ClearScreen();
}
if (keyval&KEY_SCREENMODE)
{
fgbZ_changerendering();
stub_DrawBeltBar();
ClearScreen();
}
//check for panic key
if (keyval&KEY_PANIC)
{
state_save(0);
mStopEmulation=1;
FtrSet(CREATORID, FTR_PANIC_EXIT_ID, 1);
}
pollcpt++;
//Emulate GB
fgbZ_MainLoop();
framecpt++;
if ((fgbZ_renderingmode<2) && ( (ljp_showFPS) || (ljp_showBeltbar) ))
if (framecpt>=30) {
//FPS
UInt8 *vr;
vr=(UInt8*)(g_pnobridge -> vram)/*+(g_pnobridge -> display_pitch)*2*/;
framecpt=0;
framerate=30*1000/(GetTickCount()-timecpt+1);
timecpt=GetTickCount();
if (ljp_showBeltbar) {
beltbar_draw(0,g_pnobridge -> display_height-BELTBAR_SIZE,g_pnobridge -> display_pitch,framerate,0,vr);
} else if (ljp_showFPS) {
for (int y=0;y<20;y++)
{
memset(vr,0,80*2);
vr+=(g_pnobridge -> display_pitch)*2;
}
text[0]=((framerate/100)%10)+48;
text[1]=((framerate/10)%10)+48;
text[2]=((framerate)%10)+48;
text[3]=0;
menu_messageRaw(5,0,text);
}
}
}
fgbZ_end();
if (device_type & BF_ZODIAC) {
stubzodiacblit ( 1,0,0,0 );
}
return 0;
}
/************************************/
void ClearScreen(void)
{
UInt8 *vr;
vr=(UInt8*)(g_pnobridge -> vram);
for (int y=0;y<g_pnobridge -> display_height-(fgbZ_renderingmode<2?BELTBAR_SIZE:0);y++)
{
memset(vr,0,g_pnobridge -> display_width*2);
vr+=(g_pnobridge -> display_pitch)*2;
}
}