summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorPixel <>2001-05-05 13:20:29 +0000
committerPixel <>2001-05-05 13:20:29 +0000
commitd3d5c69620a13a40aab0b55bc466621f09f89553 (patch)
tree7d4723feb62685ebf51709944127c95eee1381da /samples
parent64c9d850de6ee2a5adca9b12195cb698715d16ab (diff)
Pouet
Diffstat (limited to 'samples')
-rw-r--r--samples/p4.s177
1 files changed, 165 insertions, 12 deletions
diff --git a/samples/p4.s b/samples/p4.s
index ce534e4..95bb76e 100644
--- a/samples/p4.s
+++ b/samples/p4.s
@@ -1,4 +1,15 @@
.bss
+;
+; Organisation de la table en mémoire:
+;
+; (0,0)
+; +----> x
+; |
+; |
+; V
+; y
+;
+
Table DR 9 * 9 ; Table du jeu
.data
@@ -12,6 +23,10 @@ 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"
@@ -26,11 +41,12 @@ MsgEndl DS "\n"
;
;
; Registre globaux: R0 = 0, R1 = @Table, R2 = Joueur en cours, R3 = nombre de coups à jouer
+; R15 = registre temporaire.
;
;
-;
+;InitP4:
; Initialisations
;
@@ -71,23 +87,30 @@ BoucleInit3: MOV, [R5], R6
RET
-;
+;LitMot:
; Sert à lire un mot de la table du P4, coordonnées (R7, R8), et renvoie le résultat dans R9
;
-LitMot: PUSH R4
-
- MOV R4, 9
- MUL R4, R8
- ADD R4, Rd, R1
- ADD R4, R7
- MOV R9, [R4]
+LitMot: MOV R15, 9
+ MUL R15, R8
+ ADD R15, Rd, R1
+ ADD R15, R7
+ MOV R9, [R15]
+ RET
- POP R4
+;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
;
@@ -160,7 +183,137 @@ BoucleDebug1: MOV R7, [R4]
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
+
+ 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
+ MOV, [0xffffff04], MsgEgalite
+ RET
+Gagne: CALL AfficheP4
+ MOV, [0xffffff04], MsgGagne1
+ MOV, [0xffffff06], R2
+ MOV, [0xffffff04], MsgGagne2
+ RET
+
.start
CALL InitP4
- CALL AfficheP4
+ CALL BoucleJeu
HALT