diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 14:20:20 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 14:20:20 +0100 |
commit | 95356a12e955ac8d42e8bb4632075bf13021e201 (patch) | |
tree | c97e38a0edf35a7edafdb3a08114902edb050676 /emulator.c | |
parent | Added Readme (diff) | |
download | CHIP8-Emulator-95356a12e955ac8d42e8bb4632075bf13021e201.tar.gz CHIP8-Emulator-95356a12e955ac8d42e8bb4632075bf13021e201.tar.bz2 CHIP8-Emulator-95356a12e955ac8d42e8bb4632075bf13021e201.zip |
Feature: Added basic rom loading
Diffstat (limited to 'emulator.c')
-rw-r--r-- | emulator.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/emulator.c b/emulator.c index e69de29..afc78b1 100644 --- a/emulator.c +++ b/emulator.c @@ -0,0 +1,29 @@ +#include <emulator.h> + +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; +} |