-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJM_FREE.C
2350 lines (1857 loc) · 48.1 KB
/
JM_FREE.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// JM_FREE.C
//
// Warning!
//
// All functions in this source file are designated usable by the memory
// manager after program initialization.
//
#include "ID_HEADS.H"
#pragma hdrstop
#include "3d_def.h"
#define SKIP_CHECKSUMS (true)
#define SHOW_CHECKSUM (false)
#if GAME_VERSION == SHAREWARE_VERSION
#define AUDIOT_CHECKSUM 0xFFF87142
#define MAPTEMP_CHECKSUM 0x000370C9
#define VGAGRAPH_CHECKSUM 0xFFFFDE44
#define DIZFILE_CHECKSUM 0x00000879l
#elif GAME_VERSION == MISSIONS_1_THR_3
#define AUDIOT_CHECKSUM 0xFFF87142
#define MAPTEMP_CHECKSUM 0x00084F1F
#define VGAGRAPH_CHECKSUM 0xFFFFDE44
#define DIZFILE_CHECKSUM 0x00000879l
#else
#define AUDIOT_CHECKSUM 0xfff912C9
#define MAPTEMP_CHECKSUM 0x00107739
#define VGAGRAPH_CHECKSUM 0xffff6C9A
#define DIZFILE_CHECKSUM 0x00000879l
#endif
#pragma warn -pro
#pragma warn -use
void SDL_SBSetDMA(byte channel);
void SDL_SetupDigi(void);
//=========================================================================
//
// FAR FREE DATA
//
//=========================================================================
#if FREE_DATA
char far JM_FREE_DATA_START[1]={0};
#endif
#if TECH_SUPPORT_VERSION
char far EnterBetaCode[]="\n TECH SUPPORT VERSION!\n\n NO DISTRIBUTING!";
#elif BETA_TEST
char far EnterBetaCode[]=" !BETA VERSION!\n DO NOT DISTRIBUTE\n UNDER PENALTY OF DEATH\n\n ENTER BETA CODE";
#endif
char far * far JHParmStrings[] = {"no386","is386",nil};
char far show_text1[]="\n SYSTEM INFO\n";
char far show_text2[]="=======================\n\n";
char far show_text3[]="-- Memory avail after game is loaded --\n\n";
char far show_text4[]=" ** Insufficient memory to run the game **";
char far show_text5[]="---- Extra Devices ----\n\n";
static char far * far ParmStrings[] = {"HIDDENCARD",""};
static byte far wolfdigimap[] =
{
// These first sounds are in the upload version
ATKIONCANNONSND, 0,
ATKCHARGEDSND, 1,
ATKBURSTRIFLESND, 2,
ATKGRENADESND, 46,
OPENDOORSND, 3,
CLOSEDOORSND, 4,
HTECHDOOROPENSND, 5,
HTECHDOORCLOSESND, 6,
INFORMANTDEATHSND, 7,
SCIENTISTHALTSND, 19,
SCIENTISTDEATHSND, 20,
GOLDSTERNHALTSND, 8,
GOLDSTERNLAUGHSND, 24,
HALTSND, 9, // Rent-A-Cop 1st sighting
RENTDEATH1SND, 10, // Rent-A-Cop Death
EXPLODE1SND, 11,
GGUARDHALTSND, 12,
GGUARDDEATHSND, 17,
PROHALTSND, 16,
PROGUARDDEATHSND, 13,
BLUEBOYDEATHSND, 18,
BLUEBOYHALTSND, 51,
SWATHALTSND, 22,
SWATDIESND, 47,
SCANHALTSND, 15,
SCANDEATHSND, 23,
PODHATCHSND, 26,
PODHALTSND, 50,
PODDEATHSND, 49,
ELECTSHOTSND, 27,
DOGBOYHALTSND, 14,
DOGBOYDEATHSND, 21,
ELECARCDAMAGESND, 25,
ELECAPPEARSND, 28,
ELECDIESND, 29,
INFORMDEATH2SND, 39, // Informant Death #2
RENTDEATH2SND, 34, // Rent-A-Cop Death #2
PRODEATH2SND, 42, // PRO Death #2
SWATDEATH2SND, 48, // SWAT Death #2
SCIDEATH2SND, 53, // Gen. Sci Death #2
LIQUIDDIESND, 30,
GURNEYSND, 31,
GURNEYDEATHSND, 41,
WARPINSND, 32,
WARPOUTSND, 33,
EXPLODE2SND, 35,
LCANHALTSND, 36,
LCANDEATHSND, 37,
// RENTDEATH3SND, 38, // Rent-A-Cop Death #3
INFORMDEATH3SND, 40, // Informant Death #3
// PRODEATH3SND, 43, // PRO Death #3
// SWATDEATH3SND, 52, // Swat Guard #3
SCIDEATH3SND, 54, // Gen. Sci Death #3
LCANBREAKSND, 44,
SCANBREAKSND, 45,
CLAWATTACKSND, 56,
SPITATTACKSND, 55,
PUNCHATTACKSND, 57,
LASTSOUND
};
#if 0
static byte far wolfdigimap[] =
{
// These first sounds are in the upload version
ATKIONCANNONSND, 0,
ATKCHARGEDSND, 1,
ATKBURSTRIFLESND, 2,
ATKGRENADESND, 46,
OPENDOORSND, 3,
CLOSEDOORSND, 4,
HTECHDOOROPENSND, 5,
HTECHDOORCLOSESND, 6,
INFORMANTDEATHSND, 7,
SCIENTISTHALTSND, 19,
SCIENTISTDEATHSND, 20,
GOLDSTERNHALTSND, 8,
GOLDSTERNLAUGHSND, 24,
HALTSND, 9, // Rent-A-Cop 1st sighting
RENTDEATH1SND, 10, // Rent-A-Cop Death
EXPLODE1SND, 11,
GGUARDHALTSND, 12,
GGUARDDEATHSND, 17,
PROHALTSND, 16,
PROGUARDDEATHSND, 13,
BLUEBOYDEATHSND, 18,
BLUEBOYHALTSND, 51,
SWATHALTSND, 22,
SWATDIESND, 47,
SCANHALTSND, 15,
SCANDEATHSND, 23,
PODHATCHSND, 26,
PODHALTSND, 50,
PODDEATHSND, 49,
ELECTSHOTSND, 27,
DOGBOYHALTSND, 14,
DOGBOYDEATHSND, 21,
ELECARCDAMAGESND, 25,
ELECAPPEARSND, 28,
ELECDIESND, 29,
INFORMDEATH2SND, 39, // Informant Death #2
RENTDEATH2SND, 34, // Rent-A-Cop Death #2
PRODEATH2SND, 42, // PRO Death #2
SWATDEATH2SND, 48, // SWAT Death #2
SCIDEATH2SND, 53, // Gen. Sci Death #2
LIQUIDDIESND, 30,
GURNEYSND, 31,
GURNEYDEATHSND, 41,
WARPINSND, 32,
WARPOUTSND, 33,
EXPLODE2SND, 35,
LCANHALTSND, 36,
LCANDEATHSND, 37,
// RENTDEATH3SND, 38, // Rent-A-Cop Death #3
INFORMDEATH3SND, 40, // Informant Death #3
// PRODEATH3SND, 43, // PRO Death #3
// SWATDEATH3SND, 52, // Swat Guard #3
SCIDEATH3SND, 54, // Gen. Sci Death #3
LCANBREAKSND, 44,
SCANBREAKSND, 45,
CLAWATTACKSND, 56,
SPITATTACKSND, 55,
PUNCHATTACKSND, 57,
LASTSOUND
};
#endif
char far cinfo_text[]= "\n"
"Planet Strike\n"
"Copyright (c) 1993 - JAM Productions, Inc.\n"
"All rights reserved.\n";
#if BETA_TEST
char far dver_text[]="Download the latest version pal!";
#endif
#if FREE_DATA
char far JM_FREE_DATA_END[1]={0};
#endif
extern byte far colormap[];
byte far * lightsource;
//=========================================================================
//
// FREE FUNCTIONS
//
//=========================================================================
#if FREE_FUNCTIONS
// This function is used as a label for the start of the
// functions used by the memory manager.
//
void JM_FREE_START()
{
}
#endif
// ------------------ ID Software 'startup' functions ---------------------
/*
======================
=
= CA_Startup
=
= Open all files and load in headers
=
======================
*/
void CA_Startup (void)
{
#ifdef PROFILE
unlink ("PROFILE.TXT");
profilehandle = open("PROFILE.TXT", O_CREAT | O_WRONLY | O_TEXT);
#endif
CAL_SetupMapFile ();
CAL_SetupGrFile ();
CAL_SetupAudioFile ();
mapon = -1;
ca_levelbit = 1;
ca_levelnum = 0;
}
//#if !IN_DEVELOPMENT
extern boolean IN_Started;
extern char far * far IN_ParmStrings[];
extern boolean INL_StartJoy(word joy);
extern boolean INL_StartMouse(void);
extern void INL_StartKbd(void);
///////////////////////////////////////////////////////////////////////////
//
// INL_StartJoy() - Detects & auto-configures the specified joystick
// The auto-config assumes the joystick is centered
//
///////////////////////////////////////////////////////////////////////////
boolean
INL_StartJoy(word joy)
{
word x,y;
IN_GetJoyAbs(joy,&x,&y);
if
(
((x == 0) || (x > MaxJoyValue - 10))
|| ((y == 0) || (y > MaxJoyValue - 10))
)
return(false);
else
{
IN_SetupJoy(joy,0,x * 2,0,y * 2);
return(true);
}
}
///////////////////////////////////////////////////////////////////////////
//
// IN_Startup() - Starts up the Input Mgr
//
///////////////////////////////////////////////////////////////////////////
void
IN_Startup(void)
{
boolean checkjoys,checkmouse,checkNG;
word i;
if (IN_Started)
return;
checkjoys = true;
checkmouse = true;
checkNG = false;
for (i = 1;i < _argc;i++)
{
switch (US_CheckParm(_argv[i],IN_ParmStrings))
{
case 0:
checkjoys = false;
break;
case 1:
checkmouse = false;
break;
case 2:
checkNG = true;
break;
}
}
if (checkNG)
{
#define WORD_CODE(c1,c2) ((c2)|(c1<<8))
NGjoy(0xf0);
if ((_AX==WORD_CODE('S','G')) && _BX)
NGinstalled=true;
}
INL_StartKbd();
MousePresent = checkmouse? INL_StartMouse() : false;
for (i = 0;i < MaxJoys;i++)
JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
IN_Started = true;
}
//#endif
/*
===================
=
= MM_Startup
=
= Grabs all space from turbo with malloc/farmalloc
= Allocates bufferseg misc buffer
=
===================
*/
extern boolean mmstarted,bombonerror;
extern mmblocktype far mmblocks[], far *mmhead, far *mmfree,
far *mmnew, far *mmrover;
extern void far *farheap;
extern void *nearheap;
void MM_Startup (void)
{
int i;
unsigned long length;
void far *start;
unsigned segstart,seglength,endfree;
if (mmstarted)
MM_Shutdown ();
mmstarted = true;
bombonerror = true;
//
// set up the linked list (everything in the free list;
//
mmhead = NULL;
mmfree = &mmblocks[0];
for (i=0;i<MAXBLOCKS-1;i++)
mmblocks[i].next = &mmblocks[i+1];
mmblocks[i].next = NULL;
//
// locked block of all memory until we punch out free space
//
GETNEWBLOCK;
mmhead = mmnew; // this will allways be the first node
mmnew->start = 0;
mmnew->length = 0xffff;
mmnew->attributes = LOCKBIT;
mmnew->next = NULL;
mmrover = mmhead;
//
// get all available near conventional memory segments
//
length=coreleft();
start = (void far *)(nearheap = malloc(length));
length -= 16-(FP_OFF(start)&15);
length -= SAVENEARHEAP;
seglength = length / 16; // now in paragraphs
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
MML_UseSpace (segstart,seglength);
mminfo.nearheap = length;
//
// get all available far conventional memory segments
//
length=farcoreleft();
start = farheap = farmalloc(length);
length -= 16-(FP_OFF(start)&15);
length -= SAVEFARHEAP;
seglength = length / 16; // now in paragraphs
segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
MML_UseSpace (segstart,seglength);
mminfo.farheap = length;
mminfo.mainmem = mminfo.nearheap + mminfo.farheap;
// __SEGS_AVAILABLE__ = (long)(mminfo.EMSmem + mminfo.XMSmem + mminfo.mainmem) / 16;
//
// allocate the misc buffer
//
mmrover = mmhead; // start looking for space after low block
MM_GetPtr (&bufferseg,BUFFERSIZE);
}
//
// PML_StartupEMS() - Sets up EMS for Page Mgr's use
// Checks to see if EMS driver is present
// Verifies that EMS hardware is present
// Make sure that EMS version is 3.2 or later
// If there's more than our minimum (2 pages) available, allocate it (up
// to the maximum we need)
//
#if !DUAL_SWAP_FILES
char EMMDriverName[9] = "EMMXXXX0";
extern word EMSAvail,EMSPagesAvail,EMSHandle,
EMSPageFrame,EMSPhysicalPage;
extern EMSListStruct EMSList[];
boolean
PML_StartupEMS(void)
{
int i;
long size;
EMSPresent = false; // Assume that we'll fail
EMSAvail = 0;
_DX = (word)EMMDriverName;
_AX = 0x3d00;
geninterrupt(0x21); // try to open EMMXXXX0 device
asm jnc gothandle
goto error;
gothandle:
_BX = _AX;
_AX = 0x4400;
geninterrupt(0x21); // get device info
asm jnc gotinfo;
goto error;
gotinfo:
asm and dx,0x80
if (!_DX)
goto error;
_AX = 0x4407;
geninterrupt(0x21); // get status
asm jc error
if (!_AL)
goto error;
_AH = 0x3e;
geninterrupt(0x21); // close handle
_AH = EMS_STATUS;
geninterrupt(EMS_INT);
if (_AH)
goto error; // make sure EMS hardware is present
_AH = EMS_VERSION;
geninterrupt(EMS_INT);
if (_AH || (_AL < 0x32)) // only work on EMS 3.2 or greater (silly, but...)
goto error;
_AH = EMS_GETFRAME;
geninterrupt(EMS_INT);
if (_AH)
goto error; // find the page frame address
EMSPageFrame = _BX;
_AH = EMS_GETPAGES;
geninterrupt(EMS_INT);
if (_AH)
goto error;
if (_BX < 2)
goto error; // Require at least 2 pages (32k)
EMSAvail = _BX;
// Don't hog all available EMS
size = EMSAvail * (long)EMSPageSize;
if (size - (EMSPageSize * 2) > (ChunksInFile * (long)PMPageSize))
{
size = (ChunksInFile * (long)PMPageSize) + EMSPageSize;
EMSAvail = size / EMSPageSize;
}
_AH = EMS_ALLOCPAGES;
_BX = EMSAvail;
geninterrupt(EMS_INT);
if (_AH)
goto error;
EMSHandle = _DX;
mminfo.EMSmem += EMSAvail * (long)EMSPageSize;
// Initialize EMS mapping cache
for (i = 0;i < EMSFrameCount;i++)
EMSList[i].baseEMSPage = -1;
EMSPresent = true; // We have EMS
error:
return(EMSPresent);
}
//
// PML_StartupXMS() - Starts up XMS for the Page Mgr's use
// Checks for presence of an XMS driver
// Makes sure that there's at least a page of XMS available
// Allocates any remaining XMS (rounded down to the nearest page size)
//
extern boolean XMSPresent;
extern word XMSAvail,XMSPagesAvail,XMSHandle;
extern longword XMSDriver;
extern int XMSProtectPage;
boolean
PML_StartupXMS(void)
{
XMSPresent = false; // Assume failure
XMSAvail = 0;
asm mov ax,0x4300
asm int XMS_INT // Check for presence of XMS driver
if (_AL != 0x80)
goto error;
asm mov ax,0x4310
asm int XMS_INT // Get address of XMS driver
asm mov [WORD PTR XMSDriver],bx
asm mov [WORD PTR XMSDriver+2],es // function pointer to XMS driver
XMS_CALL(XMS_QUERYFREE); // Find out how much XMS is available
XMSAvail = _AX;
if (!_AX) // AJR: bugfix 10/8/92
goto error;
XMSAvail &= ~(PMPageSizeKB - 1); // Round off to nearest page size
if (XMSAvail < (PMPageSizeKB * 2)) // Need at least 2 pages
goto error;
_DX = XMSAvail;
XMS_CALL(XMS_ALLOC); // And do the allocation
XMSHandle = _DX;
if (!_AX) // AJR: bugfix 10/8/92
{
XMSAvail = 0;
goto error;
}
mminfo.XMSmem += XMSAvail * 1024;
XMSPresent = true;
error:
return(XMSPresent);
}
//
//
// PML_StartupMainMem() - Allocates as much main memory as is possible for
// the Page Mgr. The memory is allocated as non-purgeable, so if it's
// necessary to make requests of the Memory Mgr, PM_UnlockMainMem()
// needs to be called.
//
extern boolean MainPresent;
extern memptr MainMemPages[PMMaxMainMem];
extern PMBlockAttr MainMemUsed[PMMaxMainMem];
extern int MainPagesAvail;
void
PML_StartupMainMem(void)
{
int i,n;
memptr *p;
MainPagesAvail = 0;
MM_BombOnError(false);
for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)
{
MM_GetPtr(p,PMPageSize);
if (mmerror)
break;
MainPagesAvail++;
MainMemUsed[i] = pmba_Allocated;
}
MM_BombOnError(true);
if (mmerror)
mmerror = false;
if (MainPagesAvail < PMMinMainMem)
PM_ERROR(PML_STARTUPMAINMEM_LOW);
MainPresent = true;
}
//
// PM_Startup() - Start up the Page Mgr
//
extern boolean PMStarted;
extern char far * far PM_ParmStrings[];
void
PM_Startup(void)
{
boolean nomain,noems,noxms;
int i;
if (PMStarted)
return;
nomain = noems = noxms = false;
for (i = 1;i < _argc;i++)
{
switch (US_CheckParm(_argv[i],PM_ParmStrings))
{
case 0:
nomain = true;
break;
case 1:
noems = true;
break;
case 2:
noxms = true;
break;
}
}
OpenPageFile();
if (!noems)
PML_StartupEMS();
if (!noxms)
PML_StartupXMS();
if (nomain && !EMSPresent)
PM_ERROR(PM_STARTUP_NO_MAIN_EMS);
else
PML_StartupMainMem();
PM_Reset();
PMStarted = true;
}
#endif
///////////////////////////////////////////////////////////////////////////
//
// US_Startup() - Starts the User Mgr
//
///////////////////////////////////////////////////////////////////////////
extern boolean US_Started;
extern char far * far US_ParmStrings[];
extern char far * far US_ParmStrings2[];
extern int USL_HardError(word errval,int ax,int bp,int si);
void
US_Startup(void)
{
int i,n;
if (US_Started)
return;
harderr(USL_HardError); // Install the fatal error handler
US_InitRndT(true); // Initialize the random number generator
for (i = 1;i < _argc;i++)
{
switch (US_CheckParm(_argv[i],US_ParmStrings2))
{
case 0:
compatability = true;
break;
case 1:
compatability = false;
break;
}
}
// Check for TED launching here
for (i = 1;i < _argc;i++)
{
n = US_CheckParm(_argv[i],US_ParmStrings);
switch(n)
{
case 0:
#if 0
tedlevelnum = atoi(_argv[i + 1]);
// if (tedlevelnum >= 0)
tedlevel = true;
#endif
break;
// case 1:
// NoWait = true;
// break;
}
}
US_Started = true;
}
/*
=======================
=
= VL_Startup // WOLFENSTEIN HACK
=
=======================
*/
void VL_Startup (void)
{
int i,videocard;
asm cld;
videocard = VL_VideoID ();
for (i = 1;i < _argc;i++)
if (US_CheckParm(_argv[i],ParmStrings) == 0)
{
videocard = 5;
break;
}
if (videocard != 5)
Quit ("Improper video card! Try the -HIDDENCARD command line parameter!");
}
#if !RESTART_PICTURE_PAUSE
/*
=======================
=
= VL_SetVGAPlaneMode
=
=======================
*/
void VL_SetVGAPlaneMode (void)
{
asm mov ax,0x13
asm int 0x10
VL_DePlaneVGA ();
VGAMAPMASK(15);
VL_SetLineWidth (40);
}
/*
=================
=
= VL_ClearVideo
=
= Fill the entire video buffer with a given color
=
=================
*/
void VL_ClearVideo (byte color)
{
asm mov dx,GC_INDEX
asm mov al,GC_MODE
asm out dx,al
asm inc dx
asm in al,dx
asm and al,0xfc // write mode 0 to store directly to video
asm out dx,al
asm mov dx,SC_INDEX
asm mov ax,SC_MAPMASK+15*256
asm out dx,ax // write through all four planes
asm mov ax,SCREENSEG
asm mov es,ax
asm mov al,[color]
asm mov ah,al
asm mov cx,0x8000 // 0x8000 words, clearing 8 video bytes/word
asm xor di,di
asm rep stosw
}
/*
=================
=
= VL_DePlaneVGA
=
=================
*/
void VL_DePlaneVGA (void)
{
//
// change CPU addressing to non linear mode
//
//
// turn off chain 4 and odd/even
//
outportb (SC_INDEX,SC_MEMMODE);
outportb (SC_INDEX+1,(inportb(SC_INDEX+1)&~8)|4);
outportb (SC_INDEX,SC_MAPMASK); // leave this set throughought
//
// turn off odd/even and set write mode 0
//
outportb (GC_INDEX,GC_MODE);
outportb (GC_INDEX+1,inportb(GC_INDEX+1)&~0x13);
//
// turn off chain
//
outportb (GC_INDEX,GC_MISCELLANEOUS);
outportb (GC_INDEX+1,inportb(GC_INDEX+1)&~2);
//
// clear the entire buffer space, because int 10h only did 16 k / plane
//
VL_ClearVideo (0);
//
// change CRTC scanning from doubleword to byte mode, allowing >64k scans
//
outportb (CRTC_INDEX,CRTC_UNDERLINE);
outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1)&~0x40);
outportb (CRTC_INDEX,CRTC_MODE);
outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1)|0x40);
}
/*
====================
=
= VL_SetLineWidth
=
= Line witdh is in WORDS, 40 words is normal width for vgaplanegr
=
====================
*/
void VL_SetLineWidth (unsigned width)
{
int i,offset;
//
// set wide virtual screen
//
outport (CRTC_INDEX,CRTC_OFFSET+width*256);
//
// set up lookup tables
//
linewidth = width*2;
offset = 0;
for (i=0;i<MAXSCANLINES;i++)
{
ylookup[i]=offset;
offset += linewidth;
}
}
#endif
/*
==================
=
= BuildTables
=
= Calculates:
=
= scale projection constant
= sintable/costable overlapping fractional tables
=
==================
*/
const float radtoint = (float)FINEANGLES/2/PI;
void BuildTables (void)
{
int i;
float angle,anglestep;
double tang;
fixed value;
byte far * temp;