-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditart.c
More file actions
4786 lines (4320 loc) · 108 KB
/
editart.c
File metadata and controls
4786 lines (4320 loc) · 108 KB
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
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
// Ken Silverman's official web site: "http://www.advsys.net/ken"
// See the included license file "BUILDLIC.TXT" for license info.
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#ifdef PLATFORM_DOS
#include <direct.h>
#include <dos.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <conio.h>
#include "dos_compat.h"
#else
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "pragmas.h"
#include "sdl_driver.h"
#include "unix_compat.h"
#include <fnmatch.h> // This needs to be last - DDOI
#endif
#define MAXTILES 9216
#define MAXMENUFILES 256
#define MAXTILEFILES 256
#define NUMPALOOKUPS 32
#define GIFBUFLEN 4096
#define MAXMAPS 64
// Function Declarations
void reportmaps(void);
void captureit(long x1, long y1, long x2, long y2, long datilenum, char *dafilename, char capfilmode);
void updatescript(long picnumrangestart, long picnumrangeend);
int loadtileofscript(long tilenume, char *filespec, long *x1, long *y1, long *x2 , long *y2);
int selectbox(long *dax1, long *day1, long *dax2, long *day2);
void updatepalette(void);
void updatemaps(void);
int swapwalls(long swapwall1, long swapwall2);
long convalloc32(long size);
char gettrans(char dat1, char dat2);
void gettextcolors(void);
int resizetile(long picnume, long oldx, long oldy, long newx, long newy);
int screencapture(void);
void printmessage(char name[82]);
int printext256(long xpos, long ypos, short col, short backcol, char *name);
int menuselect(void);
void sortfilenames(void);
int getfilenames(char *kind);
void initmenupaths(char *filename);
void savenames(void);
int loadnames(void);
int drawtilescreen(long pictopleft);
long gettile(long tilenum);
void getpalookup(void);
int fillregion(long x, long y, char col, char bound);
void getpaletteconversion(void);
int drawmaskedbox(long x1, long y1, long x2, long y2, char col, char mask1, char mask2);
int drawxorbox(long x1, long y1, long x2, long y2, char col);
void drawmainscreen(void);
int loadgif(char *filename);
int loadpcx(char *filename);
int loadbmp(char *filename);
void loadpicture(char *filename);
void drawcolordot(char thecol);
void updatepanningforumode(long dax, long day);
void updatepanning(void);
int drawdot(char col);
void copywalltoscreen(char *bufptr, long dapicnum, char maskmode);
int showall(char *bufptr);
int savewall(char *bufptr, long wallnum);
int loadwall(char *bufptr, long wallnum);
int savepics(void);
int loadpics(long dapicnum);
int loadtables(void);
static struct sectortype
{
short wallptr, wallnum;
long ceilingz, floorz;
short ceilingstat, floorstat;
short ceilingpicnum, ceilingheinum;
signed char ceilingshade;
char ceilingpal, ceilingxpanning, ceilingypanning;
short floorpicnum, floorheinum;
signed char floorshade;
char floorpal, floorxpanning, floorypanning;
char visibility, filler;
short lotag, hitag, extra;
} mapsector;
static struct walltype
{
long x, y;
short point2, nextwall, nextsector, cstat;
short picnum, overpicnum;
signed char shade;
char pal, xrepeat, yrepeat, xpanning, ypanning;
short lotag, hitag, extra;
} mapwall;
static struct spritetype
{
long x, y, z;
short cstat, picnum;
signed char shade;
char pal, clipdist, filler;
unsigned char xrepeat, yrepeat;
signed char xoffset, yoffset;
short sectnum, statnum;
short ang, owner, xvel, yvel, zvel;
short lotag, hitag, extra;
} mapsprite;
short nummaps, numsprites[MAXMAPS];
static char *pic;
static short int mousx, mousy, bstatus, moustat;
static unsigned char col, trailstatus, tempbuf[4096];
static short xfillbuf[4096], yfillbuf[4096];
static unsigned char printbuf[128];
static short tilesizx[MAXTILES], tilesizy[MAXTILES];
static long picanm[MAXTILES], artversion, numtiles;
static long panx, pany, panxforu, panyforu, panyoff = 0, panxdim;
static long lastshowallxdim = 0x7fffffff, lastshowallydim = 0x7fffffff;
static unsigned char buf[1024*512], *buf2;
static long waloff[MAXTILES], totpicmem, xdim, ydim, asksave, c, d, picnum;
static long totpicsiz, animspeed, allasksave, mustsavelocals = 0;
static long needtosavenames = 0, gettilezoom = 1;
static short sintable[2048];
static char blackmasklookup[256];
static short tilookup[MAXTILES], tilookup2[MAXTILES], tilesreported = 0;
static char artfilename[20];
static long localtilestart[MAXTILEFILES], localtileend[MAXTILEFILES];
static long curtilefile, numtilefiles;
static long xres, yres;
static char pcxheader[128] =
{
0xa,0x5,0x1,0x8,0x0,0x0,0x0,0x0,0x3f,0x1,0xc7,0x0,
0x40,0x1,0xc8,0x0,0x0,0x0,0x0,0x8,0x8,0x8,0x10,0x10,
0x10,0x18,0x18,0x18,0x20,0x20,0x20,0x28,0x28,0x28,0x30,0x30,
0x30,0x38,0x38,0x38,0x40,0x40,0x40,0x48,0x48,0x48,0x50,0x50,
0x50,0x58,0x58,0x58,0x60,0x60,0x60,0x68,0x68,0x68,0x70,0x70,
0x70,0x78,0x78,0x78,0x0,0x1,0x40,0x1,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
};
static long capfil = -1L;
static char names[MAXTILES][17];
static char menuname[MAXMENUFILES][17], curpath[160], menupath[160];
static long menunamecnt, menuhighlight;
static char textfont[128][8];
static char reversemask[16] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
static char whitecol, browncol, yellowcol, greencol, blackcol;
static char palookup[NUMPALOOKUPS][256], palette[768];
static char palette2[768], palookupe[256], *transluc, translucloaded = 0;
static unsigned char gifdata[GIFBUFLEN];
static unsigned char gifsuffix[4100], giffilbuffer[768], giftempstack[4096];
static short int gifprefix[4100];
static long totalclock;
static void (__interrupt __far *oldtimerhandler)();
static void __interrupt __far timerhandler(void);
#ifdef PLATFORM_DOS
/* Most of these will be caught in pragmas.c - DDOI */
#pragma aux scale =\
"imul ebx",\
"idiv ecx",\
parm [eax][ebx][ecx]\
modify [eax edx]\
#pragma aux mulscale =\
"imul ebx",\
"shrd eax, edx, cl",\
parm [eax][ebx][ecx]\
modify [edx]\
#pragma aux boundmulscale =\
"imul ebx",\
"mov ebx, edx",\
"shrd eax, edx, cl",\
"sar edx, cl",\
"xor edx, eax",\
"js checkit",\
"xor edx, eax",\
"jz skipboundit",\
"cmp edx, 0xffffffff",\
"je skipboundit",\
"checkit:",\
"mov eax, ebx",\
"sar eax, 31",\
"add eax, 0x80000000",\
"not eax",\
"skipboundit:",\
parm [eax][ebx][ecx]\
modify [edx]\
#pragma aux divscale =\
"cdq",\
"shld edx, eax, cl",\
"sal eax, cl",\
"idiv ebx",\
parm [eax][ebx][ecx]\
modify [edx]\
#pragma aux setvmode =\
"int 0x10",\
parm [eax]\
#pragma aux clearbuf =\
"rep stosd",\
parm [edi][ecx][eax]\
#pragma aux cleartopbox =\
"mov dx, 0x3c4",\
"mov ax, 0x0f02",\
"out dx, ax",\
"mov edi, 0xa1000",\
"mov ecx, 15360",\
"mov dl, blackcol",\
"mov dh, dl",\
"mov eax, edx",\
"shl eax, 16",\
"mov ax, dx",\
"rep stosd",\
modify [eax ecx edx edi]\
#pragma aux getpixel =\
"xor eax, eax",\
"mov al, [edi]",\
parm [edi]\
#pragma aux drawchainpixel =\
"mov dx, 0x3c4",\
"mov ax, 0x0102",\
"mov cx, di",\
"and cl, 3",\
"shl ah, cl",\
"out dx, ax",\
"shr edi, 2",\
"mov byte ptr [edi+0xa0000], bl",\
parm [edi][ebx]\
modify [eax ecx edx]\
#pragma aux drawpixel =\
"mov [edi], al",\
parm [edi][eax]\
#pragma aux drawpixels =\
"mov [edi], ax",\
parm [edi][eax]\
#pragma aux drawpixelses =\
"mov [edi], eax",\
parm [edi][eax]\
#pragma aux setupmouse =\
"mov ax, 0",\
"int 33h",\
"mov moustat,1",\
#pragma aux readmouse =\
"mov ax, 11d",\
"int 33h",\
"sar cx, 1",\
"sar dx, 1",\
"mov mousx, cx",\
"mov mousy, dx",\
"mov ax, 5d",\
"int 33h",\
"mov bstatus, ax",\
modify [eax ebx ecx edx]\
#pragma aux limitrate =\
"mov dx, 0x3da",\
"wait1: in al, dx",\
"test al, 8",\
"jnz wait1",\
"wait2: in al, dx",\
"test al, 8",\
"jz wait2",\
modify [edx]\
#pragma aux cleartext =\
"mov dx, 0x3c4",\
"mov ax, 0x0f02",\
"out dx, ax",\
"mov edi, 0xa0800",\
"mov ebx, 8",\
"mov ah, browncol",\
"mov al, ah",\
"shl eax, 8",\
"mov al, ah",\
"shl eax, 8",\
"mov al, ah",\
"begclearit: mov ecx, 14",\
"rep stosd",\
"add edi, 200",\
"sub ebx, 1",\
"jnz begclearit",\
modify [eax ebx ecx edx edi]\
//the 200 above = 256-28chars*2
//eax = (eax>>bitcnt)&((1<<numbits)-1);
#pragma aux gifgetdat =\
"mov eax, dword ptr giffilbuffer[eax]",\
"shr eax, cl",\
"xchg ebx, ecx",\
"mov ebx, 1",\
"shl ebx, cl",\
"dec ebx",\
"and eax, ebx",\
parm [eax][ebx][ecx]\
modify [eax ebx ecx]\
#endif // PLATFORM_DOS
void __interrupt __far timerhandler()
{
totalclock++;
#ifdef PLATFORM_DOS
_chain_intr(oldtimerhandler);
#endif
}
int main(int argc, char **argv)
{
unsigned char ch, *keystateptr, keystate, tempchar, filename[160];
unsigned char buffer[160], buffer2[160], dacol, col1, col2;
long i, j, k, l, m, n, x, y, x1, y1, x2, y2, xoff, yoff;
long fil, templong, dat, good, vidpos;
long markx, marky, markxlen, markylen;
long xstep, ystep, lin, num, oxdim, oydim;
//printf("------------------------------------------------------------------------------\n");
//printf("EDITART.EXE Copyright (c) 1993 - 1996 Ken Silverman, 3D Realms Entertainment.\n");
//printf("This version of EDITART was created for Duke Nukem 3D.\n");
//printf("\n");
//printf("IMPORTANT: EDITART.EXE and associated tools and utilities are NOT\n");
//printf("shareware and may NOT be freely distributed to any BBS, CD, floppy, or\n");
//printf("any other media. These tools may NOT be sold or repackaged for sale in\n");
//printf("a commercial product.\n");
//printf("\n");
//printf("Please help us protect against software piracy (which drives up software\n");
//printf("prices) by following these simple rules.\n");
//printf("\n");
//printf("Thank You!\n");
//printf("------------------------------------------------------------------------------\n");
//getch();
_platform_init(argc, argv);
if (argc >= 2)
{
// Weird... GCC wants me to add these casts - DDOI
strcpy((char *)&artfilename,argv[1]);
i = 0;
while ((artfilename[i] != 0) && (i < 5))
i++;
while (i < 5)
{
artfilename[i] = '_';
i++;
}
artfilename[5] = '0';
artfilename[6] = '0';
artfilename[7] = '0';
artfilename[8] = '.';
artfilename[9] = 'a';
artfilename[10] = 'r';
artfilename[11] = 't';
artfilename[12] = 0;
}
else
strcpy((char *)&artfilename,"tiles000.art");
panxdim = 1024L;
setvmode(0x13);
outp(0x3c4,0x4); outp(0x3c5,0x6);
outp(0x3d4,0x14); outp(0x3d5,0x0);
outp(0x3d4,0x17); outp(0x3d5,0xe3);
outp(0x3d4,0x13); outp(0x3d5,panxdim>>3);
outp(0x3c4,2); outp(0x3c5,15);
clearbuf(VIDEOBASE,16384,0L);
loadtables();
printext256(80L,84L,4,0,"Editart 7/24/96");
printext256(80L,92L,4,0,"by Kenneth Silverman");
sprintf(buffer,"Loading %s...",artfilename);
printext256(80L,108L,4,0,buffer);
initmenupaths(argv[0]);
setupmouse();
for(i=0;i<MAXTILES;i++)
tilookup[i] = i;
mousx = 0;
mousy = 0;
bstatus = 0;
if ((fil = open("palette.dat",O_BINARY|O_RDWR,S_IREAD)) != -1)
{
read(fil,&palette[0],768);
read(fil,&palookup[0][0],NUMPALOOKUPS*256);
gettextcolors();
for(i=0;i<255;i++) blackmasklookup[i] = i;
blackmasklookup[255] = blackcol;
close(fil);
}
totpicmem = 16777216L; //allocate pic = rest of memory
while ((pic = (char *)malloc(totpicmem)) == 0)
totpicmem -= 4096L;
buf2 = NULL;
if (totpicmem > 1048576)
{
buf2 = (char *)(FP_OFF(pic)+totpicmem-(1024*512));
totpicmem -= (1024*512);
}
for(i=0;i<MAXTILES;i++)
{
tilesizx[i] = 0;
tilesizy[i] = 0;
picanm[i] = 0L;
}
loadnames();
for(i=0;i<MAXTILEFILES;i++)
{
localtilestart[i] = -1;
localtileend[i] = -1;
}
numtilefiles = 0;
do
{
i = numtilefiles;
strcpy(filename,artfilename);
filename[7] = (numtilefiles%10)+48;
filename[6] = ((numtilefiles/10)%10)+48;
filename[5] = ((numtilefiles/100)%10)+48;
if ((fil = open(filename,O_BINARY|O_RDONLY,S_IREAD)) != -1)
{
read(fil,&artversion,4);
if (artversion != 1)
{
printf("Wrong art version");
exit(0);
}
read(fil,&numtiles,4);
read(fil,&localtilestart[numtilefiles],4);
read(fil,&localtileend[numtilefiles],4);
close(fil);
numtilefiles++;
}
}
while (numtilefiles != i);
picnum = 0;
curtilefile = -1;
loadpics(picnum);
menunamecnt = 0;
menuhighlight = 0;
keystateptr = (char *)0x417;
col = 0;
trailstatus = 0;
ch = 0;
loadwall(buf,picnum);
c = (xdim>>1);
d = (ydim>>1);
markx = 0;
marky = 0;
markxlen = 0;
markylen = 0;
drawmainscreen();
while (ch != 27)
{
if (kbhit() != 0)
{
ch = getch();
if (ch == 0)
{
ch = getch();
keystate = *keystateptr;
if ((keystate&3) == 0)
{
drawdot(buf[(d<<10)+c]);
if ((ch == 75) && (c > 0)) c--;
if ((ch == 77) && (c < xdim-1)) c++;
if ((ch == 72) && (d > 0)) d--;
if ((ch == 80) && (d < ydim-1)) d++;
drawdot((buf[(d<<10)+c]+16)&255);
}
else
{
drawcolordot(col);
if ((ch == 75) && (col > 0)) col--;
if ((ch == 77) && (col < 255)) col++;
if ((ch == 72) && (col > 31)) col -= 32;
if ((ch == 80) && (col < 224)) col += 32;
drawcolordot((col+16)&255);
}
if ((ch == 73) && (picnum > 0))
{
if (savewall(buf,picnum) == 0)
{
picnum--;
loadpics(picnum);
loadwall(buf,picnum);
showall(buf);
drawdot((buf[(d<<10)+c]+16)&255);
}
}
if ((ch == 81) && (picnum < MAXTILES-1))
{
if (savewall(buf,picnum) == 0)
{
picnum++;
loadpics(picnum);
loadwall(buf,picnum);
showall(buf);
drawdot((buf[(d<<10)+c]+16)&255);
}
}
if (ch == 83)
{
xdim = 0;
ydim = 0;
c = (xdim>>1);
d = (ydim>>1);
asksave = 1;
drawmainscreen();
}
if (ch == 121) //ALT+2
{
xdim = 32;
ydim = 32;
c = (xdim>>1);
d = (ydim>>1);
asksave = 1;
drawmainscreen();
}
if (ch == 22) //Alt-U (update script!)
{
savewall(buf,picnum);
savepics();
updatescript(0L,MAXTILES-1L);
loadpics(picnum);
loadwall(buf,picnum);
drawmainscreen();
ch = 255;
}
if (ch == 134) //F12
{
drawdot(buf[(d<<10)+c]);
screencapture();
drawdot((buf[(d<<10)+c]+16)&255);
}
ch = 0;
}
if ((ch == 'b') || (ch == 'B'))
{
drawdot(buf[(d<<10)+c]);
screencapture();
drawdot((buf[(d<<10)+c]+16)&255);
}
if ((ch == 't') || (ch == 'T'))
{
buf[(d<<10)+c] = col, asksave = 1;
trailstatus = 1-trailstatus;
if (trailstatus == 0)
printmessage("Trail OFF");
else
printmessage("Trail ON");
}
if ((ch == 32) || (trailstatus == 1))
buf[(d<<10)+c] = col, asksave = 1;
if (ch == 92) // It'a a \!
{
drawdot(buf[(d<<10)+c]);
c = (xdim>>1);
d = (ydim>>1);
drawdot((buf[(d<<10)+c]+16)&255);
}
if (ch == '|')
{
sprintf((char *)&printbuf,"Coordinates: (%d,%d)",c,d);
printmessage(&printbuf);
}
if (ch == 8)
{
drawcolordot(col);
col = 255;
drawcolordot((col+16)&255);
}
if ((ch == ',') || (ch == '.') || (ch == '<') || (ch == '>'))
{
xstep = 0;
ystep = 0;
if (markx > c) xstep = 1;
if (markx < c) xstep = -1;
if (marky > d) ystep = 1;
if (marky < d) ystep = -1;
i = c-xstep;
do
{
i += xstep;
j = d-ystep;
do
{
j += ystep;
if ((buf[(j<<10)+i]&31) > 0)
if (ch == ',') buf[(j<<10)+i]--;
if ((buf[(j<<10)+i]&31) < 31)
if (ch == '.') buf[(j<<10)+i]++;
if (ch == '<')
{
buf[(j<<10)+i] += 224;
buf[(j<<10)+i] &= 255;
}
if (ch == '>')
{
buf[(j<<10)+i] += 32;
buf[(j<<10)+i] &= 255;
}
}
while (j != marky);
}
while (i != markx);
showall(buf);
asksave = 1;
}
if ((ch == 'M') || (ch == 'm'))
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
buf2[(j<<10)+i] = buf[(j<<10)+i];
printmessage("Tile in memory (P - restore)");
}
}
if ((ch == 'P') || (ch == 'p'))
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
buf[(j<<10)+i] = buf2[(j<<10)+i];
showall(buf);
asksave = 1;
printmessage("Tile restored from memory");
}
}
if ((ch == 'J') || (ch == 'j'))
{
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if (buf[(j<<10)+i] == buf[(d<<10)+c])
if ((rand()&15) == 0)
buf[(j<<10)+i] = col;
showall(buf);
asksave = 1;
}
if ((ch == ']') && (xdim > 0) && (ydim > 0))
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
k = (buf[(d<<10)+c]>>5);
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
buf2[(j<<10)+i] = buf[(j<<10)+i];
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if ((buf[(j<<10)+i]>>5) == k)
{
m = buf2[(((j+0)%ydim)<<10)+((i+0)%xdim)]*2, n = 2;
tempchar = buf2[(((j+0)%ydim)<<10)+((i+1)%xdim)];
if ((tempchar>>5) == k)
m += tempchar, n += 1;
tempchar = buf2[(((j+0)%ydim)<<10)+((i-1)%xdim)];
if ((tempchar>>5) == k)
m += tempchar, n += 1;
tempchar = buf2[(((j+1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) == k)
m += tempchar, n += 1;
tempchar = buf2[(((j-1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) == k)
m += tempchar, n += 1;
buf[(j<<10)+i] = (buf[(j<<10)+i]&0xe0)+(((m+(n>>1))/n)&31);
}
showall(buf);
asksave = 1;
}
}
if ((ch == '[') && (xdim > 0) && (ydim > 0))
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
k = (buf[(d<<10)+c]>>5);
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
buf2[(j<<10)+i] = buf[(j<<10)+i];
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if ((buf[(j<<10)+i]>>5) == k)
{
m = buf2[(((j+0)%ydim)<<10)+((i+0)%xdim)]*2, n = 2;
l = rand();
tempchar = buf2[(((j+0)%ydim)<<10)+((i+1)%xdim)];
if (((tempchar>>5) == k) && ((l&0x03) == 0))
m += tempchar, n++;
tempchar = buf2[(((j+0)%ydim)<<10)+((i-1)%xdim)];
if (((tempchar>>5) == k) && ((l&0x0c) == 0))
m += tempchar, n++;
tempchar = buf2[(((j+1)%ydim)<<10)+((i+0)%xdim)];
if (((tempchar>>5) == k) && ((l&0x30) == 0))
m += tempchar, n++;
tempchar = buf2[(((j-1)%ydim)<<10)+((i+0)%xdim)];
if (((tempchar>>5) == k) && ((l&0xc0) == 0))
m += tempchar, n++;
buf[(j<<10)+i] = (buf[(j<<10)+i]&0xe0)+(((m+(n>>1))/n)&31);
}
showall(buf);
asksave = 1;
}
}
if ((ch == 39) && (xdim > 0) && (ydim > 0)) // It's a '
{
k = (buf[(d<<10)+c]>>5);
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if ((buf[(j<<10)+i]>>5) == k)
{
m = (buf[(j<<10)+i]&31);
tempchar = buf[(((j+0)%ydim)<<10)+((i+1)%xdim)];
if ((tempchar>>5) != k)
m--;
tempchar = buf[(((j+0)%ydim)<<10)+((i-1)%xdim)];
if ((tempchar>>5) != k)
m++;
tempchar = buf[(((j+1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) != k)
m--;
tempchar = buf[(((j-1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) != k)
m++;
if (m < 0) m = 0;
if (m > 31) m = 31;
buf[(j<<10)+i] = (buf[(j<<10)+i]&0xe0)+m;
}
showall(buf);
asksave = 1;
}
if ((ch == ';') && (xdim > 0) && (ydim > 0))
{
k = (buf[(d<<10)+c]>>5);
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if ((buf[(j<<10)+i]>>5) == k)
{
m = (buf[(j<<10)+i]&31);
tempchar = buf[(((j+0)%ydim)<<10)+((i+1)%xdim)];
if ((tempchar>>5) != k)
m++;
tempchar = buf[(((j+0)%ydim)<<10)+((i-1)%xdim)];
if ((tempchar>>5) != k)
m--;
tempchar = buf[(((j+1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) != k)
m++;
tempchar = buf[(((j-1)%ydim)<<10)+((i+0)%xdim)];
if ((tempchar>>5) != k)
m--;
if (m < 0) m = 0;
if (m > 31) m = 31;
buf[(j<<10)+i] = (buf[(j<<10)+i]&0xe0)+m;
}
showall(buf);
asksave = 1;
}
if (((ch == 'R') || (ch == 'r')) && (xdim > 0) && (ydim > 0))
{
printmessage("Rotate tile (Use arrows)");
ch = getch();
if (ch == 0)
{
ch = getch();
if (ch == 75)
for(i=xdim-1;i>=1;i--)
for(j=0;j<ydim;j++)
{
tempchar = buf[(j<<10)+i];
buf[(j<<10)+i] = buf[(j<<10)+((i+1)%xdim)];
buf[(j<<10)+((i+1)%xdim)] = tempchar;
}
if (ch == 77)
for(i=1;i<xdim;i++)
for(j=0;j<ydim;j++)
{
tempchar = buf[(j<<10)+i];
buf[(j<<10)+i] = buf[(j<<10)+((i+1)%xdim)];
buf[(j<<10)+((i+1)%xdim)] = tempchar;
}
if (ch == 72)
for(i=0;i<xdim;i++)
for(j=ydim-1;j>=1;j--)
{
tempchar = buf[(j<<10)+i];
buf[(j<<10)+i] = buf[(((j+1)%ydim)<<10)+i];
buf[(((j+1)%ydim)<<10)+i] = tempchar;
}
if (ch == 80)
for(i=0;i<xdim;i++)
for(j=1;j<ydim;j++)
{
tempchar = buf[(j<<10)+i];
buf[(j<<10)+i] = buf[(((j+1)%ydim)<<10)+i];
buf[(((j+1)%ydim)<<10)+i] = tempchar;
}
showall(buf);
}
asksave = 1;
cleartext();
}
if ((ch == 'C') || (ch == 'c'))
{
tempchar = buf[(d<<10)+c];
for(i=0;i<xdim;i++)
for(j=0;j<ydim;j++)
if (buf[(j<<10)+i] == tempchar)
buf[(j<<10)+i] = col;
showall(buf);
asksave = 1;
}
if (ch == '1')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
markx = c;
marky = d;
printmessage("1st point set (2 - copy)");
}
}
if (ch == '2')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
x = markx, y = marky, x2 = c, y2 = d;
if (x > x2)
templong = x, x = x2, x2 = templong;
if (y > y2)
templong = y, y = y2, y2 = templong;
markxlen = x2-x+1;
markylen = y2-y+1;
for(i=0;i<markxlen;i++)
for(j=0;j<markylen;j++)
buf2[(j<<10)+i] = buf[((j+y)<<10)+(i+x)];
printmessage("Region copied (3 - paste)");
}
}
if (ch == '3')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
for(i=0;i<markxlen;i++)
for(j=0;j<markylen;j++)
if ((i+c < xdim) && (j+d < ydim) && (buf2[(j<<10)+i] != 255))
buf[((j+d)<<10)+(i+c)] = buf2[(j<<10)+i];
showall(buf);
asksave = 1;
}
}
if (ch == '4')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
for(i=0;i<(markxlen>>1);i++)
for(j=0;j<markylen;j++)
{
templong = buf2[(j<<10)+i];
buf2[(j<<10)+i] = buf2[(j<<10)+(markxlen-1-i)];
buf2[(j<<10)+(markxlen-1-i)] = templong;
}
printmessage("Region flipped x-wise");
}
}
if (ch == '5')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
for(i=0;i<markxlen;i++)
for(j=0;j<(markylen>>1);j++)
{
templong = buf2[(j<<10)+i];
buf2[(j<<10)+i] = buf2[((markylen-1-j)<<10)+i];
buf2[((markylen-1-j)<<10)+i] = templong;
}
printmessage("Region flipped y-wise");
}
}
if (ch == '6')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");
}
else
{
x2 = xdim;
y2 = ydim;
if (x2 > 480) x2 = 480;
if (y2 > 480) y2 = 480;
for(i=0;i<x2;i++)
for(j=0;j<y2;j++)
if (i > j)
{
templong = buf2[(i<<10)+j];
buf2[(i<<10)+j] = buf2[(j<<10)+i];
buf2[(j<<10)+i] = templong;
}
templong = markxlen;
markxlen = markylen;
markylen = templong;
printmessage("X and Y swapped");
}
}
if (ch == '8')
{
if (buf2 == NULL)
{
printmessage("Not enough memory for that!");