You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Step 3.2.5: Clearing a row

When a piece is locked, we need to check if there are full rows to be removed. If there are, we'll call a procedure that removes the row and brings everything down from above. We will call this procedure to each full row.

  • We will use a lookup table again to get a memory address in Screen RAM for the row.
  • Then we use the MEMSET command to clear the row.
  • We also clear the row in the playfield array.
  • Then we copy the area above downwards row by row using MEMCPY.
  • Finally we clear the topmost row.
REM -- Clear a row and cascade everything from above
PROC clear_row(row_no!)
  screen_pos = screen_address[row_no!]
  REM -- Clear row on screen
  MEMSET screen_pos, 10, 32
  REM -- Clear row in playfield
  \playfield[row_no!] = %0010000000000100
  REM -- Wait approximately half of a sec
  FOR i! = 0 to 25 : WATCH \VICII_RASTER, 255 : NEXT
  REM -- Bring everything down
  FOR row = row_no! - 1 TO 4 STEP -1
    from_pos = screen_address[row]
    targ_pos = from_pos + 40
    REM -- Bring one row down on screen
    MEMCPY from_pos, targ_pos, 10
    REM -- Bring one row down in the playfield
    \playfield[row + 1] = \playfield[row]
  REM -- Clear upper row
  MEMSET 1199, 10, 32
  REM -- The address in Screen RAM for each row in the playfield
  REM -- Slightly different from as above because we only
  REM -- care about the middle 10 chars of the stage
  DATA screen_address[] = 1039, 1079, 1119, 1159, 1199, 1239, 1279, 1319, 1359, 1399, 1439, 1479, ~
                          1519, 1559, 1599, 1639, 1679, 1719, 1759, 1799, 1839, 1879, 1919, 1959, 1999

This line might need some further explanation:

FOR i! = 0 to 25 : WATCH \VICII_RASTER, 255 : NEXT

First, we haven't yet defined the constant VICII_RASTER so let's put the following statement somewhere in the top of the program:


Okay, now the above statement will compile without errors.

The WATCH command hangs execution until the value that a memory address holds becomes the desired value. The address $d012 is mapped to the VIC-II's raster counter register. Reading this address tells us what line on the screen is currently updated. The command WATCH $d012, 255 will wait until this register reads 255, which happens about every 1/50 of a second on PAL machines and 1/60 on NTSC machines. This command is run 25 times in a loop, resulting to wait approximately half a second (a little less on an NTSC machine).

We have written all routines that we need. We can move on to the last step where we'll program the game loop!