Annotation of nono/vm/bt45x.h, revision 1.1.1.3

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: #include "monitor.h"
                     16: 
                     17: class Renderer;
                     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: 
                     36:        // ホストパレットのアドレスを取得
1.1.1.3 ! root       37:        const std::vector<Color>& GetHostPalette() const { return hostcolor; }
1.1       root       38: 
                     39:        // 生パレットを uint32 形式にしたものを返す (GUI 用)
                     40:        const std::vector<uint32> GetIntPalette() const;
                     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: 
                    119:        Renderer *renderer {};
                    120: 
                    121:        Monitor monitor { this };
                    122: 
                    123:        // ログ出力用
                    124:        static const char rgbstr[3];
                    125: };
                    126: 
1.1.1.3 ! root      127: // Bt454
        !           128: class BT454Device : public BT45xDevice
        !           129: {
        !           130:        using inherited = BT45xDevice;
        !           131: 
        !           132:        static const uint32 LOW_NIBBLE = 0x0f;
        !           133:  public:
        !           134:        BT454Device();
        !           135:        ~BT454Device() override;
        !           136: 
        !           137:  private:
        !           138:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
        !           139: 
        !           140:        uint32 ReadControl() override;
        !           141:        void WriteControl(uint32 data) override;
        !           142:        uint32 PeekControl() const override;
        !           143: 
        !           144:        uint32 PaletteToInt(uint) const override;
        !           145: };
        !           146: 
        !           147: // Bt458
        !           148: class BT458Device : public BT45xDevice
        !           149: {
        !           150:        using inherited = BT45xDevice;
        !           151:  public:
        !           152:        BT458Device();
        !           153:        ~BT458Device() override;
        !           154: 
        !           155:        bool Init() override;
        !           156: 
        !           157:  private:
        !           158:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
        !           159: 
        !           160:        uint32 ReadControl() override;
        !           161:        void WriteControl(uint32 data) override;
        !           162:        uint32 PeekControl() const override;
        !           163: 
        !           164:        uint32 PaletteToInt(uint) const override;
        !           165: 
        !           166:        void WriteRMask(uint32 data);
        !           167:        void WriteBMask(uint32 data);
        !           168:        void WriteCommand(uint32 data);
        !           169:        void WriteTest(uint32 data);
        !           170: 
        !           171:        uint8 blinkmask {};             // ブリンクマスク
        !           172:        uint8 command {};               // コマンド
        !           173:        uint8 testreg {};               // テストレジスタ
        !           174: };
        !           175: 
1.1       root      176: static inline BT45xDevice *GetBT45xDevice() {
                    177:        return Object::GetObject<BT45xDevice>(OBJ_BT45x);
                    178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.