forked from JBontes/Life32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLifeCel.pas
7950 lines (7520 loc) · 270 KB
/
LifeCel.pas
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
{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
{$WARN SYMBOL_DEPRECATED ON}
{$WARN SYMBOL_LIBRARY ON}
{$WARN SYMBOL_PLATFORM ON}
{$WARN SYMBOL_EXPERIMENTAL ON}
{$WARN UNIT_LIBRARY ON}
{$WARN UNIT_PLATFORM ON}
{$WARN UNIT_DEPRECATED ON}
{$WARN UNIT_EXPERIMENTAL ON}
{$WARN HRESULT_COMPAT ON}
{$WARN HIDING_MEMBER ON}
{$WARN HIDDEN_VIRTUAL ON}
{$WARN GARBAGE ON}
{$WARN BOUNDS_ERROR ON}
{$WARN ZERO_NIL_COMPAT ON}
{$WARN STRING_CONST_TRUNCED ON}
{$WARN FOR_LOOP_VAR_VARPAR ON}
{$WARN TYPED_CONST_VARPAR ON}
{$WARN ASG_TO_TYPED_CONST ON}
{$WARN CASE_LABEL_RANGE ON}
{$WARN FOR_VARIABLE ON}
{$WARN CONSTRUCTING_ABSTRACT ON}
{$WARN COMPARISON_FALSE ON}
{$WARN COMPARISON_TRUE ON}
{$WARN COMPARING_SIGNED_UNSIGNED ON}
{$WARN COMBINING_SIGNED_UNSIGNED ON}
{$WARN UNSUPPORTED_CONSTRUCT ON}
{$WARN FILE_OPEN ON}
{$WARN FILE_OPEN_UNITSRC ON}
{$WARN BAD_GLOBAL_SYMBOL ON}
{$WARN DUPLICATE_CTOR_DTOR ON}
{$WARN INVALID_DIRECTIVE ON}
{$WARN PACKAGE_NO_LINK ON}
{$WARN PACKAGED_THREADVAR ON}
{$WARN IMPLICIT_IMPORT ON}
{$WARN HPPEMIT_IGNORED ON}
{$WARN NO_RETVAL ON}
{$WARN USE_BEFORE_DEF ON}
{$WARN FOR_LOOP_VAR_UNDEF ON}
{$WARN UNIT_NAME_MISMATCH ON}
{$WARN NO_CFG_FILE_FOUND ON}
{$WARN IMPLICIT_VARIANTS ON}
{$WARN UNICODE_TO_LOCALE ON}
{$WARN LOCALE_TO_UNICODE ON}
{$WARN IMAGEBASE_MULTIPLE ON}
{$WARN SUSPICIOUS_TYPECAST ON}
{$WARN PRIVATE_PROPACCESSOR ON}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN OPTION_TRUNCATED ON}
{$WARN WIDECHAR_REDUCED ON}
{$WARN DUPLICATES_IGNORED ON}
{$WARN UNIT_INIT_SEQ ON}
{$WARN LOCAL_PINVOKE ON}
{$WARN MESSAGE_DIRECTIVE ON}
{$WARN TYPEINFO_IMPLICITLY_ADDED ON}
{$WARN RLINK_WARNING ON}
{$WARN IMPLICIT_STRING_CAST ON}
{$WARN IMPLICIT_STRING_CAST_LOSS ON}
{$WARN EXPLICIT_STRING_CAST OFF}
{$WARN EXPLICIT_STRING_CAST_LOSS OFF}
{$WARN CVT_WCHAR_TO_ACHAR ON}
{$WARN CVT_NARROWING_STRING_LOST ON}
{$WARN CVT_ACHAR_TO_WCHAR ON}
{$WARN CVT_WIDENING_STRING_LOST ON}
{$WARN NON_PORTABLE_TYPECAST ON}
{$WARN XML_WHITESPACE_NOT_ALLOWED ON}
{$WARN XML_UNKNOWN_ENTITY ON}
{$WARN XML_INVALID_NAME_START ON}
{$WARN XML_INVALID_NAME ON}
{$WARN XML_EXPECTED_CHARACTER ON}
{$WARN XML_CREF_NO_RESOLVE ON}
{$WARN XML_NO_PARM ON}
{$WARN XML_NO_MATCHING_PARM ON}
{$WARN IMMUTABLE_STRINGS OFF}
{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
{$WARN SYMBOL_DEPRECATED ON}
{$WARN SYMBOL_LIBRARY ON}
{$WARN SYMBOL_PLATFORM ON}
{$WARN SYMBOL_EXPERIMENTAL ON}
{$WARN UNIT_LIBRARY ON}
{$WARN UNIT_PLATFORM ON}
{$WARN UNIT_DEPRECATED ON}
{$WARN UNIT_EXPERIMENTAL ON}
{$WARN HRESULT_COMPAT ON}
{$WARN HIDING_MEMBER ON}
{$WARN HIDDEN_VIRTUAL ON}
{$WARN GARBAGE ON}
{$WARN BOUNDS_ERROR ON}
{$WARN ZERO_NIL_COMPAT ON}
{$WARN STRING_CONST_TRUNCED ON}
{$WARN FOR_LOOP_VAR_VARPAR ON}
{$WARN TYPED_CONST_VARPAR ON}
{$WARN ASG_TO_TYPED_CONST ON}
{$WARN CASE_LABEL_RANGE ON}
{$WARN FOR_VARIABLE ON}
{$WARN CONSTRUCTING_ABSTRACT ON}
{$WARN COMPARISON_FALSE ON}
{$WARN COMPARISON_TRUE ON}
{$WARN COMPARING_SIGNED_UNSIGNED ON}
{$WARN COMBINING_SIGNED_UNSIGNED ON}
{$WARN UNSUPPORTED_CONSTRUCT ON}
{$WARN FILE_OPEN ON}
{$WARN FILE_OPEN_UNITSRC ON}
{$WARN BAD_GLOBAL_SYMBOL ON}
{$WARN DUPLICATE_CTOR_DTOR ON}
{$WARN INVALID_DIRECTIVE ON}
{$WARN PACKAGE_NO_LINK ON}
{$WARN PACKAGED_THREADVAR ON}
{$WARN IMPLICIT_IMPORT ON}
{$WARN HPPEMIT_IGNORED ON}
{$WARN NO_RETVAL ON}
{$WARN USE_BEFORE_DEF ON}
{$WARN FOR_LOOP_VAR_UNDEF ON}
{$WARN UNIT_NAME_MISMATCH ON}
{$WARN NO_CFG_FILE_FOUND ON}
{$WARN IMPLICIT_VARIANTS ON}
{$WARN UNICODE_TO_LOCALE ON}
{$WARN LOCALE_TO_UNICODE ON}
{$WARN IMAGEBASE_MULTIPLE ON}
{$WARN SUSPICIOUS_TYPECAST ON}
{$WARN PRIVATE_PROPACCESSOR ON}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN OPTION_TRUNCATED ON}
{$WARN WIDECHAR_REDUCED ON}
{$WARN DUPLICATES_IGNORED ON}
{$WARN UNIT_INIT_SEQ ON}
{$WARN LOCAL_PINVOKE ON}
{$WARN MESSAGE_DIRECTIVE ON}
{$WARN TYPEINFO_IMPLICITLY_ADDED ON}
{$WARN RLINK_WARNING ON}
{$WARN IMPLICIT_STRING_CAST ON}
{$WARN IMPLICIT_STRING_CAST_LOSS ON}
{$WARN EXPLICIT_STRING_CAST OFF}
{$WARN EXPLICIT_STRING_CAST_LOSS OFF}
{$WARN CVT_WCHAR_TO_ACHAR ON}
{$WARN CVT_NARROWING_STRING_LOST ON}
{$WARN CVT_ACHAR_TO_WCHAR ON}
{$WARN CVT_WIDENING_STRING_LOST ON}
{$WARN NON_PORTABLE_TYPECAST ON}
{$WARN XML_WHITESPACE_NOT_ALLOWED ON}
{$WARN XML_UNKNOWN_ENTITY ON}
{$WARN XML_INVALID_NAME_START ON}
{$WARN XML_INVALID_NAME ON}
{$WARN XML_EXPECTED_CHARACTER ON}
{$WARN XML_CREF_NO_RESOLVE ON}
{$WARN XML_NO_PARM ON}
{$WARN XML_NO_MATCHING_PARM ON}
{$WARN IMMUTABLE_STRINGS OFF}
{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
{$WARN SYMBOL_DEPRECATED ON}
{$WARN SYMBOL_LIBRARY ON}
{$WARN SYMBOL_PLATFORM ON}
{$WARN SYMBOL_EXPERIMENTAL ON}
{$WARN UNIT_LIBRARY ON}
{$WARN UNIT_PLATFORM ON}
{$WARN UNIT_DEPRECATED ON}
{$WARN UNIT_EXPERIMENTAL ON}
{$WARN HRESULT_COMPAT ON}
{$WARN HIDING_MEMBER ON}
{$WARN HIDDEN_VIRTUAL ON}
{$WARN GARBAGE ON}
{$WARN BOUNDS_ERROR ON}
{$WARN ZERO_NIL_COMPAT ON}
{$WARN STRING_CONST_TRUNCED ON}
{$WARN FOR_LOOP_VAR_VARPAR ON}
{$WARN TYPED_CONST_VARPAR ON}
{$WARN ASG_TO_TYPED_CONST ON}
{$WARN CASE_LABEL_RANGE ON}
{$WARN FOR_VARIABLE ON}
{$WARN CONSTRUCTING_ABSTRACT ON}
{$WARN COMPARISON_FALSE ON}
{$WARN COMPARISON_TRUE ON}
{$WARN COMPARING_SIGNED_UNSIGNED ON}
{$WARN COMBINING_SIGNED_UNSIGNED ON}
{$WARN UNSUPPORTED_CONSTRUCT ON}
{$WARN FILE_OPEN ON}
{$WARN FILE_OPEN_UNITSRC ON}
{$WARN BAD_GLOBAL_SYMBOL ON}
{$WARN DUPLICATE_CTOR_DTOR ON}
{$WARN INVALID_DIRECTIVE ON}
{$WARN PACKAGE_NO_LINK ON}
{$WARN PACKAGED_THREADVAR ON}
{$WARN IMPLICIT_IMPORT ON}
{$WARN HPPEMIT_IGNORED ON}
{$WARN NO_RETVAL ON}
{$WARN USE_BEFORE_DEF ON}
{$WARN FOR_LOOP_VAR_UNDEF ON}
{$WARN UNIT_NAME_MISMATCH ON}
{$WARN NO_CFG_FILE_FOUND ON}
{$WARN IMPLICIT_VARIANTS ON}
{$WARN UNICODE_TO_LOCALE ON}
{$WARN LOCALE_TO_UNICODE ON}
{$WARN IMAGEBASE_MULTIPLE ON}
{$WARN SUSPICIOUS_TYPECAST ON}
{$WARN PRIVATE_PROPACCESSOR ON}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN OPTION_TRUNCATED ON}
{$WARN WIDECHAR_REDUCED ON}
{$WARN DUPLICATES_IGNORED ON}
{$WARN UNIT_INIT_SEQ ON}
{$WARN LOCAL_PINVOKE ON}
{$WARN MESSAGE_DIRECTIVE ON}
{$WARN TYPEINFO_IMPLICITLY_ADDED ON}
{$WARN RLINK_WARNING ON}
{$WARN IMPLICIT_STRING_CAST ON}
{$WARN IMPLICIT_STRING_CAST_LOSS ON}
{$WARN EXPLICIT_STRING_CAST OFF}
{$WARN EXPLICIT_STRING_CAST_LOSS OFF}
{$WARN CVT_WCHAR_TO_ACHAR ON}
{$WARN CVT_NARROWING_STRING_LOST ON}
{$WARN CVT_ACHAR_TO_WCHAR ON}
{$WARN CVT_WIDENING_STRING_LOST ON}
{$WARN NON_PORTABLE_TYPECAST ON}
{$WARN XML_WHITESPACE_NOT_ALLOWED ON}
{$WARN XML_UNKNOWN_ENTITY ON}
{$WARN XML_INVALID_NAME_START ON}
{$WARN XML_INVALID_NAME ON}
{$WARN XML_EXPECTED_CHARACTER ON}
{$WARN XML_CREF_NO_RESOLVE ON}
{$WARN XML_NO_PARM ON}
{$WARN XML_NO_MATCHING_PARM ON}
{$WARN IMMUTABLE_STRINGS OFF}
unit LifeCel;
(* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. *)
interface
{define time}
uses
Windows, Classes, Graphics, Controls, Dialogs, Forms, SysUtils,
DDSurface, LifeConst
{$ifdef time}
,TickTime
{$endif}, LifeUtil, FastObject6;
(* group of Cells (lowest level):
1 2
3 4 = 2x2 Celen
group of 2x2's:
1 3
2 4 = 4x4 Cells (stored in 16-bit short)
group of 4x4's:
1 2
3 4 = 8x8 Cels
group of 8x8's:
1 3
2 4 = 16x16 Cels (stored in LifeCel class)
This means the bit-to-cell mapping is as follows:
f e 7 6 1f 1e 17 16 | 8f 8e 87 86 9f 9e 97 96
d c 5 4 1d 1c 15 14 | 8d 8c 85 84 9d 9c 95 94
b a 3 2 1b 1a 13 12 | 8b 8a 83 82 9b 9a 93 92
9 8 1 0 19 18 11 10 | 89 88 81 80 99 98 91 90
|
2f 2e 27 26 3f 3e 37 36 | af ae a7 a6 bf be b7 b6
2d 2c 25 24 3d 3c 35 34 | ad ac a5 a4 bd bc b5 b4
2b 2a 23 22 3b 3a 33 32 | ab aa a3 a2 bb ba b3 b2
29 28 21 20 39 38 31 30 | a9 a8 a1 a0 b9 b8 b1 b0
__________________________|__________________________
|
4f 4e 47 46 5f 5e 57 56 | cf ce c7 c6 df de d7 d6
4d 4c 45 44 5d 5c 55 54 | cd cc c5 c4 dd dc d5 d4
4b 4a 43 42 5b 5a 53 52 | cb ca c3 c2 db da d3 d2
49 48 41 40 59 58 51 50 | c9 c8 c1 c0 d9 d8 d1 d0
|
6f 7e 77 76 7f 7e 77 76 | ef ee e7 e6 ff fe f7 f6
6d 7c 75 74 7d 7c 75 74 | ed ec e5 e4 fd fc f5 f4
6b 7a 73 72 7b 7a 73 72 | eb ea e3 e2 fb fa f3 f2
69 78 71 70 79 78 71 70 | e9 e8 e1 e0 f9 f8 f1 f0
Note that 'f' is the most significant bit.
Each of these 16 x 16 blocks has its own x,y coordinate
in the universe, which are also saved as 16 bit shorts.
Thus the universe size is 2^20 x 2^20 or a million x
a million.
In the p cycle, the real coordinates are 16x, 16y.
In the q cycle, the real coordinates are 16x+1, 16y+1.
This staggering occurs because the algorithm calls for
calculating 4 Cels at a time by table lookup on the 4x4
block surrounding it. It is simply easier (read: faster)
to stagger the cycles than it is to bit-shift all the time.
p -> q: Use p's S, E, SE blocks;
Affect q's S, E, SE blocks.
q -> p: Use q's N, W, NW blocks;
Affect p's N, W, NW blocks. *)
type
Tint = array[0..7] of integer;
TSmall = array[0..15] of smallint;
TRow = array[0..1] of integer;
TColumn = array[0..3] of smallint;
TCoor = record
case boolean of
true:(x,y: smallint);
false:(xy: integer);
end;
type
PLifeCel = ^TLifeCel;
//TLifeCel = class(TPersistent)
TLifeCel = class(TFastObject)
private
function DifferenceWithQ: TSmall;
function DifferenceWithP: TSmall;
function ConvertQtoP: TSmall;
public
S, E, SE: TLifeCel;
N, W, NW: TLifeCel;
Next, Prev: TLifeCel; //doubly linked.
DisplayNext, DisplayPrev: TLifeCel;
Down: TLifeCel;
Coor: TCoor; //enables typecasting to 32-bit integer
p: array[0..15] of smallint;
q: array[0..15] of smallint;
pstate, qstate: integer;
// bitmap:
// |31 30 29 28.27 26 25 24|23 22 21 20.19 18 17 16|15 14 13 12.11 10 9 8| 7 6 5 4. 3 2 1 0|
// | Northwest quadrant | Southwest quadrant | Northeast quadrant | Southeast quadrant |
// | morgue | hiber | morgue | hiber | morgue | hiber | morgue | hiber |
//
// each group of 4 bits:
// Whole 8x8 | Vertical 2x8 | Horizontal 8x2 | Corner 2x2
flags: integer;
// bitmap:
// 15 14 13 12.11 10 9 8. 7 6 5 4. 3 2 1 0
// | | | | | | | | | | Display (1=in)
// | | | | | | | | | Morgue (1=in)
// | | | | | | | | Hibernation (1=in)
// | | | | | Morgue & displayed (incineratable)
// | | | | the Rattling bit
// | | | q in hibernation
// | | q in morgue
// | p in hibernation
// p in morgue
destructor Destroy; override;
{$WARN DUPLICATE_CTOR_DTOR OFF}
destructor DestroySlow; virtual;
{$WARN DUPLICATE_CTOR_DTOR ON}
procedure FreeSlow;
procedure DisplayOff;
procedure DisplayOn;
procedure DisplayAllOff;
procedure DisplayAllOn;
procedure DisplayZoom_1Off;
procedure DisplayZoom_2Off;
procedure DisplayZoom_3Off;
procedure DisplayZoom_4Off;
procedure DisplayZoom_5Off;
procedure DisplayZoom_6Off;
procedure DisplayZoom_7Off;
procedure DisplayZoom_8Off;
procedure DisplayZoom_1On;
procedure DisplayZoom_2On;
procedure DisplayZoom_3On;
procedure DisplayZoom_4On;
procedure DisplayZoom_5On;
procedure DisplayZoom_6On;
procedure DisplayZoom_7On;
procedure DisplayZoom_8On;
procedure DisplayDrag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_1Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_2Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_3Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_4Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_5Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_6Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_7Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
procedure DisplayZoom_8Drag(XOffset, YOffset: Integer; DisplayQ: Boolean);
function NumberOfCels(QCycle: Boolean): integer;
function IsStable: boolean;
function IsEmpty(QCycle: boolean): boolean;
procedure FlipX(QCycle: LongBool);
procedure FlipY(QCycle: LongBool);
procedure BackFlip(QCycle: LongBool);
procedure AssignTo(Dest: TPersistent); override;
//procedure ClearRect(ARect: TRect; QCycle: boolean);
function GetCelSum(QCycle: boolean): integer;
function GetChecksum(QCycle: boolean): integer;
function GetCelDiff(c2: TLifeCel; QCycle, QCycle2: boolean): integer;
procedure Clear(QCycle: boolean);
procedure FillBlack(QCycle: boolean);
procedure Invert(QCycle: boolean);
procedure DrawHorzLineRight(x1,y1: integer; State: TLineDrawState; QCycle: boolean);
procedure DrawVertLineDown(x1,y1: integer; State: TLineDrawState; QCycle: boolean);
procedure DrawHorzLineLeft(x1,y1: integer; State: TLineDrawState; QCycle: boolean);
procedure DrawVertLineUp(x1,y1: integer; State: TLineDrawState; QCycle: boolean);
procedure ExchangeTorusLineHorz(y1,y2: integer; c: TLifeCel; QCycle: boolean);
procedure ExchangeTorusLineVert(x1,x2: integer; c: TLifeCel; QCycle: boolean);
function TopRow(QCycle: boolean): integer;
function BottomRow(QCycle: boolean): integer;
function RightCol(QCycle: boolean): integer;
function LeftCol(QCycle: boolean): integer;
function GetARow(ARow: integer; QCycle: boolean): TRow;
function GetAColumn(AColumn: integer; QCycle: boolean): TColumn;
procedure ClearRow(Arow: integer; QCycle: boolean);
procedure ClearColumn(AColumn: integer; QCycle: boolean);
procedure Write(AStream: TStream; QCycle: boolean);
procedure Read(AStream: TStream; QCycle: boolean);
end;
procedure SetBounds(AWindow: TControl; ARect: TRect);
procedure SetDisplayProps(XOrig, YOrig,ox,oy, NegZoom: integer;
DisplayQGen: Boolean);
procedure SetCelSpace(ACelSpace: integer; GridOn: Boolean);
procedure InitDDraw;
procedure DisplayChange(BitsPerPixel,Width,Height: integer);
var
MyDDSurface: TMyDDSurface;
var
BackColor: TColor = TColor($FFFFFFFF);
ForeColor: TColor = $00000000; //colors for 256 color mode only //just testing now.
DragColor: TColor = TColor($FFFFFFFF);
TorusColor: TColor = $00000000;
{$ifdef time}
var
CumDisp: Comp;
CumDiff: Comp;
{$endif}
implementation
{$ifdef time}
uses Unit1;
{$endif}
//Global vars
var
CelSpace: Integer;
CelSpace2: Integer;
CelSpace4: Integer;
CelSpace8: Integer;
CelSpace12: Integer;
CelSpace16: Integer;
CelSize: Integer;
DrawBound: TRect;
StartPoint: TPoint;
DisplayQ: Boolean;
CenterX, CenterY: integer;
XorigDiv16, YOrigDiv16: integer;
RestOfXOrig, RestOfYOrig: integer;
destructor TLifeCel.Destroy;
var
i: integer;
begin
(*if assigned(S) then S.N:= nil;
if assigned(E) then E.W:= nil;
if assigned(SE) then SE.NW:= nil;
if assigned(N) then N.S:= nil;
if assigned(W) then W.E:= nil;
if assigned(NW) then NW.SE:= nil;
Next.Prev:= Prev; //always <> nil.
Prev.Next:= Next; //always <> nil.
DisplayPrev.DisplayNext:= DisplayNext; //always assigned.
DisplayNext.DisplayPrev:= DisplayPrev; //always assigned.
{Down is NOT updated, and doesn't have to btw}
//Clear data
Flags:= 0;
PState:= 0;
QState:= 0;
inherited Destroy; (**)
if assigned(S) then S.N:= nil;
if assigned(E) then E.W:= nil;
if assigned(SE) then SE.NW:= nil;
if assigned(N) then N.S:= nil;
if assigned(W) then W.E:= nil;
if assigned(NW) then NW.SE:= nil;
Next.Prev:= Prev; //always <> nil.
Prev.Next:= Next; //always <> nil.
DisplayPrev.DisplayNext:= DisplayNext; //always assigned.
DisplayNext.DisplayPrev:= DisplayPrev; //always assigned.
{Down is NOT updated, and doesn't have to btw}
//Clear all data (except Self, hence the -4).
i:= Self.InstanceSize-4;
FillChar(S,i,0);
inherited Destroy;
end;
destructor TLifeCel.DestroySlow;
var
i: integer;
begin
if assigned(S) then S.N:= nil;
if assigned(E) then E.W:= nil;
if assigned(SE) then SE.NW:= nil;
if assigned(N) then N.S:= nil;
if assigned(W) then W.E:= nil;
if assigned(NW) then NW.SE:= nil;
Next.Prev:= Prev; //always <> nil.
Prev.Next:= Next; //always <> nil.
DisplayPrev.DisplayNext:= DisplayNext; //always assigned.
DisplayNext.DisplayPrev:= DisplayPrev; //always assigned.
{Down is NOT updated, and doesn't have to btw}
//Clear all data (except Self, hence the -4).
i:= Self.InstanceSize-4;
FillChar(S,i,0);
inherited Destroy;
end;
procedure TLifeCel.FreeSlow;
begin
if self <> nil then DestroySlow;
end;
//This routine does a lot of swapping:
//First: the celbits: fe76 are converted to 67ef.
// dc54 45cd.
// ba32 ab23.
// 9810 0189.
//then smallint 0 and 1 are swapped and then 01 and 89 etc are swapped.
//after all this the entire Cel is converted to it's X-mirrored image.
procedure TLifeCel.FlipX(Qcycle: LongBool);
begin
//Self will be in EAX and QCycle will be in EDX.
asm
push ebx
lea ecx,[eax+TLifeCel.p];
mov bx,[eax+TLifeCel.coor.x];
neg ebx
mov [eax+TLifeCel.coor.x],bx
or edx,edx
jz @@PCycle
@@QCycle:
lea ecx,[eax+TLifeCel.q]
@@PCycle://now ecx points to start of relevant celdata.
@@DWords0189:
mov edx,[ecx]
mov ebx,[ecx]
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or ebx,edx // 67452301efcdab89-67452301efcdab89
mov edx,[ecx+2*8] //get Block 8,9
mov [ecx+2*8],ebx //swap 0,1 and 8,9 and repeat this procedure.
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
lea ecx,[ecx+4] //next dword.
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or edx,ebx // 67452301efcdab89-67452301efcdab89
mov [ecx-4],edx
@@DWords23ab:
mov edx,[ecx]
mov ebx,[ecx]
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or ebx,edx // 67452301efcdab89-67452301efcdab89
mov edx,[ecx+2*8] //get Block 8,9
mov [ecx+2*8],ebx //swap 0,1 and 8,9 and repeat this procedure.
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
lea ecx,[ecx+4] //next dword.
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or edx,ebx // 67452301efcdab89-67452301efcdab89
mov [ecx-4],edx
@@DWords45cd:
mov edx,[ecx]
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or ebx,edx // 67452301efcdab89-67452301efcdab89
mov edx,[ecx+2*8] //get Block 8,9
mov [ecx+2*8],ebx //swap 0,1 and 8,9 and repeat this procedure.
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
lea ecx,[ecx+4] //next dword.
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or edx,ebx // 67452301efcdab89-67452301efcdab89
mov [ecx-4],edx
@@DWords67ef:
mov edx,[ecx]
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or ebx,edx // 67452301efcdab89-67452301efcdab89
mov edx,[ecx+2*8] //get Block 8,9
mov [ecx+2*8],ebx //swap 0,1 and 8,9 and repeat this procedure.
mov ebx,edx
and edx,$aaaaaaaa //4x 10101010
and ebx,$55555555 //4x 01010101
ror edx,9 // 0000000000000000-1111111111111111
ror ebx,7 //conversion from fedcba9876543210-fedcba9876543210
or edx,ebx //to: 1111111100000000-0000000011111111
// 67452301efcdab89-67452301efcdab89
mov ebx,edx
and edx,$FF00FF00
and ebx,$00ff00ff
ror ebx,16 //and to: 1111111111111111-0000000000000000
or edx,ebx // 67452301efcdab89-67452301efcdab89
mov [ecx],edx
pop ebx
end; {asm}
end;
procedure TLifeCel.FlipY(QCycle: LongBool);
begin
asm
push edi
push esi
lea ecx,[eax+TLifeCel.p];
mov di,[eax+TLifeCel.coor.y];
neg edi
mov [eax+TLifeCel.coor.y],di
or edx,edx
jz @@PCycle
@@QCycle:
lea ecx,[eax+TLifeCel.q]
@@PCycle://now ecx points to start of relevant celdata.
@@DWords01:
mov edx,[ecx+0*2]
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+6*2]
mov [ecx+6*2],eax
@@DWords67:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+2*2]
mov [ecx],eax
@@DWords23:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+4*2]
mov [ecx+4*2],eax
@@DWords45:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+8*2]
mov [ecx+2*2],eax
@@DWords89:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+14*2]
mov [ecx+14*2],eax
@@DWordsEF:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+10*2]
mov [ecx+8*2],eax
@@DWordsAB:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov edx,[ecx+12*2]
mov [ecx+12*2],eax
@@DWordsCD:
mov esi,edx
mov edi,edx
and esi,$30303030 //4 x 00110000
shr esi,2
and edi,$c0c0c0c0 //4 x 11000000
shr edi,6
mov eax,esi
or eax,edi
mov esi,edx
mov edi,edx
and esi,$03030303 //4 x 00000011
shl esi,6
and edi,$0c0c0c0c
shl edi,2
or eax,esi
or eax,edi
mov [ecx+10*2],eax
pop esi
pop edi
end; {asm}
end;
procedure TLifeCel.BackFlip(QCycle: longBool);
begin
asm
push ebx
push edi
push esi
lea ecx,[eax+TLifeCel.p]; //ecx:= @p;
mov di,[eax+TLifeCel.coor.y];
neg edi
mov si,[eax+TLifeCel.coor.x];
mov [eax+TLifeCel.coor.x],di //x:= -y;
neg esi
mov [eax+TLifeCel.coor.y],si; //y:= -x;
or edx,edx
jz @@PCycle //if QCycle then ecx:= @Q;
@@QCycle:
lea ecx,[eax+TLifeCel.q]
@@PCycle://now ecx points to start of relevant celdata.
@@DWords01:
mov edx,[ecx+0*2] //edx:= TInt(p)[0];
mov edi,edx //edi:= edx;
mov esi,edx //esi:= edx;
and edi,$80008000 //fedcba9876543210 02138a9b4657cedf.
shr edi,15 //f--------------- => ---------------f.
and esi,$60006000
shr esi,12 //-ed------------- => -------------ed-.
mov eax,edi
or eax,esi
mov edi,edx
mov esi,edx
and edi,$10001000
shr edi,$9 //---c------------ => ------------c---.
and esi,$08800880
shr esi,3 //----b---7------- => -------b---7----.
or eax,edi
or eax,esi
mov edi,edx
mov esi,edx
and edi,$01100110
shl edi,3 //-------8---4---- => ----8---4-------.
and esi,$00080008
shl esi,9 //------------3--- => ---3------------.
or eax,edi
or eax,esi
mov edi,edx
mov esi,edx
and edi,$00060006
shl edi,12 //-------------21- => -21-------------.
and esi,$00010001
shl esi,15 //---------------0 => 0---------------.
and edx,$06600660 //-----a9--65----- => -----a9--65-----.
or eax,edi //====================================.
or eax,esi //fedcba9876543210 => 02138a9b4657cedf.
or eax,edx
@@DWords23:
mov edx,[ecx+2*2]
mov edi,edx
mov esi,edx
and edi,$80008000
shr edi,15
and esi,$60006000
shr esi,12
mov ebx,edi
or ebx,esi
mov edi,edx
mov esi,edx
and edi,$10001000
shr edi,9
and esi,$08800880
shr esi,3
or ebx,edi
or ebx,esi
mov edi,edx
mov esi,edx
and edi,$01100110
shl edi,3
and esi,$00080008
shl esi,9
or ebx,edi
or ebx,esi
mov edi,edx
mov esi,edx
and edi,$00060006
shl edi,12
and esi,$00010001
shl esi,15
and edx,$06600660
or ebx,edi
or ebx,esi
or ebx,edx
@@Mix0123:
ror ebx,16 //01 -> 01 -> 31 -> 31 (eax)
xchg ax,bx //23 -> 32 -> 02 -> 20 (ebx)
ror ebx,16
push eax
push ebx
@@DWordsCD:
mov edx,[ecx+$C*2]
mov edi,edx
mov esi,edx
and edi,$80008000
shr edi,15
and esi,$60006000
shr esi,12
mov eax,edi
or eax,esi
mov edi,edx
mov esi,edx
and edi,$10001000
shr edi,9
and esi,$08800880
shr esi,3