summaryrefslogtreecommitdiff
path: root/samples/drawline.s
blob: 18ee1a935c4a992a9ed5c832f2742b0e4f639cf4 (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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
.data
ClrScrMsg	DS	"\e[2J\e[H"
LocateMsg1	DS	"\e["
LocateMsg2	DS	";"
LocateMsg3	DS	"H"
PointMsg	DS	"."

.text

;ClrScr:
; Efface l'écran
;

ClrScr:		MOV,	[0xffffff04], ClrScrMsg
		RET

;Locate:
; Positionne le curseur a la position (R10, R11), sous la forme (ligne, colonne)
;

Locate:		MOV,	[0xffffff04], LocateMsg1
		MOV,	[0xffffff06], R10
		MOV,	[0xffffff04], LocateMsg2
		MOV,	[0xffffff06], R11
		MOV,	[0xffffff04], LocateMsg3
		RET

;DrawLinePrim1:
; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne))
;4~

; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e

DrawLinePrim1:	PUSH	R10
		PUSH	R11
		PUSH	R12
		PUSH	R13
		PUSH	R14
		PUSH	R30
		MOV	R30, 1
		SUB	R13, R9, R7
		SHL	R13, R30
		SUB	R12, R8, R6
		SUB	R14, R12, R13
		SHL	R12, R30
		MOV	R10, R6
		MOV	R11, R7
DrawLinePrim1B:	JNLE	R10, R8, DrawLinePrim1O
		CALL	Locate
		MOV,	[0xffffff04], PointMsg
		JNL	R14, R0, DrawLinePrim1C
		ADD	R11, 1
		ADD	R14, R12
		SUB	R14, R13
		JMP	DrawLinePrim1L
DrawLinePrim1C:	SUB	R14, R12
DrawLinePrim1L:	ADD	R10, 1
		JMP	DrawLinePrim1B
DrawLinePrim1O:	POP	R30
		POP	R14
		POP	R13
		POP	R12
		POP	R11
		POP	R10
		RET

; void DrawXLine_Prim1(int x1, int y1, int x2, int y2, Color_t color) {
;  int x, y, ddx, ddy, e, c;
;
;  ddy = (y2 - y1) << 1;
;  ddx = x2 - x1;
;  e = ddx - ddy;
;  ddx <<= 1;
;  for (x = x1, y = y1; x <= x2; x++) {
;    putpixel(x, y, color);
;    if (e < 0) {
;      y++;
;      e += ddx - ddy;
;    } else {
;      e -= ddy;
;    }
;  }
;}

;DrawLinePrim2:
; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne))
;

; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e

DrawLinePrim2:	PUSH	R10
		PUSH	R11
		PUSH	R12
		PUSH	R13
		PUSH	R14
		PUSH	R30
		MOV	R30, 1
		SUB	R12, R8, R6
		SHL	R12, R30
		SUB	R13, R9, R7
		SUB	R14, R13, R12
		SHL	R13, R30
		MOV	R10, R6
		MOV	R11, R7
DrawLinePrim2B:	JNLE	R11, R9, DrawLinePrim2O
		CALL	Locate
		MOV,	[0xffffff04], PointMsg
		JNL	R14, R0, DrawLinePrim2C
		ADD	R10, 1
		ADD	R14, R13
		SUB	R14, R12
		JMP	DrawLinePrim2L
DrawLinePrim2C:	SUB	R14, R13
DrawLinePrim2L:	ADD	R11, 1
		JMP	DrawLinePrim2B
DrawLinePrim2O:	POP	R30
		POP	R14
		POP	R13
		POP	R12
		POP	R11
		POP	R10
		RET

;void DrawXLine_Prim2(int x1, int y1, int x2, int y2, Color_t color) {
;  int x, y, ddx, ddy, e;
;
;  ddx = (x2 - x1) << 1;
;  ddy = y2 - y1;
;  e = ddy - ddx;
;  ddy <<= 1;
;  for (y = y1, x = x1; y <= y2; y++) {
;    putpixel(x, y, color);
;    if (e < 0) {
;      x++;
;      e += ddy - ddx;
;    } else {
;      e -= ddx;
;    }
;  }
;}

;DrawLinePrim3:
; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne))
;

; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e

DrawLinePrim3:	PUSH	R10
		PUSH	R11
		PUSH	R12
		PUSH	R13
		PUSH	R14
		PUSH	R30
		MOV	R30, 1
		SUB	R12, R6, R8
		SHL	R12, R30
		SUB	R13, R9, R7
		SUB	R14, R13, R12
		SHL	R13, R30
		MOV	R10, R6
		MOV	R11, R7
