added v2.0

This commit is contained in:
Michael Schröder
2023-01-11 11:13:09 +01:00
parent 2a5a64ca91
commit 971b323822
584 changed files with 159319 additions and 0 deletions

View File

@@ -0,0 +1 @@
../Array.jack

View File

@@ -0,0 +1 @@
../GPIO.jack

View File

@@ -0,0 +1,42 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/12/MemoryTest/Main.jack
/** Test program for the OS Memory class. */
class Main {
/** Performs various memory manipulations. */
function void main() {
var int temp;
var Array a, b, c;
do Memory.poke(4107, 333); // RAM[4107] = 333
let temp = Memory.peek(4107);
do Memory.poke(4108, temp + 1); // RAM[4108] = 334
let a = Array.new(3); // uses Memory.alloc
let a[2] = 222;
do Memory.poke(4109, a[2]); // RAM[4109] = 222
let b = Array.new(3);
let b[1] = a[2] - 100;
do Memory.poke(4110, b[1]); // RAM[4110] = 122
let c = Array.new(500);
let c[499] = a[2] - b[1];
do Memory.poke(4111, c[499]); // RAM[4111] = 100
do a.dispose(); // uses Memory.deAlloc
do b.dispose();
let b = Array.new(3);
let b[0] = c[499] - 90;
do Memory.poke(4107, b[0]); // RAM[4107] = 10
do c.dispose();
do b.dispose();
return;
}
}

View File

@@ -0,0 +1,18 @@
all: jack vm asm bin sim
jack:
../../tools/JackCompiler/JackCompiler.pyc ./
vm:
../../tools/VMTranslator/VMTranslator.pyc ./
asm:
../../tools/Assembler/assembler.pyc out.asm
bin:
../../tools/AsciiToBin.py out.hack
sim:
cp out.hack ../00_HACK/ROM.hack
upload:
iceprogduino -o 64k -w out.bin
clean:
rm -f *.vm *.asm *.hack *.bin *~
.PHONY: all clean

View File

@@ -0,0 +1 @@
../Memory.jack

View File

@@ -0,0 +1,2 @@
|RAM[8000]|RAM[8001]|RAM[8002]|RAM[8003]|RAM[8004]|RAM[8005]|
| 333 | 334 | 222 | 122 | 100 | 10 |

View File

@@ -0,0 +1,15 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/12/MemoryTest/MemoryTest.tst
load,
output-file MemoryTest.out,
compare-to MemoryTest.cmp,
output-list RAM[8000]%D2.6.1 RAM[8001]%D2.6.1 RAM[8002]%D2.6.1 RAM[8003]%D2.6.1 RAM[8004]%D2.6.1 RAM[8005]%D2.6.1;
repeat 1000000 {
vmstep;
}
output;

View File

@@ -0,0 +1,33 @@
## Memory.jack
This library provides two services: direct access to the computer's main memory (RAM), and allocation and recycling of memory blocks. The Hack RAM consists of 3840 words, each holding a 16-bit binary number.
Don't be afraid of the limited memory size of "only" 3840 words. Let the heap start at address 1024 with `do Memory.init(1024,3839)` in the Sys.init(). This will leave 768 words of stack, which is surely enough to run tetris.
| addr | segment |
| --------- | ----------------------------- |
| 0-15 | R0-R15 (SP,LCL,ARG,THIS,THAT) |
| 16-255 | static |
| 256-1023 | stack |
| 1024-3839 | heap |
| 4096-4111 | IO-devices |
***
### Project
* Implement `Memory.jack`
* Test in simulation:
```
$ cd 04_Memory_Test
$ make
$ cd ../00_HACK
$ apio clean
$ apio sim
```
* Check the content of special function register DEBUG0--DEBUG4.
![](memory.png)

View File

@@ -0,0 +1,28 @@
## Memory.jack
This library provides two services: direct access to the computer's main memory (RAM), and allocation and recycling of memory blocks. The Hack RAM consists of 3840 words, each holding a 16-bit binary number.
### function void init(int start, int end)
Initializes the class. First address of heap is start, last address of heap is end.
### function int peek(int address)
Returns the RAM value at the given address.
### function void poke(int address, int value)
Sets the RAM value at the given address to the given value.
### function int alloc(int size)
Finds an available RAM block of the given size and returns a reference to its base address.
### function void deAlloc(Array o)
De-allocates the given object (cast as an array) by making it available for future allocations.
***
### Project
* Implement `Memory.jack`
* Test in simulation:
```
$ cd 04_Memory_Test
$ make
$ cd ../00_HACK
$ apio clean
$ apio sim
```
* Check the content of special function register DEBUG0--DEBUG4.
![](memory.png)

View File

@@ -0,0 +1 @@
../Sys.jack

View File

@@ -0,0 +1 @@
../UART.jack

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB