-
Notifications
You must be signed in to change notification settings - Fork 7
/
jfbuild.patch
1384 lines (1252 loc) · 40.3 KB
/
jfbuild.patch
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
diff --git a/include/build.h b/include/build.h
index 00df940..7eb53f5 100644
--- a/include/build.h
+++ b/include/build.h
@@ -43,19 +43,40 @@ extern "C" {
#define MAXSPRITESV5 4096
#define MAXTILESV5 4096
+#ifdef EMBEDDED
+extern unsigned maxcache1dsize;
+extern char playanm_flag;
+int can_allocache(size_t);
+#define MAXSECTORS MAXSECTORSV7
+#ifndef MAXWALLS
+#define MAXWALLS MAXWALLSV7
+#endif
+#ifndef MAXSPRITES
+#define MAXSPRITES MAXSPRITESV7
+#endif
+#ifndef MAXTILES
+#define MAXTILES 9216
+#endif
+#define MAXVOXELS 80
+#else
#define MAXSECTORS MAXSECTORSV8
#define MAXWALLS MAXWALLSV8
#define MAXSPRITES MAXSPRITESV8
#define MAXTILES 9216
#define MAXVOXELS 4096
+#endif
#define MAXSTATUS 1024
#define MAXPLAYERS 16
+#if !defined(MAXXDIM) && !defined(MAXYDIM)
#define MAXXDIM 2880
#define MAXYDIM 1800
+#endif
#define MAXPALOOKUPS 256
#define MAXPSKYTILES 256
+#ifndef MAXSPRITESONSCREEN
#define MAXSPRITESONSCREEN 2048
+#endif
#define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites
#define CLIPMASK0 (((1L)<<16)+1L)
@@ -116,7 +137,12 @@ typedef struct
signed char floorshade;
unsigned char floorpal, floorxpanning, floorypanning;
unsigned char visibility, filler;
+#ifdef __cplusplus
+ union { short lotag, type; };
+ short hitag, extra;
+#else
short lotag, hitag, extra;
+#endif
} sectortype;
//cstat:
@@ -140,7 +166,12 @@ typedef struct
short picnum, overpicnum;
signed char shade;
unsigned char pal, xrepeat, yrepeat, xpanning, ypanning;
+#ifdef __cplusplus
+ union { short lotag, type; };
+ short hitag, extra;
+#else
short lotag, hitag, extra;
+#endif
} walltype;
//cstat:
@@ -168,8 +199,18 @@ typedef struct
unsigned char xrepeat, yrepeat;
signed char xoffset, yoffset;
short sectnum, statnum;
+#ifdef __cplusplus
+ short ang, owner;
+ union { short xvel, index; };
+ short yvel;
+ union { short zvel, inittype; };
+ union { short lotag, type; };
+ union { short hitag, flags; };
+ short extra;
+#else
short ang, owner, xvel, yvel, zvel;
short lotag, hitag, extra;
+#endif
} spritetype;
// 12 bytes
@@ -186,7 +227,9 @@ typedef struct {
EXTERN sectortype sector[MAXSECTORS];
EXTERN walltype wall[MAXWALLS];
EXTERN spritetype sprite[MAXSPRITES];
+#if USE_POLYMOST && USE_OPENGL
EXTERN spriteexttype spriteext[MAXSPRITES+MAXUNIQHUDID];
+#endif
EXTERN int guniqhudid;
EXTERN int spritesortcnt;
@@ -197,7 +240,11 @@ EXTERN spritetype tsprite[MAXSPRITESONSCREEN];
EXTERN int xdim, ydim, ylookup[MAXYDIM+1], numpages;
EXTERN int yxaspect, xyaspect, pixelaspect, widescreen, tallscreen, viewingrange;
+#if EMBEDDED == 2
+#define MAXVALIDMODES 2
+#else
#define MAXVALIDMODES 256
+#endif
EXTERN int validmodecnt;
struct validmode_t {
int xdim,ydim;
@@ -211,7 +258,11 @@ EXTERN struct validmode_t validmode[MAXVALIDMODES];
EXTERN short numsectors, numwalls;
EXTERN /*volatile*/ int totalclock;
EXTERN int numframes, randomseed;
+#if NO_FLOAT && defined(ENGINE)
+#include "engine_tables.h"
+#else
EXTERN short sintable[2048];
+#endif
EXTERN unsigned char palette[768];
EXTERN short numpalookups;
EXTERN unsigned char *palookup[MAXPALOOKUPS];
@@ -230,7 +281,9 @@ EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES];
EXTERN unsigned char walock[MAXTILES];
+#ifndef __cplusplus
EXTERN int numtiles, picanm[MAXTILES];
+#endif
EXTERN intptr_t waloff[MAXTILES];
//These variables are for auto-mapping with the draw2dscreen function.
diff --git a/include/compat.h b/include/compat.h
index 387f121..f977f3e 100644
--- a/include/compat.h
+++ b/include/compat.h
@@ -42,7 +42,7 @@
#define _CRT_DECLARE_NONSTDC_NAMES 0
#endif
-#ifdef __cplusplus
+#if defined(__cplusplus) && !defined(EMBEDDED)
# include <cerrno>
# include <climits>
# include <cstdarg>
@@ -209,7 +209,11 @@ static inline float B_SWAPFLOAT(float f) {
// On Windows, _MAX_PATH is 260, null included.
// POSIX says 256 is the most it will write into a user buffer of unspecified size, null included.
// X/Open says 1024 for the same purposes as POSIX.
+#ifdef EMBEDDED
+#define BMAX_PATH 64
+#else
#define BMAX_PATH 1024
+#endif
// Definitely not BSD/POSIX dirent.h.
struct Bdirent {
@@ -396,6 +400,33 @@ int Bwildmatch (const char *i, const char *j);
# define Btime time
#endif
+#ifdef EMBEDDED
+static inline void write32_le(void *p, unsigned a) {
+ uint8_t *d = (uint8_t*)p; d[0] = a; d[1] = a >> 8;
+ d[2] = a >> 16; d[3] = a >> 24;
+}
+
+static inline int read32_le(const void *p) {
+ const uint8_t *s = (const uint8_t*)p;
+ return s[0] | s[1] << 8 | s[2] << 16 | s[3] << 24;
+}
+
+static inline int read16u_le(const void *p) {
+ const uint8_t *s = (const uint8_t*)p;
+ return s[0] | s[1] << 8;
+}
+
+static inline int read16s_le(const void *p) {
+ const uint8_t *s = (const uint8_t*)p;
+ return s[0] | ((const int8_t*)s)[1] << 8;
+}
+#else
+static inline void write32_le(void *p, unsigned a) { *(uint32_t*)p = a; }
+static inline int read32_le(const void *p) { return *(uint32_t*)p; }
+static inline int read16u_le(const void *p) { return *(uint16_t*)p; }
+static inline int read16s_le(const void *p) { return *(int16_t*)p; }
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/include/osd.h b/include/osd.h
index 348b42b..0008608 100644
--- a/include/osd.h
+++ b/include/osd.h
@@ -20,6 +20,29 @@ typedef struct {
extern "C" {
#endif
+#if NO_OSD
+static inline void OSD_Init(void) {}
+static inline void OSD_SetFunctions(
+ void (*drawchar)(int,int,char,int,int),
+ void (*drawstr)(int,int,char*,int,int,int),
+ void (*drawcursor)(int,int,int,int),
+ int (*colwidth)(int),
+ int (*rowheight)(int),
+ void (*clearbg)(int,int),
+ int (*gettime)(void),
+ void (*onshow)(int)) {}
+static inline int OSD_CaptureKey(int sc) { return 0x45; }
+static inline int OSD_HandleChar(int ch) { return 1; }
+static inline int OSD_HandleKey(int sc, int press) { return 1; }
+static inline void OSD_ResizeDisplay(int w, int h) {}
+static inline void OSD_ShowDisplay(int onf) {}
+static inline void OSD_Draw(void) {}
+static inline void OSD_Printf(const char *fmt, ...) {}
+static inline void OSD_Puts(const char *str) {}
+static inline void OSD_DispatchQueued(void) {}
+static inline int OSD_RegisterFunction(const char *name, const char *help,
+ int (*func)(const osdfuncparm_t*)) { return -1; }
+#else
// initializes things
void OSD_Init(void);
@@ -80,6 +103,7 @@ int OSD_Dispatch(const char *cmd);
// help = a short help string
// func = the entry point to the function
int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const osdfuncparm_t*));
+#endif
#ifdef __cplusplus
}
diff --git a/include/scriptfile.h b/include/scriptfile.h
index 220b37e..a30b2f8 100644
--- a/include/scriptfile.h
+++ b/include/scriptfile.h
@@ -21,6 +21,7 @@ char *scriptfile_peektoken(scriptfile *sf);
int scriptfile_getnumber(scriptfile *sf, int *num);
int scriptfile_gethex(scriptfile *sf, int *num); // For reading specifically hex without requiring an 0x prefix
int scriptfile_getdouble(scriptfile *sf, double *num);
+int scriptfile_getfixed16(scriptfile *sf, int *num);
int scriptfile_getstring(scriptfile *sf, char **st);
int scriptfile_getsymbol(scriptfile *sf, int *num);
int scriptfile_getlinum(scriptfile *sf, char *ptr);
diff --git a/src/baselayer.c b/src/baselayer.c
index 2982655..d90748e 100644
--- a/src/baselayer.c
+++ b/src/baselayer.c
@@ -69,8 +69,10 @@ int checkvideomode(int *x, int *y, int c, int fs, int forced)
// fix up the passed resolution values to be multiples of 8
// and at least 320x200 or at most MAXXDIMxMAXYDIM
+#ifndef EMBEDDED
if (*x < 320) *x = 320;
if (*y < 200) *y = 200;
+#endif
if (*x > MAXXDIM) *x = MAXXDIM;
if (*y > MAXYDIM) *y = MAXYDIM;
*x &= 0xfffffff8l;
diff --git a/src/baselayer_priv.h b/src/baselayer_priv.h
index 3537fe8..7f7ed76 100644
--- a/src/baselayer_priv.h
+++ b/src/baselayer_priv.h
@@ -9,7 +9,9 @@ extern char modechange;
extern char videomodereset;
// undefine to restrict windowed resolutions to conventional sizes
+#ifndef EMBEDDED
#define ANY_WINDOWED_SIZE
+#endif
int baselayer_init(void);
diff --git a/src/cache1d.c b/src/cache1d.c
index 95a27a7..504fa2a 100644
--- a/src/cache1d.c
+++ b/src/cache1d.c
@@ -5,7 +5,9 @@
// This file has been modified from Ken Silverman's original release
// by Jonathon Fowler ([email protected])
+#ifndef EMBEDDED
#define WITHKPLIB
+#endif
#include "build.h"
#include "cache1d.h"
@@ -58,7 +60,9 @@ static int kzipopen(const char *filnam)
// After calling uninitcache, it is still ok to call allocache
// without first calling initcache.
+#ifndef MAXCACHEOBJECTS
#define MAXCACHEOBJECTS 9216
+#endif
static size_t cachesize = 0;
int cachecount = 0;
@@ -95,6 +99,12 @@ void initcache(void *dacachestart, size_t dacachesize)
buildprintf("initcache(): Initialised with %zu bytes\n", cachesize);
}
+#ifdef EMBEDDED
+int can_allocache(size_t newbytes) {
+ return newbytes + 16 < cachesize;
+}
+#endif
+
void allocache(void **newhandle, size_t newbytes, unsigned char *newlockptr)
{
int z, zz, bestz=0, suckz;
@@ -297,6 +307,34 @@ int addsearchpath(const char *p)
int findfrompath(const char *fn, char **where)
{
+#ifdef EMBEDDED
+ // try to open "tilesNNN.art" outside the archive only once
+ // because these files are often opened during the game
+ char *dup;
+ unsigned i = 0, k = 0x80000000;
+ static unsigned artmask = 0, artcase = 0;
+ if (*fn == 't' && !memcmp(fn + 1, "iles0", 5)) {
+ unsigned x;
+#define X(j) (k = k * 10 + (x = fn[j] - '0'), x < 10) &&
+ if (X(6) X(7) k < 32 && !strcmp(fn + 8, ".art")) {
+#undef X
+ if (artmask >> k & 1) return -1;
+ i = artcase >> k & 1;
+ } else k = -1;
+ }
+ dup = strdup(fn);
+ do {
+ if (i) strupr(dup);
+ if (access(dup, F_OK) >= 0) {
+ if (k < 32) artcase |= i << k;
+ *where = dup;
+ return 0;
+ }
+ } while (++i < 2);
+ if (k < 32) artmask |= 1 << k;
+ free(dup);
+ return -1;
+#endif
searchpath_t *sp;
char *pfn, *ffn;
size_t allocsiz;
@@ -358,6 +396,7 @@ int openfrompath(const char *fn, int flags, int mode)
return h;
}
+#ifndef EMBEDDED
BFILE* fopenfrompath(const char *fn, const char *mode)
{
int fh;
@@ -384,6 +423,7 @@ BFILE* fopenfrompath(const char *fn, const char *mode)
return h;
}
+#endif
#define MAXGROUPFILES 4 //Warning: Fix groupfil if this is changed
@@ -882,6 +922,9 @@ void klistfree(CACHE1D_FIND_REC *rec)
CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int type)
{
CACHE1D_FIND_REC *rec = NULL;
+#ifdef EMBEDDED
+ return rec;
+#endif
char *path;
// pathsearchmode == 0: enumerates a path in the virtual filesystem
@@ -1275,8 +1318,13 @@ static int lzwcompress(unsigned char *lzwinbuf, int uncompleng, unsigned char *l
lzwbuf2[addrcnt] = -1;
lzwbuf3[addrcnt] = -1;
+#ifdef EMBEDDED
+ (void)intptr; (void)shortptr;
+ write32_le(&lzwoutbuf[bitcnt>>3], read32_le(&lzwoutbuf[bitcnt>>3])|addr<<(bitcnt&7));
+#else
intptr = (int *)&lzwoutbuf[bitcnt>>3];
intptr[0] |= B_LITTLE32(addr<<(bitcnt&7));
+#endif
bitcnt += numbits;
if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
bitcnt--;
@@ -1285,8 +1333,12 @@ static int lzwcompress(unsigned char *lzwinbuf, int uncompleng, unsigned char *l
if (addrcnt > oneupnumbits) { numbits++; oneupnumbits <<= 1; }
} while ((bytecnt1 < uncompleng) && (bitcnt < (uncompleng<<3)));
+#ifdef EMBEDDED
+ write32_le(&lzwoutbuf[bitcnt>>3], read32_le(&lzwoutbuf[bitcnt>>3])|addr<<(bitcnt&7));
+#else
intptr = (int *)&lzwoutbuf[bitcnt>>3];
intptr[0] |= B_LITTLE32(addr<<(bitcnt&7));
+#endif
bitcnt += numbits;
if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
bitcnt--;
@@ -1322,8 +1374,13 @@ static int lzwuncompress(unsigned char *lzwinbuf, int compleng, unsigned char *l
numbits = 8; oneupnumbits = (1<<8);
do
{
+#ifdef EMBEDDED
+ (void)intptr;
+ dat = (read32_le(&lzwinbuf[bitcnt>>3])>>(bitcnt&7)) & (oneupnumbits-1);
+#else
intptr = (int *)&lzwinbuf[bitcnt>>3];
dat = ((B_LITTLE32(intptr[0])>>(bitcnt&7)) & (oneupnumbits-1));
+#endif
bitcnt += numbits;
if ((dat&((oneupnumbits>>1)-1)) > ((currstr-1)&((oneupnumbits>>1)-1)))
{ dat &= ((oneupnumbits>>1)-1); bitcnt--; }
diff --git a/src/compat.c b/src/compat.c
index 64c27d1..551e468 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -83,6 +83,7 @@ int Bvasprintf(char **ret, const char *format, va_list ap)
* The caller must free the string when done with it.
* @return NULL if it could not be determined
*/
+#ifndef EMBEDDED
char *Bgethomedir(void)
{
char *dir = NULL;
@@ -192,6 +193,7 @@ char *Bgetsupportdir(int global)
return dir;
}
+#endif // EMBEDDED
int Bcorrectfilename(char *filename, int removefn)
{
@@ -543,7 +545,9 @@ int Bwildmatch (const char *i, const char *j)
//
size_t Bgetsysmemsize(void)
{
-#ifdef _WIN32
+#ifdef EMBEDDED
+ return 0x7fffffff;
+#elif defined(_WIN32)
size_t siz = 0x7fffffff;
MEMORYSTATUSEX memst;
diff --git a/src/config.c b/src/config.c
index 3f6d933..df28328 100644
--- a/src/config.c
+++ b/src/config.c
@@ -119,9 +119,11 @@ static struct {
"; Maximum OpenGL mode refresh rate (Windows only, in Hertz)\n"
},
#endif
+#if !NO_MOUSE
{ "mousesensitivity", type_fixed16, &msens,
"; Mouse sensitivity\n"
},
+#endif
{ "keyforward", type_hex, &keys[0],
"; Key Settings\n"
"; Here's a map of all the keyboard scan codes: NOTE: values are listed in hex!\n"
@@ -217,6 +219,13 @@ int loadsetup(const char *fn)
break;
}
case type_fixed16: {
+#if NO_FLOAT
+ int value = 0;
+ if (scriptfile_getfixed16(cfg, &value)) break;
+ *(int*)configspec[item].store = value;
+ break;
+ }
+#else
double value = 0.0;
if (scriptfile_getdouble(cfg, &value)) break;
*(int*)configspec[item].store = (int)(value*65536.0);
@@ -228,6 +237,7 @@ int loadsetup(const char *fn)
*(double*)configspec[item].store = value;
break;
}
+#endif
default: {
buildputs("loadsetup: unhandled value type\n");
break;
@@ -298,6 +308,15 @@ int writesetup(const char *fn)
break;
}
case type_fixed16: {
+#if NO_FLOAT
+ int num = *(int*)configspec[item].store;
+ unsigned a = num < 0 ? -num : num;
+ uint64_t f = ((uint64_t)a * 100000 + 0x8000) >> 16;
+ a = f / 100000; f %= 100000;
+ fprintf(fp, "%s%u.%05u\n", num < 0 ? "-" : "", a, (int)f);
+ break;
+ }
+#else
fprintf(fp, "%g\n", (double)(*(int*)configspec[item].store) / 65536.0);
break;
}
@@ -305,6 +324,7 @@ int writesetup(const char *fn)
fprintf(fp, "%g\n", *(double*)configspec[item].store);
break;
}
+#endif
default: {
fputs("?\n", fp);
break;
diff --git a/src/defs.c b/src/defs.c
index 06634eb..88b5e63 100644
--- a/src/defs.c
+++ b/src/defs.c
@@ -8,6 +8,10 @@
#include "build.h"
#include "baselayer.h"
#include "scriptfile.h"
+#if NO_FLOAT
+#define double int
+#define scriptfile_getdouble scriptfile_getfixed16
+#endif
enum {
T_EOF = -2,
@@ -486,13 +490,16 @@ static int defsparser(scriptfile *script)
break;
}
+#if !NO_VOXELS
for (tilex = ftilenume; tilex <= ltilenume; tilex++) {
tiletovox[tilex] = lastvoxid;
}
+#endif
}
break;
// NEW (ENCOURAGED) DEFINITION SYNTAX
+#if !NO_NEWSTYLE
case T_MODEL:
{
char *modelend, *modelfn;
@@ -751,13 +758,16 @@ static int defsparser(scriptfile *script)
//case T_ERROR: buildprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break;
case T_TILE:
scriptfile_getsymbol(script,&tilex);
+#if !NO_VOXELS
if ((unsigned int)tilex < MAXTILES) tiletovox[tilex] = lastvoxid;
else buildprintf("Invalid tile number on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr));
+#endif
break;
case T_TILE0:
scriptfile_getsymbol(script,&tile0); break; //1st tile #
case T_TILE1:
scriptfile_getsymbol(script,&tile1);
+#if !NO_VOXELS
if (tile0 > tile1)
{
buildprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,voxeltokptr));
@@ -766,11 +776,22 @@ static int defsparser(scriptfile *script)
if ((tile1 < 0) || (tile0 >= MAXTILES))
{ buildprintf("Invalid tile range on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); break; }
for(tilex=tile0;tilex<=tile1;tilex++) tiletovox[tilex] = lastvoxid;
+#endif
break; //last tile number (inclusive)
case T_SCALE: {
+#if NO_FLOAT
+ int scale=1<<16;
+ scriptfile_getfixed16(script,&scale);
+#if !NO_VOXELS
+ voxscale[lastvoxid] = scale;
+#endif
+#else
double scale=1.0;
scriptfile_getdouble(script,&scale);
+#if !NO_VOXELS
voxscale[lastvoxid] = 65536*scale;
+#endif
+#endif
break;
}
}
@@ -1011,6 +1032,7 @@ static int defsparser(scriptfile *script)
#endif
}
break;
+#endif
default:
buildputs("Unknown token.\n"); break;
diff --git a/src/engine.c b/src/engine.c
index c7c92b2..b03363a 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -39,10 +39,16 @@
void *kmalloc(bsize_t size) { return(Bmalloc(size)); }
void kfree(void *buffer) { Bfree(buffer); }
+#if !NO_VOXELS
void loadvoxel(int voxindex) { (void)voxindex; }
int tiletovox[MAXTILES];
int usevoxels = 1;
+#ifdef GAME_BLOOD
+#define kloadvoxel _Z10qloadvoxeli
+void kloadvoxel(int32_t);
+#else
#define kloadvoxel loadvoxel
+#endif
int novoxmips = 0;
@@ -57,7 +63,17 @@ int voxscale[MAXVOXELS];
static int ggxinc[MAXXSIZ+1], ggyinc[MAXXSIZ+1];
static int lowrecip[1024], nytooclose, nytoofar;
+#if NO_DISTRECIP
+extern int reciptable[2048];
+extern int xdimen;
+static inline int voxrecip_small(uint32_t x) {
+ unsigned c = x ? __builtin_clz(x) : 0;
+ return ((int64_t)(xdimen << 4) * reciptable[(x<<(c+1))>>21])>>(31-c);
+}
+#else
static unsigned int distrecip[65536];
+#endif
+#endif
static int *lookups = NULL;
int dommxoverlay = 1, beforedrawrooms = 1;
@@ -65,7 +81,9 @@ int dommxoverlay = 1, beforedrawrooms = 1;
static int oxdimen = -1, oviewingrange = -1, oxyaspect = -1;
int curbrightness = 0, gammabrightness = 0;
+#if !NO_FLOAT
float curgamma = 1.0;
+#endif
//Textured Map variables
static unsigned char globalpolytype;
@@ -90,7 +108,10 @@ int artsize = 0;
size_t cachesize = 0;
int editorgridextent = 131072;
-static short radarang[1280], radarang2[MAXXDIM];
+#if !NO_FLOAT
+static short radarang[1280];
+#endif
+static short radarang2[MAXXDIM];
static unsigned short sqrtable[4096], shlookup[4096+256];
unsigned char pow2char[8] = {1,2,4,8,16,32,64,128};
int pow2long[32] =
@@ -106,7 +127,9 @@ int pow2long[32] =
};
int reciptable[2048], fpuasm;
+#if !NO_FLOAT
unsigned char britable[16][256];
+#endif
static char kensmessage[128];
char *engineerrstr = NULL;
@@ -429,11 +452,22 @@ static inline int msqrtasm(unsigned int c)
return a;
}
+#if defined(EMBEDDED) && defined(USE_ASM)
+int krecipasm(int i);
+#else
static inline int krecipasm(int i)
-{ // Ken did this
+{
+#if NO_FLOAT
+ int s = i >> 31; uint32_t x = (i^s)-s;
+ unsigned c = i ? __builtin_clz(x) : 0;
+ return(reciptable[(x<<(c+1))>>21]>>(c^31))^s;
+#else
+ // Ken did this
float f = (float)i; i = *(int *)&f;
return((reciptable[(i>>12)&2047]>>(((i-0x3f800000)>>23)&31))^(i>>31));
+#endif
}
+#endif
static inline int getclipmask(int a, int b, int c, int d)
@@ -491,8 +525,14 @@ unsigned char globparaceilclip, globparaflorclip;
int viewingrangerecip;
+#if defined(EMBEDDED) && defined(USE_ASM)
+extern int asm1, asm2, globalx3, globaly3;
+extern intptr_t asm3;
+int asm4;
+#else
int asm1, asm2, asm4;
intptr_t asm3;
+#endif
int vplce[4], vince[4];
intptr_t palookupoffse[4], bufplce[4];
unsigned char globalxshift, globalyshift;
@@ -500,7 +540,11 @@ int globalxpanning, globalypanning, globalshade;
short globalpicnum, globalshiftval;
int globalzd, globalyscale, globalorientation;
intptr_t globalbufplc;
+#if defined(EMBEDDED) && defined(USE_ASM)
+int globalx1, globaly1, globalx2, globaly2, globalzx;
+#else
int globalx1, globaly1, globalx2, globaly2, globalx3, globaly3, globalzx;
+#endif
int globalx, globaly, globalz;
short sectorborder[256], sectorbordercnt;
@@ -599,6 +643,10 @@ static inline int getpalookup(int davis, int dashade)
{
return(min(max(dashade+(davis>>8),0),numpalookups-1));
}
+#ifdef GAME_BLOOD
+int32_t _Z12qgetpalookupii(int32_t, int32_t);
+#define getpalookup _Z12qgetpalookupii
+#endif
//
@@ -1098,6 +1146,10 @@ static void prepwall(int z, walltype *wal)
//
// animateoffs (internal)
//
+#ifdef GAME_BLOOD
+#define animateoffs _Z12qanimateoffsii
+int animateoffs(int a1, int a2);
+#else
int animateoffs(short tilenum, short fakevar)
{
int i, k, offs;
@@ -1126,6 +1178,7 @@ int animateoffs(short tilenum, short fakevar)
}
return(offs);
}
+#endif
//
@@ -2296,6 +2349,7 @@ static void parascan(int dax1, int dax2, int sectnum, unsigned char dastat, int
{
wallnum = thewall[z]; nextsectnum = wall[wallnum].nextsector;
+ if (nextsectnum < 0) j = 0; else /* ASan */
if (dastat == 0) j = sector[nextsectnum].ceilingstat;
else j = sector[nextsectnum].floorstat;
@@ -2746,6 +2800,7 @@ static void drawalls(int bunch)
//
// drawvox
//
+#if !NO_VOXELS
static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
int daxscale, int dayscale, unsigned char daindex,
signed char dashade, unsigned char dapal, int *daumost, int *dadmost)
@@ -2802,8 +2857,13 @@ static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
dayscalerecip = (1<<30)/dayscale;
longptr = (int *)davoxptr;
+#ifdef EMBEDDED
+ daxsiz = read32_le(&longptr[0]); daysiz = read32_le(&longptr[1]); dazsiz = read32_le(&longptr[2]);
+ daxpivot = read32_le(&longptr[3]); daypivot = read32_le(&longptr[4]); dazpivot = read32_le(&longptr[5]);
+#else
daxsiz = B_LITTLE32(longptr[0]); daysiz = B_LITTLE32(longptr[1]); dazsiz = B_LITTLE32(longptr[2]);
daxpivot = B_LITTLE32(longptr[3]); daypivot = B_LITTLE32(longptr[4]); dazpivot = B_LITTLE32(longptr[5]);
+#endif
davoxptr += (6<<2);
x = mulscale16(globalposx-dasprx,daxscalerecip);
@@ -2901,7 +2961,11 @@ static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
for(x=xs;x!=xe;x+=xi)
{
+#ifdef EMBEDDED
+ slabxoffs = (intptr_t)&davoxptr[read32_le(&longptr[x])];
+#else
slabxoffs = (intptr_t)&davoxptr[B_LITTLE32(longptr[x])];
+#endif
shortptr = (short *)&davoxptr[((x*(daysiz+1))<<1)+xyvoxoffs];
nx = mulscale16(ggxstart+ggxinc[x],viewingrangerecip)+x1;
@@ -2909,10 +2973,26 @@ static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
for(y=ys;y!=ye;y+=yi,nx+=dagyinc,ny-=dagxinc)
{
if ((ny <= nytooclose) || (ny >= nytoofar)) continue;
+#ifdef EMBEDDED
+ voxptr = (unsigned char *)(read16s_le(&shortptr[y])+slabxoffs);
+ voxend = (unsigned char *)(read16s_le(&shortptr[y+1])+slabxoffs);
+#else
voxptr = (unsigned char *)(B_LITTLE16(shortptr[y])+slabxoffs);
voxend = (unsigned char *)(B_LITTLE16(shortptr[y+1])+slabxoffs);
+#endif
if (voxptr == voxend) continue;
+#if NO_DISTRECIP
+ lx = mulscale32(nx>>3,voxrecip_small(ny+y1))+halfxdimen;
+ if (lx < 0) lx = 0;
+ rx = mulscale32((nx+nxoff)>>3,voxrecip_small(ny+y2))+halfxdimen;
+ if (rx > xdimen) rx = xdimen;
+ if (rx <= lx) continue;
+ rx -= lx;
+
+ l1 = voxrecip_small(ny-yoff);
+ l2 = voxrecip_small(ny+yoff);
+#else
lx = mulscale32(nx>>3,distrecip[(ny+y1)>>14])+halfxdimen;
if (lx < 0) lx = 0;
rx = mulscale32((nx+nxoff)>>3,distrecip[(ny+y2)>>14])+halfxdimen;
@@ -2922,6 +3002,7 @@ static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
l1 = distrecip[(ny-yoff)>>14];
l2 = distrecip[(ny+yoff)>>14];
+#endif
for(;voxptr<voxend;voxptr+=voxptr[1]+3)
{
j = (voxptr[0]<<15)-syoff;
@@ -2967,6 +3048,7 @@ static void drawvox(int dasprx, int daspry, int dasprz, int dasprang,
}
}
}
+#endif // NO_VOXELS
//
@@ -3001,6 +3083,7 @@ static void drawsprite(int snum)
cstat = tspr->cstat;
if ((cstat&48)==48) vtilenum = tilenum; // if the game wants voxels, it gets voxels
+#if !NO_VOXELS
else if ((cstat&48)!=48 && (usevoxels) && (tiletovox[tilenum] != -1)
#if USE_POLYMOST && USE_OPENGL
&& (!(spriteext[tspr->owner].flags&SPREXT_NOTMD))
@@ -3009,6 +3092,7 @@ static void drawsprite(int snum)
vtilenum = tiletovox[tilenum];
cstat |= 48;
}
+#endif
if ((cstat&48) != 48)
{
@@ -3623,7 +3707,7 @@ static void drawsprite(int snum)
xsi[z] = scale(rxi[z],xdimen<<15,rzi[z]) + (xdimen<<15);
ysi[z] = scale(ryi[z],xdimen<<15,rzi[z]) + (globalhoriz<<16);
if (xsi[z] < 0) xsi[z] = 0;
- if (xsi[z] > (xdimen<<16)) xsi[z] = (xdimen<<16);
+ if (xsi[z] > (xdimen-1)<<16) xsi[z] = (xdimen-1)<<16; /* ASan */
if (ysi[z] < ((int)0<<16)) ysi[z] = ((int)0<<16);
if (ysi[z] > ((int)ydimen<<16)) ysi[z] = ((int)ydimen<<16);
if (xsi[z] < lmax) lmax = xsi[z], lpoint = z;
@@ -3757,9 +3841,12 @@ static void drawsprite(int snum)
}
else if ((cstat&48) == 48)
{
+#if NO_VOXELS
+ buildprintf("!!! an attempt to draw a voxel\n");
+#else
int nxrepeat, nyrepeat;
- lx = 0; rx = xdim-1;
+ lx = 0; rx = xdimen-1; /* ASan */
for(x=lx;x<=rx;x++)
{
lwall[x] = (int)startumost[x+windowx1]-windowy1;
@@ -3825,6 +3912,7 @@ static void drawsprite(int snum)
}
if (!(cstat&128)) tspr->z -= mulscale22(B_LITTLE32(longptr[5]),nyrepeat);
+ if (tspr->owner < 0) /* ASan */ yoff = (int)tspr->yoffset; else
yoff = (int)((signed char)((picanm[sprite[tspr->owner].picnum]>>16)&255))+((int)tspr->yoffset);
tspr->z -= mulscale14(yoff,nyrepeat);
@@ -3884,8 +3972,10 @@ static void drawsprite(int snum)
i += spriteext[tspr->owner].angoff;
#endif
drawvox(tspr->x,tspr->y,tspr->z,i,(int)tspr->xrepeat,(int)tspr->yrepeat,vtilenum,tspr->shade,tspr->pal,lwall,swall);
+#endif // NO_VOXELS
}
+ if (spritenum >= 0) /* ASan */
if (automapping == 1) show2dsprite[spritenum>>3] |= pow2char[spritenum&7];
}
@@ -4877,9 +4967,13 @@ static void dosetaspect(void)
if (j != 0) j = mulscale16((int)radarang[k+1]-(int)radarang[k],j);
radarang2[i] = (short)(((int)radarang[k]+j)>>6);
}
+#if !NO_VOXELS
+#if !NO_DISTRECIP
for(i=1;i<65536;i++) distrecip[i] = divscale20(xdimen,i);
+#endif
nytooclose = xdimen*2100;
nytoofar = 65536*16384-1048576;
+#endif
}
}
@@ -4887,6 +4981,7 @@ static void dosetaspect(void)
//
// loadtables (internal)
//
+#if !NO_FLOAT
static void calcbritable(void)
{
int i,j;
@@ -4898,12 +4993,17 @@ static void calcbritable(void)
britable[i][j] = (unsigned char)(pow((double)j,a)*b);
}
}
+#endif
static int loadtables(void)
{
int i;
initksqrt();
+#if NO_FLOAT
+ for(i=0;i<2048;i++)
+ reciptable[i] = divscale30(2048L,i+2048);
+#else
for(i=0;i<2048;i++) {
sintable[i] = (short)(16384*sin((double)i*3.14159265358979/1024));
reciptable[i] = divscale30(2048L,i+2048);
@@ -4922,6 +5022,7 @@ static int loadtables(void)
engineerrstr = "Calculation of radarang yielded unexpected results.";
return 1;
}
+#endif
return 0;
}
@@ -4976,6 +5077,10 @@ static int loadpalette(void)
int fil = -1;
off_t flen;
+#ifdef GAME_BLOOD
+ void _Z12qloadpalettev(void);
+ _Z12qloadpalettev();
+#else
if ((fil = kopen4load("palette.dat",0)) < 0) goto badpalette;
flen = kfilelength(fil);
@@ -5012,15 +5117,18 @@ static int loadpalette(void)
kclose(fil);
return 1;
}
+#endif
globalpalwritten = palookup[0]; globalpal = 0;
setpalookupaddress(globalpalwritten);
fixtransluscence(transluc);
+#ifndef GAME_BLOOD
kread(fil,palookup[globalpal],numpalookups<<8);
kread(fil,transluc,65536);
kclose(fil);
+#endif
initfastcolorlookup(30L,59L,11L);
@@ -5373,7 +5481,9 @@ int preinitengine(void)
assert(sizeof(spritetype) == 44);
assert((intptr_t)&sprite[1] - (intptr_t)&sprite[0] == sizeof(spritetype));
assert(sizeof(spriteexttype) == 12);
+#if USE_POLYMOST && USE_OPENGL
assert((intptr_t)&spriteext[1] - (intptr_t)&spriteext[0] == sizeof(spriteexttype));
+#endif
if (initsystem()) exit(1);
@@ -5423,6 +5533,7 @@ int initengine(void)
parallaxtype = 2; parallaxyoffs = 0L; parallaxyscale = 65536;
showinvisibility = 0;
+#if !NO_VOXELS
for(i=1;i<1024;i++) lowrecip[i] = ((1<<24)-1)/i;
for(i=0;i<MAXVOXELS;i++)
for(j=0;j<MAXVOXMIPS;j++)
@@ -5433,6 +5544,7 @@ int initengine(void)
for(i=0;i<MAXTILES;i++)
tiletovox[i] = -1;
clearbuf(&voxscale[0],sizeof(voxscale)>>2,65536L);
+#endif
searchit = 0; searchstat = -1;
@@ -5490,8 +5602,10 @@ void uninitengine(void)
uninitsystem();
+#ifndef EMBEDDED
if (logfile) Bfclose(logfile);
logfile = NULL;
+#endif
if (artfil != -1) kclose(artfil);
@@ -5508,6 +5622,11 @@ void uninitengine(void)
//