diff options
Diffstat (limited to 'projects/09')
25 files changed, 0 insertions, 10459 deletions
diff --git a/projects/09/Average/Main.jack b/projects/09/Average/Main.jack deleted file mode 100644 index a359602..0000000 --- a/projects/09/Average/Main.jack +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/Average/Main.jack - -// Inputs some numbers and computes their average -class Main { - function void main() { - var Array a; - var int length; - var int i, sum; - - let length = Keyboard.readInt("How many numbers? "); - let a = Array.new(length); // constructs the array - - let i = 0; - while (i < length) { - let a[i] = Keyboard.readInt("Enter a number: "); - let sum = sum + a[i]; - let i = i + 1; - } - - do Output.printString("The average is "); - do Output.printInt(sum / length); - return; - } -} diff --git a/projects/09/BitmapEditor/BitmapEditor.html b/projects/09/BitmapEditor/BitmapEditor.html deleted file mode 100644 index fdb9e0b..0000000 --- a/projects/09/BitmapEditor/BitmapEditor.html +++ /dev/null @@ -1,200 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" - "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<head> - <title>Sokoban Bitmap Editor</title> - <script type="text/javascript"> - var grid = new Array(0); - - function Init() { - grid = InitGrid(); - DisplayGrid(); - } - - function InitGrid() { - var _grid = new Array(16); - for (i=0; i<16; i++) { - _grid[i] = new Array(16); - for (j=0; j<16; j++) { - _grid[i][j]=false; - } - } - return _grid; - } - - function RotateBitmapRight() { - var _grid = InitGrid(); - - for (i=0; i<16; i++) { - for (j=0; j<16; j++) { - _grid[j][15-i]=grid[i][j]; - } - } - - grid = _grid; - DisplayGrid(); - } - - function MirrorBitmap() { - var _grid = InitGrid(); - - for (i=0; i<16; i++) { - for (j=0; j<16; j++) { - _grid[i][15-j]=grid[i][j]; - } - } - - grid = _grid; - DisplayGrid(); - } - - function DisplayGrid() { - var str = "<table border=1 cellspacing=0>"; - var i,j, backgroundColor; - for (i=-1; i<16; i++) { - str=str+"<tr>"; - for (j=-1; j<16; j++) { - if (i == -1 && j != -1) { - str=str+"<td>" + (j+1) + "</td>"; - } else if (i != -1 && j == -1) { - str=str+"<td>" + (i+1) + "</td>"; - } else if (i ==-1 && j == -1) { - str=str+"<td/>"; - } else { - - if (grid[i][j] == true) - backgroundColor = "black"; - else - backgroundColor = "white"; - - str=str+"<td onclick=\"OnCellClicked(this)\" id="; str=str+(i*16+j); str=str+" width=16 height=16 bgcolor=" + backgroundColor + "></td>"; - } - } - str=str+"</tr>"; - } - str=str+"</table>" - - gridElement = document.getElementById('grid'); - gridElement.innerHTML = str; - GenerateBitMap() ; - } - - function OnCellClicked(cell) { - var i = cell.id / 16 |0; - var j = cell.id - i*16; - grid[i][j] = !grid[i][j]; - if (grid[i][j]) - cell.style.backgroundColor = "black"; - else - cell.style.backgroundColor = "white"; - GenerateBitMap(); - } - - function GenerateBitMap() { - var i, j; - var value; - - var functionTypeSelect = document.getElementById('functionType'); - methodType = functionTypeSelect.options[functionTypeSelect.selectedIndex].value; - - generateCode = document.getElementById('generatedCode'); - generateCode.value = methodType + " void " + - document.getElementById('functionName').value + - "(int location) {\n\tlet memAddress = 16384+location;\n"; - - for (i=0; i<16; i++) { - //get grid binary representation - binary = ""; - for (j=0; j<16; j++) { - if (grid[i][j]) - binary = "1" + binary; - else - binary = "0" + binary; - } - - isNegative = false; - //if number is negative, get its one's complement - if (binary[0] == "1") { - isNegative = true; - oneComplement = ""; - for (k=0; k<16; k++) { - if (binary[k] == "1") - oneComplement = oneComplement + "0"; - else - oneComplement = oneComplement + "1"; - } - binary = oneComplement; - } - - //calculate one's complement decimal value - value = 0; - for (k=0; k<16; k++) { - value = value * 2; - if (binary[k] == "1") - value=value+1; - } - - //two's complement value if it is a negative value - if (isNegative == true) - value = -(value + 1) - - generateCode.value = generateCode.value + GenerateCodeLine(i, value); - } - - generateCode.value = generateCode.value + "\treturn;\n}"; - } - - function GenerateCodeLine(row, value) { - str = "\tdo Memory.poke(memAddress+" + row*32 + ", " + value + ");\n"; - return str; - } - </script> -</head> -<body onload="Init();"> - <h4><i>IDC Herzliya / Efi Arazi School of Computer Science / Digital Systems Construction, Spring 2011 / Project 09 / Golan Parashi</i></h4> - <h1>Sokoban Bitmap Editor</h1> - <p>This javascript applicaiton is used to generate highly optimized jack code for drawing a 16x16 bitmap to the screen.</p> - <p>Using the mouse, click the desired cell to mark/unmark it. You may use 90 degrees rotation and vertical mirroring by<br> - clicking the appropriate buttons.</p> - <p>When you are finished drawing, you may select function type and enter function's name.</p> - <p> - <table> - <thead> - <tr> - <th align="left">Bitmap</th> - <th align="left"></th> - <th align="left">Generated Jack Code</th> - </tr> - </thead> - <tr> - <td><div id="grid"/></td> - <td> - <form action="javascript:GenerateBitMap();"> - <table> - <tr><td align="left">Function Type:</td></tr> - <tr><td align="center"> - <select id="functionType" onChange="GenerateBitMap()"> - <option value="function" selected="selected">function</option> - <option value="method">method</option> - </select> - </td></tr> - <tr><td align="left">Function Name:</td></tr> - <tr><td align="left"><input type="text" value="draw" id="functionName" onkeyup="GenerateBitMap()"/></td></tr> - <tr><td></td></tr> - <tr><td align="center"><input type="button" value="Generate Code >>" onclick="GenerateBitMap()"/></td></tr> - </table> - </form> - </td> - <td><textarea id="generatedCode" cols="50" rows="20" readonly="read-only"></textarea></td> - </tr> - <tr> - <table> - <tr> - <td align="center"><input type="button" value="Rotate right" onclick="RotateBitmapRight()"/></td> - <td align="center"><input type="button" value="Vertical Mirror" onclick="MirrorBitmap()"/></td> - </tr> - </table> - </tr> - </table> -</body> -</html>
\ No newline at end of file diff --git a/projects/09/BitmapEditor/BitmapEditor.iml b/projects/09/BitmapEditor/BitmapEditor.iml deleted file mode 100644 index ef582b1..0000000 --- a/projects/09/BitmapEditor/BitmapEditor.iml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> - diff --git a/projects/09/Fraction/Fraction.jack b/projects/09/Fraction/Fraction.jack deleted file mode 100644 index c86f0a5..0000000 --- a/projects/09/Fraction/Fraction.jack +++ /dev/null @@ -1,65 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/Fraction/Fraction.jack - -/** Represents the Fraction type and related operations. */ -class Fraction { - field int numerator, denominator; // field = property = member variable. - - /** Constructs a (reduced) fraction from the given numerator and denominator. */ - constructor Fraction new(int x, int y) { - let numerator = x; - let denominator = y; - do reduce(); // reduces the fraction - return this; // a constructor is expected to return a reference to the new object - } - - // Reduces this fraction. - method void reduce() { - var int g; - let g = Fraction.gcd(numerator, denominator); - if (g > 1) { - let numerator = numerator / g; - let denominator = denominator / g; - } - return; - } - - /** Accessors. */ - method int getNumerator() { return numerator; } - method int getDenominator() { return denominator; } - - /** Returns the sum of this fraction and the other one. */ - method Fraction plus(Fraction other) { - var int sum; - let sum = (numerator * other.getDenominator()) + (other.getNumerator() * denominator); - return Fraction.new(sum, denominator * other.getDenominator()); - } - - // More fraction-related methods (minus, times, div, etc.) can be added here. - - /** Disposes this fraction. */ - method void dispose() { - do Memory.deAlloc(this); // uses an OS routine to recycle the memory held by the object - return; - } - - /** Prints this fraction in the format x/y. */ - method void print() { - do Output.printInt(numerator); - do Output.printString("/"); - do Output.printInt(denominator); - return; - } - - // Computes the greatest common divisor of the given integers. - function int gcd(int a, int b) { - var int r; - while (~(b = 0)) { // applies Euclid's algorithm - let r = a - (b * (a / b)); // r = remainder of the integer division a/b - let a = b; let b = r; - } - return a; - } -} diff --git a/projects/09/Fraction/Main.jack b/projects/09/Fraction/Main.jack deleted file mode 100644 index 43ddece..0000000 --- a/projects/09/Fraction/Main.jack +++ /dev/null @@ -1,16 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/Fraction/Main.jack - -// Computes the sum of 2/3 and 1/5. -class Main { - function void main() { - var Fraction a, b, c; - let a = Fraction.new(2,3); - let b = Fraction.new(1,5); - let c = a.plus(b); // Computes c = a + b - do c.print(); // Prints "13/15" - return; - } -} diff --git a/projects/09/HelloWorld/HelloWorld.asm b/projects/09/HelloWorld/HelloWorld.asm deleted file mode 100644 index 550a010..0000000 --- a/projects/09/HelloWorld/HelloWorld.asm +++ /dev/null @@ -1,923 +0,0 @@ -@256 -D=A -@SP -M=D -@RET0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Sys.init -0;JMP -(RET0) -(Main.main) -@12 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@String.new -0;JMP -(RET2) -@72 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET4 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET4) -@101 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET6 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET6) -@108 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET8 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET8) -@108 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET10 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET10) -@111 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET12 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET12) -@32 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET14 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET14) -@119 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET16 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET16) -@111 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET18 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET18) -@114 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET20 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET20) -@108 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET22 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET22) -@100 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET24 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET24) -@33 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET26 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@2 -D=D-A -@ARG -M=D -@String.appendChar -0;JMP -(RET26) -@RET27 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Output.printString -0;JMP -(RET27) -@SP -AM=M-1 -D=M -@5 -M=D -@RET29 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Output.println -0;JMP -(RET29) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP diff --git a/projects/09/HelloWorld/Main.jack b/projects/09/HelloWorld/Main.jack deleted file mode 100644 index 446b21b..0000000 --- a/projects/09/HelloWorld/Main.jack +++ /dev/null @@ -1,14 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/HelloWorld/Main.jack - -/** Hello World program. */ -class Main { - function void main() { - /* Prints some text using the standard library. */ - do Output.printString("Hello world!"); - do Output.println(); // New line - return; - } -} diff --git a/projects/09/HelloWorld/Main.vm b/projects/09/HelloWorld/Main.vm deleted file mode 100644 index 32eb03f..0000000 --- a/projects/09/HelloWorld/Main.vm +++ /dev/null @@ -1,33 +0,0 @@ -function Main.main 0 -push constant 12 -call String.new 1 -push constant 72 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 100 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -call Output.printString 1 -pop temp 0 -call Output.println 0 -pop temp 0 -push constant 0 -return diff --git a/projects/09/Jack OS API.pdf b/projects/09/Jack OS API.pdf Binary files differdeleted file mode 100644 index e653e86..0000000 --- a/projects/09/Jack OS API.pdf +++ /dev/null diff --git a/projects/09/K/Board.jack b/projects/09/K/Board.jack deleted file mode 100644 index 91a8d98..0000000 --- a/projects/09/K/Board.jack +++ /dev/null @@ -1,327 +0,0 @@ -class Board { - field Array grid; - field int nTurn, seed, status; // status: 0: begin game; 1: in game; 2: lose; 3: win; - static String boardBar, strLost, strCont, strGameOver, strWon, strTurn; - - constructor Board new() { - var int i; - let grid = Array.new(4); - let i = 0; - while (i < 4) { - let grid[i] = Array.new(4); - let i = i + 1; - } - do initBoard(); - let seed = 0; - return this; - } - - function void init() { - let boardBar = "+----+"; - let strLost = "You lost!"; - let strWon = "You won!"; - let strCont = "Press any key to continue"; - let strGameOver = "Game over!"; - let strTurn = "Turn: "; - return; - } - - method void initBoard() { - var int i, j; - var Array t; - let i = 0; - while (i < 4) { - let j = 0; - let t = grid[i]; - while (j < 4) { - let t[j] = 32; - let j = j + 1; - } - let i = i + 1; - } - let t = grid[0]; - let t[0] = 65; - let nTurn = 0; - let status = 0; - return; - } - - - method void transpose() { - do exch(0, 1); - do exch(0, 2); - do exch(0, 3); - do exch(1, 2); - do exch(1, 3); - do exch(2, 3); - return; - } - - method void exch(int i, int j){ - var int t; - var Array s1, s2; - let s1 = grid[i]; - let s2 = grid[j]; - let t = s1[j]; - let s1[j] = s2[i]; - let s2[i] = t; - return; - } - - method void align(Array xs, boolean left){ - var int i, j; - let i = 0; - let j = 0; - if (left) { - while (i < 4) { - if (xs[i] > 64) { - let xs[j] = xs[i]; - let j = j + 1; - } - let i = i + 1; - } - while (j < 4) { - let xs[j] = 32; - let j = j + 1; - } - } else { - while (i < 4) { - if (xs[3 - i] > 64) { - let xs[3 - j] = xs[3 - i]; - let j = j + 1; - } - let i = i + 1; - } - while (j < 4) { - let xs[3 - j] = 32; - let j = j + 1; - } - } - return; - } - - method void reduce(Array xs, boolean left){ - if ((xs[0] = xs[1]) & (xs[2] = xs[3]) & (xs[0] > 64) & (xs[2] > 64)) { - if (left) { - let xs[0] = xs[0] + 1; - let xs[1] = xs[2] + 1; - let xs[2] = 32; - let xs[3] = 32; - } else { - let xs[3] = xs[3] + 1; - let xs[2] = xs[1] + 1; - let xs[1] = 32; - let xs[0] = 32; - } - return; - } - if ((xs[0] = xs[1]) & (xs[0] > 64)) { - if (left) { - let xs[0] = xs[0] + 1; - let xs[1] = xs[2]; - let xs[2] = xs[3]; - let xs[3] = 32; - } else { - let xs[1] = xs[1] + 1; - let xs[0] = 32; - } - return; - } - if ((xs[2] = xs[3]) & (xs[2] > 64)) { - if (left) { - let xs[2] = xs[2] + 1; - let xs[3] = 32; - } else { - let xs[3] = xs[3] + 1; - let xs[2] = xs[1]; - let xs[1] = xs[0]; - let xs[0] = 32; - } - return; - } - if ((xs[1] = xs[2]) & (xs[1] > 64)) { - if (left) { - let xs[1] = xs[1] + 1; - let xs[2] = xs[3]; - let xs[3] = 32; - } else { - let xs[2] = xs[2] + 1; - let xs[1] = xs[0]; - let xs[0] = 32; - } - return; - } - return; - } - - method void addTile(){ - var Array t; - var int r, c, parity, newTile; - /* - let t = grid[1]; - if (t[1] = 32) { - let t[1] = 65; - } - */ - - if (~(status = 1)) { - return; - } - - let seed = seed * 25173 + 13849; - if (seed < 0) { - let seed = - seed; - } - - if (seed - (seed / 2 * 2) = 0) { - let parity = 1; - } else { - let parity = -1; - } - - let seed = seed - (seed / 16 * 16); - let r = seed / 4; - let c = seed - (4 * r); - let t = grid[r]; - let newTile = 65; - - while (t[c] > 64){ - let seed = seed + parity; - if (seed < 0) { - let seed = 15; - } - let seed = seed - (seed / 16 * 16); - let r = seed / 4; - let c = seed - (4 * r); - let t = grid[r]; - let newTile = 131 - newTile; - } - let t[c] = newTile; - return; - } - - method void transform(char dir){ - var boolean isVertical, left; - var int i; - if ((dir = 0) | (dir = 1)) { - let left = true; - } else { - let left = false; - } - if ((dir = 0) | (dir = 2)) { - let isVertical = false; - } else { - let isVertical = true; - } - if (isVertical) { - do transpose(); - } - let i = 0; - while (i < 4) { - do align(grid[i], left); - do reduce(grid[i], left); - let i = i + 1; - } - if (isVertical) { - do transpose(); - } - return; - } - - method void next(int dir){ - let nTurn = nTurn + 1; - do transform(dir); - do updateStatus(); - return; - } - - method int getStatus(){ - return status; - } - - method void setStatus(int x){ - let status = x; - return; - } - - method void updateStatus(){ - var int i, j; - var Array r; - let i = 0; - while (i < 4) { - let r = grid[i]; - let j = 0; - while (j < 4) { - if (r[j] = 75) { - let status = 3; - return; - } - if (r[j] = 32) { - let status = 1; - return; - } - let j = j + 1; - } - let i = i + 1; - } - let status = 2; - return; - } - - method void draw(){ - var int r, c, i, j; - var Array t; - let r = 9; - let c = 30; - - if (status = 0) { - do Output.moveCursor(r - 1, c - 1); - do Output.printChar(75); - do Output.moveCursor(r + 1, c - 1); - do Output.printString(strCont); - } else { if (status = 2) { - do Output.moveCursor(r - 1, c - 1); - do Output.printString(strGameOver); - do Output.moveCursor(r + 1, c - 1); - do Output.printString(strLost); - do Output.moveCursor(r + 3, c - 1); - do Output.printString(strCont); - } else { if (status = 3) { - do Output.moveCursor(r - 1, c - 1); - do Output.printString(strGameOver); - do Output.moveCursor(r + 1, c - 1); - do Output.printString(strWon); - do Output.moveCursor(r + 3, c - 1); - do Output.printString(strCont); - } else { - do Output.moveCursor(r - 1, c - 1); - do Output.printString(boardBar); - do Output.moveCursor(r + 4, c - 1); - do Output.printString(boardBar); - - let i = 0; - while (i < 4) { - let j = 0; - do Output.moveCursor(r + i, c - 1); - do Output.printChar(124); // 124 is | - let t = grid[i]; - while (j < 4) { - do Output.printChar(t[j]); - let j = j + 1; - } - do Output.printChar(124); - let i = i + 1; - } - - do Output.moveCursor(r + 6, c - 2); - do Output.printString(strTurn); - do Output.printInt(nTurn); - }}} - return; - } - - method void dispose() { - do Memory.deAlloc(this); - return; - } -} diff --git a/projects/09/K/Board.vm b/projects/09/K/Board.vm deleted file mode 100644 index 985e813..0000000 --- a/projects/09/K/Board.vm +++ /dev/null @@ -1,1465 +0,0 @@ -function Board.new 1 -push constant 4 -call Memory.alloc 1 -pop pointer 0 -push constant 4 -call Array.new 1 -pop this 0 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push constant 4 -lt -not -if-goto WHILE_END0 -push local 0 -push this 0 -add -push constant 4 -call Array.new 1 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push pointer 0 -call Board.initBoard 1 -pop temp 0 -push constant 0 -pop this 2 -push pointer 0 -return -function Board.init 0 -push constant 6 -call String.new 1 -push constant 43 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 45 -call String.appendChar 2 -push constant 43 -call String.appendChar 2 -pop static 0 -push constant 9 -call String.new 1 -push constant 89 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 108 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -pop static 1 -push constant 8 -call String.new 1 -push constant 89 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 119 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -pop static 4 -push constant 25 -call String.new 1 -push constant 80 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 115 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 107 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 121 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 99 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 116 -call String.appendChar 2 -push constant 105 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -pop static 2 -push constant 10 -call String.new 1 -push constant 71 -call String.appendChar 2 -push constant 97 -call String.appendChar 2 -push constant 109 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -push constant 111 -call String.appendChar 2 -push constant 118 -call String.appendChar 2 -push constant 101 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 33 -call String.appendChar 2 -pop static 3 -push constant 6 -call String.new 1 -push constant 84 -call String.appendChar 2 -push constant 117 -call String.appendChar 2 -push constant 114 -call String.appendChar 2 -push constant 110 -call String.appendChar 2 -push constant 58 -call String.appendChar 2 -push constant 32 -call String.appendChar 2 -pop static 5 -push constant 0 -return -function Board.initBoard 3 -push argument 0 -pop pointer 0 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push constant 4 -lt -not -if-goto WHILE_END0 -push constant 0 -pop local 1 -push local 0 -push this 0 -add -pop pointer 1 -push that 0 -pop local 2 -label WHILE_EXP1 -push local 1 -push constant 4 -lt -not -if-goto WHILE_END1 -push local 1 -push local 2 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -push this 0 -add -pop pointer 1 -push that 0 -pop local 2 -push constant 0 -push local 2 -add -push constant 65 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -pop this 1 -push constant 0 -pop this 3 -push constant 0 -return -function Board.transpose 0 -push argument 0 -pop pointer 0 -push pointer 0 -push constant 0 -push constant 1 -call Board.exch 3 -pop temp 0 -push pointer 0 -push constant 0 -push constant 2 -call Board.exch 3 -pop temp 0 -push pointer 0 -push constant 0 -push constant 3 -call Board.exch 3 -pop temp 0 -push pointer 0 -push constant 1 -push constant 2 -call Board.exch 3 -pop temp 0 -push pointer 0 -push constant 1 -push constant 3 -call Board.exch 3 -pop temp 0 -push pointer 0 -push constant 2 -push constant 3 -call Board.exch 3 -pop temp 0 -push constant 0 -return -function Board.exch 3 -push argument 0 -pop pointer 0 -push argument 1 -push this 0 -add -pop pointer 1 -push that 0 -pop local 1 -push argument 2 -push this 0 -add -pop pointer 1 -push that 0 -pop local 2 -push argument 2 -push local 1 -add -pop pointer 1 -push that 0 -pop local 0 -push argument 2 -push local 1 -add -push argument 1 -push local 2 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push argument 1 -push local 2 -add -push local 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -return -function Board.align 2 -push argument 0 -pop pointer 0 -push constant 0 -pop local 0 -push constant 0 -pop local 1 -push argument 2 -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -label WHILE_EXP0 -push local 0 -push constant 4 -lt -not -if-goto WHILE_END0 -push local 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 1 -push argument 1 -add -push local 0 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push constant 1 -add -pop local 1 -label IF_FALSE1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -label WHILE_EXP1 -push local 1 -push constant 4 -lt -not -if-goto WHILE_END1 -push local 1 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -goto IF_END0 -label IF_FALSE0 -label WHILE_EXP2 -push local 0 -push constant 4 -lt -not -if-goto WHILE_END2 -push constant 3 -push local 0 -sub -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 3 -push local 1 -sub -push argument 1 -add -push constant 3 -push local 0 -sub -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push constant 1 -add -pop local 1 -label IF_FALSE2 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP2 -label WHILE_END2 -label WHILE_EXP3 -push local 1 -push constant 4 -lt -not -if-goto WHILE_END3 -push constant 3 -push local 1 -sub -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP3 -label WHILE_END3 -label IF_END0 -push constant 0 -return -function Board.reduce 0 -push argument 0 -pop pointer 0 -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -eq -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -eq -and -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -and -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -and -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push argument 2 -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 0 -push argument 1 -add -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push argument 1 -add -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -goto IF_END1 -label IF_FALSE1 -push constant 3 -push argument 1 -add -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push argument 1 -add -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -label IF_END1 -push constant 0 -return -label IF_FALSE0 -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -eq -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -and -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push argument 2 -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push constant 0 -push argument 1 -add -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push argument 1 -add -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push argument 1 -add -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -goto IF_END3 -label IF_FALSE3 -push constant 1 -push argument 1 -add -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -label IF_END3 -push constant 0 -return -label IF_FALSE2 -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -eq -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -and -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -push argument 2 -if-goto IF_TRUE5 -goto IF_FALSE5 -label IF_TRUE5 -push constant 2 -push argument 1 -add -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -goto IF_END5 -label IF_FALSE5 -push constant 3 -push argument 1 -add -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push argument 1 -add -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push argument 1 -add -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -label IF_END5 -push constant 0 -return -label IF_FALSE4 -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -eq -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 64 -gt -and -if-goto IF_TRUE6 -goto IF_FALSE6 -label IF_TRUE6 -push argument 2 -if-goto IF_TRUE7 -goto IF_FALSE7 -label IF_TRUE7 -push constant 1 -push argument 1 -add -push constant 1 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 2 -push argument 1 -add -push constant 3 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 3 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -goto IF_END7 -label IF_FALSE7 -push constant 2 -push argument 1 -add -push constant 2 -push argument 1 -add -pop pointer 1 -push that 0 -push constant 1 -add -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 1 -push argument 1 -add -push constant 0 -push argument 1 -add -pop pointer 1 -push that 0 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -push argument 1 -add -push constant 32 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -label IF_END7 -push constant 0 -return -label IF_FALSE6 -push constant 0 -return -function Board.addTile 5 -push argument 0 -pop pointer 0 -push this 3 -push constant 1 -eq -not -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -return -label IF_FALSE0 -push this 2 -push constant 25173 -call Math.multiply 2 -push constant 13849 -add -pop this 2 -push this 2 -push constant 0 -lt -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push this 2 -neg -pop this 2 -label IF_FALSE1 -push this 2 -push this 2 -push constant 2 -call Math.divide 2 -push constant 2 -call Math.multiply 2 -sub -push constant 0 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push constant 1 -pop local 3 -goto IF_END2 -label IF_FALSE2 -push constant 1 -neg -pop local 3 -label IF_END2 -push this 2 -push this 2 -push constant 16 -call Math.divide 2 -push constant 16 -call Math.multiply 2 -sub -pop this 2 -push this 2 -push constant 4 -call Math.divide 2 -pop local 1 -push this 2 -push constant 4 -push local 1 -call Math.multiply 2 -sub -pop local 2 -push local 1 -push this 0 -add -pop pointer 1 -push that 0 -pop local 0 -push constant 65 -pop local 4 -label WHILE_EXP0 -push local 2 -push local 0 -add -pop pointer 1 -push that 0 -push constant 64 -gt -not -if-goto WHILE_END0 -push this 2 -push local 3 -add -pop this 2 -push this 2 -push constant 0 -lt -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push constant 15 -pop this 2 -label IF_FALSE3 -push this 2 -push this 2 -push constant 16 -call Math.divide 2 -push constant 16 -call Math.multiply 2 -sub -pop this 2 -push this 2 -push constant 4 -call Math.divide 2 -pop local 1 -push this 2 -push constant 4 -push local 1 -call Math.multiply 2 -sub -pop local 2 -push local 1 -push this 0 -add -pop pointer 1 -push that 0 -pop local 0 -push constant 131 -push local 4 -sub -pop local 4 -goto WHILE_EXP0 -label WHILE_END0 -push local 2 -push local 0 -add -push local 4 -pop temp 0 -pop pointer 1 -push temp 0 -pop that 0 -push constant 0 -return -function Board.transform 3 -push argument 0 -pop pointer 0 -push argument 1 -push constant 0 -eq -push argument 1 -push constant 1 -eq -or -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -not -pop local 1 -goto IF_END0 -label IF_FALSE0 -push constant 0 -pop local 1 -label IF_END0 -push argument 1 -push constant 0 -eq -push argument 1 -push constant 2 -eq -or -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 0 -pop local 0 -goto IF_END1 -label IF_FALSE1 -push constant 0 -not -pop local 0 -label IF_END1 -push local 0 -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push pointer 0 -call Board.transpose 1 -pop temp 0 -label IF_FALSE2 -push constant 0 -pop local 2 -label WHILE_EXP0 -push local 2 -push constant 4 -lt -not -if-goto WHILE_END0 -push pointer 0 -push local 2 -push this 0 -add -pop pointer 1 -push that 0 -push local 1 -call Board.align 3 -pop temp 0 -push pointer 0 -push local 2 -push this 0 -add -pop pointer 1 -push that 0 -push local 1 -call Board.reduce 3 -pop temp 0 -push local 2 -push constant 1 -add -pop local 2 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push pointer 0 -call Board.transpose 1 -pop temp 0 -label IF_FALSE3 -push constant 0 -return -function Board.next 0 -push argument 0 -pop pointer 0 -push this 1 -push constant 1 -add -pop this 1 -push pointer 0 -push argument 1 -call Board.transform 2 -pop temp 0 -push pointer 0 -call Board.updateStatus 1 -pop temp 0 -push constant 0 -return -function Board.getStatus 0 -push argument 0 -pop pointer 0 -push this 3 -return -function Board.setStatus 0 -push argument 0 -pop pointer 0 -push argument 1 -pop this 3 -push constant 0 -return -function Board.updateStatus 3 -push argument 0 -pop pointer 0 -push constant 0 -pop local 0 -label WHILE_EXP0 -push local 0 -push constant 4 -lt -not -if-goto WHILE_END0 -push local 0 -push this 0 -add -pop pointer 1 -push that 0 -pop local 2 -push constant 0 -pop local 1 -label WHILE_EXP1 -push local 1 -push constant 4 -lt -not -if-goto WHILE_END1 -push local 1 -push local 2 -add -pop pointer 1 -push that 0 -push constant 75 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 3 -pop this 3 -push constant 0 -return -label IF_FALSE0 -push local 1 -push local 2 -add -pop pointer 1 -push that 0 -push constant 32 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push constant 1 -pop this 3 -push constant 0 -return -label IF_FALSE1 -push local 1 -push constant 1 -add -pop local 1 -goto WHILE_EXP1 -label WHILE_END1 -push local 0 -push constant 1 -add -pop local 0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 2 -pop this 3 -push constant 0 -return -function Board.draw 5 -push argument 0 -pop pointer 0 -push constant 9 -pop local 0 -push constant 30 -pop local 1 -push this 3 -push constant 0 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push local 0 -push constant 1 -sub -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push constant 75 -call Output.printChar 1 -pop temp 0 -push local 0 -push constant 1 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 2 -call Output.printString 1 -pop temp 0 -goto IF_END0 -label IF_FALSE0 -push this 3 -push constant 2 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push local 0 -push constant 1 -sub -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 3 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 1 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 1 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 3 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 2 -call Output.printString 1 -pop temp 0 -goto IF_END1 -label IF_FALSE1 -push this 3 -push constant 3 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push local 0 -push constant 1 -sub -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 3 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 1 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 4 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 3 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 2 -call Output.printString 1 -pop temp 0 -goto IF_END2 -label IF_FALSE2 -push local 0 -push constant 1 -sub -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 0 -call Output.printString 1 -pop temp 0 -push local 0 -push constant 4 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push static 0 -call Output.printString 1 -pop temp 0 -push constant 0 -pop local 2 -label WHILE_EXP0 -push local 2 -push constant 4 -lt -not -if-goto WHILE_END0 -push constant 0 -pop local 3 -push local 0 -push local 2 -add -push local 1 -push constant 1 -sub -call Output.moveCursor 2 -pop temp 0 -push constant 124 -call Output.printChar 1 -pop temp 0 -push local 2 -push this 0 -add -pop pointer 1 -push that 0 -pop local 4 -label WHILE_EXP1 -push local 3 -push constant 4 -lt -not -if-goto WHILE_END1 -push local 3 -push local 4 -add -pop pointer 1 -push that 0 -call Output.printChar 1 -pop temp 0 -push local 3 -push constant 1 -add -pop local 3 -goto WHILE_EXP1 -label WHILE_END1 -push constant 124 -call Output.printChar 1 -pop temp 0 -push local 2 -push constant 1 -add -pop local 2 -goto WHILE_EXP0 -label WHILE_END0 -push local 0 -push constant 6 -add -push local 1 -push constant 2 -sub -call Output.moveCursor 2 -pop temp 0 -push static 5 -call Output.printString 1 -pop temp 0 -push this 1 -call Output.printInt 1 -pop temp 0 -label IF_END2 -label IF_END1 -label IF_END0 -push constant 0 -return -function Board.dispose 0 -push argument 0 -pop pointer 0 -push pointer 0 -call Memory.deAlloc 1 -pop temp 0 -push constant 0 -return diff --git a/projects/09/K/K.txt b/projects/09/K/K.txt deleted file mode 100644 index dc75c82..0000000 --- a/projects/09/K/K.txt +++ /dev/null @@ -1,25 +0,0 @@ -from a to k - -- a title frame showing game name and instructions. space to continue. -- a main frame showing the game running -- a endofgame frame showing game results: win or lose - -- a Board class with cell being a 4 by 4 two-d array. -- arrange strings according to an orientation: arrange(4 strings, dir)=cells - - dir: 0: align to left, 1: align to right, 2: align to top, 3:align to bottom - - e.g.: arrange({"abc", "bc", "dc", "efeh", 0}) gives the following board: - abc_ - bc__ - dc__ - efeh - - arrange({"abc", "bc", "dc", "efeh", 0}, 3) gives the following - ___e - a__f - bbde - ccch -- a new tile of 'a' or 'b' appears each turn somewhere, using some quasirandomisation e.g. (23 * n^2 + 79) mod 16. - - addtile(char, x, y) -- the board transformation: board.trans(dir) = arrange(dir) . (fmap reduce) . getstring(dir). calls getstrings, then reduce on each row / column -- board.getstrings(dir)= the strings according to direction dir. Inverse of arrange. -- reduce(string)=string: reduce("baac")=="bbc"; reduce("aabb")=="bc"; and reduce("cbb")== "cc" instead of "d". -- when one of the hjkl keys is pressed get the direction dir. diff --git a/projects/09/K/KGame.jack b/projects/09/K/KGame.jack deleted file mode 100644 index 017b4e8..0000000 --- a/projects/09/K/KGame.jack +++ /dev/null @@ -1,57 +0,0 @@ -class KGame{ - field Board board; - - constructor KGame new() { - let board = Board.new(); - do board.draw(); - return this; - } - - method void dispose() { - do board.dispose(); - do Memory.deAlloc(this); - return; - } - - method void run() { - var int key, key1, st; - var boolean exit; - let exit = false; - while (~exit) { - let st = board.getStatus(); - let key = 0; - while (key = 0) { - let key = Keyboard.keyPressed(); - } - let key1 = key; - while (~(key1 = 0)) { - let key1 = Keyboard.keyPressed(); - } - if (key = 81) { - let exit = true; - } else { if ((st = 0)) { - do Screen.clearScreen(); - do board.setStatus(1); - do board.draw(); - } else { if ((st = 2) | (st = 3)) { - do Screen.clearScreen(); - do board.setStatus(0); - do board.draw(); - do board.initBoard(); - } else { if (key = 82) { // r for restart - do Screen.clearScreen(); - do board.initBoard(); - do board.draw(); - } else { if ((key > 129) & (key < 134)) { - do Screen.clearScreen(); - do board.next(key - 130); - do board.draw(); - do Sys.wait(300); - do Screen.clearScreen(); - do board.addTile(); - do board.draw(); - }}}}} - } - return; - } -} diff --git a/projects/09/K/KGame.vm b/projects/09/K/KGame.vm deleted file mode 100644 index df3a069..0000000 --- a/projects/09/K/KGame.vm +++ /dev/null @@ -1,169 +0,0 @@ -function KGame.new 0 -push constant 1 -call Memory.alloc 1 -pop pointer 0 -call Board.new 0 -pop this 0 -push this 0 -call Board.draw 1 -pop temp 0 -push pointer 0 -return -function KGame.dispose 0 -push argument 0 -pop pointer 0 -push this 0 -call Board.dispose 1 -pop temp 0 -push pointer 0 -call Memory.deAlloc 1 -pop temp 0 -push constant 0 -return -function KGame.run 4 -push argument 0 -pop pointer 0 -push constant 0 -pop local 3 -label WHILE_EXP0 -push local 3 -not -not -if-goto WHILE_END0 -push this 0 -call Board.getStatus 1 -pop local 2 -push constant 0 -pop local 0 -label WHILE_EXP1 -push local 0 -push constant 0 -eq -not -if-goto WHILE_END1 -call Keyboard.keyPressed 0 -pop local 0 -goto WHILE_EXP1 -label WHILE_END1 -push local 0 -pop local 1 -label WHILE_EXP2 -push local 1 -push constant 0 -eq -not -not -if-goto WHILE_END2 -call Keyboard.keyPressed 0 -pop local 1 -goto WHILE_EXP2 -label WHILE_END2 -push local 0 -push constant 81 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -not -pop local 3 -goto IF_END0 -label IF_FALSE0 -push local 2 -push constant 0 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -call Screen.clearScreen 0 -pop temp 0 -push this 0 -push constant 1 -call Board.setStatus 2 -pop temp 0 -push this 0 -call Board.draw 1 -pop temp 0 -goto IF_END1 -label IF_FALSE1 -push local 2 -push constant 2 -eq -push local 2 -push constant 3 -eq -or -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -call Screen.clearScreen 0 -pop temp 0 -push this 0 -push constant 0 -call Board.setStatus 2 -pop temp 0 -push this 0 -call Board.draw 1 -pop temp 0 -push this 0 -call Board.initBoard 1 -pop temp 0 -goto IF_END2 -label IF_FALSE2 -push local 0 -push constant 82 -eq -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -call Screen.clearScreen 0 -pop temp 0 -push this 0 -call Board.initBoard 1 -pop temp 0 -push this 0 -call Board.draw 1 -pop temp 0 -goto IF_END3 -label IF_FALSE3 -push local 0 -push constant 129 -gt -push local 0 -push constant 134 -lt -and -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -call Screen.clearScreen 0 -pop temp 0 -push this 0 -push local 0 -push constant 130 -sub -call Board.next 2 -pop temp 0 -push this 0 -call Board.draw 1 -pop temp 0 -push constant 300 -call Sys.wait 1 -pop temp 0 -call Screen.clearScreen 0 -pop temp 0 -push this 0 -call Board.addTile 1 -pop temp 0 -push this 0 -call Board.draw 1 -pop temp 0 -label IF_FALSE4 -label IF_END3 -label IF_END2 -label IF_END1 -label IF_END0 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return diff --git a/projects/09/K/Main.jack b/projects/09/K/Main.jack deleted file mode 100644 index 7f86973..0000000 --- a/projects/09/K/Main.jack +++ /dev/null @@ -1,10 +0,0 @@ -class Main { - function void main() { - var KGame game; - do Board.init(); - let game = KGame.new(); - do game.run(); - do game.dispose(); - return; - } -} diff --git a/projects/09/K/Main.vm b/projects/09/K/Main.vm deleted file mode 100644 index 0441c7a..0000000 --- a/projects/09/K/Main.vm +++ /dev/null @@ -1,13 +0,0 @@ -function Main.main 1 -call Board.init 0 -pop temp 0 -call KGame.new 0 -pop local 0 -push local 0 -call KGame.run 1 -pop temp 0 -push local 0 -call KGame.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/09/List/List.jack b/projects/09/List/List.jack deleted file mode 100644 index c62fe28..0000000 --- a/projects/09/List/List.jack +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/List/List.jack - -/** Represents a linked list of integers. */ -class List { - field int data; // a list consists of a data field, - field List next; // followed by a list - - /* Creates a List. */ - constructor List new(int car, List cdr) { - let data = car; // the identifiers car and cdr are used in - let next = cdr; // memory of the Lisp programming language - return this; - } - - /** Accessors. */ - method int getData() { return data; } - method int getNext() { return next; } - - /** Prints this list. */ - method void print() { - var List current; // initializes current to the first item - let current = this; // of this list - while (~(current = null)) { - do Output.printInt(current.getData()); - do Output.printChar(32); // prints a space - let current = current.getNext(); - } - return; - } - - /** Disposes this List by recursively disposing its tail. */ - method void dispose() { - if (~(next = null)) { - do next.dispose(); - } - // Uses an OS routine to recycle this object. - do Memory.deAlloc(this); - return; - } - - // More list processing methods can come here. - -} diff --git a/projects/09/List/Main.jack b/projects/09/List/Main.jack deleted file mode 100644 index 824eb6f..0000000 --- a/projects/09/List/Main.jack +++ /dev/null @@ -1,17 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/List/Main.jack - -/** Demonstrates the use of the List abstraction. */ -class Main { - function void main() { - // Creates and uses the list (2,3,5). - var List v; - let v = List.new(5,null); - let v = List.new(2,List.new(3,v)); - do v.print(); // prints 2 3 5 - do v.dispose(); // disposes the list - return; - } -} diff --git a/projects/09/Square/Main.jack b/projects/09/Square/Main.jack deleted file mode 100644 index 8311cc2..0000000 --- a/projects/09/Square/Main.jack +++ /dev/null @@ -1,15 +0,0 @@ -// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/09/Square/Main.jack
-
-/** Initializes a new Square Dance game and starts running it. */
-class Main {
- function void main() {
- var SquareGame game;
- let game = SquareGame.new();
- do game.run();
- do game.dispose();
- return;
- }
-}
diff --git a/projects/09/Square/Main.vm b/projects/09/Square/Main.vm deleted file mode 100644 index a3b355b..0000000 --- a/projects/09/Square/Main.vm +++ /dev/null @@ -1,11 +0,0 @@ -function Main.main 1 -call SquareGame.new 0 -pop local 0 -push local 0 -call SquareGame.run 1 -pop temp 0 -push local 0 -call SquareGame.dispose 1 -pop temp 0 -push constant 0 -return diff --git a/projects/09/Square/Square.asm b/projects/09/Square/Square.asm deleted file mode 100644 index 8ad70dd..0000000 --- a/projects/09/Square/Square.asm +++ /dev/null @@ -1,6346 +0,0 @@ -@256 -D=A -@SP -M=D -@RET0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Sys.init -0;JMP -(RET0) -(Main.main) -@SP -A=M -M=0 -@SP -M=M+1 -@RET1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@SquareGame.new -0;JMP -(RET1) -@LCL -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET4 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@SquareGame.run -0;JMP -(RET4) -@SP -AM=M-1 -D=M -@5 -M=D -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET7 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@SquareGame.dispose -0;JMP -(RET7) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(SquareGame.new) -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Memory.alloc -0;JMP -(RET2) -@SP -AM=M-1 -D=M -@3 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@30 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET7 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@3 -D=D-A -@ARG -M=D -@Square.new -0;JMP -(RET7) -@THIS -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(SquareGame.dispose) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET17 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.dispose -0;JMP -(RET17) -@SP -AM=M-1 -D=M -@5 -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET20 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Memory.deAlloc -0;JMP -(RET20) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(SquareGame.moveSquare) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame29 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame29 -0;JMP -(IFSquareGame29) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame29) -@SP -AM=M-1 -D=M -@SquareGame.moveSquare$IF_TRUE0 -D;JNE -@SquareGame.moveSquare$IF_FALSE0 -0;JMP -(SquareGame.moveSquare$IF_TRUE0) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET34 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.moveUp -0;JMP -(RET34) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.moveSquare$IF_FALSE0) -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame39 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame39 -0;JMP -(IFSquareGame39) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame39) -@SP -AM=M-1 -D=M -@SquareGame.moveSquare$IF_TRUE1 -D;JNE -@SquareGame.moveSquare$IF_FALSE1 -0;JMP -(SquareGame.moveSquare$IF_TRUE1) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET44 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.moveDown -0;JMP -(RET44) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.moveSquare$IF_FALSE1) -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@3 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame49 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame49 -0;JMP -(IFSquareGame49) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame49) -@SP -AM=M-1 -D=M -@SquareGame.moveSquare$IF_TRUE2 -D;JNE -@SquareGame.moveSquare$IF_FALSE2 -0;JMP -(SquareGame.moveSquare$IF_TRUE2) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET54 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.moveLeft -0;JMP -(RET54) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.moveSquare$IF_FALSE2) -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@4 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame59 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame59 -0;JMP -(IFSquareGame59) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame59) -@SP -AM=M-1 -D=M -@SquareGame.moveSquare$IF_TRUE3 -D;JNE -@SquareGame.moveSquare$IF_FALSE3 -0;JMP -(SquareGame.moveSquare$IF_TRUE3) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET64 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.moveRight -0;JMP -(RET64) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.moveSquare$IF_FALSE3) -@5 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET68 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Sys.wait -0;JMP -(RET68) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(SquareGame.run) -@SP -A=M -M=0 -@SP -M=M+1 -@SP -A=M -M=0 -@SP -M=M+1 -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$WHILE_EXP0) -@LCL -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SquareGame.run$WHILE_END0 -D;JNE -(SquareGame.run$WHILE_EXP1) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame85 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame85 -0;JMP -(IFSquareGame85) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame85) -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SquareGame.run$WHILE_END1 -D;JNE -@RET88 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Keyboard.keyPressed -0;JMP -(RET88) -@LCL -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET91 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@SquareGame.moveSquare -0;JMP -(RET91) -@SP -AM=M-1 -D=M -@5 -M=D -@SquareGame.run$WHILE_EXP1 -0;JMP -(SquareGame.run$WHILE_END1) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@81 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame97 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame97 -0;JMP -(IFSquareGame97) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame97) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE0 -D;JNE -@SquareGame.run$IF_FALSE0 -0;JMP -(SquareGame.run$IF_TRUE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@LCL -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$IF_FALSE0) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@90 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame107 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame107 -0;JMP -(IFSquareGame107) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame107) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE1 -D;JNE -@SquareGame.run$IF_FALSE1 -0;JMP -(SquareGame.run$IF_TRUE1) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET112 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.decSize -0;JMP -(RET112) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.run$IF_FALSE1) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@88 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame117 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame117 -0;JMP -(IFSquareGame117) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame117) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE2 -D;JNE -@SquareGame.run$IF_FALSE2 -0;JMP -(SquareGame.run$IF_TRUE2) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET122 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.incSize -0;JMP -(RET122) -@SP -AM=M-1 -D=M -@5 -M=D -(SquareGame.run$IF_FALSE2) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@131 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame127 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame127 -0;JMP -(IFSquareGame127) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame127) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE3 -D;JNE -@SquareGame.run$IF_FALSE3 -0;JMP -(SquareGame.run$IF_TRUE3) -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$IF_FALSE3) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@133 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame136 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame136 -0;JMP -(IFSquareGame136) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame136) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE4 -D;JNE -@SquareGame.run$IF_FALSE4 -0;JMP -(SquareGame.run$IF_TRUE4) -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$IF_FALSE4) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@130 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame145 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame145 -0;JMP -(IFSquareGame145) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame145) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE5 -D;JNE -@SquareGame.run$IF_FALSE5 -0;JMP -(SquareGame.run$IF_TRUE5) -@3 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$IF_FALSE5) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@132 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame154 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame154 -0;JMP -(IFSquareGame154) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame154) -@SP -AM=M-1 -D=M -@SquareGame.run$IF_TRUE6 -D;JNE -@SquareGame.run$IF_FALSE6 -0;JMP -(SquareGame.run$IF_TRUE6) -@4 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -(SquareGame.run$IF_FALSE6) -(SquareGame.run$WHILE_EXP2) -@LCL -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquareGame164 -D;JEQ -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquareGame164 -0;JMP -(IFSquareGame164) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquareGame164) -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SquareGame.run$WHILE_END2 -D;JNE -@RET168 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@0 -D=D-A -@ARG -M=D -@Keyboard.keyPressed -0;JMP -(RET168) -@LCL -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET171 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@SquareGame.moveSquare -0;JMP -(RET171) -@SP -AM=M-1 -D=M -@5 -M=D -@SquareGame.run$WHILE_EXP2 -0;JMP -(SquareGame.run$WHILE_END2) -@SquareGame.run$WHILE_EXP0 -0;JMP -(SquareGame.run$WHILE_END0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.new) -@3 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Memory.alloc -0;JMP -(RET2) -@SP -AM=M-1 -D=M -@3 -M=D -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@ARG -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET11 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.draw -0;JMP -(RET11) -@SP -AM=M-1 -D=M -@5 -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.dispose) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET19 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Memory.deAlloc -0;JMP -(RET19) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.draw) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@RET28 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET28) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET38 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET38) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.erase) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET46 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET46) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET56 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET56) -@SP -AM=M-1 -D=M -@5 -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.incSize) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@254 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare67 -D;JLT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare67 -0;JMP -(IFSquare67) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare67) -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@510 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare72 -D;JLT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare72 -0;JMP -(IFSquare72) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare72) -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M&D -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@Square.incSize$IF_TRUE0 -D;JNE -@Square.incSize$IF_FALSE0 -0;JMP -(Square.incSize$IF_TRUE0) -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET78 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.erase -0;JMP -(RET78) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET85 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.draw -0;JMP -(RET85) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.incSize$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.decSize) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare95 -D;JGT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare95 -0;JMP -(IFSquare95) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare95) -@SP -AM=M-1 -D=M -@Square.decSize$IF_TRUE0 -D;JNE -@Square.decSize$IF_FALSE0 -0;JMP -(Square.decSize$IF_TRUE0) -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET100 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.erase -0;JMP -(RET100) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@3 -D=M -@SP -A=M -M=D -@SP -M=M+1 -@RET107 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Square.draw -0;JMP -(RET107) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.decSize$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.moveUp) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare117 -D;JGT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare117 -0;JMP -(IFSquare117) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare117) -@SP -AM=M-1 -D=M -@Square.moveUp$IF_TRUE0 -D;JNE -@Square.moveUp$IF_FALSE0 -0;JMP -(Square.moveUp$IF_TRUE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET122 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET122) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET136 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET136) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@RET144 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET144) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET154 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET154) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.moveUp$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.moveDown) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@254 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare166 -D;JLT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare166 -0;JMP -(IFSquare166) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare166) -@SP -AM=M-1 -D=M -@Square.moveDown$IF_TRUE0 -D;JNE -@Square.moveDown$IF_FALSE0 -0;JMP -(Square.moveDown$IF_TRUE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET171 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET171) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET181 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET181) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@RET189 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET189) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET203 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET203) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.moveDown$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.moveLeft) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare213 -D;JGT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare213 -0;JMP -(IFSquare213) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare213) -@SP -AM=M-1 -D=M -@Square.moveLeft$IF_TRUE0 -D;JNE -@Square.moveLeft$IF_FALSE0 -0;JMP -(Square.moveLeft$IF_TRUE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET218 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET218) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET232 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET232) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@RET240 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET240) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET250 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET250) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.moveLeft$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP -(Square.moveRight) -@ARG -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@3 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@510 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@IFSquare262 -D;JLT -@SP -A=M -M=0 -@SP -M=M+1 -@ENDIFSquare262 -0;JMP -(IFSquare262) -@SP -A=M -M=-1 -@SP -M=M+1 -(ENDIFSquare262) -@SP -AM=M-1 -D=M -@Square.moveRight$IF_TRUE0 -D;JNE -@Square.moveRight$IF_FALSE0 -0;JMP -(Square.moveRight$IF_TRUE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@RET267 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET267) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET277 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET277) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@2 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -@R13 -M=D -@SP -AM=M-1 -D=M -@R13 -A=M -M=D -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -A=M -M=!D -@SP -M=M+1 -@RET285 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@1 -D=D-A -@ARG -M=D -@Screen.setColor -0;JMP -(RET285) -@SP -AM=M-1 -D=M -@5 -M=D -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@1 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M-D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@0 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@1 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@2 -D=A+D -A=D -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -AM=M-1 -D=M -@SP -AM=M-1 -D=M+D -@SP -A=M -M=D -@SP -M=M+1 -@RET299 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@SP -A=M -M=D -@SP -M=M+1 -@ARG -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THIS -D=M -@SP -A=M -M=D -@SP -M=M+1 -@THAT -D=M -@SP -A=M -M=D -@SP -M=M+1 -@SP -D=M -@LCL -M=D -@5 -D=D-A -@4 -D=D-A -@ARG -M=D -@Screen.drawRectangle -0;JMP -(RET299) -@SP -AM=M-1 -D=M -@5 -M=D -(Square.moveRight$IF_FALSE0) -@0 -D=A -@SP -A=M -M=D -@SP -M=M+1 -@LCL -D=M -@R13 -M=D -@5 -A=D-A -D=M -@R14 -M=D -@SP -AM=M-1 -D=M -@ARG -A=M -M=D -@ARG -D=M+1 -@SP -M=D -@R13 -AM=M-1 -D=M -@THAT -M=D -@R13 -AM=M-1 -D=M -@THIS -M=D -@R13 -AM=M-1 -D=M -@ARG -M=D -@R13 -AM=M-1 -D=M -@LCL -M=D -@R14 -A=M -0;JMP diff --git a/projects/09/Square/Square.jack b/projects/09/Square/Square.jack deleted file mode 100644 index 38066e5..0000000 --- a/projects/09/Square/Square.jack +++ /dev/null @@ -1,108 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/09/Square/Square.jack - -/** Implements a graphical square. */ -class Square { - - field int x, y; // screen location of the square's top-left corner - field int size; // length of this square, in pixels - - /** Constructs a new square with a given location and size. */ - constructor Square new(int Ax, int Ay, int Asize) { - let x = Ax; - let y = Ay; - let size = Asize; - do draw(); - return this; - } - - /** Disposes this square. */ - method void dispose() { - do Memory.deAlloc(this); - return; - } - - /** Draws the square on the screen. */ - method void draw() { - do Screen.setColor(true); - do Screen.drawRectangle(x, y, x + size, y + size); - return; - } - - /** Erases the square from the screen. */ - method void erase() { - do Screen.setColor(false); - do Screen.drawRectangle(x, y, x + size, y + size); - return; - } - - /** Increments the square size by 2 pixels. */ - method void incSize() { - if (((y + size) < 254) & ((x + size) < 510)) { - do erase(); - let size = size + 2; - do draw(); - } - return; - } - - /** Decrements the square size by 2 pixels. */ - method void decSize() { - if (size > 2) { - do erase(); - let size = size - 2; - do draw(); - } - return; - } - - /** Moves the square up by 2 pixels. */ - method void moveUp() { - if (y > 1) { - do Screen.setColor(false); - do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size); - let y = y - 2; - do Screen.setColor(true); - do Screen.drawRectangle(x, y, x + size, y + 1); - } - return; - } - - /** Moves the square down by 2 pixels. */ - method void moveDown() { - if ((y + size) < 254) { - do Screen.setColor(false); - do Screen.drawRectangle(x, y, x + size, y + 1); - let y = y + 2; - do Screen.setColor(true); - do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size); - } - return; - } - - /** Moves the square left by 2 pixels. */ - method void moveLeft() { - if (x > 1) { - do Screen.setColor(false); - do Screen.drawRectangle((x + size) - 1, y, x + size, y + size); - let x = x - 2; - do Screen.setColor(true); - do Screen.drawRectangle(x, y, x + 1, y + size); - } - return; - } - - /** Moves the square right by 2 pixels. */ - method void moveRight() { - if ((x + size) < 510) { - do Screen.setColor(false); - do Screen.drawRectangle(x, y, x + 1, y + size); - let x = x + 2; - do Screen.setColor(true); - do Screen.drawRectangle((x + size) - 1, y, x + size, y + size); - } - return; - } -} diff --git a/projects/09/Square/Square.vm b/projects/09/Square/Square.vm deleted file mode 100644 index e3932bc..0000000 --- a/projects/09/Square/Square.vm +++ /dev/null @@ -1,304 +0,0 @@ -function Square.new 0 -push constant 3 -call Memory.alloc 1 -pop pointer 0 -push argument 0 -pop this 0 -push argument 1 -pop this 1 -push argument 2 -pop this 2 -push pointer 0 -call Square.draw 1 -pop temp 0 -push pointer 0 -return -function Square.dispose 0 -push argument 0 -pop pointer 0 -push pointer 0 -call Memory.deAlloc 1 -pop temp 0 -push constant 0 -return -function Square.draw 0 -push argument 0 -pop pointer 0 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -push constant 0 -return -function Square.erase 0 -push argument 0 -pop pointer 0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -push constant 0 -return -function Square.incSize 0 -push argument 0 -pop pointer 0 -push this 1 -push this 2 -add -push constant 254 -lt -push this 0 -push this 2 -add -push constant 510 -lt -and -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push pointer 0 -call Square.erase 1 -pop temp 0 -push this 2 -push constant 2 -add -pop this 2 -push pointer 0 -call Square.draw 1 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Square.decSize 0 -push argument 0 -pop pointer 0 -push this 2 -push constant 2 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push pointer 0 -call Square.erase 1 -pop temp 0 -push this 2 -push constant 2 -sub -pop this 2 -push pointer 0 -call Square.draw 1 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Square.moveUp 0 -push argument 0 -pop pointer 0 -push this 1 -push constant 1 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 2 -add -push constant 1 -sub -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -push this 1 -push constant 2 -sub -pop this 1 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push this 2 -add -push this 1 -push constant 1 -add -call Screen.drawRectangle 4 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Square.moveDown 0 -push argument 0 -pop pointer 0 -push this 1 -push this 2 -add -push constant 254 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push this 2 -add -push this 1 -push constant 1 -add -call Screen.drawRectangle 4 -pop temp 0 -push this 1 -push constant 2 -add -pop this 1 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 2 -add -push constant 1 -sub -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Square.moveLeft 0 -push argument 0 -pop pointer 0 -push this 0 -push constant 1 -gt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 2 -add -push constant 1 -sub -push this 1 -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -push this 0 -push constant 2 -sub -pop this 0 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push constant 1 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -label IF_FALSE0 -push constant 0 -return -function Square.moveRight 0 -push argument 0 -pop pointer 0 -push this 0 -push this 2 -add -push constant 510 -lt -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 1 -push this 0 -push constant 1 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -push this 0 -push constant 2 -add -pop this 0 -push constant 0 -not -call Screen.setColor 1 -pop temp 0 -push this 0 -push this 2 -add -push constant 1 -sub -push this 1 -push this 0 -push this 2 -add -push this 1 -push this 2 -add -call Screen.drawRectangle 4 -pop temp 0 -label IF_FALSE0 -push constant 0 -return diff --git a/projects/09/Square/SquareGame.jack b/projects/09/Square/SquareGame.jack deleted file mode 100644 index 02393e2..0000000 --- a/projects/09/Square/SquareGame.jack +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of www.nand2tetris.org
-// and the book "The Elements of Computing Systems"
-// by Nisan and Schocken, MIT Press.
-// File name: projects/09/Square/SquareGame.jack
-
-/**
- * Implements the Square Dance game.
- * This simple game allows the user to move a black square around
- * the screen, and change the square's size during the movement.
- * When the game starts, a square of 30 by 30 pixels is shown at the
- * top-left corner of the screen. The user controls the square as follows.
- * The 4 arrow keys are used to move the square up, down, left, and right.
- * The 'z' and 'x' keys are used, respectively, to decrement and increment
- * the square's size. The 'q' key is used to quit the game.
- */
-
-class SquareGame {
- field Square square; // the square of this game
- field int direction; // the square's current direction:
- // 0=none, 1=up, 2=down, 3=left, 4=right
-
- /** Constructs a new Square Game. */
- constructor SquareGame new() {
- // Creates a 30 by 30 pixels square and positions it at the top-left
- // of the screen.
- let square = Square.new(0, 0, 30);
- let direction = 0; // initial state is no movement
- return this;
- }
-
- /** Disposes this game. */
- method void dispose() {
- do square.dispose();
- do Memory.deAlloc(this);
- return;
- }
-
- /** Moves the square in the current direction. */
- method void moveSquare() {
- if (direction = 1) { do square.moveUp(); }
- if (direction = 2) { do square.moveDown(); }
- if (direction = 3) { do square.moveLeft(); }
- if (direction = 4) { do square.moveRight(); }
- do Sys.wait(5); // delays the next movement
- return;
- }
-
- /** Runs the game: handles the user's inputs and moves the square accordingly */
- method void run() {
- var char key; // the key currently pressed by the user
- var boolean exit;
- let exit = false;
-
- while (~exit) {
- // waits for a key to be pressed
- while (key = 0) {
- let key = Keyboard.keyPressed();
- do moveSquare();
- }
- if (key = 81) { let exit = true; } // q key
- if (key = 90) { do square.decSize(); } // z key
- if (key = 88) { do square.incSize(); } // x key
- if (key = 131) { let direction = 1; } // up arrow
- if (key = 133) { let direction = 2; } // down arrow
- if (key = 130) { let direction = 3; } // left arrow
- if (key = 132) { let direction = 4; } // right arrow
-
- // waits for the key to be released
- while (~(key = 0)) {
- let key = Keyboard.keyPressed();
- do moveSquare();
- }
- } // while
- return;
- }
-}
-
-
-
diff --git a/projects/09/Square/SquareGame.vm b/projects/09/Square/SquareGame.vm deleted file mode 100644 index 8444dbc..0000000 --- a/projects/09/Square/SquareGame.vm +++ /dev/null @@ -1,179 +0,0 @@ -function SquareGame.new 0 -push constant 2 -call Memory.alloc 1 -pop pointer 0 -push constant 0 -push constant 0 -push constant 30 -call Square.new 3 -pop this 0 -push constant 0 -pop this 1 -push pointer 0 -return -function SquareGame.dispose 0 -push argument 0 -pop pointer 0 -push this 0 -call Square.dispose 1 -pop temp 0 -push pointer 0 -call Memory.deAlloc 1 -pop temp 0 -push constant 0 -return -function SquareGame.moveSquare 0 -push argument 0 -pop pointer 0 -push this 1 -push constant 1 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push this 0 -call Square.moveUp 1 -pop temp 0 -label IF_FALSE0 -push this 1 -push constant 2 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push this 0 -call Square.moveDown 1 -pop temp 0 -label IF_FALSE1 -push this 1 -push constant 3 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push this 0 -call Square.moveLeft 1 -pop temp 0 -label IF_FALSE2 -push this 1 -push constant 4 -eq -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push this 0 -call Square.moveRight 1 -pop temp 0 -label IF_FALSE3 -push constant 5 -call Sys.wait 1 -pop temp 0 -push constant 0 -return -function SquareGame.run 2 -push argument 0 -pop pointer 0 -push constant 0 -pop local 1 -label WHILE_EXP0 -push local 1 -not -not -if-goto WHILE_END0 -label WHILE_EXP1 -push local 0 -push constant 0 -eq -not -if-goto WHILE_END1 -call Keyboard.keyPressed 0 -pop local 0 -push pointer 0 -call SquareGame.moveSquare 1 -pop temp 0 -goto WHILE_EXP1 -label WHILE_END1 -push local 0 -push constant 81 -eq -if-goto IF_TRUE0 -goto IF_FALSE0 -label IF_TRUE0 -push constant 0 -not -pop local 1 -label IF_FALSE0 -push local 0 -push constant 90 -eq -if-goto IF_TRUE1 -goto IF_FALSE1 -label IF_TRUE1 -push this 0 -call Square.decSize 1 -pop temp 0 -label IF_FALSE1 -push local 0 -push constant 88 -eq -if-goto IF_TRUE2 -goto IF_FALSE2 -label IF_TRUE2 -push this 0 -call Square.incSize 1 -pop temp 0 -label IF_FALSE2 -push local 0 -push constant 131 -eq -if-goto IF_TRUE3 -goto IF_FALSE3 -label IF_TRUE3 -push constant 1 -pop this 1 -label IF_FALSE3 -push local 0 -push constant 133 -eq -if-goto IF_TRUE4 -goto IF_FALSE4 -label IF_TRUE4 -push constant 2 -pop this 1 -label IF_FALSE4 -push local 0 -push constant 130 -eq -if-goto IF_TRUE5 -goto IF_FALSE5 -label IF_TRUE5 -push constant 3 -pop this 1 -label IF_FALSE5 -push local 0 -push constant 132 -eq -if-goto IF_TRUE6 -goto IF_FALSE6 -label IF_TRUE6 -push constant 4 -pop this 1 -label IF_FALSE6 -label WHILE_EXP2 -push local 0 -push constant 0 -eq -not -not -if-goto WHILE_END2 -call Keyboard.keyPressed 0 -pop local 0 -push pointer 0 -call SquareGame.moveSquare 1 -pop temp 0 -goto WHILE_EXP2 -label WHILE_END2 -goto WHILE_EXP0 -label WHILE_END0 -push constant 0 -return |