--- nono/vm/rom.cpp 2026/04/29 17:05:29 1.1.1.13 +++ nono/vm/rom.cpp 2026/04/29 17:05:42 1.1.1.14 @@ -48,6 +48,22 @@ ROMDevice::~ROMDevice() { } +// ROM 用の領域を用意する。 +bool +ROMDevice::AllocROM(uint len, uint8 fill) +{ + imagebuf.reset(new(std::nothrow) uint8 [len]); + if ((bool)imagebuf == false) { + warnx("Cannot allocate %u bytes at %s", len, __method__); + return false; + } + memset(&imagebuf[0], fill, len); + mem = &imagebuf[0]; + mask = len - 1; + + return true; +} + // name の ROM を探してロードする。 // name はパスを含まないファイル名のみ。パスはこちらで探す。 // 失敗した場合はエラーメッセージを表示して false を返す。 @@ -66,7 +82,7 @@ ROMDevice::LoadROM(const char *name, uin } // メモリを確保 - imagebuf.reset(new uint8 [size]); + imagebuf.reset(new(std::nothrow) uint8 [size]); if ((bool)imagebuf == false) { warnx("ROM \"%s\": Cannot allocate memory (%u bytes)", filename.c_str(), size);