summaryrefslogtreecommitdiff
path: root/projects/04/misc/rect.asm
blob: 3106f04fae318e682f70b0e1b464ff1287f749c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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