|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.7 root 7: //
8: // ビデオコントローラ
9: //
10:
1.1 root 11: #pragma once
12:
13: #include "device.h"
1.1.1.9 root 14: #include "bitmap.h"
1.1.1.8 root 15: #include <array>
1.1.1.11 root 16: #include <atomic>
1.1.1.8 root 17:
1.1.1.12 root 18: class GVRAMDevice;
1.1.1.10 root 19: class PlaneVRAMDevice;
1.1.1.13 root 20: class VideoRenderer;
1.1.1.12 root 21: class UIMessage;
1.1 root 22:
1.1.1.12 root 23: class VideoCtlr
24: {
25: public:
26: // f e d c b a 9 8 7 6 5 4 3 2 1 0
27: // +--------------------------------------+--+-----+
28: // R0 | |SZ| COL |
29: // +--------------------------------------+--+-----+
30: static constexpr uint32 R0_SIZ = 0x0004;
31: static constexpr uint32 R0_COL = 0x0003;
32:
33: // f e d c b a 9 8 7 6 5 4 3 2 1 0
34: // +-----+-----+-----+-----+-----+-----+-----+-----+
35: // R1 | %00 | SP | TX | GR | GP3 | GP2 | GP1 | GP0 |
36: // +-----+-----+-----+-----+-----+-----+-----+-----+
37: static constexpr uint32 R1_SP = 0x3000; // スプライト優先度
38: static constexpr uint32 R1_TX = 0x0c00; // テキスト画面優先度
39: static constexpr uint32 R1_GR = 0x0300; // グラフィック画面優先度
40: static constexpr uint32 R1_G3 = 0x00c0; // GP3 優先度
41: static constexpr uint32 R1_G2 = 0x0030; // GP2 優先度
42: static constexpr uint32 R1_G1 = 0x000c; // GP1 優先度
43: static constexpr uint32 R1_G0 = 0x0003; // GP0 優先度
44:
45: // f e d c b a 9 8 7 6 5 4 3 2 1 0
46: // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
47: // R2 |YS|AH|VH|EX|HP|BP|GG|GT| |SO|TO|GO|G3|G2|G1|G0|
48: // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
49: static constexpr uint32 R2_YS = 0x8000;
50: static constexpr uint32 R2_AH = 0x4000;
51: static constexpr uint32 R2_VH = 0x2000;
52: static constexpr uint32 R2_EX = 0x1000;
53: static constexpr uint32 R2_HP = 0x0800;
54: static constexpr uint32 R2_BP = 0x0400;
55: static constexpr uint32 R2_GG = 0x0200;
56: static constexpr uint32 R2_GT = 0x0100;
57: static constexpr uint32 R2_SP_ON = 0x0040; // スプライトオン
58: static constexpr uint32 R2_TX_ON = 0x0020; // テキスト画面オン
59: static constexpr uint32 R2_GR_ON = 0x0010; // グラフィック画面オン
60: static constexpr uint32 R2_G3_ON = 0x0008; // グラフィック(P3)オン
61: static constexpr uint32 R2_G2_ON = 0x0004; // グラフィック(P2)オン
62: static constexpr uint32 R2_G1_ON = 0x0002; // グラフィック(P1)オン
63: static constexpr uint32 R2_G0_ON = 0x0001; // グラフィック(P0)オン
64: };
65:
66: class VideoCtlrDevice : public IODevice, public VideoCtlr
1.1 root 67: {
68: using inherited = IODevice;
1.1.1.7 root 69:
1.1.1.8 root 70: static const uint32 baseaddr = 0xe82000;
1.1 root 71:
1.1.1.12 root 72: // 描画順のための描画フラグ
73: static constexpr uint32 SORDER_NONE = 0x0;
74: static constexpr uint32 SORDER_SP = 0x1;
75: static constexpr uint32 SORDER_TX = 0x2;
76: static constexpr uint32 SORDER_GR = 0x3;
77: static constexpr uint32 SORDER_BG = 0x4;
78: static constexpr uint32 SORDER_BLACK = 0x5; // 仮想的な背景
79:
1.1 root 80: public:
81: VideoCtlrDevice();
1.1.1.9 root 82: ~VideoCtlrDevice() override;
1.1 root 83:
1.1.1.8 root 84: bool Init() override;
1.1.1.7 root 85: void ResetHard(bool poweron) override;
1.1.1.3 root 86:
1.1.1.10 root 87: busdata Read(busaddr addr) override;
88: busdata Write(busaddr addr, uint32 data) override;
89: busdata Peek1(uint32 addr) override;
90: bool Poke1(uint32 addr, uint32 data) override;
1.1.1.9 root 91:
92: // コントラストを取得 (Peek() からも呼ぶので副作用を起こしてはいけない)
1.1.1.10 root 93: uint GetContrast() const { return target_contrast / 0x11; }
1.1.1.9 root 94: // コントラストを設定
1.1.1.10 root 95: void SetContrast(uint);
1.1.1.9 root 96:
1.1.1.11 root 97: // 画面作成。
98: void VDisp();
99:
1.1.1.9 root 100: // 画面合成
1.1.1.11 root 101: bool Render(BitmapRGBX& dst);
1.1.1.9 root 102:
1.1.1.12 root 103: // モニタ更新(下請け)
1.1.1.14! root 104: int MonitorScreen(TextScreen&, int y, uint32 crtc_r20);
1.1.1.12 root 105:
106: // グラフィック画面を取得。(モニタ用)
107: const BitmapRGBX& GetGraphicBitmap() const { return grbmp; }
108:
109: // ホストパレットを取得。(レンダラとかからの参照用)
1.1.1.10 root 110: const std::vector<Color>& GetHostPalette() const { return hostcolor; }
1.1.1.8 root 111:
1.1.1.12 root 112: // ホストパレットのアドレスを取得。
113: const Color *GetHostPalettePtr(int idx) const { return &hostcolor[idx]; }
114:
115: // ゲストパレットを取得。(GUI 情報表示用)
116: const std::vector<uint16>& GetGuestPalette() const { return palette; }
117:
118: // モニタ用。CRTC からも使う。
119: static const char * const siz_str[2];
120: static const char * const col_str[4];
1.1 root 121:
122: private:
1.1.1.10 root 123: static inline uint32 Decoder(uint32 addr);
124: static inline uint Offset2Rn(uint32 offset);
125:
126: uint32 Get16(uint32 offset) const;
127: void Set8(uint32 offset, uint32 data);
128: void Set16(uint32 offset, uint32 data);
1.1.1.8 root 129:
1.1.1.2 root 130: void MakePalette();
1.1.1.9 root 131: void RenderContrast(BitmapRGBX& dst, const BitmapRGBX& src);
132: static void RenderContrast_gen(BitmapRGBX&, const BitmapRGBX&, uint32);
133: #if defined(HAVE_AVX2)
134: static void RenderContrast_avx2(BitmapRGBX&, const BitmapRGBX&, uint32);
135: bool enable_avx2 {};
136: #endif
1.1.1.10 root 137: #if defined(HAVE_NEON)
138: static void RenderContrast_neon(BitmapRGBX&, const BitmapRGBX&, uint32);
139: bool enable_neon {};
140: #endif
1.1.1.9 root 141:
1.1.1.12 root 142: void ContrastCallback(Event *);
1.1 root 143:
1.1.1.10 root 144: // ワードレジスタ R0, R1, R2
145: std::array<uint16, 3> reg {};
1.1.1.12 root 146: uint16 prev_reg1 {};
147: uint16 prev_reg2 {};
1.1.1.8 root 148:
1.1.1.12 root 149: // 各画面
150: BitmapRGBX txbmp {};
151: BitmapRGBX grbmp {};
152:
153: // 合成画面 (コントラスト適用前)
154: BitmapRGBX mixbmp {};
1.1.1.9 root 155:
1.1.1.10 root 156: // パレット (ホストバイトオーダー)
1.1.1.12 root 157: std::vector<uint16> palette {};
1.1.1.2 root 158:
1.1.1.7 root 159: // ホスト形式のテキストパレット (レンダラ用に加工したもの)
1.1.1.10 root 160: std::vector<Color> hostcolor {};
1.1.1.8 root 161:
1.1.1.12 root 162: // 描画順 (SORDER_* を LSB 側から4ビットずつ並べる)
163: uint32 screen_order {};
164:
1.1.1.9 root 165: // 設定したコントラスト値 (0-255)
166: uint32 target_contrast {};
167: // 現在の (遷移中かもしれない) コントラスト値 (0-255)
168: uint32 running_contrast {};
169: // 設定を変える時の初期値 (0-255)
170: uint32 initial_contrast {};
171: // 設定を変える時の起点
172: uint64 contrast_time0 {};
173:
1.1.1.11 root 174: // VM スレッドからレンダラスレッドへの連絡用。(0-255)
175: std::atomic<uint32> pending_contrast {};
176:
1.1.1.9 root 177: // レンダリングに使っているコントラスト値 (0-255)
178: uint32 rendering_contrast {};
179:
1.1.1.12 root 180: Event *contrast_event {};
1.1.1.9 root 181:
1.1.1.12 root 182: GVRAMDevice *gvram {};
1.1.1.9 root 183: PlaneVRAMDevice *planevram {};
1.1.1.12 root 184: UIMessage *uimessage {};
1.1.1.13 root 185: VideoRenderer *renderer {};
1.1 root 186: };
187:
1.1.1.14! root 188: inline VideoCtlrDevice *GetVideoCtlrDevice() {
1.1.1.8 root 189: return Object::GetObject<VideoCtlrDevice>(OBJ_VIDEOCTLR);
190: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.