-
Notifications
You must be signed in to change notification settings - Fork 0
/
mappyal.c
executable file
·1623 lines (1465 loc) · 46.4 KB
/
mappyal.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
/* Mappy playback library functions and variables
* (C)2001 Robin Burrows - rburrows@bigfoot.com
* This version (R11C) released May 2002 - for Mappy FMP maps
* Please read the readmeal.txt file and look at the examples
*/
#include <stdio.h>
#include <string.h>
#include <allegro.h>
#ifdef __cplusplus
#error "Hey, stop compiling mappyal.c as C++!, see MappyAL readme.txt"
#endif
/* Comment out next line to disable index0 to truecolour pink conversion */
#define RB8BITTOPINK
#define MER_NONE 0 /* All the horrible things that can go wrong */
#define MER_OUTOFMEM 1
#define MER_MAPLOADERROR 2
#define MER_NOOPEN 3
#define MER_NOSCREEN 4
#define MER_NOACCELERATION 5
#define MER_CVBFAILED 6
#define MER_MAPTOONEW 7
#define AN_END -1 /* Animation types, AN_END = end of anims */
#define AN_NONE 0 /* No anim defined */
#define AN_LOOPF 1 /* Loops from start to end, then jumps to start etc */
#define AN_LOOPR 2 /* As above, but from end to start */
#define AN_ONCE 3 /* Only plays once */
#define AN_ONCEH 4 /* Only plays once, but holds end frame */
#define AN_PPFF 5 /* Ping Pong start-end-start-end-start etc */
#define AN_PPRR 6 /* Ping Pong end-start-end-start-end etc */
#define AN_PPRF 7 /* Used internally by playback */
#define AN_PPFR 8 /* Used internally by playback */
#define AN_ONCES 9 /* Used internally by playback */
typedef struct { /* Structure for data blocks */
long int bgoff, fgoff; /* offsets from start of graphic blocks */
long int fgoff2, fgoff3; /* more overlay blocks */
unsigned long int user1, user2; /* user long data */
unsigned short int user3, user4; /* user short data */
unsigned char user5, user6, user7; /* user byte data */
unsigned char tl : 1; /* bits for collision detection */
unsigned char tr : 1;
unsigned char bl : 1;
unsigned char br : 1;
unsigned char trigger : 1; /* bit to trigger an event */
unsigned char unused1 : 1;
unsigned char unused2 : 1;
unsigned char unused3 : 1;
} BLKSTR;
typedef struct { /* Animation control structure */
signed char antype; /* Type of anim, AN_? */
signed char andelay; /* Frames to go before next frame */
signed char ancount; /* Counter, decs each frame, till 0, then resets to andelay */
signed char anuser; /* User info */
long int ancuroff; /* Points to current offset in list */
long int anstartoff; /* Points to start of blkstr offsets list, AFTER ref. blkstr offset */
long int anendoff; /* Points to end of blkstr offsets list */
} ANISTR;
/* All global variables used by Mappy playback are here */
int maperror, mapgfxinbitmaps; /* Set to a MER_ error if something wrong happens */
short int mapwidth, mapheight, mapblockwidth, mapblockheight, mapdepth;
short int mapblockstrsize, mapnumblockstr, mapnumblockgfx;
PACKFILE * mapfilept;
short int * mappt = NULL;
short int ** maparraypt = NULL;
char * mapcmappt = NULL;
char * mapblockgfxpt = NULL;
char * mapblockstrpt = NULL;
ANISTR * mapanimstrpt = NULL;
int * mapanimseqpt = NULL;
ANISTR * mapanimstrendpt;
RGB mapcmap6bit[256];
short int * mapmappt[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
short int ** mapmaparraypt[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
BITMAP ** abmTiles = NULL;
/* NEW for Release 6 */
int mapaltdepth;
int maptype, mapislsb, mapclickmask;
int mapblockgapx, mapblockgapy, mapblockstaggerx, mapblockstaggery;
int mapblocksinvidmem, mapblocksinsysmem;
char mapnovctext[80];
/* End of Mappy globals */
int MapGenerateYLookup (void)
{
int i, j;
for (i=0;i<8;i++) {
if (mapmaparraypt[i]!=NULL) { free (mapmaparraypt[i]); mapmaparraypt[i] = NULL; }
if (mapmappt[i]!=NULL) {
mapmaparraypt[i] = malloc (mapheight*sizeof(short int *));
if (mapmaparraypt[i] == NULL) return -1;
for (j=0;j<mapheight;j++) mapmaparraypt[i][j] = (mapmappt[i]+(j*mapwidth));
if (mapmappt[i] == mappt) maparraypt = mapmaparraypt[i];
}
}
return 0;
}
static int MEClickmask (int x, int y, int xory)
{
if (abmTiles == NULL) return 0;
x %= mapblockgapx; y %= mapblockgapy;
if (x >= mapblockwidth && xory == 0) return 0;
if (x >= mapblockwidth && xory == 1) {
if (y < mapblockstaggery) return -1;
else return 1;
}
if (y >= mapblockheight && xory == 1) return 1;
if (y >= mapblockheight && xory == 0) {
if (x < mapblockstaggerx) return -1;
else return 0;
}
switch (mapdepth) {
case 8:
if (getpixel (abmTiles[mapclickmask], x, y) == 0) {
if (x < (mapblockwidth/2) && xory == 0) return -1;
if (x >= (mapblockwidth/2) && xory == 0) return 0;
if (y < (mapblockheight/2) && xory == 1) return -1;
if (y >= (mapblockheight/2) && xory == 1) return 1;
}
return 0;
default:
if (getpixel (abmTiles[mapclickmask], x, y) == makecol (255,0,255)) {
if (x < (mapblockwidth/2) && xory == 0) return -1;
if (x >= (mapblockwidth/2) && xory == 0) return 0;
if (y < (mapblockheight/2) && xory == 1) return -1;
if (y >= (mapblockheight/2) && xory == 1) return 1;
}
return 0;
}
return 0;
}
int MapGetXOffset (int xpix, int ypix)
{
int xb;
if (mapblockstaggerx || mapblockstaggery) {
xpix += (mapblockstaggerx);
ypix += (mapblockstaggery);
}
xb = xpix/mapblockgapx;
if ((mapblockstaggerx || mapblockstaggery) && mapclickmask) xb += MEClickmask (xpix, ypix, 0);
if (xb < 0) xb = 0;
if (xb >= mapwidth) xb = mapwidth-1;
return xb;
}
int MapGetYOffset (int xpix, int ypix)
{
int yb;
if (mapblockstaggerx || mapblockstaggery) {
xpix += (mapblockstaggerx);
ypix += (mapblockstaggery);
}
yb = ypix/mapblockgapy;
if ((mapblockstaggerx || mapblockstaggery) && mapclickmask) {
yb *= 2;
yb += MEClickmask (xpix, ypix, 1);
}
if (yb < 0) yb = 0;
if (yb >= mapheight) yb = mapheight-1;
return yb;
}
BLKSTR * MapGetBlockInPixels (int x, int y)
{
int xp, yp;
short int * mymappt;
ANISTR * myanpt;
if (x < 0 || y < 0 || x >= (mapwidth*mapblockwidth) || y >= (mapheight*mapblockheight)) return NULL;
xp = x; yp = y;
x = MapGetXOffset (xp, yp);
y = MapGetYOffset (xp, yp);
if (maparraypt!= NULL) {
mymappt = maparraypt[y]+x;
} else {
mymappt = mappt;
mymappt += x;
mymappt += y*mapwidth;
}
if (*mymappt>=0) return ((BLKSTR*) mapblockstrpt) + *mymappt;
else { myanpt = mapanimstrendpt + *mymappt;
return ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
}
BLKSTR * MapGetBlock (int x, int y)
{
short int * mymappt;
ANISTR * myanpt;
if (maparraypt!= NULL) {
mymappt = maparraypt[y]+x;
} else {
mymappt = mappt;
mymappt += x;
mymappt += y*mapwidth;
}
if (*mymappt>=0) return ((BLKSTR*) mapblockstrpt) + *mymappt;
else { myanpt = mapanimstrendpt + *mymappt;
return ((BLKSTR *) mapblockstrpt) + mapanimseqpt[myanpt->ancuroff]; }
}
void MapSetBlockInPixels (int x, int y, int strvalue)
{
int xp, yp;
short int * mymappt;
if (x < 0 || y < 0 || x >= (mapwidth*mapblockwidth) || y >= (mapheight*mapblockheight)) return;
xp = x; yp = y;
x = MapGetXOffset (xp, yp);
y = MapGetYOffset (xp, yp);
if (maparraypt!= NULL) {
mymappt = maparraypt[y]+x;
} else {
mymappt = mappt;
mymappt += x;
mymappt += y*mapwidth;
}
*mymappt = strvalue;
}
void MapSetBlock (int x, int y, int strvalue)
{
short int * mymappt;
if (maparraypt!= NULL) {
mymappt = maparraypt[y]+x;
} else {
mymappt = mappt;
mymappt += x;
mymappt += y*mapwidth;
}
*mymappt = strvalue;
}
int MapChangeLayer (int newlyr)
{
if (newlyr<0 || newlyr>7 || mapmappt[newlyr] == NULL) return -1;
mappt = mapmappt[newlyr]; maparraypt = mapmaparraypt[newlyr];
return newlyr;
}
int MapGetBlockID (int blid, int usernum)
{
int i;
BLKSTR * myblkpt;
myblkpt = (BLKSTR *) mapblockstrpt;
if (myblkpt == NULL) return -1;
for (i=0;i<mapnumblockstr;i++) {
switch (usernum) {
case 1:
if (myblkpt[i].user1 == blid) return i;
break;
case 2:
if (myblkpt[i].user2 == blid) return i;
break;
case 3:
if (myblkpt[i].user3 == blid) return i;
break;
case 4:
if (myblkpt[i].user4 == blid) return i;
break;
case 5:
if (myblkpt[i].user5 == blid) return i;
break;
case 6:
if (myblkpt[i].user6 == blid) return i;
break;
case 7:
if (myblkpt[i].user7 == blid) return i;
break;
}
}
return -1;
}
int MapDecodeMAR (unsigned char * mrpt, int marlyr)
{
int i, j;
short int * mymarpt;
if (marlyr < 0 || marlyr > 7) return -1;
if (mapmappt[marlyr] == NULL)
mapmappt[marlyr] = malloc (mapwidth*mapheight*sizeof(short int));
memcpy (mapmappt[marlyr], mrpt, (mapwidth*mapheight*sizeof(short int)));
mymarpt = mapmappt[marlyr];
j = 0; for (i=0;i<(mapwidth*mapheight);i++) { if (mymarpt[i]&0xF) j = 1; }
if (j == 0) {
for (i=0;i<(mapwidth*mapheight);i++) {
if (mymarpt[i] >= 0) mymarpt[i] /= 32;
else mymarpt[i] /= 16;
}
}
return 0;
}
int MapLoadMAR (char * mname, int marlyr)
{
int i, j;
short int * mymarpt;
PACKFILE * marfpt;
if (marlyr < 0 || marlyr > 7) return -1;
marfpt = pack_fopen (mname, "rp");
if (marfpt==NULL) { marfpt = pack_fopen (mname, "r");
if (marfpt==NULL) { return -1; } }
if (mapmappt[marlyr] == NULL)
mapmappt[marlyr] = malloc (mapwidth*mapheight*sizeof(short int));
if (pack_fread (mapmappt[marlyr], (mapwidth*mapheight*sizeof(short int)), marfpt) !=
(mapwidth*mapheight*sizeof(short int))) { pack_fclose (marfpt); return -1; }
pack_fclose (marfpt);
mymarpt = mapmappt[marlyr];
j = 0; for (i=0;i<(mapwidth*mapheight);i++) { if (mymarpt[i]&0xF) j = 1; }
if (j == 0) {
for (i=0;i<(mapwidth*mapheight);i++) {
if (mymarpt[i] >= 0) mymarpt[i] /= 32;
else mymarpt[i] /= 16;
}
}
return 0;
}
void MapInitAnims (void)
{
ANISTR * myanpt;
if (mapanimstrpt==NULL) return;
myanpt = (ANISTR *) mapanimstrendpt; myanpt--;
while (myanpt->antype!=-1)
{
if (myanpt->antype==AN_PPFR) myanpt->antype = AN_PPFF;
if (myanpt->antype==AN_PPRF) myanpt->antype = AN_PPRR;
if (myanpt->antype==AN_ONCES) myanpt->antype = AN_ONCE;
if ((myanpt->antype==AN_LOOPR) || (myanpt->antype==AN_PPRR))
{
myanpt->ancuroff = myanpt->anstartoff;
if ((myanpt->anstartoff)!=(myanpt->anendoff)) myanpt->ancuroff=(myanpt->anendoff)-1;
} else {
myanpt->ancuroff = myanpt->anstartoff;
}
myanpt->ancount = myanpt->andelay;
myanpt--;
}
}
void MapUpdateAnims (void)
{
ANISTR * myanpt;
if (mapanimstrpt==NULL) return;
myanpt = (ANISTR *) mapanimstrendpt; myanpt--;
while (myanpt->antype!=-1)
{
if (myanpt->antype!=AN_NONE) { myanpt->ancount--; if (myanpt->ancount<0) {
myanpt->ancount = myanpt->andelay;
if (myanpt->antype==AN_LOOPF)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
if (myanpt->ancuroff==myanpt->anendoff) myanpt->ancuroff = myanpt->anstartoff;
} }
if (myanpt->antype==AN_LOOPR)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
if (myanpt->ancuroff==((myanpt->anstartoff)-1))
myanpt->ancuroff = (myanpt->anendoff)-1;
} }
if (myanpt->antype==AN_ONCE)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
if (myanpt->ancuroff==myanpt->anendoff) { myanpt->antype = AN_ONCES;
myanpt->ancuroff = myanpt->anstartoff; }
} }
if (myanpt->antype==AN_ONCEH)
{
if (myanpt->anstartoff!=myanpt->anendoff) {
if (myanpt->ancuroff!=((myanpt->anendoff)-1)) myanpt->ancuroff++;
} }
if (myanpt->antype==AN_PPFF)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
if (myanpt->ancuroff==myanpt->anendoff) { myanpt->ancuroff -= 2;
myanpt->antype = AN_PPFR;
if (myanpt->ancuroff<myanpt->anstartoff) myanpt->ancuroff++; }
} } else {
if (myanpt->antype==AN_PPFR)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
if (myanpt->ancuroff==((myanpt->anstartoff)-1)) { myanpt->ancuroff += 2;
myanpt->antype = AN_PPFF;
if (myanpt->ancuroff>myanpt->anendoff) myanpt->ancuroff --; }
} } }
if (myanpt->antype==AN_PPRR)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff--;
if (myanpt->ancuroff==((myanpt->anstartoff)-1)) { myanpt->ancuroff += 2;
myanpt->antype = AN_PPRF;
if (myanpt->ancuroff>myanpt->anendoff) myanpt->ancuroff--; }
} } else {
if (myanpt->antype==AN_PPRF)
{
if (myanpt->anstartoff!=myanpt->anendoff) { myanpt->ancuroff++;
if (myanpt->ancuroff==myanpt->anendoff) { myanpt->ancuroff -= 2;
myanpt->antype = AN_PPRR;
if (myanpt->ancuroff<myanpt->anstartoff) myanpt->ancuroff++; }
} } }
} } myanpt--; }
}
void Mapconv8to6pal (unsigned char * palpt)
{
int i;
for (i=0;i<256;i++)
{
mapcmap6bit[i].r=(*(palpt)>>2);
mapcmap6bit[i].g=(*(palpt+1)>>2);
mapcmap6bit[i].b=(*(palpt+2)>>2);
palpt+=3;
}
}
void MapFreeMem (void)
{
int i;
for (i=0;i<8;i++) { if (mapmappt[i]!=NULL) { free (mapmappt[i]); mapmappt[i] = NULL; } }
mappt = NULL;
for (i=0;i<8;i++) { if (mapmaparraypt[i]!=NULL) { free (mapmaparraypt[i]); mapmaparraypt[i] = NULL; } }
maparraypt = NULL;
if (mapcmappt!=NULL) { free (mapcmappt); mapcmappt = NULL; }
if (mapblockgfxpt!=NULL) { free (mapblockgfxpt); mapblockgfxpt = NULL; }
if (mapblockstrpt!=NULL) { free (mapblockstrpt); mapblockstrpt = NULL; }
if (mapanimseqpt!=NULL) { free (mapanimseqpt); mapanimseqpt = NULL; }
if (mapanimstrpt!=NULL) { free (mapanimstrpt); mapanimstrpt = NULL; }
if (abmTiles != NULL) {
i = 0; while (abmTiles[i]!=NULL) { destroy_bitmap (abmTiles[i]); i++; }
free (abmTiles); abmTiles = NULL;
}
mapnovctext[0] = 0;
mapblocksinvidmem = 0; mapblocksinsysmem = 0;
}
void MapSetPal8 (void)
{
if (screen!=NULL) { if ((bitmap_color_depth (screen)==8) && mapdepth == 8) set_palette (mapcmap6bit); }
}
void MapCorrectColours (void)
{
/* Remember, Intel stores shorts and longs the wrong way round!
* ie. 0x12345678 will be 0x78563412
*/
return;
}
void MapRestore (void)
{
int i, j, k;
unsigned char * newgfxpt;
if (mapgfxinbitmaps!=1 || abmTiles == NULL) return;
i = 0; newgfxpt = mapblockgfxpt; while (abmTiles[i]!=NULL) {
acquire_bitmap (abmTiles[i]);
for (k=0;k<mapblockheight;k++) {
for (j=0;j<mapblockwidth;j++) {
switch (mapdepth) {
case 8:
putpixel (abmTiles[i], j, k, *((unsigned char *) newgfxpt));
newgfxpt++;
break;
case 15:
case 16:
putpixel (abmTiles[i], j, k, *((unsigned short int *) newgfxpt));
newgfxpt+=2;
break;
case 24:
putpixel (abmTiles[i], j, k, makecol (newgfxpt[0], newgfxpt[1], newgfxpt[2]));
newgfxpt+=3;
break;
case 32:
putpixel (abmTiles[i], j, k, makecol (newgfxpt[1], newgfxpt[2], newgfxpt[3]));
newgfxpt+=4;
break;
} } }
release_bitmap (abmTiles[i]);
i++;
}
}
int MapRelocate2 (void)
{
int i, j, k;
BLKSTR * myblkstrpt;
//ANISTR * myanpt;
unsigned char * newgfxpt, * novcarray;
char ascnum[80];
//long int * myanblkpt;
i = mapnumblockstr;
myblkstrpt = (BLKSTR *) mapblockstrpt;
novcarray = malloc (mapnumblockgfx);
memset (novcarray, 0, mapnumblockgfx);
i = 0; while (mapnovctext[i] != 0) {
j = 0; while (mapnovctext[i] >= '0' && mapnovctext[i] <= '9') {
ascnum[j] = mapnovctext[i];
i++; j++;
}
ascnum[j] = 0;
k = atoi(ascnum);
if (k < 0 || k >= mapnumblockgfx) break;
if (mapnovctext[i] == '-') {
i++;
j = 0; while (mapnovctext[i] >= '0' && mapnovctext[i] <= '9') {
ascnum[j] = mapnovctext[i];
i++; j++;
}
ascnum[j] = 0;
j = atoi(ascnum);
if (j < k || j >= mapnumblockgfx) break;
while (k <= j) {
novcarray[k] = 1; k++;
}
} else {
novcarray[k] = 1;
}
if (mapnovctext[i] == ',') i++;
}
if (abmTiles == NULL) abmTiles = malloc ((sizeof (BITMAP *))*(mapnumblockgfx+2));
abmTiles[0] = NULL;
i = 0; newgfxpt = mapblockgfxpt; while (i<mapnumblockgfx) {
abmTiles[i+1] = NULL;
if (mapgfxinbitmaps==1 && novcarray[i]==0) {
abmTiles[i] = create_video_bitmap (mapblockwidth, mapblockheight);
if (abmTiles[i] != NULL) {
mapblocksinvidmem++;
acquire_bitmap (abmTiles[i]);
} else {
abmTiles[i] = create_bitmap (mapblockwidth, mapblockheight);
if (abmTiles[i] == NULL) { MapFreeMem (); maperror = MER_CVBFAILED ; return -1; }
mapblocksinsysmem++;
}
set_clip (abmTiles[i], 0, 0, 0, 0);
} else {
abmTiles[i] = create_bitmap (mapblockwidth, mapblockheight);
if (abmTiles[i] == NULL) { MapFreeMem (); maperror = MER_CVBFAILED ; return -1; }
mapblocksinsysmem++;
set_clip (abmTiles[i], 0, 0, 0, 0);
}
for (k=0;k<mapblockheight;k++) {
for (j=0;j<mapblockwidth;j++) {
switch (mapdepth) {
case 8:
putpixel (abmTiles[i], j, k, *((unsigned char *) newgfxpt));
newgfxpt++;
break;
case 15:
case 16:
putpixel (abmTiles[i], j, k, *((unsigned short int *) newgfxpt));
newgfxpt+=2;
break;
case 24:
putpixel (abmTiles[i], j, k, makecol (newgfxpt[0], newgfxpt[1], newgfxpt[2]));
newgfxpt+=3;
break;
case 32:
putpixel (abmTiles[i], j, k, makecol (newgfxpt[1], newgfxpt[2], newgfxpt[3]));
newgfxpt+=4;
break;
} } }
if (is_video_bitmap(abmTiles[i])) release_bitmap (abmTiles[i]);
i++;
}
i = mapnumblockstr; while (i) {
((BITMAP *) myblkstrpt->bgoff) = abmTiles[myblkstrpt->bgoff];
if (myblkstrpt->fgoff!=0)
((BITMAP *) myblkstrpt->fgoff) = abmTiles[myblkstrpt->fgoff];
if (myblkstrpt->fgoff2!=0)
((BITMAP *) myblkstrpt->fgoff2) = abmTiles[myblkstrpt->fgoff2];
if (myblkstrpt->fgoff3!=0)
((BITMAP *) myblkstrpt->fgoff3) = abmTiles[myblkstrpt->fgoff3];
myblkstrpt++; i--;
}
free (novcarray);
return 0;
}
int MapRelocate (void)
{
int i, j, cdepth, pixcol, ccr, ccg, ccb;
//BLKSTR * myblkstrpt;
unsigned char * oldgfxpt;
unsigned char * mycmappt;
unsigned char * newgfxpt;
unsigned char * newgfx2pt;
if (screen == NULL) { MapFreeMem (); maperror = MER_NOSCREEN; return -1; }
if (!gfx_capabilities&GFX_HW_VRAM_BLIT && mapgfxinbitmaps==1)
{ MapFreeMem (); maperror = MER_NOACCELERATION; return -1; }
cdepth = bitmap_color_depth (screen);
oldgfxpt = (unsigned char *) mapblockgfxpt;
newgfxpt = (unsigned char *)
malloc (mapblockwidth*mapblockheight*((mapdepth+1)/8)*mapnumblockgfx*((cdepth+1)/8));
if (newgfxpt==NULL) { MapFreeMem (); maperror = MER_OUTOFMEM; return -1; }
newgfx2pt = newgfxpt;
mycmappt = (unsigned char *) mapcmappt; pixcol = 0;
for (i=0;i<(mapblockwidth*mapblockheight*mapnumblockgfx);i++)
{
switch (mapdepth) {
case 8:
if (cdepth==8) pixcol = (int) *oldgfxpt; else {
j = (*oldgfxpt)*3;
pixcol = makecol (mycmappt[j], mycmappt[j+1], mycmappt[j+2]);
#ifdef RB8BITTOPINK
if (j == 0 && cdepth!=8) pixcol = makecol (255, 0, 255); }
#endif
oldgfxpt++;
break;
case 15:
ccr = ((((int) *oldgfxpt)&0x7C)<<1);
ccg = ((((((int) *oldgfxpt)&0x3)<<3)|(((int) *(oldgfxpt+1))>>5))<<3);
ccb = (((int) *(oldgfxpt+1)&0x1F)<<3);
ccr |= ((ccr>>5)&0x07);
ccg |= ((ccg>>5)&0x07);
ccb |= ((ccb>>5)&0x07);
pixcol = makecol (ccr, ccg, ccb);
if (cdepth==8) { if (ccr == 0xFF && ccg == 0 && ccb == 0xFF) pixcol = 0; }
oldgfxpt += 2;
break;
case 16:
ccr = (((int) *oldgfxpt)&0xF8);
ccg = ((((((int) *oldgfxpt)&0x7)<<3)|(((int) *(oldgfxpt+1))>>5))<<2);
ccb = (((int) *(oldgfxpt+1)&0x1F)<<3);
ccr |= ((ccr>>5)&0x07);
ccg |= ((ccg>>6)&0x03);
ccb |= ((ccb>>5)&0x07);
pixcol = makecol (ccr, ccg, ccb);
if (cdepth==8) { if (ccr == 0xFF && ccg == 0 && ccb == 0xFF) pixcol = 0; }
oldgfxpt += 2;
break;
case 24:
pixcol = makecol (*oldgfxpt, *(oldgfxpt+1), *(oldgfxpt+2));
if (cdepth==8) { if (*oldgfxpt == 0xFF && *(oldgfxpt+1) == 0 &&
*(oldgfxpt+2) == 0xFF) pixcol = 0; }
oldgfxpt += 3;
break;
case 32:
pixcol = makecol (*(oldgfxpt+1), *(oldgfxpt+2), *(oldgfxpt+3));
if (cdepth==8) { if (*(oldgfxpt+1) == 0xFF && *(oldgfxpt+2) == 0 &&
*(oldgfxpt+3) == 0xFF) pixcol = 0; }
oldgfxpt += 4;
break;
}
switch (cdepth) {
case 8:
*newgfxpt = (unsigned char) pixcol;
newgfxpt++;
break;
case 15:
case 16:
*((unsigned short int *) newgfxpt) = (unsigned short int) pixcol;
newgfxpt+=2;
break;
case 24:
*newgfxpt = (unsigned char) (pixcol>>16)&0xFF;
*(newgfxpt+1) = (unsigned char) (pixcol>>8)&0xFF;
*(newgfxpt+2) = (unsigned char) pixcol&0xFF;
newgfxpt+=3;
break;
case 32:
*newgfxpt = 0;
*(newgfxpt+1) = (unsigned char) (pixcol>>16)&0xFF;
*(newgfxpt+2) = (unsigned char) (pixcol>>8)&0xFF;
*(newgfxpt+3) = (unsigned char) pixcol&0xFF;
newgfxpt+=4;
break;
}
}
free (mapblockgfxpt); mapblockgfxpt = (char *) newgfx2pt;
mapdepth = cdepth;
return MapRelocate2 ();
}
static int MapGetchksz (unsigned char * locpt)
{
return ((((int) (locpt[0]))<<24)|(((int) (locpt[1]))<<16)|
(((int) (locpt[2]))<<8)|((int) (locpt[3])));
}
static int MapGetshort (unsigned char * locpt)
{
int rval;
if (mapislsb)
rval = ((((int) (locpt[1]))<<8)|((int) (locpt[0])));
else
rval = ((((int) (locpt[0]))<<8)|((int) (locpt[1])));
if (rval & 0x8000) rval -= 0x10000;
return rval;
}
static int MapGetlong (unsigned char * locpt)
{
if (mapislsb)
return ((((int) (locpt[3]))<<24)|(((int) (locpt[2]))<<16)|
(((int) (locpt[1]))<<8)|((int) (locpt[0])));
else
return ((((int) (locpt[0]))<<24)|(((int) (locpt[1]))<<16)|
(((int) (locpt[2]))<<8)|((int) (locpt[3])));
}
int MapDecodeMPHD (unsigned char * mdatpt)
{
mdatpt += 8;
if (mdatpt[0] > 1) { maperror = MER_MAPTOONEW; return -1; }
if (mdatpt[2] == 1) mapislsb = 1; else mapislsb = 0;
maptype = (int) mdatpt[3];
if (maptype > 3) { maperror = MER_MAPTOONEW; return -1; }
mapwidth = (short) MapGetshort (mdatpt+4);
mapheight = (short) MapGetshort (mdatpt+6);
mapblockwidth = (short) MapGetshort (mdatpt+12);
mapblockheight = (short) MapGetshort (mdatpt+14);
mapdepth = (short) MapGetshort (mdatpt+16);
mapaltdepth = mapdepth;
mapblockstrsize = (short) MapGetshort (mdatpt+18);
mapnumblockstr = (short) MapGetshort (mdatpt+20);
mapnumblockgfx = (short) MapGetshort (mdatpt+22);
if (MapGetchksz (mdatpt-4) > 28) {
mapblockgapx = (int) MapGetshort (mdatpt+28);
mapblockgapy = (int) MapGetshort (mdatpt+30);
mapblockstaggerx = (int) MapGetshort (mdatpt+32);
mapblockstaggery = (int) MapGetshort (mdatpt+34);
} else {
mapblockgapx = (int) mapblockwidth;
mapblockgapy = (int) mapblockheight;
mapblockstaggerx = 0;
mapblockstaggery = 0;
}
if (MapGetchksz (mdatpt-4) > 36) mapclickmask = (short) MapGetshort (mdatpt+36);
else mapclickmask = 0;
return 0;
}
/*
int DecodeEDHD (unsigned char * mdatpt)
{
int i, j;
short int * mybrshpt;
char * mynamept;
short int * mybrsh2pt;
mdatpt += 8;
xmapoffset = (short) MapGetshort (mdatpt);
ymapoffset = (short) MapGetshort (mdatpt+2);
fgcolour = (int) MapGetlong (mdatpt+4);
bgcolour = (int) MapGetlong (mdatpt+8);
swidth = (short) MapGetshort (mdatpt+12);
sheight = (short) MapGetshort (mdatpt+14);
strtstr = (short) MapGetshort (mdatpt+16);
strtblk = (short) MapGetshort (mdatpt+18);
curstr = (short) MapGetshort (mdatpt+20);
curanim = (short) MapGetshort (mdatpt+22); curanim = -1;
animspd = (short) MapGetshort (mdatpt+24);
span = (short) MapGetshort (mdatpt+26);
numbrushes = (short) MapGetshort (mdatpt+28);
if (clickmask == 0) {
clickmask = (int) MapGetshort (mdatpt+30);
if (clickmask<0 || clickmask >= numblockgfx) clickmask = 0;
}
if (numbrushes>0)
{
mybrshpt =(short int *) (mdatpt+32);
for (i=0;i<8;i++)
{
j = *mybrshpt; j *= *(mybrshpt+1); j *= 2; j += 4;
brshpt[i] = malloc (j); j /= 2; mybrsh2pt = brshpt[i];
*mybrsh2pt = *mybrshpt;
mybrsh2pt++; mybrshpt++;
*mybrsh2pt = *mybrshpt;
mybrsh2pt++; mybrshpt++;
j -= 2;
if (maptype == 0) {
while (j) {
j--;
*mybrsh2pt = *mybrshpt;
if (*mybrsh2pt >= 0) *mybrsh2pt /= BLOCKSTRSIZE;
mybrsh2pt++; mybrshpt++;
}
} else {
while (j) {
j--;
*mybrsh2pt = *mybrshpt;
if (*mybrsh2pt < 0) *mybrsh2pt *= sizeof(ANISTR);
mybrsh2pt++; mybrshpt++;
}
}
numbrushes--; if (!numbrushes) i=8;
}
mynamept = (char *) mybrshpt;
if ((MapGetchksz (mdatpt-4)) > (mynamept-((char *) mdatpt))) {
for (i=0;i<8;i++) {
if (brshpt[i] != NULL) {
strcpy (brshname[i], mynamept);
mynamept += strlen (mynamept);
mynamept++;
}
}
}
}
return 0;
}
int DecodeATHR (unsigned char * mdatpt)
{
int i, j;
mdatpt += 8;
i = 0; while (i < MapGetchksz (mdatpt-4))
{
authorname[i]=mdatpt[i];
if (mdatpt[i]==0) break;
i++;
}
i++; j = 0;
while (i < MapGetchksz (mdatpt-4))
{
authorinfo1[j]=mdatpt[i];
if (mdatpt[i]==0) break;
i++; j++;
}
i++; j = 0;
while (i < MapGetchksz (mdatpt-4))
{
authorinfo2[j]=mdatpt[i];
if (mdatpt[i]==0) break;
i++; j++;
}
i++; j = 0;
while (i < MapGetchksz (mdatpt-4))
{
authorinfo3[j]=mdatpt[i];
if (mdatpt[i]==0) break;
i++; j++;
}
return 0;
}
*/
int MapDecodeCMAP (unsigned char * mdatpt)
{
mdatpt += 8;
mapcmappt = (unsigned char *) malloc (MapGetchksz (mdatpt-4));
if (mapcmappt==NULL) { maperror = MER_OUTOFMEM; return -1; }
memcpy (mapcmappt, mdatpt, MapGetchksz (mdatpt-4));
Mapconv8to6pal (mapcmappt);
return 0;
}
int MapDecodeBKDT (unsigned char * mdatpt)
{
int i, j;
BLKSTR * myblkpt;
mdatpt += 8;
mapblockstrpt = malloc (mapnumblockstr*sizeof(BLKSTR));
if (mapblockstrpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
myblkpt = (BLKSTR *) mapblockstrpt;
j = MapGetchksz (mdatpt-4);
i = 0; while (i < (mapnumblockstr*mapblockstrsize)) {
myblkpt->bgoff = (int) MapGetlong (mdatpt+i);
myblkpt->fgoff = (int) MapGetlong (mdatpt+i+4);
myblkpt->fgoff2 = (int) MapGetlong (mdatpt+i+8);
myblkpt->fgoff3 = (int) MapGetlong (mdatpt+i+12);
if (maptype == 0) {
myblkpt->bgoff /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
myblkpt->fgoff /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
myblkpt->fgoff2 /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
myblkpt->fgoff3 /= (mapblockwidth*mapblockheight*((mapdepth+1)/8));
}
myblkpt->user1 = (unsigned int) MapGetlong (mdatpt+i+16);
myblkpt->user2 = (unsigned int) MapGetlong (mdatpt+i+20);
myblkpt->user3 = (unsigned short int) MapGetshort (mdatpt+i+24);
myblkpt->user4 = (unsigned short int) MapGetshort (mdatpt+i+26);
myblkpt->user5 = mdatpt[i+28];
myblkpt->user6 = mdatpt[i+29];
myblkpt->user7 = mdatpt[i+30];
if (mdatpt[i+31]&0x80) myblkpt->unused3 = 1; else myblkpt->unused3 = 0;
if (mdatpt[i+31]&0x40) myblkpt->unused2 = 1; else myblkpt->unused2 = 0;
if (mdatpt[i+31]&0x20) myblkpt->unused1 = 1; else myblkpt->unused1 = 0;
if (mdatpt[i+31]&0x10) myblkpt->trigger = 1; else myblkpt->trigger = 0;
if (mdatpt[i+31]&0x08) myblkpt->br = 1; else myblkpt->br = 0;
if (mdatpt[i+31]&0x04) myblkpt->bl = 1; else myblkpt->bl = 0;
if (mdatpt[i+31]&0x02) myblkpt->tr = 1; else myblkpt->tr = 0;
if (mdatpt[i+31]&0x01) myblkpt->tl = 1; else myblkpt->tl = 0;
i += mapblockstrsize;
myblkpt++;
}
return 0;
}
int MapDecodeANDT (unsigned char * mdatpt)
{
int numani, i, ancksz;
unsigned char * mdatendpt;
mdatpt += 8;
ancksz = MapGetchksz(mdatpt-4);
mdatendpt = mdatpt+ancksz;
numani = 0; while (1) {
mdatendpt -= 16;
numani++;
if (*mdatendpt == 255) break;
}
mapanimseqpt = malloc (((mdatendpt-mdatpt)/4)*sizeof(int));
if (mapanimseqpt == NULL) { maperror = MER_OUTOFMEM; return -1; }
i = 0; while (mdatpt != mdatendpt) {
mapanimseqpt[i] = MapGetlong (mdatpt);
if (maptype == 0) mapanimseqpt[i] /= mapblockstrsize;
mdatpt += 4; i++;
}
mapanimstrpt = malloc (numani*sizeof(ANISTR));
if (mapanimstrpt == NULL) { maperror = MER_OUTOFMEM; return -1; }
mapanimstrendpt = mapanimstrpt;
mapanimstrendpt += numani;
i = 0; while (i<numani) {
mapanimstrpt[i].antype = mdatendpt[0];
mapanimstrpt[i].andelay = mdatendpt[1];
mapanimstrpt[i].ancount = mdatendpt[2];
mapanimstrpt[i].anuser = mdatendpt[3];
if (maptype == 0) {
mapanimstrpt[i].ancuroff = (int) ((MapGetlong (mdatendpt+4)+ancksz)/4);
mapanimstrpt[i].anstartoff = (int) ((MapGetlong (mdatendpt+8)+ancksz)/4);
mapanimstrpt[i].anendoff = (int) ((MapGetlong (mdatendpt+12)+ancksz)/4);
} else {
mapanimstrpt[i].ancuroff = (int) MapGetlong (mdatendpt+4);
mapanimstrpt[i].anstartoff = (int) MapGetlong (mdatendpt+8);
mapanimstrpt[i].anendoff = (int) MapGetlong (mdatendpt+12);
}
mdatendpt += 16; i++;
}
MapInitAnims ();
return 0;
}
int MapDecodeAGFX (unsigned char * mdatpt)
{
if (bitmap_color_depth (screen) > 8) return 0;
if (mapblockgfxpt != NULL) free (mapblockgfxpt);
mapblockgfxpt = malloc (MapGetchksz (mdatpt+4));
if (mapblockgfxpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
memcpy (mapblockgfxpt, mdatpt+8, MapGetchksz(mdatpt+4));
mapaltdepth = 8;
return 0;