diff --git a/CoreWar/Instruc b/CoreWar/Instruc deleted file mode 100755 index aaed576..0000000 Binary files a/CoreWar/Instruc and /dev/null differ diff --git a/CoreWar/Instruc.c b/CoreWar/Instruc.c deleted file mode 100644 index a8ebedb..0000000 --- a/CoreWar/Instruc.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include - -#include "Instruc.h" - -void printBits(size_t const size, void const * const ptr) -{ - unsigned char *b = (unsigned char*) ptr; - unsigned char byte; - int i, j; - - for (i = size-1; i >= 0; i--) { - for (j = 7; j >= 0; j--) { - byte = (b[i] >> j) & 1; - printf("%u", byte); - } - } - puts(""); -} - -long parseInst(char* instruction, char* argA, char* argB) { - long binaryInstruction; - - char a[100], b[100]; - - strcpy(a, argA); - strcpy(b, argB); - - if (!strcmp(instruction, "MOV")) binaryInstruction = 1; - else if (!strcmp(instruction, "ADD")) binaryInstruction = 2; - else if (!strcmp(instruction, "SUB")) binaryInstruction = 3; - else if (!strcmp(instruction, "JMP")) binaryInstruction = 4; - else if (!strcmp(instruction, "JMZ")) binaryInstruction = 5; - else if (!strcmp(instruction, "JMG")) binaryInstruction = 6; - else if (!strcmp(instruction, "DJZ")) binaryInstruction = 7; - else if (!strcmp(instruction, "CMP")) binaryInstruction = 8; - else if (!strcmp(instruction, "DAT")) binaryInstruction = 0; - binaryInstruction = binaryInstruction << 2; - - if (strlen(a) > 1) { - if (a[0] == '@') { - binaryInstruction += 2; - a[0] = ' '; - } else if (a[0] != '#') { - binaryInstruction += 1; - } else a[0] = ' '; - } - binaryInstruction = binaryInstruction << 2; - - if (strlen(b) > 1 && strcmp(instruction, "DAT")) { - if (b[0] == '@') { - binaryInstruction += 2; - b[0] = ' '; - } else if (b[0] != '#') { - binaryInstruction += 1; - } else b[0] = ' '; - } - binaryInstruction = binaryInstruction << 28; - - int da = atoi(a) % 8000; - int db = atoi(b) % 8000; - - while (da < 0) da += 8000; - while (db < 0) db += 8000; - - if (strlen(a) > 1) binaryInstruction += (da & 268435455); - binaryInstruction = binaryInstruction << 28; - if (strlen(b) > 1) binaryInstruction += (db & 268435455); - - return binaryInstruction; -} - -int convertFile(char* filename, char* destination) { - FILE* sourceFile = fopen(filename, "r"); - FILE* destFile = fopen(destination, "w"); - - char funcName[4], argA[10], argB[10]; - long code; - - fseek(sourceFile, 0L, SEEK_SET); - - if (sourceFile && destFile) { - while (!feof(sourceFile)) { - fscanf(sourceFile, "%s", funcName); - - strcpy(argA, ""); - strcpy(argB, ""); - - if (!strcmp(funcName, "JMP")) { - fscanf(sourceFile, "%s", argA); - } else if (!strcmp(funcName, "DAT")) { - fscanf(sourceFile, "%s", argB); - } else { - fscanf(sourceFile, "%s %s", argA, argB); - } - - code = parseInst(funcName, argA, argB); - fprintf(destFile, "%ld\n", code); - } - } else return 0; - - fclose(sourceFile); - fclose(destFile); -} \ No newline at end of file diff --git a/CoreWar/Instruc.h b/CoreWar/Instruc.h deleted file mode 100644 index 110701c..0000000 --- a/CoreWar/Instruc.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CONVERTER_H -#define CONVERTER_H - -void printBits(size_t const size, void const * const ptr); -long parseInst(char* instruction, char* argA, char* argB); - -int convertFile(char* filename, char* destination); - -#endif \ No newline at end of file diff --git a/CoreWar/Makefile b/CoreWar/Makefile deleted file mode 100644 index 7f266ed..0000000 --- a/CoreWar/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -corewar : Instruc.o core.o - gcc -o corewar.out main.c Instruc.o core.o - ./corewar.out - -Instruc.o : Instruc.c Instruc.h - gcc -c Instruc.c - -core.o : core.c core.h - gcc -c core.c - -clean : - rm -f *.o - rm -f redcode/*.mars - rm -f corewar.out \ No newline at end of file diff --git a/CoreWar/SAE12_2021 b/CoreWar/SAE12_2021 deleted file mode 160000 index 7b744c7..0000000 --- a/CoreWar/SAE12_2021 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7b744c7240255188005f7ce6c7eac66b1b12d7b0 diff --git a/CoreWar/core b/CoreWar/core deleted file mode 100755 index 07f5fe0..0000000 Binary files a/CoreWar/core and /dev/null differ diff --git a/CoreWar/core.c b/CoreWar/core.c deleted file mode 100644 index f9367f1..0000000 --- a/CoreWar/core.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include - -#include "core.h" - -int virus1Address, virus2Address; - -int setupViruses(long memory[8000]) { - srand(time(NULL)); - int randAddress = rand() % 8000; - int virusLines = 0; - long instruction; - - virus1Address = randAddress; - - FILE* virusFile = fopen("redcode/virus1.mars", "r"); - - if (virusFile) { - fseek(virusFile, 0L, SEEK_SET); - while (!feof(virusFile)) { - instruction = 0; - fscanf(virusFile, "%ld", &instruction); - memory[(randAddress + virusLines) % 8000] = instruction; - virusLines++; - } - } else { - puts("Could not load Virus 1."); - return 0; - } - - fclose(virusFile); - srand(rand()); - - virusFile = fopen("redcode/virus2.mars", "r"); - - if (virusFile) { - long trash; - while(!feof(virusFile)) { - fscanf(virusFile, "%ld", &trash); - virusLines++; - } - - fseek(virusFile, 0L, SEEK_SET); - - randAddress = (randAddress + rand()) % (8000 - virusLines); - virus2Address = randAddress; - virusLines = 0; - - while (!feof(virusFile)) { - instruction = 0; - fscanf(virusFile, "%ld", &instruction); - memory[(randAddress + virusLines) % 8000] = instruction; - virusLines++; - } - } else { - puts("Could not load Virus 1."); - return 0; - } - - fclose(virusFile); -} - -void execInst(int address, long instruction) { - -} \ No newline at end of file diff --git a/CoreWar/core.h b/CoreWar/core.h deleted file mode 100644 index 22f476e..0000000 --- a/CoreWar/core.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef MARS_H -#define MARS_H - -int setupViruses(long memory[8000]); -void execInst(int address, long instruction); - -#endif \ No newline at end of file diff --git a/CoreWar/main.c b/CoreWar/main.c deleted file mode 100644 index 545b24c..0000000 --- a/CoreWar/main.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -#include "Instruc.h" -#include "core.h" - -int main (int argc, char* argv[]){ - long mainMemory[8000] = {}; - convertFile("redcode/redcode.ass","redcode/virus1.mars"); - convertFile("redcode/redcode.ass","redcode/virus2.mars"); - setupViruses(mainMemory); - - for (int i = 0; i < 8000; ++i) { - if (mainMemory[i] != 0) { - printf("%d -> %ld\n", i, mainMemory[i]); - } - } - -} \ No newline at end of file diff --git a/CoreWar/redcode/redcode.ass b/CoreWar/redcode/redcode.ass deleted file mode 100644 index b3c3b5e..0000000 --- a/CoreWar/redcode/redcode.ass +++ /dev/null @@ -1,4 +0,0 @@ -DAT -1 -ADD #57 -1 -MOV #0 @-2 -JMP -2 \ No newline at end of file diff --git a/CoreWar/redcode/virus1.mars b/CoreWar/redcode/virus1.mars deleted file mode 100644 index 119a107..0000000 --- a/CoreWar/redcode/virus1.mars +++ /dev/null @@ -1,4 +0,0 @@ -7999 -2377900618552450879 -1297036692682710846 -4899918541525876736 diff --git a/CoreWar/redcode/virus2.mars b/CoreWar/redcode/virus2.mars deleted file mode 100644 index 119a107..0000000 --- a/CoreWar/redcode/virus2.mars +++ /dev/null @@ -1,4 +0,0 @@ -7999 -2377900618552450879 -1297036692682710846 -4899918541525876736