Annotation of nono/vm/mfp.h, revision 1.1.1.9

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "device.h"
1.1.1.9 ! root       10: #include "monitor.h"
1.1       root       11: #include "scheduler.h"
                     12: 
                     13: struct MFP
                     14: {
                     15:        static const int GPIP   = 0;    // $E88001
                     16:        static const int AER    = 1;    // $E88003
                     17:        static const int DDR    = 2;    // $E88005
                     18:        static const int IERA   = 3;    // $E88007
                     19:        static const int IERB   = 4;    // $E88009
                     20:        static const int IPRA   = 5;    // $E8800B
                     21:        static const int IPRB   = 6;    // $E8800D
                     22:        static const int ISRA   = 7;    // $E8800F
                     23:        static const int ISRB   = 8;    // $E88011
                     24:        static const int IMRA   = 9;    // $E88013
                     25:        static const int IMRB   = 10;   // $E88015
                     26:        static const int VR             = 11;   // $E88017
                     27:        static const int TACR   = 12;   // $E88019
                     28:        static const int TBCR   = 13;   // $E8801B
                     29:        static const int TCDCR  = 14;   // $E8801D
                     30:        static const int TADR   = 15;   // $E8801F
                     31:        static const int TBDR   = 16;   // $E88021
                     32:        static const int TCDR   = 17;   // $E88023
                     33:        static const int TDDR   = 18;   // $E88025
                     34:        static const int SCR    = 19;   // $E88027
                     35:        static const int UCR    = 20;   // $E88029
                     36:        static const int RSR    = 21;   // $E8802B
                     37:        static const int TSR    = 22;   // $E8802D
                     38:        static const int UDR    = 23;   // $E8802F
                     39: 
                     40:        union ir16 {
                     41:                uint16 w;
                     42:                struct {
                     43: #if BYTE_ORDER == LITTLE_ENDIAN
                     44:                        uint8 b, a;
                     45: #else
                     46:                        uint8 a, b;
                     47: #endif
                     48:                };
                     49:        };
                     50: 
                     51:        // ハードウェア未実装ビットは書き込み時に '0' にする
                     52: 
                     53:        uint8 gpip;
                     54:        uint8 aer;
                     55:        uint8 ddr;
                     56:        static const int GPIP_HSYNC = 7;
                     57:        static const int GPIP_CIRQ  = 6;
                     58:                                                                                // 5 は常に '1'
                     59:        static const int GPIP_VDISP = 4;
                     60:        static const int GPIP_FMIRQ = 3;
                     61:        static const int GPIP_POWSW = 2;
                     62:        static const int GPIP_EXPON = 1;
                     63:        static const int GPIP_ALARM = 0;
                     64: 
1.1.1.3   root       65:        static const uint INTR_RTC_ALARM        = 0;
                     66:        static const uint INTR_EXPON            = 1;
                     67:        static const uint INTR_POW_SW           = 2;
                     68:        static const uint INTR_FM_IRQ           = 3;
                     69:        static const uint INTR_TIMER_D          = 4;
                     70:        static const uint INTR_TIMER_C          = 5;
                     71:        static const uint INTR_VDISP            = 6;
                     72:        static const uint INTR_unused           = 7;
                     73:        static const uint INTR_TIMER_B          = 8;
                     74:        static const uint INTR_TXERR            = 9;
                     75:        static const uint INTR_TXEMPTY          = 10;
                     76:        static const uint INTR_RXERR            = 11;
                     77:        static const uint INTR_RXFULL           = 12;
                     78:        static const uint INTR_TIMER_A          = 13;
                     79:        static const uint INTR_CRTC_IRQ         = 14;
                     80:        static const uint INTR_HSYNC            = 15;
1.1       root       81:        ir16 ier;
                     82:        ir16 ipr;
                     83:        ir16 isr;
                     84:        ir16 imr;
1.1.1.6   root       85: 
                     86:        //
                     87:        //     | b7  | b6  | b5  | b4  | b3  | b2  | b1  | b0  |
                     88:        // VR  | V7  | V6  | V5  | V4  |  S  | --- | --- | --- |
                     89:        //        |     |     |     |     +------------ In-Service Register Enable
                     90:        //        +-----+-----+-----+------------------ Vector Number
                     91:        uint8 vr_vec;           // ベクタの上位4ビット
                     92:        uint8 vr_s;                     // %1:ソフトウェアEOI(ISR有効)、%0:自動EOI(ISR無効)
                     93:        uint8 GetVR() const     { return vr_vec | vr_s; }
1.1       root       94: 
                     95:        // TDR のカウンタをメインカウンタと呼び、このメインカウンタを
                     96:        // 1減らすためのカウンタをプリスケーラカウンタと呼ぶ。
                     97:        // 実際のハードウェアは 4MHz のクロック入力ごとにプリスケーラカウンタを
                     98:        // カウントしていき指定回数カウントすればメインカウンタを1減らすのだが、
1.1.1.6   root       99:        // この実装ではどちらのカウンタも持たず、タイマー終了時刻と現在時刻で
                    100:        // 管理する。そのためメインカウンタの値はこの時間差から求める。
1.1       root      101: 
1.1.1.6   root      102:        // tcr は書き込み値、現在のモードを保持する。
1.1       root      103:        uint8 tcr[4];           // --- --- --- RST AC3 AC2 AC1 AC0 : TACR
                    104:                                                // --- --- --- RST BC3 BC2 BC1 BC0 : TBCR
                    105:                                                // --- CC2 CC1 CC0 --- DC2 DC1 DC0 : TCDCR
                    106: 
1.1.1.6   root      107:        // tdr はカウンタの現在値。
1.1       root      108:        uint8 tdr[4];
                    109: 
                    110:        // initial_tdr はカウントダウン開始時点での TxDR の値。
                    111:        // カウンタが 1 から 0 になるタイミングで tdr の値をリロードする。
                    112:        // tdr に $00 を書き込むと 256 カウントになるため、
                    113:        // initial_tdr は 1..256 の値をとる。
                    114:        uint initial_tdr[4];
                    115: 
                    116:        uint8 scr;
1.1.1.3   root      117: 
                    118:        //     | b7  | b6  | b5  | b4  | b3  | b2  | b1  | b0  |
                    119:        // UCR | CLK |    WL     |    ST     | PE  | E/O | --- |
                    120:        //        |        |           |        |     +--------- %1で偶数パリティ
                    121:        //        |        |           |        +--------------- %1でパリティエラー
                    122:        //        |        |           +------------------- スタート/ストップビット
                    123:        //        |        +--- データ長                    %00 同期
                    124:        //        |             %00:8bit,  %01:7bit         %01 非同期 1bit/1bit
                    125:        //        |             %10:6bit,  %11:5bit         %10 非同期 1bit/1.5bit
                    126:        //        |                                         %11 非同期 1bit/2bit
                    127:        //        |
                    128:        //        +------------------------------------- %1 送受信速度が入力の1/16
                    129:        static const uint32 UCR_CLK = 0x80;
                    130:        static const uint32 UCR_WL  = 0x60;
                    131:        static const uint32 UCR_ST  = 0x18;
                    132:        static const uint32 UCR_PE  = 0x04;
                    133:        static const uint32 UCR_EO  = 0x02;
                    134:        uint8 ucr;
                    135: 
                    136:        //     | b7  | b6  | b5  | b4  | b3  | b2  | b1  | b0  |
                    137:        // RSR | BF  | OE  | PE  | FE  |  B  | CIP | SS  | RE  |
                    138:        //        |     |     |     |     |     |     |     +--- %1 RX Enable
                    139:        //        |     |     |     |     |     |     +--------- Sync Stop
                    140:        //        |     |     |     |     |     +--------------- 非同期なら
                    141:        //        |     |     |     |     |                      %1 Detect Start Bit
                    142:        //        |     |     |     |     |                      %0 Detect Stop Bit
                    143:        //        |     |     |     |     +--------------------- %1 非同期ならBreak
                    144:        //        |     |     |     +--------------------------- %1 Framing Error
                    145:        //        |     |     +--------------------------------- %1 Parity Error
                    146:        //        |     +--------------------------------------- %1 Overflow Error
                    147:        //        +--------------------------------------------- %1 RX Buffer Full
                    148:        static const uint32 RSR_BF  = 0x80;
                    149:        static const uint32 RSR_OE  = 0x40;
                    150:        static const uint32 RSR_PE  = 0x20;
                    151:        static const uint32 RSR_FE  = 0x10;
                    152:        static const uint32 RSR_B   = 0x08;
                    153:        static const uint32 RSR_CIP = 0x04;
                    154:        static const uint32 RSR_SS  = 0x02;
                    155:        static const uint32 RSR_RE  = 0x01;
1.1       root      156:        uint8 rsr;
1.1.1.3   root      157: 
                    158:        //     | b7  | b6  | b5  | b4  | b3  | b2  | b1  | b0  |
                    159:        // TSR | BE  | UE  | AT  | END |  B  |  H  |  L  | TE  |
                    160:        //        |     |           |                       +--- %1 TX Enable
                    161:        //        |     |           +--------------------------- %1 TX Disabled
                    162:        //        |     +--------------------------------------- %1 Underrun Error
                    163:        //        +--------------------------------------------- %1 TX Buffer Empty
                    164:        static const uint32 TSR_BE  = 0x80;
                    165:        static const uint32 TSR_UE  = 0x40;
                    166:        static const uint32 TSR_AT  = 0x20;
                    167:        static const uint32 TSR_END = 0x10;
                    168:        static const uint32 TSR_B   = 0x08;
                    169:        static const uint32 TSR_H   = 0x04;
                    170:        static const uint32 TSR_L   = 0x02;
                    171:        static const uint32 TSR_TE  = 0x01;
1.1       root      172:        uint8 tsr;
                    173: 
1.1.1.3   root      174:        // 送受信レジスタ。
                    175:        // 受信データがなければ -1 にする
                    176:        uint16 udr;
1.1       root      177: };
                    178: 
