--- nono/vm/rom.cpp 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/rom.cpp 2026/04/29 17:04:36 1.1.1.3 @@ -1,13 +1,12 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include -#include -#include #include "rom.h" -#include "configfile.h" +#include "mainapp.h" +#include "mystring.h" // // ROM 共通部 @@ -25,10 +24,6 @@ ROMDevice::ROMDevice() ROMDevice::~ROMDevice() { - if (file) { - free(file); - file = NULL; - } } // name の ROM を探してロードする。 @@ -38,32 +33,20 @@ ROMDevice::~ROMDevice() bool ROMDevice::LoadROM(const char *name, int size) { - filename = gConfig->SearchFile(name); + filename = gMainApp.SearchFile(name); if (filename.empty()) { - warn("%s: cannot find %s", devname, filename.c_str()); + warnx("%s not found", name); return false; } // オープン - fd = open(filename.c_str(), O_RDONLY); - if (fd == -1) { - warn("%s: cannot open %s", devname, filename.c_str()); - return false; - } - - // mmap - // ファイルには書き戻さないけど、オンメモリでハックを入れることが - // できるように MAP_PRIVATE を指定する。 - filesize = size; - file = (uint8 *)mmap(NULL, filesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE, fd, 0); - if (file == MAP_FAILED) { - warn("%s: cannot mmap %s", devname, filename.c_str()); - close(fd); + file.SetFilename(filename); + file.SetDispname(string_format("ROM \"%s\"", filename.c_str())); + mem = file.OpenRdOnly((off_t)size); + if (mem == NULL) { return false; } - mem = file; return true; }