This commit is contained in:
Richard
2026-03-26 18:43:01 +01:00
commit 9616a8236b
25 changed files with 2773 additions and 0 deletions

24
farm/program.c Normal file
View File

@@ -0,0 +1,24 @@
#include "program.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
struct Program* load_program(char* filename) {
FILE* f = fopen(filename, "r");
if (f == NULL) {
return NULL;
}
int num_instructions;
int num_read = fread(&num_instructions, 4, 1, f);
if (num_read != 1) {
return NULL;
}
int program_size = 4 + num_instructions * 4;
struct Program* program = (struct Program *)malloc(program_size);
program->num_instructions = num_instructions;
num_read = fread(&program->instructions, 1, program_size-4, f);
if (num_read != program_size-4) {
return NULL;
}
fclose(f);
return program;
}