--- nono/vm/pio.cpp 2026/04/29 17:04:32 1.1 +++ nono/vm/pio.cpp 2026/04/29 17:04:42 1.1.1.4 @@ -1,13 +1,15 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "pio.h" +#include "config.h" #include "lcd.h" +#include "mainapp.h" #include "mystring.h" #include "scheduler.h" -#include "config.h" // IODevice // | @@ -36,6 +38,17 @@ i8255Device::~i8255Device() { } +// リセット +void +i8255Device::ResetHard() +{ + // clears the control register + // and place ports A, B, and C in input mode. + // The input latches in ports A, B, and C are not cleared. + + ctrl = 0b10011011; +} + // コントロールポートへの書き込み。 void i8255Device::WriteCtrl(uint32 data) @@ -97,6 +110,8 @@ PPIDevice::~PPIDevice() uint64 PPIDevice::Read(uint32 addr) { + gMPU->AddCycle(19); // InsideOut p.135 + switch (addr) { case 0: case 1: @@ -116,6 +131,8 @@ PPIDevice::Read(uint32 addr) uint64 PPIDevice::Write(uint32 addr, uint32 data) { + gMPU->AddCycle(19); // InsideOut p.135 + switch (addr) { case 0: case 1: @@ -156,6 +173,7 @@ PPIDevice::Peek(uint32 addr) // 変数は dipsw{1,2}[0..7] に対応。 // 設定ファイルと変数の値は %0 が down を表し、%1 が up を表す。 // +// LUNA-1: // #1-1 up なら UNIX をロードして移行。down なら ROM モニタで起動。 // #1-2 up ならディスプレイコンソール。down ならシリアルコンソール。 // #1-3 up - color display, down - force to have monochrome display @@ -172,6 +190,13 @@ PPIDevice::Peek(uint32 addr) // あれば /boot がプロンプトで停止。これは ROM ではなく NetBSD のブート // ローダの話。 // どこか由来のソースコードらしいがたぶんビット演算を間違えている。 +// +// LUNA88K: +// #1-1 up なら ROM モニタで停止、down ならマルチユーザブート。 +// OpenBSD カーネルも up なら UserKernelConfig で止まる模様?。 +// #1-2 up なら外付けシリアルコンソール、down なら内蔵ビットマップ。 +// #1-3..#1-8 は予約。 +// #2-x はユーザ(?) // コンストラクタ PIO0Device::PIO0Device() @@ -181,6 +206,24 @@ PIO0Device::PIO0Device() devname = "PIO0"; devaddr = 0x49000000; devlen = 4; + + // 機種固有パラメータ + + // LUNA-1 と LUNA88K で使いやすいように初期値を変えておく。 + switch (gMainApp.GetVMType()) { + case VMTYPE_LUNA1: + gConfig->SetDefault("luna-dipsw1", "11110111"); + break; + case VMTYPE_LUNA88K: + gConfig->SetDefault("luna-dipsw1", "11111111"); + break; + default: + __unreachable(); + } + // DIP-SW#2 はユーザ定義(?)なので(今の所?)どちらも共通。 + gConfig->SetDefault("luna-dipsw2", "11111111"); + + monitor_size = nnSize(22, 11); } // デストラクタ @@ -193,14 +236,14 @@ PIO0Device::Init() { // XXX 本当はラッチのタイミングが違う気もするけど、とりあえずね - const ConfigItem& item1 = gConfig->Get("luna-dipsw1"); + const ConfigItem& item1 = gConfig->Find("luna-dipsw1"); const std::string& str1 = item1.AsString(); if (str1.size() != 8) { item1.Err("must be 8 digits"); return false; } - const ConfigItem& item2 = gConfig->Get("luna-dipsw2"); + const ConfigItem& item2 = gConfig->Find("luna-dipsw2"); const std::string& str2 = item2.AsString(); if (str2.size() != 8) { item2.Err("must be 8 digits"); @@ -290,6 +333,43 @@ PIO0Device::Peek(uint32 addr) } } +void +PIO0Device::MonitorUpdate(TextScreen& monitor) +{ + int y; + + monitor.Clear(); + + y = 0; + monitor.Print(0, y++, "PortA(DIPSW1):%c%c%c%c%c%c%c%c", + (dipsw1[0] ? '1' : '0'), + (dipsw1[1] ? '1' : '0'), + (dipsw1[2] ? '1' : '0'), + (dipsw1[3] ? '1' : '0'), + (dipsw1[4] ? '1' : '0'), + (dipsw1[5] ? '1' : '0'), + (dipsw1[6] ? '1' : '0'), + (dipsw1[7] ? '1' : '0')); + monitor.Print(0, y++, "PortB(DIPSW2):%c%c%c%c%c%c%c%c", + (dipsw2[0] ? '1' : '0'), + (dipsw2[1] ? '1' : '0'), + (dipsw2[2] ? '1' : '0'), + (dipsw2[3] ? '1' : '0'), + (dipsw2[4] ? '1' : '0'), + (dipsw2[5] ? '1' : '0'), + (dipsw2[6] ? '1' : '0'), + (dipsw2[7] ? '1' : '0')); + monitor.Puts(0, y++, "PortC"); + monitor.Puts(1, y++, TA::OnOff(xp_reset), "b7: XP Reset"); + monitor.Puts(1, y++, TA::OnOff(parity), "b6: Parity"); + monitor.Puts(1, y++, "b5: ---"); + monitor.Puts(1, y++, TA::OnOff(int5en), "b4: Int5 Enable"); + monitor.Puts(1, y++, TA::OnOff(int5rq), "b3: Int5 Request"); + monitor.Puts(1, y++, TA::OnOff(int1en), "b2: Int1 Enable"); + monitor.Puts(1, y++, "b1: ---"); + monitor.Puts(1, y++, TA::OnOff(int1rq), "b0: Intq Request"); +} + // PortA (DIP-SW 1) 読み込み uint32 PIO0Device::GetPA() const @@ -405,6 +485,15 @@ PIO1Device::~PIO1Device() { } +// リセット +void +PIO1Device::ResetHard() +{ + inherited::ResetHard(); + + poffevent.Stop(); +} + uint64 PIO1Device::Read(uint32 addr) { @@ -537,7 +626,7 @@ PIO1Device::SetPC(int pc, int val) // 電源 OFF イベントのコールバック void -PIO1Device::PowerOffCallback(int arg) +PIO1Device::PowerOffCallback(Event& ev) { putlog(0, "電源 OFF"); gScheduler->RequestPowerOff();