1.1.1.9 ! root      179: class MFPDevice : public IODevice
1.1       root      180: {
1.1.1.3   root      181:        using inherited = IODevice;
1.1       root      182: 
                    183:        static const int baseaddr = 0xe88000;
                    184: 
                    185:  public:
                    186:        MFPDevice();
1.1.1.6   root      187:        virtual ~MFPDevice() override;
1.1       root      188: 
1.1.1.5   root      189:        void ResetHard() override;
1.1       root      190: 
1.1.1.6   root      191:        // 割り込みアクノリッジ
                    192:        int InterruptAcknowledge();
                    193: 
1.1       root      194:        // VDisp 入力
                    195:        void SetVDisp(bool vdisp);
                    196: 
1.1.1.3   root      197:        // KEY CTRL 状態を設定する
                    198:        void SetKeyCtrl(bool ctrl);
                    199: 
1.1.1.8   root      200:        // キーボードからの送信が可能なら true を返す。
                    201:        bool RxIsReady() const;
1.1.1.3   root      202: 
                    203:        // キーボードからデータを受信
                    204:        void Rx(uint32 data);
1.1.1.2   root      205: 
1.1.1.3   root      206:  protected:
                    207:        // BusIO インタフェース
                    208:        static const uint32 NPORT = 0x20;
1.1.1.7   root      209:        uint64 Read(uint32 offset);
                    210:        uint64 Write(uint32 offset, uint32 data);
                    211:        uint64 Peek(uint32 offset);
1.1.1.3   root      212: 
                    213:  private:
1.1       root      214:        void SetTCR(int ch, uint32 data);
1.1.1.2   root      215:        uint8 GetTDR(int ch) const;
1.1       root      216:        void SetTDR(int ch, uint32 data);
                    217: 
                    218:        // GPIP の信号状態をセットする
                    219:        void SetGPIP(int num, bool val);
                    220: 
1.1.1.3   root      221:        void SetUCR(uint32 data);
                    222:        void SetRSR(uint32 data);
                    223:        void SetUDR(uint32 data);
                    224: 
1.1.1.8   root      225:        // RSR::BF ビットの状態を変える
                    226:        void SetBF();
                    227:        void ClearBF();
                    228:        // MFP の RR 線の状態を返す
                    229:        bool IsRR() const;
                    230: 
1.1.1.3   root      231:        // イベントコールバック
1.1.1.5   root      232:        void TimerCallback(Event& ev);
                    233:        void KeyCallback(Event& ev);
1.1       root      234: 
1.1.1.6   root      235:        // 必要なら割り込みを上げる
                    236:        void SetInterrupt(uint ch);
                    237: 
                    238:        // 割り込み信号線の状態を変える
                    239:        void ChangeInterrupt();
                    240: 
1.1.1.9 ! root      241:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
        !           242: 
1.1       root      243:        struct MFP mfp {};
                    244:        Event event[4] {};
1.1.1.9 ! root      245:        Event key_event { this };
        !           246: 
        !           247:        Monitor monitor { this };
1.1.1.3   root      248: 
1.1       root      249:        static const char *intrname[];
                    250:        static const char *gpipname[];
                    251:        static const int prescale_ns[8];
                    252:        static const char *prescale_str[8];
                    253:        static const int timer_vector[4];
                    254: };
                    255: 
1.1.1.2   root      256: extern std::unique_ptr<MFPDevice> gMFP;

unix.superglobalmegacorp.com

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