summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/memoire.c7
-rw-r--r--lib/simulator.c48
-rw-r--r--lib/terminal.c34
4 files changed, 73 insertions, 18 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 352f089..dedd82d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = -I. -I.. -I$(includedir) -I../include
lib_LTLIBRARIES = libCompilo.la libSimul.la libLinker.la
libCompilo_la_SOURCES = assembler.c parser.c meta.c numbers.c hash.c exceptions.c
-libSimul_la_SOURCES = alu.c simulator.c exceptions.c fpu.c interne.c memoire.c registre.c
+libSimul_la_SOURCES = alu.c simulator.c exceptions.c fpu.c interne.c memoire.c registre.c terminal.c
libLinker_la_SOURCES = linker.c exceptions.c hash.c
libCompilo_la_LDFLAGS = -version-info $(ProjetArchi_VERSION_INFO)
diff --git a/lib/memoire.c b/lib/memoire.c
index ee99983..48daf0e 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -2,6 +2,7 @@
#include "interne.h"
#include "simulator.h"
#include "exceptions.h"
+#include "terminal.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
@@ -10,6 +11,8 @@
char temp[BUFSIZ];
+Uint32 * memoire_principale;
+
/*****************************************/
/** **/
@@ -28,7 +31,9 @@ Uint32 LD(Uint32 offset)
case 0xffffff01:
return (fgetc(stdin));
case 0xffffff05:
- fscanf(stdin, "%i", &i);
+ clearterm();
+ fscanf(input, "%i", &i);
+ initterm();
return i;
default:
if (offset >= TAILLE_MEMOIRE) {
diff --git a/lib/simulator.c b/lib/simulator.c
index 247a8c4..d542a07 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -14,19 +14,12 @@
#include "fpu.h"
#include "exceptions.h"
#include "linker.h"
+#include "terminal.h"
-/*
- initialisation de la MP avec un malloc
- fermeture du prog et free
- catch du ctrl-c
- */
-
-
-int HasToRun = 1, HasToReset;
+int HasToRun = 1, HasToReset = 0, debug = 0;
Uint32 base_addr = 0;
-
Uint32 LireInstruction(void)
{
return (LD(LireRegistrePC()));
@@ -373,22 +366,45 @@ void AfficheReg(void) // affiche reg
for (i = 0; i <= 3; i++) {
for (j = 1; j <= 8; j++) {
- printf(" R%02d ", (i * 8 + j));
+ fprintf(stderr, " R%02d ", (i * 8 + j));
}
- printf("\n");
+ fprintf(stderr, "\n");
for (j = 1; j <= 8; j++) {
- printf("%08lX ", (registre[i * 8 + j - 1]));
+ fprintf(stderr, "%08lX ", (registre[i * 8 + j - 1]));
}
- printf("\n");
+ fprintf(stderr, "\n");
}
- printf("Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(),
+ fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n\n", LireRegistreRG(), LireRegistreRD(),
LireRegistreFLAG(), registre[REG_PC]);
- printf("\n");
}
void Debogueur(void)
{
- AfficheReg();
+ int out = 0;
+
+ while (!out) {
+ AfficheReg();
+ printf("%08lX:%08lX > ", LireRegistrePC(), LD(LireRegistrePC()));
+
+ switch (fgetc(input)) {
+ case 'G':
+ case 'g':
+ fprintf(stderr, "Go\n")
+ debug = 0;
+ out = 1;
+ break;
+ case 'p':
+ case 'P':
+ fprintf(stderr, "Proceed\n");
+ out = 1;
+ break;
+ case 'R':
+ case 'r':
+ break;
+ default:
+ fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\n\n");
+ }
+ }
}
void ChargeBinaire(char *filename)
diff --git a/lib/terminal.c b/lib/terminal.c
new file mode 100644
index 0000000..df3e61d
--- /dev/null
+++ b/lib/terminal.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <termios.h>
+#include <string.h>
+#include "config.h"
+
+FILE *input;
+struct termios initial_settings, new_settings;
+
+void initterm() {
+ tcgetattr(fileno(input), &initial_settings);
+ new_settings = initial_settings;
+ new_settings.c_lflag &= ~ICANON;
+ new_settings.c_lflag &= ~ECHO;
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+ new_settings.c_lflag &= ~ISIG;
+
+ if (tcsetattr(fileno(input), TCSANOW, &new_settings) != 0) {
+ exception(1, _("could not set terminal attributes"));
+ }
+
+}
+
+void clearterm() {
+ tcsetattr(fileno(input), TCSANOW, &initial_settings);
+}
+
+void openterm() {
+ if (!(input = fopen("/dev/tty", "r"))) {
+ exception(1, _("could not open terminal"));
+ }
+}