summaryrefslogtreecommitdiff
path: root/projects/04/misc/rect.asm
diff options
context:
space:
mode:
Diffstat (limited to 'projects/04/misc/rect.asm')
-rw-r--r--projects/04/misc/rect.asm95
1 files changed, 95 insertions, 0 deletions
diff --git a/projects/04/misc/rect.asm b/projects/04/misc/rect.asm
new file mode 100644
index 0000000..3106f04
--- /dev/null
+++ b/projects/04/misc/rect.asm
@@ -0,0 +1,95 @@
+@R0
+D=M
+@width
+M=D // width (max 32) = RAM[0] words = 16 * RAM[0] px
+
+@32
+D=A
+@width
+D=D-M // D = 32 - width
+@WIDTH_PASS
+D;JGE // if (D >= 0, i.e. width <= 32) goto WIDTH_PASS
+
+@32
+D=A
+@width
+M=D // width = 32
+
+(WIDTH_PASS)
+
+@R1
+D=M
+@height
+M=D // height (max 256) = RAM[1] px
+
+@256
+D=A
+@height
+D=D-M // D = 256 - height
+@HEIGHT_PASS
+D;JGE // if (D >= 0, i.e. height <= 256) goto HEIGHT_PASS
+
+@256
+D=A
+@height
+M=D
+
+(HEIGHT_PASS)
+
+@32
+D=A
+@offset
+M=D // offset = 32
+@width
+D=M
+@offset
+M=M-D // offset -= width
+
+@x
+M=0 // x = 0
+
+@y
+M=0 // y = 0
+
+@SCREEN
+D=A
+@pos
+M=D // pos = &SCREEN
+
+(DRAW_Y)
+ (DRAW_X)
+ @pos
+ A=M
+ M=-1 // *pos = 0xffff
+ @pos
+ M=M+1 // pos++
+ @x
+ M=M+1 // x++
+ D=M // D = x
+ @width
+ D=D-M // D = x - width
+ @EXIT_X
+ D;JEQ // if (x - width == 0) break
+ @DRAW_X
+ 0;JMP
+ (EXIT_X)
+ @x
+ M=0;
+ @offset
+ D=M
+ @pos
+ M=M+D // pos += offset
+ @y
+ M=M+1 // y++
+ D=M // D = y
+ @height
+ D=D-M // D = y - height
+ @END
+ D;JEQ // if (y - height == 0) break
+ @DRAW_Y
+ 0;JMP
+
+(END)
+ @END
+ 0;JMP
+