// ****************************************************************************
//
// Logic 8: Check for filled rows
//
// ****************************************************************************

#include "defines.txt"

#define cur_row v255
#define cur_x v254
#define varno v253
#define cell_value v252
#define tmp_x v251
#define tmp_y v250
#define real_tmp_x v249
#define real_tmp_y v248
#define row_filled f255
#define rows_changed f254

cur_row = 20;
reset(rows_changed);

next_row:
cur_x = 11;
set(row_filled);

next_x:
varno = cur_row;  varno *= 10;  varno += cur_x;  varno += 9;
cell_value = *varno;
if (cell_value == 0) { reset(row_filled); }

cur_x++;
if (cur_x < 21) {
  goto(next_x);
}

if (isset(row_filled)) {

  tmp_y = cur_row;
  next_tmp_y1:
  tmp_x = 11;
  next_tmp_x1:

  varno = tmp_y;  varno *= 10;  varno += tmp_x;  varno += 9;
  if (tmp_y > 1) {
    varno -= 10;
    cell_value = *varno;
    varno += 10;
    *varno = cell_value;
  }
  else {
    *varno = 0;
  }

  tmp_x++;
  if (tmp_x < 21) { goto(next_tmp_x1); }
  tmp_y--;
  if (tmp_y > 0) { goto(next_tmp_y1); }


  set(rows_changed);
  cur_row++;
}

cur_row--;
if (cur_row > 0) {
  goto(next_row);
}

if (rows_changed) {
  tmp_y = 20;
  next_tmp_y2:
  tmp_x = 11;
  next_tmp_x2:

  varno = tmp_y;  varno *= 10;  varno += tmp_x;  varno += 9;

  v244 = 1;  // view number
  v245 = 0;  // loop number
  v246 = *varno;  // cel number
  v247 = 4;  // priority & margin
  real_tmp_x = tmp_x; real_tmp_x *= 5;
  real_tmp_y = tmp_y; real_tmp_y *= 8;
  add.to.pic.v(v244,v245,v246,real_tmp_x,real_tmp_y,v247,v247);
  tmp_x++;
  if (tmp_x < 21) { goto(next_tmp_x2); }
  tmp_y--;
  if (tmp_y > 0) { goto(next_tmp_y2); }
}


return();