.bss ; ; Organisation de la table en mémoire: ; ; (0,0) ; +----> x ; | ; | ; V ; y ; Table DR 9 * 9 ; Table du jeu .data ; ; Les quelques textes qui seront affichés ; MsgTour1 DS "C'est au tour du joueur " MsgTour2 DS " de jouer\n" MsgGagne1 DS "Le joueur " MsgGagne2 DS " a gagné\n" MsgEgalite DS "Égalité\n" MsgCoup DS "Votre coup: " MsgColonne DS "Colonne " MsgPlein DS " pleine\n" MsgInvalide DS " invalide\n" MsgDraw DS "| " MsgDrawJ1 DS "|\e[31mO\e[0m" MsgDrawJ2 DS "|\e[34mO\e[0m" MsgDrawWall DS "|\n" MsgsDraw DD MsgDraw, MsgDrawJ1, MsgDrawJ2, MsgDrawWall MsgDrawBegin DS "\e[2J\e[0;0H 1 2 3 4 5 6 7\n" MsgDrawEnd DS "+-+-+-+-+-+-+-+\n" MsgEndl DS "\n" .text ; ; ; Registre globaux: R0 = 0, R1 = @Table, R2 = Joueur en cours, R3 = nombre de coups à jouer ; R15 = registre temporaire. ; ; ;InitP4: ; Initialisations ; InitP4: PUSH R4 PUSH R5 PUSH R6 MOV R1, Table MOV R2, 1 MOV R3, 7 * 7; ; On met tout à zéro. MOV R4, Table + (9 * 9); MOV R5, R1 BoucleInit1: MOV, [R5], R0 ADD R5, 1 JNE R5, R4, BoucleInit1 ; On met à 3 les 'murs' gauche et droite. MOV R5, R1 MOV R6, 3 BoucleInit2: MOV, [R5], R6 MOV, [R5 + 8], R6 ADD R5, 9 JNE R5, R4, BoucleInit2 ; On met à 3 les 'murs' haut et bas. MOV R4, Table + 9; MOV R5, R1 BoucleInit3: MOV, [R5], R6 MOV, [R5 + 8 * 9], R6 ADD R5, 1 JNE R5, R4, BoucleInit3 POP R6 POP R5 POP R4 RET ;LitMot: ; Sert à lire un mot de la table du P4, coordonnées (R7, R8), et renvoie le résultat dans R9 ; LitMot: MOV R15, 9 MUL R15, R8 ADD R15, Rd, R1 ADD R15, R7 MOV R9, [R15] RET ;EcritMot: ; Sert à écrire le mot R2 de la table du P4, coordonnées (R7, R8) ; EcritMot: MOV R15, 9 MUL R15, R8 ADD R15, Rd, R1 ADD R15, R7 MOV, [R15], R2 RET ;AfficheP4: ; Sert à afficher la table ; AfficheP4: PUSH R4 PUSH R5 PUSH R6 PUSH R7 PUSH R8 PUSH R9 MOV, [0xffffff04], MsgDrawBegin MOV R8, 8 MOV R9, 9 ADD R4, R1, 10 MOV R5, 1 BoucleAffiche2: MOV R6, 1 BoucleAffiche1: MOV R7, [R4] MOV R7, MsgsDraw[R7] MOV, [0xffffff04], R7 ADD R4, 1 ADD R6, 1 JNE R6, R9, BoucleAffiche1 ADD R5, 1 ADD R4, 1 JNE R5, R8, BoucleAffiche2 MOV, [0xffffff04], MsgDrawEnd MOV, [0xffffff04], MsgTour1 MOV, [0xffffff06], R2 MOV, [0xffffff04], MsgTour2 POP R9 POP R8 POP R7 POP R6 POP R5 POP R4 RET ; ; Sert pour le debuggage lors du developpement de l'application. ; AfficheDebug: PUSH R4 PUSH R5 PUSH R6 PUSH R7 PUSH R9 MOV, [0xffffff04], MsgEndl MOV R9, 9 MOV R4, R1 MOV R5, R0 BoucleDebug2: MOV R6, R0 BoucleDebug1: MOV R7, [R4] MOV, [0xffffff06], R7 ADD R4, 1 ADD R6, 1 JNE R6, R9, BoucleDebug1 MOV, [0xffffff04], MsgEndl ADD R5, 1 JNE R5, R9, BoucleDebug2 POP R9 POP R7 POP R6 POP R5 POP R4 RET ;Has4V: ; Calcule autour du point de coordonnées (R7, R8), si le vecteur (R10, R11) donne 4 points alignés, ; et renvoie un booleen dans R12. ; Has4V: PUSH R9 PUSH R13 PUSH R14 PUSH R7 PUSH R8 CALL LitMot MOV R13, R9 MOV R14, R0 BouclePlus: ADD R7, R10 ADD R8, R11 CALL LitMot ADD R14, 1 JE R9, R13, BouclePlus POP R8 POP R7 PUSH R7 PUSH R8 BoucleMoins: SUB R7, R10 SUB R8, R11 CALL LitMot ADD R14, 1 JE R9, R13, BoucleMoins MOV R12, R0 MOV R15, 4 JLE R14, R15, SortieHas4V MOV R12, 1 SortieHas4V: POP R8 POP R7 POP R14 POP R13 POP R9 RET ;Has4: ; Cette procédure nous dit si autour de (R7, R8) il y a 4 points identiques et renvoie un booléen dans R9 ; Has4: PUSH R10 PUSH R11 PUSH R12 MOV R9, 1 MOV R10, R0 MOV R11, 1 CALL Has4V JNE R12, R0, SortieHas4 MOV R10, R11 CALL Has4V JNE R12, R0, SortieHas4 MOV R11, R0 CALL Has4V JNE R12, R0, SortieHas4 SUB R11, 1 CALL Has4V JNE R12, R0, SortieHas4 MOV R9, R0 SortieHas4: POP R12 POP R11 POP R10 RET ;GetLig: ; Nous sort dans R8 la ligne la plus basse de la colonne R7. R8 vaudra 0 si la colonne est pleine. ; GetLig: PUSH R9 MOV R8, R0 BoucleGetLig: ADD R8, 1 CALL LitMot JE R9, R0, BoucleGetLig SUB R8, 1 POP R9 RET ;LireClavier ; Lit un coup pour un joueur. ; LitClavier: MOV, [0xffffff04], MsgCoup MOV R7, [0xffffff05] MOV R15, 8 JLE R7, R0, LitErreurI JGE R7, R15, LitErreurI CALL GetLig JE R8, R0, LitErreurP CALL EcritMot RET LitErreurI: MOV, [0xffffff04], MsgColonne MOV, [0xffffff06], R7 MOV, [0xffffff04], MsgInvalide JMP LitClavier LitErreurP: MOV, [0xffffff04], MsgColonne MOV, [0xffffff06], R7 MOV, [0xffffff04], MsgPlein JMP LitClavier ;BoucleJeu: ; Boucle principale du jeu. ; BoucleJeu: CALL AfficheP4 CALL LitClavier CALL Has4 JNE R9, R0, Gagne SUB R2, 1 JNE R2, R0, SautBoucleJeu MOV R2, 2 SautBoucleJeu: SUB R3, 1 JNE R3, R0, BoucleJeu CALL AfficheP4 MOV, [0xffffff04], MsgEgalite RET Gagne: CALL AfficheP4 MOV, [0xffffff04], MsgGagne1 MOV, [0xffffff06], R2 MOV, [0xffffff04], MsgGagne2 RET .start CALL InitP4 CALL BoucleJeu HALT