DEADSOFTWARE

Drop non-standard `malloc.h` include
[flatwaifu.git] / src / main.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include "glob.h"
24 #include <stdio.h>
25 ///#include <process.h>
26 #include <stdarg.h>
27 ///#include <conio.h>
28 //#include <time.h>
29 ///#include <dos.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include "error.h"
33 #include "config.h"
34 #include "memory.h"
35 #include "keyb.h"
36 #include "sound.h"
37 #include "vga.h"
38 #include "files.h"
39 #include "view.h"
40 #include "menu.h"
41 #include "player.h"
42 #include "misc.h"
44 #include <SDL.h>
46 int gammaa=0;
48 char main_pal[256][3],std_pal[256][3];
49 byte mixmap[256][256];
50 byte clrmap[256*12];
52 void logo(const char *s,...) {
53 va_list ap;
54 int x,y;
56 va_start(ap,s);
57 vprintf(s,ap);
58 va_end(ap);
59 fflush(stdout);
60 }
62 void logo_gas(int cur,int all) {
63 }
65 byte gamcor[5][64]={
66 #include "gamma.dat"
67 };
69 void setgamma(int g) {
70 int t;
72 if(g>4) g=4;
73 if(g<0) g=0;
74 gammaa=g;
75 for(t=0;t<256;++t) {
76 std_pal[t][0]=gamcor[gammaa][main_pal[t][0]];
77 std_pal[t][1]=gamcor[gammaa][main_pal[t][1]];
78 std_pal[t][2]=gamcor[gammaa][main_pal[t][2]];
79 }
80 VP_setall(std_pal);
81 }
83 void myrandomize(void);
85 byte bright[256];
87 int main(int argc, char *argv[]) {
88 if (SDL_Init(SDL_INIT_VIDEO)<0) ERR_failinit("Unable to init SDL: %s\n", SDL_GetError());
89 SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D");
90 int i;
92 pl1.ku=SDLK_KP8;
93 pl1.kd=SDLK_KP5;
94 pl1.kl=SDLK_KP4;
95 pl1.kr=SDLK_KP6;
96 pl1.kf=SDLK_PAGEDOWN;
97 pl1.kj=SDLK_DELETE;
98 pl1.kwl=SDLK_HOME;
99 pl1.kwr=SDLK_END;
100 pl1.kp=SDLK_KP8;
101 pl1.id=-1;
102 pl2.ku=SDLK_e;
103 pl2.kd=SDLK_d;
104 pl2.kl=SDLK_s;
105 pl2.kr=SDLK_f;
106 pl2.kf=SDLK_a;
107 pl2.kj=SDLK_q;
108 pl2.kwl=SDLK_1;
109 pl2.kwr=SDLK_2;
110 pl2.kp=SDLK_e;
111 pl2.id=-2;
112 myrandomize();
113 F_startup();
114 char *pw;
115 #ifndef WIN32
116 pw = "/usr/share/doom2d-rembo/doom2d.wad";
117 #else
118 pw = "doom2d.wad";
119 #endif
120 if (fexists(pw))
121 F_addwad(pw);
122 else
123 F_addwad("doom2d.wad");
124 CFG_args(argc, argv);
125 CFG_load();
126 F_initwads();
127 M_startup();
128 F_allocres();
129 F_loadres(F_getresid("PLAYPAL"),main_pal,0,768);
130 for(i=0;i<256;++i)
131 bright[i]=((int)main_pal[i][0]+main_pal[i][1]+main_pal[i][2])*8/(63*3);
132 F_loadres(F_getresid("MIXMAP"),mixmap,0,0x10000);
133 F_loadres(F_getresid("COLORMAP"),clrmap,0,256*12);
134 G_init();
135 K_init();
136 logo("S_init: настройка звука\n");
137 S_init();
138 S_initmusic();
139 logo("V_init: настройка видео\n");
140 if(V_init()!=0) ERR_failinit("Не могу установить видеорежим VGA");
141 setgamma(gammaa);
142 V_setscr(scrbuf);
143 GM_init();
144 F_loadmus("MENU");S_startmusic(0);
146 Uint32 ticks = 0;
147 for(;;) {
149 updatee_keys();
151 S_updatemusic();
153 G_act();
155 G_draw();
157 Uint32 t;
158 while ((t = SDL_GetTicks())-ticks < DELAY) {
159 SDL_Delay(1);
161 ticks = t - t % DELAY;