+/TECS

git clone https://git.julia.blue/+/TECS

P1n3appl3Remove headers5e97a3a

master
1.4 KiB34 linesraw
1/**
2 * The complete address space of the Hack computer's memory,
3 * including RAM and memory-mapped I/O. 
4 * The chip facilitates read and write operations, as follows:
5 *     Read:  out(t) = Memory[address(t)](t)
6 *     Write: if load(t-1) then Memory[address(t-1)](t) = in(t-1)
7 * In words: the chip always outputs the value stored at the memory 
8 * location specified by address. If load==1, the in value is loaded 
9 * into the memory location specified by address. This value becomes 
10 * available through the out output from the next time step onward.
11 * Address space rules:
12 * Only the upper 16K+8K+1 words of the Memory chip are used. 
13 * Access to address>0x6000 is invalid. Access to any address in 
14 * the range 0x4000-0x5FFF results in accessing the screen memory 
15 * map. Access to address 0x6000 results in accessing the keyboard 
16 * memory map. The behavior in these addresses is described in the 
17 * Screen and Keyboard chip specifications given in the book.
18 */
19
20CHIP Memory {
21    IN in[16], load, address[15];
22    OUT out[16];
23
24    PARTS:
25    Not(in=address[14],out=w1);
26    And(a=w1,b=load,out=w2);
27    And(a=address[14],b=load,out=w7);
28    RAM16K(in=in,load=w2,address=address[0..13],out=w3);
29    Screen(in=in,load=w7,address=address[0..12],out=w4);
30    Keyboard(out=w5);
31    Mux16(a=w3,b=w4,sel=address[14],out=w6);
32    And(a=address[13],b=address[14],out=w8);
33    Mux16(a=w6,b=w5,sel=w8,out=out); 
34}