|
|
1.1 root 1: /*
2: WHMSC.C
3: */
4:
5: #include "icorp.h"
6:
7: static
8: int cursbot,curstop,
9: cursx,cursy,
10: winx1,winy1,
11: winx2,winy2,
12: winatr;
13:
14: #if MULTIPLAYER
15: int ipxflag;
16:
17: int totstarts;
18:
19: long fakepersec,
20: gotlastpacketclock,
21: movefifoend,
22: movefifoplc,
23: ototalclock,
24: ready2send;
25:
26: struct baksync baksync[MAXPLAYERS],
27: *baksyncptr[MAXPLAYERS];
28:
29: struct multistart multistart[MAXMULTISTARTS],
30: *multistartptr[MAXMULTISTARTS];
31:
32: char synckeys[MAXSYNCKEYS]={
33: KEYFWD,KEYBACK,KEYLEFT,KEYRIGHT,KEYRUN,KEYSTRAFE,KEYFIRE,KEYUSE,
34: KEYELEVUP,KEYELEVDN,KEYSTAND,KEYLAY,KEYUP,KEYDOWN,KEYGUN1,KEYGUN2,
35: KEYGUN3,KEYGUN4,KEYGUN5,KEYGUN6
36: },
37: tempbuf[576];
38:
39:
40: // DPMI stuff
41:
42: struct rmreg { // real mode register pack
43: unsigned long edi;
44: unsigned long esi;
45: unsigned long ebp;
46: unsigned long rsv;
47: unsigned long ebx;
48: unsigned long edx;
49: unsigned long ecx;
50: unsigned long eax;
51: unsigned short flags;
52: unsigned short es;
53: unsigned short ds;
54: unsigned short fs;
55: unsigned short gs;
56: unsigned short ip;
57: unsigned short cs;
58: unsigned short sp;
59: unsigned short ss;
60: } rmreg;
61:
62: struct ipxentry {
63: unsigned short cs;
64: unsigned short ip;
65: } ipxentry;
66: #endif
67:
68:
69: void
70: faketimerhandler(void)
71: {
72: #if MULTIPLAYER
73: short other,tempbufleng;
74: long i,j,k,l;
75: struct player *plr;
76: struct playerext *plrx;
77:
78: if (totalclock < ototalclock+TICSPERFRAME) {
79: return;
80: }
81: if (ready2send == 0) {
82: return;
83: }
84: fakepersec++;
85: ototalclock=totalclock;
86: if ((pyrn == connecthead) || (option[4] == 0)) {
87: if (option[4] != 0) {
88: while ((tempbufleng=getpacket(&other,tempbuf)) > 0) {
89: plr=plptrlist[other];
90: plrx=(struct playerext *)plr->ext1;
91: switch (tempbuf[0]) {
92: case 1: //[1] (receive slave sync buffer)
93: j=2;
94: k=tempbuf[1];
95: if (k&1) {
96: plrx->vel=tempbuf[j++];
97: }
98: if (k&2) {
99: plrx->svel=tempbuf[j++];
100: }
101: if (k&4) {
102: plrx->angvel=tempbuf[j++];
103: }
104: if (k&8) {
105: plrx->syncbits=((plrx->syncbits&0xFFFFFF00)|((long)tempbuf[j++]));
106: }
107: if (k&16) {
108: plrx->syncbits=((plrx->syncbits&0xFFFF00FF)|((long)tempbuf[j++]<<8));
109: }
110: if (k&32) {
111: plrx->syncbits=((plrx->syncbits&0xFF00FFFF)|((long)tempbuf[j++]<<16));
112: }
113: if (k&64) {
114: plrx->syncbits=((plrx->syncbits&0x00FFFFFF)|((long)tempbuf[j++]<<24));
115: }
116: if (k&128) {
117: plrx->weapon=tempbuf[j++];
118: }
119: break;
120: case 2: // typed message text
121: break;
122: case 3: // voice transmission
123: break;
124: case 255: //[255] (logout)
125: showmessage("Player %d left the game",other);
126: deletesprite(plr->spritenum);
127: break;
128: }
129: }
130: }
131: if (getoutputcirclesize() < 16) {
132: getinput(plptrlist[pyrn]);
133: if (option[4] != 0) {
134: tempbuf[0]=0;
135: tempbuf[1]=numplayers;
136: j=2;
137: for (i=connecthead ; i >= 0 ; i=connectpoint2[i]) {
138: plr=plptrlist[i];
139: plrx=(struct playerext *)plr->ext1;
140: tempbuf[j]=(plr->x&0x000000FF);
141: tempbuf[j+1]=(plr->x>>8)&0x000000FF;
142: tempbuf[j+2]=(plr->x>>16)&0x000000FF;
143: tempbuf[j+3]=(plr->x>>24)&0x000000FF;
144: j+=4;
145: tempbuf[j]=(plr->y&0x000000FF);
146: tempbuf[j+1]=(plr->y>>8)&0x000000FF;
147: tempbuf[j+2]=(plr->y>>16)&0x000000FF;
148: tempbuf[j+3]=(plr->y>>24)&0x000000FF;
149: j+=4;
150: tempbuf[j]=(plr->z&0x000000FF);
151: tempbuf[j+1]=(plr->z>>8)&0x000000FF;
152: tempbuf[j+2]=(plr->z>>16)&0x000000FF;
153: tempbuf[j+3]=(plr->z>>24)&0x000000FF;
154: j+=4;
155: tempbuf[j]=(plr->ang&0x000000FF);
156: tempbuf[j+1]=(plr->ang>>8)&0x000000FF;
157: j+=2;
158: tempbuf[j]=(plr->sector&0x000000FF);
159: tempbuf[j+1]=(plr->sector>>8)&0x000000FF;
160: j+=2;
161: tempbuf[j]=(plrx->syncbits&0xFF);
162: tempbuf[j+1]=(plrx->syncbits>>8)&0xFF;
163: tempbuf[j+2]=(plrx->syncbits>>16)&0xFF;
164: tempbuf[j+3]=(plrx->syncbits>>24)&0xFF;
165: j+=4;
166: tempbuf[j]=plrx->weapon;
167: j+=1;
168: tempbuf[j]=(plrx->health&0x00FF);
169: tempbuf[j+1]=(plrx->health>>8)&0x00FF;
170: j+=2;
171: plrx->oldvel=plrx->vel;
172: plrx->oldsvel=plrx->svel;
173: plrx->oldangvel=plrx->angvel;
174: plrx->oldsyncbits=plrx->syncbits;
175: if (plrx->weapon != plrx->oldweapon) {
176: memmove(&plrx->weapontype,wptptr[plrx->weapon],
177: sizeof(struct weapontype));
178: plrx->oldweapon=plrx->weapon;
179: }
180: }
181: for (i=connectpoint2[connecthead] ; i >= 0 ; i=connectpoint2[i]) {
182: sendpacket(i,tempbuf,j);
183: }
184: }
185: movethings(); //Move EVERYTHING (you too!)
186: }
187: }
188: else { //I am a SLAVE
189: while ((tempbufleng=getpacket(&other,tempbuf)) > 0) {
190: switch (tempbuf[0]) {
191: case 0: //[0] (receive master sync buffer)
192: if (numplayers != tempbuf[1]) {
193: crash("faketimer: numplayers mismatch - "
194: "master=%d,slave=%d",tempbuf[1],numplayers);
195: }
196: j=2;
197: for (i=connecthead ; i >= 0 ; i=connectpoint2[i]) {
198: plr=plptrlist[i];
199: plrx=(struct playerext *)plr->ext1;
200: plr->x=tempbuf[j]+(tempbuf[j+1]<<8)
201: +(tempbuf[j+2]<<16)+(tempbuf[j+3]<<24);
202: j+=4;
203: plr->y=tempbuf[j]+(tempbuf[j+1]<<8)
204: +(tempbuf[j+2]<<16)+(tempbuf[j+3]<<24);
205: j+=4;
206: plr->z=tempbuf[j]+(tempbuf[j+1]<<8)
207: +(tempbuf[j+2]<<16)+(tempbuf[j+3]<<24);
208: j+=4;
209: plr->ang=tempbuf[j]+(tempbuf[j+1]<<8);
210: j+=2;
211: plr->sector=tempbuf[j]+(tempbuf[j+1]<<8);
212: j+=2;
213: plrx->syncbits=tempbuf[j]+(tempbuf[j+1]<<8)
214: +(tempbuf[j+2]<<16)+(tempbuf[j+3]<<24);
215: j+=4;
216: if (i != pyrn) {
217: plrx->weapon=tempbuf[j];
218: if (plrx->weapon != plrx->oldweapon) {
219: memmove(&plrx->weapontype,wptptr[plrx->weapon],
220: sizeof(struct weapontype));
221: plrx->oldweapon=plrx->weapon;
222: }
223: }
224: j+=1;
225: plrx->health=tempbuf[j]+(tempbuf[j+1]<<8);
226: j+=2;
227: }
228: movethings(); //Move all players and sprites
229: break;
230: case 2:
231: break;
232: case 3:
233: break;
234: case 255: //[255] (logout)
235: showmessage("Player %d left the game",other);
236: deletesprite(plptrlist[other]->spritenum);
237: break;
238: }
239: }
240: if (getoutputcirclesize() < 16) {
241: getinput(plptrlist[pyrn]);
242: tempbuf[0]=1;
243: k=0;
244: j=2;
245: plr=plptrlist[pyrn];
246: plrx=(struct playerext *)plr->ext1;
247: if (plrx->vel != plrx->oldvel) {
248: tempbuf[j++]=plrx->vel;
249: k|=1;
250: }
251: if (plrx->svel != plrx->oldsvel) {
252: tempbuf[j++]=plrx->svel;
253: k|=2;
254: }
255: if (plrx->angvel != plrx->oldangvel) {
256: tempbuf[j++]=plrx->angvel;
257: k|=4;
258: }
259: if ((plrx->syncbits&0x000000FF) != (plrx->oldsyncbits&0x000000FF)) {
260: tempbuf[j++]=(plrx->syncbits&255);
261: k|=8;
262: }
263: if ((plrx->syncbits&0x0000FF00) != (plrx->oldsyncbits&0x0000FF00)) {
264: tempbuf[j++]=((plrx->syncbits>>8)&255);
265: k|=16;
266: }
267: if ((plrx->syncbits&0x00FF0000) != (plrx->oldsyncbits&0x00FF0000)) {
268: tempbuf[j++]=((plrx->syncbits>>16)&255);
269: k|=32;
270: }
271: if ((plrx->syncbits&0xFF000000) != (plrx->oldsyncbits&0xFF000000)) {
272: tempbuf[j++]=((plrx->syncbits>>24)&255);
273: k|=64;
274: }
275: if (plrx->weapon != plrx->oldweapon) {
276: tempbuf[j++]=(char)plrx->weapon;
277: k|=128;
278: }
279: tempbuf[1]=k;
280: plrx->oldvel=plrx->vel;
281: plrx->oldsvel=plrx->svel;
282: plrx->oldangvel=plrx->angvel;
283: plrx->oldsyncbits=plrx->syncbits;
284: sendpacket(connecthead,tempbuf,j);
285: }
286: }
287: #endif
288: }
289:
290:
291: char buf[80];
292:
293: void
294: setvmode(int m)
295: {
296: union REGS regs;
297:
298: memset(®s,0,sizeof(union REGS));
299: regs.h.ah=0x00;
300: regs.h.al=m;
301: int386(0x10,®s,®s);
302: }
303:
304: void
305: setatr(int fore,int back)
306: {
307: winatr=(((back&0x0F)<<4)|(fore&0x0F));
308: }
309:
310: void
311: setcsize(int t,int b)
312: {
313: union REGS regs;
314:
315: memset(®s,0,sizeof(union REGS));
316: regs.h.ah=0x01;
317: regs.h.ch=t;
318: regs.h.cl=b;
319: int386(0x10,®s,®s);
320: }
321:
322: void
323: gotoxy(int x,int y)
324: {
325: union REGS regs;
326:
327: memset(®s,0,sizeof(union REGS));
328: regs.h.ah=0x02;
329: regs.h.bh=0;
330: regs.h.dh=y;
331: regs.h.dl=x;
332: int386(0x10,®s,®s);
333: cursx=x;
334: cursy=y;
335: }
336:
337: void
338: getcurs(void)
339: {
340: union REGS regs;
341:
342: memset(®s,0,sizeof(union REGS));
343: regs.h.ah=0x03;
344: regs.h.bh=0;
345: int386(0x10,®s,®s);
346: if (curstop == -1) {
347: curstop=regs.h.ch;
348: }
349: if (cursbot == -1) {
350: cursbot=regs.h.cl;
351: }
352: cursy=regs.h.dh;
353: cursx=regs.h.dl;
354: }
355:
356: void
357: setregion(int x1,int y1,int x2,int y2)
358: {
359: winx1=x1;
360: winy1=y1;
361: winx2=x2;
362: winy2=y2;
363: }
364:
365: void
366: scrollup(void)
367: {
368: union REGS regs;
369:
370: memset(®s,0,sizeof(union REGS));
371: regs.h.ah=0x06;
372: regs.h.al=1;
373: regs.h.bh=winatr;
374: regs.h.ch=winy1;
375: regs.h.cl=winx1;
376: regs.h.dh=winy2;
377: regs.h.dl=winx2;
378: int386(0x10,®s,®s);
379: }
380:
381: void
382: scrolldn(void)
383: {
384: union REGS regs;
385:
386: memset(®s,0,sizeof(union REGS));
387: regs.h.ah=0x07;
388: regs.h.al=1;
389: regs.h.bh=winatr;
390: regs.h.ch=winy1;
391: regs.h.cl=winx1;
392: regs.h.dh=winy2;
393: regs.h.dl=winx2;
394: int386(0x10,®s,®s);
395: }
396:
397: void
398: clrregion(int fore,int back)
399: {
400: union REGS regs;
401:
402: setatr(fore,back);
403: memset(®s,0,sizeof(union REGS));
404: regs.h.ah=0x06;
405: regs.h.al=0;
406: regs.h.bh=winatr;
407: regs.h.ch=winy1;
408: regs.h.cl=winx1;
409: regs.h.dh=winy2;
410: regs.h.dl=winx2;
411: int386(0x10,®s,®s);
412: }
413:
414:
415: void far *
416: dpmi_getexception(int no)
417: {
418: void far *fp;
419: union REGS regs;
420:
421: regs.x.eax=0x202;
422: regs.x.ebx=no;
423: int386(0x31,®s,®s);
424: fp=MK_FP(regs.w.cx,regs.x.edx);
425: return(fp);
426: }
427:
428: void
429: dpmi_setexception(int no,void far *func)
430: {
431: union REGS regs;
432:
433: regs.x.eax=0x203;
434: regs.x.ebx=no;
435: regs.x.ecx=FP_SEG(func);
436: regs.x.edx=FP_OFF(func);
437: int386(0x31,®s,®s);
438: }
439:
440: #if MULTIPLAYER
441: int
442: dpmi_callrealint(int no,struct rmreg *r)
443: {
444: union REGS regs;
445: struct SREGS sregs;
446: void far *fp;
447:
448: fp=(void far *)r;
449: segread(&sregs);
450: regs.x.eax=0x300;
451: regs.x.ebx=no;
452: regs.x.ecx=0;
453: sregs.es=FP_SEG(fp);
454: regs.x.edi=FP_OFF(fp);
455: r->ss=0;
456: r->sp=0;
457: r->flags=0;
458: int386x(0x31,®s,®s,&sregs);
459: return(regs.x.cflag);
460: }
461:
462: int
463: isipx(void)
464: {
465: rmreg.eax=0x7A00;
466: dpmi_callrealint(0x2F,&rmreg);
467: if ((rmreg.eax&0x000000FF) != 0xFF) {
468: ipxentry.cs=0;
469: ipxentry.ip=0;
470: ipxflag=0;
471: }
472: else {
473: ipxentry.cs=rmreg.es;
474: ipxentry.ip=rmreg.edi&0xFFFF;
475: ipxflag=1;
476: }
477: return(ipxflag);
478: }
479: #endif
480:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.