-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTiles2.cs
1327 lines (1185 loc) · 47.6 KB
/
Tiles2.cs
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
namespace M1TE2
{
public static class TilesU // undo backup copy
{
public static int[] Tile_Arrays = new int[8 * 256 * 8 * 8]; // 131072
}
public static class Tiles
{
public static int[] Tile_Arrays = new int[8 * 256 * 8 * 8]; // 131072
// 8 sets, 256 tiles, 8 high, 8 wide
// 4 sets 4bpp allow values 0-15, 4 sets 2bpp allow values 0-3
public static int[] Tile_Copier = new int[8 * 8]; // one tile
public static int[] Tile_Copier16 = new int[16 * 16]; // one tile
public static int[] Tile_Temp16 = new int[16 * 16]; // one tile
public static bool Has_Copied = false;
public static int[] trans_array = new int[16384]; // linear
public static int[] copy_array = new int[16384];
public static int trans_x, trans_y; // in tiles
public static int trans_w = 1; // in tiles
public static int trans_h = 1;
public static int copy_x, copy_y; // in tiles
public static int copy_w = 1; // in tiles
public static int copy_h = 1;
// you know, I regret the way I set up the tile array
// and I think a linear format woud be easier to
// work with for large transformations
// this converts from tile array to a linear format
public static void Tiles_2_Linear()
{
//in - globals trans_x, trans_y, trans_w, trans_h
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
// should be values 0-127
int offset = Form1.tile_set * 16384;
for (int y1 = start_y; y1 < final_y; y1++)
{
for (int x1 = start_x; x1 < final_x; x1++)
{
int tile_xH = x1 >> 3;
int tile_xL = x1 & 7;
int tile_yH = y1 >> 3;
int tile_yL = y1 & 7;
int index1 = (tile_yH * 1024) + (tile_xH * 64) + (tile_yL * 8) + tile_xL;
index1 += offset;
int index2 = (y1 * 128) + x1;
trans_array[index2] = Tile_Arrays[index1];
}
}
}
// this converts the linear / transformation array
// back to the old tile format
public static void Linear_2_Tiles()
{
//in - globals trans_x, trans_y, trans_w, trans_h
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
// should be values 0-127
int offset = Form1.tile_set * 16384;
for (int y1 = start_y; y1 < final_y; y1++)
{
for (int x1 = start_x; x1 < final_x; x1++)
{
int tile_xH = x1 >> 3;
int tile_xL = x1 & 7;
int tile_yH = y1 >> 3;
int tile_yL = y1 & 7;
int index1 = (tile_yH * 1024) + (tile_xH * 64) + (tile_yL * 8) + tile_xL;
index1 += offset;
int index2 = (y1 * 128) + x1;
Tile_Arrays[index1] = trans_array[index2];
}
}
}
public static void Make_Box_Same()
{
trans_x = Form1.BE_x1;
trans_y = Form1.BE_y1;
trans_w = Form1.BE_x2 - Form1.BE_x1;
if (trans_w < 1) trans_y = 1;
trans_h = Form1.BE_y2 - Form1.BE_y1;
if (trans_h < 1) trans_h = 1;
}
public static void Nix_Copy()
{
Has_Copied = false;
}
public static void shift_left_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
for (int y1 = start_y; y1 < final_y; y1++)
{
int index = (y1 * 128) + start_x;
int temp = trans_array[index];
for (int x1 = start_x; x1 < final_x - 1; x1++)
{
index = (y1 * 128) + x1;
trans_array[index] = trans_array[index + 1];
}
index = (y1 * 128) + final_x - 1;
trans_array[index] = temp;
}
Linear_2_Tiles();
}
public static void shift_left()
{
if(Form1.brushsize == Form1.BRUSH_MULTI)
{
shift_left_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z + (y * 8)]; // save the left most
for (int x = 0; x < 7; x++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + (y * 8) + x + 1];
}
Tile_Arrays[z + (y * 8) + 7] = temp; // put it on the right
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z + (y * 8)]; // save the left most
for (int x = 0; x < 7; x++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + (y * 8) + x + 1];
}
//transfer 1 pixel from R tile to L tile
Tile_Arrays[z + (y * 8) + 7] = Tile_Arrays[z2 + (y * 8)];
for (int x = 0; x < 7; x++)
{
Tile_Arrays[z2 + (y * 8) + x] = Tile_Arrays[z2 + (y * 8) + x + 1];
}
Tile_Arrays[z2 + (y * 8) + 7] = temp; // put it on the right
}
// one tile down
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z + (y * 8)]; // save the left most
for (int x = 0; x < 7; x++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + (y * 8) + x + 1];
}
//transfer 1 pixel from R tile to L tile
Tile_Arrays[z + (y * 8) + 7] = Tile_Arrays[z2 + (y * 8)];
for (int x = 0; x < 7; x++)
{
Tile_Arrays[z2 + (y * 8) + x] = Tile_Arrays[z2 + (y * 8) + x + 1];
}
Tile_Arrays[z2 + (y * 8) + 7] = temp; // put it on the right
}
}
}
public static void shift_right_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
for (int y1 = start_y; y1 < final_y; y1++)
{
int index = (y1 * 128) + final_x - 1;
int temp = trans_array[index];
for (int x1 = final_x - 2; x1 >= start_x; x1--)
{
index = (y1 * 128) + x1;
trans_array[index + 1] = trans_array[index];
}
index = (y1 * 128) + start_x;
trans_array[index] = temp;
}
Linear_2_Tiles();
}
public static void shift_right()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
shift_right_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z + (y * 8) + 7]; // save the right most
for (int x = 6; x >= 0; x--)
{
Tile_Arrays[z + (y * 8) + x + 1] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + (y * 8)] = temp; // put it on the left
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z2 + (y * 8) + 7]; // save the right most
for (int x = 6; x >= 0; x--)
{
Tile_Arrays[z2 + (y * 8) + x + 1] = Tile_Arrays[z2 + (y * 8) + x];
}
//transfer 1 pixel from L tile to R tile
Tile_Arrays[z2 + (y * 8)] = Tile_Arrays[z + (y * 8) + 7];
for (int x = 6; x >= 0; x--)
{
Tile_Arrays[z + (y * 8) + x + 1] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + (y * 8)] = temp; // put it on the left
}
// one tile down
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
int temp = Tile_Arrays[z2 + (y * 8) + 7]; // save the right most
for (int x = 6; x >= 0; x--)
{
Tile_Arrays[z2 + (y * 8) + x + 1] = Tile_Arrays[z2 + (y * 8) + x];
}
//transfer 1 pixel from L tile to R tile
Tile_Arrays[z2 + (y * 8)] = Tile_Arrays[z + (y * 8) + 7];
for (int x = 6; x >= 0; x--)
{
Tile_Arrays[z + (y * 8) + x + 1] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + (y * 8)] = temp; // put it on the left
}
}
}
public static void shift_up_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
for (int x1 = start_x; x1 < final_x; x1++)
{
int index = (start_y * 128) + x1;
int temp = trans_array[index];
for (int y1 = start_y; y1 < final_y - 1; y1++)
{
index = (y1 * 128) + x1;
trans_array[index] = trans_array[index + 128];
}
index = ((final_y - 1) * 128) + x1;
trans_array[index] = temp;
}
Linear_2_Tiles();
}
public static void shift_up()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
shift_up_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + x]; // save the top most
for (int y = 0; y < 7; y++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + ((y + 1) * 8) + x];
}
Tile_Arrays[z + 56 + x] = temp; // put it on the bottom
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + x]; // save the top most
for (int y = 0; y < 7; y++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + ((y + 1) * 8) + x];
}
//transfer 1 pixel from bottom tile to top
Tile_Arrays[z + 56 + x] = Tile_Arrays[z2 + x];
for (int y = 0; y < 7; y++)
{
Tile_Arrays[z2 + (y * 8) + x] = Tile_Arrays[z2 + ((y + 1) * 8) + x];
}
Tile_Arrays[z2 + 56 + x] = temp; // put it on the bottom
}
// one to the right
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + x]; // save the top most
for (int y = 0; y < 7; y++)
{
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + ((y + 1) * 8) + x];
}
//transfer 1 pixel from bottom tile to top
Tile_Arrays[z + 56 + x] = Tile_Arrays[z2 + x];
for (int y = 0; y < 7; y++)
{
Tile_Arrays[z2 + (y * 8) + x] = Tile_Arrays[z2 + ((y + 1) * 8) + x];
}
Tile_Arrays[z2 + 56 + x] = temp; // put it on the bottom
}
}
}
public static void shift_down_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
for (int x1 = start_x; x1 < final_x; x1++)
{
int index = ((final_y - 1) * 128) + x1;
int temp = trans_array[index];
for (int y1 = final_y - 2; y1 >= start_y; y1--)
{
index = (y1 * 128) + x1;
trans_array[index + 128] = trans_array[index];
}
index = (start_y * 128) + x1;
trans_array[index] = temp;
}
Linear_2_Tiles();
}
public static void shift_down()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
shift_down_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + 56 + x]; // save the bottom most
for (int y = 6; y >= 0; y--)
{
Tile_Arrays[z + ((y + 1) * 8) + x] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + x] = temp; // put it on the top
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z2 + 56 + x]; // save the bottom most
for (int y = 6; y >= 0; y--)
{
Tile_Arrays[z2 + ((y + 1) * 8) + x] = Tile_Arrays[z2 + (y * 8) + x];
}
//transfer 1 pixel from top to bottom
Tile_Arrays[z2 + x] = Tile_Arrays[z + 56 + x];
for (int y = 6; y >= 0; y--)
{
Tile_Arrays[z + ((y + 1) * 8) + x] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + x] = temp; // put it on the top
}
// one to the right
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z2 + 56 + x]; // save the bottom most
for (int y = 6; y >= 0; y--)
{
Tile_Arrays[z2 + ((y + 1) * 8) + x] = Tile_Arrays[z2 + (y * 8) + x];
}
//transfer 1 pixel from top to bottom
Tile_Arrays[z2 + x] = Tile_Arrays[z + 56 + x];
for (int y = 6; y >= 0; y--)
{
Tile_Arrays[z + ((y + 1) * 8) + x] = Tile_Arrays[z + (y * 8) + x];
}
Tile_Arrays[z + x] = temp; // put it on the top
}
}
}
public static void tile_copy_big()
{
// just copy the entire set
int offset = Form1.tile_set * 16384;
for (int i = 0; i < 16384; i++)
{
copy_array[i] = Tile_Arrays[i + offset];
}
// remember the bounds
copy_x = trans_x;
copy_y = trans_y;
copy_w = trans_w;
copy_h = trans_h;
Has_Copied = true;
}
public static void tile_copy()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_copy_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int x = 0; x < 64; x++)
{
Tile_Copier[x] = Tile_Arrays[z + x];
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
for (int x = 0; x < 64; x++)
{
Tile_Copier16[x] = Tile_Arrays[z + x];
}
int temp_tile_num = (Form1.tile_num + 1);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Copier16[x + 64] = Tile_Arrays[z + x];
}
temp_tile_num = (Form1.tile_num + 16);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Copier16[x + 128] = Tile_Arrays[z + x];
}
temp_tile_num = (Form1.tile_num + 17);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Copier16[x + 192] = Tile_Arrays[z + x];
}
}
Has_Copied = true;
}
public static void tile_paste_big()
{
// copy_x, copy_y, copy_w, copy_h = bounds
// copy_array[] = where, usual tile format
int offset = Form1.tile_set * 16384;
// 0, 64, 128, etc.
// 1024
for (int y1 = 0; y1 < copy_h; y1++) // in tiles
{
for (int x1 = 0; x1 < copy_w; x1++)
{
if ((Form1.tile_x + x1) >= 16) continue; // no wrapping
if ((Form1.tile_y + y1) >= 16) continue; // no overflow
int src_index = ((copy_y + y1) * 1024) + ((copy_x + x1) * 64);
int dest_index = ((Form1.tile_y + y1) * 1024) + ((Form1.tile_x + x1) * 64);
if (dest_index >= 16384) continue; // no overflow
dest_index += offset;
//copy tile by tile, which is 64 values
if (Form1.map_view == 2) // 2bpp
{
for (int i = 0; i < 64; i++)
{
Tile_Arrays[dest_index + i] = copy_array[src_index + i] & 3;
}
}
else // 4bpp
{
for (int i = 0; i < 64; i++)
{
Tile_Arrays[dest_index + i] = copy_array[src_index + i];
}
}
}
}
}
public static void tile_paste()
{
if (Has_Copied == false) return;
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_paste_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
if (Form1.map_view == 2) // 2bpp
{
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier[x] & 3; //values 0-3
}
}
else // 4bpp
{
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier[x];
}
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
if (Form1.map_view == 2) // 2bpp
{
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x] & 3;
}
int temp_tile_num = (Form1.tile_num + 1);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 64] & 3;
}
temp_tile_num = (Form1.tile_num + 16);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 128] & 3;
}
temp_tile_num = (Form1.tile_num + 17);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 192] & 3;
}
}
else // 4bpp
{
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x];
}
int temp_tile_num = (Form1.tile_num + 1);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 64];
}
temp_tile_num = (Form1.tile_num + 16);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 128];
}
temp_tile_num = (Form1.tile_num + 17);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = Tile_Copier16[x + 192];
}
}
}
}
public static void tile_delete_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
for (int y1 = start_y; y1 < final_y; y1++)
{
for (int x1 = start_x; x1 < final_x; x1++)
{
int index = (y1 * 128) + x1;
trans_array[index] = 0;
}
}
Linear_2_Tiles();
}
public static void tile_delete()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_delete_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = 0;
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = 0;
}
int temp_tile_num = (Form1.tile_num + 1);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = 0;
}
temp_tile_num = (Form1.tile_num + 16);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = 0;
}
temp_tile_num = (Form1.tile_num + 17);
z = (Form1.tile_set * 256 * 8 * 8) + (temp_tile_num * 8 * 8);
for (int x = 0; x < 64; x++)
{
Tile_Arrays[z + x] = 0;
}
}
}
public static void tile_h_flip_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
int mid_x = trans_w * 4;
for (int y1 = start_y; y1 < final_y; y1++)
{
for (int x1 = 0; x1 < mid_x; x1++)
{
int left_x = start_x + x1;
int right_x = (final_x - x1) - 1;
int index1 = (y1 * 128) + left_x;
int index2 = (y1 * 128) + right_x;
int temp = trans_array[index1];
trans_array[index1] = trans_array[index2];
trans_array[index2] = temp;
}
}
Linear_2_Tiles();
}
public static void tile_h_flip()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_h_flip_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 4; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + (y * 8) + (7 - x)];
Tile_Arrays[z + (y * 8) + (7 - x)] = temp;
}
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z2 + (y * 8) + (7 - x)];
Tile_Arrays[z2 + (y * 8) + (7 - x)] = temp;
}
}
//lower
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z2 + (y * 8) + (7 - x)];
Tile_Arrays[z2 + (y * 8) + (7 - x)] = temp;
}
}
}
}
public static void tile_v_flip_big()
{
Tiles_2_Linear();
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
int mid_y = trans_h * 4;
for (int x1 = start_x; x1 < final_x; x1++)
{
for (int y1 = 0; y1 < mid_y; y1++)
{
int top_y = start_y + y1;
int low_y = (final_y - y1) - 1;
int index1 = (top_y * 128) + x1;
int index2 = (low_y * 128) + x1;
int temp = trans_array[index1];
trans_array[index1] = trans_array[index2];
trans_array[index2] = temp;
}
}
Linear_2_Tiles();
}
public static void tile_v_flip()
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_v_flip_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
if (Form1.tilesize == Form1.TILE_8X8)
{
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z + ((7 - y) * 8) + x];
Tile_Arrays[z + ((7 - y) * 8) + x] = temp;
}
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z2 + ((7 - y) * 8) + x];
Tile_Arrays[z2 + ((7 - y) * 8) + x] = temp;
}
}
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 8; x++)
{
int temp = Tile_Arrays[z + (y * 8) + x];
Tile_Arrays[z + (y * 8) + x] = Tile_Arrays[z2 + ((7 - y) * 8) + x];
Tile_Arrays[z2 + ((7 - y) * 8) + x] = temp;
}
}
}
}
public static void tile_rot_cw_big()
{
Tiles_2_Linear();
// make it a square, or else this function will mangle it
if (trans_w > trans_h)
{
trans_w = trans_h;
Form1.BE_x2 = Form1.BE_x1 + trans_w;
}
if (trans_h > trans_w)
{
trans_h = trans_w;
Form1.BE_y2 = Form1.BE_y1 + trans_h;
}
int start_x = trans_x * 8;
int final_x = (trans_w * 8) + start_x;
int start_y = trans_y * 8;
int final_y = (trans_h * 8) + start_y;
int mid_x = trans_w * 4;
int mid_y = trans_h * 4;
for (int y1 = 0; y1 < mid_y; y1++)
{
for (int x1 = 0; x1 < mid_x; x1++)
{
int index1, index2, index3, index4;
int y2 = start_y + y1;
int x2 = start_x + x1;
index1 = (y2 * 128) + x2;
int temp = trans_array[index1];
int y3 = final_y - x1 - 1;
int x3 = start_x + y1;
index3 = (y3 * 128) + x3;
trans_array[index1] = trans_array[index3];
y2 = final_y - y1 - 1;
x2 = final_x - x1 - 1;
index4 = (y2 * 128) + x2;
trans_array[index3] = trans_array[index4];
y3 = start_y + x1;
x3 = final_x - y1 - 1;
index2 = (y3 * 128) + x3;
trans_array[index4] = trans_array[index2];
trans_array[index2] = temp;
}
}
Linear_2_Tiles();
}
public static void tile_rot_cw() // R, rotate clockwise
{
if (Form1.brushsize == Form1.BRUSH_MULTI)
{
tile_rot_cw_big();
return;
}
int z = (Form1.tile_set * 256 * 8 * 8) + (Form1.tile_num * 8 * 8); // base index
int[] temp_arr = new int[64];
if (Form1.tilesize == Form1.TILE_8X8)
{
int count = 0;
for (int x = 0; x < 8; x++)
{
for (int y = 7; y >= 0; y--)
{
temp_arr[count++] = Tile_Arrays[z + (y * 8) + x];
}
}
for (int i = 0; i < 64; i++)
{
Tile_Arrays[z + i] = temp_arr[i];
}
}
else // 16x16
{
if ((Form1.tile_x > 14) || (Form1.tile_y > 14)) return;
// this should never wrap around now
// first copy tiles in to next over in a clockwise fashion
for(int i = 0; i < 64; i++)
{ // save top left
temp_arr[i] = Tile_Arrays[z + i];
}
int z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 16) * 8 * 8); // base index
for (int i = 0; i < 64; i++)
{ // copy BL to TL
Tile_Arrays[z + i] = Tile_Arrays[z2 + i];
}
z = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 17) * 8 * 8); // base index
for (int i = 0; i < 64; i++)
{ // copy BR to BL
Tile_Arrays[z2 + i] = Tile_Arrays[z + i];
}
z2 = (Form1.tile_set * 256 * 8 * 8) + ((Form1.tile_num + 1) * 8 * 8); // base index
for (int i = 0; i < 64; i++)
{ // copy TR to BR
Tile_Arrays[z + i] = Tile_Arrays[z2 + i];
}
for (int i = 0; i < 64; i++)
{ // copy temp to TR