-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_startup.cpp
159 lines (141 loc) · 3.65 KB
/
g_startup.cpp
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
/******************************************************************
* winv2: g_startup.cpp *
* copyright (c) 2001 vecna *
******************************************************************/
#include "xerxes.h"
#include "vergepal.h"
/******************
TODO:
* maybe fix switch() ??
*******************/
/****************************** data ******************************/
int v2_xres, v2_yres;
bool eagle;
bool windowmode;
bool sound;
bool cheats;
image *myscreen;
char mapname[80];
/****************************** code ******************************/
void InitDefaults()
{
v2_xres = 320;
v2_yres = 200;
eagle = false;
windowmode = false;
sound = true;
cheats = false;
}
void LoadConfig()
{
cfg_Init("user.cfg");
cfg_SetDefaultKeyValue("startmap", "test.map");
if (cfg_KeyPresent("xres"))
v2_xres = atoi(cfg_GetKeyValue("xres"));
if (cfg_KeyPresent("yres"))
v2_yres = atoi(cfg_GetKeyValue("yres"));
if (cfg_KeyPresent("eagle"))
eagle = atoi(cfg_GetKeyValue("eagle")) ? true : false;
if (cfg_KeyPresent("windowmode"))
windowmode = atoi(cfg_GetKeyValue("windowmode")) ? true : false;
if (cfg_KeyPresent("nosound"))
sound = atoi(cfg_GetKeyValue("nosound")) ? false : true;
if (cfg_KeyPresent("startmap"))
strcpy(mapname, cfg_GetKeyValue("startmap"));
if (cfg_KeyPresent("paranoid"))
vc_paranoid = atoi(cfg_GetKeyValue("paranoid"));
if (cfg_KeyPresent("arraycheck"))
vc_arraycheck = atoi(cfg_GetKeyValue("arraycheck"));
if (cfg_KeyPresent("appname"))
SetWindowText(hMainWnd, cfg_GetKeyValue("appname"));
if (cfg_KeyPresent("vecnascockishuge"))
cheats = true;
if (cfg_KeyPresent("mount1"))
MountVFile(cfg_GetKeyValue("mount1"));
if (cfg_KeyPresent("mount2"))
MountVFile(cfg_GetKeyValue("mount2"));
if (cfg_KeyPresent("mount3"))
MountVFile(cfg_GetKeyValue("mount3"));
}
void InitVideo()
{
if (!eagle && !windowmode)
{
int result = vid_SetMode(v2_xres, v2_yres, 16, 0, MODE_SOFTWARE);
if (!result)
result = vid_SetMode(v2_xres, v2_yres, DesktopBPP, 1, MODE_SOFTWARE);
if (!result)
err("Could not set video mode!");
myscreen = screen;
return;
}
if (!eagle && windowmode)
{
int result = vid_SetMode(v2_xres, v2_yres, DesktopBPP, 1, MODE_SOFTWARE);
if (!result)
err("Could not set video mode!");
myscreen = screen;
return;
}
if (eagle && !windowmode)
{
int result = vid_SetMode(v2_xres * 2, v2_yres * 2, 16, 0, MODE_SOFTWARE);
if (!result)
result = vid_SetMode(v2_xres * 2, v2_yres * 2, DesktopBPP, 1, MODE_SOFTWARE);
if (!result)
err("Could not set video mode!");
myscreen = new image(v2_xres, v2_yres);
return;
}
if (eagle && windowmode)
{
int result = vid_SetMode(v2_xres * 2, v2_yres * 2, DesktopBPP, 1, MODE_SOFTWARE);
if (!result)
err("Could not set video mode!");
myscreen = new image(v2_xres, v2_yres);
return;
}
}
void ShowPage()
{
if (eagle)
run2xSAI(myscreen, screen);
Flip();
}
void InitVergePalette()
{
for (int i=0; i<768; i++)
base_pal8[i] = vergepal[i] * 255 / 63;
memcpy(pal8, base_pal8, sizeof pal8);
for (i=0; i<256; i++)
pal[i] = MakeColor(pal8[i * 3], pal8[(i * 3) + 1], pal8[(i * 3) + 2]);
memcpy(base_pal, pal, sizeof base_pal);
}
void InitTransTbl()
{
VFILE *f = vopen("trans.tbl");
if (!f)
{
for (int y=0; y<256; y++)
for (int x=0; x<256; x++)
transtbl[y][x] = x;
return;
}
vread(transtbl, 65535, f);
vclose(f);
}
void xmain(int argc, char *argv[])
{
InitDefaults();
LoadConfig();
InitVideo();
Init8bpp();
InitVergePalette();
InitTransTbl();
if (sound) InitSound();
LoadFont("system.fnt");
LoadSystemVC();
RunVCAutoexec();
while (true)
Engine_Start(mapname);
}