summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/memoire.h2
-rw-r--r--include/simulator.h4
-rw-r--r--include/terminal.h4
-rw-r--r--lib/alu.c91
-rw-r--r--lib/meta.c12
-rw-r--r--lib/simulator.c7
-rw-r--r--src/compilo.c2
-rw-r--r--src/linker.c2
-rw-r--r--src/simul.c22
9 files changed, 70 insertions, 76 deletions
diff --git a/include/memoire.h b/include/memoire.h
index 88c9def..075d4a4 100644
--- a/include/memoire.h
+++ b/include/memoire.h
@@ -1,7 +1,7 @@
#ifndef __MEMOIRE_H__
#define __MEMOIRE_H__
#include "types.h"
-extern Uint32 * memoire_principale;
+extern Uint32 *memoire_principale;
Uint32 LD(Uint32 offset);
void ST(Uint32 offset, Uint32 valeur);
void InitMemoire(void);
diff --git a/include/simulator.h b/include/simulator.h
index 51b965d..c94ba5e 100644
--- a/include/simulator.h
+++ b/include/simulator.h
@@ -18,6 +18,6 @@ extern int debug, HasToRun;
void Initialisation(void);
void Flush(void);
-void ChargeBinaire(char * filename);
+void ChargeBinaire(char *filename);
-#endif \ No newline at end of file
+#endif
diff --git a/include/terminal.h b/include/terminal.h
index 763c965..cf3eafb 100644
--- a/include/terminal.h
+++ b/include/terminal.h
@@ -2,11 +2,11 @@
#define __TERMINAL_H__
#include <stdio.h>
-extern FILE * input;
+extern FILE *input;
extern struct termios initial_settings, new_settings;
void openterm(void);
void clearterm(void);
void initterm(void);
-#endif \ No newline at end of file
+#endif
diff --git a/lib/alu.c b/lib/alu.c
index 0adac7d..a23494e 100644
--- a/lib/alu.c
+++ b/lib/alu.c
@@ -15,34 +15,36 @@ Uint32 SecondResult = 0;
/* ALU rapide */
-Uint32 RNot(Uint32 a) {
+Uint32 RNot(Uint32 a)
+{
return (~a) + 1;
}
Uint32 RAdditionNonSigne(Uint32 a, Uint32 b)
{
unsigned long long tr = a, masq = 1;
+
tr += b;
-
+
masq <<= 32;
if (masq & tr) {
SetOverflow();
} else {
ResetOverflow();
}
-
+
if (tr) {
ResetZero();
} else {
SetZero();
}
-
+
if (tr & 1) {
SetParity();
} else {
ResetParity();
}
-
+
ResetSign();
return tr;
}
@@ -50,6 +52,7 @@ Uint32 RAdditionNonSigne(Uint32 a, Uint32 b)
Uint32 RAdditionSigne(long int a, long int b)
{
long int tr = a;
+
tr += b;
if (((a & 0x80000000) && (b & 0x80000000) && !(tr & 0x80000000)) ||
@@ -58,19 +61,19 @@ Uint32 RAdditionSigne(long int a, long int b)
} else {
ResetOverflow();
}
-
+
if (tr) {
ResetZero();
} else {
SetZero();
}
-
+
if (tr & 1) {
SetParity();
} else {
ResetParity();
}
-
+
if (tr & 0x80000000) {
SetSign();
} else {
@@ -159,7 +162,7 @@ Uint32 RDivisionNonSigne(Uint32 a, Uint32 b)
Uint32 RDivisionSigne(long int a, long int b)
{
long long temp = a;
-
+
temp /= b;
if (temp & 1) {
SetParity();
@@ -819,63 +822,50 @@ couple MultipliSig(Uint32 x, Uint32 y)
Uint32 NDivisionNonSigne(Uint32 a, Uint32 b)
{
Uint32 quot, rest;
- if (b>a)
- {
- quot=0;
- rest=a;
- }
- else
- {
- if (b==a)
- {
- quot=1;
- rest=0;
- }
- else
- {
- quot=0;
- rest=a;
- while (rest>=b)
- {
- rest=NSoustractionNonSigne(rest,b);
+
+ if (b > a) {
+ quot = 0;
+ rest = a;
+ } else {
+ if (b == a) {
+ quot = 1;
+ rest = 0;
+ } else {
+ quot = 0;
+ rest = a;
+ while (rest >= b) {
+ rest = NSoustractionNonSigne(rest, b);
quot++;
}
}
}
SecondResult = rest;
return quot;
-}
+}
Uint32 NDivisionSigne(long int a, long int b)
{
long int quot, rest;
-
- if (b>a)
- {
- quot=0;
- rest=a;
- }
- else
- {
- if (b==a)
- {
- quot=1;
- rest=0;
- }
- else
- {
- quot=0;
- rest=a;
- while (rest>=b)
- {
- rest=NSoustractionNonSigne(rest,b);
+
+ if (b > a) {
+ quot = 0;
+ rest = a;
+ } else {
+ if (b == a) {
+ quot = 1;
+ rest = 0;
+ } else {
+ quot = 0;
+ rest = a;
+ while (rest >= b) {
+ rest = NSoustractionNonSigne(rest, b);
quot++;
}
}
}
SecondResult = rest;
return quot;
-}
+}
Uint32 NMultiplicationNonSigne(Uint32 a, Uint32 b)
{
@@ -1004,4 +994,3 @@ Uint32 SHR(Uint32 a)
return NSHR(a);
}
}
-
diff --git a/lib/meta.c b/lib/meta.c
index 6a50ecf..be13434 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -579,20 +579,20 @@ void main(void)
fprintf(stderr, " + %s (%s) type: %s\n",
pattern->expr[i]->name ? pattern->expr[i]->name : "Opérateur [",
pattern->expr[i]->string ? pattern->expr[i]->string : "Aucune chaîne associée",
- pattern->expr[i]->type ? "Constante prédéfinie" : pattern->
- expr[i]->left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
+ pattern->expr[i]->type ? "Constante prédéfinie" : pattern->expr[i]->
+ left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
if (pattern->expr[i]->left) {
fprintf(stderr, " - gauche: %s (%s) type: %s\n",
pattern->expr[i]->left->name ? pattern->expr[i]->left->name : "Opérateur [",
- pattern->expr[i]->left->string ? pattern->expr[i]->
- left->string : "Aucune chaîne associée",
+ pattern->expr[i]->left->string ? pattern->expr[i]->left->
+ string : "Aucune chaîne associée",
pattern->expr[i]->left->type ? "Constante prédéfinie" : "Feuille");
}
if (pattern->expr[i]->right) {
fprintf(stderr, " - droite: %s (%s) type: %s\n",
pattern->expr[i]->right->name ? pattern->expr[i]->right->name : "Opérateur [",
- pattern->expr[i]->right->string ? pattern->expr[i]->
- right->string : "Aucune chaîne associée",
+ pattern->expr[i]->right->string ? pattern->expr[i]->right->
+ string : "Aucune chaîne associée",
pattern->expr[i]->right->type ? "Constante prédéfinie" : "Feuille");
}
}
diff --git a/lib/simulator.c b/lib/simulator.c
index 729e379..380c705 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -26,6 +26,7 @@ Uint32 LireInstruction(void)
void IncrementeCompteurOrdinal(void)
{
Uint32 of = LireRegistreFLAG();
+
EcrireRegistrePC(AdditionNonSigne(LireRegistrePC(), 1));
EcrireRegistreFLAG(of);
}
@@ -90,7 +91,8 @@ void Initialisation(void)
EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */
}
-void Flush(void) {
+void Flush(void)
+{
FlushMemoire();
}
@@ -415,7 +417,8 @@ void Debogueur(void)
fprintf(stderr, "Opcode: %02X, extension: %02X, champ1: %02X, champ2: %02X, champ3: %02X\n",
Opcode(instruction), Extension(instruction), Champ1(instruction), Champ2(instruction),
Champ3(instruction));
- fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ", LireRegistrePC(), instruction, LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
+ fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ", LireRegistrePC(), instruction,
+ LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
switch (fgetc(input)) {
case 'G':
diff --git a/src/compilo.c b/src/compilo.c
index 12a6f05..f2c4c98 100644
--- a/src/compilo.c
+++ b/src/compilo.c
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
fprintf(stderr, _("\nPerforming shutdown...\n\n"));
flush_all();
-
+
signal(SIGSEGV, NULL);
fprintf(stderr, _("Exitting, bye!\n"));
diff --git a/src/linker.c b/src/linker.c
index 5016703..727f76f 100644
--- a/src/linker.c
+++ b/src/linker.c
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
fprintf(stderr, _("\nPerforming shutdown...\n\n"));
flush_all();
-
+
signal(SIGSEGV, NULL);
fprintf(stderr, _("Exitting, bye!\n"));
diff --git a/src/simul.c b/src/simul.c
index e531150..19de608 100644
--- a/src/simul.c
+++ b/src/simul.c
@@ -40,16 +40,18 @@ void segfaulthand(int i)
exception(1, _("Signal received: segfault"));
}
-void ctrlbreakhand(int i) {
+void ctrlbreakhand(int i)
+{
debug = 1;
}
-char * readargs(int argc, char ** argv) {
- char * r = NULL;
-
+char *readargs(int argc, char **argv)
+{
+ char *r = NULL;
+
argc--;
argv++;
-
+
Rapide = 1;
while (argc) {
@@ -73,7 +75,7 @@ char * readargs(int argc, char ** argv) {
argv++;
argc--;
}
-
+
if (!r) {
usage();
}
@@ -83,7 +85,7 @@ char * readargs(int argc, char ** argv) {
int main(int argc, char **argv)
{
int i;
- char * nom;
+ char *nom;
invite();
@@ -91,7 +93,7 @@ int main(int argc, char **argv)
signal(SIGSEGV, segfaulthand);
signal(SIGINT, ctrlbreakhand);
-
+
fprintf(stderr, _("\nPerforming initialisation...\n\n"));
init_all();
@@ -102,12 +104,12 @@ int main(int argc, char **argv)
clearterm();
ChargeBinaire(nom);
clearterm();
-
+
popcontext();
fprintf(stderr, _("\nPerforming shutdown...\n\n"));
flush_all();
-
+
signal(SIGSEGV, NULL);
signal(SIGINT, NULL);