.
@@ -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 |
@@ -0,0 +1,3 @@
|
||||
repeat {
|
||||
ticktock;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
repeat {
|
||||
tick,
|
||||
tock;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
repeat {
|
||||
vmstep;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/ALU.hdl
|
||||
|
||||
/**
|
||||
* The ALU. Computes one of the following functions:
|
||||
* x+y, x-y, y–x, 0, 1, -1, x, y, -x, -y, !x, !y,
|
||||
* x+1, y+1, x-1, y-1, x&y, x|y on two 16-bit inputs.
|
||||
* Which function to compute is determined by 6 input bits
|
||||
* denoted zx, nx, zy, ny, f, no.
|
||||
* The computed function's value is called "out".
|
||||
* In addition to computing out, the ALU computes two
|
||||
* 1-bit outputs called zr and ng:
|
||||
* if out == 0, zr = 1; otherwise zr = 0;
|
||||
* If out < 0, ng = 1; otherwise ng = 0.
|
||||
* The 6-bit combinations (zx,nx,zy,ny,f,no) and
|
||||
* their effect are documented in the book.
|
||||
*/
|
||||
|
||||
// Implementation: the ALU manipulates the x and y
|
||||
// inputs and then operates on the resulting values,
|
||||
// as follows:
|
||||
// if (zx == 1) sets x = 0 // 16-bit constant
|
||||
// if (nx == 1) sets x = ~x // bitwise "not"
|
||||
// if (zy == 1) sets y = 0 // 16-bit constant
|
||||
// if (ny == 1) sets y = ~y // bitwise "not"
|
||||
// if (f == 1) sets out = x + y // integer 2's-complement addition
|
||||
// if (f == 0) sets out = x & y // bitwise And
|
||||
// if (no == 1) sets out = ~out // bitwise Not
|
||||
// if (out == 0) sets zr = 1
|
||||
// if (out < 0) sets ng = 1
|
||||
|
||||
|
||||
CHIP ALU {
|
||||
|
||||
IN // 16-bit inputs:
|
||||
x[16], y[16],
|
||||
// Control bits:
|
||||
zx, // Zero the x input
|
||||
nx, // Negate the x input
|
||||
zy, // Zero the y input
|
||||
ny, // Negate the y input
|
||||
f, // Function code: 1 for add, 0 for and
|
||||
no; // Negate the out output
|
||||
|
||||
OUT // 16-bit output
|
||||
out[16],
|
||||
|
||||
// ALU output flags
|
||||
zr, // 1 if out=0, 0 otherwise
|
||||
ng; // 1 if out<0, 0 otherwise
|
||||
|
||||
BUILTIN ALU;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/ARegister.hdl
|
||||
|
||||
/**
|
||||
* A 16-Bit register called "A Register".
|
||||
* If load[t-1]=1 then out[t] = in[t-1]
|
||||
* else out does not change (out[t] = out[t-1])
|
||||
*
|
||||
* This built-in chip implementation has the side effect of
|
||||
* providing a GUI representation of a 16-bit register
|
||||
* called "A register" (typically used to store an address).
|
||||
*/
|
||||
|
||||
CHIP ARegister {
|
||||
|
||||
IN in[16], load;
|
||||
OUT out[16];
|
||||
|
||||
BUILTIN ARegister;
|
||||
CLOCKED in, load;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/Add16.hdl
|
||||
|
||||
/*
|
||||
* Adds two 16-bit values.
|
||||
* The most significant carry bit is ignored.
|
||||
*/
|
||||
|
||||
CHIP Add16 {
|
||||
|
||||
IN a[16], b[16];
|
||||
OUT out[16];
|
||||
|
||||
BUILTIN Add16;
|
||||
}
|
||||
|
||||
@@ -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: tools/builtIn/And.hdl
|
||||
|
||||
/**
|
||||
* And gate: out = 1 if {a == 1 and b == 1}, 0 otherwise
|
||||
*/
|
||||
|
||||
CHIP And {
|
||||
|
||||
IN a, b;
|
||||
OUT out;
|
||||
|
||||
BUILTIN And;
|
||||
}
|
||||
@@ -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: tools/builtIn/And16.hdl
|
||||
|
||||
/**
|
||||
* 16-bit-wise And gate: for i = 0..15: out[i] = a[i] and b[i]
|
||||
*/
|
||||
|
||||
CHIP And16 {
|
||||
|
||||
IN a[16], b[16];
|
||||
OUT out[16];
|
||||
|
||||
BUILTIN And;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/Bit.hdl
|
||||
|
||||
/**
|
||||
* 1-bit register.
|
||||
* If load[t] == 1 then out[t+1] = in[t]
|
||||
* else out[t+1] = out[t] (no change)
|
||||
*/
|
||||
|
||||
CHIP Bit {
|
||||
|
||||
IN in, load;
|
||||
OUT out;
|
||||
|
||||
BUILTIN Bit;
|
||||
CLOCKED in, load;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/DFF.hdl
|
||||
|
||||
/**
|
||||
* Data Flip-flop: out(t) = in(t-1)
|
||||
* where t is the current time unit, or clock cycle.
|
||||
*/
|
||||
|
||||
CHIP DFF {
|
||||
|
||||
IN in;
|
||||
OUT out;
|
||||
|
||||
BUILTIN DFF;
|
||||
CLOCKED in;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/DMux.hdl
|
||||
|
||||
/**
|
||||
* Dmultiplexor.
|
||||
* {a,b} = {in,0} if sel == 0
|
||||
* {0,in} if sel == 1
|
||||
*/
|
||||
|
||||
|
||||
CHIP DMux {
|
||||
|
||||
IN in, sel;
|
||||
OUT a, b;
|
||||
|
||||
BUILTIN DMux;
|
||||
}
|
||||
|
||||