-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
163 lines (133 loc) · 3.25 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <SDL.h>
#include <SDL_mixer.h>
//#include "globalvar.h"
#include "controlpad.h"
#include "gameloop.h"
#include "sfont.h"
#include "initall.h"
#define DEBUGON 1
#ifdef GP2X
#include "sys/mman.h"
#include "fcntl.h"
volatile unsigned short *MEM_REG;
unsigned long gp2x_dev=0;
void RamHack(void)//I't me! RamHack!
{
gp2x_dev = open("/dev/mem", O_RDWR);
MEM_REG=(unsigned short *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, gp2x_dev, 0xc0000000);
unsigned short v,timing;
//tRC
timing=5;
v = (unsigned short)(MEM_REG[0x3804>>1] & (~(0xF << 8)));
MEM_REG[0x3804>>1] = ((timing & 0xF) << 8) | v;
//tRAS
timing=3;
v = (unsigned short)(MEM_REG[0x3804>>1] & (~(0xF << 4)));
MEM_REG[0x3804>>1] = ((timing & 0xF) << 4) | v;
//tWR
timing=0;
v = (unsigned short)(MEM_REG[0x3804>>1] & (~(0xF)));
MEM_REG[0x3804>>1] = (timing & 0xF) | v;
//tMRD
timing=0;
v = (unsigned short)(MEM_REG[0x3802>>1] & (~(0xF << 12)));
MEM_REG[0x3802>>1] = ((timing & 0xF) << 12) | v;
//tRFC
timing=0;
v = (unsigned short)(MEM_REG[0x3802>>1] & (~(0xF << 8)));
MEM_REG[0x3802>>1] = ((timing & 0xF) << 8) | v;
//tRP
timing=1;
v = (unsigned short)(MEM_REG[0x3802>>1] & (~(0xF << 4)));
MEM_REG[0x3802>>1] = ((timing & 0xF) << 4) | v;
//tRCD
timing=1;
v = (unsigned short)(MEM_REG[0x3802>>1] & (~(0xF)));
MEM_REG[0x3802>>1] = (timing & 0xF) | v;
close(gp2x_dev);
}
#endif
////
int main (int argc, char *argv[])
{
#ifdef PC
fullscreen = false;
#endif
for (int i=1; i < argc; ++i) {
if (!strcmp("--fullscreen", argv[i])) {
fullscreen = true;
} else
if (!strcmp("--editor", argv[i])) {
EditorOn = 1;
} else {
printf("%s [--fullscreen] [--editor]\n", argv[0]);
return strcmp("--help", argv[i]);
}
}
#ifdef GP2X
RamHack();
//system("/sbin/insmod mmuhack.o");
#endif
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
{
exit (1);
}
SDL_ShowCursor(SDL_DISABLE);
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
exit(1);
}
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
#ifdef PC
SDL_WM_SetCaption("FleshChasmer","");
screen = SDL_SetVideoMode (640, 480, 32, SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0));
if (screen == NULL) {
exit (2);
}
#endif
#ifdef GP2X
screen = SDL_SetVideoMode (320, 240, 8, SDL_HWSURFACE || SDL_DOUBLEBUF);
if (screen == NULL) {
exit (2);
}
#endif
//load all
LoadConfig();
InitAll();
if (EditorOn)
{
GameMode=EDITOR_MENU;//enchance this
NewGameMode=EDITOR_MENU;//enchance this
}
else
{
NewGameMode=LOADING_GAME;//enchance this
GameMode=LOADING_GAME;
}
CradleMode=0;
if (SDL_NumJoysticks() > 0) {
joy = SDL_JoystickOpen(0);
}
#ifdef GP2X
if (SDL_NumJoysticks() > 1)
{
CradleMode=1;
USBjoy = SDL_JoystickOpen(1);
}
#endif
#ifdef GP2X
#endif
gameloop();
Mix_CloseAudio();
SDL_Quit();
SaveConfig();
#ifdef GP2X
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
#endif
return 0;
}