From c0d358028ba9f795f1775c191d7b0992fcd7a8ed Mon Sep 17 00:00:00 2001 From: Yvan Date: Fri, 17 Dec 2021 10:36:49 +0100 Subject: [PATCH] je ne dors plus --- Makefile | 6 ++++-- mars_main.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- mars_types.h | 6 +++++- options.h | 6 ++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 options.h diff --git a/Makefile b/Makefile index f8ae18e..afb6851 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ OFILES = mars_main.o main.out: $(OFILES) gcc ${OFILES} -o main.out -lgraph -mars_main.o: mars_main.c mars_types.h +mars_main.o: mars_main.c mars_types.h options.h gcc -c mars_main.c clean: rm *.o *.out -.PHONY: clean \ No newline at end of file +clear: + rm *.o *.out +.PHONY: clean clear \ No newline at end of file diff --git a/mars_main.c b/mars_main.c index 92da516..3fad833 100644 --- a/mars_main.c +++ b/mars_main.c @@ -1,12 +1,46 @@ #include #include +#include #include /* Utilisé pour obtenir une adresse de démarrage aléatoire */ #include"mars_types.h" /* importe les types utilisés dans le programme */ +#include"options.h" /* Inclus les options du programme */ + +void initialiser_memoire(); /* Va initialiser la mémoire en plaçant les deux programmes dans des adresses aléatoires */ + +int calculer_position(); /* Va permettre de calculer la position à laquelle le programme doit effectuer une action*/ + +void execute_instruction(union mars_instruction instruction, int player, struct adresse memoire[8000], int position[2]){ + short int operation = instruction.instruct.codeOp; + + if(operation == MOV){ + /* Transfère contenu adresse A à Adresse B */ + printf("on a demandé un mov noice\n"); + } else if (operation == ADD){ + /* Ajoute contenu adresse A à adresse B */ + printf("test"); + } else if (operation == SUB){ + /* Soustrait contenu adresse A à l'adresse B */ + } else if (operation == JMP){ + /* On saute à la position demandée par l'instruction */ + } else if (operation == JMZ){ + /* Transferer execution à adresse A si contenu adresse b = 0*/ + } else if (operation == JMG){ + /* Transferer execution à l'adresse A si contenu B > 0 */ + } else if (operation == DJZ){ + /* Retrancher 1 du contenu de l'adresse B et sauter à l'adresse A si seulement resultat = 0 */ + }else if (operation == CMP){ + /* Compare deux adresses, si différents sauter l'instruction suivante */ + }else if (operation == DAT){ + /* Cette instruction ne peut pas être exécutée, elle permet de contenir une valeur */ + } +} int main(int argc, char* argv[]){ - int position_player1, position_player2; /* Permet de connaître la position des joueurs dans la mémoire */ - struct adresse memoire[8000]; // Initialisation de la mémoire 0->7999 + srand(time(NULL)); /* Initialise le pseudo aléatoire pour tout le programme */ + + struct adresse memoire[TAILLE_MEM]; // Initialisation de la mémoire 0->7999 + int position[2] = {0,0}; /* Position des joueurs */ if (argc < 3){ printf("Vous n'avez pas rentrez assez d'arguments \n"); @@ -36,5 +70,15 @@ int main(int argc, char* argv[]){ fclose(fichier1); fclose(fichier2); + + union mars_instruction to_do; + to_do.instruct.codeOp = 1; + to_do.instruct.ArgA = 7909; + to_do.instruct.ArgB = 100; + to_do.instruct.modeAddrA = 1; + to_do.instruct.modeAddrB = 2; + printf("Valeur instruction: %lld\n", to_do.instructLL); + execute_instruction(to_do, 1, memoire, position); + return EXIT_SUCCESS; } diff --git a/mars_types.h b/mars_types.h index 2340b36..c7638ad 100644 --- a/mars_types.h +++ b/mars_types.h @@ -1,5 +1,4 @@ #ifndef MARS_TYPES_H - #define MARS_TYPES_H struct adresse { @@ -19,4 +18,9 @@ union mars_instruction { short int ArgB; } instruct; }; + +/* Listes des opérations possibles */ + +enum liste_operations {DAT,MOV, ADD, SUB, JMP, JMZ, JMG, DJZ, CMP}; + #endif \ No newline at end of file diff --git a/options.h b/options.h new file mode 100644 index 0000000..6cba58c --- /dev/null +++ b/options.h @@ -0,0 +1,6 @@ +#ifndef OPTIONS_H + +#define OPTIONS_H +#define TAILLE_MEM 8000 + +#endif \ No newline at end of file