Try 20
This commit is contained in:
parent
6dbc75c640
commit
7b744c7240
66
core.c
Normal file
66
core.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#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) {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user