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