.
@@ -0,0 +1,27 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?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>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
function Main.main 1
|
||||
push constant 1
|
||||
neg
|
||||
pop local 0
|
||||
push constant 0
|
||||
push constant 20
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 17
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
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 116
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 84
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 0
|
||||
lt
|
||||
push local 0
|
||||
push constant 100
|
||||
gt
|
||||
or
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 33
|
||||
call String.new 1
|
||||
push constant 69
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 109
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 119
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
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 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 49
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Keyboard.readInt 1
|
||||
pop local 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Tetris.tetris 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,999 @@
|
||||
function Tetris.tetris 25
|
||||
call Piece.init 0
|
||||
pop temp 0
|
||||
call Tetris.border 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
pop static 0
|
||||
push constant 25
|
||||
call Array.new 1
|
||||
pop local 23
|
||||
push constant 0
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 1
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 23
|
||||
add
|
||||
push constant 32
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
push constant 32
|
||||
push constant 47
|
||||
push constant 47
|
||||
push constant 2
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 16
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 3
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 47
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 4
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 32
|
||||
push constant 0
|
||||
push constant 63
|
||||
push constant 15
|
||||
push constant 5
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 31
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 6
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push argument 0
|
||||
push constant 3
|
||||
call Math.multiply 2
|
||||
pop static 1
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push constant 0
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 7
|
||||
call String.new 1
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
push constant 12
|
||||
call String.new 1
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 120
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push constant 0
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push static 2
|
||||
pop local 12
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push local 12
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 240
|
||||
add
|
||||
push local 4
|
||||
push local 5
|
||||
push constant 240
|
||||
add
|
||||
push local 6
|
||||
push local 7
|
||||
push constant 240
|
||||
add
|
||||
push local 8
|
||||
push local 9
|
||||
push constant 240
|
||||
add
|
||||
push local 10
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 0
|
||||
push local 0
|
||||
call Piece.draw 1
|
||||
not
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Tetris.finish 0
|
||||
not
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE1
|
||||
label IF_FALSE0
|
||||
push static 2
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 16
|
||||
add
|
||||
push local 4
|
||||
push constant 32
|
||||
add
|
||||
push local 5
|
||||
push constant 16
|
||||
add
|
||||
push local 6
|
||||
push constant 32
|
||||
add
|
||||
push local 7
|
||||
push constant 16
|
||||
add
|
||||
push local 8
|
||||
push constant 32
|
||||
add
|
||||
push local 9
|
||||
push constant 16
|
||||
add
|
||||
push local 10
|
||||
push constant 32
|
||||
add
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 1
|
||||
push local 1
|
||||
call Piece.draw 1
|
||||
pop temp 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
call Piece.getMove 1
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 15
|
||||
label WHILE_EXP2
|
||||
push local 15
|
||||
push constant 3
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
call Keyboard.keyPressed 0
|
||||
pop local 11
|
||||
push local 11
|
||||
push constant 130
|
||||
eq
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
call Piece.moveLeft 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE2
|
||||
push local 11
|
||||
push constant 132
|
||||
eq
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 0
|
||||
call Piece.moveRight 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE3
|
||||
push local 11
|
||||
push constant 131
|
||||
eq
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push local 0
|
||||
call Piece.rotate 1
|
||||
pop temp 0
|
||||
label IF_FALSE4
|
||||
push local 11
|
||||
push constant 133
|
||||
eq
|
||||
if-goto IF_TRUE5
|
||||
goto IF_FALSE5
|
||||
label IF_TRUE5
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
label IF_FALSE5
|
||||
push local 15
|
||||
push constant 1
|
||||
add
|
||||
pop local 15
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push constant 0
|
||||
pop local 2
|
||||
push local 0
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
call Tetris.completeRow 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
push constant 7
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 16
|
||||
push constant 32
|
||||
push constant 80
|
||||
push constant 96
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
not
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.completeRow 4
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 0
|
||||
push constant 15
|
||||
pop local 1
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
not
|
||||
pop local 3
|
||||
push constant 0
|
||||
pop local 2
|
||||
label WHILE_EXP1
|
||||
push local 2
|
||||
push constant 10
|
||||
lt
|
||||
push local 3
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
push local 1
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
add
|
||||
call Memory.peek 1
|
||||
push local 3
|
||||
and
|
||||
pop local 3
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push local 3
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 176
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 335
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 15
|
||||
add
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push static 0
|
||||
push constant 1
|
||||
add
|
||||
pop static 0
|
||||
push local 1
|
||||
call Tetris.shift 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push local 1
|
||||
push constant 1
|
||||
sub
|
||||
pop local 1
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.shift 5
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 2
|
||||
label WHILE_EXP0
|
||||
push argument 0
|
||||
push constant 1
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
pop local 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push constant 10
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 4
|
||||
label WHILE_EXP2
|
||||
push local 4
|
||||
push constant 16
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
call Memory.peek 1
|
||||
pop local 1
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
push local 1
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 3
|
||||
push constant 0
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 4
|
||||
push constant 1
|
||||
add
|
||||
pop local 4
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
pop argument 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.border 0
|
||||
push constant 175
|
||||
push constant 0
|
||||
push constant 175
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 336
|
||||
push constant 0
|
||||
push constant 336
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.newPiece 1
|
||||
push constant 9
|
||||
call Array.new 1
|
||||
pop local 0
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push argument 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 0
|
||||
add
|
||||
push argument 2
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 0
|
||||
add
|
||||
push argument 3
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 0
|
||||
add
|
||||
push argument 4
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 0
|
||||
add
|
||||
push argument 5
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 0
|
||||
add
|
||||
push argument 6
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 7
|
||||
push local 0
|
||||
add
|
||||
push argument 7
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 8
|
||||
push local 0
|
||||
add
|
||||
push argument 8
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
return
|
||||
function Tetris.randomNumber 4
|
||||
push constant 7
|
||||
pop local 0
|
||||
push constant 13
|
||||
pop local 1
|
||||
push constant 1133
|
||||
pop local 2
|
||||
push local 0
|
||||
push static 1
|
||||
call Math.multiply 2
|
||||
push local 1
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
push local 2
|
||||
call Tetris.mod 2
|
||||
pop static 1
|
||||
push static 1
|
||||
push constant 7
|
||||
call Tetris.mod 2
|
||||
return
|
||||
function Tetris.finish 1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 24
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 12
|
||||
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 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 10000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 63
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
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 105
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
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 112
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 103
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 44
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 89
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
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 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
call Keyboard.readChar 0
|
||||
pop local 0
|
||||
push local 0
|
||||
push constant 89
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push local 0
|
||||
push constant 78
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
call Sys.halt 0
|
||||
pop temp 0
|
||||
label IF_FALSE1
|
||||
push constant 0
|
||||
not
|
||||
return
|
||||
function Tetris.mod 2
|
||||
push argument 0
|
||||
push argument 1
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push argument 1
|
||||
call Math.divide 2
|
||||
push argument 1
|
||||
call Math.multiply 2
|
||||
pop local 1
|
||||
push argument 0
|
||||
push local 1
|
||||
sub
|
||||
pop local 0
|
||||
push local 0
|
||||
return
|
||||
@@ -0,0 +1,19 @@
|
||||
class Main {
|
||||
function void main (){
|
||||
var int s;
|
||||
let s = -1;
|
||||
do Output.moveCursor(0,20);
|
||||
do Output.printString("Welcome to Tetris");
|
||||
do Sys.wait(2000);
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
while ((s < 0) | (s > 100)){ // gets a number used for seed for the random function
|
||||
let s = Keyboard.readInt("Enter a number between 0 and 100:");
|
||||
do Screen.clearScreen();
|
||||
}
|
||||
do Sys.wait(2000);
|
||||
do Tetris.tetris(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,473 @@
|
||||
class Piece {
|
||||
static int lBorder, rBorder, uBorder, dBorder, st;
|
||||
field int x1, y1, x2, y2, x3, y3, x4, y4, piece, direction;
|
||||
field bool move;
|
||||
static Array st;
|
||||
|
||||
constructor Piece new(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4, int p) {
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
let piece = p;
|
||||
let direction = 0;
|
||||
let move = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
function void init(){
|
||||
var int a;
|
||||
let lBorder = 0;
|
||||
let rBorder = 511;
|
||||
let uBorder = 0;
|
||||
let dBorder = 255;
|
||||
let st = Array.new(16);
|
||||
let st[0] = 1;
|
||||
while (a < 15){
|
||||
let a = a + 1;
|
||||
let st[a] = st[a - 1] + st[a - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
method void dispose() {
|
||||
do Memory.deAlloc(this);
|
||||
return;
|
||||
}
|
||||
|
||||
/** draws 2 rectangles also checks if there is a piece at the spawn which will indicate end of the game. */
|
||||
method bool draw() {
|
||||
var bool finish;
|
||||
let finish = true;
|
||||
let finish = Piece.sample(x1,y1) & finish;
|
||||
let finish = Piece.sample(x2,y2) & finish;
|
||||
let finish = Piece.sample(x3,y3) & finish;
|
||||
let finish = Piece.sample(x4,y4) & finish;
|
||||
if (finish){
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Erases the square from the screen. */
|
||||
method void erase() {
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
/** checks if those coodinates hold any value > 0. */
|
||||
function bool sample(int x, int y){
|
||||
var int value, address, bit, memBlock;
|
||||
let memBlock = x / 16;
|
||||
let address = (32 * y) + memBlock + 16384;
|
||||
if (address > 24576){
|
||||
return false;
|
||||
}
|
||||
let value = Memory.peek(address);
|
||||
if (value = 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
method bool getMove(){
|
||||
return move;
|
||||
}
|
||||
|
||||
/** Checks if the piece can move in the given direction(dir). */
|
||||
method bool fullSample(int dir){
|
||||
var int size1, size2, i, j;
|
||||
var bool result, flagUpon;
|
||||
if (dir = 1){ //down
|
||||
let size1 = x2 - x1;
|
||||
let size2 = x4 - x3;
|
||||
let result = true;
|
||||
while (i < size1){ // for each block of the first rectangle
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){ // for each block of the second rectangle
|
||||
if ((x1 + i) = (x3 + j)){ // if this block of the first rectangle sits upon a block of the second rectangle
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x3 + j, y4 + 1); // if there is a block under the second rectangle
|
||||
let j = j + 16; // sets the coords for the next block of the second rectangle
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x1 + i, y2 + 1); // if there is a block under the first rectangle
|
||||
}
|
||||
let i = i + 16; // sets the coords for the next block of the firs rectangle
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{
|
||||
if (dir = 2){ //right
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size1){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){
|
||||
if ((y1 + i) = (y3 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x4 + 1, (y3 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x2 + 1, (y1 + i));
|
||||
}
|
||||
let i = i +16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{ // left
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size2){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size1){
|
||||
if ((y3 + i) = (y1 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x1 - 1, (y1 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x3 - 1, (y3 + i));
|
||||
}
|
||||
let i = i + 16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels down. */
|
||||
method void moveDown() {
|
||||
var int i;
|
||||
if ((y2 < dBorder) & (y4 < dBorder) & (move) & fullSample(1)) {
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y1);
|
||||
do Screen.drawRectangle(x3, y3, x4, y3);
|
||||
let y1 = y1 + 1;
|
||||
let y2 = y2 + 1;
|
||||
let y3 = y3 + 1;
|
||||
let y4 = y4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y4, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
else{
|
||||
let move = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the left. */
|
||||
method void moveLeft() {
|
||||
var int i;
|
||||
if ((x1 + 15 > lBorder) & (move) & (x3 + 15 > lBorder)& fullSample(0)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x2, y1, x2, y2);
|
||||
do Screen.drawRectangle(x4, y3, x4, y4);
|
||||
let x1 = x1 - 1;
|
||||
let x2 = x2 - 1;
|
||||
let x3 = x3 - 1;
|
||||
let x4 = x4 - 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the right. */
|
||||
method void moveRight() {
|
||||
var int i;
|
||||
if ((x4 < rBorder) & (move) & (x2 < rBorder) & fullSample(2)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x1, y2);
|
||||
do Screen.drawRectangle(x3, y3, x3, y4);
|
||||
let x1 = x1 + 1;
|
||||
let x2 = x2 + 1;
|
||||
let x3 = x3 + 1;
|
||||
let x4 = x4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Deletes the piece and draws it at the new coodinates. */
|
||||
method void reDraw(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4){
|
||||
var int absTmp;
|
||||
if((Ax1 < 175) | (Ax3 < 175) | (Ax2 > 336) | (Ax4 > 336)){
|
||||
return;
|
||||
}
|
||||
if((Ay2 > 255) | (Ay4 > 255) | (Ay1 < 0) | (Ay3 < 0)){
|
||||
return;
|
||||
}
|
||||
if((Ax1 > Ax2) | (Ax3 > Ax4) | (Ay1 > Ay2) | (Ay3 > Ay4)){
|
||||
return;
|
||||
}
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
do Screen.setColor(true);
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Rotates the piece clockwise. */
|
||||
method void rotate(){
|
||||
var bool samp;
|
||||
let samp = true;
|
||||
if (direction = 0){ // starting position
|
||||
if (piece = 0){ // arrow
|
||||
let samp = Piece.sample(x4, y1) & samp; // checks if the place at which the new piece will be drawn are free
|
||||
let samp = Piece.sample(x4, y1 - 1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2, y2, x4 - 15, y4 - 47, x4, y4); // redraws it at the new location
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 + 16, y1) & samp;
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4, y1 - 16) & samp;
|
||||
if(samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x4 - 16, y4, x4 - 15, y1 - 16, x4, y1 - 1);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 16, y2 + 16, x3 + 32, y3, x4, y4);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3 + 16, y3 - 32) & samp;
|
||||
let samp = Piece.sample(x4, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1, x2, y2 + 16, x3 + 16, y3 - 32, x4, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 + 32, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3 + 32, y3 - 32, x4 + 16, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 32, y1 - 32) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 - 32, x2 + 16, y2 - 16, x3, y3, x4 - 16, y4 + 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 1){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y3) & samp;
|
||||
let samp = Piece.sample(x1 - 1, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y3, x4, y3 + 15, x1, y1, x2, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x4, y4 + 16, x3, y3 + 32, x4, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 32, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x2 + 16, y2 - 16, x3 - 32, y3, x4 - 32, y4);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
let samp = Piece.sample(x4, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1, x2, y2 - 16, x3 - 16, y3 +32, x4, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 32, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3 - 32, y3 + 32, x4 - 16, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 32, y1 + 16, x2 - 16, y2, x3, y3 - 16, x4 + 16, y4 - 32);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 2){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y1+16) & samp;
|
||||
let samp = Piece.sample(x1, y1+32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x1 + 15, y1 + 47, x3, y3, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 + 16, x1 + 15, y1 + 31, x1 + 16, y1 - 16, x4 - 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2 - 32, y2 - 16, x3 + 16, y3 - 32, x4 + 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x2 - 16, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3, y3 - 32, x4 - 16, y4 - 16);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 - 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 32, y2, x3 + 16, y3 - 16, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 32, y4 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x2, y2, x3 - 16, y3 + 16, x4 - 32, y4 + 32);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x3, y3, x4, y4, x1, y1 + 32, x1 + 47, y1 + 47);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2, y2 -16, x1, y1, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 + 32, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 + 16, x2 + 32, y2 + 16, x3 - 16, y3 + 32, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3, y3 + 32, x4 + 16, y4 + 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 16, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 + 16, x2 + 32, y2, x3 - 16, y3 + 16, x4, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 32) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 32, x2, y2 + 16, x3 + 16, y3, x4 + 32, y4 - 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
class Tetris {
|
||||
static int points, seed, next_seed;
|
||||
|
||||
function void tetris(int z){
|
||||
var Piece p, nextPiece;
|
||||
var int i, x1, y1, x2, y2, x3, y3, x4, y4, key, j, randTmp, piece_number, moves;
|
||||
var Array left_g, right_g, box, stick, left_z, right_z,dick, all_piece, tmp;
|
||||
do Piece.init();
|
||||
do Tetris.border();
|
||||
let points = 0;
|
||||
let all_piece = Array.new(25);
|
||||
let all_piece[0] = Tetris.newPiece(16,0,31,15, 0,16,47,31, 0); // arrow
|
||||
let all_piece[1] = Tetris.newPiece(0,0,15,15, 0,16,47,31, 1); // right_L
|
||||
let all_piece[2] = Tetris.newPiece(32,16,47,31, 0,32,47,47, 2); // left_L
|
||||
let all_piece[3] = Tetris.newPiece(0,0,31,15, 16,16,47,31, 3); // left_z
|
||||
let all_piece[4] = Tetris.newPiece(16,0,47,15, 0,16,31,31, 4); // right_z
|
||||
let all_piece[5] = Tetris.newPiece(0,0,31,15, 32,0,63,15, 5); //stick
|
||||
let all_piece[6] = Tetris.newPiece(0,0,15,31, 16,0,31,31, 6); //box
|
||||
|
||||
|
||||
let seed = z * 3; // multiply by 3, because it gets in a loop on some even numbers
|
||||
let next_seed = Tetris.randomNumber();
|
||||
do Output.moveCursor(0,0);
|
||||
do Output.printString("Point: ");
|
||||
do Output.printInt(points);
|
||||
do Output.println();
|
||||
do Output.printString("Next Piece: ");
|
||||
while (true){ // The main game loop
|
||||
let j = next_seed;
|
||||
let next_seed = Tetris.randomNumber();
|
||||
let tmp = all_piece[j]; // initializes the coords of the game piece
|
||||
let x1 = tmp[0];
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let p = Piece.new(x1 + 240, y1, x2 + 240, y2, x3 + 240, y3, x4 + 240, y4, piece_number);
|
||||
if (~(p.draw())){ // if a piece tries to spawn above a limit the game ends
|
||||
if (~(Tetris.finish())){
|
||||
return;
|
||||
}
|
||||
}
|
||||
let tmp = all_piece[next_seed];
|
||||
let x1 = tmp[0]; // initializes the coords of the next game piece that is being displayed
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let nextPiece = Piece.new(x1 + 16, y1 + 32, x2+16, y2 + 32, x3+16, y3 + 32, x4 + 16, y4 + 32, piece_number);
|
||||
do nextPiece.draw();
|
||||
while (p.getMove()){
|
||||
let moves = 0;
|
||||
while (moves < 3){ // one can move its piece 3 times before it moves down automatically
|
||||
let key = Keyboard.keyPressed();
|
||||
if (key = 130){
|
||||
do p.moveLeft();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 132){
|
||||
do p.moveRight();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 131){
|
||||
do p.rotate();
|
||||
}
|
||||
if (key = 133){
|
||||
do p.moveDown();
|
||||
do p.moveDown();
|
||||
}
|
||||
let moves = moves +1;
|
||||
}
|
||||
do p.moveDown();
|
||||
let i = i + 1;
|
||||
do Sys.wait(80);
|
||||
}
|
||||
let i = 0;
|
||||
do p.dispose();
|
||||
do Tetris.completeRow();
|
||||
do Output.moveCursor(0,7);
|
||||
do Output.printInt(points);
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(16,32,80,96);
|
||||
do Screen.setColor(true);
|
||||
do nextPiece.dispose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void completeRow(){ // checks if a row has been completed
|
||||
var int adddress, row, colloum;
|
||||
var bool complete;
|
||||
let adddress = 16384 + 11;
|
||||
let row = 15;
|
||||
while (row > 0){ // for each row
|
||||
let complete = true;
|
||||
let colloum = 0;
|
||||
while ((colloum < 10) & (complete)){ // for each collum
|
||||
let complete = Memory.peek(adddress + colloum + (row * 512)) & complete;
|
||||
let colloum = colloum + 1;
|
||||
}
|
||||
if (complete){ // removes the row
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(176, row * 16, 335, ((row * 16)+ 15) );
|
||||
let points = points + 1;
|
||||
do Tetris.shift(row);
|
||||
}
|
||||
let row = row - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void shift(int rowShift){ // shifts all rows above the completed one
|
||||
var int j, val, adddress, tmp, k;
|
||||
let adddress = 16384 + 11;
|
||||
while (rowShift > 1){ // each row
|
||||
let j = 0;
|
||||
while (j < 10){ // collum in the game field
|
||||
let k = 0;
|
||||
while (k < 16){ // each line a in 16 x 16 box
|
||||
let tmp = adddress + j + (((rowShift - 1) * 512) + (k * 32));
|
||||
let val = Memory.peek(tmp);
|
||||
do Memory.poke(adddress + j + ((rowShift * 512) + (k * 32)), val);
|
||||
do Memory.poke(tmp,0);
|
||||
let k = k+ 1;
|
||||
}
|
||||
let j = j + 1;
|
||||
}
|
||||
let rowShift = rowShift - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void border(){ // draws a border
|
||||
do Screen.drawLine(175,0,175,255);
|
||||
do Screen.drawLine(336,0,336,255);
|
||||
return;
|
||||
}
|
||||
|
||||
function Array newPiece(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4,int p){
|
||||
var Array gamepice;
|
||||
let gamepice = Array.new(9);
|
||||
let gamepice[0] = Ax1;
|
||||
let gamepice[1] = Ay1;
|
||||
let gamepice[2] = Ax2;
|
||||
let gamepice[3] = Ay2;
|
||||
let gamepice[4] = Ax3;
|
||||
let gamepice[5] = Ay3;
|
||||
let gamepice[6] = Ax4;
|
||||
let gamepice[7] = Ay4;
|
||||
let gamepice[8] = p;
|
||||
return gamepice;
|
||||
}
|
||||
|
||||
function int randomNumber(){ // radom number generator
|
||||
var int multiplier,additor,moduler,toBeModulated;
|
||||
let multiplier = 7;
|
||||
let additor = 13;
|
||||
let moduler = 1133;
|
||||
let toBeModulated = (multiplier * seed) + additor;
|
||||
let seed = Tetris.mod(toBeModulated,moduler);
|
||||
return Tetris.mod(seed,7);
|
||||
}
|
||||
|
||||
function bool finish(){ // after finishing the game the player has 2 options to start onether or to end the game
|
||||
var char c;
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,24);
|
||||
do Output.printString("Your score: ");
|
||||
do Output.printInt(points);
|
||||
do Sys.wait(10000);
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,0);
|
||||
do Output.printString("Would you like to play again, for yes click 'Y' and for no 'N':");
|
||||
let c = Keyboard.readChar();
|
||||
if (c = 89){
|
||||
do Screen.clearScreen();
|
||||
return false;
|
||||
}
|
||||
if (c = 78){
|
||||
do Screen.clearScreen();
|
||||
do Sys.halt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function int mod(int tbm, int mo){ //simple moduler devision
|
||||
var int val, tmp2;
|
||||
if (tbm < mo){
|
||||
return tbm;
|
||||
}
|
||||
let tmp2 = (tbm / mo) * mo;
|
||||
let val = tbm - tmp2;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: Assembler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%2"=="" goto :USAGE
|
||||
if "%~1"=="/?" (
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo Assembler Starts the assembler in interactive mode.
|
||||
echo Assembler FILE[.asm] Assembles FILE.asm to FILE.hack.
|
||||
exit -b
|
||||
)
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
if "%~1"=="" (
|
||||
start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
|
||||
HackAssemblerMain
|
||||
) else (
|
||||
echo Assembling "%_arg1%"
|
||||
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
|
||||
HackAssemblerMain "%_arg1%"
|
||||
)
|
||||
popd
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: Assembler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` Starts the assembler in interactive mode."
|
||||
echo " `basename "$0"` FILE[.asm] Assembles FILE.asm to FILE.hack."
|
||||
elif [ $# -eq 0 ]
|
||||
then
|
||||
# Run assembler in interactive mode
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain &
|
||||
else
|
||||
# Convert arg1 to an absolute path and run assembler with arg1.
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="${dir}/$1"
|
||||
fi
|
||||
echo Assembling "$arg1"
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain "$arg1"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: CPUEmulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%2"=="" goto :USAGE
|
||||
if "%~1"=="/?" (
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo CPUEmulator Starts the CPU Emulator in interactive mode.
|
||||
echo CPUEmulator FILE.tst Starts the CPU Emulator and runs the FILE.tst
|
||||
echo test script. The success/failure message
|
||||
echo is printed to the command console.
|
||||
exit -b
|
||||
)
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
if "%~1"=="" (
|
||||
start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
CPUEmulatorMain
|
||||
) else (
|
||||
rem echo Running "%_arg1%"
|
||||
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
CPUEmulatorMain "%_arg1%"
|
||||
)
|
||||
popd
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: CPUEmulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` Starts the CPU Emulator in interactive mode."
|
||||
echo " `basename "$0"` FILE.tst Starts the CPU Emulator and runs the File.tst"
|
||||
echo " test script. The success/failure message"
|
||||
echo " is printed to the command console."
|
||||
elif [ $# -eq 0 ]
|
||||
then
|
||||
# Run CPU emulator in interactive mode
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain &
|
||||
else
|
||||
# Convert arg1 to an absolute path and run CPU emulator with arg1
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="${dir}/$1"
|
||||
fi
|
||||
# echo Running "$arg1"
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain "$arg1"
|
||||
fi
|
||||
@@ -0,0 +1,30 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: HardwareSimulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%2"=="" goto :USAGE
|
||||
if "%~1"=="/?" (
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo HardwareSimulator Starts the Hardware Simulator in
|
||||
echo interactive mode.
|
||||
echo HardwareSimulator FILE.tst Starts the Hardware Simulator and runs the
|
||||
echo FILE.tst test script. The success/failure
|
||||
echo message is printed to the command console.
|
||||
exit -b
|
||||
)
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
if "%~1"=="" (
|
||||
start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
HardwareSimulatorMain
|
||||
) else (
|
||||
rem echo Running "%_arg1%"
|
||||
java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
HardwareSimulatorMain "%_arg1%"
|
||||
)
|
||||
popd
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: HardwareSimulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` Starts the Hardware Simulator in"
|
||||
echo " interactive mode."
|
||||
echo " `basename "$0"` FILE.tst Starts the Hardware Simulator and runs the"
|
||||
echo " FILE.tst test script. The success/failure"
|
||||
echo " message is printed to the command console."
|
||||
elif [ $# -eq 0 ]
|
||||
then
|
||||
# Run hardware simulator in interactive mode
|
||||
java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain &
|
||||
else
|
||||
# Convert arg1 to an absolute path and run hardware simulator with arg1
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="${dir}/$1"
|
||||
fi
|
||||
# echo Running "$arg1"
|
||||
java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain "$arg1"
|
||||
fi
|
||||
@@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: JackCompiler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%2"=="" goto :USAGE
|
||||
if "%~1"=="/?" (
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo JackCompiler Compiles all .jack files in the current
|
||||
echo working directory.
|
||||
echo JackCompiler DIRECTORY Compiles all .jack files in DIRECTORY.
|
||||
echo JackCompiler FILE.jack Compiles FILE.jack to FILE.vm.
|
||||
exit -b
|
||||
)
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
) else (
|
||||
set "_arg1=%CD%"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
echo Compiling "%_arg1%"
|
||||
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/Compilers.jar" ^
|
||||
Hack.Compiler.JackCompiler "%_arg1%"
|
||||
popd
|
||||
@@ -0,0 +1,350 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from tokenizer import Tokenizer
|
||||
from vmwriter import VMWriter
|
||||
from symbol_table import SymbolTable
|
||||
|
||||
|
||||
# TODO add names to variables when you call for them, aka current_vm_append(thingtobeappended=blablac)
|
||||
|
||||
class CompilationEngine:
|
||||
def __init__(self, tokenizer, full_path_vm):
|
||||
self.string = self.sub_type = self.class_name = self.function_type = ''
|
||||
self.tab = self.recursion_index = 0
|
||||
self.tokenizer = tokenizer
|
||||
self.sym_table = []
|
||||
self.vmwriter = VMWriter(full_path_vm)
|
||||
self.current_vm = [] # used to reverse some of the commands, eg a+b need to be a b +
|
||||
|
||||
def search_kind_of_sym(self, current_vm):
|
||||
if self.sym_table[-1].kind_of(current_vm) is not None:
|
||||
return self.sym_table[-1].kind_of(current_vm), self.sym_table[-1].index_of(current_vm)
|
||||
for i in range(len(self.sym_table) - 2, -1,
|
||||
-1): # start from the amount of sym_tables -2 so it starts from one below the current,
|
||||
# until it is bigger than -1, walking it backwards
|
||||
if self.sym_table[i].kind_of(current_vm) in ('static', 'this'):
|
||||
return self.sym_table[i].kind_of(current_vm), self.sym_table[i].index_of(current_vm)
|
||||
|
||||
def search_type_of_sym(self, current_vm):
|
||||
for i in range(len(self.sym_table) - 1, -1, -1):
|
||||
if self.sym_table[i].type_of(current_vm) is not None:
|
||||
return self.sym_table[i].type_of(current_vm)
|
||||
|
||||
def write_token(self):
|
||||
if self.tokenizer.token_type() == 'stringConstant':
|
||||
self.string += ' ' * self.tab + '<' + self.tokenizer.token_type() + '> ' + self.tokenizer.token.strip(
|
||||
'"') + ' </' + self.tokenizer.token_type() + '>\n'
|
||||
else:
|
||||
self.string += ' ' * self.tab + '<' + self.tokenizer.token_type() + '> ' + self.tokenizer.token + ' </' \
|
||||
+ self.tokenizer.token_type() + '>\n'
|
||||
|
||||
def compile_class(self):
|
||||
self.sym_table.append(SymbolTable())
|
||||
self.tokenizer.advance() # class ->
|
||||
self.tokenizer.advance() # type ->
|
||||
self.class_name = self.tokenizer.token
|
||||
self.tokenizer.advance() # name ->
|
||||
self.tokenizer.advance() # { ->
|
||||
while self.tokenizer.token != '}':
|
||||
if self.tokenizer.token in ['static', 'field']:
|
||||
self.compile_class_var_dec()
|
||||
if self.tokenizer.token in ['constructor', 'function', 'method']:
|
||||
self.compile_subroutine()
|
||||
self.tokenizer.advance()
|
||||
self.sym_table.pop()
|
||||
self.vmwriter.close_vm_file()
|
||||
|
||||
def compile_class_var_dec(self):
|
||||
var_kind = tokenizer_main.token
|
||||
self.tokenizer.advance()
|
||||
var_type = tokenizer_main.token
|
||||
self.tokenizer.advance()
|
||||
var_name = tokenizer_main.token
|
||||
self.sym_table[-1].define(var_name, var_type, var_kind)
|
||||
self.tokenizer.advance()
|
||||
while self.tokenizer.token == ',':
|
||||
self.tokenizer.advance()
|
||||
var_name = tokenizer_main.token
|
||||
self.sym_table[-1].define(var_name, var_type, var_kind)
|
||||
self.tokenizer.advance()
|
||||
self.tokenizer.advance()
|
||||
|
||||
def compile_subroutine(self):
|
||||
self.sym_table.append(SymbolTable())
|
||||
self.sub_type = self.tokenizer.token
|
||||
self.tokenizer.advance() # subroutine type(function|method|constructor) ->
|
||||
self.function_type = self.tokenizer.token
|
||||
self.tokenizer.advance() # subroutine kind(int|void|etc..) ->
|
||||
sub_name = self.tokenizer.token
|
||||
self.tokenizer.advance() # subroutine name ->
|
||||
self.tokenizer.advance() # ( ->
|
||||
if self.sub_type == 'method':
|
||||
self.sym_table[-1].start_subroutine('this', self.class_name)
|
||||
self.compile_parameter_list()
|
||||
self.tokenizer.advance() # { ->
|
||||
while self.tokenizer.token == 'var': # create only symbol teable entries
|
||||
self.compile_var_dec()
|
||||
if self.sub_type == 'constructor':
|
||||
self.vmwriter.write_function(f'{self.class_name}.{sub_name}', self.sym_table[-1].var_count('var'))
|
||||
self.vmwriter.write_push('constant', self.sym_table[-2].var_count('field'))
|
||||
self.vmwriter.write_call('Memory.alloc', 1)
|
||||
self.vmwriter.write_pop('pointer', 0)
|
||||
elif self.sub_type == 'method':
|
||||
self.vmwriter.write_function(f'{self.class_name}.{sub_name}', self.sym_table[-1].var_count('var'))
|
||||
self.vmwriter.write_push('argument', 0)
|
||||
self.vmwriter.write_pop('pointer', 0)
|
||||
else:
|
||||
self.vmwriter.write_function(f'{self.class_name}.{sub_name}', self.sym_table[-1].var_count('var'))
|
||||
while self.tokenizer.token != '}':
|
||||
self.compile_statements()
|
||||
self.tokenizer.advance()
|
||||
self.sym_table.pop()
|
||||
|
||||
def compile_parameter_list(self):
|
||||
if self.tokenizer.token != ')':
|
||||
var_type = self.tokenizer.token
|
||||
self.tokenizer.advance() # var ype ->
|
||||
var_name = self.tokenizer.token
|
||||
self.sym_table[-1].define(var_name, var_type, 'argument')
|
||||
self.tokenizer.advance() # var name ->
|
||||
while self.tokenizer.token == ',':
|
||||
self.tokenizer.advance() # , ->
|
||||
var_type = self.tokenizer.token
|
||||
self.tokenizer.advance() # type ->
|
||||
var_name = self.tokenizer.token
|
||||
self.sym_table[-1].define(var_name, var_type, 'argument')
|
||||
self.tokenizer.advance() # name ->
|
||||
self.tokenizer.advance() # )->
|
||||
|
||||
def compile_var_dec(self):
|
||||
var_kind = tokenizer_main.token
|
||||
self.tokenizer.advance()
|
||||
var_type = tokenizer_main.token
|
||||
self.tokenizer.advance()
|
||||
var_name = tokenizer_main.token
|
||||
self.sym_table[-1].define(var_name, var_type, var_kind)
|
||||
self.tokenizer.advance()
|
||||
while self.tokenizer.token == ',':
|
||||
self.tokenizer.advance()
|
||||
var_name = tokenizer_main.token
|
||||
self.sym_table[-1].define(var_name, var_type, var_kind)
|
||||
self.tokenizer.advance()
|
||||
self.tokenizer.advance()
|
||||
|
||||
def compile_statements(self):
|
||||
while True:
|
||||
if self.tokenizer.token == 'let':
|
||||
self.compile_let()
|
||||
elif self.tokenizer.token == 'if':
|
||||
self.compile_if()
|
||||
elif self.tokenizer.token == 'while':
|
||||
self.compile_while()
|
||||
elif self.tokenizer.token == 'do':
|
||||
self.compile_do()
|
||||
elif self.tokenizer.token == 'return':
|
||||
self.compile_return()
|
||||
else:
|
||||
break
|
||||
|
||||
def compile_do(self):
|
||||
self.tokenizer.advance() # do ->
|
||||
class_name = self.tokenizer.token
|
||||
self.tokenizer.advance() # name ->
|
||||
if self.tokenizer.token == '(': # method
|
||||
self.vmwriter.write_push('pointer', 0)
|
||||
self.tokenizer.advance() # ( ->
|
||||
count = self.compile_expression_list()
|
||||
self.tokenizer.advance() # ) ->
|
||||
self.vmwriter.write_call(f'{self.class_name}.{class_name}', count + 1)
|
||||
elif self.tokenizer.token == '.': # method or function
|
||||
self.tokenizer.advance() # . ->
|
||||
fname = f'{class_name}.{self.tokenizer.token}'
|
||||
sname = f'{self.search_type_of_sym(class_name)}.{self.tokenizer.token}'
|
||||
self.tokenizer.advance() # name ->
|
||||
if self.search_kind_of_sym(class_name) is not None:
|
||||
self.vmwriter.write_push(*self.search_kind_of_sym(class_name))
|
||||
self.tokenizer.advance() # ( ->
|
||||
count = self.compile_expression_list()
|
||||
self.tokenizer.advance() # ) ->
|
||||
if self.search_kind_of_sym(class_name) is not None:
|
||||
self.vmwriter.write_call(f'{sname}', count + 1)
|
||||
else:
|
||||
self.vmwriter.write_call(f'{fname}', count)
|
||||
self.vmwriter.write_pop('temp', '0')
|
||||
self.tokenizer.advance() # ; ->
|
||||
|
||||
def compile_let(self):
|
||||
flag_array = 0
|
||||
self.tokenizer.advance() # let ->
|
||||
self.current_vm.append(self.tokenizer.token)
|
||||
self.tokenizer.advance() # var_name ->
|
||||
if self.tokenizer.token == '[':
|
||||
self.vmwriter.write_push(*self.search_kind_of_sym(self.current_vm[-1]))
|
||||
self.tokenizer.advance() # [ ->
|
||||
self.compile_expression()
|
||||
self.tokenizer.advance() # ] ->
|
||||
flag_array = 1
|
||||
self.tokenizer.advance() # = ->
|
||||
self.compile_expression()
|
||||
self.tokenizer.advance() # ; ->
|
||||
if flag_array == 0:
|
||||
self.vmwriter.write_pop(*self.search_kind_of_sym(self.current_vm[-1]))
|
||||
else:
|
||||
self.vmwriter.write_pop('temp', 1)
|
||||
self.vmwriter.write_arithmetic('+')
|
||||
self.vmwriter.write_pop('pointer', 1)
|
||||
self.vmwriter.write_push('temp', 1)
|
||||
self.vmwriter.write_pop('that', 0)
|
||||
self.current_vm.pop()
|
||||
|
||||
def compile_while(self):
|
||||
self.tokenizer.advance() # while ->
|
||||
label1 = self.vmwriter.label_index
|
||||
self.vmwriter.write_lable(self.vmwriter.label_index)
|
||||
self.vmwriter.label_index += 1
|
||||
self.tokenizer.advance() # ( ->
|
||||
self.compile_expression()
|
||||
self.tokenizer.advance() # ) ->
|
||||
label2 = self.vmwriter.label_index
|
||||
self.vmwriter.write_if(self.vmwriter.label_index)
|
||||
self.vmwriter.label_index += 1
|
||||
self.tokenizer.advance() # { ->
|
||||
self.compile_statements()
|
||||
self.tokenizer.advance() # } ->
|
||||
self.vmwriter.write_goto(label1)
|
||||
self.vmwriter.write_lable(label2)
|
||||
|
||||
def compile_return(self):
|
||||
self.tokenizer.advance() # return ->
|
||||
if self.tokenizer.token != ';':
|
||||
self.compile_expression()
|
||||
self.vmwriter.write_return(self.function_type)
|
||||
self.tokenizer.advance() # ; ->
|
||||
|
||||
def compile_if(self):
|
||||
self.tokenizer.advance() # if ->
|
||||
self.tokenizer.advance() # ( ->
|
||||
self.compile_expression()
|
||||
self.tokenizer.advance() # ) ->
|
||||
label1 = self.vmwriter.label_index
|
||||
self.vmwriter.write_if(self.vmwriter.label_index)
|
||||
self.vmwriter.label_index += 1
|
||||
self.tokenizer.advance() # { ->
|
||||
self.compile_statements()
|
||||
self.tokenizer.advance() # } ->
|
||||
label2 = self.vmwriter.label_index
|
||||
self.vmwriter.write_goto(self.vmwriter.label_index)
|
||||
self.vmwriter.label_index += 1
|
||||
self.vmwriter.write_lable(label1)
|
||||
if self.tokenizer.token == 'else':
|
||||
self.tokenizer.advance() # else ->
|
||||
self.tokenizer.advance() # { ->
|
||||
self.compile_statements()
|
||||
self.tokenizer.advance() # } ->
|
||||
self.vmwriter.write_lable(label2)
|
||||
|
||||
def compile_expression(self):
|
||||
self.compile_term()
|
||||
while self.tokenizer.token in ['+', '-', '*', '/', '|', '=', '>', '<', '&']:
|
||||
self.current_vm.append(self.tokenizer.token)
|
||||
self.tokenizer.advance() # symbol ->
|
||||
self.compile_term()
|
||||
self.vmwriter.write_arithmetic(self.current_vm[-1])
|
||||
self.current_vm.pop()
|
||||
|
||||
def compile_term(self):
|
||||
if self.tokenizer.token == '(': # expression ()
|
||||
self.tokenizer.advance() # ( ->
|
||||
self.compile_expression()
|
||||
self.tokenizer.advance() # ) ->
|
||||
elif self.tokenizer.token in ['~', '-']: # uniry op
|
||||
self.current_vm.append(self.tokenizer.token)
|
||||
tmp = 'neg' if self.tokenizer.token == '-' else self.tokenizer.token
|
||||
self.tokenizer.advance() # ~ or - ->
|
||||
self.compile_term()
|
||||
self.vmwriter.write_arithmetic(tmp)
|
||||
self.current_vm.pop()
|
||||
elif self.tokenizer.token_type() != 'symbol':
|
||||
self.current_vm.append(self.tokenizer.token)
|
||||
self.tokenizer.advance() # integer, string, keyword, varnname, subroutine_name, class_name, var_name ->
|
||||
if self.tokenizer.token == '[': # Array
|
||||
self.tokenizer.advance() # [ ->
|
||||
self.vmwriter.write_push(*self.search_kind_of_sym(self.current_vm[-1]))
|
||||
self.current_vm.pop()
|
||||
self.compile_expression()
|
||||
self.vmwriter.write_arithmetic('+')
|
||||
self.vmwriter.write_pop('pointer', 1)
|
||||
self.vmwriter.write_push('that', 0)
|
||||
self.tokenizer.advance() # ] ->
|
||||
elif self.tokenizer.token == '(': # subroutine_name ()
|
||||
self.tokenizer.advance() # ( ->
|
||||
count = self.compile_expression_list()
|
||||
self.tokenizer.advance() # ) ->
|
||||
self.vmwriter.write_call(f'{self.class_name}.{self.current_vm[-1]}', count)
|
||||
self.current_vm.pop()
|
||||
elif self.tokenizer.token == '.': # method
|
||||
if self.search_type_of_sym(self.current_vm[-1]) is not None:
|
||||
flag = 1
|
||||
self.vmwriter.write_push(*self.search_kind_of_sym(self.current_vm[-1]))
|
||||
else:
|
||||
flag = 0
|
||||
self.tokenizer.advance() # . ->
|
||||
fname = self.tokenizer.token
|
||||
self.tokenizer.advance() # subroutine name ->
|
||||
self.tokenizer.advance() # ( ->
|
||||
count = self.compile_expression_list()
|
||||
self.tokenizer.advance() # ) ->
|
||||
if flag == 1:
|
||||
self.vmwriter.write_call(f'{self.search_type_of_sym(self.current_vm[-1])}.{fname}', count + 1)
|
||||
else:
|
||||
self.vmwriter.write_call(f'{self.current_vm[-1]}.{fname}', count)
|
||||
self.current_vm.pop()
|
||||
elif self.tokenizer.token_type(self.current_vm[-1]) == 'stringConstant':
|
||||
self.vmwriter.write_push('constant', len(self.current_vm[-1].strip('"')))
|
||||
self.vmwriter.write_call('String.new', 1)
|
||||
for index, item in enumerate(self.current_vm[-1].strip('"')):
|
||||
self.vmwriter.write_push('constant', ord(item))
|
||||
self.vmwriter.write_call('String.appendChar', 2)
|
||||
self.current_vm.pop()
|
||||
elif self.tokenizer.token_type(self.current_vm[-1]) == 'integerConstant':
|
||||
self.vmwriter.write_push('constant', self.current_vm[-1])
|
||||
self.current_vm.pop()
|
||||
elif self.tokenizer.token_type(self.current_vm[-1]) == 'identifier':
|
||||
self.vmwriter.write_push(*self.search_kind_of_sym(self.current_vm[-1]))
|
||||
self.current_vm.pop()
|
||||
elif self.current_vm[-1] == 'true':
|
||||
self.vmwriter.write_push('constant', '1')
|
||||
self.vmwriter.write_arithmetic('neg')
|
||||
self.current_vm.pop()
|
||||
elif self.current_vm[-1] == 'false' or self.current_vm[-1] == 'null':
|
||||
self.vmwriter.write_push('constant', '0')
|
||||
self.current_vm.pop()
|
||||
elif self.current_vm[-1] == 'this':
|
||||
self.vmwriter.write_push('pointer', '0')
|
||||
self.current_vm.pop()
|
||||
elif self.current_vm[-1] == 'that':
|
||||
self.vmwriter.write_push('pointer', '1')
|
||||
self.current_vm.pop()
|
||||
|
||||
def compile_expression_list(self):
|
||||
count_exp = 0
|
||||
if self.tokenizer.token in ['(', '~', '-'] or self.tokenizer.token_type() != 'symbol':
|
||||
count_exp += 1
|
||||
self.compile_expression()
|
||||
while self.tokenizer.token == ',':
|
||||
count_exp += 1
|
||||
self.tokenizer.advance() # ,
|
||||
self.compile_expression()
|
||||
return count_exp
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = os.getcwd()
|
||||
for root, dirs, files in os.walk(path, topdown=False):
|
||||
for name in files:
|
||||
if name[-4:] == 'jack':
|
||||
tokenizer_main = Tokenizer()
|
||||
tokenizer_main.clear_file(Path(root, name))
|
||||
full_path = Path(root, name[:-4] + 'vm')
|
||||
comp_eng_main = CompilationEngine(tokenizer_main, full_path)
|
||||
comp_eng_main.compile_class()
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: JackCompiler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` Compiles all .jack files in the current"
|
||||
echo " working directory."
|
||||
echo " `basename "$0"` DIRECTORY Compiles all .jack files in DIRECTORY."
|
||||
echo " `basename "$0"` FILE.jack Compiles FILE.jack to FILE.vm."
|
||||
else
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
# Use current directory as arg1
|
||||
arg1="$dir"
|
||||
else
|
||||
# Convert arg1 to an absolute path
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="$dir/$1"
|
||||
fi
|
||||
fi
|
||||
echo Compiling "$arg1"
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar" Hack.Compiler.JackCompiler "$arg1"
|
||||
fi
|
||||
@@ -0,0 +1,19 @@
|
||||
class Main {
|
||||
function void main (){
|
||||
var int s;
|
||||
let s = -1;
|
||||
do Output.moveCursor(0,20);
|
||||
do Output.printString("Welcome to Tetris");
|
||||
do Sys.wait(2000);
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
do Output.println();
|
||||
while ((s < 0) | (s > 100)){ // gets a number used for seed for the random function
|
||||
let s = Keyboard.readInt("Enter a number between 0 and 100:");
|
||||
do Screen.clearScreen();
|
||||
}
|
||||
do Sys.wait(2000);
|
||||
do Tetris.tetris(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
function Main.main 1
|
||||
push constant 1
|
||||
neg
|
||||
pop local 0
|
||||
push constant 0
|
||||
push constant 20
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 17
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
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 116
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 84
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 0
|
||||
lt
|
||||
push local 0
|
||||
push constant 100
|
||||
gt
|
||||
or
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 33
|
||||
call String.new 1
|
||||
push constant 69
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 109
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 98
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 119
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
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 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 49
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 48
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Keyboard.readInt 1
|
||||
pop local 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 2000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Tetris.tetris 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,23 @@
|
||||
function Array.new 0
|
||||
push argument 0
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 2
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
call Memory.alloc 1
|
||||
return
|
||||
function Array.dispose 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push pointer 0
|
||||
call Memory.deAlloc 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,102 @@
|
||||
function Keyboard.init 0
|
||||
push constant 0
|
||||
return
|
||||
function Keyboard.keyPressed 0
|
||||
push constant 24576
|
||||
call Memory.peek 1
|
||||
return
|
||||
function Keyboard.readChar 2
|
||||
push constant 0
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push constant 0
|
||||
eq
|
||||
push local 0
|
||||
push constant 0
|
||||
gt
|
||||
or
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
call Keyboard.keyPressed 0
|
||||
pop local 0
|
||||
push local 0
|
||||
push constant 0
|
||||
gt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push local 0
|
||||
pop local 1
|
||||
label IF_FALSE0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
call String.backSpace 0
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
return
|
||||
function Keyboard.readLine 5
|
||||
push constant 80
|
||||
call String.new 1
|
||||
pop local 3
|
||||
push argument 0
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
call String.newLine 0
|
||||
pop local 1
|
||||
call String.backSpace 0
|
||||
pop local 2
|
||||
label WHILE_EXP0
|
||||
push local 4
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
call Keyboard.readChar 0
|
||||
pop local 0
|
||||
push local 0
|
||||
push local 1
|
||||
eq
|
||||
pop local 4
|
||||
push local 4
|
||||
not
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push local 0
|
||||
push local 2
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 3
|
||||
call String.eraseLastChar 1
|
||||
pop temp 0
|
||||
goto IF_END1
|
||||
label IF_FALSE1
|
||||
push local 3
|
||||
push local 0
|
||||
call String.appendChar 2
|
||||
pop local 3
|
||||
label IF_END1
|
||||
label IF_FALSE0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 3
|
||||
return
|
||||
function Keyboard.readInt 2
|
||||
push argument 0
|
||||
call Keyboard.readLine 1
|
||||
pop local 0
|
||||
push local 0
|
||||
call String.intValue 1
|
||||
pop local 1
|
||||
push local 0
|
||||
call String.dispose 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
return
|
||||
@@ -0,0 +1,408 @@
|
||||
function Math.init 1
|
||||
push constant 16
|
||||
call Array.new 1
|
||||
pop static 1
|
||||
push constant 16
|
||||
call Array.new 1
|
||||
pop static 0
|
||||
push constant 0
|
||||
push static 0
|
||||
add
|
||||
push constant 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 15
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
push local 0
|
||||
push static 0
|
||||
add
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Math.abs 0
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
neg
|
||||
pop argument 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
return
|
||||
function Math.multiply 5
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
push argument 1
|
||||
push constant 0
|
||||
gt
|
||||
and
|
||||
push argument 0
|
||||
push constant 0
|
||||
gt
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
and
|
||||
or
|
||||
pop local 4
|
||||
push argument 0
|
||||
call Math.abs 1
|
||||
pop argument 0
|
||||
push argument 1
|
||||
call Math.abs 1
|
||||
pop argument 1
|
||||
push argument 0
|
||||
push argument 1
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
pop local 1
|
||||
push argument 1
|
||||
pop argument 0
|
||||
push local 1
|
||||
pop argument 1
|
||||
label IF_FALSE0
|
||||
label WHILE_EXP0
|
||||
push local 2
|
||||
push constant 1
|
||||
sub
|
||||
push argument 1
|
||||
push constant 1
|
||||
sub
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 3
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 1
|
||||
and
|
||||
push constant 0
|
||||
eq
|
||||
not
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 0
|
||||
push argument 0
|
||||
add
|
||||
pop local 0
|
||||
push local 2
|
||||
push local 3
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop local 2
|
||||
label IF_FALSE1
|
||||
push argument 0
|
||||
push argument 0
|
||||
add
|
||||
pop argument 0
|
||||
push local 3
|
||||
push constant 1
|
||||
add
|
||||
pop local 3
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 4
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
neg
|
||||
pop local 0
|
||||
label IF_FALSE2
|
||||
push local 0
|
||||
return
|
||||
function Math.divide 4
|
||||
push argument 1
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 3
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
push argument 1
|
||||
push constant 0
|
||||
gt
|
||||
and
|
||||
push argument 0
|
||||
push constant 0
|
||||
gt
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
and
|
||||
or
|
||||
pop local 2
|
||||
push constant 0
|
||||
push static 1
|
||||
add
|
||||
push argument 1
|
||||
call Math.abs 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push argument 0
|
||||
call Math.abs 1
|
||||
pop argument 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 15
|
||||
lt
|
||||
push local 3
|
||||
not
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 32767
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
sub
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
lt
|
||||
pop local 3
|
||||
push local 3
|
||||
not
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
push static 1
|
||||
add
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
gt
|
||||
pop local 3
|
||||
push local 3
|
||||
not
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label IF_FALSE2
|
||||
label IF_FALSE1
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push constant 1
|
||||
neg
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
gt
|
||||
not
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 1
|
||||
push local 0
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop local 1
|
||||
push argument 0
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
sub
|
||||
pop argument 0
|
||||
label IF_FALSE3
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push local 2
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push local 1
|
||||
neg
|
||||
pop local 1
|
||||
label IF_FALSE4
|
||||
push local 1
|
||||
return
|
||||
function Math.sqrt 4
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 4
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push constant 7
|
||||
pop local 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 1
|
||||
neg
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 3
|
||||
push local 0
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop local 1
|
||||
push local 1
|
||||
push local 1
|
||||
call Math.multiply 2
|
||||
pop local 2
|
||||
push local 2
|
||||
push argument 0
|
||||
gt
|
||||
not
|
||||
push local 2
|
||||
push constant 0
|
||||
lt
|
||||
not
|
||||
and
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 1
|
||||
pop local 3
|
||||
label IF_FALSE1
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 3
|
||||
return
|
||||
function Math.max 0
|
||||
push argument 0
|
||||
push argument 1
|
||||
gt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
pop argument 1
|
||||
label IF_FALSE0
|
||||
push argument 1
|
||||
return
|
||||
function Math.min 0
|
||||
push argument 0
|
||||
push argument 1
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
pop argument 1
|
||||
label IF_FALSE0
|
||||
push argument 1
|
||||
return
|
||||
@@ -0,0 +1,376 @@
|
||||
function Memory.init 0
|
||||
push constant 0
|
||||
pop static 0
|
||||
push constant 2048
|
||||
push static 0
|
||||
add
|
||||
push constant 14334
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2049
|
||||
push static 0
|
||||
add
|
||||
push constant 2050
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 0
|
||||
return
|
||||
function Memory.peek 0
|
||||
push argument 0
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
return
|
||||
function Memory.poke 0
|
||||
push argument 0
|
||||
push static 0
|
||||
add
|
||||
push argument 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 0
|
||||
return
|
||||
function Memory.alloc 2
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 5
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 1
|
||||
pop argument 0
|
||||
label IF_FALSE1
|
||||
push constant 2048
|
||||
pop local 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 16383
|
||||
lt
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 0
|
||||
lt
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 1
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 0
|
||||
eq
|
||||
push local 1
|
||||
push constant 16382
|
||||
gt
|
||||
or
|
||||
push constant 0
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 0
|
||||
eq
|
||||
or
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 1
|
||||
pop local 0
|
||||
goto IF_END2
|
||||
label IF_FALSE2
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
sub
|
||||
push constant 0
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 1
|
||||
push constant 2
|
||||
add
|
||||
eq
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push local 0
|
||||
push constant 2
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto IF_END3
|
||||
label IF_FALSE3
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label IF_END3
|
||||
label IF_END2
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 0
|
||||
push argument 0
|
||||
add
|
||||
push constant 16379
|
||||
gt
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push constant 6
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE4
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 0
|
||||
push constant 2
|
||||
add
|
||||
gt
|
||||
if-goto IF_TRUE5
|
||||
goto IF_FALSE5
|
||||
label IF_TRUE5
|
||||
push argument 0
|
||||
push constant 2
|
||||
add
|
||||
push local 0
|
||||
add
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 0
|
||||
sub
|
||||
push constant 2
|
||||
sub
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
push constant 2
|
||||
add
|
||||
eq
|
||||
if-goto IF_TRUE6
|
||||
goto IF_FALSE6
|
||||
label IF_TRUE6
|
||||
push argument 0
|
||||
push constant 3
|
||||
add
|
||||
push local 0
|
||||
add
|
||||
push local 0
|
||||
push argument 0
|
||||
add
|
||||
push constant 4
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto IF_END6
|
||||
label IF_FALSE6
|
||||
push argument 0
|
||||
push constant 3
|
||||
add
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label IF_END6
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push local 0
|
||||
push argument 0
|
||||
add
|
||||
push constant 2
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label IF_FALSE5
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push constant 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
push constant 2
|
||||
add
|
||||
return
|
||||
function Memory.deAlloc 2
|
||||
push argument 0
|
||||
push constant 2
|
||||
sub
|
||||
pop local 0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 1
|
||||
push constant 0
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
sub
|
||||
push constant 2
|
||||
sub
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto IF_END0
|
||||
label IF_FALSE0
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
sub
|
||||
push constant 0
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 1
|
||||
push constant 2
|
||||
add
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push local 0
|
||||
push constant 2
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto IF_END1
|
||||
label IF_FALSE1
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push constant 1
|
||||
push local 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label IF_END1
|
||||
label IF_END0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,806 @@
|
||||
function Screen.init 1
|
||||
push constant 16384
|
||||
pop static 1
|
||||
push constant 0
|
||||
not
|
||||
pop static 2
|
||||
push constant 17
|
||||
call Array.new 1
|
||||
pop static 0
|
||||
push constant 0
|
||||
push static 0
|
||||
add
|
||||
push constant 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 16
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
push local 0
|
||||
push static 0
|
||||
add
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.clearScreen 1
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push constant 8192
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push static 1
|
||||
add
|
||||
push constant 0
|
||||
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 constant 0
|
||||
return
|
||||
function Screen.updateLocation 0
|
||||
push static 2
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
push static 1
|
||||
add
|
||||
push argument 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 1
|
||||
or
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
goto IF_END0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push static 1
|
||||
add
|
||||
push argument 0
|
||||
push static 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push argument 1
|
||||
not
|
||||
and
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
label IF_END0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.setColor 0
|
||||
push argument 0
|
||||
pop static 2
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawPixel 3
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
push argument 0
|
||||
push constant 511
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 1
|
||||
push constant 255
|
||||
gt
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 7
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push constant 16
|
||||
call Math.divide 2
|
||||
pop local 0
|
||||
push argument 0
|
||||
push local 0
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
sub
|
||||
pop local 1
|
||||
push argument 1
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
push local 0
|
||||
add
|
||||
pop local 2
|
||||
push local 2
|
||||
push local 1
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawConditional 0
|
||||
push argument 2
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 1
|
||||
push argument 0
|
||||
call Screen.drawPixel 2
|
||||
pop temp 0
|
||||
goto IF_END0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push argument 1
|
||||
call Screen.drawPixel 2
|
||||
pop temp 0
|
||||
label IF_END0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawLine 11
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
push argument 2
|
||||
push constant 511
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 3
|
||||
push constant 255
|
||||
gt
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 8
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 2
|
||||
push argument 0
|
||||
sub
|
||||
call Math.abs 1
|
||||
pop local 3
|
||||
push argument 3
|
||||
push argument 1
|
||||
sub
|
||||
call Math.abs 1
|
||||
pop local 2
|
||||
push local 3
|
||||
push local 2
|
||||
lt
|
||||
pop local 6
|
||||
push local 6
|
||||
push argument 3
|
||||
push argument 1
|
||||
lt
|
||||
and
|
||||
push local 6
|
||||
not
|
||||
push argument 2
|
||||
push argument 0
|
||||
lt
|
||||
and
|
||||
or
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push argument 0
|
||||
pop local 4
|
||||
push argument 2
|
||||
pop argument 0
|
||||
push local 4
|
||||
pop argument 2
|
||||
push argument 1
|
||||
pop local 4
|
||||
push argument 3
|
||||
pop argument 1
|
||||
push local 4
|
||||
pop argument 3
|
||||
label IF_FALSE1
|
||||
push local 6
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 3
|
||||
pop local 4
|
||||
push local 2
|
||||
pop local 3
|
||||
push local 4
|
||||
pop local 2
|
||||
push argument 1
|
||||
pop local 1
|
||||
push argument 0
|
||||
pop local 0
|
||||
push argument 3
|
||||
pop local 8
|
||||
push argument 0
|
||||
push argument 2
|
||||
gt
|
||||
pop local 7
|
||||
goto IF_END2
|
||||
label IF_FALSE2
|
||||
push argument 0
|
||||
pop local 1
|
||||
push argument 1
|
||||
pop local 0
|
||||
push argument 2
|
||||
pop local 8
|
||||
push argument 1
|
||||
push argument 3
|
||||
gt
|
||||
pop local 7
|
||||
label IF_END2
|
||||
push constant 2
|
||||
push local 2
|
||||
call Math.multiply 2
|
||||
push local 3
|
||||
sub
|
||||
pop local 5
|
||||
push constant 2
|
||||
push local 2
|
||||
call Math.multiply 2
|
||||
pop local 9
|
||||
push constant 2
|
||||
push local 2
|
||||
push local 3
|
||||
sub
|
||||
call Math.multiply 2
|
||||
pop local 10
|
||||
push local 1
|
||||
push local 0
|
||||
push local 6
|
||||
call Screen.drawConditional 3
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push local 8
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 5
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 5
|
||||
push local 9
|
||||
add
|
||||
pop local 5
|
||||
goto IF_END3
|
||||
label IF_FALSE3
|
||||
push local 5
|
||||
push local 10
|
||||
add
|
||||
pop local 5
|
||||
push local 7
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 0
|
||||
goto IF_END4
|
||||
label IF_FALSE4
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label IF_END4
|
||||
label IF_END3
|
||||
push local 1
|
||||
push constant 1
|
||||
add
|
||||
pop local 1
|
||||
push local 1
|
||||
push local 0
|
||||
push local 6
|
||||
call Screen.drawConditional 3
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawRectangle 9
|
||||
push argument 0
|
||||
push argument 2
|
||||
gt
|
||||
push argument 1
|
||||
push argument 3
|
||||
gt
|
||||
or
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 2
|
||||
push constant 511
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 3
|
||||
push constant 255
|
||||
gt
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 9
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push constant 16
|
||||
call Math.divide 2
|
||||
pop local 3
|
||||
push argument 0
|
||||
push local 3
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
sub
|
||||
pop local 7
|
||||
push argument 2
|
||||
push constant 16
|
||||
call Math.divide 2
|
||||
pop local 4
|
||||
push argument 2
|
||||
push local 4
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
sub
|
||||
pop local 8
|
||||
push local 7
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
not
|
||||
pop local 6
|
||||
push local 8
|
||||
push constant 1
|
||||
add
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 5
|
||||
push argument 1
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
push local 3
|
||||
add
|
||||
pop local 0
|
||||
push local 4
|
||||
push local 3
|
||||
sub
|
||||
pop local 2
|
||||
label WHILE_EXP0
|
||||
push argument 1
|
||||
push argument 3
|
||||
gt
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
pop local 1
|
||||
push local 2
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 0
|
||||
push local 5
|
||||
push local 6
|
||||
and
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
goto IF_END1
|
||||
label IF_FALSE1
|
||||
push local 0
|
||||
push local 6
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push local 1
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push constant 1
|
||||
neg
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push local 1
|
||||
push local 5
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
label IF_END1
|
||||
push argument 1
|
||||
push constant 1
|
||||
add
|
||||
pop argument 1
|
||||
push local 1
|
||||
push constant 32
|
||||
add
|
||||
push local 2
|
||||
sub
|
||||
pop local 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawHorizontal 11
|
||||
push argument 1
|
||||
push argument 2
|
||||
call Math.min 2
|
||||
pop local 7
|
||||
push argument 1
|
||||
push argument 2
|
||||
call Math.max 2
|
||||
pop local 8
|
||||
push argument 0
|
||||
push constant 1
|
||||
neg
|
||||
gt
|
||||
push argument 0
|
||||
push constant 256
|
||||
lt
|
||||
and
|
||||
push local 7
|
||||
push constant 512
|
||||
lt
|
||||
and
|
||||
push local 8
|
||||
push constant 1
|
||||
neg
|
||||
gt
|
||||
and
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push local 7
|
||||
push constant 0
|
||||
call Math.max 2
|
||||
pop local 7
|
||||
push local 8
|
||||
push constant 511
|
||||
call Math.min 2
|
||||
pop local 8
|
||||
push local 7
|
||||
push constant 16
|
||||
call Math.divide 2
|
||||
pop local 1
|
||||
push local 7
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
sub
|
||||
pop local 9
|
||||
push local 8
|
||||
push constant 16
|
||||
call Math.divide 2
|
||||
pop local 2
|
||||
push local 8
|
||||
push local 2
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
sub
|
||||
pop local 10
|
||||
push local 9
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
not
|
||||
pop local 5
|
||||
push local 10
|
||||
push constant 1
|
||||
add
|
||||
push static 0
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 4
|
||||
push argument 0
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
push local 1
|
||||
add
|
||||
pop local 0
|
||||
push local 2
|
||||
push local 1
|
||||
sub
|
||||
pop local 6
|
||||
push local 0
|
||||
push local 6
|
||||
add
|
||||
pop local 3
|
||||
push local 6
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push local 0
|
||||
push local 4
|
||||
push local 5
|
||||
and
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
goto IF_END1
|
||||
label IF_FALSE1
|
||||
push local 0
|
||||
push local 5
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push local 3
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push constant 1
|
||||
neg
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 3
|
||||
push local 4
|
||||
call Screen.updateLocation 2
|
||||
pop temp 0
|
||||
label IF_END1
|
||||
label IF_FALSE0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawSymetric 0
|
||||
push argument 1
|
||||
push argument 3
|
||||
sub
|
||||
push argument 0
|
||||
push argument 2
|
||||
add
|
||||
push argument 0
|
||||
push argument 2
|
||||
sub
|
||||
call Screen.drawHorizontal 3
|
||||
pop temp 0
|
||||
push argument 1
|
||||
push argument 3
|
||||
add
|
||||
push argument 0
|
||||
push argument 2
|
||||
add
|
||||
push argument 0
|
||||
push argument 2
|
||||
sub
|
||||
call Screen.drawHorizontal 3
|
||||
pop temp 0
|
||||
push argument 1
|
||||
push argument 2
|
||||
sub
|
||||
push argument 0
|
||||
push argument 3
|
||||
sub
|
||||
push argument 0
|
||||
push argument 3
|
||||
add
|
||||
call Screen.drawHorizontal 3
|
||||
pop temp 0
|
||||
push argument 1
|
||||
push argument 2
|
||||
add
|
||||
push argument 0
|
||||
push argument 3
|
||||
sub
|
||||
push argument 0
|
||||
push argument 3
|
||||
add
|
||||
call Screen.drawHorizontal 3
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Screen.drawCircle 3
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
push argument 0
|
||||
push constant 511
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 1
|
||||
push constant 255
|
||||
gt
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 12
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push argument 2
|
||||
sub
|
||||
push constant 0
|
||||
lt
|
||||
push argument 0
|
||||
push argument 2
|
||||
add
|
||||
push constant 511
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push argument 2
|
||||
sub
|
||||
push constant 0
|
||||
lt
|
||||
or
|
||||
push argument 1
|
||||
push argument 2
|
||||
add
|
||||
push constant 255
|
||||
gt
|
||||
or
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 13
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE1
|
||||
push argument 2
|
||||
pop local 1
|
||||
push constant 1
|
||||
push argument 2
|
||||
sub
|
||||
pop local 2
|
||||
push argument 0
|
||||
push argument 1
|
||||
push local 0
|
||||
push local 1
|
||||
call Screen.drawSymetric 4
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push local 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 2
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 2
|
||||
push constant 2
|
||||
push local 0
|
||||
call Math.multiply 2
|
||||
add
|
||||
push constant 3
|
||||
add
|
||||
pop local 2
|
||||
goto IF_END2
|
||||
label IF_FALSE2
|
||||
push local 2
|
||||
push constant 2
|
||||
push local 0
|
||||
push local 1
|
||||
sub
|
||||
call Math.multiply 2
|
||||
add
|
||||
push constant 5
|
||||
add
|
||||
pop local 2
|
||||
push local 1
|
||||
push constant 1
|
||||
sub
|
||||
pop local 1
|
||||
label IF_END2
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
push argument 0
|
||||
push argument 1
|
||||
push local 0
|
||||
push local 1
|
||||
call Screen.drawSymetric 4
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,393 @@
|
||||
function String.new 0
|
||||
push constant 3
|
||||
call Memory.alloc 1
|
||||
pop pointer 0
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 14
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push constant 0
|
||||
gt
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push argument 0
|
||||
call Array.new 1
|
||||
pop this 1
|
||||
label IF_FALSE1
|
||||
push argument 0
|
||||
pop this 0
|
||||
push constant 0
|
||||
pop this 2
|
||||
push pointer 0
|
||||
return
|
||||
function String.dispose 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 0
|
||||
push constant 0
|
||||
gt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push this 1
|
||||
call Array.dispose 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push pointer 0
|
||||
call Memory.deAlloc 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function String.length 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 2
|
||||
return
|
||||
function String.charAt 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
push argument 1
|
||||
push this 2
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push this 2
|
||||
eq
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 15
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 1
|
||||
push this 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
return
|
||||
function String.setCharAt 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
push argument 1
|
||||
push this 2
|
||||
gt
|
||||
or
|
||||
push argument 1
|
||||
push this 2
|
||||
eq
|
||||
or
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 16
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push argument 1
|
||||
push this 1
|
||||
add
|
||||
push argument 2
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 0
|
||||
return
|
||||
function String.appendChar 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 2
|
||||
push this 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 17
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push this 2
|
||||
push this 1
|
||||
add
|
||||
push argument 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push this 2
|
||||
push constant 1
|
||||
add
|
||||
pop this 2
|
||||
push pointer 0
|
||||
return
|
||||
function String.eraseLastChar 0
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 2
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 18
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push this 2
|
||||
push constant 1
|
||||
sub
|
||||
pop this 2
|
||||
push constant 0
|
||||
return
|
||||
function String.intValue 5
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 2
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push constant 0
|
||||
not
|
||||
pop local 3
|
||||
push constant 0
|
||||
push this 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 45
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 0
|
||||
not
|
||||
pop local 4
|
||||
push constant 1
|
||||
pop local 0
|
||||
label IF_FALSE1
|
||||
label WHILE_EXP0
|
||||
push local 0
|
||||
push this 2
|
||||
lt
|
||||
push local 3
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push local 0
|
||||
push this 1
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
push constant 48
|
||||
sub
|
||||
pop local 2
|
||||
push local 2
|
||||
push constant 0
|
||||
lt
|
||||
push local 2
|
||||
push constant 9
|
||||
gt
|
||||
or
|
||||
not
|
||||
pop local 3
|
||||
push local 3
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 1
|
||||
push constant 10
|
||||
call Math.multiply 2
|
||||
push local 2
|
||||
add
|
||||
pop local 1
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label IF_FALSE2
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 4
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 1
|
||||
neg
|
||||
pop local 1
|
||||
label IF_FALSE3
|
||||
push local 1
|
||||
return
|
||||
function String.setInt 4
|
||||
push argument 0
|
||||
pop pointer 0
|
||||
push this 0
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 19
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push constant 6
|
||||
call Array.new 1
|
||||
pop local 2
|
||||
push argument 1
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 0
|
||||
not
|
||||
pop local 3
|
||||
push argument 1
|
||||
neg
|
||||
pop argument 1
|
||||
label IF_FALSE1
|
||||
push argument 1
|
||||
pop local 1
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push argument 1
|
||||
push constant 10
|
||||
call Math.divide 2
|
||||
pop local 1
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
push constant 48
|
||||
push argument 1
|
||||
push local 1
|
||||
push constant 10
|
||||
call Math.multiply 2
|
||||
sub
|
||||
add
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
push local 1
|
||||
pop argument 1
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push local 3
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
push constant 45
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
label IF_FALSE2
|
||||
push this 0
|
||||
push local 0
|
||||
lt
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push constant 19
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE3
|
||||
push local 0
|
||||
push constant 0
|
||||
eq
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push constant 0
|
||||
push this 1
|
||||
add
|
||||
push constant 48
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
pop this 2
|
||||
goto IF_END4
|
||||
label IF_FALSE4
|
||||
push constant 0
|
||||
pop this 2
|
||||
label WHILE_EXP1
|
||||
push this 2
|
||||
push local 0
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push this 2
|
||||
push this 1
|
||||
add
|
||||
push local 0
|
||||
push this 2
|
||||
push constant 1
|
||||
add
|
||||
sub
|
||||
push local 2
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push this 2
|
||||
push constant 1
|
||||
add
|
||||
pop this 2
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
label IF_END4
|
||||
push local 2
|
||||
call Array.dispose 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function String.newLine 0
|
||||
push constant 128
|
||||
return
|
||||
function String.backSpace 0
|
||||
push constant 129
|
||||
return
|
||||
function String.doubleQuote 0
|
||||
push constant 34
|
||||
return
|
||||
@@ -0,0 +1,83 @@
|
||||
function Sys.init 0
|
||||
call Memory.init 0
|
||||
pop temp 0
|
||||
call Math.init 0
|
||||
pop temp 0
|
||||
call Screen.init 0
|
||||
pop temp 0
|
||||
call Output.init 0
|
||||
pop temp 0
|
||||
call Keyboard.init 0
|
||||
pop temp 0
|
||||
call Main.main 0
|
||||
pop temp 0
|
||||
call Sys.halt 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Sys.halt 0
|
||||
label WHILE_EXP0
|
||||
push constant 0
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Sys.wait 1
|
||||
push argument 0
|
||||
push constant 0
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 1
|
||||
call Sys.error 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
label WHILE_EXP0
|
||||
push argument 0
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 50
|
||||
pop local 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push constant 1
|
||||
sub
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
pop argument 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Sys.error 0
|
||||
push constant 69
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
push constant 82
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
push constant 82
|
||||
call Output.printChar 1
|
||||
pop temp 0
|
||||
push argument 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
call Sys.halt 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
@@ -0,0 +1,473 @@
|
||||
class Piece {
|
||||
static int lBorder, rBorder, uBorder, dBorder, st;
|
||||
field int x1, y1, x2, y2, x3, y3, x4, y4, piece, direction;
|
||||
field bool move;
|
||||
static Array st;
|
||||
|
||||
constructor Piece new(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4, int p) {
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
let piece = p;
|
||||
let direction = 0;
|
||||
let move = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
function void init(){
|
||||
var int a;
|
||||
let lBorder = 0;
|
||||
let rBorder = 511;
|
||||
let uBorder = 0;
|
||||
let dBorder = 255;
|
||||
let st = Array.new(16);
|
||||
let st[0] = 1;
|
||||
while (a < 15){
|
||||
let a = a + 1;
|
||||
let st[a] = st[a - 1] + st[a - 1];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
method void dispose() {
|
||||
do Memory.deAlloc(this);
|
||||
return;
|
||||
}
|
||||
|
||||
/** draws 2 rectangles also checks if there is a piece at the spawn which will indicate end of the game. */
|
||||
method bool draw() {
|
||||
var bool finish;
|
||||
let finish = true;
|
||||
let finish = Piece.sample(x1,y1) & finish;
|
||||
let finish = Piece.sample(x2,y2) & finish;
|
||||
let finish = Piece.sample(x3,y3) & finish;
|
||||
let finish = Piece.sample(x4,y4) & finish;
|
||||
if (finish){
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Erases the square from the screen. */
|
||||
method void erase() {
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
/** checks if those coodinates hold any value > 0. */
|
||||
function bool sample(int x, int y){
|
||||
var int value, address, bit, memBlock;
|
||||
let memBlock = x / 16;
|
||||
let address = (32 * y) + memBlock + 16384;
|
||||
if (address > 24576){
|
||||
return false;
|
||||
}
|
||||
let value = Memory.peek(address);
|
||||
if (value = 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
method bool getMove(){
|
||||
return move;
|
||||
}
|
||||
|
||||
/** Checks if the piece can move in the given direction(dir). */
|
||||
method bool fullSample(int dir){
|
||||
var int size1, size2, i, j;
|
||||
var bool result, flagUpon;
|
||||
if (dir = 1){ //down
|
||||
let size1 = x2 - x1;
|
||||
let size2 = x4 - x3;
|
||||
let result = true;
|
||||
while (i < size1){ // for each block of the first rectangle
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){ // for each block of the second rectangle
|
||||
if ((x1 + i) = (x3 + j)){ // if this block of the first rectangle sits upon a block of the second rectangle
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x3 + j, y4 + 1); // if there is a block under the second rectangle
|
||||
let j = j + 16; // sets the coords for the next block of the second rectangle
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x1 + i, y2 + 1); // if there is a block under the first rectangle
|
||||
}
|
||||
let i = i + 16; // sets the coords for the next block of the firs rectangle
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{
|
||||
if (dir = 2){ //right
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size1){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size2){
|
||||
if ((y1 + i) = (y3 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x4 + 1, (y3 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x2 + 1, (y1 + i));
|
||||
}
|
||||
let i = i +16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else{ // left
|
||||
let size1 = y2 - y1;
|
||||
let size2 = y4 - y3;
|
||||
let result = true;
|
||||
while (i < size2){
|
||||
let j = 0;
|
||||
let flagUpon = false;
|
||||
while (j < size1){
|
||||
if ((y3 + i) = (y1 + j)){
|
||||
let flagUpon = true;
|
||||
}
|
||||
let result = result & Piece.sample(x1 - 1, (y1 + j));
|
||||
let j = j + 16;
|
||||
}
|
||||
if (~(flagUpon)){
|
||||
let result = result & Piece.sample(x3 - 1, (y3 + i));
|
||||
}
|
||||
let i = i + 16;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels down. */
|
||||
method void moveDown() {
|
||||
var int i;
|
||||
if ((y2 < dBorder) & (y4 < dBorder) & (move) & fullSample(1)) {
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y1);
|
||||
do Screen.drawRectangle(x3, y3, x4, y3);
|
||||
let y1 = y1 + 1;
|
||||
let y2 = y2 + 1;
|
||||
let y3 = y3 + 1;
|
||||
let y4 = y4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y2, x2, y2);
|
||||
do Screen.drawRectangle(x3, y4, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
else{
|
||||
let move = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the left. */
|
||||
method void moveLeft() {
|
||||
var int i;
|
||||
if ((x1 + 15 > lBorder) & (move) & (x3 + 15 > lBorder)& fullSample(0)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x2, y1, x2, y2);
|
||||
do Screen.drawRectangle(x4, y3, x4, y4);
|
||||
let x1 = x1 - 1;
|
||||
let x2 = x2 - 1;
|
||||
let x3 = x3 - 1;
|
||||
let x4 = x4 - 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Moves the game piece 16 pixels to the right. */
|
||||
method void moveRight() {
|
||||
var int i;
|
||||
if ((x4 < rBorder) & (move) & (x2 < rBorder) & fullSample(2)){
|
||||
while (i < 16){
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x1, y2);
|
||||
do Screen.drawRectangle(x3, y3, x3, y4);
|
||||
let x1 = x1 + 1;
|
||||
let x2 = x2 + 1;
|
||||
let x3 = x3 + 1;
|
||||
let x4 = x4 + 1;
|
||||
do Screen.setColor(true);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
let i = i + 1;
|
||||
do Sys.wait(10);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/** Deletes the piece and draws it at the new coodinates. */
|
||||
method void reDraw(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4){
|
||||
var int absTmp;
|
||||
if((Ax1 < 175) | (Ax3 < 175) | (Ax2 > 336) | (Ax4 > 336)){
|
||||
return;
|
||||
}
|
||||
if((Ay2 > 255) | (Ay4 > 255) | (Ay1 < 0) | (Ay3 < 0)){
|
||||
return;
|
||||
}
|
||||
if((Ax1 > Ax2) | (Ax3 > Ax4) | (Ay1 > Ay2) | (Ay3 > Ay4)){
|
||||
return;
|
||||
}
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
do Screen.setColor(true);
|
||||
let x1 = Ax1;
|
||||
let y1 = Ay1;
|
||||
let x2 = Ax2;
|
||||
let y2 = Ay2;
|
||||
let x3 = Ax3;
|
||||
let y3 = Ay3;
|
||||
let x4 = Ax4;
|
||||
let y4 = Ay4;
|
||||
do Screen.drawRectangle(x1, y1, x2, y2);
|
||||
do Screen.drawRectangle(x3, y3, x4, y4);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Rotates the piece clockwise. */
|
||||
method void rotate(){
|
||||
var bool samp;
|
||||
let samp = true;
|
||||
if (direction = 0){ // starting position
|
||||
if (piece = 0){ // arrow
|
||||
let samp = Piece.sample(x4, y1) & samp; // checks if the place at which the new piece will be drawn are free
|
||||
let samp = Piece.sample(x4, y1 - 1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2, y2, x4 - 15, y4 - 47, x4, y4); // redraws it at the new location
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 + 16, y1) & samp;
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4, y1 - 16) & samp;
|
||||
if(samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x4 - 16, y4, x4 - 15, y1 - 16, x4, y1 - 1);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 16, y2 + 16, x3 + 32, y3, x4, y4);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3 + 16, y3 - 32) & samp;
|
||||
let samp = Piece.sample(x4, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1, x2, y2 + 16, x3 + 16, y3 - 32, x4, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 + 32, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3 + 32, y3 - 32, x4 + 16, y4 - 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 32, y1 - 32) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 - 32, x2 + 16, y2 - 16, x3, y3, x4 - 16, y4 + 16);
|
||||
let direction = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 1){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y3) & samp;
|
||||
let samp = Piece.sample(x1 - 1, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y3, x4, y3 + 15, x1, y1, x2, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x4, y4 + 16, x3, y3 + 32, x4, y2);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 16, y2 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 32, y3) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 16, x2 + 16, y2 - 16, x3 - 32, y3, x4 - 32, y4);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x1 - 16, y1) & samp;
|
||||
let samp = Piece.sample(x4, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1, x2, y2 - 16, x3 - 16, y3 +32, x4, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 32, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3 - 32, y3 + 32, x4 - 16, y4 + 16);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 32, y1 + 16, x2 - 16, y2, x3, y3 - 16, x4 + 16, y4 - 32);
|
||||
let direction = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (direction = 2){
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x1, y1+16) & samp;
|
||||
let samp = Piece.sample(x1, y1+32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x1 + 15, y1 + 47, x3, y3, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 + 16, x1 + 15, y1 + 31, x1 + 16, y1 - 16, x4 - 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2 - 32, y2 - 16, x3 + 16, y3 - 32, x4 + 16, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x2 - 16, y2 + 16) & samp;
|
||||
let samp = Piece.sample(x3, y3 - 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 - 16, y2 + 16, x3, y3 - 32, x4 - 16, y4 - 16);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x1 - 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x2 - 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 - 16, x2 - 32, y2, x3 + 16, y3 - 16, x4, y4);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 + 16, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 - 16) & samp;
|
||||
let samp = Piece.sample(x4 - 32, y4 + 32) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 - 16, x2, y2, x3 - 16, y3 + 16, x4 - 32, y4 + 32);
|
||||
let direction = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (piece = 0){
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x3, y3, x4, y4, x1, y1 + 32, x1 + 47, y1 + 47);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 1){
|
||||
let samp = Piece.sample(x1, y1 - 16) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1 - 16, x2, y2 -16, x1, y1, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 2){
|
||||
let samp = Piece.sample(x1 + 32, y1 + 16) & samp;
|
||||
let samp = Piece.sample(x3 - 16, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 32, y1 + 16, x2 + 32, y2 + 16, x3 - 16, y3 + 32, x4 + 16, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 3){
|
||||
let samp = Piece.sample(x3, y3 + 32) & samp;
|
||||
let samp = Piece.sample(x4 + 16, y4 + 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1, y1, x2 + 16, y2 - 16, x3, y3 + 32, x4 + 16, y4 + 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 4){
|
||||
let samp = Piece.sample(x3 - 16, y3 + 16) & samp;
|
||||
let samp = Piece.sample(x2 + 32, y2) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 + 16, y1 + 16, x2 + 32, y2, x3 - 16, y3 + 16, x4, y4);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
if (piece = 5){
|
||||
let samp = Piece.sample(x1 - 16, y1 + 32) & samp;
|
||||
let samp = Piece.sample(x3 + 16, y3) & samp;
|
||||
let samp = Piece.sample(x4 + 32, y4 - 16) & samp;
|
||||
if (samp){
|
||||
do reDraw(x1 - 16, y1 + 32, x2, y2 + 16, x3 + 16, y3, x4 + 32, y4 - 16);
|
||||
let direction = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
class Tetris {
|
||||
static int points, seed, next_seed;
|
||||
|
||||
function void tetris(int z){
|
||||
var Piece p, nextPiece;
|
||||
var int i, x1, y1, x2, y2, x3, y3, x4, y4, key, j, randTmp, piece_number, moves;
|
||||
var Array left_g, right_g, box, stick, left_z, right_z,dick, all_piece, tmp;
|
||||
do Piece.init();
|
||||
do Tetris.border();
|
||||
let points = 0;
|
||||
let all_piece = Array.new(25);
|
||||
let all_piece[0] = Tetris.newPiece(16,0,31,15, 0,16,47,31, 0); // arrow
|
||||
let all_piece[1] = Tetris.newPiece(0,0,15,15, 0,16,47,31, 1); // right_L
|
||||
let all_piece[2] = Tetris.newPiece(32,16,47,31, 0,32,47,47, 2); // left_L
|
||||
let all_piece[3] = Tetris.newPiece(0,0,31,15, 16,16,47,31, 3); // left_z
|
||||
let all_piece[4] = Tetris.newPiece(16,0,47,15, 0,16,31,31, 4); // right_z
|
||||
let all_piece[5] = Tetris.newPiece(0,0,31,15, 32,0,63,15, 5); //stick
|
||||
let all_piece[6] = Tetris.newPiece(0,0,15,31, 16,0,31,31, 6); //box
|
||||
|
||||
|
||||
let seed = z * 3; // multiply by 3, because it gets in a loop on some even numbers
|
||||
let next_seed = Tetris.randomNumber();
|
||||
do Output.moveCursor(0,0);
|
||||
do Output.printString("Point: ");
|
||||
do Output.printInt(points);
|
||||
do Output.println();
|
||||
do Output.printString("Next Piece: ");
|
||||
while (true){ // The main game loop
|
||||
let j = next_seed;
|
||||
let next_seed = Tetris.randomNumber();
|
||||
let tmp = all_piece[j]; // initializes the coords of the game piece
|
||||
let x1 = tmp[0];
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let p = Piece.new(x1 + 240, y1, x2 + 240, y2, x3 + 240, y3, x4 + 240, y4, piece_number);
|
||||
if (~(p.draw())){ // if a piece tries to spawn above a limit the game ends
|
||||
if (~(Tetris.finish())){
|
||||
return;
|
||||
}
|
||||
}
|
||||
let tmp = all_piece[next_seed];
|
||||
let x1 = tmp[0]; // initializes the coords of the next game piece that is being displayed
|
||||
let y1 = tmp[1];
|
||||
let x2 = tmp[2];
|
||||
let y2 = tmp[3];
|
||||
let x3 = tmp[4];
|
||||
let y3 = tmp[5];
|
||||
let x4 = tmp[6];
|
||||
let y4 = tmp[7];
|
||||
let piece_number = tmp[8];
|
||||
let nextPiece = Piece.new(x1 + 16, y1 + 32, x2+16, y2 + 32, x3+16, y3 + 32, x4 + 16, y4 + 32, piece_number);
|
||||
do nextPiece.draw();
|
||||
while (p.getMove()){
|
||||
let moves = 0;
|
||||
while (moves < 3){ // one can move its piece 3 times before it moves down automatically
|
||||
let key = Keyboard.keyPressed();
|
||||
if (key = 130){
|
||||
do p.moveLeft();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 132){
|
||||
do p.moveRight();
|
||||
do Sys.wait(80);
|
||||
}
|
||||
if (key = 131){
|
||||
do p.rotate();
|
||||
}
|
||||
if (key = 133){
|
||||
do p.moveDown();
|
||||
do p.moveDown();
|
||||
}
|
||||
let moves = moves +1;
|
||||
}
|
||||
do p.moveDown();
|
||||
let i = i + 1;
|
||||
do Sys.wait(80);
|
||||
}
|
||||
let i = 0;
|
||||
do p.dispose();
|
||||
do Tetris.completeRow();
|
||||
do Output.moveCursor(0,7);
|
||||
do Output.printInt(points);
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(16,32,80,96);
|
||||
do Screen.setColor(true);
|
||||
do nextPiece.dispose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void completeRow(){ // checks if a row has been completed
|
||||
var int adddress, row, colloum;
|
||||
var bool complete;
|
||||
let adddress = 16384 + 11;
|
||||
let row = 15;
|
||||
while (row > 0){ // for each row
|
||||
let complete = true;
|
||||
let colloum = 0;
|
||||
while ((colloum < 10) & (complete)){ // for each collum
|
||||
let complete = Memory.peek(adddress + colloum + (row * 512)) & complete;
|
||||
let colloum = colloum + 1;
|
||||
}
|
||||
if (complete){ // removes the row
|
||||
do Screen.setColor(false);
|
||||
do Screen.drawRectangle(176, row * 16, 335, ((row * 16)+ 15) );
|
||||
let points = points + 1;
|
||||
do Tetris.shift(row);
|
||||
}
|
||||
let row = row - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void shift(int rowShift){ // shifts all rows above the completed one
|
||||
var int j, val, adddress, tmp, k;
|
||||
let adddress = 16384 + 11;
|
||||
while (rowShift > 1){ // each row
|
||||
let j = 0;
|
||||
while (j < 10){ // collum in the game field
|
||||
let k = 0;
|
||||
while (k < 16){ // each line a in 16 x 16 box
|
||||
let tmp = adddress + j + (((rowShift - 1) * 512) + (k * 32));
|
||||
let val = Memory.peek(tmp);
|
||||
do Memory.poke(adddress + j + ((rowShift * 512) + (k * 32)), val);
|
||||
do Memory.poke(tmp,0);
|
||||
let k = k+ 1;
|
||||
}
|
||||
let j = j + 1;
|
||||
}
|
||||
let rowShift = rowShift - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function void border(){ // draws a border
|
||||
do Screen.drawLine(175,0,175,255);
|
||||
do Screen.drawLine(336,0,336,255);
|
||||
return;
|
||||
}
|
||||
|
||||
function Array newPiece(int Ax1, int Ay1, int Ax2, int Ay2, int Ax3, int Ay3, int Ax4, int Ay4,int p){
|
||||
var Array gamepice;
|
||||
let gamepice = Array.new(9);
|
||||
let gamepice[0] = Ax1;
|
||||
let gamepice[1] = Ay1;
|
||||
let gamepice[2] = Ax2;
|
||||
let gamepice[3] = Ay2;
|
||||
let gamepice[4] = Ax3;
|
||||
let gamepice[5] = Ay3;
|
||||
let gamepice[6] = Ax4;
|
||||
let gamepice[7] = Ay4;
|
||||
let gamepice[8] = p;
|
||||
return gamepice;
|
||||
}
|
||||
|
||||
function int randomNumber(){ // radom number generator
|
||||
var int multiplier,additor,moduler,toBeModulated;
|
||||
let multiplier = 7;
|
||||
let additor = 13;
|
||||
let moduler = 1133;
|
||||
let toBeModulated = (multiplier * seed) + additor;
|
||||
let seed = Tetris.mod(toBeModulated,moduler);
|
||||
return Tetris.mod(seed,7);
|
||||
}
|
||||
|
||||
function bool finish(){ // after finishing the game the player has 2 options to start onether or to end the game
|
||||
var char c;
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,24);
|
||||
do Output.printString("Your score: ");
|
||||
do Output.printInt(points);
|
||||
do Sys.wait(10000);
|
||||
do Screen.clearScreen();
|
||||
do Output.moveCursor(10,0);
|
||||
do Output.printString("Would you like to play again, for yes click 'Y' and for no 'N':");
|
||||
let c = Keyboard.readChar();
|
||||
if (c = 89){
|
||||
do Screen.clearScreen();
|
||||
return false;
|
||||
}
|
||||
if (c = 78){
|
||||
do Screen.clearScreen();
|
||||
do Sys.halt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function int mod(int tbm, int mo){ //simple moduler devision
|
||||
var int val, tmp2;
|
||||
if (tbm < mo){
|
||||
return tbm;
|
||||
}
|
||||
let tmp2 = (tbm / mo) * mo;
|
||||
let val = tbm - tmp2;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,999 @@
|
||||
function Tetris.tetris 25
|
||||
call Piece.init 0
|
||||
pop temp 0
|
||||
call Tetris.border 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
pop static 0
|
||||
push constant 25
|
||||
call Array.new 1
|
||||
pop local 23
|
||||
push constant 0
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 1
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 23
|
||||
add
|
||||
push constant 32
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 0
|
||||
push constant 32
|
||||
push constant 47
|
||||
push constant 47
|
||||
push constant 2
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 16
|
||||
push constant 16
|
||||
push constant 47
|
||||
push constant 31
|
||||
push constant 3
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 23
|
||||
add
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 47
|
||||
push constant 15
|
||||
push constant 0
|
||||
push constant 16
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 4
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 15
|
||||
push constant 32
|
||||
push constant 0
|
||||
push constant 63
|
||||
push constant 15
|
||||
push constant 5
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 23
|
||||
add
|
||||
push constant 0
|
||||
push constant 0
|
||||
push constant 15
|
||||
push constant 31
|
||||
push constant 16
|
||||
push constant 0
|
||||
push constant 31
|
||||
push constant 31
|
||||
push constant 6
|
||||
call Tetris.newPiece 9
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push argument 0
|
||||
push constant 3
|
||||
call Math.multiply 2
|
||||
pop static 1
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push constant 0
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 7
|
||||
call String.new 1
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
call Output.println 0
|
||||
pop temp 0
|
||||
push constant 12
|
||||
call String.new 1
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 120
|
||||
call String.appendChar 2
|
||||
push constant 116
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 80
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
label WHILE_EXP0
|
||||
push constant 0
|
||||
not
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push static 2
|
||||
pop local 12
|
||||
call Tetris.randomNumber 0
|
||||
pop static 2
|
||||
push local 12
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 240
|
||||
add
|
||||
push local 4
|
||||
push local 5
|
||||
push constant 240
|
||||
add
|
||||
push local 6
|
||||
push local 7
|
||||
push constant 240
|
||||
add
|
||||
push local 8
|
||||
push local 9
|
||||
push constant 240
|
||||
add
|
||||
push local 10
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 0
|
||||
push local 0
|
||||
call Piece.draw 1
|
||||
not
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Tetris.finish 0
|
||||
not
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE1
|
||||
label IF_FALSE0
|
||||
push static 2
|
||||
push local 23
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 24
|
||||
push constant 0
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 3
|
||||
push constant 1
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 4
|
||||
push constant 2
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 5
|
||||
push constant 3
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 6
|
||||
push constant 4
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 7
|
||||
push constant 5
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 8
|
||||
push constant 6
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 9
|
||||
push constant 7
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 10
|
||||
push constant 8
|
||||
push local 24
|
||||
add
|
||||
pop pointer 1
|
||||
push that 0
|
||||
pop local 14
|
||||
push local 3
|
||||
push constant 16
|
||||
add
|
||||
push local 4
|
||||
push constant 32
|
||||
add
|
||||
push local 5
|
||||
push constant 16
|
||||
add
|
||||
push local 6
|
||||
push constant 32
|
||||
add
|
||||
push local 7
|
||||
push constant 16
|
||||
add
|
||||
push local 8
|
||||
push constant 32
|
||||
add
|
||||
push local 9
|
||||
push constant 16
|
||||
add
|
||||
push local 10
|
||||
push constant 32
|
||||
add
|
||||
push local 14
|
||||
call Piece.new 9
|
||||
pop local 1
|
||||
push local 1
|
||||
call Piece.draw 1
|
||||
pop temp 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
call Piece.getMove 1
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 15
|
||||
label WHILE_EXP2
|
||||
push local 15
|
||||
push constant 3
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
call Keyboard.keyPressed 0
|
||||
pop local 11
|
||||
push local 11
|
||||
push constant 130
|
||||
eq
|
||||
if-goto IF_TRUE2
|
||||
goto IF_FALSE2
|
||||
label IF_TRUE2
|
||||
push local 0
|
||||
call Piece.moveLeft 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE2
|
||||
push local 11
|
||||
push constant 132
|
||||
eq
|
||||
if-goto IF_TRUE3
|
||||
goto IF_FALSE3
|
||||
label IF_TRUE3
|
||||
push local 0
|
||||
call Piece.moveRight 1
|
||||
pop temp 0
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
label IF_FALSE3
|
||||
push local 11
|
||||
push constant 131
|
||||
eq
|
||||
if-goto IF_TRUE4
|
||||
goto IF_FALSE4
|
||||
label IF_TRUE4
|
||||
push local 0
|
||||
call Piece.rotate 1
|
||||
pop temp 0
|
||||
label IF_FALSE4
|
||||
push local 11
|
||||
push constant 133
|
||||
eq
|
||||
if-goto IF_TRUE5
|
||||
goto IF_FALSE5
|
||||
label IF_TRUE5
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
label IF_FALSE5
|
||||
push local 15
|
||||
push constant 1
|
||||
add
|
||||
pop local 15
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
call Piece.moveDown 1
|
||||
pop temp 0
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
push constant 80
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push constant 0
|
||||
pop local 2
|
||||
push local 0
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
call Tetris.completeRow 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
push constant 7
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 16
|
||||
push constant 32
|
||||
push constant 80
|
||||
push constant 96
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
not
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push local 1
|
||||
call Piece.dispose 1
|
||||
pop temp 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.completeRow 4
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 0
|
||||
push constant 15
|
||||
pop local 1
|
||||
label WHILE_EXP0
|
||||
push local 1
|
||||
push constant 0
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
not
|
||||
pop local 3
|
||||
push constant 0
|
||||
pop local 2
|
||||
label WHILE_EXP1
|
||||
push local 2
|
||||
push constant 10
|
||||
lt
|
||||
push local 3
|
||||
and
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push local 0
|
||||
push local 2
|
||||
add
|
||||
push local 1
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
add
|
||||
call Memory.peek 1
|
||||
push local 3
|
||||
and
|
||||
pop local 3
|
||||
push local 2
|
||||
push constant 1
|
||||
add
|
||||
pop local 2
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push local 3
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push constant 0
|
||||
call Screen.setColor 1
|
||||
pop temp 0
|
||||
push constant 176
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 335
|
||||
push local 1
|
||||
push constant 16
|
||||
call Math.multiply 2
|
||||
push constant 15
|
||||
add
|
||||
call Screen.drawRectangle 4
|
||||
pop temp 0
|
||||
push static 0
|
||||
push constant 1
|
||||
add
|
||||
pop static 0
|
||||
push local 1
|
||||
call Tetris.shift 1
|
||||
pop temp 0
|
||||
label IF_FALSE0
|
||||
push local 1
|
||||
push constant 1
|
||||
sub
|
||||
pop local 1
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.shift 5
|
||||
push constant 16384
|
||||
push constant 11
|
||||
add
|
||||
pop local 2
|
||||
label WHILE_EXP0
|
||||
push argument 0
|
||||
push constant 1
|
||||
gt
|
||||
not
|
||||
if-goto WHILE_END0
|
||||
push constant 0
|
||||
pop local 0
|
||||
label WHILE_EXP1
|
||||
push local 0
|
||||
push constant 10
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END1
|
||||
push constant 0
|
||||
pop local 4
|
||||
label WHILE_EXP2
|
||||
push local 4
|
||||
push constant 16
|
||||
lt
|
||||
not
|
||||
if-goto WHILE_END2
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
call Memory.peek 1
|
||||
pop local 1
|
||||
push local 2
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
push constant 512
|
||||
call Math.multiply 2
|
||||
push local 4
|
||||
push constant 32
|
||||
call Math.multiply 2
|
||||
add
|
||||
add
|
||||
push local 1
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 3
|
||||
push constant 0
|
||||
call Memory.poke 2
|
||||
pop temp 0
|
||||
push local 4
|
||||
push constant 1
|
||||
add
|
||||
pop local 4
|
||||
goto WHILE_EXP2
|
||||
label WHILE_END2
|
||||
push local 0
|
||||
push constant 1
|
||||
add
|
||||
pop local 0
|
||||
goto WHILE_EXP1
|
||||
label WHILE_END1
|
||||
push argument 0
|
||||
push constant 1
|
||||
sub
|
||||
pop argument 0
|
||||
goto WHILE_EXP0
|
||||
label WHILE_END0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.border 0
|
||||
push constant 175
|
||||
push constant 0
|
||||
push constant 175
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 336
|
||||
push constant 0
|
||||
push constant 336
|
||||
push constant 255
|
||||
call Screen.drawLine 4
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
function Tetris.newPiece 1
|
||||
push constant 9
|
||||
call Array.new 1
|
||||
pop local 0
|
||||
push constant 0
|
||||
push local 0
|
||||
add
|
||||
push argument 0
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 1
|
||||
push local 0
|
||||
add
|
||||
push argument 1
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 2
|
||||
push local 0
|
||||
add
|
||||
push argument 2
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 3
|
||||
push local 0
|
||||
add
|
||||
push argument 3
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 4
|
||||
push local 0
|
||||
add
|
||||
push argument 4
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 5
|
||||
push local 0
|
||||
add
|
||||
push argument 5
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 6
|
||||
push local 0
|
||||
add
|
||||
push argument 6
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 7
|
||||
push local 0
|
||||
add
|
||||
push argument 7
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push constant 8
|
||||
push local 0
|
||||
add
|
||||
push argument 8
|
||||
pop temp 0
|
||||
pop pointer 1
|
||||
push temp 0
|
||||
pop that 0
|
||||
push local 0
|
||||
return
|
||||
function Tetris.randomNumber 4
|
||||
push constant 7
|
||||
pop local 0
|
||||
push constant 13
|
||||
pop local 1
|
||||
push constant 1133
|
||||
pop local 2
|
||||
push local 0
|
||||
push static 1
|
||||
call Math.multiply 2
|
||||
push local 1
|
||||
add
|
||||
pop local 3
|
||||
push local 3
|
||||
push local 2
|
||||
call Tetris.mod 2
|
||||
pop static 1
|
||||
push static 1
|
||||
push constant 7
|
||||
call Tetris.mod 2
|
||||
return
|
||||
function Tetris.finish 1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 24
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 12
|
||||
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 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
push static 0
|
||||
call Output.printInt 1
|
||||
pop temp 0
|
||||
push constant 10000
|
||||
call Sys.wait 1
|
||||
pop temp 0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 10
|
||||
push constant 0
|
||||
call Output.moveCursor 2
|
||||
pop temp 0
|
||||
push constant 63
|
||||
call String.new 1
|
||||
push constant 87
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 117
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
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 105
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
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 112
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 103
|
||||
call String.appendChar 2
|
||||
push constant 97
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 44
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 121
|
||||
call String.appendChar 2
|
||||
push constant 101
|
||||
call String.appendChar 2
|
||||
push constant 115
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 108
|
||||
call String.appendChar 2
|
||||
push constant 105
|
||||
call String.appendChar 2
|
||||
push constant 99
|
||||
call String.appendChar 2
|
||||
push constant 107
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 89
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
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 100
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 102
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 114
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 110
|
||||
call String.appendChar 2
|
||||
push constant 111
|
||||
call String.appendChar 2
|
||||
push constant 32
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 78
|
||||
call String.appendChar 2
|
||||
push constant 39
|
||||
call String.appendChar 2
|
||||
push constant 58
|
||||
call String.appendChar 2
|
||||
call Output.printString 1
|
||||
pop temp 0
|
||||
call Keyboard.readChar 0
|
||||
pop local 0
|
||||
push local 0
|
||||
push constant 89
|
||||
eq
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
push constant 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push local 0
|
||||
push constant 78
|
||||
eq
|
||||
if-goto IF_TRUE1
|
||||
goto IF_FALSE1
|
||||
label IF_TRUE1
|
||||
call Screen.clearScreen 0
|
||||
pop temp 0
|
||||
call Sys.halt 0
|
||||
pop temp 0
|
||||
label IF_FALSE1
|
||||
push constant 0
|
||||
not
|
||||
return
|
||||
function Tetris.mod 2
|
||||
push argument 0
|
||||
push argument 1
|
||||
lt
|
||||
if-goto IF_TRUE0
|
||||
goto IF_FALSE0
|
||||
label IF_TRUE0
|
||||
push argument 0
|
||||
return
|
||||
label IF_FALSE0
|
||||
push argument 0
|
||||
push argument 1
|
||||
call Math.divide 2
|
||||
push argument 1
|
||||
call Math.multiply 2
|
||||
pop local 1
|
||||
push argument 0
|
||||
push local 1
|
||||
sub
|
||||
pop local 0
|
||||
push local 0
|
||||
return
|
||||
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: TextComparer.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%3"=="" goto :USAGE
|
||||
if "%1"=="/?" goto :USAGE
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
)
|
||||
if not "%~2"=="" (
|
||||
set "_arg2=%~f2"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
if NOT "%~1"=="" (
|
||||
if NOT "%~2"=="" (
|
||||
java -classpath "%CLASSPATH%;bin/classes" TextComparer ^
|
||||
"%_arg1%" "%_arg2%"
|
||||
popd
|
||||
exit /B
|
||||
)
|
||||
)
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo TextComparer FILE1 FILE2 Compares FILE1 and FILE2. The success
|
||||
echo message or the first miscompared line
|
||||
echo is printed to the command console.
|
||||
popd
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: TextComparer.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -ne 2 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
# print usage
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` FILE1 FILE2 Compares FILE1 and FILE2. The success"
|
||||
echo " message or the first miscompared line"
|
||||
echo " is printed to the command console."
|
||||
else
|
||||
# Convert arg1 to an absolute path
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="$dir/$1"
|
||||
fi
|
||||
# Convert arg2 to an absolute path
|
||||
if [ `echo "$2" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg2="$2"
|
||||
else
|
||||
arg2="$dir/$2"
|
||||
fi
|
||||
# echo Comparing "$arg1" "$arg2"
|
||||
java -classpath "${CLASSPATH}:bin/classes" TextComparer "$arg1" "$arg2"
|
||||
fi
|
||||
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
|
||||
rem $Id: VMEmulator.bat,v 1.3 2014/05/10 00:51:55 marka Exp $
|
||||
rem mark.armbrust@pobox.com
|
||||
|
||||
setlocal
|
||||
if not "%2"=="" goto :USAGE
|
||||
if "%~1"=="/?" (
|
||||
:USAGE
|
||||
echo Usage:
|
||||
echo VMEmulator Starts the VM Emulator in interactive mode.
|
||||
echo VMEmulator FILE.tst Starts the VM Emulator and runs the FILE.tst test
|
||||
echo script. The success/failure message is
|
||||
echo printed to the command console.
|
||||
exit -b
|
||||
)
|
||||
if not "%~1"=="" (
|
||||
set "_arg1=%~f1"
|
||||
)
|
||||
pushd "%~dp0"
|
||||
if "%~1"=="" (
|
||||
start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
VMEmulatorMain
|
||||
) else (
|
||||
rem echo Running "%_arg1%"
|
||||
java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
|
||||
VMEmulatorMain "%_arg1%"
|
||||
)
|
||||
popd
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# $Id: VMEmulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
|
||||
# mark.armbrust@pobox.com
|
||||
|
||||
# User's CDPATH can interfere with cd in this script
|
||||
unset CDPATH
|
||||
# Get the true name of this script
|
||||
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
|
||||
dir="$PWD"
|
||||
cd "`dirname "$script"`"
|
||||
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
|
||||
then
|
||||
echo "Usage:"
|
||||
echo " `basename "$0"` Starts the VM Emulator in interactive mode."
|
||||
echo " `basename "$0"` FILE.tst Starts the VM Emulator and runs the FILE.tst test"
|
||||
echo " script. The success/failure message is"
|
||||
echo " printed to the command console."
|
||||
elif [ $# -eq 0 ]
|
||||
then
|
||||
# Run VM emulator in interactive mode
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" VMEmulatorMain &
|
||||
else
|
||||
# Convert arg1 to an absolute path and run VM emulator with arg1
|
||||
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
|
||||
then
|
||||
arg1="$1"
|
||||
else
|
||||
arg1="${dir}/$1"
|
||||
fi
|
||||
# echo Running "$arg1"
|
||||
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" VMEmulatorMain "$arg1"
|
||||
fi
|
||||
@@ -0,0 +1 @@
|
||||
C:\Users\SQA-AGrudev\Desktop\nand2tetris\projects\08\ProgramFlow\BasicLoop\BasicLoop.hack
|
||||
@@ -0,0 +1 @@
|
||||
C:\Users\SQA-AGrudev\Desktop\nand2tetris\projects\08\FunctionCalls\NestedCall
|
||||
@@ -0,0 +1 @@
|
||||
C:\Users\Andrean\Desktop\nand2tetris\projects\03\a
|
||||
@@ -0,0 +1 @@
|
||||
C:\Users\SQA-AGrudev\Desktop\nand2tetris\projects\09\Tetris
|
||||
@@ -0,0 +1,96 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 10">
|
||||
<meta name=Originator content="Microsoft Word 10">
|
||||
<link rel=File-List href="asmAbout_files/filelist.xml">
|
||||
<title>About Assembler</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:8.5in 11.0in;
|
||||
margin:1.0in 1.25in 1.0in 1.25in;
|
||||
mso-header-margin:.5in;
|
||||
mso-footer-margin:.5in;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0in 5.4pt 0in 5.4pt;
|
||||
mso-para-margin:0in;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:.5in'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>Assembler, Version 2.5</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'>This program is
|
||||
part of www.nand2tetris.org<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>and</span>
|
||||
the book "The Elements of Computing Systems"<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>by</span>
|
||||
Nisan and Schocken, MIT Press.</p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,115 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 11">
|
||||
<meta name=Originator content="Microsoft Word 11">
|
||||
<link rel=File-List href="asmUsage_files/filelist.xml">
|
||||
<title>Usage instruction and tips can be found in:</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:ValidateAgainstSchemas/>
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:612.0pt 792.0pt;
|
||||
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
||||
mso-header-margin:36.0pt;
|
||||
mso-footer-margin:36.0pt;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:36.0pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Usage instruction and tips can be found in:</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Assembler Tutorial</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'> </span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Available in www.nand2tetris.org</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>And in relevant book chapters from </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Elements of Computing Systems,<o:p></o:p></span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>by Noam Nisan and Shimon Schocken</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>MIT Press</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
Jack Compiler, Version 2.5
|
||||
|
||||
This program is part of www.nand2tetris.org
|
||||
and the book "The Elements of Computing Systems"
|
||||
by Nisan and Schocken, MIT Press.
|
||||
|
||||
Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski
|
||||
|
||||
Usage instruction and tips can be found in the relevant book chapters.
|
||||
@@ -0,0 +1,96 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 10">
|
||||
<meta name=Originator content="Microsoft Word 10">
|
||||
<link rel=File-List href="cpuAbout_files/filelist.xml">
|
||||
<title>About CPU Emulator</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:8.5in 11.0in;
|
||||
margin:1.0in 1.25in 1.0in 1.25in;
|
||||
mso-header-margin:.5in;
|
||||
mso-footer-margin:.5in;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0in 5.4pt 0in 5.4pt;
|
||||
mso-para-margin:0in;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:.5in'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>CPU Emulator, Version 2.5</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'>This program is
|
||||
part of www.nand2tetris.org<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>and</span>
|
||||
the book "The Elements of Computing Systems"<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>by</span>
|
||||
Nisan and Schocken, MIT Press.</p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,115 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 11">
|
||||
<meta name=Originator content="Microsoft Word 11">
|
||||
<link rel=File-List href="cpuUsage_files/filelist.xml">
|
||||
<title>Usage instruction and tips can be found in:</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:ValidateAgainstSchemas/>
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:612.0pt 792.0pt;
|
||||
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
||||
mso-header-margin:36.0pt;
|
||||
mso-footer-margin:36.0pt;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:36.0pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Usage instruction and tips can be found in:</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The CPU Emulator Tutorial</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'> </span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Available in www.nand2tetris.org</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>And in relevant book chapters from </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Elements of Computing Systems,<o:p></o:p></span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>by Noam Nisan and Shimon Schocken</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>MIT Press</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,96 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 10">
|
||||
<meta name=Originator content="Microsoft Word 10">
|
||||
<link rel=File-List href="hwAbout_files/filelist.xml">
|
||||
<title>About Hardware Simulator</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0in;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:8.5in 11.0in;
|
||||
margin:1.0in 1.25in 1.0in 1.25in;
|
||||
mso-header-margin:.5in;
|
||||
mso-footer-margin:.5in;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0in 5.4pt 0in 5.4pt;
|
||||
mso-para-margin:0in;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:.5in'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>Hardware Simulator, Version 2.5</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'>This program is
|
||||
part of www.nand2tetris.org<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>and</span>
|
||||
the book "The Elements of Computing Systems"<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>by</span>
|
||||
Nisan and Schocken, MIT Press.</p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Software Architects: Yaron Ukrainitz and Yannai A. Gonczarowski</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,115 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 11">
|
||||
<meta name=Originator content="Microsoft Word 11">
|
||||
<link rel=File-List href="hwUsage_files/filelist.xml">
|
||||
<title>Usage instruction and tips can be found in:</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:ValidateAgainstSchemas/>
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:612.0pt 792.0pt;
|
||||
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
||||
mso-header-margin:36.0pt;
|
||||
mso-footer-margin:36.0pt;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:36.0pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Usage instruction and tips can be found in:</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Hardware Simulator Tutorial</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'> </span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Available in www.nand2tetris.org</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>And in relevant book chapters from </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Elements of Computing Systems,<o:p></o:p></span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>by Noam Nisan and Shimon Schocken</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>MIT Press</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,110 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 11">
|
||||
<meta name=Originator content="Microsoft Word 11">
|
||||
<link rel=File-List href="vmAbout_files/filelist.xml">
|
||||
<title>About Virtual Machine Emulator</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:ValidateAgainstSchemas/>
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
span.GramE
|
||||
{mso-style-name:"";
|
||||
mso-gram-e:yes;}
|
||||
@page Section1
|
||||
{size:612.0pt 792.0pt;
|
||||
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
||||
mso-header-margin:36.0pt;
|
||||
mso-footer-margin:36.0pt;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:36.0pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>Virtual Machine Emulator, Version 2.5</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'>This program is
|
||||
part of www.nand2tetris.org<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>and</span>
|
||||
the book "The Elements of Computing Systems"<o:p></o:p></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span class=GramE>by</span>
|
||||
Nisan and Schocken, MIT Press.</p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Software Architects: Yaron Ukrainitz and Yannai A.
|
||||
Gonczarowski</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,115 @@
|
||||
<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
|
||||
<meta name=ProgId content=Word.Document>
|
||||
<meta name=Generator content="Microsoft Word 11">
|
||||
<meta name=Originator content="Microsoft Word 11">
|
||||
<link rel=File-List href="vmUsage_files/filelist.xml">
|
||||
<title>Usage instruction and tips can be found in:</title>
|
||||
<!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:GrammarState>Clean</w:GrammarState>
|
||||
<w:ValidateAgainstSchemas/>
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]-->
|
||||
<style>
|
||||
<!--
|
||||
/* Style Definitions */
|
||||
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||
{mso-style-parent:"";
|
||||
margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:12.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
|
||||
{margin:0cm;
|
||||
margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:13.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";}
|
||||
@page Section1
|
||||
{size:612.0pt 792.0pt;
|
||||
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
||||
mso-header-margin:36.0pt;
|
||||
mso-footer-margin:36.0pt;
|
||||
mso-paper-source:0;}
|
||||
div.Section1
|
||||
{page:Section1;}
|
||||
-->
|
||||
</style>
|
||||
<!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:"Table Normal";
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body lang=EN-US style='tab-interval:36.0pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Usage instruction and tips can be found in:</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The VM Emulator Tutorial</span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'> </span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>Available in www.nand2tetris.org</span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'> </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>And in relevant book chapters from </span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><b><span
|
||||
style='font-size:12.0pt'>The Elements of Computing Systems,<o:p></o:p></span></b></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>by Noam Nisan and Shimon Schocken<b><o:p></o:p></b></span></p>
|
||||
|
||||
<p class=MsoBodyText align=center style='text-align:center'><span
|
||||
style='font-size:12.0pt'>MIT Press</span></p>
|
||||
|
||||
<p class=MsoNormal> </p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 302 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1014 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1017 B |
|
After Width: | Height: | Size: 988 B |
|
After Width: | Height: | Size: 920 B |
|
After Width: | Height: | Size: 930 B |
|
After Width: | Height: | Size: 969 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 949 B |
|
After Width: | Height: | Size: 946 B |
|
After Width: | Height: | Size: 898 B |
|
After Width: | Height: | Size: 863 B |
|
After Width: | Height: | Size: 1000 B |
|
After Width: | Height: | Size: 925 B |
|
After Width: | Height: | Size: 873 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1021 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 972 B |