(uxncli) Load ROM using the File device functions.

This commit is contained in:
Andrew Alderwick 2022-03-28 18:51:29 +01:00
parent 42dea5b914
commit 47f65c7b82
3 changed files with 15 additions and 14 deletions

View File

@ -215,3 +215,15 @@ file_dei(Device *d, Uint8 port)
} }
return d->dat[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;
}

View File

@ -15,3 +15,4 @@ WITH REGARD TO THIS SOFTWARE.
void file_deo(Device *d, Uint8 port); void file_deo(Device *d, Uint8 port);
Uint8 file_dei(Device *d, Uint8 port); Uint8 file_dei(Device *d, Uint8 port);
int load_rom(Uxn *u, char *filename);

View File

@ -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 int
uxn_interrupt(void) uxn_interrupt(void)
{ {
@ -126,8 +113,9 @@ main(int argc, char **argv)
return error("Usage", "uxncli game.rom args"); return error("Usage", "uxncli game.rom args");
if(!start(&u)) if(!start(&u))
return error("Start", "Failed"); return error("Start", "Failed");
if(!load(&u, argv[1])) if(!load_rom(&u, argv[1]))
return error("Load", "Failed"); return error("Load", "Failed");
fprintf(stderr, "Loaded %s\n", argv[1]);
if(!uxn_eval(&u, PAGE_PROGRAM)) if(!uxn_eval(&u, PAGE_PROGRAM))
return error("Init", "Failed"); return error("Init", "Failed");
for(i = 2; i < argc; i++) { for(i = 2; i < argc; i++) {