diff options
author | Pixel <> | 2001-04-16 17:40:18 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-16 17:40:18 +0000 |
commit | 9ce986215bb20165d5342245da893f9e9c05cf6d (patch) | |
tree | 3c567519ff2965a885d08569b1ca18e762fec9f2 /lib | |
parent | fc38c729eed19df92d2294fab1491810e86252ec (diff) |
Memoire
Diffstat (limited to 'lib')
-rw-r--r-- | lib/memoire.c | 92 |
1 files changed, 81 insertions, 11 deletions
diff --git a/lib/memoire.c b/lib/memoire.c index 36b2afa..869c708 100644 --- a/lib/memoire.c +++ b/lib/memoire.c @@ -8,6 +8,8 @@ #define _(x) x #endif +char temp[BUFSIZ]; + /*****************************************/ /** **/ @@ -19,22 +21,90 @@ Uint32 LD(Uint32 offset) { Uint32 i; + + switch (offset) { + case 0xffffff00: + return (!feof(stdin)); + case 0xffffff01: + return (fgetc(stdin)); + case 0xffffff05: + fscanf(stdin, "%i", &i); + return i; + default: + if (offset >= TAILLE_MEMOIRE) { + exception(1, _("Invalid Memory Adress")); + return (i); + } else { + i = memoire_principale[offset]; + return (i); + } + break; + } +} - Reset(&i); - if (offset < 0 || offset >= TAILLE_MEMOIRE) { - exception(1, _("Invalid Memory Adress")); - return (i); - } else { - i = memoire_principale[offset]; - return (i); +static void copychaine(Uint32 * t, char * s) { + while (*s) { + *(t++) = *(s++); + } +} + +static void litchaine(char * s, Uint32 * t) { + while (*t) { + *(s++) = *(t++); + } +} + +static void Affiche(Uint32 * t) { + while (*t) { + fprintf(stdout, "%c", (*t++)); + } +} + +static void AfficheBinaire(Uint32 valeur) { + if (valeur) { + AfficheBinaire(valeur >> 1); + fprintf(stdout, "%i", valeur & 1); } } /* Ecrit le mot 'valeur' à l'offset 'offset' en mémoire */ void ST(Uint32 offset, Uint32 valeur) { - if (offset < 0 || offset >= TAILLE_MEMOIRE) - exception(1, _("Invalid Memory Adress")); - else - memoire_principale[offset] = valeur; + switch (offset) { + case 0xffffff02: + fgets(temp, BUFSIZ, stdin); + copychaine(&memoire_principale[valeur], temp); + break; + case 0xffffff03: + fprintf(stdout, "%c", valeur); + break; + case 0xffffff04: + Affiche(&memoire_principale[valeur]); + break; + case 0xffffff06: + fprintf(stdout, "%i", valeur); + break; + case 0xffffff07: + fprintf(stdout, "%x", valeur); + break; + case 0xffffff08: + fprintf(stdout, "%o", valeur); + break; + case 0xffffff09: + if (valeur) { + AfficheBinaire(valeur); + } else { + fprintf(stdout, "0"); + } + break; + case 0xffffff0a: + litchaine(temp, &memoire_principale[valeur]); + ChargeBinaire(char * temp); + default: + if (offset < 0 || offset >= TAILLE_MEMOIRE) + exception(1, _("Invalid Memory Adress")); + else + memoire_principale[offset] = valeur; + break; + } } |