home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / games / wcoltris / source / columns.c < prev    next >
C/C++ Source or Header  |  1994-12-31  |  19KB  |  662 lines

  1. #include <vdi.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>    /* mem... */
  5.  
  6. #include <image.h>
  7.  
  8. #include "cltr.h"
  9.  
  10. extern int planes,columns_vdi;
  11.  
  12. #define WIDTH        6
  13. #define HEIGHT        16
  14. #define FIRSTLINE    4
  15. #define XHEIGHT        (HEIGHT+FIRSTLINE+1)
  16. #define XWIDTH        (WIDTH+2)
  17. static int BLOCK_SW    = 24;
  18. static int BLOCK_W        = 20;
  19. static int BLOCK_H        = 20;
  20. static int BLOCK_XW;
  21. static int BLOCK_XH;
  22.  
  23. int feld[HEIGHT+5][WIDTH+2];
  24.  
  25. void get_columns_size(int *w,int *h)
  26. {
  27.     *w=WIDTH*BLOCK_W;
  28.     *h=HEIGHT*BLOCK_H;
  29. }
  30. void get_columns_prev(int *w,int *h)
  31. {
  32.     *w=BLOCK_W*2;
  33.     *h=BLOCK_H*4;
  34. }
  35.  
  36. char col_quick1[]={
  37. 0x00,0x00,0x00,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,
  38. 0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x00,0x00,0x00,
  39. 0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x00,
  40.  
  41. 0x00,0x00,0x00,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,
  42. 0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x00,0x00,0x00,
  43. 0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x00,
  44.  
  45. 0x00,0x00,0x00,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,
  46. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  47. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,
  48.  
  49. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0b,0x11,0x15,0x0b,0x55,0x55,
  50. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  51. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0xdf,0xdd,0x00,
  52.  
  53. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  54. 0x0a,0x88,0x8d,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  55. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x8f,0x8d,0x00,
  56.  
  57. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x44,0x45,0x0b,0x55,0x55,
  58. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  59. 0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0b,0x07,0x05,0x00,
  60.  
  61. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  62. 0x0a,0x22,0x25,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  63. 0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0a,0x02,0x01,0x0a,0x02,0x01,0x00,
  64.  
  65. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0b,0x11,0x15,0x0b,0x55,0x55,
  66. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  67. 0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0b,0x07,0x05,0x00,
  68.  
  69. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  70. 0x0a,0x88,0x8d,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  71. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x8f,0x8d,0x00,
  72.  
  73. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x44,0x45,0x0b,0x55,0x55,
  74. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  75. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0xdf,0xdd,0x00,
  76.  
  77. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  78. 0x0a,0x22,0x25,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  79. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,
  80.  
  81. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0b,0x11,0x15,0x0b,0x55,0x55,
  82. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  83. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0xdf,0xdd,0x00,
  84.  
  85. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  86. 0x0a,0x88,0x8d,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  87. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x8f,0x8d,0x00,
  88.  
  89. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x44,0x45,0x0b,0x55,0x55,
  90. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  91. 0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0b,0x07,0x05,0x00,
  92.  
  93. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  94. 0x0a,0x22,0x25,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  95. 0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0a,0x02,0x01,0x0a,0x02,0x01,0x00,
  96.  
  97. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0b,0x11,0x15,0x0b,0x55,0x55,
  98. 0x0b,0x55,0x55,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  99. 0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x07,0x05,0x0b,0x07,0x05,0x00,
  100.  
  101. 0x00,0x00,0x00,0x0a,0x00,0x05,0x0a,0x00,0x05,0x0a,0xaa,0xad,
  102. 0x0a,0x88,0x8d,0x0a,0xaa,0xad,0x0b,0xff,0xfd,0x00,0x00,0x00,
  103. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0x8f,0x8d,0x0b,0x8f,0x8d,0x00,
  104.  
  105. 0x00,0x00,0x00,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,
  106. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x00,0x00,0x00,
  107. 0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xff,0xfd,0x0b,0xdf,0xdd,0x0b,0xdf,0xdd,0x00,
  108.  
  109. 0x00,0x00,0x00,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,
  110. 0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x00,0x00,0x00,
  111. 0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x08,0x00,0x01,0x00,
  112.  
  113. 0x00,0x00,0x00,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,
  114. 0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x00,0x00,0x00,
  115. 0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x07,0xff,0xfe,0x00,
  116. };
  117.  
  118. char col_quick2[]={
  119. 0x00,0x00,0x00,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,
  120. 0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x00,0x00,0x00,
  121. 0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x00,
  122.  
  123. 0x00,0x00,0x00,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,
  124. 0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x00,0x00,0x00,
  125. 0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x00,
  126.  
  127. 0x00,0x00,0x00,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,
  128. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  129. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,
  130.  
  131. 0x00,0x00,0x00,0xa0,0x00,0x50,0xb1,0x11,0x50,0xb5,0x55,0x50,
  132. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  133. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xbd,0xfd,0xd0,0x00,
  134.  
  135. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  136. 0xa8,0x88,0xd0,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  137. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb8,0xf8,0xd0,0x00,
  138.  
  139. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa4,0x44,0x50,0xb5,0x55,0x50,
  140. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  141. 0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xb0,0x70,0x50,0x00,
  142.  
  143. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  144. 0xa2,0x22,0x50,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  145. 0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xa0,0x20,0x10,0xa0,0x20,0x10,0x00,
  146.  
  147. 0x00,0x00,0x00,0xa0,0x00,0x50,0xb1,0x11,0x50,0xb5,0x55,0x50,
  148. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  149. 0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xb0,0x70,0x50,0x00,
  150.  
  151. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  152. 0xa8,0x88,0xd0,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  153. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb8,0xf8,0xd0,0x00,
  154.  
  155. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa4,0x44,0x50,0xb5,0x55,0x50,
  156. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  157. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xbd,0xfd,0xd0,0x00,
  158.  
  159. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  160. 0xa2,0x22,0x50,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  161. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,
  162.  
  163. 0x00,0x00,0x00,0xa0,0x00,0x50,0xb1,0x11,0x50,0xb5,0x55,0x50,
  164. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  165. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xbd,0xfd,0xd0,0x00,
  166.  
  167. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  168. 0xa8,0x88,0xd0,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  169. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb8,0xf8,0xd0,0x00,
  170.  
  171. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa4,0x44,0x50,0xb5,0x55,0x50,
  172. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  173. 0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xb0,0x70,0x50,0x00,
  174.  
  175. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  176. 0xa2,0x22,0x50,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  177. 0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xa0,0x20,0x10,0xa0,0x20,0x10,0x00,
  178.  
  179. 0x00,0x00,0x00,0xa0,0x00,0x50,0xb1,0x11,0x50,0xb5,0x55,0x50,
  180. 0xb5,0x55,0x50,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  181. 0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb0,0x70,0x50,0xb0,0x70,0x50,0x00,
  182.  
  183. 0x00,0x00,0x00,0xa0,0x00,0x50,0xa0,0x00,0x50,0xaa,0xaa,0xd0,
  184. 0xa8,0x88,0xd0,0xaa,0xaa,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  185. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xb8,0xf8,0xd0,0xb8,0xf8,0xd0,0x00,
  186.  
  187. 0x00,0x00,0x00,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,
  188. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0x00,0x00,0x00,
  189. 0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbf,0xff,0xd0,0xbd,0xfd,0xd0,0xbd,0xfd,0xd0,0x00,
  190.  
  191. 0x00,0x00,0x00,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,
  192. 0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x00,0x00,0x00,
  193. 0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x80,0x00,0x10,0x00,
  194.  
  195. 0x00,0x00,0x00,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,
  196. 0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x00,0x00,0x00,
  197. 0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x7f,0xff,0xe0,0x00,
  198. };
  199.  
  200. MFDB cbloecke={col_quick2,20*16,20,20,0,1,0,0,0};
  201.  
  202. typedef struct {
  203.     int x;
  204.     int y;
  205.     int c[3];
  206. } STONE;
  207.  
  208. static STONE stone,next;
  209.  
  210. extern long screen_addr,buffer_addr;
  211. extern MFDB buffer;
  212. extern int screen_width;
  213. extern dr_columns1(char *dest,char *source);
  214. extern dr_columns2(char *dest,char *source);
  215.  
  216. static int x_pos[XWIDTH];
  217. static int y_pos[XHEIGHT];
  218.  
  219. static void (*dr_block)(int x,int y,int col);
  220.  
  221. static void qdr_block(int x,int y,int col)
  222. {
  223. int xx,yy;
  224. char *source,*dest;
  225.  
  226.     xx=x_pos[x];
  227.     yy=y_pos[y];
  228.     dest=(char*)buffer_addr+(long)yy*buffer_width+xx/8;
  229.     if ( xx&7 ) {
  230.         source=col_quick1+col*3;
  231.         dr_columns1(dest,source);
  232.     }
  233.     else {
  234.         source=col_quick2+col*3;
  235.         dr_columns2(dest,source);
  236.     }
  237.     if ( yy<copy_min )
  238.         copy_min=yy;
  239.     if ( yy+BLOCK_XH>copy_max )
  240.         copy_max=yy+BLOCK_XH;
  241. }
  242. static void vdidr_block(int x,int y,int col)
  243. {    
  244. int xy[8],yy;
  245.  
  246.     xy[0]=col*BLOCK_SW;    /* blöcke auf bytegrenze verbreitert */
  247.     xy[1]=0;
  248.     xy[2]=xy[0]+BLOCK_XW;
  249.     xy[3]=BLOCK_XH;
  250.     xy[4]=x_pos[x];
  251.     yy=xy[5]=y_pos[y];
  252.     xy[6]=xy[4]+BLOCK_XW;
  253.     xy[7]=xy[5]+BLOCK_XH;
  254.     vro_cpyfm(handle,S_ONLY,xy,&cbloecke,&buffer);
  255.     if ( yy<copy_min )
  256.         copy_min=yy;
  257.     if ( yy+BLOCK_XH>copy_max )
  258.         copy_max=yy+BLOCK_XH;
  259. }
  260.  
  261. static void dr_vdi(int x,int y,int col,int x_off,int y_off)
  262. {    
  263. int xy[8];
  264.  
  265.     xy[0]=col*BLOCK_SW;    /* blöcke auf bytegrenze verbreitert */
  266.     xy[1]=0;
  267.     xy[2]=xy[0]+BLOCK_XW;
  268.     xy[3]=BLOCK_XH;
  269.     xy[4]=x_pos[x]+x_off;
  270.     xy[5]=y_pos[y]+y_off;
  271.     xy[6]=xy[4]+BLOCK_XW;
  272.     xy[7]=xy[5]+BLOCK_XH;
  273.     vro_cpyfm(handle,S_ONLY,xy,&cbloecke,&screen);
  274. }
  275.  
  276. static void rm_stone(void)
  277. {
  278. int i,y;
  279.  
  280.     for ( i=0; i<3; i++ ) {
  281.         y=stone.y+i;
  282.         if ( y>=FIRSTLINE ) {
  283.             dr_block(stone.x,y,0);
  284.         }
  285.     }
  286. }
  287.  
  288. static void dr_stone(void)
  289. {
  290. int i,y;
  291.     for ( i=0; i<3; i++ ) {
  292.         y=stone.y+i;
  293.         if ( y>=FIRSTLINE ) {
  294.             dr_block(stone.x,y,stone.c[i]);
  295.         }
  296.     }
  297. }
  298.  
  299. /*------------------------------------------------------------------------------
  300.  
  301.     preview
  302.  
  303. ------------------------------------------------------------------------------*/
  304. static void do_draw(void *data,int x,int y,int w,int h)
  305. {
  306. int i;
  307.  
  308.     for ( i=0; i<3; i++ )
  309.         dr_vdi(1,FIRSTLINE+i,next.c[i],prev_x+(prev_w-BLOCK_W)/2,prev_y+(prev_h-BLOCK_H*3)/2);
  310. }
  311.  
  312. static void dr_preview(void)
  313. {
  314.     draw_preview(do_draw,0l);
  315. }
  316.  
  317. void dr_cstat(int x,int y,int dy)
  318. {
  319. int i;
  320.  
  321.     for ( i=1; i<7; i++,y+=dy )
  322.         dr_vdi(2,FIRSTLINE,i,x,y);
  323. }
  324.  
  325. static void init_feld(void)
  326. {
  327. int i,j;
  328.  
  329.     for ( i=0; i<XHEIGHT; i++ ) {
  330.         for ( j=0; j<XWIDTH; j++ )
  331.             feld[i][j]=0;
  332.         feld[i][0]=feld[i][XWIDTH-1]=-1;
  333.     }
  334.     for ( j=0; j<XWIDTH; j++ )
  335.         feld[XHEIGHT-1][j]=-1;
  336.  
  337.     for ( i=XHEIGHT-1-opts.columns.random; i<XHEIGHT-1; i++ ) {
  338.         for ( j=1; j<XWIDTH-1; j++ ) {
  339.             feld[i][j]=(int)(xrandom()%6+1);
  340.             dr_block(j,i,feld[i][j]);
  341.         }
  342.     }
  343.     copy_out();
  344. }
  345.  
  346. static int check_stone(STONE *stone)
  347. {
  348.     if ( feld[stone->y+3][stone->x]!=0 )
  349.         return 1;
  350.     return 0;
  351. }
  352.  
  353. static int xcheck(void)
  354. {
  355. int i,j;
  356.  
  357.     for ( i=0; i<FIRSTLINE; i++ )
  358.         for ( j=1; j<XWIDTH-1; j++ )
  359.             if ( feld[i][j]!=0 )
  360.                 return 1;
  361.     return 0;
  362. }
  363.  
  364. static int check_side(STONE *stone,int side)
  365. {
  366.     if ( feld[stone->y][stone->x+side]!=0 ||
  367.             feld[stone->y+1][stone->x+side]!=0 ||
  368.             feld[stone->y+2][stone->x+side]!=0 )
  369.         return 1;
  370.     return 0;
  371. }
  372.  
  373. static void init_stone(void)
  374. {
  375.     next.x=XWIDTH/2;
  376.     next.y=1;
  377.     next.c[0]=(int)(xrandom()%6+1);
  378.     next.c[1]=(int)(xrandom()%6+1);
  379.     next.c[2]=(int)(xrandom()%6+1);
  380. }
  381.  
  382. static int check_feld(uint *lines)
  383. {
  384. int flags[XHEIGHT][XWIDTH];
  385. int i,j;
  386. int ii;
  387. int done=0;
  388.  
  389.     memset(flags,0,sizeof(flags));
  390.     for ( i=FIRSTLINE; i<XHEIGHT-1; i++ ) {
  391.         for ( j=1; j<XWIDTH-1; j++ ) {
  392.             if ( feld[i][j]==0 )
  393.                 continue;
  394.             if ( feld[i][j]==feld[i-1][j] && feld[i][j]==feld[i+1][j] ) {
  395.                 if ( flags[i-1][j]==0 )
  396.                     { flags[i-1][j]=1; (*lines)++; }
  397.                 if ( flags[i][j]==0 )
  398.                     { flags[i][j]=1; (*lines)++; }
  399.                 if ( flags[i+1][j]==0 )
  400.                     { flags[i+1][j]=1; (*lines)++; }
  401.                 done=1;
  402.             }
  403.             if ( feld[i][j]==feld[i][j-1] && feld[i][j]==feld[i][j+1] ) {
  404.                 if ( flags[i][j-1]==0 )
  405.                     { flags[i][j-1]=1; (*lines)++; }
  406.                 if ( flags[i][j]==0 )
  407.                     { flags[i][j]=1; (*lines)++; }
  408.                 if ( flags[i][j+1]==0 )
  409.                     { flags[i][j+1]=1; (*lines)++; }
  410.                 done=1;
  411.             }
  412.             if ( feld[i][j]==feld[i-1][j-1] && feld[i][j]==feld[i+1][j+1] ) {
  413.                 if ( flags[i-1][j-1]==0 )
  414.                     { flags[i-1][j-1]=1; (*lines)++; }
  415.                 if ( flags[i][j]==0 )
  416.                     { flags[i][j]=1; (*lines)++; }
  417.                 if ( flags[i+1][j+1]==0 )
  418.                     { flags[i+1][j+1]=1; (*lines)++; }
  419.                 done=1;
  420.             }
  421.             if ( feld[i][j]==feld[i-1][j+1] && feld[i][j]==feld[i+1][j-1] ) {
  422.                 if ( flags[i-1][j+1]==0 )
  423.                     { flags[i-1][j+1]=1; (*lines)++; }
  424.                 if ( flags[i][j]==0 )
  425.                     { flags[i][j]=1; (*lines)++; }
  426.                 if ( flags[i+1][j-1]==0 )
  427.                     { flags[i+1][j-1]=1; (*lines)++; }
  428.                 done=1;
  429.             }
  430.         }
  431.     }
  432.     if ( done ) {
  433.         for ( ii=8; ii<=12; ii++ ) {
  434.             init_wait();
  435.             for ( i=FIRSTLINE; i<XHEIGHT-1; i++ ) {
  436.                 for ( j=1; j<XWIDTH-1; j++ ) {
  437.                     if ( flags[i][j] )
  438.                         dr_block(j,i,ii);
  439.                 }
  440.             }
  441.             copy_out();
  442.             do_wait(5);
  443.         }
  444.  
  445.         for ( j=1; j<XWIDTH-1; j++ ) {
  446.             for ( ii=i=XHEIGHT-2; ii>=FIRSTLINE; ii--,i-- ) {
  447.                 while ( flags[i][j]!=0 )
  448.                     i--;
  449.                 if ( i<0 )
  450.                     i=0;
  451.                 if ( i!=ii ) {
  452.                     feld[ii][j]=feld[i][j];
  453.                     if ( feld[ii][j]==0 )
  454.                         dr_block(j,ii,0);
  455.                     else
  456.                         dr_block(j,ii,feld[ii][j]);
  457.                 }
  458.             }
  459.             for ( ; ii>=0; ii-- )
  460.                 feld[ii][j]=0;
  461.         }
  462.         copy_out();
  463.     }
  464.     return done;
  465. }
  466.  
  467. int columns(void)
  468. {
  469. long time;
  470. int draw,let_it_fall,drop_line;
  471. uint level,delay;
  472. uint stones,lines,score;
  473. STONE x;
  474. KEY key;
  475. uint stat[6]={0,0,0,0,0,0};
  476.  
  477.     init_feld();
  478.     while ( check_feld(&lines) )
  479.         ;
  480.  
  481.     level=opts.columns.start_level;
  482.     delay=calc_delay(level);
  483.     stones=lines=score=0;
  484.  
  485.     init_stone();
  486.  
  487.     while ( 1 ) {
  488.         stone=next;
  489.  
  490.         init_stone();
  491.         if ( preview_flag )
  492.             dr_preview();
  493.  
  494.         stat[stone.c[0]-1]++;
  495.         stat[stone.c[1]-1]++;
  496.         stat[stone.c[2]-1]++;
  497.         if ( stat_flag )
  498.             dr_stat(stat);
  499.  
  500.         if ( check_stone(&stone) || xcheck() )    /* game over? */
  501.             break;
  502.         x=stone;                    /* stein merken */
  503.  
  504.         stones++;
  505.         if ( level<9 && lines>level*50+50 )
  506.             { level++; inv_feld(); delay=calc_delay(level); }
  507.         dr_score(level,lines,stones,score);
  508.  
  509.         let_it_fall=0;                /* nicht fallen lassen */
  510.         time=gettime();                /* zeit merken */
  511.         draw=1;                        /* zeichnen */
  512.  
  513.         while ( 1 ) {
  514.             if ( draw ) {            /* nur wenn nötig */
  515.                 dr_stone();            /* stein zeichnen */
  516.                 draw=0;                /* flag löschen */
  517.                 copy_out();
  518.             }
  519.  
  520.             if ( !let_it_fall )        /* falls fallen lassen */
  521.                 key=get_key();
  522.             else
  523.                 key=NO_KEY;            /* kein zeichen einlesen */
  524.  
  525.             switch ( key ) {
  526.               case K_QUIT:
  527.                 return 0;
  528.               /*break;*/
  529.               case K_LEFT:
  530.                 if ( !check_side(&x,-1) )
  531.                     x.x--;
  532.               break;
  533.               case K_RIGHT:
  534.                 if ( !check_side(&x,+1) )
  535.                     x.x++;
  536.               break;
  537.               case K_ROTATE: {
  538.                int i;
  539.                 i=x.c[2];
  540.                 x.c[2]=x.c[1];
  541.                 x.c[1]=x.c[0];
  542.                 x.c[0]=i;
  543.               } break;
  544.               case K_DROP:
  545.                 let_it_fall=1;
  546.                 drop_line=x.y;
  547.               break;
  548.               case K_LEVEL:
  549.                 if ( level<9 ) {
  550.                       level++;
  551.                     inv_feld();
  552.                     delay=calc_delay(level);
  553.                     dr_score(level,lines,stones,score);
  554.                 }
  555.               break;
  556.               case K_NEXT:
  557.                 set_preview();
  558.                 if ( preview_flag )
  559.                     dr_preview();
  560.               break;
  561.               case K_INFO:
  562.                   set_score();
  563.               break;
  564.               case K_STAT:
  565.                   set_statistic();
  566.                   if ( stat_flag )
  567.                     dr_stat(stat);
  568.               break;
  569.               case K_STOP:
  570.                 xget_key();            /* taste mit warten holen */
  571.                 time=gettime();
  572.               break;
  573.             }
  574.  
  575.             if ( gettime()>time+delay || (let_it_fall && gettime()>time+1) ) {
  576.                 if ( check_stone(&x) )/* eins tiefer */
  577.                     break;
  578.                 time=gettime();
  579.                 x.y++;
  580.             }
  581.             if ( memcmp(&x,&stone,sizeof(x)) ) {
  582.                 draw=1;                /* falls sich was getan hat */
  583.                 rm_stone();            /* stein neuzeichnen */
  584.                 stone=x;
  585.             }
  586.         }
  587.  
  588.         if ( memcmp(&x,&stone,sizeof(x)) ) {
  589.             rm_stone();            /* stein neuzeichnen */
  590.             stone=x;
  591.             dr_stone();
  592.             copy_out();
  593.         }
  594.                                     /* stein ist unten angekommen */
  595.                                     /* eintragen ins feld */
  596.         feld[stone.y][stone.x]=stone.c[0];
  597.         feld[stone.y+1][stone.x]=stone.c[1];
  598.         feld[stone.y+2][stone.x]=stone.c[2];
  599.  
  600.                                     /* steine wegräumen */
  601.         while ( check_feld(&lines) )
  602.             ;
  603.  
  604.                                     /* score berechnen */
  605.         score+=5+level*2;
  606.         if ( let_it_fall )
  607.             score+=XHEIGHT-1-drop_line;
  608.         else 
  609.             score+=XHEIGHT-1-stone.y;
  610.         if ( preview_flag )
  611.             score-=3;
  612.  
  613.                                     /* tastaturpuffer löschen */
  614.         clr_keys();
  615.     }
  616.     clr_keys();
  617.     dr_score(level,lines,stones,score);
  618.     do_score(score,opts.col_hi);
  619.     return 1;
  620. }
  621.  
  622. int init_columns(void)
  623. {
  624. char name[16];
  625. MFDB pic;
  626. int i;
  627.  
  628.     sprintf(name,"COLUMNS%1d.IMG",planes);
  629.  
  630.     if ( !load_img(name,&pic) ) {
  631.         cbloecke=pic;
  632.         if ( planes>1 ) {
  633.             cbloecke.fd_addr=malloc(pic.fd_wdwidth*2l*planes*pic.fd_h);
  634.             pic.fd_stand=1;
  635.             cbloecke.fd_stand=0;
  636.             vr_trnfm(handle,&pic,&cbloecke);
  637.         }
  638.         BLOCK_SW=BLOCK_W=cbloecke.fd_w/16;
  639.         BLOCK_H=cbloecke.fd_h;
  640.         columns_vdi=1;
  641.         dr_block=vdidr_block;
  642.     }
  643.     else if ( planes==1 ) {
  644.         dr_block=qdr_block;
  645.         columns_vdi=0;
  646.     }
  647.     else {
  648.         columns_vdi=-1;
  649.         return 0;
  650.     }
  651.  
  652.     for ( i=1; i<XWIDTH; i++ )
  653.         x_pos[i]=(i-1)*BLOCK_W;
  654.     for ( i=FIRSTLINE; i<XHEIGHT; i++ )
  655.         y_pos[i]=(i-FIRSTLINE)*BLOCK_H;
  656.     BLOCK_XW=BLOCK_W-1;
  657.     BLOCK_XH=BLOCK_H-1;
  658.  
  659.     return 1;
  660. }
  661.  
  662.