From 95356a12e955ac8d42e8bb4632075bf13021e201 Mon Sep 17 00:00:00 2001 From: Manuel Palenzuela Date: Mon, 19 Jul 2021 14:20:20 +0100 Subject: Feature: Added basic rom loading --- emulator.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'emulator.c') diff --git a/emulator.c b/emulator.c index e69de29..afc78b1 100644 --- a/emulator.c +++ b/emulator.c @@ -0,0 +1,29 @@ +#include + +int emulator_load_rom(Emulator* emulator, char* rom_name) +{ + printf("load rom!: %s\n", rom_name); + FILE* rom = fopen(rom_name, "r"); + if(rom == NULL) + { + perror("no rom file!\n"); + return 1; + } + + struct stat st; + fstat(fileno(rom), &st); + + int bytes_read = fread(emulator->memory, 1, st.st_size, rom); + if(bytes_read != st.st_size) + { + perror("doesnt cuadrar\n"); + return 2; + } + + return 0; +} + +int emulator_tick(Emulator* emulator) +{ + return 0; +} -- cgit 1.4.1