-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing.asm
178 lines (141 loc) · 3.41 KB
/
drawing.asm
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;
; Board coords - coordinates according to squares.
; Each square has its own coordinate top left is (0, 0)
;
; Screen coords - coordinates according to pixels on screen
;
;
;
; bx: X - Screen coords
; dx: Y - Screen coords
; al: Color
; Draws pixel at the coordinates of x,y with the color
proc ColorPixel
doPush ax,bx,cx,dx,es
push ax
mov ax, 0A000H; Initialize Segement for coloring
mov es, ax
mov ax, 0000H
;n * 320 == n * ( 256 + 64) == n * (2^6 + 2^8) == n*2^6 + n*2^8
mov ax, dx; Store y for calculation
shl dx, 6; n * 2^6
shl ax, 8; n * 2^8
add ax, dx
add ax, bx; n*2^6 + n*2^8
mov di,ax
pop ax
mov [es:di], al
doPop es,dx,cx,bx,ax
ret
endp ColorPixel
;dx: Y for line - Screen coords
;al: Color
;Draws horizontal line from 0 to LEN_HORIZONTAL go to vars file for explanation for LEN_HORIZONTAL
proc DrawLineHorizontal
doPush ax,bx,cx,dx
mov cx, [LEN_HORIZONTAL]
loopForLineHoriz:
mov bx,cx
dec bx; Decrement bx to include 0
call ColorPixel
loop loopForLineHoriz
doPop dx,cx,bx,ax
ret
endp DrawLineHorizontal
;bx: X for line - screen coords
;al: Color
;Draws vertical line from 0 to LEN_VERTICAL go to vars file for explanation for LEN_VERTICAL
proc DrawLineVertical
doPush ax,bx,cx,dx
mov cx, [LEN_VERTICAL]
loopForLineVert:
mov dx,cx
dec dx
call ColorPixel
loop loopForLineVert
doPop dx,cx,bx,ax
ret
endp DrawLineVertical
;Draws grid based on square size
proc DrawGrid
doPush ax,bx,cx,dx
mov cx,[AMOUNT_OF_SQUARES_VERTICAL]; Amount of lines to draw
mov dx, 0000H
inc cx; Inc because zero is not included in loop
mov al, LINE_COLOR
drawGridLoopHoriz:
call DrawLineHorizontal
add dx,[SQUARE_SIZE]
loop drawGridLoopHoriz
mov cx,[AMOUNT_OF_SQUARES_HORIZONTAL]
mov bx, 0000H
inc cx
mov al, LINE_COLOR
drawGridLoopVert:
call DrawLineVertical
add bx,[SQUARE_SIZE]
loop drawGridLoopVert
;Draw bottom right corner because it is not included in the lines
mov bx, [LEN_HORIZONTAL]
mov dx, [LEN_VERTICAL]
call ColorPixel
doPop dx,cx,bx,ax
ret
endp DrawGrid
;ax: X - Board coords
;dx: Y - Board coords
;SquareColor: Color of square
;Draws a square at coordinates in the color of whatever is stored in SquareColor
proc DrawSquare
doPush ax,bx,cx,dx
push dx
mul [SQUARE_SIZE]; Convert ax(X value) from board coords to screen coords by multiplication
pop dx
inc ax; inc to not include left line
push ax; Push calculated ax because we need it for multiplication
mov ax,dx
mul [SQUARE_SIZE]; Convert dx (Y value) from board coords to screen coords by multiplication
mov dx,ax
inc dx; inc for not including upper line
pop ax; Return calculated ax from stack to ax
mov cx, [SQUARE_SIZE]; Amount of loops for outer loop
dec cx; Dec for not including line
outerLoopDrawSquare:
push cx
mov cx, [SQUARE_SIZE]
dec cx; Dec for not including line
mov bx, ax
innnerLoopDrawSquare:
push ax
mov al, [SquareColor]; Color for pixels
call ColorPixel
pop ax
inc bx
loop innnerLoopDrawSquare
pop cx
inc dx
loop outerLoopDrawSquare
doPop dx,cx,bx,ax
ret
endp DrawSquare
;Draws all squares in screen according to board
proc DrawSquares
doPush ax,bx,cx,dx
mov cx, [AMOUNT_OF_SQUARES_HORIZONTAL]
outerDrawSquares:
push cx
mov ax,cx
dec ax
mov cx, [AMOUNT_OF_SQUARES_VERTICAL]
innerDrawSquares:
mov dx,cx
dec dx
call GetBoardAtCord
mov [SquareColor], bl
call DrawSquare
loop innerDrawSquares
pop cx
loop outerDrawSquares
doPop dx,cx,bx,ax
ret
endp DrawSquares