--- nono/vm/human68k.cpp 2026/04/29 17:04:28 1.1 +++ nono/vm/human68k.cpp 2026/04/29 17:04:32 1.1.1.3 @@ -6,6 +6,7 @@ // #include "human68k.h" +#include "mainapp.h" #include "mpu.h" #include "m68030bus.h" #include "m68030core.h" @@ -33,14 +34,14 @@ static bool human68k_fline_callback(m68kcpu *cpu, void *arg); // コンストラクタ -Human68k::Human68k(const char *file, const char *arg) +Human68k::Human68k() { logname = "human68k"; devname = "Human68k"; - assert(file); - human68k_file = file; - human68k_arg = arg; + assert(gMainApp.human68k_file); + human68k_file = gMainApp.human68k_file; + human68k_arg = gMainApp.human68k_arg; Files[0].fd = 0; Files[0].filename = strdup("|stdin"); @@ -63,15 +64,15 @@ Human68k::Init() uint8 *file; // ショートカット用 - ram = gRAM; + ram = gRAM.get(); // Fライン命令をこちらで処理する - gMPU->SetFLineCallback(human68k_fline_callback, this); + gMPU680x0->SetFLineCallback(human68k_fline_callback, this); // ワークを用意 (どこでやるか) // $CBC.B MPU 種別 (3:68030) gRAM->Write8(0x0cbc, 3); // $CBD.B FPU 有無 (0xff:あり) - if (gMPU->HaveFPU()) { + if (gMPU680x0->HaveFPU()) { gRAM->Write8(0x0cbd, 0xff); } @@ -80,13 +81,14 @@ Human68k::Init() // 実行ファイルオープン int file_fd = open(human68k_file, O_RDONLY); if (file_fd == -1) { - warn("open %s", human68k_file); + warn("Human68k executable \"%s\" open failed", human68k_file); return false; } struct stat st; if (fstat(file_fd, &st) != 0) { - warn("fstat %s", human68k_file); + warn("Human68k executable \"%s\" fstat failed", human68k_file); + close(file_fd); return false; } uint32 file_size; @@ -96,7 +98,8 @@ Human68k::Init() // mmap file = (uint8 *)mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, file_fd, 0); if (file == MAP_FAILED) { - warn("mmap"); + warn("Human68k executable \"%s\" mmap failed", human68k_file); + close(file_fd); return false; } @@ -113,12 +116,17 @@ Human68k::Init() } else if (file[0] == 0x60 && file[1] == 0x1a) { r = LoadZ(file, file_size); } else { - warnx("Invalid file extension"); + warnx("Human68k executable \"%s\" cannot identify file type", + human68k_file); + munmap(file, file_size); + close(file_fd); return false; } } if (!r) { - warnx("Invalid file format"); + warnx("Human68k executable \"%s\" invalid file format", human68k_file); + munmap(file, file_size); + close(file_fd); return false; } @@ -420,14 +428,12 @@ Human68k::WriteFile(int32 fileno, uint32 } IODeviceStream ds(ram, dataaddr); - uint8 *buf = new uint8[size]; + std::unique_ptr buf(new uint8[size]); for (int i = 0; i < size; i++) { buf[i] = ds.Read8(); } - int32 rv = write(f->fd, buf, size); - - delete[] buf; + int32 rv = write(f->fd, buf.get(), size); return rv; } @@ -498,7 +504,7 @@ Human68k::IOCS(m68kcpu *cpu) // MPU 状態の取得 RegD(0) = ((250) << 16) // 25.0MHz - | ((gMPU->HaveFPU() ? 1 : 0) << 15) // FPU + | ((gMPU680x0->HaveFPU() ? 1 : 0) << 15) // FPU | ((0) << 14) // MMU | ((3) << 0); // MPU Type break;