Created
April 28, 2022 11:04
-
-
Save AndyPro720/3b02c12025dea3701655c08528d2f2aa to your computer and use it in GitHub Desktop.
Screen Fill on key press, project 4, part 1 (N2T)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@state | |
M=0; //state is 0 at start(screen white) | |
(ILOOP) | |
@SCREEN | |
D=A | |
@d_add | |
M=D //SCREEN(add)=d_add | |
@KBD | |
D=M //checks for KBD scan code, feeds in D | |
@PRESSED | |
D;JNE //change current state to -1, else current state 0 | |
@c_state | |
M=0; //else current state 0 | |
(SUB) //checks if current state is same as old | |
@state | |
D=M; | |
@c_state | |
D=M-D; //state - current state = D | |
@ILOOP | |
D;JEQ //if state = current state, goto ILOOP | |
@state | |
M=!M //else, state is flipped(same as, state = current state) | |
@24575 //last screen address | |
D=A | |
@i | |
M=D //i=8192 | |
(LOOP) | |
@i | |
D=M //D=i | |
@ILOOP | |
D;JLE //if i<=0; goto ILOOP | |
@state // change from state to *KBD* for quicker updates, but KBD might update (if processing speed is slow) from the state and run half or either loop | |
D=M; | |
@BLACK | |
D;JNE //if D!=0; goto black, else white | |
(WHITE) | |
@i | |
AD=M //set display address as A | |
M=0 //set the selected register to 0 | |
A=D-1 | |
M=0 | |
@2 | |
D=A | |
@i | |
M=M-D //i-- | |
@LOOP | |
0;JMP //goto LOOP | |
(BLACK) //same as while, but set register to -1 | |
@i | |
AD=M | |
M=-1 | |
A=D-1 | |
M=-1 | |
@2 | |
D=A | |
@i | |
M=M-D | |
@LOOP | |
0;JMP | |
(PRESSED) | |
@c_state | |
M=-1 | |
@SUB | |
0;JMP | |
//scope: when (black) or (white) is runnning and mode is switched before completion, the remaning loop should run in reverse to earse/write remaining. (instead of starting over again) | |
//the M-1 and M-2 was me trying to find a marginal difference in reducing the instructions before the next register print, to see a perfomance gain. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea is such,
when the state is same, the writing to registers in loop doesn't occur. (this isn't in a improvement in speed but just reducing processing overhead)
Rest is pretty much straightforward. The last part with M-2 was an experiment, as mentioned in last comment