--- nono/vm/crtc.cpp 2026/04/29 17:04:55 1.1.1.7 +++ nono/vm/crtc.cpp 2026/04/29 17:05:09 1.1.1.8 @@ -4,10 +4,9 @@ // Licensed under nono-license.txt // -#include "crtc.h" -#include "mfp.h" -#include "renderer.h" -#include "tvram.h" +// +// CRTC +// // e80000..e803ff 内は $40 バイトでミラー。 // e80400..e807ff 内は 256 バイトでミラーになっており、このうち @@ -16,33 +15,54 @@ // 仕様は $e80480.w に1ポートあるので、これがワードで全域にミラーされている? // 全体としては この $800 バイトずつが繰り返して見える。 -std::unique_ptr gCRTC; +#include "crtc.h" +#include "mfp.h" +#include "mpu.h" +#include "renderer.h" +#include "scheduler.h" +#include "tvram.h" + +// グローバル参照用 +CRTCDevice *gCRTC; +// コンストラクタ CRTCDevice::CRTCDevice() : inherited("CRTC") { devaddr = 0xe80000; devlen = 0x2000; - vdisp_event.func = (DeviceCallback_t)&CRTCDevice::VDispCallback; - vdisp_event.SetName("CRTC V-DISP"); + hsync_event.func = ToEventCallback(&CRTCDevice::HSyncCallback); + hsync_event.Regist("CRTC H-Sync"); + vdisp_event.func = ToEventCallback(&CRTCDevice::VDispCallback); + vdisp_event.Regist("CRTC V-DISP"); + + monitor.func = ToMonitorCallback(&CRTCDevice::MonitorUpdate); + monitor.SetSize(60, 5); + monitor.Regist(ID_MONITOR_CRTC); } +// デストラクタ CRTCDevice::~CRTCDevice() { + gCRTC = NULL; } +// リセット void -CRTCDevice::ResetHard() +CRTCDevice::ResetHard(bool poweron) { // XXX 初期値適当 crtc.r[20] = 0x0016; // XXX 適当 - // すぐに垂直帰線期間を開始する + // すぐに水平同期と垂直帰線期間を開始する + hsync_event.time = 0; + hsync_event.code = 1; + gScheduler->RestartEvent(hsync_event); vdisp_event.time = 0; vdisp_event.code = 1; - vdisp_event.Start(); + gScheduler->RestartEvent(vdisp_event); } uint64 @@ -107,8 +127,7 @@ CRTCDevice::Write(uint32 offset, uint32 if ((offset & (0x80 / 2)) == 0) { // +$00..+$7f return (uint64)-1; } else { - crtc.op = data & 0x0b; - putlog(2, "$E80480.W <- $%04x", crtc.op); + WriteOp(data); } } @@ -141,6 +160,40 @@ CRTCDevice::Peek(uint32 offset) return data; } +void +CRTCDevice::MonitorUpdate(Monitor *, TextScreen& screen) +{ + int y; + uint16 val; + + screen.Clear(); + + y = 0; + screen.Print(0, y++, "R10:$%04x (Text ScrollX)", crtc.r[10]); + screen.Print(0, y++, "R11:$%04x (Text ScrollY)", crtc.r[11]); + + val = crtc.r[21]; + screen.Print(0, y, "R21:$%04x (Text Plane)", val); + screen.Print(29, y, "MEN=%c SA=%c AP=%%%c%c%c%c CP=%%%c%c%c%c", + (val & 0x0200) ? '1' : '0', + (val & 0x0100) ? '1' : '0', + (val & 0x0080) ? '1' : '0', + (val & 0x0040) ? '1' : '0', + (val & 0x0020) ? '1' : '0', + (val & 0x0010) ? '1' : '0', + (val & 0x0008) ? '1' : '0', + (val & 0x0004) ? '1' : '0', + (val & 0x0002) ? '1' : '0', + (val & 0x0001) ? '1' : '0'); + y++; + + val = crtc.r[22]; + screen.Print(0, y++, "R22:$%04x (Text Raster Copy) src=$%02x dst=$%02x", + val, (val >> 8), (val & 0xff)); + + screen.Print(0, y++, "R23:$%04x (Text Access Mask)", crtc.r[23]); +} + // CRTC レジスタへの書き込み。 // reg は CRTC::R00 .. CRTC::R23 void @@ -160,7 +213,15 @@ CRTCDevice::SetReg(uint32 reg, uint32 da case CRTC::R21: // 頻度が高いのでログレベルを上げておく putlog(3, "R%02d <- $%04x", reg, data); - gTVRAM->set_crtc_21(crtc.r[21]); + gTVRAM->SetAccessPlane(crtc.r[21]); + break; + case CRTC::R22: + putlog(3, "R%02d <- $%04x", reg, data); + break; + case CRTC::R23: + // 頻度が高いのでログレベルを上げておく + putlog(3, "R%02d <- $%04x", reg, data); + gTVRAM->SetAccessMask(crtc.r[23]); break; default: putlog(2, "R%02d <- $%04x (未実装)", reg, data); @@ -168,12 +229,76 @@ CRTCDevice::SetReg(uint32 reg, uint32 da } } +// 動作ポートへの書き込み。 +void +CRTCDevice::WriteOp(uint32 data) +{ + uint16 oldop = crtc.op; + + crtc.op = data & 0x0b; + putlog(2, "$E80480.W <- $%04x", crtc.op); + + uint16 change = oldop ^ crtc.op; + + if ((change & CRTC::OP_RC)) { + // テキスト画面ラスターコピー + if ((crtc.op & CRTC::OP_RC)) { + // 0->1 開始 + StartRasterCopy(); + + // XXX 本当は終わったら 0 にするはず + crtc.op &= ~CRTC::OP_RC; + } else { + // 1->0 停止 + // XXX 今の所一瞬で終わるので… + //StopRasterCopy(); + } + } + + if ((change & 0x03)) { + putlog(0, "動作ポート $%02x->$%02x 未実装", + oldop & 0x03, crtc.op & 0x03); + } +} + +// テキスト画面のラスターコピー開始 +void +CRTCDevice::StartRasterCopy() +{ + int src = (crtc.r[22] >> 8) * 4; + int dst = (crtc.r[22] & 0xff) * 4; + + gTVRAM->RasterCopy(src, dst); +} + +// 水平同期イベント +void +CRTCDevice::HSyncCallback(Event& ev) +{ + int hsync = ev.code; + + // GPIP の状態を更新 + gMFP->SetHSync(hsync); + + // 次のタイミングを計算 + if (hsync) { + // 水平同期期間 + ev.time = 3.45_usec; + ev.code = 0; + } else { + // + ev.time = 22.09_usec + 4.14_usec + 2.07_usec; + ev.code = 1; + } + gScheduler->StartEvent(ev); +} + // 垂直表示・帰線イベント // ev.code が 1 なら表示期間開始(V-disp)、0 なら帰線期間開始(V-blank)。 void CRTCDevice::VDispCallback(Event& ev) { - int& vdisp = ev.code; + int vdisp = ev.code; // GPIP の状態を更新 gMFP->SetVDisp(vdisp); @@ -192,8 +317,8 @@ CRTCDevice::VDispCallback(Event& ev) ev.code = 0; } else { // 垂直帰線期間 - ev.time = 1778_usec; + ev.time = 191_usec + 1111_usec + 476_usec; ev.code = 1; } - ev.Start(); + gScheduler->StartEvent(ev); }