SNOW.PAS 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. {$D+,E+,G+,N+,X+,Y+}
  2. (*) Simple SnowFall (*)
  3. Program SnowFall;
  4. Uses Dos,MGUnit;
  5. Const BackGrndColor = 0;
  6. LightSnow = 255;
  7. DarkSnow = 254;
  8. Type tScreen = Array [0..63999] Of Byte;
  9. pScreen = ^tScreen;
  10. vP=array[0..255,0..2] of byte;
  11. Var
  12. PCX_File:File of char;
  13. Manufacturer:byte;
  14. Version:shortint;
  15. encoding:shortint;
  16. x,y,
  17. width,height,
  18. horz_res,vert_res:word;
  19. vScreen:pScreen;
  20. vPal:^vP;
  21. gd,gm:integer;
  22. Mmemory:Pointer;
  23. (*) FOR PCX (*)
  24. i,c : Word;
  25. vScr,SB : pScreen;
  26. h,m,s,s1,hn,mn,sn,s1n:word;
  27. DF : Boolean;
  28. Cnt : Byte;
  29. frames:word; sec:double;
  30. (*) *------------------* Procedure And Functions *-----------------------* (*)
  31. Procedure Read_Header;
  32. var c:char; ex:boolean;
  33. begin
  34. ex:=true;
  35. Read(PCX_File,c);
  36. Manufacturer:=ord(c);
  37. if Manufacturer<>10 then begin
  38. write('Error: wrong file.');
  39. Ex:=False;
  40. end;
  41. Read(PCX_File,c);
  42. version:=ord(c);
  43. case version of
  44. 0:writeln('Ver. 2.5 PaintBrush');
  45. 2:writeln('Ver. 2.8 Pallette');
  46. 3:writeln('Ver. 2.8 Without Pallette');
  47. 5:writeln('Ver. 3.0 or greater');
  48. else begin
  49. writeln('Wrong version.');
  50. ex:=false;
  51. end;
  52. end;
  53. read(PCX_File,c);
  54. encoding:=ord(c);
  55. if encoding=1 then writeln('RLE Encoding') else begin
  56. writeln('Wrong encoding');
  57. Ex:=false;
  58. end;
  59. read(PCX_File,c);
  60. x:=ord(c);
  61. read(PCX_File,c);
  62. y:=ord(c);
  63. writeln('The coordinates of the upper left corner is (',x,';',y,').');
  64. read(PCX_File,c);
  65. width:=ord(c);
  66. read(PCX_File,c);
  67. height:=ord(c);
  68. writeln('Image Height Is ',height,' and width ',width,'.');
  69. read(PCX_File,c);
  70. horz_res:=ord(c);
  71. read(PCX_File,c);
  72. vert_res:=ord(c);
  73. writeln('Vertical rezolution is ',vert_res,' and horizontal is ',horz_res,'.');
  74. end;
  75. Procedure Read_Main;
  76. var count,num,color,n:word; c:char;
  77. begin
  78. seek(PCX_File,128);
  79. count:=0;
  80. While (count<=64000) do
  81. begin
  82. Read(PCX_File,c);
  83. n:=ord(c);
  84. if (n>=192) and (N<=255) then begin
  85. num:=n-192;
  86. read(PCX_File,c);
  87. color:=ord(c);
  88. for n:=0 to num-1 do
  89. vScreen^[count+n]:=color;
  90. inc(count,num);
  91. end
  92. else begin vScreen^[count]:=n; inc(count); end;
  93. end;
  94. end;
  95. Procedure Pal_Read;
  96. var count:word;c:char;
  97. begin
  98. seek(PCX_File,FileSize(PCX_File)-256*3);
  99. count:=0;
  100. while (count<256) do
  101. begin
  102. Read(PCX_File,c);
  103. vPal^[count,0]:=ord(c) shr 2;
  104. Read(PCX_File,c);
  105. vPal^[count,1]:=ord(c) shr 2;
  106. Read(PCX_File,c);
  107. vPal^[count,2]:=ord(c) shr 2;
  108. inc(count);
  109. end;
  110. end;
  111. Function CalcTime(a,b,c,d,a1,b1,c1,d1:word):double;
  112. var dh,dm,ds,ds1:integer;
  113. begin
  114. dh:=a1-a; dm:=b1-b; ds:=c1-c; ds1:=d1-d;
  115. if ds1<0 then begin
  116. inc(ds1,60);
  117. dec(ds);
  118. end;
  119. if ds<0 then begin
  120. inc(ds,60);
  121. dec(dm);
  122. end;
  123. if dm<0 then begin
  124. inc(dm,60);
  125. dec(dh);
  126. end;
  127. CalcTime:=((dh*60+dm)*60+ds)+(ds1/60);
  128. end;
  129. (*) Set Needed Mode (*)
  130. Procedure SetMode(Mode : Byte); Assembler;
  131. asm
  132. Mov AH,0
  133. Mov AL,[Mode]
  134. Int 10h
  135. end;
  136. (*) Sets Red, Green and Blue Components Of The Current Color (*)
  137. Procedure SetRGB(C, R, G, B : Byte); Assembler;
  138. asm
  139. Mov DX, 3C8h
  140. Mov AL, [C]
  141. Out DX, AL
  142. Inc DX
  143. Mov AL, [R]
  144. Out DX, AL
  145. Mov AL, [G]
  146. Out DX, AL
  147. Mov AL, [B]
  148. Out DX, AL
  149. end;
  150. (*) Clears The Screen In VGA 320x200x256 (*)
  151. Procedure Cls(Color : Byte); Assembler;
  152. Asm
  153. Push DS
  154. Push $A000
  155. Pop ES
  156. Mov AL, [Color]
  157. Mov AH, AL
  158. Mov CX, 64000/2
  159. Rep StoSw
  160. Pop DS
  161. End;
  162. (*) Approximates The Number For Pallete (*)
  163. Function Color(I : Byte; Seed : Word) : Byte;
  164. Begin
  165. Color := Round(63*Abs(Sin(I*Pi/Seed)))
  166. End;
  167. (*) Copies The Buffer To The Screen (*)
  168. Procedure Flip; Assembler;
  169. Asm
  170. Push DS
  171. Les DI, vScr
  172. Mov DS, SEGA000
  173. Xor SI, SI
  174. Mov AX, 0A000h
  175. Mov ES, AX
  176. Xor DI, DI
  177. Mov CX, 16000
  178. Db $66
  179. Rep MovSw
  180. Pop DS
  181. End;
  182. (*) Wait For The Vertical RetRace (*)
  183. Procedure WaitRetRace;
  184. Begin
  185. While Port[$3da] And $08 = 0 Do
  186. end;
  187. (*) Main Procedure Of Falling Snow (*)
  188. Procedure Fall1;
  189. Var C,
  190. D : Integer;
  191. l,r,
  192. dl,
  193. dn,
  194. dr : Boolean;
  195. Begin
  196. For I := 63999-320 DownTo 0 Do
  197. Begin
  198. If (vScr^[I]>0) Then
  199. Begin
  200. c:=vScr^[i]; vScr^[i]:=0;
  201. dl:=vScr^[i+319]=0; dn:=vScr^[i+320]=0; dr:=vScr^[i+321]=0;
  202. if not dl and not dn and not dr then
  203. d:=0
  204. else
  205. if dl and dn and dr then
  206. begin
  207. d:=random(4);
  208. case d of
  209. 0: d:=319;
  210. 1: d:=320;
  211. 2: d:=321;
  212. 3: d:=1;
  213. 4: d:=-1;
  214. end;
  215. end
  216. else
  217. if dl and dn and not dr then
  218. begin
  219. d:=random(3);
  220. case d of
  221. 0: d:=319;
  222. 1: d:=320;
  223. 2: d:=1;
  224. 3: d:=-1;
  225. end;
  226. end
  227. else
  228. if dl and not dn and dr then
  229. begin
  230. d:=random(3);
  231. case d of
  232. 0: d:=319;
  233. 1: d:=321;
  234. 2: d:=1;
  235. 3: d:=-1;
  236. end;
  237. end
  238. else
  239. if not dl and dn and dr then
  240. begin
  241. d:=random(3);
  242. case d of
  243. 0: d:=320;
  244. 1: d:=321;
  245. 2: d:=1;
  246. 3: d:=-1;
  247. end;
  248. end
  249. else
  250. if dl and not dn and not dr then
  251. d:=319
  252. else
  253. if not dl and not dn and dr then
  254. d:=321
  255. else
  256. if not dl and dn and not dr then
  257. d:=320;
  258. {if (ParamCount<2) or ((ParamCount=1) and (ParamStr(1)='ACID'))
  259. then}
  260. > ‚®â ®â á § ª®¬¥­â à¨âì
  261. if (vScr^[i+d]>0) and (vScr^[i+d]<250) then begin vScr^[i]:=c;
  262. continue; end;
  263. > ¨ ¤® á.
  264. case c of
  265. DarkSnow : if DF then
  266. if (d=0) or (i+d>63999-320) then
  267. vScr^[i]:=LightSnow else vScr^[i+d]:=c
  268. else vScr^[i]:=c;
  269. LightSnow: if d=0 then vScr^[i]:=LightSnow else vScr^[i+d]:=c
  270. else vScr^[i]:=c;
  271. end;
  272. end;
  273. End
  274. End;
  275. Procedure ShowPicture;
  276. var i:Word;
  277. begin
  278. for i:=0 to 64000 do
  279. If vScreen^[i]>0 then vScr^[i]:=vScreen^[i];
  280. end;
  281. (*) *-------------------------* Main Body *------------------------------* (*)
  282. Begin
  283. new(vScreen); FillChar(vScreen^,64000,0); new(vPal); FillChar(vPal^,256*3,0);
  284. assign(PCX_File,'hny1.pcx');
  285. reset(PCX_File); Read_Main; Pal_Read; Close(PCX_File);
  286. SetMode($13);
  287. for i:=0 to 255 do SetRGB(i,vPal^[i,0],vPal^[i,1],vPal^[i,2]);
  288. Dispose(vPal);
  289. (*) Prepares The Buffer (*)
  290. New(vScr); FillChar(vScr^,64000,0); SegA000 := Seg(vScr^);
  291. Randomize; Cls(BackGrndColor);
  292. (*) Prepares Pallete (*)
  293. SetRGB(254,Color(110,512),Color(110,512),Color(110,512));
  294. SetRGB(255,Color(195,512),Color(195,512),Color(195,512));
  295. ShowPicture;
  296. GetTime(h,m,s,s1); frames:=0;
  297. (*) Main Falling (*)
  298. cnt:=0;
  299. Repeat
  300. DF:=False;
  301. if cnt=0 then
  302. inc(cnt)
  303. else
  304. begin
  305. Df:=True;
  306. Cnt:=0;
  307. end;
  308. (*) Puts Leading Flakes (*)
  309. For I := 0 To 319 Do
  310. Begin
  311. C := Random(170);
  312. Case c Of
  313. 1: vScr^[I] := LightSnow;
  314. 2: vScr^[I] := DarkSnow;
  315. End
  316. End;
  317. Fall1; Flip; inc(frames);
  318. Until Port[$60] = 1;
  319. GetTime(hn,mn,sn,s1n);sec:=CalcTime(h,m,s,s1,hn,mn,sn,s1n);
  320. (*) ShutDown The Buffer And Returns Back To The Text Screen (*)
  321. Dispose(vScr);Dispose(vScreen);SetMode($3);
  322. writeln(frames/sec:2:5,' fps');
  323. (*) GodBye (*)
  324. Writeln('Coded By Mike Korablin Jr. (MMK)',#10#13,
  325. 'Fido : 2:5025/2000.7@FidoNet.Org AKA
  326. 2:5025/40.48@FidoNet.Org'#10#13,
  327. 'E-Mail : mmk@archiv.vrn.ru');
  328. (*) The End :'''( (*)
  329. End.