summaryrefslogtreecommitdiff
path: root/samples/cube.s
blob: 593bf79f25edb25fb28bd5b68ecd2fb0123a1485 (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
;
; cube.s : representation en 3d d un cube en rotation autour de son centre de symetrie  
;	a linker avec: trig.s, drawline.s 
;
;


.bss
Points3D	DR 8 * 3;	sommets du cube 
Points2D 	DR 8 * 2;	sommets projetes
Matr		DR 3 * 3;	matrice de rotation

.data
T1 		DB 0;		angle rotation suivant z
T2 		DB 0;		angle rotation suivant y
T3		DB 0;		angle rotation suivant x
L  		DB 8 * 65536;	longueur d une arete
NL		DB, ( (-8) * 65536);  oppose de L
V		DB 8 * 2;	distance pt de vue - plan de l ecran
X0		DB 40;		centre de l ecran
Y0		DB 12;		centre de l ecran
.text 

;
;
; Mult : multiplication de deux pseudos flottants
;
;

Mult: 	MUL	R5, R6;
	SHR	Rd, 16;
	SHL	Rg, 16;
	ADD	R5, Rg, Rd;
	RET;  



;
;
; InitCube : initialisation des coords des sommets du cube
;
;

InitCube: MOV, Points3D[0], L;
	MOV, Points3D[1], L;
	MOV, Points3D[2], L;
;		
	MOV, Points3D[3], L;	
	MOV, Points3D[4], L;	
	MOV, Points3D[5], NL;	
;
	MOV, Points3D[6], L;	
	MOV, Points3D[7], NL;	
	MOV, Points3D[8], L;	
;
	MOV, Points3D[9], L;
	MOV, Points3D[10], NL;
	MOV, Points3D[11], NL;
;
	MOV, Points3D[12], NL;
	MOV, Points3D[13], L;
	MOV, Points3D[14], L;
;
	MOV, Points3D[15], NL;
	MOV, Points3D[16], L;
	MOV, Points3D[17], NL;
;
	MOV, Points3D[18], NL;
	MOV, Points3D[19], NL;
	MOV, Points3D[20], L;
;
	MOV, Points3D[21], NL;
	MOV, Points3D[22], NL;
	MOV, Points3D[23], NL;
;
	RET;


;
;
; MajMatr : mise a jour de la matrice de rotation
;
;

MajMatr: MOV	R5, [T1];
	MOV	R6, COS[R5];
	MOV	R5, [T2];
	MOV	R6, COS[R5];
	CALL	Mult;
	MOV,	Matr[0+0], R5;
;	
; M[1,1] = cosT1*cosT2
;
	MOV	R5, [T1];
	MOV	R5, COS[R5];
	SUB	R5, R0, R5;
	MOV	R7, R5;
	MOV 	R5, [T2];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	MOV	R7, R6;
	CALL	Mult;
	MOV 	R7, R5;
	MOV	R5, [T1];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV 	R5, [T3];
	MOV	R5, COS[R5];
	CALL	Mult;
	SUB	R5, R7, R5;
	MOV,	Matr[0+1], R5;
;
; M[1,2] = -cosT1*sinT2*sinT3-sinT1*CosT3		  
;
	MOV	R5, [T1];
	MOV	R5, COS[R5];
	SUB	R5, R0, R5;
	MOV	R7, R5;
	MOV 	R5, [T2];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, COS[R5];
	CALL	Mult;
	MOV	R7, R6;
	CALL	Mult;
	MOV 	R7, R5;
	MOV	R5, [T1];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV 	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	ADD	R5, R7, R5;
	MOV,	Matr[0+2], R5;
;
; M[1,3] = -cosT1*sinT2*cosT3+sinT1*sinT3
;
	MOV	R5, [T1];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV	R5, [T2];
	MOV	R5, COS[R5];
	CALL	Mult;
	MOV,	Matr[3+0], R5;
;
; M[2,1] = sinT1*cosT2	 
;
	MOV	R5, [T1];
	MOV	R5, SIN[R5];
	SUB	R5, R0, R5;
	MOV	R7, R5;
	MOV 	R5, [T2];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	MOV	R7, R6;
	CALL	Mult;
	MOV 	R7, R5;
	MOV	R5, [T1];
	MOV	R5, COS[R5];
	MOV	R6, R5;
	MOV 	R5, [T3];
	MOV	R5, COS[R5];
	CALL	Mult;
	ADD	R5, R7, R5;
	MOV,	Matr[3+1], R5;
;
; M[2,2] = -sinT1*sinT2*sinT3+cosT1*cosT3		  
;
	MOV	R5, [T1];
	MOV	R5, SIN[R5];
	SUB	R5, R0, R5;
	MOV	R7, R5;
	MOV 	R5, [T2];
	MOV	R5, SIN[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	MOV	R7, R6;
	CALL	Mult;
	MOV 	R7, R5;
	MOV	R5, [T1];
	MOV	R5, COS[R5];
	MOV	R6, R5;
	MOV 	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	SUB	R5, R7, R5;
	MOV,	Matr[3+2], R5;
;	
; M[2,3] = -sinT1*sinT2*sinT3-cosT1*sinT3
;
	MOV	R5, [T2];
	MOV	R5, SIN[R5];
	MOV,	Matr[6+0], R5;
;
; M[3,1] = sinT2
;
	MOV	R5, [T2];
	MOV	R5, COS[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, SIN[R5];
	CALL	Mult;
	MOV, 	Matr[6+1], R5;
;
; M[3,2] = cosT2*sinT3
;
	MOV	R5, [T2];
	MOV	R5, COS[R5];
	MOV	R6, R5;
	MOV	R5, [T3];
	MOV	R5, COS[R5];
	CALL	Mult;
	MOV, 	Matr[6+2], R5;
;
; M[3,3] = cosT2*cosT3
;
	RET;




;
;
; RotCube : Rotation du cube suivant les angles T1, T2, T3
;
;

RotCube: MOV R3, 0;
	MOV R4, 24;
BouclCube: MOV	R5, Matr[0+0];
	MOV	R6, Points3D[R3+0];
	CALL	Mult;
	MOV	R10, R5;
	MOV	R5, Matr[0+1];
	MOV	R6, Points3D[R3+1];
	CALL	Mult;
	ADD	R10, R10, R5;
	MOV	R5, Matr[0+2];
	MOV	R6, Points3D[R3+2];
	CALL	Mult;
	ADD	R10, R10, R5;
; x
	MOV	R5, Matr[3+0];
	MOV	R6, Points3D[R3+0];
	CALL	Mult;
	MOV	R11, R5;
	MOV	R5, Matr[3+1];
	MOV	R6, Points3D[R3+1];
	CALL	Mult;
	ADD	R11, R11, R5;
	MOV	R5, Matr[3+2];
	MOV	R6, Points3D[R3+2];
	CALL	Mult;
	ADD	R11, R11, R5;
; y
	MOV	R5, Matr[6+0];
	MOV	R6, Points3D[R3+0];
	CALL	Mult;
	MOV	R12, R5;
	MOV	R5, Matr[6+1];
	MOV	R6, Points3D[R3+1];
	CALL	Mult;
	ADD	R12, R12, R5;
	MOV	R5, Matr[6+2];
	MOV	R6, Points3D[R3+2];
	CALL	Mult;
	ADD	R12, R12, R5;
; z
	MOV, 	Points3D[R3+0], R10;
	MOV,	Points3D[R3+1], R11;
	MOV, 	Points3D[R3+2], R12;
	ADD	R3, R3, 3; 
	JNE	R3, R4, BouclCube;
	RET;



;
;
; Proj : Projection du cube sur le plan de l ecran ( perspective )
;
;

Proj:	MOV 	R2, 0;
	MOV	R3, 0;
	MOV	R4, 24;  
BouclProj: MOV	R5, Points3D[R3+0];
	MOV	R6, [V];
	CALL	Mult;
	MOV	R7, Points3D[R3+2];
	ADD	R6, R6, R7; 
	DIV	R5, R6;
	MOV	R5, Rg;
	SHR	R5, 16;
	MOV	R6, [X0];
	ADD	R5, R5, R6;  
	MOV	Points2D[R2], R5;
;
; x' = (V*x)/(V+z)
;
	MOV	R5, Points3D[R3+1];
	MOV	R6, [V];
	CALL	Mult;
	MOV	R7, Points3D[R3+2];
	ADD	R6, R6, R7; 
	DIV	R5, R6;
	MOV	R5, Rg;
	SHR	R5, 16;
	MOV	R6, [Y0];
	ADD	R5, R5, R6; 
	MOV	Points2D[R2+1], R5;
;
; y'=(V*y)/(V+z)	
;
	ADD	R2, R2, 2;
	ADD	R3, R3, 3;
	JNE	R3, R4, BouclProj;
	RET;
	  	


;
;
; Draw : trace le cube
;
;


Draw:	MOV R7,  Points2D[0];
	MOV R6,  Points2D[1];
	MOV R9,  Points2D[2];
	MOV R8,  Points2D[3];
	CALL DrawLine;
	MOV R7,  Points2D[2];
	MOV R6,  Points2D[3];
	MOV R9,  Points2D[4];
	MOV R8,  Points2D[5];
	CALL DrawLine;
	MOV R7,  Points2D[4];
	MOV R6,  Points2D[5];
	MOV R9,  Points2D[6];
	MOV R8,  Points2D[7];
	CALL DrawLine;	
	MOV R7,  Points2D[6];
	MOV R6,  Points2D[7];
	MOV R9,  Points2D[0];
	MOV R8,  Points2D[1];
	CALL DrawLine;
	MOV R7,  Points2D[8];
	MOV R6,  Points2D[9];
	MOV R9,  Points2D[10];
	MOV R8,  Points2D[11];
	CALL DrawLine;
	MOV R7,  Points2D[10];
	MOV R6,  Points2D[11];
	MOV R9,  Points2D[12];
	MOV R8,  Points2D[13];
	CALL DrawLine;
	MOV R7,  Points2D[12];
	MOV R6,  Points2D[13];
	MOV R9,  Points2D[14];
	MOV R8,  Points2D[15];
	CALL DrawLine;
	MOV R7,  Points2D[14];
	MOV R6,  Points2D[15];
	MOV R9,  Points2D[8];
	MOV R8,  Points2D[9];
	CALL DrawLine;
	MOV R7,  Points2D[0];
	MOV R6,  Points2D[1];
	MOV R9,  Points2D[8];
	MOV R8,  Points2D[9];
	CALL DrawLine; 	
	MOV R7,  Points2D[2];
	MOV R6,  Points2D[3];
	MOV R9,  Points2D[10];
	MOV R8,  Points2D[11];
	CALL DrawLine;
	MOV R7,  Points2D[4];
	MOV R6,  Points2D[5];
	MOV R9,  Points2D[12];
	MOV R8,  Points2D[13];
	CALL DrawLine;
	MOV R7,  Points2D[6];
	MOV R6,  Points2D[7];
	MOV R9,  Points2D[14];
	MOV R8,  Points2D[15];
	CALL DrawLine;
	RET;



;
;
; IncrAngl : incremente T1, T2, T3  
;
;


IncrAngl: MOV	R5, [T1];
	MOV	R6, 56;
	ADD	R5, R5, R6;
	MOV	R6, 4096;
	DIV	R5, R6; 
	MOV,	[T1], Rd;
	MOV	R5, [T2];
	MOV	R6, 30;
	ADD	R5, R5, R6;
	MOV	R6, 4096;
	DIV	R5, R6;
	MOV,	[T2], Rd;
	MOV	R5, [T3];
	MOV	R6, 80;
	ADD	R5, R5, R6;
	MOV	R6, 4096;
	DIV	R5, R6;
	MOV,	[T3], Rd;	
	RET;

;
;
; Main : boucle principale
;
;
.start
	CALL	InitCube;
Main: 	CALL	IncrAngl;
	CALL	MajMatr;
	CALL	RotCube;
	CALL	Proj;
	CALL	ClrScr;
	CALL	Draw;
	JMP	Main;