--- nono/cli/cli_app.cpp 2026/04/29 17:04:28 1.1 +++ nono/cli/cli_app.cpp 2026/04/29 17:04:33 1.1.1.3 @@ -1,54 +1,39 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "header.h" #include "mainapp.h" -#include "mpu.h" +#include "mpu680x0.h" #include "pluto.h" #include "rtc.h" #include "vm.h" +void cli_halt_callback(void *); + // wxApp と相似にするためのクラス class CLIApp { public: bool OnInit(); bool Parse(); - void OnCreate(); + [[noreturn]] void OnCreate(); int ac; char **av; }; -// コマンドラインオプションとか -const char *human68k_file = NULL; -char human68k_arg[256]; - -void -usage() -{ - printf("%s []\n", getprogname()); - printf(" -b break point\n"); - printf(" -B benchmark mode\n"); - printf(" -c vm directory\n"); - printf(" -d debugger prompt on startup\n"); - printf(" -f fast mode\n"); - printf(" -L = loglevel (-L help displays names)\n"); - printf(" -X human68k console emulation\n"); - printf(" -v version\n"); -} - int main(int ac, char *av[]) { - CLIApp *app = new CLIApp(); + std::unique_ptr app(new CLIApp()); // wxApp とよく似せるため app->ac = ac; app->av = av; - if (app->OnInit()) { + if (!app->OnInit()) { return 1; } return 0; @@ -58,15 +43,10 @@ main(int ac, char *av[]) bool CLIApp::OnInit() { - debug_breakaddr = 0xffffffff; - vmdir = "."; - - if (!Parse()) { + if (!gMainApp.Init(true, ac, av)) { return false; } - - // CLI 版では常にコンソールに(も)ログを出力 - if (!main_init(true)) { + if (!gMainApp.Start()) { return false; } @@ -76,77 +56,15 @@ CLIApp::OnInit() return true; } -// 引数をパースする。 -// 知らない引数とかがあればこちらで usage を表示して false を返す。 -bool -CLIApp::Parse() -{ - int b; - int c; - - while ((c = getopt(ac, av, "b:B:c:dfL:X:v")) != -1) { - switch (c) { - case 'b': - debug_breakaddr = (uint32)strtoul(optarg, NULL, 16); - break; - - case 'B': - b = atoi(optarg); - if (b < 2 || b > 6) { - fprintf(stderr, "-B : 2..6\n"); - return false; - } - PlutoDevice::benchmark_mode = b; - break; - - case 'c': - vmdir = std::string(optarg); - break; - - case 'd': - debug_on_start = true; - break; - - case 'f': - fast_mode = true; - break; - - case 'L': - if (logopt[0] != '\0') { - strlcat(logopt, ",", sizeof(logopt)); - } - strlcat(logopt, optarg, sizeof(logopt)); - break; - - case 'X': - human68k_file = optarg; - for (int i = optind; i < ac; i++) { - if (i != optind) { - strlcat(human68k_arg, " ", sizeof(human68k_arg)); - } - strlcat(human68k_arg, av[i], sizeof(human68k_arg)); - } - optind = ac; - break; - - case 'v': - fprintf(stderr, "nono-cli version %d.%d.%d\n", - NONO_MAJOR_VER, NONO_MINOR_VER, NONO_PATCH_VER); - exit(0); - - default: - usage(); - return false; - } - } - - return true; -} - // メインウィンドウ作成後のイベントに相当するところ void CLIApp::OnCreate() { + // VM にコールバックを登録 + if (gMPU680x0) { + gMPU680x0->SetHaltCallback(cli_halt_callback, NULL); + } + // 時刻開始? // なるべく VM が開始する直前にしたい。 gRTC->InitRTC(); @@ -159,3 +77,11 @@ CLIApp::OnCreate() sleep(1); } } + +// m680x0 ダブルバスフォールト時に呼ばれるコールバック。 +void +cli_halt_callback(void *dummy) +{ + // どうする? + warnx("Double bus fault has occurred in VM"); +}