summaryrefslogtreecommitdiff
path: root/src/simul.c
blob: 3701ea10319d47977aba90e9670350f0b4190c52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>

#include "config.h"
#include "simulator.h"
#include "alu.h"
#include "terminal.h"
#include "exceptions.h"

typedef void (*sighandler_t) (int);

void invite(void)
{
    fprintf(stderr, _("Simul v1.0\n\n"));
}

void usage(void)
{
    fprintf(stderr, _("Usage: linker [-s] [-d] binary\n"));
    exit(0);
}

void init_all(void)
{
    fprintf(stderr, _(" o Initialising the simulator...   "));

    Initialisation();
    fprintf(stderr, _(" Done!\n"));
}

void flush_all(void)
{
    Flush();
}

void segfaulthand(int i)
{
    exception(1, _("Signal received: segfault"));
}

void ctrlbreakhand(int i)
{
    debug = 1;
}

char *readargs(int argc, char **argv)
{
    char *r = NULL;

    argc--;
    argv++;

    Rapide = 1;

    while (argc) {
	if (**argv == '-') {
	    switch ((*argv)[1]) {
	    case 's':
		Rapide = 0;
		break;
	    case 'd':
		debug = 1;
		break;
	    default:
		usage();
	    }
	} else {
	    if (r) {
		usage();
	    }
	    r = *argv;
	}
	argv++;
	argc--;
    }

    if (!r) {
	usage();
    }
    return r;
}

int main(int argc, char **argv)
{
    int i;
    char *nom;

    invite();

    nom = readargs(argc, argv);

    signal(SIGSEGV, segfaulthand);
    signal(SIGINT, ctrlbreakhand);

    fprintf(stderr, _("\nPerforming initialisation...\n\n"));
    init_all();

    pushcontext(_("Beginning simulation"));

    openterm();
    initterm();
    clearterm();
    ChargeBinaire(nom);
    clearterm();

    popcontext();

    fprintf(stderr, _("\nPerforming shutdown...\n\n"));
    flush_all();

    signal(SIGSEGV, NULL);
    signal(SIGINT, NULL);

    fprintf(stderr, _("Exitting, bye!\n"));
    return 0;
}