-
Notifications
You must be signed in to change notification settings - Fork 0
/
VC.CC
2346 lines (2009 loc) · 43.6 KB
/
VC.CC
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
/*
Copyright (C) 1998 BJ Eirich (aka vecna)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
// ³ The VERGE Engine ³
// ³ Copyright (C)1998 BJ Eirich (aka vecna) ³
// ³ VergeC Interpreter Core module ³
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// NOTES:
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// CHANGELOG:
// <vecna, aug 2>
// + changed vc var TIMER to address vctimer, not timer_count
// timer_count is zeroed after each call to ExecuteEvent, and not zeroed
// for hooked events.
// <aen, may 14>
// + added PaletteMorph() rgb truncation (<0=0, >63=63)
// <zero 5.8.99>
// + Mistake in PaletteMorph()? was not setting global pal2[], only a local
// copy
// <aen, may 7>
// + added division-by-zero protection for Random()
// <aen, may 5>
// + altered vec's vc_Silhouette() to use new silhouette vdriver routines
// instead of allocating mem, generating mask, calling sprite routines,
// then freeing mem.
// + added vc_SilhouetteScale, vc_Tint, & vc_TintScale (unimplemented)
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//#define VC_H
#include <math.h>
#include "verge.h"
#include "vccode.h"
#include "sincos.h"
#include "mouse.h"
#include "mikmod.h"
#define USERFUNC_MARKER 10000
// prototypes
void CheckHookTimer();
void HookTimer();
// ================================= Data ====================================
int v2_touchy =0;
char* sysvc =0;
char* mapvc =0;
char* basevc =0; // VC pool ptrs
char* code =0; // VC current instruction pointer (IP)
int* globalint =0; // system.vc global int variables
int maxint =0; // maximum allocated # of ints
//char *stringbuf;
string* vc_strings =0; // vc string workspace
int stralloc =0;
int vcreturn =0; // return value of last function
char* movescriptbuf =0; // VC EntityMove buffer
char vctrack =0; // VC call tracking to verge.log
quad* vcstack =0; // VC stack (seperate from main stack)
quad* vcsp =0; // VC stack pointer [esp]
int mapevents =0; // number of map events in this VC
int* event_offsets =0; // map VC offset table
//char* mapvctbl[1024] ={0}; // map VC offset table
// event offset marker
int hookretrace =0;
int hooktimer =0;
int invc =0;
char kill =0;
// FUNC/STR/VAR ARRAYS
funcdecl* funcs =0;
int numfuncs =0;
strdecl* str =0;
int numstr =0;
vardecl* vars =0;
int numvars =0;
// LOCAL FUNC VARS
// *****
#define NEW_LOCALS
// *****
#ifdef NEW_LOCALS // *****
//#define DEBUG_LOCALS
static int int_stack[1024 +20];
static int int_stack_base=0, int_stack_ptr=0;
static string str_stack[1024 +20];
static int str_stack_base=0, str_stack_ptr=0;
static int int_base[1024 +20];
static int str_base[1024 +20];
static int base_ptr=0;
static int int_last_base=0;
static int str_last_base=0;
static void PushBase(int ip, int sp)
{
if (base_ptr<0 || base_ptr>=1024)
Sys_Error("PushBase: DEI!");
int_base[base_ptr]=ip;
str_base[base_ptr]=sp;
base_ptr++;
}
static void PopBase()
{
if (base_ptr<=0 || base_ptr>1024)
Sys_Error("PushBase: DEI!");
base_ptr--;
int_stack_base=int_base[base_ptr];
str_stack_base=str_base[base_ptr];
}
static void PushInt(int n)
{
if (int_stack_ptr<0 || int_stack_ptr>=1024)
Sys_Error("PushInt: DEI!");
int_stack[int_stack_ptr]=n;
#ifdef DEBUG_LOCALS
Log(va("base=%-04d, push# %d", int_stack_base, int_stack[int_stack_ptr]));
#endif
int_stack_ptr++;
}
static int PopInt()
{
if (int_stack_ptr<=0 || int_stack_ptr>1024)
Sys_Error("PopInt: DEI!");
--int_stack_ptr;
#ifdef DEBUG_LOCALS
Log(va("base=%-04d, pop# %d", int_stack_base, int_stack[int_stack_ptr]));
#endif
return int_stack[int_stack_ptr];
}
static void PushStr(string s)
{
if (str_stack_ptr<0 || str_stack_ptr>=1024)
Sys_Error("PushStr: DEI!");
str_stack[str_stack_ptr]=s;
#ifdef DEBUG_LOCALS
Log(va("base=%-04d, push$ %-60s", str_stack_base, str_stack[str_stack_ptr].c_str()));
#endif
str_stack_ptr++;
}
static string PopStr()
{
if (str_stack_ptr<=0 || str_stack_ptr>1024)
Sys_Error("PopStr: DEI!");
--str_stack_ptr;
#ifdef DEBUG_LOCALS
Log(va("base=%-04d, pop$ %-60s", str_stack_base, str_stack[str_stack_ptr].c_str()));
#endif
return str_stack[str_stack_ptr];
}
#else // OLD LOCALS
#define MAX_ARGS 20
#define MAX_LOCAL_STRINGS 10
struct lvars
{
int nargs[MAX_ARGS];
string s[MAX_LOCAL_STRINGS];
};
static lvars lvar;
#endif // !def NEW_LOCALS
// PROTOTYPES /////////////////////////////////////////////////////////////////////////////////////
string ResolveString();
void ExecuteSection();
void ExecuteEvent(int i);
void ExecuteUserFunc(int i);
int ProcessOperand(); // Mutually dependant functions suck.
int ProcessIfOperand(); // Hell yeah they do, bitch.
void HandleExternFunc();
void HandleStdLib();
void ExecuteBlock();
// CODE ///////////////////////////////////////////////////////////////////////////////////////////
static int sys_codesize=0;
static char* absolute_sys=0;
void LoadSystemIndex()
{
VFILE* f;
// open system script variable/function/string offset table file
f=vopen("system.idx");
if (!f)
{
//Sys_Error("Could not open system.idx.");
numvars=0;
numfuncs=0;
numstr=0;
return;
}
// read # variables
vread(&numvars, 4, f);
if (numvars)
{
vars = (vardecl *)valloc(numvars * sizeof(vardecl), "LoadSystemVC$vars", OID_VC);
vread(vars, numvars*48, f);
}
// read # functions
vread(&numfuncs, 4, f);
if (numfuncs)
{
funcs=(funcdecl *)valloc(numfuncs * sizeof(funcdecl), "LoadSystemVC$funcs", OID_VC);
vread(funcs, numfuncs*76, f);
}
// read # strings
vread(&numstr, 4, f);
if (numstr < 1)
numstr = 1;
str=(strdecl *)valloc(numstr * sizeof(strdecl), "LoadSystemVC$str", OID_VC);
vread(str, numstr*48, f);
// done w/ this file
vclose(f);
}
void LoadSystemCode()
{
VFILE* f;
// open system script code file
f=vopen("system.vcs");
if (!f)
{
//Sys_Error("Could not open system.vcs");
sys_codesize=0;
sysvc=0;
absolute_sys=sysvc;
numfuncs=0;
maxint=0;
stralloc=0;
return;
}
// grab system script code size and allocate a buffer for it
sys_codesize=filesize(f);
sysvc=(char *) valloc(sys_codesize, "LoadSystemVC$sysvc", OID_VC);
absolute_sys=sysvc;
// how many funcs, global ints, and global strings?
vread(&numfuncs, 4, f);
vread(&maxint, 4, f);
vread(&stralloc, 4, f);
// allocate global integer and string arrays
if (maxint)
{
globalint=(int *)valloc(4 * maxint, "globalint", OID_VC);
}
if (stralloc)
{
vc_strings=new string[stralloc]; //(string *)valloc(sizeof(string) * stralloc, "vc_strings", OID_VC);
}
// read in system script code
vread(sysvc, sys_codesize, f);
vclose(f);
}
void RunSystemAutoexec()
{
int n;
for (n=0; n<numfuncs; n++)
{
char* x=funcs[n].fname;
V_strlwr(x);
if (!V_strcmp(x,"autoexec"))
break;
}
if (n<numfuncs)
ExecuteUserFunc(n);
else
Sys_Error("No AutoExec() found in system scripts.");
}
void LoadSystemVC()
{
Log("Initializing VC interpreter");
LoadSystemIndex();
LoadSystemCode();
// initialize VC stack
vcstack=(quad *)valloc(6000, "vcstack", OID_VC);
vcsp=vcstack;
movescriptbuf=(char *)valloc(256*256, "movescriptbuf", OID_VC);
Log(va("system vclib init: %d funcs, %d ints (%d bytes), %d strings",
numfuncs, numvars, maxint*4, numstr, stralloc));
RunSystemAutoexec();
}
static int map_codesize=0;
static char* absolute_map=0;
void LoadMapVC(VFILE *f)
{
//int codesize=0;
vread(&mapevents, 4, f);
if (event_offsets)
delete[] event_offsets;
event_offsets=new int[mapevents];
if (!event_offsets)
{
Sys_Error("LoadMapVC: memory exhausted on event_offsets");
}
vread(event_offsets, 4*mapevents, f);
vread(&map_codesize, 4, f);
mapvc=(char *) valloc(map_codesize, "mapvc", OID_VC);
absolute_map=mapvc;
vread(mapvc, map_codesize, f);
}
byte GrabC()
{
/*
if (basevc==absolute_map)
{
if (code<absolute_map || code>=absolute_map+map_codesize)
{
if (code<absolute_map)
Sys_Error("mapvc: GrabC: out of range by -%d; (%08X:%08X)", absolute_map-code, absolute_map, code);
else
Sys_Error("mapvc: GrabC: out of range by +%d; (%08X:%08X)", code-absolute_map, absolute_map, code);
}
}
else if (basevc==absolute_sys)
{
if (code<absolute_sys || code>=absolute_sys+sys_codesize)
{
if (code<absolute_sys)
Sys_Error("sysvc: GrabC: out of range by -%d; (%08X:%08X)", absolute_sys-code, absolute_sys, code);
else
Sys_Error("sysvc: GrabC: out of range by +%d; (%08X:%08X)", code-absolute_sys, absolute_sys, code);
}
}
else
Sys_Error("GrabC: foul things afoot");
*/
return *code++;
}
word GrabW(void)
{
/*
if (basevc==absolute_map)
{
if (code+2-1<absolute_map || code+2-1>=absolute_map+map_codesize)
{
if (code+2-1<absolute_map)
Sys_Error("mapvc: GrabW: out of range by -%d; (%08X:%08X)", absolute_map-(code+2-1), absolute_map, code);
else
Sys_Error("mapvc: GrabW: out of range by +%d; (%08X:%08X)", (code+2-1)-absolute_map, absolute_map, code);
}
}
else if (basevc==absolute_sys)
{
if (code+2-1<absolute_sys || code+2-1>=absolute_sys+sys_codesize)
{
if (code+2-1<absolute_sys)
Sys_Error("sysvc: GrabW: out of range by -%d; (%08X:%08X)", absolute_sys-(code+2-1), absolute_sys, code);
else
Sys_Error("sysvc: GrabW: out of range by +%d; (%08X:%08X)", (code+2-1)-absolute_sys, absolute_sys, code);
}
}
else
Sys_Error("GrabW: foul things afoot");
*/
code+=2;
return *(word *)(code-2);
}
quad GrabD(void)
{
/*
if (basevc==absolute_map)
{
if (code+4-1<absolute_map || code+4-1>=absolute_map+map_codesize)
{
if (code+4-1<absolute_map)
Sys_Error("mapvc: GrabD: out of range by -%d; (%d:%d)", absolute_map-(code+4-1), absolute_map, code);
else
Sys_Error("mapvc: GrabD: out of range by +%d; (%d:%d)", (code+4-1)-absolute_map, absolute_map, code);
}
}
else if (basevc==absolute_sys)
{
if (code+4-1<absolute_sys || code+4-1>=absolute_sys+sys_codesize)
{
if (code+4-1<absolute_sys)
Sys_Error("sysvc: GrabD: out of range by -%d; (%d:%d)", absolute_sys-(code+4-1), absolute_sys, code);
else
Sys_Error("sysvc: GrabD: out of range by +%d; (%d:%d)", (code+4-1)-absolute_sys, absolute_sys, code);
}
}
else
Sys_Error("GrabD: foul things afoot");
*/
code+=4;
return *(quad *)(code-4);
}
string GrabString()
{
string ret;
int c;
char temp[32+1]; // soften the blow
ret="";
c=0;
while (*code)
{
temp[c++]=GrabC(); //*code++;
if (c>=32)
{
c=temp[c]='\0';
ret+=temp;
}
}
if (c)
{
temp[c]='\0';
ret+=temp;
}
code++;
return ret;
}
int ReadInt(char category, int loc, int ofs)
{
switch (category)
{
case op_UVAR:
if (loc<0 || loc>=maxint)
Sys_Error("ReadInt: bad offset to globalint (var)");
return globalint[loc];
case op_UVARRAY:
if (loc<0 || loc>=maxint)
Sys_Error("ReadInt: bad offset to globalint (arr)");
return globalint[loc];
case op_HVAR0:
switch (loc)
{
case 0: return xwin;
case 1: return ywin;
case 2: return cameratracking;
case 3: return vctimer;
case 4: return up;
case 5: return down;
case 6: return left;
case 7: return right;
case 8: return b1;
case 9: return b2;
case 10: return b3;
case 11: return b4;
case 12: return screen_width;
case 13: return screen_length;
case 14: return playernum;
case 15: return cc;
case 16: return tracker;
case 17: return Mouse_X();
case 18: return Mouse_Y();
case 19: return Mouse_ButtonFlags();
case 20: return vctrack;
case 21: return Image_Width();
case 22: return Image_Length();
case 23: return mp_volume;
case 24: return (int)vsp;
case 25: return lastent;
case 26: return key_lastpress; //key_last(); //last_pressed;
case 27: return layer[0].sizex;
case 28: return layer[0].sizey;
case 29: return vsync;
case 30: return entities;
}
case op_HVAR1:
switch (loc)
{
case 0:
if (ofs<0 || ofs>=screen_width*screen_length)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to screen[]: %d (base: $%08X, %dx%d)",
ofs, (int) screen, screen_width, screen_length);
return 0;
}
return hicolor
? ((unsigned short *) screen)[ofs]
: screen[ofs];
case 1:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.x[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].x;
case 2:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.y[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].y;
case 3:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.tx[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].tx;
case 4:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.ty[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].ty;
case 5:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.facing[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].facing;
case 6:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.moving[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].moving;
case 7:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.specframe[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].specframe;
case 8:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.speed[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].speed;
case 9:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.movecode[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].movecode;
case 10:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entidx[]: %d (%d total)",
ofs, entities);
return 0;
}
return entidx[ofs];
case 11:
if (ofs<0 || ofs>=128)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to key[]: %d", ofs);
return 0;
}
return key_down[scantokey[ofs]];
case 12:
if (ofs<0 || ofs>=numlayers)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to layer.hline[]: %d (%d total)",
ofs, numlayers);
return 0;
}
return layer[ofs].hline;
case 13: return (int) (*(byte *)ofs);
case 14: return (int) (*(word *)ofs);
case 15: return (int) (*(quad *)ofs);
case 16:
if (ofs<0 || ofs>=3*256)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to pal[]: %d", ofs);
return 0;
}
return (int) game_palette[ofs];
case 17: return (int) (*(char *)ofs);
case 18: return (int) (*(short*)ofs);
case 19: return (int) (*(int *)ofs);
/*
// Modified by Pyro
case 20:
if (ofs<0 || ofs>=entities)
return 0;
//Sys_Error("ReadInt: bad offset to entity.x");
return chr[entity[ofs].chrindex].hx;
case 21:
if (ofs<0 || ofs>=entities)
return 0;
//Sys_Error("ReadInt: bad offset to entity.x");
return chr[entity[ofs].chrindex].hy;
case 22:
if (ofs<0 || ofs>=entities)
return 0;
// Sys_Error("ReadInt: bad offset to entity.x");
return chr[entity[ofs].chrindex].hw;
case 23:
if (ofs<0 || ofs>=entities)
return 0;
//Sys_Error("ReadInt: bad offset to entity.x");
return chr[entity[ofs].chrindex].hh;
*/
case 20:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.isob[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].obsmode2;
case 21:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.canob[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].obsmode1;
case 22:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("ReadInt: bad offset to entity.autoface[]: %d (%d total)",
ofs, entities);
return 0;
}
return entity[ofs].face;
}
case op_LVAR:
if (loc<0 || loc>19)
{
Sys_Error("ReadInt: bad offset to local ints: %d", loc);
}
#ifdef NEW_LOCALS
#ifdef DEBUG_LOCALS
Log(va("op_LVAR: int_stack_base=%d, loc=%d", int_stack_base, loc));
#endif
return int_stack[int_stack_base+loc];
#else // OLD LOCALS
return lvar.nargs[loc];
#endif
default:
Sys_Error("VC Execution error: Invalid ReadInt category %d", (int) category);
}
return 0;
}
void WriteInt(char category, int loc, int ofs, int value)
{
switch (category)
{
case op_UVAR:
if (loc<0 || loc>=maxint)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to globalint (var)");
break;
}
globalint[loc]=value;
break;
case op_UVARRAY:
if (loc<0 || loc>=maxint)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to globalint (arr)");
break;
}
globalint[loc]=value;
break;
case op_HVAR0:
switch (loc)
{
case 0: xwin=value; return;
case 1: ywin=value; return;
case 2: cameratracking=(byte)value; return;
case 3: vctimer=value; return;
case 16: tracker=(byte)value; return;
case 17: Mouse_SetPosition(value, Mouse_Y()); return;
case 18: Mouse_SetPosition(Mouse_X(), value); return;
case 19: Mouse_ButtonSetFlags(value); return;
case 20: vctrack=(char)value; return;
case 23: mp_volume=(UBYTE)value; return;
case 26: key_lastpress=value; return;
case 29: vsync=value; return;
}
case op_HVAR1:
switch (loc)
{
case 0:
if (ofs < 0 || ofs >= screen_width*screen_length)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to screen[]: %d (dest: $%08X, %dx%d)",
ofs, (int) screen, screen_width, screen_length);
return;
}
screen[ofs] = (byte) value;
return;
case 1:
if (ofs<0 || ofs>=entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.x[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].x=value;
return;
case 2:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.y[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].y = value;
return;
case 3:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.tx[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].tx = (word) value;
return;
case 4:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.ty[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].ty = (word) value;
return;
case 5:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.facing[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].facing = (byte) value;
return;
case 6:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.moving[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].moving = (byte) value;
return;
case 7:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.specframe[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].specframe = (byte) value;
return;
case 8:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.speed[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].speed = (byte) value;
return;
case 9:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.movecode[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].movecode = (byte) value;
return;
//case 10:
case 11:
if (ofs < 0 || ofs >= 128)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to key[]: %d (%d total)",
ofs, entities);
return;
}
key_down[scantokey[ofs]] = value;
return;
case 12:
if (ofs < 0 || ofs >= numlayers)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to layer.hline[]: %d (%d total)", ofs, numlayers);
return;
}
layer[ofs].hline = (unsigned char) value;
return;
case 13: (*(byte *)ofs)=(byte) value; return;
case 14: (*(word *)ofs)=(word) value; return;
case 15: (*(quad *)ofs)=(quad) value; return;
case 16:
if (ofs < 0 || ofs >= 3*256)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to game_palette[]: %d", ofs);
return;
}
game_palette[ofs] = (byte) value;
return;
case 17: (*(char *)ofs)=(byte) value; return;
case 18: (*(short*)ofs)=(word) value; return;
case 19: (*(int *)ofs)=(quad) value; return;
case 20:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.isob[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].obsmode2 = (byte) value;
return;
case 21:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.canob[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].obsmode1 = (byte) value;
return;
case 22:
if (ofs < 0 || ofs >= entities)
{
if (v2_touchy)
Sys_Error("WriteInt: bad offset to entity.autoface[]: %d (%d total)",
ofs, entities);
return;
}
entity[ofs].face = (byte) value;
return;
}
case op_LVAR:
if (loc<0 || loc>19)
{
Sys_Error("WriteInt: bad offset to local ints: %d", loc);
}
#ifdef NEW_LOCALS
int_stack[int_stack_base+loc]=value;
#else // OLD LOCALS
lvar.nargs[loc]=value;
#endif
return;
default:
Sys_Error("VC Execution error: Invalid WriteInt category %d", (int) category);
}
}
int ResolveOperand()
{
int cr=0;
int d=0;
byte c=0;
cr=ProcessOperand(); // Get base number
while (1)
{
c=GrabC();