uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 47f65c7b82a6fce27c9728882a9d30fc12b32fbd
parent 42dea5b9145f99333300ecf8a46a180d3e71871f
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 28 Mar 2022 18:51:29 +0100

(uxncli) Load ROM using the File device functions.

Diffstat:
Msrc/devices/file.c | 12++++++++++++
Msrc/devices/file.h | 1+
Msrc/uxncli.c | 16++--------------
3 files changed, 15 insertions(+), 14 deletions(-)

diff --git 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 @@ -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 @@ -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++) {