--- nono/vm/crtc.h 2026/04/29 17:04:28 1.1 +++ nono/vm/crtc.h 2026/04/29 17:05:17 1.1.1.9 @@ -1,15 +1,89 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// CRTC // #pragma once #include "device.h" -#include "scheduler.h" +#include "event.h" +#include "monitor.h" + +class MFPDevice; +class Renderer; +class TVRAMDevice; 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 | - |MEM|SIZ| COL | - |HF | VD | HD | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R21 | - |MEN|SA | AP | CP | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R22 | ソースラスタ | デスティネーションラスタ | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R23 | マスクパターン | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + // R24 | - |RC | 0 |FC |VI | + // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + uint16 r[24]; uint16 op; @@ -38,32 +112,68 @@ struct CRTC static const uint32 R22 = 0x16; // $E8002C static const uint32 R23 = 0x17; // $E8002E static const uint32 REG_END = 0x18; - static const uint32 REG_OP = 0x240; // $E80480 + static const uint32 REG_OP = 0x240; // $E80480 + + // R20 + static const uint16 R20_MEM = 0x0800; + static const uint16 R20_SIZ = 0x0400; + static const uint16 R20_COL = 0x0300; + static const uint16 R20_HF = 0x0010; + static const uint16 R20_VD = 0x000c; + static const uint16 R20_HD = 0x0003; + + // 動作ポート + 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 { - typedef IODevice inherited; + using inherited = IODevice; public: CRTCDevice(); - virtual ~CRTCDevice(); + virtual ~CRTCDevice() override; - virtual void ResetHard(); + bool Init() override; + void ResetHard(bool poweron) override; - virtual uint64 Read8(uint32 addr); - virtual uint64 Read16(uint32 addr); - virtual uint64 Write8(uint32 addr, uint32 data); - virtual uint64 Write16(uint32 addr, uint32 data); - virtual uint64 Peek8(uint32 addr); + protected: + // BusIO インタフェース + static const uint NPORT = 0x800; + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + uint64 Peek(uint32 offset); private: - void WriteReg(uint32 offset, uint32 data); + // レジスタへの書き込み + void SetReg(uint32 offset, uint32 data); + // 動作ポートへの書き込み + void WriteOp(uint32 data); + + // 水平同期信号イベント + void HSyncCallback(Event& ev); + + // ラスターコピー完了イベント + void RasterCallback(Event& ev); // 垂直表示期間イベント - void VDispCallback(int arg); + void VDispCallback(Event& ev); + + DECLARE_MONITOR_CALLBACK(MonitorUpdate); struct CRTC crtc {}; - Event vdisp_event {}; + // ラスターコピー指示 + bool raster_copy {}; + + MFPDevice *mfp {}; + Renderer *renderer {}; + TVRAMDevice *tvram {}; + + Event hsync_event { this }; + Event vdisp_event { this }; + Event raster_event { this }; + + Monitor monitor { this }; };