--- nono/vm/crtc.h 2026/04/29 17:04:50 1.1.1.5 +++ nono/vm/crtc.h 2026/04/29 17:05:10 1.1.1.7 @@ -4,13 +4,81 @@ // Licensed under nono-license.txt // +// +// CRTC +// + #pragma once -#include "device.h" -#include "scheduler.h" +#include "event.h" +#include "monitor.h" struct CRTC { + // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R00 | - | 水平トータル | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R01 | - | 水平同期終了位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R02 | - | 水平表示開始位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R03 | - | 水平表示終了位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R04 | - | 垂直トータル | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R05 | - | 垂直同期終了位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R06 | - | 垂直表示開始位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R07 | - | 垂直表示終了位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // + // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R08 | - | 外部同期水平アジャスト | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R09 | - | ラスタ番号 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R10 | - | テキスト画面スクロール X位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R11 | - | テキスト画面スクロール Y位置 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // + // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R12 | - | グラフィック画面スクロール X0 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R13 | - | グラフィック画面スクロール Y0 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R14 | - | グラフィック画面スクロール X1 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R15 | - | グラフィック画面スクロール Y1 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R16 | - | グラフィック画面スクロール X2 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R17 | - | グラフィック画面スクロール Y2 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R18 | - | グラフィック画面スクロール X3 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R19 | - | グラフィック画面スクロール Y3 | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // + // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R20 | - |SIZ| COL | - |HF | VD | HD | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R21 | - |MEN|SA | AP | CP | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R22 | ソースラスタ | デスティネーションラスタ | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R23 | マスクパターン | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R24 | - |RC | 0 |FC |VI | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + uint16 r[24]; uint16 op; @@ -40,17 +108,21 @@ struct CRTC static const uint32 R23 = 0x17; // $E8002E static const uint32 REG_END = 0x18; static const uint32 REG_OP = 0x240; // $E80480 + + // 動作ポート + static const uint32 OP_RC = 0x08; // ラスターコピー開始(%1) + static const uint32 OP_FC = 0x02; // 高速クリア開始(%1) + static const uint32 OP_VI = 0x01; // 画像取り込み開始(%1) }; -class CRTCDevice - : public IODevice +class CRTCDevice : public IODevice { using inherited = IODevice; public: CRTCDevice(); virtual ~CRTCDevice() override; - void ResetHard() override; + void ResetHard(bool poweron) override; protected: // BusIO インタフェース @@ -60,14 +132,28 @@ class CRTCDevice uint64 Peek(uint32 offset); private: + // レジスタへの書き込み void SetReg(uint32 offset, uint32 data); + // 動作ポートへの書き込み + void WriteOp(uint32 data); + + // テキスト画面のラスターコピー + void StartRasterCopy(); + + // 水平同期信号イベント + void HSyncCallback(Event& ev); // 垂直表示期間イベント void VDispCallback(Event& ev); + DECLARE_MONITOR_CALLBACK(MonitorUpdate); + struct CRTC crtc {}; - Event vdisp_event {}; + Event hsync_event { this }; + Event vdisp_event { this }; + + Monitor monitor { this }; }; -extern std::unique_ptr gCRTC; +extern CRTCDevice *gCRTC;