// Tetris in Vaporlang // 2017 Will Smith (minkcv) // 2026 changes: add T piece, better randomness, fix rotation not working bugs, another rotate button var previousGPUState; var GPUState; var spriteIndex; var spriteSegment; var buttons; var prevButtons; // General purpose iterators and temporary variables var i; var i2; var color; var x; var y; var x2; var y2; // Randomness for next piece var random; var seedDone; var frameCount; var updateRender; // True when render is needed var clearRender; // True to reset tile sprites to disabled var renderTileX; var renderTileY; var renderSegment; var renderAddress; var renderTileColor; // Current piece sprites go here const pieceSegment 79; // Constants for piece type const pieceL 0; const pieceReverseL 1; const pieceS 2; const pieceReverseS 3; const pieceLine 4; const pieceSquare 5; const pieceT 6; var nextPieceType; var currentPieceType; var currentRotation; const tileWidth 8; const tileHeight 8; const leftMargin 80; const topMargin 20; // Current piece tiles var tile1X; var tile1Y; var tile2X; var tile2Y; var tile3X; var tile3Y; var tile4X; var tile4Y; // For checking rotations var dest1X; var dest1Y; var dest2X; var dest2Y; var dest3X; var dest3Y; var dest4X; var dest4Y; // For counting tiles in each row of each newly placed tile var row1Tiles; var row2Tiles; var row3Tiles; var row4Tiles; var clearY; // Argument to clearRowY // True (1) when a piece hits an existing tile var hitBelow; // True when the current piece can move right var canMoveRight; // True when the current piece can move left var canMoveLeft; // Arguments and return values for getTileXY and getXYFromTile var getX; var getY; var getXY; // Arguments to setTileXY var setX; var setY; var setXY; // True or false value of tile const nCols 8; const nRows 16; // Number of tiles at [ 0 , 0 ] through [ 0 , 255 ] // Stored in xy pairs var nTiles; // Colors stored at [ 1 , 0 ] through [ 1 , 255 ] // stored in 2 byte pairs but only the first byte is used const blue 3; const red 224; const green 28; const cyan 31; const magenta 227; const yellow 252; const gray 73; const white 255; var waitCounter; var gameOver; // True when the game has been lost var paused; // True when paused // Set background to grayish [ 127 , 16 ] = gray; call reset; [ 127 , 17 ] = 1; // Enable GPU // Main loop while 1 { prevButtons = buttons; buttons = [ 127 , 0 ]; if paused == 0 { if buttons & 4 { // Left if prevButtons & 4 == 0 { call checkMoveLeft; if canMoveLeft { call movePieceLeft; } } } if buttons & 8 { // Right if prevButtons & 8 == 0 { call checkMoveRight; if canMoveRight { call movePieceRight; } } } if buttons & 2 { // Drop piece waitCounter = 0; seedDone = 1; } if buttons & 16 { if prevButtons & 16 == 0 { call rotatePiece; } } if waitCounter == 0 { call checkHitBelow; if hitBelow { if seedDone == 0 { frameCount = tile3X; random = tile3X; } call addPieceToTiles; if seedDone { random = frameCount; } if frameCount == 255 { random = random ^ tile2X; } nextPieceType = random & 7; while nextPieceType > 6 { nextPieceType = nextPieceType - 7; } call newPiece; } if hitBelow == 0 { call movePieceDown; } // Slow things down the fewer tiles we have // because having more of them will also slow things down. waitCounter = 40; if nTiles > 30 { waitCounter = 30; if nTiles > 50 { waitCounter = 20; if nTiles > 70 { waitCounter = 10; } } } } waitCounter = waitCounter - 1; } if buttons & 128 { if prevButtons & 128 == 0 { paused = ~ paused; if gameOver { call reset; } } } if seedDone { frameCount = frameCount + 1; } call render; call waitScreen; } func addPieceToTiles { if tile1Y == 0 { if tile1X < 6 { if tile1X > 2 { paused = 1; gameOver = 1; return; } } } updateRender = 1; [ 0 , nTiles ] = tile1X; [ 0 , nTiles + 1 ] = tile1Y; [ 1 , nTiles ] = currentPieceType; nTiles = nTiles + 2; [ 0 , nTiles ] = tile2X; [ 0 , nTiles + 1 ] = tile2Y; [ 1 , nTiles ] = currentPieceType; nTiles = nTiles + 2; [ 0 , nTiles ] = tile3X; [ 0 , nTiles + 1 ] = tile3Y; [ 1 , nTiles ] = currentPieceType; nTiles = nTiles + 2; [ 0 , nTiles ] = tile4X; [ 0 , nTiles + 1 ] = tile4Y; [ 1 , nTiles ] = currentPieceType; nTiles = nTiles + 2; call clearRows; } func clearRows { row1Tiles = 0; row2Tiles = 0; row3Tiles = 0; row4Tiles = 0; i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y == tile1Y { row1Tiles = row1Tiles + 1; } if y == tile2Y { row2Tiles = row2Tiles + 1; } if y == tile3Y { row3Tiles = row3Tiles + 1; } if y == tile4Y { row4Tiles = row4Tiles + 1; } i = i + 2; } if row1Tiles == nCols { clearY = tile1Y; call clearRowY; clearRender = 1; i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y < clearY + 1 { [ 0 , i + 1 ] = y + 1; } i = i + 2; } } if row2Tiles == nCols { if tile2Y - tile1Y > 0 { // Not equal clearY = tile2Y; call clearRowY; clearRender = 1; i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y < clearY + 1 { [ 0 , i + 1 ] = y + 1; } i = i + 2; } } } if row3Tiles == nCols { if tile3Y - tile2Y > 0 { if tile3Y - tile1Y > 0 { clearY = tile3Y; call clearRowY; clearRender = 1; i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y < clearY + 1 { [ 0 , i + 1 ] = y + 1; } i = i + 2; } } } } if row4Tiles == nCols { if tile4Y - tile3Y > 0 { if tile4Y - tile2Y > 0 { if tile4Y - tile1Y > 0 { clearY = tile4Y; call clearRowY; clearRender = 1; i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y < clearY + 1 { [ 0 , i + 1 ] = y + 1; } i = i + 2; } } } } } } // IN: clearY: the row to clear func clearRowY { i = 0; while i < nTiles { y = [ 0 , i + 1 ]; if y == clearY { // Replace this tile with one off the end of the array x2 = [ 0 , nTiles - 2 ]; y2 = [ 0 , nTiles - 1 ]; color = [ 1 , nTiles - 2 ]; [ 0 , i ] = x2; [ 0 , i + 1 ] = y2; [ 1 , i ] = color; nTiles = nTiles - 2; i = i - 2; } i = i + 2; } } func movePieceDown { tile1Y = tile1Y + 1; tile2Y = tile2Y + 1; tile3Y = tile3Y + 1; tile4Y = tile4Y + 1; } func movePieceRight { tile1X = tile1X + 1; tile2X = tile2X + 1; tile3X = tile3X + 1; tile4X = tile4X + 1; } func movePieceLeft { tile1X = tile1X - 1; tile2X = tile2X - 1; tile3X = tile3X - 1; tile4X = tile4X - 1; } func checkHitBelow { hitBelow = 0; // Check if a tile is at the bottom if tile1Y == nRows - 1{ hitBelow = 1; return; } if tile2Y == nRows - 1{ hitBelow = 1; return; } if tile3Y == nRows - 1{ hitBelow = 1; return; } if tile4Y == nRows - 1{ hitBelow = 1; return; } // Check if a tile hits a tile below i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if tile1X == x { if tile1Y + 1 == y { hitBelow = 1; return; } } if tile2X == x { if tile2Y + 1 == y { hitBelow = 1; return; } } if tile3X == x { if tile3Y + 1 == y { hitBelow = 1; return; } } if tile4X == x { if tile4Y + 1 == y { hitBelow = 1; return; } } i = i + 2; } } func checkMoveRight { canMoveRight = 1; // Check the right boundary if tile1X == nCols - 1 { canMoveRight = 0; return; } if tile2X == nCols - 1 { canMoveRight = 0; return; } if tile3X == nCols - 1 { canMoveRight = 0; return; } if tile4X == nCols - 1 { canMoveRight = 0; return; } // Check if a tile hits a tile to the right i = 0; while i < nTiles { // Optimization note, instead of adding 1 to each tilex, // just subtract one from current tile x x = [ 0 , i ]; x = x - 1; y = [ 0 , i + 1 ]; if tile1Y == y { if tile1X == x { canMoveRight = 0; return; } } if tile2Y == y { if tile2X == x { canMoveRight = 0; return; } } if tile3Y == y { if tile3X == x { canMoveRight = 0; return; } } if tile4Y == y { if tile4X == x { canMoveRight = 0; return; } } i = i + 2; } } func checkMoveLeft { canMoveLeft = 1; // Check the left boundary if tile1X == 0 { canMoveLeft = 0; return; } if tile2X == 0 { canMoveLeft = 0; return; } if tile3X == 0 { canMoveLeft = 0; return; } if tile4X == 0 { canMoveLeft = 0; return; } // Check if a tile hits a tile to the left i = 0; while i < nTiles { // Optimization note, instead of subtracting 1 from each tilex, // just add one to current tile x x = 1 + [ 0 , i ]; y = [ 0 , i + 1 ]; if tile1Y == y { if tile1X == x { canMoveLeft = 0; return; } } if tile2Y == y { if tile2X == x { canMoveLeft = 0; return; } } if tile3Y == y { if tile3X == x { canMoveLeft = 0; return; } } if tile4Y == y { if tile4X == x { canMoveLeft = 0; return; } } i = i + 2; } } func rotatePiece { if currentPieceType == pieceSquare { return; } if currentPieceType == pieceL { call rotateL; return; } if currentPieceType == pieceReverseL { call rotateReverseL; return; } if currentPieceType == pieceS { call rotateS; return; } if currentPieceType == pieceReverseS { call rotateReverseS; return; } if currentPieceType == pieceLine { call rotateLine; return; } if currentPieceType == pieceT { call rotateT; } } // tiles must be in order 1234 top to bottom func rotateReverseL { if currentRotation == 0 { // 123 // 4 dest1X = tile2X; dest2Y = tile4Y; dest3X = tile2X; dest3Y = tile3Y + 2; dest4X = tile1X; dest4Y = dest3Y; if dest3Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest2Y == y { if dest2X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2Y = dest2Y; tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 1; return; } if currentRotation == 1 { // 1 // 2 // 43 dest1X = tile4X; dest1Y = tile1Y; dest3X = tile4X; dest3Y = tile2Y; dest4X = tile1X + 1; dest4Y = tile2Y; if dest4X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile1Y = dest1Y; tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 2; return; } if currentRotation == 2 { // 1 // 324 dest2Y = tile1Y; dest4X = tile1X; dest4Y = tile3Y + 1; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest2Y == y { if dest2X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile2Y = dest2Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 3; return; } // Else currentRotation 3 // 12 // 3 // 4 dest3X = tile2X + 1; dest3Y = tile2Y; dest4X = dest3X; dest4Y = tile3Y; if dest3X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 0; } func rotateL { if currentRotation == 0 { // 123 // 4 dest3X = tile2X; dest3Y = tile4Y; dest4X = tile2X; dest4Y = tile4Y + 1; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 1; return; } if currentRotation == 1 { // 12 // 3 // 4 dest1X = tile2X + 1; dest2Y = tile3Y; dest3X = tile1X; dest4X = dest1X; dest4Y = tile3Y; if dest1X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest2Y == y { if dest2X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2Y = dest2Y; tile3X = dest3X; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 2; return; } if currentRotation == 2 { // 1 // 324 dest1X = tile3X; dest2X = tile3X; dest3Y = tile3Y + 1; dest4X = tile2X; dest4Y = dest3Y; if dest3Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest2Y == y { if dest2X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2X = dest2X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 3; return; } // Else currentRotation 3 // 1 // 2 // 34 dest2X = tile4X; dest2Y = tile1Y; dest3X = tile4X + 1; dest3Y = tile1Y; dest4X = tile1X; dest4Y = tile2Y; if dest3X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest2Y == y { if dest2X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile2X = dest2X; tile2Y = dest2Y; tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 0; } func rotateS { if currentRotation == 0 { // 21 // 43 dest1X = tile4X; dest2X = tile4X; dest2Y = tile4Y; dest4X = tile3X; dest4Y = tile4Y + 1; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest2Y == y { if dest2X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2X = dest2X; tile2Y = dest2Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 1; return; } // Else currentRotation 1 // 1 // 23 // 4 dest1X = tile4X + 1; dest2X = tile3X; dest2Y = tile1Y; dest4X = tile1X; dest4Y = tile3Y; if dest1X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest2Y == y { if dest2X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2X = dest2X; tile2Y = dest2Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 0; } func rotateReverseS { if currentRotation == 0 { // 12 // 34 dest1X = tile2X; dest2Y = tile3Y; dest3X = tile1X; dest4X = tile1X; dest4Y = tile3Y + 1; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest2Y == y { if dest2X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2Y = dest2Y; tile3X = dest3X; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 1; return; } // Else currentRotation 1 // 1 // 32 // 4 dest1X = tile3X; dest2Y = tile1Y; dest3X = tile2X; dest4X = tile2X + 1; dest4Y = tile2Y; if dest4X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile2Y = dest2Y; tile3X = dest3X; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 0; } func rotateLine { if currentRotation == 0 { // (gap) // 1234 dest1X = tile2X; dest1Y = tile2Y - 1; dest3X = tile2X; dest3Y = tile2Y + 1; dest4X = tile2X; dest4Y = tile1Y + 2; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile1Y = dest1Y; tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 1; return; } // Else currentRotation 1 // g1 // a2 // p3 // 4 dest1X = tile1X - 1; dest1Y = tile2Y; dest3X = tile2X + 1; dest3Y = tile2Y; dest4X = tile2X + 2; dest4Y = tile2Y; if dest4X > nCols - 1 { return; } if tile1X == 0 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } if dest3Y == y { if dest3X == x { return; } } if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile1X = dest1X; tile1Y = dest1Y; tile3X = dest3X; tile3Y = dest3Y; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 0; } func rotateT { if currentRotation == 0 { // gap // 123 // 4 dest1X = tile2X; dest1Y = tile2Y - 1; dest2X = tile1X; dest2Y = tile1Y; dest3X = tile2X; dest3Y = tile2Y; i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } i = i + 2; } tile1X = dest1X; tile1Y = dest1Y; tile2X = dest2X; tile2Y = dest2Y; tile3X = dest3X; tile3Y = dest3Y; currentRotation = 1; return; } if currentRotation == 1 { // 1 // 23 // 4 dest4X = tile4X + 1; dest4Y = tile4Y - 1; if dest4X > nCols - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile4X = dest4X; tile4Y = dest4Y; currentRotation = 2; return; } if currentRotation == 2 { // 1 // 234 dest2X = tile3X; dest3X = tile4X; dest4X = tile3X; dest4Y = tile4Y + 1; if dest4Y > nRows - 1 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest4Y == y { if dest4X == x { return; } } i = i + 2; } tile2X = dest2X; tile3X = dest3X; tile4X = dest4X; tile4Y = dest4Y; currentRotation = 3; return; } // else currentRotation == 3 // 1 // 23 // 4 dest1X = tile1X - 1; dest1Y = tile2Y; if tile4X == 0 { return; } i = 0; while i < nTiles { x = [ 0 , i ]; y = [ 0 , i + 1 ]; if dest1Y == y { if dest1X == x { return; } } i = i + 2; } tile1X = dest1X; tile1Y = dest1Y; currentRotation = 0; } func newPiece { currentPieceType = nextPieceType; currentRotation = 0; if currentPieceType == pieceReverseL { tile1X = 3; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 5; tile3Y = 0; tile4X = 5; tile4Y = 1; return; } if currentPieceType == pieceL { // 123 // 4 tile1X = 3; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 5; tile3Y = 0; tile4X = 3; tile4Y = 1; return; } if currentPieceType == pieceS { tile1X = 5; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 4; tile3Y = 1; tile4X = 3; tile4Y = 1; return; } if currentPieceType == pieceReverseS { tile1X = 3; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 4; tile3Y = 1; tile4X = 5; tile4Y = 1; return; } if currentPieceType == pieceLine { tile1X = 3; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 5; tile3Y = 0; tile4X = 6; tile4Y = 0; return; } if currentPieceType == pieceSquare { tile1X = 3; tile1Y = 0; tile2X = 3; tile2Y = 1; tile3X = 4; tile3Y = 0; tile4X = 4; tile4Y = 1; return; } if currentPieceType == pieceT { // 123 // 4 tile1X = 3; tile1Y = 0; tile2X = 4; tile2Y = 0; tile3X = 5; tile3Y = 0; tile4X = 4; tile4Y = 1; } } func render { if clearRender { renderAddress = 16; renderSegment = 64; i = 0; while i < 253 { [ renderSegment , renderAddress ] = 0; // Disable if renderAddress == 240 { renderSegment = renderSegment + 1; } renderAddress = renderAddress + 16; i = i + 2; } clearRender = 0; } if updateRender { renderAddress = 16; renderSegment = 64; i = 0; while i < nTiles { renderTileX = [ 0 , i ]; renderTileY = [ 0 , i + 1 ]; renderTileColor = [ 1 , i ]; call renderTile; if renderAddress == 240 { renderSegment = renderSegment + 1; } renderAddress = renderAddress + 16; i = i + 2; } updateRender = 0; } renderSegment = pieceSegment; renderAddress = 0; renderTileX = tile1X; renderTileY = tile1Y; renderTileColor = currentPieceType; call renderTile; renderAddress = renderAddress + 16; renderTileX = tile2X; renderTileY = tile2Y; renderTileColor = currentPieceType; call renderTile; renderAddress = renderAddress + 16; renderTileX = tile3X; renderTileY = tile3Y; renderTileColor = currentPieceType; call renderTile; renderAddress = renderAddress + 16; renderTileX = tile4X; renderTileY = tile4Y; renderTileColor = currentPieceType; call renderTile; } // IN: renderTileX renderTileY renderSegment renderAddress, renderTileColor func renderTile { [ renderSegment , renderAddress ] = 128; // Enable x2 = 0; i2 = 0; while i2 < tileWidth { x2 = x2 + renderTileX; i2 = i2 + 1; } y2 = 0; i2 = 0; while i2 < tileHeight { y2 = y2 + renderTileY; i2 = i2 + 1; } x2 = x2 + leftMargin; y2 = y2 + topMargin; i2 = 0; color = 0; if renderTileColor == 0 { color = red; } if renderTileColor == 1 { color = green; } if renderTileColor == 2 { color = blue; } if renderTileColor == 3 { color = cyan; } if renderTileColor == 4 { color = magenta; } if renderTileColor == 5 { color = yellow; } if renderTileColor == 6 { color = white; } [ renderSegment , renderAddress + 1 ] = x2; [ renderSegment , renderAddress + 2 ] = y2; [ renderSegment , renderAddress + 7 ] = color; } func reset { seedDone = 0; nTiles = 0; call initSprites; call newPiece; paused = 0; gameOver = 0; } func initSprites { // Black background for tile area [ 64 , 0 ] = 128; [ 64 , 1 ] = leftMargin; // X [ 64 , 2 ] = topMargin; // Y i = 0; x = 0; while i < nCols { x = x + tileWidth; i = i + 1; } i = 0; y = 0; while i < nRows { y = y + tileHeight; i = i + 1; } [ 64 , 3 ] = x; // Width [ 64 , 4 ] = y; // Height // Use data at end of ROM as color info [ 64 , 5 ] = 240; [ 64 , 7 ] = 0; // Black // Tiles start at [ 64 , 16 ] spriteIndex = 16; spriteSegment = 64; i = 0; while i < 128 { [ spriteSegment , spriteIndex ] = 0; // Disable [ spriteSegment , spriteIndex + 3 ] = tileWidth; [ spriteSegment , spriteIndex + 4 ] = tileHeight; [ spriteSegment , spriteIndex + 5 ] = 128; // Sprite data segment [ spriteSegment , spriteIndex + 7 ] = 255; // White if spriteIndex == 240 { spriteSegment = spriteSegment + 1; } spriteIndex = spriteIndex + 16; i = i + 1; } spriteIndex = 0; while spriteIndex < 64 { [ pieceSegment , spriteIndex ] = 0; // Disable [ pieceSegment , spriteIndex + 3 ] = tileWidth; [ pieceSegment , spriteIndex + 4 ] = tileHeight; [ pieceSegment , spriteIndex + 5 ] = 128; // Sprite data segment [ pieceSegment , spriteIndex + 7 ] = 255; // White spriteIndex = spriteIndex + 16; } } func waitScreen { while GPUState == previousGPUState { GPUState = [ 127 , 17 ]; GPUState = GPUState & 2; } previousGPUState = GPUState; }