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

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

unix.superglobalmegacorp.com

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