From 7b744c7240255188005f7ce6c7eac66b1b12d7b0 Mon Sep 17 00:00:00 2001 From: baillyj Date: Fri, 17 Dec 2021 15:16:52 +0100 Subject: [PATCH] Try 20 --- core.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ core.h | 7 +++++++ 2 files changed, 73 insertions(+) create mode 100644 core.c create mode 100644 core.h diff --git a/core.c b/core.c new file mode 100644 index 0000000..f9367f1 --- /dev/null +++ b/core.c @@ -0,0 +1,66 @@ +#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/core.h b/core.h new file mode 100644 index 0000000..22f476e --- /dev/null +++ b/core.h @@ -0,0 +1,7 @@ +#ifndef MARS_H +#define MARS_H + +int setupViruses(long memory[8000]); +void execInst(int address, long instruction); + +#endif \ No newline at end of file