DrawLinePrim3B:	JNLE	R11, R9, DrawLinePrim3O
		CALL	Locate
		MOV,	[0xffffff04], PointMsg
		JNL	R14, R0, DrawLinePrim3C
		ADD	R10, 1
		ADD	R14, R13
		SUB	R14, R12
		JMP	DrawLinePrim3L
DrawLinePrim3C:	SUB	R14, R13
DrawLinePrim3L:	ADD	R11, 1
		JMP	DrawLinePrim3B
DrawLinePrim3O:	POP	R30
		POP	R14
		POP	R13
		POP	R12
		POP	R11
		POP	R10
		RET

;void DrawXLine_Prim3(int x1, int y1, int x2, int y2, Color_t color) {
;  int x, y, ddx, ddy, e;
;
;  ddx = (x1 - x2) << 1;
;  ddy = y2 - y1;
;  e = ddy - ddx;
;  ddy <<= 1;
;  for (y = y1, x = x1; y <= y2; y++) {
;    putpixel(x, y, color);
;    if (e < 0) {
;      x--;
;      e += ddy - ddx;
;    } else {
;      e -= ddx;
;    }
;  }
;}

;DrawLinePrim4:
; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne))
;

; R10 = x, R11 = y, R12 = ddx, R13 = ddy, R14 = e

DrawLinePrim4:	PUSH	R10
		PUSH	R11
		PUSH	R12
		PUSH	R13
		PUSH	R14
		PUSH	R30
		MOV	R30, 1
		SUB	R13, R9, R7
		SHL	R13, R30
		SUB	R12, R6, R8
		SUB	R14, R12, R13
		SHL	R12, R30
		MOV	R10, R6
		MOV	R11, R7
DrawLinePrim4B:	JNGE	R10, R8, DrawLinePrim4O
		CALL	Locate
		MOV,	[0xffffff04], PointMsg
		JNL	R14, R0, DrawLinePrim4C
		ADD	R11, 1
		ADD	R14, R12
		SUB	R14, R13
		JMP	DrawLinePrim4L
DrawLinePrim4C:	SUB	R14, R12
DrawLinePrim4L:	ADD	R10, 1
		JMP	DrawLinePrim4B
DrawLinePrim4O:	POP	R14
		POP	R13
		POP	R12
		POP	R11
		POP	R10
		RET

;void DrawXLine_Prim4(int x1, int y1, int x2, int y2, Color_t color) {
;  int x, y, ddx, ddy, e;
;
;  ddy = (y2 - y1) << 1;
;  ddx = x1 - x2;
;  e = ddx - ddy;
;  ddx <<= 1;
;  for (x = x1, y = y1; x >= x2; x--) {
;    putpixel(x, y, color);
;    if (e < 0) {
;      y++;
;      e += ddx - ddy;
;    } else {
;      e -= ddy;
;    }
;  }
;}

;DrawLine:
; Dessine une ligne entre (R6, R7) et (R8, R9) (sous la forme (ligne, colonne))
;

DrawLine:	PUSH	R1
		PUSH	R2
		JNL	R9, R7, DrawLineC1
		MOV	R1, R6
		MOV	R6, R8
		MOV	R8, R1
		MOV	R1, R7
		MOV	R7, R9
		MOV	R9, R1
DrawLineC1:	JNGE	R8, R6, DrawLineC2
		SUB	R1, R8, R6
		SUB	R2, R9, R7
		JNGE	R1, R2, DrawLineC3
		CALL	DrawLinePrim1
		JMP	DrawLineO
DrawLineC3:	CALL	DrawLinePrim2
		JMP	DrawLineO
DrawLineC2:	SUB	R1, R6, R8
		SUB	R2, R9, R7
		JNGE	R1, R2, DrawLineC4
		CALL	DrawLinePrim3
		JMP	DrawLineO
DrawLineC4:	CALL	DrawLinePrim4
DrawLineO:	POP	R2
		POP	R1
		RET

;void DrawXLine(int x1, int y1, int x2, int y2, Color_t color) {
;  if (y2 < y1) {
;    SWAP(x1, x2);
;    SWAP(y1, y2);
;  }
;  if (x2 >= x1) {
;    if ((x2 - x1) >= (y2 - y1)) DrawXLine_Prim1(x1, y1, x2, y2, color);
;    else DrawXLine_Prim2(x1, y1, x2, y2, color);
;  } else {
;    if ((x1 - x2) >= (y2 - y1)) DrawXLine_Prim4(x1, y1, x2, y2, color);
;    else DrawXLine_Prim3(x1, y1, x2, y2, color);
;  }
;}

;.start
;		CALL	ClrScr
;		MOV	R6, 10
;		MOV	R7, 4
;		MOV	R8, 15
;		MOV	R9, 20
;		CALL	DrawLine
;		MOV	R10, 30
;		MOV	R11, 1
;		CALL	Locate
;		HALT