--- nono/vm/human68k.cpp 2026/04/29 17:04:29 1.1.1.2 +++ nono/vm/human68k.cpp 2026/04/29 17:04:35 1.1.1.4 @@ -1,19 +1,22 @@ // // nono -// Copyright (C) 2017 Y.Sugahara (moveccr) +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + // // human68k .r .x .z console emulator // #include "human68k.h" -#include "mpu.h" -#include "m68030bus.h" -#include "m68030core.h" #include "bus.h" #include "iodevstream.h" +#include "mainapp.h" +#include "m68030bus.h" +#include "m68030core.h" +#include "mpu680x0.h" #include "scheduler.h" #include "vm.h" -#include #include #include #include @@ -33,21 +36,21 @@ 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"); + Files[0].filename = "|stdin"; Files[1].fd = 1; - Files[1].filename = strdup("|stdout"); + Files[1].filename = "|stdout"; Files[2].fd = 2; - Files[2].filename = strdup("|stderr"); + Files[2].filename = "|stderr"; } // デストラクタ @@ -63,15 +66,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); } @@ -117,11 +120,15 @@ Human68k::Init() } else { warnx("Human68k executable \"%s\" cannot identify file type", human68k_file); + munmap(file, file_size); + close(file_fd); return false; } } if (!r) { warnx("Human68k executable \"%s\" invalid file format", human68k_file); + munmap(file, file_size); + close(file_fd); return false; } @@ -338,7 +345,7 @@ Human68k::OpenFile(uint32 fileaddr, uint { // XXX: unix host only - int32 fileno; + int32 fileno {}; Human68k::File *f = NULL; // 開いているエントリを検索して Human fileno を取得 @@ -378,7 +385,7 @@ Human68k::OpenFile(uint32 fileaddr, uint } f->fd = fd; - f->filename = strdup(filename); + f->filename = filename; return fileno; } @@ -394,13 +401,13 @@ Human68k::CloseFile(int32 fileno) return -1; } f = &Files[fileno]; - putmsg(1, "CloseFile: %d %s", fileno, f->filename); + putmsg(1, "CloseFile: %d %s", fileno, f->filename.c_str()); if (f->fd > 2) { // stdin/out/err は閉じない close(f->fd); } f->fd = -1; - free(f->filename); + f->filename.clear(); return 0; } @@ -423,14 +430,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; } @@ -452,7 +457,7 @@ Human68k::FputsFile(int32 fileno, uint32 IODeviceStream ds(ram, dataaddr); int size = 1024; - uint8 buf[size]; + std::vector buf(size); bool eof = false; do { @@ -466,7 +471,7 @@ Human68k::FputsFile(int32 fileno, uint32 len++; } if (len > 0) { - write(f->fd, buf, len); + write(f->fd, &buf[0], len); } } while (!eof); } @@ -501,7 +506,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;