stuffs
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "../instruction.h"
|
||||
#include "../util.h"
|
||||
|
||||
// Table of strings to instructions
|
||||
struct _stringToInstructionOpcodeTable {char* str; InstructionOpcode opcode;} stringToInstructionOpcodeTable[] = {
|
||||
@@ -212,27 +213,15 @@ void serializeProgramToFile(Program* program, const char* outputFileName) {
|
||||
}
|
||||
|
||||
// Write magic header
|
||||
size_t written = fwrite("mlc\0", 4, 1, fp);
|
||||
if (written != 1) {
|
||||
fprintf(stderr, "failed to write magic header into file %s\n", outputFileName);
|
||||
fclose(fp);
|
||||
exit(1);
|
||||
}
|
||||
ROMFileHeader header = {
|
||||
.magic = "mlc\0",
|
||||
.version = 1,
|
||||
.numInstructions = program->len
|
||||
};
|
||||
|
||||
// Write program version
|
||||
uint8_t version = 1;
|
||||
written = fwrite(&version, sizeof(uint8_t), 1, fp);
|
||||
size_t written = fwrite(&header, sizeof(ROMFileHeader), 1, fp);
|
||||
if (written != 1) {
|
||||
fprintf(stderr, "failed to write version header into file %s\n", outputFileName);
|
||||
fclose(fp);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Write instruction count
|
||||
uint32_t instCount = program->len;
|
||||
written = fwrite(&instCount, sizeof(uint32_t), 1, fp);
|
||||
if (written != 1) {
|
||||
fprintf(stderr, "failed to write instruction count header into file %s\n", outputFileName);
|
||||
fprintf(stderr, "failed to write file header into file %s\n", outputFileName);
|
||||
fclose(fp);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
memcpy(emu->mem + MEM_PROGRAM_START, rom->instructions, sizeof(SerializedInst) * rom->header.numInstructions);
|
||||
|
||||
printf("hi i exist\n");
|
||||
|
||||
startEmulator(emu);
|
||||
freeEmulator(emu);
|
||||
|
||||
|
||||
@@ -2,4 +2,5 @@ mvi a 2
|
||||
mvi b 2
|
||||
|
||||
add a b
|
||||
hlt
|
||||
hlt
|
||||
hlt
|
||||
|
||||
Reference in New Issue
Block a user