summaryrefslogtreecommitdiff
path: root/samples/p4.s
diff options
context:
space:
mode:
authorPixel <>2001-04-23 21:09:03 +0000
committerPixel <>2001-04-23 21:09:03 +0000
commit5796178981fe51ea279b56a2dca19cf19fb73edf (patch)
treec630f6d1ae5356870c7590c690cea29679ae69b2 /samples/p4.s
parenta3456122423c7784a5f72c202f3636256e0da7c9 (diff)
Bug dans le simulateur (2) et ajout de l'exemple "Puissance4"
Diffstat (limited to 'samples/p4.s')
-rw-r--r--samples/p4.s123
1 files changed, 123 insertions, 0 deletions
diff --git a/samples/p4.s b/samples/p4.s
new file mode 100644
index 0000000..28b79fd
--- /dev/null
+++ b/samples/p4.s
@@ -0,0 +1,123 @@
+.bss
+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"
+MsgDraw DS "| "
+MsgDrawJ1 DS "|\e[31m;O\e[0m;"
+MsgDrawJ2 DS "|\e[34m;O\e[0m;"
+MsgDrawWall DS "|\n"
+MsgsDraw DD MsgDraw, MsgDrawJ1, MsgDrawJ2, MsgDraw
+MsgDrawBegin DS "\e[2J 1 2 3 4 5 6 7\n"
+MsgDrawEnd DS "+-+-+-+-+-+-+-+\n"
+
+.text
+
+;
+;
+; Registre globaux: R0 = 0, R1 = @Table, R2 = Joueur en cours, R3 = nombre de coups à jouer
+;
+;
+
+
+;
+; 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, 1
+ 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
+
+
+;
+; 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]
+
+ POP R4
+ RET
+
+
+;
+; Sert à afficher la table.
+;
+
+AfficheP4: PUSH R4
+ PUSH R5
+ PUSH R6
+ PUSH R7
+ PUSH R8
+ PUSH R9
+
+ MOV, [0xffffff04], MsgDrawBegin
+
+ MOV R5, Table + 9;
+ ADD R4, R5, 7 * 9;
+
+BoucleAffiche: MOV R9, [R5]
+ MOV R6, Table[R9]
+ MOV, [0xffffff04], R6
+ ADD R5, 1
+ JNE R5, R4, BoucleAffiche
+
+ MOV, [0xffffff04], MsgDrawEnd
+
+ POP R9
+ POP R8
+ POP R7
+ POP R6
+ POP R5
+ POP R4
+ RET
+
+.start
+ CALL InitP4
+ CALL AfficheP4
+ HALT