all repos — nand2tetris @ 830f9925962642fd137c1e90b9c9c4f33a167c30

my nand2tetris progress

Re-do Fill.asm (TODO optimize later)
x1phosura x1phosura@x1phosura.zone
Sun, 12 Dec 2021 02:00:54 -0800
commit

830f9925962642fd137c1e90b9c9c4f33a167c30

parent

cd6d60e361f05422bdada321e09e6b1d48e11d16

1 files changed, 61 insertions(+), 1 deletions(-)

jump to
M projects/04/fill/Fill.asmprojects/04/fill/Fill.asm

@@ -11,4 +11,64 @@ // When no key is pressed, the program clears the screen, i.e. writes

// "white" in every pixel; // the screen should remain fully clear as long as no key is pressed. -// Put your code here.+// Put your code here. + +// TODO: optimize better in the future + +(SET_SCREEN_PTR) + // R0 = SCREEN pointer + @SCREEN + D=A + @R0 + M=D + +// TODO: fix infinitely incrementing screen pointer bug +// end of screen: 0x5fff (dec 24575) + +(IS_KEYPRESSED) + // if R0 == 24575; goto SET_SCREEN_PTR + @R0 + D=M + @24575 + D=D-A + @SET_SCREEN_PTR + D;JEQ + + // D=KBD, goto WHITE_SCREEN if D == 0 + @KBD + D=M + @WHITE_SCREEN + D;JEQ + +(BLACK_SCREEN) + // *R0 = -1 + @R0 + A=M + M=-1 + + // ++R0 + @R0 + M=M+1 + + @IS_KEYPRESSED + 0;JMP + // TODO: replace with D;JLT or something + +(WHITE_SCREEN) + // *R0 = 0 + @R0 + A=M + M=0 + + // ++R0 + @R0 + M=M+1 + + @IS_KEYPRESSED + 0;JMP + // TODO: replace with D;JLT or something + +(END) + @END + 0;JMP +