forked from y-salnikov/ironseed_fpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintro.pas
1716 lines (1609 loc) · 39.9 KB
/
intro.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
program intro;
(********************************************************************
This file is part of Ironseed.
Ironseed is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ironseed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ironseed. If not, see <http://www.gnu.org/licenses/>.
********************************************************************)
{*********************************************
Introduction Sequence for IronSeed
Copyright:
1994 Channel 7, Destiny: Virtual
2013 y-salnikov
2018 Nuke Bloodaxe
2020 Matija Nalis <[email protected]>
**********************************************}
uses utils_, sysutils, gmouse, modplay, version, math;
(*
var sdl_scr: PSDL_Surface;
begin
SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and use it for screen
SDL_Quit; // close the subsystems and SDL
*)
const
CPR_NONE=0; { 0 no compresion }
// CPR_NOPAL=1; { 1 no palette, compressed }
// CPR_PAL=2; { 2 palette, compressed }
// CPR_HEADERINCL=3; { 3 header included }
CPR_ERROR=255; { global error }
// CPR_CURRENT=CPR_HEADERINCL; { current version }
CPR_BUFFSIZE=8192; { adjustable buffer size }
{$PACKRECORDS 1}
type
CPR_HEADER=
record
signature: word; {RWM, no version. RM, version }
version: byte;
width,height: word;
flags,headersize: byte;
end;
pCPR_HEADER= ^CPR_HEADER;
type
// paltype=array[0..255,1..3] of byte;
fonttype= array[0..2] of byte;
plantype= array[1..120,1..120] of byte;
landtype= array[1..240,1..120] of byte;
pscreentype= ^screentype;
bigfonttype= array[0..7] of byte;
{$PACKRECORDS DEFAULT}
const
font: array[1..84] of fonttype=
((0,0,0),(34,32,32),(85,0,0),(34,0,0),(36,68,32),
(66,34,64),(9,105,0),(2,114,0),(0,2,36),(0,240,0),
(0,0,32),(1,36,128),(107,221,96),(38,34,112),(241,248,240),
(241,113,240),(170,175,32),(248,241,240),(248,249,240),(241,17,16),
(249,105,240),(249,241,240),(2,2,0),(2,2,36),(18,66,16),
(15,15,0),(132,36,128),(249,48,32),(249,249,144),(249,233,240),
(249,137,240),(233,153,224),(248,232,240),(248,232,128),(248,185,240),
(153,249,144),(114,34,112),(241,25,240),(158,153,144),(136,136,240),
(159,153,144),(157,185,144),(249,153,240),(249,248,128),(249,155,240),
(249,233,144),(120,97,224),(242,34,32),(153,153,240),(153,149,32),
(153,187,96),(153,105,144),(153,241,240),(242,72,240),(9,36,144),
(8,66,16),(15,155,208),(143,153,240),(15,136,240),(31,153,240),
(15,188,240),(249,200,128),(15,151,159),(143,153,144),(32,34,32),
(16,17,159),(137,233,144),(34,34,32),(9,249,144),(14,153,144),
(15,153,240),(15,153,248),(15,153,241),(15,152,128),(7,66,224),
(39,34,32),(9,153,240),(9,149,32),(9,155,96),(9,105,144),
(9,159,31),(15,36,240),(53,170,83),(202,17,172));
bigfont: array[1..82] of bigfonttype=
((0,0,0,0,0,0,0,0),(48,48,48,16,0,48,48,0),(40,40,0,0,0,0,0,0),(8,8,0,0,0,0,0,0),
(8,16,16,16,16,8,0,0),(32,16,16,16,16,32,0,0),(0,84,16,124,16,84,0,0),(0,16,16,124,16,16,0,0),
(0,0,0,0,48,48,96,0),(0,0,0,254,254,0,0,0),(0,0,0,0,48,48,0,0),(2,4,8,16,32,64,0,0),
(124,134,138,146,162,124,0,0),(24,56,8,8,8,126,0,0),(124,130,4,56,64,254,0,0),(124,130,60,2,130,124,0,0),
(6,10,18,34,126,2,0,0),(254,128,124,2,130,124,0,0),(124,128,188,130,130,124,0,0),(254,2,4,8,8,8,0,0),
(124,130,124,130,130,124,0,0),(124,130,126,2,130,124,0,0),(0,48,48,0,48,48,0,0),(0,48,48,0,48,48,96,0),
(2,4,8,8,4,2,0,0),(0,0,124,0,124,0,0,0),(64,32,16,16,32,64,0,0),(56,68,4,24,0,16,0,0),
(60,66,158,130,130,130,0,0),(252,130,252,130,130,252,0,0),(124,130,128,128,130,124,0,0),(252,130,130,130,130,252,0,0),
(254,0,248,128,128,254,0,0),(254,128,248,128,128,128,0,0),(124,130,128,134,130,124,0,0),(130,130,130,254,130,130,0,0),
(254,16,16,16,16,254,0,0),(254,2,2,2,130,124,0,0),(130,130,252,130,130,130,0,0),(128,128,128,128,128,254,0,0),
(198,170,146,130,130,130,0,0),(248,132,130,130,130,130,0,0),(124,130,130,130,130,124,0,0),(252,130,130,252,128,128,0,0),
(124,130,130,138,134,124,2,0),(252,130,130,252,130,130,0,0),(124,130,124,2,130,124,0,0),(254,16,16,16,16,16,0,0),
(130,130,130,130,130,124,0,0),(130,130,130,68,40,16,0,0),(130,130,130,146,170,68,0,0),(130,68,56,68,130,130,0,0),
(130,130,126,2,130,124,0,0),(124,8,16,32,64,124,0,0),(98,100,8,16,38,70,0,0),(64,32,16,8,4,2,0,0),
(0,60,66,158,130,130,0,0),(0,254,130,252,130,254,0,0),(0,124,130,128,130,124,0,0),(0,252,130,130,130,252,0,0),
(0,254,0,224,128,254,0,0),(0,254,128,224,128,128,0,0),(0,124,128,134,130,124,0,0),(0,130,130,254,130,130,0,0),
(0,254,16,16,16,254,0,0),(0,254,2,2,130,124,0,0),(0,130,130,252,130,130,0,0),(0,128,128,128,128,254,0,0),
(0,198,170,146,130,130,0,0),(0,248,132,130,130,130,0,0),(0,124,130,130,130,124,0,0),(0,252,130,252,128,128,0,0),
(0,124,130,138,134,124,2,0),(0,252,130,252,130,130,0,0),(0,126,128,124,2,252,0,0),(0,254,16,16,16,16,0,0),
(0,130,130,130,130,124,0,0),(0,130,130,68,40,16,0,0),(0,130,130,146,170,68,0,0),(0,130,68,56,68,130,0,0),
(0,130,130,126,2,252,0,0),(0,124,8,16,32,124,0,0));
var
tcolor,bkcolor,i,j,z,cursor,permx,permy,code,j2,m,index,alt,ecl,
r2,c,radius,m1,m2,m3,m4,tslice,water,waterindex,x,ofsx,ofsy: integer;
keymode: boolean;
key: char;
modth,modtm,modts,curth,curtm,curts: byte;
y,part,part2,c2: real;
planet: ^plantype;
landform: ^landtype;
screen: screentype;
colors: paltype;
s1,s2,s3: pscreentype;
k: word;
// module: pmodule;
spcindex: array[0..5] of integer;
//{$L mover2}
//{$L mover}
//{$L vga256}
//{$L scroller}
//{$F+}
procedure errorhandler(s: string; errtype: integer);
begin
closegraph;
writeln;
case errtype of
1: writeln('Open File Error: ',s);
2: writeln('Mouse Error: ',s);
3: writeln('Sound Error: ',s);
4: writeln('EMS Error: ',s);
5: writeln('Fatal File Error: ',s);
6: writeln('Program Error: ',s);
7: writeln('Music Error: ',s);
end;
halt(4);
end;
procedure gettime;
var hh,mm,ss,ms:Word;
begin
DecodeTime(Now,hh,mm,ss,ms);
modth:=byte(hh);//h;
modtm:=byte(mm);//m;
modts:=byte(ss);//s;
end;
procedure getcurtime; // get current time
var hh,mm,ss,ms:Word;
begin
DecodeTime(Now,hh,mm,ss,ms);
curth:=byte(hh);
curtm:=byte(mm);;
curts:=byte(ss);;
end;
procedure wait(s: integer); //wait s seconds?
var hh,mm,ss,ms,ss2,mm2,hh2:Word;
t2:word;
begin
DecodeTime(Now,hh,mm,ss,ms);
repeat
DecodeTime(Now,hh2,mm2,ss2,ms);
t2:=abs(ss-ss2)+60*abs(mm-mm2)+3600*abs(hh-hh2);
until(t2>=s);
end;
procedure uncompressfile_data(s: string; ts: pscreentype; h: pCPR_HEADER);
type
buftype = array[0..CPR_BUFFSIZE] of byte;
var
f : file;
err,num,count,databyte,index,x : word;
total,totalsize,j : longint;
buffer : ^buftype;
procedure handleerror;
begin
h^.version:=CPR_ERROR;
if buffer<>nil then dispose(buffer);
buffer:=nil;
close(f);
j:=ioresult;
end;
procedure getbuffer;
begin
if total>CPR_BUFFSIZE then num:=CPR_BUFFSIZE else num:=total;
blockread(f,buffer^,num,err);
// writeln('readed ',num);
if (err<num) or (ioresult<>0) then
begin
handleerror;
exit;
end;
total:=total-num;
index:=0;
end;
function handleversion(n: integer): boolean;
begin
handleversion:=false;
if n<>4 then exit;
if h^.flags and 1>0 then
begin
num:=768;
seek(f,h^.headersize);
blockread(f,colors,num,err);
if (ioresult<>0) or (num<>err) then exit;
total:=filesize(f)-768-h^.headersize;
end
else total:=filesize(f)-h^.headersize;
seek(f,filesize(f)-total);
if ioresult<>0 then exit;
handleversion:=true;
end;
function checkversion: boolean;
begin
checkversion:=false;
num:=sizeof(CPR_HEADER);
blockread(f,h^,num,err);
if (err<num) or (ioresult<>0) or (h^.signature<>19794)
or (not handleversion(h^.version)) then exit;
checkversion:=true;
end;
function decode: boolean;
begin
decode:=false;
getbuffer;
j:=0;
totalsize:=h^.width;
totalsize:=totalsize*h^.height;
// writeln(h^.width,' x ',h^.height,' = ',totalsize);
x:=0;
repeat
if buffer^[index]=255 then
begin
inc(index);
if index=CPR_BUFFSIZE then getbuffer;
count:=buffer^[index];
inc(index);
if index=CPR_BUFFSIZE then getbuffer;
databyte:=buffer^[index];
if j+count>totalsize then count:=totalsize-j;
j:=j+count;
while count>0 do
begin
ts^[0,x]:=databyte;
inc(x);
dec(count);
end;
end
else
begin
databyte:=buffer^[index];
ts^[0,x]:=databyte;
inc(j);
inc(x);
end;
inc(index);
if index=CPR_BUFFSIZE then getbuffer;
until j>=totalsize;
decode:=true;
end;
begin
new(buffer);
assign(f,loc_data()+s);
reset(f,1);
if (ioresult<>0) or (not checkversion) then
begin
handleerror;
exit;
end;
if h^.version=CPR_NONE then exit;
if not decode then
begin
handleerror;
exit;
end;
close(f);
if buffer<>nil then dispose(buffer);
end;
procedure loadmainpalette;
var palfile: file of paltype;
begin
//writeln('intro loadmainpalette');
assign(palfile,loc_data()+'main.pal');
reset(palfile);
if ioresult<>0 then errorhandler('data/main.pal',1);
read(palfile,colors);
if ioresult<>0 then errorhandler('data/main.pal',5);
close(palfile);
end;
procedure loadscreen_data(s: string; ts: pointer);
var ftype: CPR_HEADER;
begin
//writeln('intro loadscreen_data ', s);
uncompressfile_data(s+'.cpr',ts,@ftype);
// writeln('uncompressed');
if ftype.version=CPR_ERROR then errorhandler(s,5);
end;
procedure printxy(x1,y1: integer; s: string);
var letter,a,x,y,t: integer;
begin
t:=tcolor;
x1:=x1+4; { this stupid offset is pissing me off!!!!}
for j:=1 to length(s) do
begin
tcolor:=t;
case s[j] of
'a'..'z': letter:=ord(s[j])-40;
'A' ..'Z': letter:=ord(s[j])-36;
' ' ..'"': letter:=ord(s[j])-31;
''''..'?': letter:=ord(s[j])-35;
'%': letter:=55;
#1: letter:=83;
#2: begin
letter:=84;
dec(x1);
end;
else letter:=1;
end;
y:=y1;
for i:=0 to 5 do
begin
x:=x1;
inc(y);
for a:=7 downto 4 do
begin
inc(x);
//writeln ('y=', y, ' x=', x, ' mem=', y*320+x, ' c=', s[j]);
assert (y*320+x < 320*200, 'printxy memory overflow1');
if font[letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,2);
x:=x1;
inc(y);
inc(i);
for a:=3 downto 0 do
begin
inc(x);
//assert ((x>=0) and (x<320) and (y>=0) and (y<200), 'printxy coords out of range');
assert (y*320+x < 320*200, 'printxy memory overflow2');
if font[letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,2);
end;
x1:=x1+5;
assert ((y1+i)*320+x1 < 320*200, 'printxy memory overflow3');
if bkcolor<255 then for i:=1 to 6 do screen[y1+i,x1]:=bkcolor;
end;
tcolor:=t;
end;
procedure bigprintxy(x1,y1: integer; s: string);
var letter,a,x,y,t: integer;
begin
t:=tcolor;
for j:=1 to length(s) do
begin
tcolor:=t;
case s[j] of
'a'..'z': letter:=ord(s[j])-40;
'A' ..'Z': letter:=ord(s[j])-36;
' ' ..'"': letter:=ord(s[j])-31;
''''..'?': letter:=ord(s[j])-35;
'%': letter:=55;
else letter:=1;
end;
y:=y1;
for i:=0 to 7 do
begin
x:=x1;
inc(y);
for a:=7 downto 0 do
begin
inc(x);
assert (y*320+x < 320*200, 'bigprintxy memory overflow');
if bigfont[letter,i] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor);
end;
x1:=x1+8;
end;
tcolor:=t;
end;
procedure readygraph; // init video
begin
SetExceptionMask([exInvalidOp, exDenormalized, exPrecision]); // fix for EDivByZero error in software OpenGL, see https://github.com/mnalis/ironseed_fpc/issues/26
init_video(screen);
loadmainpalette;
set256colors(colors);
end;
procedure fading;
var a,b: integer;
temppal: paltype;
px,dx,pdx: array[1..768] of shortint;
begin
temppal[0,1]:=0; // to turn off warnings, variables are actually correctly initialized by function below
move(colors,temppal,sizeof(paltype));
dx[1]:=0; // to turn off warnings, variables are actually correctly initialized by function below
fillchar(dx,sizeof(paltype),48);
for j:=1 to 768 do
begin
px[j]:=colors[0,j] div 48;
pdx[j]:=colors[0,j] mod 48;
end;
b:=tslice shr 1;
for a:=47 downto 1 do
begin
for j:=1 to 768 do
begin
dec(temppal[0,j],px[j]);
dec(dx[j],pdx[j]);
if (dx[j]<=0) then
begin
inc(dx[j],48);
dec(temppal[0,j]);
end;
end;
set256colors(temppal);
delay(b);
end;
fillchar(temppal,sizeof(paltype),0);
set256colors(temppal);
end;
procedure fadein;
var a,b: integer;
temppal: paltype;
px,dx,pdx: array[1..768] of shortint;
begin
b:=tslice shr 2;
temppal[0,1]:=0; // to turn off warnings, variables are actually correctly initialized by function below
fillchar(temppal,sizeof(paltype),0);
dx[1]:=0; // to turn off warnings, variables are actually correctly initialized by function below
fillchar(dx,sizeof(paltype),0);
for j:=1 to 768 do
begin
px[j]:=colors[0,j] div 48;
pdx[j]:=colors[0,j] mod 48;
end;
for a:=1 to 47 do
begin
for j:=1 to 768 do
begin
inc(temppal[0,j],px[j]);
inc(dx[j],pdx[j]);
if (dx[j]>=48) then
begin
inc(temppal[0,j]);
dec(dx[j],48);
end;
end;
set256colors(temppal);
delay(b);
end;
set256colors(colors);
end;
procedure runintro; forward;
procedure blast(c1,c2,c3: integer);
var a,b: integer;
begin
b:=tslice div 2;
for a:=1 to 31 do
begin
for j:=0 to 255 do
begin
colors[j,1]:=colors[j,1] + round(a*(c1-colors[j,1])/31);
colors[j,2]:=colors[j,2] + round(a*(c2-colors[j,2])/31);
colors[j,3]:=colors[j,3] + round(a*(c3-colors[j,3])/31);
end;
set256colors(colors);
delay(b);
end;
set256colors(colors);
end;
procedure loadstarfield;
begin
new(s1);
new(s2);
new(s3);
mousehide;
scrfrom_move(screen,s2^,sizeof(screen));
mouseshow;
loadscreen_data('cloud',s1);
end;
procedure startit;
begin
case cursor of
1: code:=1;
2: begin
dispose(s1);
dispose(s2);
dispose(s3);
fading;
mousehide;
scr_fillchar(screen,sizeof(screen),0);
stopmod;
runintro;
playmod(true,loc_sound()+'INTRO2.MOD');
loadstarfield;
setcolor(207);
end;
3: code:=2;
4: code:=4;
end;
end;
procedure drawcursor;
begin
if cursor=0 then exit;
mousehide;
case cursor of
1:rectangle(25,148,159,167);
2:rectangle(43,168,159,187);
3:rectangle(159,148,283,167);
4:rectangle(159,168,267,187);
end;
mouseshow;
end;
procedure findmouse;
var button: boolean;
begin
// writeln(mouse.x,' ',mouse.y, ' ',mouse.getstatus );
if mouse.getstatus then button:=true else button:=false;
if (permx<>mouse.x) or (permy<>mouse.y) then keymode:=false;
if (keymode) and (not button) then exit;
case mouse.y of
148..167: case mouse.x of
25..159: cursor:=1;
160..283: cursor:=3;
else cursor:=0;
end;
168..187: case mouse.x of
43..159: cursor:=2;
160..267: cursor:=4;
else cursor:=0;
end;
else if not keymode then cursor:=0;
end;
if (button) and (cursor>0) then startit;
end;
procedure checkkey(c: char);
begin
case c of
#72: if cursor=0 then cursor:=1
else if cursor=1 then cursor:=4 else dec(cursor);
#80: if cursor=0 then cursor:=1
else if cursor=4 then cursor:=1 else inc(cursor);
#75: if cursor>2 then cursor:=cursor-2
else cursor:=cursor+2;
#77: if cursor>2 then cursor:=cursor-2
else cursor:=cursor+2;
end;
end;
procedure mainloop;
var p:pointer;
ps2,ps3,ps2_,ps3_: ^byte;
si,di:word;
begin
// writeln('wtf?');
code:=0;
cursor:=0;
keymode:=false;
playmod(true,loc_sound()+'INTRO2.MOD');
loadstarfield;
k:=random(32000);
setcolor(207);
repeat
dec(k);
if k>64000 then k:=k-64000;
{ asm // scroll?
push es
push ds
mov ax, [k]
les di, [s3]
mov bx, di
lds si, [s1]
mov cx, 64000
sub cx, ax
add di, ax
cld
rep movsb
mov cx, ax
mov di, bx
rep movsb
pop ds
push ds
les si, [s2]
lds di, [s3]
mov si, 51453
mov di, 7210
xor bl, bl
@@loopit:
cmp bl, [es: di]
je @@black
mov al, [es: di]
mov [ds: di], al
@@black:
inc di
dec si
jnz @@loopit
pop ds
pop es
end;
}
{we should probably typecast this to work under "-Sy" instead of disabling it? see https://wiki.freepascal.org/local_compiler_directives}
{$T-}
p:=@(s3^);
move(s1^,(p+k)^,64000-k);
p:=@(s1^);
move((p+64000-k)^,s3^,k);
si:=51453; di:=7210;
ps2:=@(s2^);
ps3:=@(s3^);
repeat
ps2_:=(@ps2^)+di;
ps3_:=(@ps3^)+di;
if(ps2_^>0) then
begin
ps3_^:=ps2_^;
end;
inc(di);
dec(si);
until(si=0);
{$T+}
mousehide;
scrto_move(s3^,screen,sizeof(screen));
mouseshow;
drawcursor;
findmouse;
if fastkeypressed then
begin
keymode:=true;
permx:=mouse.x;
permy:=mouse.y;
key:=readkey;
if key=#0 then checkkey(readkey);
if key=#13 then startit;
end;
delay(tslice);
until code>0;
dispose(s1);
dispose(s2);
dispose(s3);
stopmod;
fading;
mousehide;
// textmode(co80);
end;
procedure showmars;
var temp: pscreentype;
begin
fillchar(colors,sizeof(paltype),0);
set256colors(colors);
loadscreen_data('cloud',@screen);
new(temp);
loadscreen_data('world',temp);
colors[29]:=colors[0];
colors[30]:=colors[0];
set256colors(colors);
upscroll(temp^);
dispose(temp);
end;
{function timewait(t: integer): boolean; // true if t sec. passed since gettime
var i:dword ;
begin
getcurtime;
i:=abs(curth-modth)*3600+abs(curtm-modtm)*60+abs(curts-modts);
if(i>=t) then timewait:=true else timewait:=false;
end;}
procedure dothefade;
var temppal: paltype;
a: integer;
begin
temppal[0,1]:=0; // to turn off warnings, variables are actually correctly initialized by function below
move(colors,temppal,sizeof(paltype));
for a:=31 downto 0 do
begin
for j:=0 to 31 do
if j<>31 then
begin
for i:=1 to 3 do
temppal[j,i]:=round(a*colors[j,i]/32);
end
else
begin
if a>16 then
begin
for i:=1 to 3 do
temppal[31,i]:=round((a-16)*colors[31,i]/16);
end
else
begin
temppal[31,1]:=round(63/16*(16-a));
end;
end;
set256colors(temppal);
delay(tslice);
end;
move(temppal,colors,sizeof(paltype));
end;
procedure printxy2(x1,y1,tcolor: integer; s: string);
var letter,a,x,y: integer;
begin
x1:=x1+4; { this stupid offset is pissing me off!!!!}
for j:=1 to length(s) do
begin
case s[j] of
'a'..'z': letter:=ord(s[j])-40;
'A' ..'Z': letter:=ord(s[j])-36;
' ' ..'"': letter:=ord(s[j])-31;
''''..'?': letter:=ord(s[j])-35;
'%': letter:=55;
else letter:=1;
end;
y:=y1;
for i:=0 to 5 do
begin
x:=x1;
inc(y);
for a:=7 downto 4 do
begin
inc(x);
if font[letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor;
end;
x:=x1;
inc(y);
inc(i);
for a:=3 downto 0 do
begin
inc(x);
if font[letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor;
end;
end;
x1:=x1+5;
end;
end;
procedure writestr2(s1,s2,s3: string);
var i,j1,j2,j3,b: integer;
begin
scr_fillchar(screen,sizeof(screen),0);
j1:=156-((length(s1)*5) div 2);
j2:=156-((length(s2)*5) div 2);
j3:=156-((length(s3)*5) div 2);
set256colors(colors);
b:=tslice div 2;
for i:=31 downto 0 do
begin
printxy2(j1-i,90-i,31-i,s1);
printxy2(j1-i,90+i,31-i,s1);
printxy2(j1+i,90-i,31-i,s1);
printxy2(j1+i,90+i,31-i,s1);
printxy2(j2-i,100-i,31-i,s2);
printxy2(j2-i,100+i,31-i,s2);
printxy2(j2+i,100-i,31-i,s2);
printxy2(j2+i,100+i,31-i,s2);
printxy2(j3-i,110-i,31-i,s3);
printxy2(j3-i,110+i,31-i,s3);
printxy2(j3+i,110-i,31-i,s3);
printxy2(j3+i,110+i,31-i,s3);
delay(b);
end;
dothefade;
end;
(*
procedure domainscreen;
var backgr: pscreentype;
begin
loadscreen_data('main',@screen);
new(backgr);
loadscreen_data('cloud',backgr);
{ asm // mix 2 images 255 - mask color
push es
push ds
les si, [backgr]
mov ax, $A000
mov ds, ax
xor si, si
@@loopit:
mov al, [ds: si]
cmp al, 255
jne @@nodraw
mov al, [es: si]
mov [ds: si], al
@@nodraw:
inc si
cmp si, 64000
jne @@loopit
pop ds
pop es
end;
* }
dispose(backgr);
end;
procedure scrollmainscreen;
var temp,backgr: pscreentype;
y1,a,b,t: integer;
begin
new(temp);
new(backgr);
loadscreen_data('main',temp);
loadscreen_data('cloud',backgr);
set256colors(colors);
for i:=1 to 120 do
move(planet^[i],backgr^[i+12,28],30*4);
for y1:=0 to 4 do
for b:=6 to 138 do
for a:=10 to 303 do
if temp^[b,a]=255 then screen[b,a]:=backgr^[b+y1,a+y1];
t:=tslice div 4;
for y1:=0 to 36 do
begin
for j:=0 to 255 do
begin
colors[j,1]:=colors[j,1] + round((63-colors[j,1])/30);
colors[j,2]:=colors[j,2] - round(colors[j,2]/30);
colors[j,3]:=colors[j,3] - round(colors[j,3]/30);
end;
set256colors(colors);
delay(t);
end;
dispose(backgr);
dispose(temp);
end;
*)
procedure powerupencodes;
var a,b,t: integer;
part: real;
begin
setcolor(31);
part:=31/36;
//t:=tslice div 4;
t:=tslice;
for a:=0 to 5 do
for b:=0 to 36 do
begin
screen[(a mod 3)*30+48,(a div 3)*258+b+13]:=round(b*part)+64;
screen[(a mod 3)*30+49,(a div 3)*258+b+13]:=round(b*part)+64;
for i:=128 to 143 do
colors[i]:=colors[random(22)];
for i:=144 to 159 do
colors[i]:=colors[0];
set256colors(colors);
delay(t);
for i:=144 to 159 do
colors[i]:=colors[random(16)];
for i:=128 to 143 do
colors[i]:=colors[0];
set256colors(colors);
for i:=(a mod 3)*30+37 to (a mod 3)*30+42 do
for j:=(a div 3)*138+89 to (a div 3)*138+93 do
if screen[i,j] div 16=3 then screen[i,j]:=screen[i,j]+32;
end;
end;
(*
procedure createplanet(xc,yc: integer);
var x1,y1: integer;
a: longint;
begin
x1:=xc;
y1:=yc;
for a:=1 to 75000 do
begin
x1:=x1-1+random(3);
y1:=y1-1+random(3);
if x1>240 then x1:=1 else if x1<1 then x1:=240;
if y1>120 then y1:=1 else if y1<1 then y1:=120;
if landform^[x1,y1]<240 then landform^[x1,y1]:=landform^[x1,y1]+5;
end;
end;
*)
procedure generateplanet;
var f: file of landtype;
begin
randomize;
assign(f,loc_data()+'plan1.dta');
reset(f);
if ioresult<>0 then errorhandler('data/plan1.dta',1);
read(f,landform^);
if ioresult<>0 then errorhandler('data/plan1.dta',5);
close(f);
fillchar(planet^,14400,0);
water:=50;
part2:=28/(255-water);
c:=0;
ecl:=180;
radius:=3025;
c2:=1.09;
r2:=round(sqrt(radius));
waterindex:=33;
for j:=0 to 3 do spcindex[j]:=48+j;
spcindex[4]:=128;
spcindex[5]:=129;
end;
procedure makeplanet(t: integer; eclipse: boolean);
//var modth,modtm,modts,curth,curtm,curts: byte;
label endcheck;
begin
{asm
mov ah, 2Ch
int 21h
mov modth, ch
mov modtm, cl
mov modts, dh
end;}
gettime;
repeat
inc(c,1);
if c>240 then c:=c-240;
if (eclipse) and (c mod 2=0) then
begin
inc(ecl);
if ecl>340 then ecl:=ecl-340;
end;
x:=2*r2+10;
ofsy:=0;
for i:=6 to 2*r2+4 do
begin
y:=sqrt(radius-sqr(i-r2-5));
m:=round((r2-y)*c2);
part:=r2/y;
inc(ofsy);
ofsx:=m;
for j:=1 to x do
begin
index:=round(j*part);
if index>x then goto endcheck;
inc(ofsx);
if ecl>170 then
begin
if j=1 then alt:=10
else alt:=(index-ecl+186) div 2;
end
else if ecl<171 then
begin
if index=x then alt:=10
else alt:=(ecl-index) div 2
end
else alt:=0;
if alt<0 then alt:=0;