diff --git a/src/devices/file.c b/src/devices/file.c index 906ac73..c0ecc4e 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -215,3 +215,15 @@ file_dei(Device *d, Uint8 port) } return d->dat[port]; } + +/* Boot */ + +int +load_rom(Uxn *u, char *filename) +{ + int ret; + file_init(uxn_file, filename, strlen(filename) + 1); + ret = file_read(uxn_file, &u->ram[PAGE_PROGRAM], 0x10000 - PAGE_PROGRAM); + reset(uxn_file); + return ret; +} diff --git a/src/devices/file.h b/src/devices/file.h index 9fc5b44..f6db406 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -15,3 +15,4 @@ WITH REGARD TO THIS SOFTWARE. void file_deo(Device *d, Uint8 port); Uint8 file_dei(Device *d, Uint8 port); +int load_rom(Uxn *u, char *filename); diff --git a/src/uxncli.c b/src/uxncli.c index bb3eb47..1c2ccda 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -74,19 +74,6 @@ run(Uxn *u) } } -static int -load(Uxn *u, char *filepath) -{ - FILE *f; - int r; - if(!(f = fopen(filepath, "rb"))) return 0; - r = fread(u->ram + PAGE_PROGRAM, 1, 0x10000 - PAGE_PROGRAM, f); - fclose(f); - if(r < 1) return 0; - fprintf(stderr, "Loaded %s\n", filepath); - return 1; -} - int uxn_interrupt(void) { @@ -126,8 +113,9 @@ main(int argc, char **argv) return error("Usage", "uxncli game.rom args"); if(!start(&u)) return error("Start", "Failed"); - if(!load(&u, argv[1])) + if(!load_rom(&u, argv[1])) return error("Load", "Failed"); + fprintf(stderr, "Loaded %s\n", argv[1]); if(!uxn_eval(&u, PAGE_PROGRAM)) return error("Init", "Failed"); for(i = 2; i < argc; i++) {