main: fixed error handling when we can't read rom file

This commit is contained in:
(Tim) Efthimis Kritikos 2024-01-23 17:43:08 +00:00
parent b1c9177460
commit 756d8a49d9

8
main.c
View File

@ -23,6 +23,7 @@
#include "simdata.h" #include "simdata.h"
#include "stdint.h" #include "stdint.h"
#include <unistd.h> #include <unistd.h>
#include <errno.h>
void help(char* progname){ void help(char* progname){
printf("Usage: %s -i <file> \n", progname); printf("Usage: %s -i <file> \n", progname);
@ -54,6 +55,13 @@ int main(int argc, char* argd[] ){
/// READ ROM FILE /// /// READ ROM FILE ///
FILE* rom=fopen(infile,"r"); FILE* rom=fopen(infile,"r");
if (rom == NULL) {
printf("ERROR: Couldn't open rom file\n");
perror(infile);
return 1;
}
fseek(rom, 0, SEEK_END); fseek(rom, 0, SEEK_END);
if(ftell(rom)!=16777216){ if(ftell(rom)!=16777216){
printf("ERROR: ROM file isn't 16MiB\n"); printf("ERROR: ROM file isn't 16MiB\n");