d_main.c (5419B)
1 /* D_main.c */ 2 3 #include "i_main.h" 4 #include "doomdef.h" 5 #include "p_spec.h" 6 #include "r_local.h" 7 8 int gamevbls; // 80063130 /* may not really be vbls in multiplayer */ 9 int gametic; // 80063134 10 int ticsinframe; // 80063138 /* how many tics since last drawer */ 11 int ticon; // 8006313C 12 int lastticon; // 80063140 13 int vblsinframe[MAXPLAYERS]; // 80063144 /* range from 4 to 8 */ 14 int ticbuttons[MAXPLAYERS]; // 80063148 15 int oldticbuttons[MAXPLAYERS]; // 8006314C 16 17 buttons_t *BT_DATA[MAXPLAYERS];// 800A559C 18 19 extern boolean run_hectic_demo; 20 21 void D_DoomMain(void) // 800027C0 22 { 23 int exit; 24 25 I_Init(); 26 Z_Init(); 27 W_Init(); 28 R_Init(); 29 ST_Init(); 30 31 gamevbls = 0; 32 gametic = 0; 33 ticsinframe = 0; 34 ticon = 0; 35 ticbuttons[0] = 0; 36 oldticbuttons[0] = 0; 37 38 D_SplashScreen(); 39 40 while(true) 41 { 42 exit = D_TitleMap(); 43 44 if(exit != ga_exit) 45 { 46 exit = D_RunDemo("DEMO1LMP", sk_medium, 3); 47 if(exit != ga_exit) 48 { 49 exit = D_RunDemo("DEMO2LMP", sk_medium, 9); 50 if(exit != ga_exit) 51 { 52 exit = D_RunDemo("DEMO3LMP", sk_medium, 17); 53 if(exit != ga_exit) 54 { 55 if(run_hectic_demo) 56 { 57 run_hectic_demo = false; 58 exit = D_RunDemo("DEMO4LMP", sk_medium, 32); 59 } 60 61 if(exit != ga_exit) 62 { 63 exit = D_Credits(); 64 65 if(exit != ga_exit) 66 { 67 continue; 68 } 69 } 70 } 71 } 72 } 73 } 74 75 do { 76 exit = M_RunTitle(); 77 } while(exit != ga_timeout); 78 } 79 } 80 81 /* 82 =============== 83 = 84 = M_Random 85 = 86 = Returns a 0-255 number 87 = 88 =============== 89 */ 90 91 unsigned char rndtable[256] = { // 8005A190 92 0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66 , 93 74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36 , 94 95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188 , 95 52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224 , 96 149, 104, 25, 178, 252, 182, 202, 182, 141, 197, 4, 81, 181, 242 , 97 145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175, 249, 0 , 98 175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235 , 99 25, 92, 20, 145, 138, 77, 69, 166, 78, 176, 173, 212, 166, 113 , 100 94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37, 171, 75 , 101 136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196 , 102 135, 106, 63, 197, 195, 86, 96, 203, 113, 101, 170, 247, 181, 113 , 103 80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, 166, 103, 241 , 104 24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224 , 105 145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95 , 106 28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226 , 107 71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36 , 108 17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106 , 109 197, 242, 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136 , 110 120, 163, 236, 249 111 }; 112 113 int rndindex = 0; // 8005A18C 114 int prndindex = 0; // 8005A188 115 116 int P_Random(void) // 80002928 117 { 118 prndindex = (prndindex + 1) & 0xff; 119 return rndtable[prndindex]; 120 } 121 122 int M_Random(void) // 80002954 123 { 124 rndindex = (rndindex + 1) & 0xff; 125 return rndtable[rndindex]; 126 } 127 128 void M_ClearRandom(void) // 80002980 129 { 130 rndindex = prndindex = 0; 131 } 132 133 /* 134 =============== 135 = 136 = MiniLoop 137 = 138 =============== 139 */ 140 141 int MiniLoop(void(*start)(void), void(*stop)(), 142 int(*ticker)(void), void(*drawer)(void)) // 80002998 143 { 144 int exit; 145 int buttons; 146 147 gameaction = ga_nothing; 148 gamevbls = 0; 149 gametic = 0; 150 ticon = 0; 151 ticsinframe = 0; 152 153 /* */ 154 /* setup (cache graphics, etc) */ 155 /* */ 156 if(start != NULL) 157 start(); 158 159 drawsync1 = 0; 160 drawsync2 = vsync; 161 162 while (true) 163 { 164 vblsinframe[0] = drawsync1; 165 166 // get buttons for next tic 167 oldticbuttons[0] = ticbuttons[0]; 168 169 buttons = I_GetControllerData(); 170 ticbuttons[0] = buttons; 171 172 //Read|Write demos 173 if (demorecording || demoplayback) 174 { 175 if (demoplayback) 176 { 177 if (buttons & (ALL_JPAD|ALL_BUTTONS)) 178 { 179 exit = ga_exit; 180 break; 181 } 182 183 buttons = *demobuffer++; 184 ticbuttons[0] = buttons; 185 } 186 187 if (demorecording) 188 { 189 *demobuffer++ = buttons; 190 } 191 192 if ((buttons & PAD_START) || ((((int)demobuffer - (int)demo_p) >> 2) >= 4000)) 193 { 194 exit = ga_exitdemo; 195 break; 196 } 197 } 198 199 ticon += vblsinframe[0]; 200 if (ticsinframe < (ticon >> 1)) 201 { 202 gametic += 1; 203 ticsinframe = (ticon >> 1); 204 } 205 206 if (disabledrawing == false) 207 { 208 exit = ticker(); 209 if (exit != ga_nothing) 210 break; 211 212 drawer(); 213 } 214 215 gamevbls = gametic; 216 } 217 218 I_GetScreenGrab(); 219 220 if(stop != NULL) 221 stop(exit); 222 223 oldticbuttons[0] = ticbuttons[0]; 224 225 return exit; 226 }