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

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();
        !            25:        virtual ~BT45xDevice() override;
        !            26: 
        !            27:        bool Init() override;
        !            28:        void ResetHard(bool poweron) override;
        !            29: 
        !            30:        uint64 Read8(uint32 addr) override;
        !            31:        uint64 Write8(uint32 addr, uint32 data) override;
        !            32:        uint64 Peek8(uint32 addr) override;
        !            33: 
        !            34:        // プレーン数を取得
        !            35:        int GetPlaneCount() const { return nplane; }
        !            36: 
        !            37:        // ホストパレットのアドレスを取得
        !            38:        const std::vector<ColorXBGR>& GetHostPalette() const { return hostcolor; }
        !            39: 
        !            40:        // 生パレットを uint32 形式にしたものを返す (GUI 用)
        !            41:        const std::vector<uint32> GetIntPalette() const;
        !            42: 
        !            43:        // 内部アクセス
        !            44:        // (内蔵 ROM からのアクセス用に特別に public にしてある)
        !            45:        uint64 Write(uint32 offset, uint32 data);
        !            46: 
        !            47:  private:
        !            48:        // BusIO に似てるが、BusIO ではない。
        !            49:        uint64 Read(uint32 offset);
        !            50:        uint64 Peek(uint32 offset);
        !            51: 
        !            52:        // レジスタ値からホストパレットを作成
        !            53:        void MakeHostColor(int idx);
        !            54: 
        !            55:        // 通知
        !            56:        void Notify();
        !            57: 
        !            58:        uint32 ReadAddress();
        !            59:        uint32 ReadPalette();
        !            60:        uint32 ReadControl();
        !            61:        void WriteAddress(uint32 data);
        !            62:        void WritePalette(uint32 data);
        !            63:        void WriteControl(uint32 data);
        !            64:        uint32 PeekControl() const;
        !            65: 
        !            66:        // Bt458 拡張
        !            67:        void WriteRMask(uint32 data);
        !            68:        void WriteBMask(uint32 data);
        !            69:        void WriteCommand(uint32 data);
        !            70:        void WriteTest(uint32 data);
        !            71: 
        !            72:        uint32 Palette454ToInt(int n) const;
        !            73:        uint32 Palette458ToInt(int n) const;
        !            74: 
        !            75:        DECLARE_MONITOR_CALLBACK(MonitorUpdate454);
        !            76:        DECLARE_MONITOR_CALLBACK(MonitorUpdate458);
        !            77: 
        !            78:        // モデル種別。Bt454 なら true。
        !            79:        bool bt454 {};
        !            80: 
        !            81:        // ビットマップのプレーン数 (1, 4, 8)
        !            82:        int nplane {};
        !            83: 
        !            84:        // パレット数 (16 or 256)
        !            85:        int palettes {};
        !            86: 
        !            87:        // データの下位ニブルマスク。Bt454 なら LOW_NIBBLE。
        !            88:        uint8 low_nibble {};
        !            89: 
        !            90:        // Bt458 拡張
        !            91:        uint8 readmask {};              // パレットアドレスマスク
        !            92:        uint8 blinkmask {};             // ブリンクマスク
        !            93:        uint8 command {};               // コマンド
        !            94:        uint8 testreg {};               // テストレジスタ
        !            95: 
        !            96:        // idx は次にアクセスされるべき color[] へのインデックス。
        !            97:        // idx = 0 ならパレット0 の R。
        !            98:        // idx = 4 ならパレット1 の G。
        !            99:        // Bt454 では R/G/B をカウントするための 3値 2ビットのカウンタ(?)を
        !           100:        // ADDRa,ADDRb (ADDRa,b) と呼んだりしているようなので、ここではその
        !           101:        // modulo 3 を数えるカウンタを ab と呼ぶことにする。つまり
        !           102:        // idx = 0 はパレット 0、ab 0。
        !           103:        // idx = 4 はパレット 1、ab 1。
        !           104:        int idx;
        !           105: 
        !           106:        // パレットは R, G, B の順に格納されている。
        !           107:        // color[0] = パレット0 R
        !           108:        // color[1] = パレット0 G
        !           109:        // color[2] = パレット0 B
        !           110:        // color[3] = パレット1 R
        !           111:        // :
        !           112:        // color[47] = パレット15 B
        !           113:        //
        !           114:        // Bt454 なら 16パレット * 3 = 48エントリ。
        !           115:        // 色深度は 4ビットで上位4ビットと下位4ビットに同じものを格納する。
        !           116:        // つまり $4 なら $44、$f なら $ff として格納しておく。
        !           117:        //
        !           118:        // Bt458 なら 256パレット * 3 = 768エントリ。
        !           119:        // 色深度は 8ビットでそのまま格納。
        !           120:        std::vector<uint8> color;
        !           121: 
        !           122:        // ホスト用に変換したパレットデータ。
        !           123:        // ホスト用なので各8ビット、といいつつ元情報 (color[]) が8ビットすべて
        !           124:        // 有効なので値はそのまま流用する。
        !           125:        //
        !           126:        // また 1bpp モードなら R,G,B のうち G だけが使われるので、ここで
        !           127:        // 展開する。パレットのうち実際には #14 と #15 だけが使われるが、
        !           128:        // それについてはレンダラ側で処理している。
        !           129:        // see https://twitter.com/tsutsuii/status/356704682514714625
        !           130:        std::vector<ColorXBGR> hostcolor;
        !           131: 
        !           132:        Renderer *renderer {};
        !           133: 
        !           134:        Monitor monitor { this };
        !           135: 
        !           136:        // ログ出力用
        !           137:        static const char rgbstr[3];
        !           138: };
        !           139: 
        !           140: static inline BT45xDevice *GetBT45xDevice() {
        !           141:        return Object::GetObject<BT45xDevice>(OBJ_BT45x);
        !           142: }

unix.superglobalmegacorp.com

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