#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) { }