diff --git a/Makefile b/Makefile index 1bb8525..aa5043c 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ all:first first:gui.o main.o simdata.o - gcc $^ -fsanitize=address -lncurses -ltinfo -o $@ + gcc -ggdb $^ -fsanitize=address -lncurses -ltinfo -o $@ %.o:%.c - gcc -c $< -Wall -Wextra -Werror -fsanitize=address + gcc -ggdb -c $< -Wall -Wextra -Werror -fsanitize=address .PHONY: clean clean: diff --git a/gui.c b/gui.c index d44d95e..906e02f 100644 --- a/gui.c +++ b/gui.c @@ -51,6 +51,7 @@ int start_gui(){ start_color(); init_pair(1, COLOR_RED, COLOR_BLACK); } + noecho(); curs_set(0); get_terminal_size(); mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator..."); diff --git a/main.c b/main.c index 2cff58d..1ed7249 100644 --- a/main.c +++ b/main.c @@ -22,35 +22,88 @@ #include "gui.h" #include "simdata.h" #include "stdint.h" +#include -int main(){ - if(start_gui()){ - printf("Failed on start_gui()\n"); +void help(char* progname){ + printf("Usage: %s -i \n", progname); +} + +int main(int argc, char* argd[] ){ + /// PARSE COMMAND LINE /// + char *infile = NULL; + int opt; + while ((opt = getopt(argc, argd, "hi:")) != -1) { + switch (opt) { + case 'h': + help(argd[0]); + return 0; + break; + case 'i': + infile=optarg; + break; + default: + help(argd[0]); + return 1; + break; + } + } + if (infile==NULL){ + help(argd[0]); return 1; } + /// READ ROM FILE /// + FILE* rom=fopen(infile,"r"); + fseek(rom, 0, SEEK_END); + if(ftell(rom)!=16777216){ + printf("ERROR: ROM file isn't 16MiB\n"); + return 1; + } + fseek(rom, 0, SEEK_SET); + uint8_t *RAM=malloc(16777216); //Maximum addressable memory if(!RAM){ gui_error("failed to allocate 16MiB of memory for the system ram"); return 1; } + if(fread(RAM, 16777216, 1, rom)==0){ + printf("ERROR: failed to read input file\n"); + free(RAM); + return 1; + } + fclose(rom); + + + /// INITIALISE GUI /// + if(start_gui()){ + printf("Failed on start_gui()\n"); + free(RAM); + return 1; + } + struct simdata_t *simdata = init_simdata(); if(!simdata){ gui_error("failed to initialise simdata"); + free(RAM); return 1; } - gui_error("failed to initialise simdata"); + char *temp=malloc(1000); + sprintf(temp,"Last byte of ram is 0x%02x",RAM[0xFFFFFF]); + gui_error(temp); + free(temp); if(gui_continue_request()){ end_gui(); printf("Failed on gui_continue_request()\n"); free_simdata(simdata); + free(RAM); return 1; } if(end_gui()){ printf("Failed on end_gui()\n"); free_simdata(simdata); + free(RAM); return 1; }