summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <>2001-05-05 13:20:29 +0000
committerPixel <>2001-05-05 13:20:29 +0000
commitd3d5c69620a13a40aab0b55bc466621f09f89553 (patch)
tree7d4723feb62685ebf51709944127c95eee1381da
parent64c9d850de6ee2a5adca9b12195cb698715d16ab (diff)
Pouet
-rw-r--r--include/simulator.h2
-rw-r--r--lib/linker.c12
-rw-r--r--lib/memoire.c6
-rw-r--r--lib/simulator.c54
-rw-r--r--po/ProjetArchi.pot49
-rw-r--r--po/cat-id-tbl.c1
-rw-r--r--samples/p4.s177
-rw-r--r--src/simul.c1
8 files changed, 238 insertions, 64 deletions
diff --git a/include/simulator.h b/include/simulator.h
index c94ba5e..d98cf7a 100644
--- a/include/simulator.h
+++ b/include/simulator.h
@@ -14,7 +14,7 @@
extern Uint32 registre[NB_REGISTRES_PHYSIQUES]; /* Registres classiques */
-extern int debug, HasToRun;
+extern int debug, HasToRun, trace;
void Initialisation(void);
void Flush(void);
diff --git a/lib/linker.c b/lib/linker.c
index b85cbb2..f1f371d 100644
--- a/lib/linker.c
+++ b/lib/linker.c
@@ -146,19 +146,23 @@ void addfile(char *nom)
readword(f); /* Taille de la table des symboles */
nbsymbols = readword(f);
+ objects[objindex]->textstart = textsize;
+ objects[objindex]->datastart = datasize;
+ objects[objindex]->bssstart = bsssize;
+
pushcontext(_("Reading symbols"));
for (i = 0; i < nbsymbols; i++) {
type = readword(f);
offset = readword(f);
snom = readstring(f);
+#if 1
+ if (!(type & 1))
+ fprintf(stderr, "Adding symbol %s at offset %X\n", snom, offset);
+#endif
addsymbol(snom, offset, type);
}
popcontext();
- objects[objindex]->textstart = textsize;
- objects[objindex]->datastart = datasize;
- objects[objindex]->bssstart = bsssize;
-
objects[objindex]->text = (Uint32 *) Emalloc(objects[objindex]->s_text * sizeof(Uint32));
objects[objindex]->data = (Uint32 *) Emalloc(objects[objindex]->s_data * sizeof(Uint32));
diff --git a/lib/memoire.c b/lib/memoire.c
index 067f8f8..e9fc240 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -37,6 +37,7 @@ void FlushMemoire(void)
Uint32 LD(Uint32 offset)
{
Uint32 i;
+ char buf[256];
switch (offset) {
case 0xffffff00:
@@ -50,7 +51,10 @@ Uint32 LD(Uint32 offset)
clearterm();
break;
case 0xffffff05:
- fscanf(input, "%i", &i);
+ fgets(buf, 256, input);
+ if (sscanf(buf, "%i", &i) != 1) {
+ i = 0;
+ }
break;
default:
if (offset >= TAILLE_MEMOIRE) {
diff --git a/lib/simulator.c b/lib/simulator.c
index c7c709c..8db38ef 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -14,7 +14,7 @@
#include "linker.h"
#include "terminal.h"
-int HasToRun = 1, HasToReset = 0, debug = 0;
+int HasToRun = 1, HasToReset = 0, debug = 0, trace = 0;
Uint32 base_addr = 0;
@@ -424,28 +424,38 @@ void Debogueur(void)
Champ1(instruction), Champ2(instruction), Champ3(instruction));
fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ",
LireRegistrePC(), instruction, LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
-
- switch (fgetc(input)) {
- case 'G':
- case 'g':
- fprintf(stderr, "Go\n\n");
- debug = 0;
- out = 1;
- break;
- case 'p':
- case 'P':
- fprintf(stderr, "Proceed\n\n");
+
+ if (!trace) {
+ switch (fgetc(input)) {
+ case 'G':
+ case 'g':
+ fprintf(stderr, "Go\n\n");
+ debug = 0;
+ out = 1;
+ break;
+ case 'p':
+ case 'P':
+ fprintf(stderr, "Proceed\n\n");
+ out = 1;
+ break;
+ case 'R':
+ case 'r':
+ break;
+ case 'T':
+ case 't':
+ trace = 1;
+ out = 1;
+ break;
+ case 'Q':
+ case 'q':
+ clearterm();
+ exception(1, _("Shutdown requested"));
+ default:
+ fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\nT: trace\nQ: quit\n"));
+ }
+ } else {
+ fprintf(stderr, "Tracing...\n\n");
out = 1;
- break;
- case 'R':
- case 'r':
- break;
- case 'Q':
- case 'q':
- clearterm();
- exception(1, _("Shutdown requested"));
- default:
- fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\nQ: quit\n"));
}
}
}
diff --git a/po/ProjetArchi.pot b/po/ProjetArchi.pot
index b2f16dc..e4fcb04 100644
--- a/po/ProjetArchi.pot
+++ b/po/ProjetArchi.pot
@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2001-04-23 23:13+0200\n"
+"POT-Creation-Date: 2001-05-05 15:13+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -296,7 +296,7 @@ msgstr ""
msgid "Error writing output file"
msgstr ""
-#: lib/assembler.c:2222 lib/linker.c:284
+#: lib/assembler.c:2222 lib/linker.c:288
msgid "Writing output file"
msgstr ""
@@ -449,7 +449,7 @@ msgstr ""
msgid "FPU not implemented"
msgstr ""
-#: lib/memoire.c:57 lib/memoire.c:131
+#: lib/memoire.c:61 lib/memoire.c:135
msgid "Invalid Memory Adress"
msgstr ""
@@ -475,49 +475,49 @@ msgstr ""
msgid "Startpoint already defined."
msgstr ""
-#: lib/linker.c:149
+#: lib/linker.c:153
msgid "Reading symbols"
msgstr ""
-#: lib/linker.c:165
+#: lib/linker.c:169
msgid "Reading text and data segments"
msgstr ""
-#: lib/linker.c:219
+#: lib/linker.c:223
#, c-format
msgid "Symbol %s not found"
msgstr ""
-#: lib/linker.c:235 lib/linker.c:258 lib/linker.c:270
+#: lib/linker.c:239 lib/linker.c:262 lib/linker.c:274
msgid "Internal error"
msgstr ""
-#: lib/linker.c:288
+#: lib/linker.c:292
msgid "No startpoint defined."
msgstr ""
-#: lib/linker.c:291
+#: lib/linker.c:295
msgid "Writing headers"
msgstr ""
-#: lib/linker.c:300
+#: lib/linker.c:304
msgid "Writing relocating informations"
msgstr ""
-#: lib/linker.c:303
+#: lib/linker.c:307
msgid "Writing text segments"
msgstr ""
-#: lib/linker.c:308
+#: lib/linker.c:312
msgid "Writing data segments"
msgstr ""
-#: lib/linker.c:317
+#: lib/linker.c:321
#, c-format
msgid "Statistics: %i words of text, %i words of data and reserving %i words\n"
msgstr ""
-#: lib/linker.c:321
+#: lib/linker.c:325
#, c-format
msgid "Output file size: %i words containing %i relocating offsets.\n"
msgstr ""
@@ -539,35 +539,36 @@ msgstr ""
msgid "DecodeExec: Invalid Opcode"
msgstr ""
-#: lib/simulator.c:446
+#: lib/simulator.c:452
msgid "Shutdown requested"
msgstr ""
-#: lib/simulator.c:448
+#: lib/simulator.c:454
msgid ""
"Help:\n"
"G: go\n"
"P: Proceed\n"
"R: display registers\n"
+"T: trace\n"
"Q: quit\n"
msgstr ""
-#: lib/simulator.c:481
+#: lib/simulator.c:491
#, c-format
msgid "Opening file %s"
msgstr ""
#. verification de la signature
-#: lib/simulator.c:485
+#: lib/simulator.c:495
msgid "Invalid Signature"
msgstr ""
-#: lib/simulator.c:489
+#: lib/simulator.c:499
#, c-format
msgid "Loading file %s"
msgstr ""
-#: lib/simulator.c:523
+#: lib/simulator.c:533
#, c-format
msgid "Executing file %s"
msgstr ""
@@ -622,21 +623,21 @@ msgstr ""
msgid "Signal received: segfault"
msgstr ""
-#: src/compilo.c:69 src/linker.c:51 src/simul.c:97
+#: src/compilo.c:69 src/linker.c:51 src/simul.c:98
msgid ""
"\n"
"Performing initialisation...\n"
"\n"
msgstr ""
-#: src/compilo.c:74 src/linker.c:63 src/simul.c:110
+#: src/compilo.c:74 src/linker.c:63 src/simul.c:111
msgid ""
"\n"
"Performing shutdown...\n"
"\n"
msgstr ""
-#: src/compilo.c:79 src/linker.c:68 src/simul.c:116
+#: src/compilo.c:79 src/linker.c:68 src/simul.c:117
msgid "Exitting, bye!\n"
msgstr ""
@@ -654,7 +655,7 @@ msgstr ""
msgid " o Initialising the simulator... "
msgstr ""
-#: src/simul.c:100
+#: src/simul.c:101
msgid "Beginning simulation"
msgstr ""
diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c
index f5efdd2..38c658c 100644
--- a/po/cat-id-tbl.c
+++ b/po/cat-id-tbl.c
@@ -140,6 +140,7 @@ Help:\n\
G: go\n\
P: Proceed\n\
R: display registers\n\
+T: trace\n\
Q: quit\n", 126},
{"Opening file %s", 127},
{"Invalid Signature", 128},
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
diff --git a/src/simul.c b/src/simul.c
index 3701ea1..50def1c 100644
--- a/src/simul.c
+++ b/src/simul.c
@@ -43,6 +43,7 @@ void segfaulthand(int i)
void ctrlbreakhand(int i)
{
debug = 1;
+ trace = 0;
}
char *readargs(int argc, char **argv)