[04/fill] Done with Automated screen fill

Updated NOTES
This commit is contained in:
Nemo 2020-05-28 16:45:38 +05:30
parent 25e828ec9d
commit e85ff27425
4 changed files with 204 additions and 210 deletions

View File

@ -8,3 +8,33 @@ RAM64
RAM512 RAM512
: I used the premise of the previous note and decided to index the RAM64 moduls by the LSB instead of the customary MSB. It still works :metal: : I used the premise of the previous note and decided to index the RAM64 moduls by the LSB instead of the customary MSB. It still works :metal:
Fill.asm
: Figured out that my RAM16K implementation was wrong while working on this. The rough pseudocode would be:
```c
int r0=*screen;
while(true) {
int color = 0;
if (*kbd > 0) {
color = -1;
}
// This sets an entire row of pixels to color
// each row has 32 registers (512/16) that we set to color
*r0 = color;
*r0+1 = color;
*r0+2 = color;
*r0+3 = color;
*r0+4 = color;
// and so on
*r0+31 = color;
// if we are on the last row
if (r0-24575 <=0) {
r0 = *screen;
}
}
```
So every "cycle" of the loop, we are coloring an entire row. The row is decided by R0, which is set to @SCREEN at the start. So if you press a key while we are on the middle of the loop (say 120th row), everything from that row onwards would get painted in black, and then the loop resets r0=*screen once we cross the limits. The next iteration of the loop then starts filling the white pixels we'd left in the previous iteration. I kept the smallest paint unit as the row, but it doesn't really matter that much. The only difference is that I'm reading kbd a total of 256 times to paint the screen. Reading once per register also would work, and reading once per "screenfill" would also work. But that changes the 'delay' b/w your keyboard press and the screen fill start. I thought per row was a good compromise.
**assembly**: Since our assembly doesn't have any functions, writing Assembly is much tougher than I thought it would be. All state is global, there are no functions, and you can only jump using goto.

View File

@ -11,10 +11,13 @@
// "white" in every pixel; // "white" in every pixel;
// the screen should remain fully clear as long as no key is pressed. // the screen should remain fully clear as long as no key is pressed.
// Set i to 255 // See NOTES.md for details on how this works
@255
(PROGRAM_START)
// Set R0 to SCREEN
@SCREEN
D=A D=A
@i @R0
M=D M=D
(KEYBOARD_LOOP) (KEYBOARD_LOOP)
@ -36,47 +39,107 @@ M=D
// At this point @color = 0|-1 depending on whether a key is pressed // At this point @color = 0|-1 depending on whether a key is pressed
// This is adapted from manual-fill.asm
// coloring code goes here // coloring code goes here
// Read color to D
@color @color
D=M D=M
@SCREEN // Load the value in R0 to A
@R0
A=M
// And off we go hunting
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D
A=A+1
M=D M=D
// Keyboard Loop ending // Keyboard Loop ending
// Reduce i by 1 // Bump A by 1 and write it to R0
@i A=A+1
M=M-1
// Jump to ENDIF if @i>0
@i
D=M
@ENDIF
D;JGT
// Here i==0, so we reset it to 255
@255
D=A D=A
@i @R0
M=D M=D
// If R0-24575 <= 0, then jump to program start
@24575
D=A
@R0
D=M-D // (D=R0-24575)
@ENDIF
D;JLE
// Here, R1 is negative
// set R0=@SCREEN and let the loop continue
@SCREEN
D=A
@R0
M=D
(ENDIF) (ENDIF)
// OTHERWISE, we just restart the keyboard loop
@KEYBOARD_LOOP @KEYBOARD_LOOP
0;JMP 0;JMP
// @WRITE_COMPLETE_ROW
// 0;JMP
(END)
@END
0;JMP

View File

@ -1,8 +1,8 @@
0000000011111111 0100000000000000
1110110000010000 1110110000010000
0000000000010000 0000000000000000
1110001100001000 1110001100001000
0000000000010001 0000000000010000
1110101010001000 1110101010001000
0110000000000000 0110000000000000
1111110000010000 1111110000010000
@ -11,188 +11,88 @@
0000000000000000 0000000000000000
1110110000010000 1110110000010000
1110001110010000 1110001110010000
0000000000010001
1110001100001000
1110101010010000
0000000000010000 0000000000010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
1111000010010000
0100000000000000
1110000010110000
0000000000010010
1110001100001000 1110001100001000
0000000000010000 0000000000010000
1111110000010000 1111110000010000
0000000000111101 0000000000000000
1110001100000001 1111110000100000
0000000011111111 1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110001100001000
1110110111100000
1110110000010000 1110110000010000
0000000000010000 0000000000000000
1110001100001000 1110001100001000
0000000000010001 0101111111111111
1111110000010000 1110110000010000
0000000000010010 0000000000000000
1111110000100000 1111000111010000
0000000001100000
1110001100000110
0100000000000000
1110110000010000
0000000000000000
1110001100001000 1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010010
1111110111100000
1111110000100000
1110001100001000
0000000000010000
1111110010001000
0000000000000100 0000000000000100
1110101010000111 1110101010000111

View File

@ -1,3 +1,4 @@
|RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]| |RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| -1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |