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