|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // Bt454/458
9: //
10:
11: #pragma once
12:
13: #include "device.h"
14: #include "color.h"
15:
1.1.1.4 root 16: class LunafbDevice;
1.1.1.5 root 17: class UIMessage;
1.1 root 18:
19: class BT45xDevice : public IODevice
20: {
21: using inherited = IODevice;
22:
23: public:
24: BT45xDevice();
1.1.1.2 root 25: ~BT45xDevice() override;
1.1 root 26:
27: bool Init() override;
28: void ResetHard(bool poweron) override;
29:
1.1.1.3 root 30: // 設定からプレーン数を取得
31: static int GetConfigPlaneCount();
1.1 root 32:
33: // プレーン数を取得
1.1.1.3 root 34: uint GetPlaneCount() const { return nplane; }
1.1 root 35:
1.1.1.5 root 36: // ホストパレットを取得。(レンダラとかからの参照用)
1.1.1.3 root 37: const std::vector<Color>& GetHostPalette() const { return hostcolor; }
1.1 root 38:
1.1.1.5 root 39: // ゲストパレットを取得。(GUI 情報表示用)
40: const std::vector<uint8>& GetGuestPalette() const { return color; }
1.1 root 41:
1.1.1.3 root 42: // BusIO インタフェース
1.1 root 43: // (内蔵 ROM からのアクセス用に特別に public にしてある)
1.1.1.3 root 44: busdata WritePort(uint32 offset, uint32 data);
45: protected:
46: static const uint32 NPORT = 4;
47: busdata ReadPort(uint32 offset);
48: busdata PeekPort(uint32 offset);
49: bool PokePort(uint32 offset, uint32 data);
1.1 root 50:
51: // レジスタ値からホストパレットを作成
1.1.1.3 root 52: void MakeHostColor(uint idx);
53:
54: // パレット n の色を uint32 表現したものを返す (GUI 用)
55: virtual uint32 PaletteToInt(uint n) const = 0;
1.1 root 56:
57: // 通知
58: void Notify();
59:
1.1.1.3 root 60: uint32 PeekAddress() const;
61: uint32 PeekPalette() const;
1.1 root 62: void WriteAddress(uint32 data);
63: void WritePalette(uint32 data);
1.1.1.3 root 64: virtual uint32 ReadControl() = 0;
65: virtual void WriteControl(uint32 data) = 0;
66: virtual uint32 PeekControl() const = 0;
1.1 root 67:
68: // モデル種別。Bt454 なら true。
69: bool bt454 {};
70:
71: // ビットマップのプレーン数 (1, 4, 8)
1.1.1.3 root 72: uint nplane {};
1.1 root 73:
74: // パレット数 (16 or 256)
1.1.1.3 root 75: uint palettes {};
1.1 root 76:
77: // データの下位ニブルマスク。Bt454 なら LOW_NIBBLE。
78: uint8 low_nibble {};
79:
1.1.1.3 root 80: // Bt458 のパレットアドレスマスク。(Bt454 なら使用しない)
81: uint8 readmask {};
1.1 root 82:
83: // idx は次にアクセスされるべき color[] へのインデックス。
84: // idx = 0 ならパレット0 の R。
85: // idx = 4 ならパレット1 の G。
86: // Bt454 では R/G/B をカウントするための 3値 2ビットのカウンタ(?)を
87: // ADDRa,ADDRb (ADDRa,b) と呼んだりしているようなので、ここではその
88: // modulo 3 を数えるカウンタを ab と呼ぶことにする。つまり
89: // idx = 0 はパレット 0、ab 0。
90: // idx = 4 はパレット 1、ab 1。
1.1.1.3 root 91: uint idx {};
1.1 root 92:
93: // パレットは R, G, B の順に格納されている。
94: // color[0] = パレット0 R
95: // color[1] = パレット0 G
96: // color[2] = パレット0 B
97: // color[3] = パレット1 R
98: // :
99: // color[47] = パレット15 B
100: //
101: // Bt454 なら 16パレット * 3 = 48エントリ。
102: // 色深度は 4ビットで上位4ビットと下位4ビットに同じものを格納する。
103: // つまり $4 なら $44、$f なら $ff として格納しておく。
104: //
105: // Bt458 なら 256パレット * 3 = 768エントリ。
106: // 色深度は 8ビットでそのまま格納。
1.1.1.3 root 107: std::vector<uint8> color {};
1.1 root 108:
109: // ホスト用に変換したパレットデータ。
110: // ホスト用なので各8ビット、といいつつ元情報 (color[]) が8ビットすべて
111: // 有効なので値はそのまま流用する。
112: //
113: // また 1bpp モードなら R,G,B のうち G だけが使われるので、ここで
114: // 展開する。パレットのうち実際には #14 と #15 だけが使われるが、
115: // それについてはレンダラ側で処理している。
116: // see https://twitter.com/tsutsuii/status/356704682514714625
1.1.1.3 root 117: std::vector<Color> hostcolor {};
1.1 root 118:
1.1.1.4 root 119: Monitor *monitor {};
1.1 root 120:
121: // ログ出力用
122: static const char rgbstr[3];
1.1.1.4 root 123:
124: LunafbDevice *lunafb {};
1.1.1.5 root 125: UIMessage *uimessage {};
1.1 root 126: };
127:
1.1.1.3 root 128: // Bt454
129: class BT454Device : public BT45xDevice
130: {
131: using inherited = BT45xDevice;
132:
133: static const uint32 LOW_NIBBLE = 0x0f;
134: public:
135: BT454Device();
136: ~BT454Device() override;
137:
138: private:
1.1.1.6 ! root 139: DECLARE_MONITOR_SCREEN(MonitorScreen);
1.1.1.3 root 140:
141: uint32 ReadControl() override;
142: void WriteControl(uint32 data) override;
143: uint32 PeekControl() const override;
144:
145: uint32 PaletteToInt(uint) const override;
146: };
147:
148: // Bt458
149: class BT458Device : public BT45xDevice
150: {
151: using inherited = BT45xDevice;
152: public:
153: BT458Device();
154: ~BT458Device() override;
155:
156: bool Init() override;
157:
158: private:
1.1.1.6 ! root 159: DECLARE_MONITOR_SCREEN(MonitorScreen);
1.1.1.3 root 160:
161: uint32 ReadControl() override;
162: void WriteControl(uint32 data) override;
163: uint32 PeekControl() const override;
164:
165: uint32 PaletteToInt(uint) const override;
166:
167: void WriteRMask(uint32 data);
168: void WriteBMask(uint32 data);
169: void WriteCommand(uint32 data);
170: void WriteTest(uint32 data);
171:
172: uint8 blinkmask {}; // ブリンクマスク
173: uint8 command {}; // コマンド
174: uint8 testreg {}; // テストレジスタ
175: };
176:
1.1.1.6 ! root 177: inline BT45xDevice *GetBT45xDevice() {
1.1 root 178: return Object::GetObject<BT45xDevice>(OBJ_BT45x);
179: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.