voxel.pp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. {
  2. $Id$
  3. This program is part of the FPC demoes.
  4. Copyright (C) 1999 by Marco van de Voort
  5. A port of a more "dirty" graphical program, to demonstrate
  6. some Go32 features. The program displays a landscape in which
  7. you can move with the cursorkeys
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************
  14. The sources for this game was found in SWAG, and was also posted to the
  15. International FIDO Pascal area.
  16. I assume that it is PD (both sources said nothing about the form of copyrights,
  17. but it was contributed to SWAG, which is generally PD)
  18. If there is somebody that claims authorship of these programs,
  19. please mail [email protected], and the sources will be removed from our
  20. websites.
  21. ------------------------------------------------------------------------
  22. There was no real original, I reconstructed some from several versions.
  23. A voxel source from Swag patched for FPC.
  24. - The original author was unknown. I saw a different version which named
  25. "Borek" (Marcin Borkowski), 2:480/25 as author.
  26. - Bas van Gaalen donated it to SWAG.
  27. - I, Marco van de Voort made some small FPC adjustments.
  28. - However one problem remained (wrapping of arrays), and Jonas Maebe mailed me
  29. that glitch to me. This practically meant putting all those WORD()
  30. typecasts in the array-parameters.
  31. Still BP compatible, Gameunit contains some BP alternatives for Go32
  32. procedures needed.}
  33. PROGRAM voxel;
  34. {$R-}
  35. USES Crt,Dos {$IFDEF FPC}, Go32{$ENDIF};
  36. type lrgarr=array[0..65534] of byte;
  37. const
  38. pal:array[1..384] of byte=(
  39. 0,0,0,48,48,48,1,0,43,1,3,43,2,5,44,2,7,44,3,9,45,4,11,46,5,13,47,6,15,48,
  40. 7,17,49,8,19,50,9,21,51,10,22,52,11,24,52,12,26,54,13,28,54,14,30,56,15,32,
  41. 56,16,34,58,17,34,58,17,36,58,18,38,60,19,40,60,20,42,62,21,44,62,10,31,0,
  42. 11,31,0,11,31,1,11,32,1,12,32,1,12,32,2,12,33,2,13,33,2,14,33,3,15,33,3,15,
  43. 34,3,15,34,4,15,35,4,16,35,4,16,35,5,16,36,5,17,36,5,17,36,6,18,37,6,18,38,
  44. 7,19,38,8,20,39,8,20,40,9,21,40,10,22,41,10,22,42,11,23,42,12,24,43,12,24,
  45. 44,13,25,44,14,25,45,14,26,46,15,27,46,16,27,47,17,28,47,18,28,48,19,29,49,
  46. 19,30,49,20,30,50,21,31,51,21,32,51,22,32,52,23,33,53,23,34,53,24,34,54,25,
  47. 35,55,25,36,55,26,36,56,27,37,57,27,38,57,27,39,57,27,41,57,27,42,57,27,43,
  48. 57,27,44,57,27,45,57,27,46,57,27,47,57,27,49,57,27,50,57,27,51,57,27,52,57,
  49. 27,53,57,27,55,57,27,56,57,27,57,57,27,58,57,27,58,57,26,58,57,25,58,57,24,
  50. 58,56,23,58,55,22,58,54,20,58,53,19,58,51,18,58,50,17,58,50,16,58,49,15,58,
  51. 48,14,58,47,13,58,46,12,58,45,11,58,44,11,58,44,10,58,43,10,58,42,9,57,41,
  52. 8,57,40,8,56,39,7,56,38,6,55,37,5,55,35,4,54,33,4,54,31,2,32,32,32,63,63,63,
  53. 63,63,63,63,63,63,63,63,63,48,48,48,63,63,63,63,63,63);
  54. VAR
  55. MP,Scr : ^lrgarr;
  56. rng : array[0..320] of byte;
  57. dir,i,x,y : integer;
  58. function ncol(mc,n,dvd:integer):integer;
  59. var loc:integer;
  60. begin
  61. loc:=(mc+n-random(2*n)) div dvd; ncol:=loc;
  62. if loc>250 then ncol:=250; if loc<5 then ncol:=5
  63. end;
  64. procedure plasma(x1,y1,x2,y2:word);
  65. var xn,yn,dxy,p1,p2,p3,p4:word;
  66. begin
  67. if (x2-x1<2) and (y2-y1<2) then
  68. exit;
  69. p1:=mp^[WORD(256*y1+x1)]; p2:=mp^[WORD(256*y2+x1)]; p3:=mp^[WORD(256*y1+x2)];
  70. p4:=mp^[WORD(256*y2+x2)]; xn:=((x2+x1) shr 1) and $ffff; yn:=((y2+y1) shr 1) and $ffff;
  71. dxy:=5*(x2-x1+y2-y1) div 3;
  72. if mp^[WORD(256*y1+xn)]=0 then mp^[WORD(256*y1+xn)]:=ncol(p1+p3,dxy,2);
  73. if mp^[WORD(256*yn+x1)]=0 then mp^[WORD(256*yn+x1)]:=ncol(p1+p2,dxy,2);
  74. if mp^[WORD(256*yn+x2)]=0 then mp^[WORD(256*yn+x2)]:=ncol(p3+p4,dxy,2);
  75. if mp^[WORD(256*y2+xn)]=0 then mp^[WORD(256*y2+xn)]:=ncol(p2+p4,dxy,2);
  76. mp^[WORD(word(256*yn)+xn)]:=ncol(word(p1+p2+p3+p4),word(dxy),4);
  77. plasma(x1,y1,xn,yn); plasma(xn,y1,x2,yn);
  78. plasma(x1,yn,xn,y2); plasma(xn,yn,x2,y2);
  79. end;
  80. procedure draw(xp,yp,dir:integer);
  81. var z,zobs,ix,iy,iy1,iyp,ixp,x,y,s,csf,snf,mpc,i,j:integer;
  82. begin
  83. fillchar(rng,sizeof(rng),200); zobs:=100+mp^[WORD(256*yp+xp)];
  84. csf:=round(256*cos((dir)/180*pi)); snf:=round(256*sin((dir)/180*pi));
  85. fillchar(scr^,64000,0);
  86. for iy:=yp to yp+55 do
  87. begin
  88. iy1:=1+2*(iy-yp); s:=4+300 div iy1;
  89. for ix:=xp+yp-iy to xp-yp+iy do
  90. begin
  91. ixp:=xp+((ix-xp)*csf+(iy-yp)*snf) shr 8;
  92. iyp:=yp+((iy-yp)*csf-(ix-xp)*snf) shr 8;
  93. x:=160+360*(ix-xp) div iy1;
  94. if (x>=0) and (x+s<=318) then
  95. begin
  96. z:=mp^[WORD(iyp shl 8+ixp)]; mpc:=z shr 1;
  97. if z<47 then z:=46; y:=100+(zobs-z)*30 div iy1;
  98. if (y<=199) and (y>=0) then
  99. for j:=x to x+s do
  100. begin
  101. for i:=y to rng[j] do
  102. scr^[WORD(320*i+j)]:=mpc;
  103. if y<rng[WORD(j)] then rng[WORD(j)]:=y
  104. end;
  105. end;
  106. end;
  107. end;
  108. {$IFDEF FPC}
  109. DosMemPut($A000,0,Scr^,64000);
  110. {$ELSE}
  111. Move(Scr^,mem[$A000:0],64000);
  112. {$ENDIF}
  113. end;
  114. VAR Reg : Registers;
  115. begin
  116. writeln('creating landscape...');
  117. randomize; x:=0; y:=0; dir:=0; new(mp); fillchar(mp^,65535,0);
  118. new(scr); mp^[$0000]:=128; plasma(0,0,256,256);
  119. Reg.ax:=$13; Intr($10,Reg);
  120. {$IFDEF FPC}
  121. Outportb($3C8,0);
  122. for i:=1 to 384 do OutPortb($3c9,pal[i]);
  123. {$ELSE}
  124. Port[$3C8] := 0;
  125. for i:=1 to 384 do Port[$3c9] := pal[i];
  126. {$ENDIF}
  127. repeat
  128. dir:=dir mod 360;
  129. draw(x,y,dir);
  130. case readkey of
  131. #0:case readkey of
  132. #75:dec(dir,10);
  133. #77:inc(dir,10);
  134. #72:begin
  135. y:=y+round(5*cos((dir)/180*pi));
  136. x:=x+round(5*sin((dir)/180*pi));
  137. end;
  138. #80:begin
  139. y:=y-round(5*cos((dir)/180*pi));
  140. x:=x-round(5*sin((dir)/180*pi));
  141. end;
  142. end;
  143. #27: begin
  144. Reg.ax:=$3;
  145. Intr($10,Reg);
  146. halt
  147. end
  148. end
  149. until false;
  150. end.
  151. {
  152. $Log$
  153. Revision 1.3 2002-09-07 15:06:35 peter
  154. * old logs removed and tabs fixed
  155. Revision 1.2 2002/02/22 21:45:24 carl
  156. - range check option gives big problems
  157. }