From d5926835b392801dc48e2ccaffaead1de40c7a4a Mon Sep 17 00:00:00 2001 From: biouman <> Date: Sun, 13 May 2001 14:51:25 +0000 Subject: *** empty log message *** --- samples/cube.s | 438 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 samples/cube.s (limited to 'samples/cube.s') diff --git a/samples/cube.s b/samples/cube.s new file mode 100644 index 0000000..d42e3a7 --- /dev/null +++ b/samples/cube.s @@ -0,0 +1,438 @@ +; +; 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, Rd, 16; + SHL Rg, 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]; + CALL Cosinus; + MOV R6, R5; + MOV R5, [T2]; + CALL Cosinus; + CALL Mult; + MOV, Matr[0+0], R5; +; +; M[1,1] = cosT1*cosT2 +; + MOV R5, [T1]; + CALL Cosinus; + SUB R5, R0, R5; + MOV R7, R5; + MOV R5, [T2]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + MOV R7, R6; + CALL Mult; + MOV R7, R5; + MOV R5, [T1]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Cosinus; + CALL Mult; + SUB R5, R7, R5; + MOV, Matr[0+1], R5; +; +; M[1,2] = -cosT1*sinT2*sinT3-sinT1*CosT3 +; + MOV R5, [T1]; + CALL Cosinus; + SUB R5, R0, R5; + MOV R7, R5; + MOV R5, [T2]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Cosinus; + CALL Mult; + MOV R7, R6; + CALL Mult; + MOV R7, R5; + MOV R5, [T1]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + ADD R5, R7, R5; + MOV, Matr[0+2], R5; +; +; M[1,3] = -cosT1*sinT2*cosT3+sinT1*sinT3 +; + MOV R5, [T1]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T2]; + CALL Cosinus; + CALL Mult; + MOV, Matr[3+0], R5; +; +; M[2,1] = sinT1*cosT2 +; + MOV R5, [T1]; + CALL Sinus; + SUB R5, R0, R5; + MOV R7, R5; + MOV R5, [T2]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + MOV R7, R6; + CALL Mult; + MOV R7, R5; + MOV R5, [T1]; + CALL Cosinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Cosinus; + CALL Mult; + ADD R5, R7, R5; + MOV, Matr[3+1], R5; +; +; M[2,2] = -sinT1*sinT2*sinT3+cosT1*cosT3 +; + MOV R5, [T1]; + CALL Sinus; + SUB R5, R0, R5; + MOV R7, R5; + MOV R5, [T2]; + CALL Sinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + MOV R7, R6; + CALL Mult; + MOV R7, R5; + MOV R5, [T1]; + CALL Cosinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + SUB R5, R7, R5; + MOV, Matr[3+2], R5; +; +; M[2,3] = -sinT1*sinT2*sinT3-cosT1*sinT3 +; + MOV R5, [T2]; + CALL Sinus; + MOV, Matr[6+0], R5; +; +; M[3,1] = sinT2 +; + MOV R5, [T2]; + CALL Cosinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Sinus; + CALL Mult; + MOV, Matr[6+1], R5; +; +; M[3,2] = cosT2*sinT3 +; + MOV R5, [T2]; + CALL Cosinus; + MOV R6, R5; + MOV R5, [T3]; + CALL Cosinus; + 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, 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, 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, [T1], R5; + MOV R5, [T2]; + MOV R6, 30; + ADD R5, R5, R6; + MOV, [T2], R5; + MOV R5, [T3]; + MOV R6, 80; + ADD R5, R5, R6; + MOV, [T3], R5; + RET; + +; +; +; Main : boucle principale +; +; +.start + CALL InitTrig; + CALL InitCube; +Main: CALL IncrAngl; + CALL MajMatr; + CALL RotCube; + CALL Proj; + CALL ClrScr; + CALL Draw; + JMP Main; \ No newline at end of file -- cgit v1.2.3