Annotation of nono/vm/mk48t02.h, revision 1.1.1.2

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #pragma once
                      7: 
                      8: #include "device.h"
                      9: #include "rtc.h"
                     10: 
                     11: // MK48T02 の時計部分のレジスタと内部状態
                     12: struct MK48T02Clock
                     13: {
                     14:        // コントロールレジスタは以下の3つを保持。
                     15:        uint8 ctrl;
                     16:        static const uint8 WRITE        = 0x80; // WRITE BIT
                     17:        static const uint8 READ         = 0x40; // READ BIT
                     18:        static const uint8 SIGN         = 0x20; // SIGN BIT (?)
                     19: 
                     20:        // 秒カウンタ(BCD)
                     21:        uint8 sec;
                     22:        // 秒カウンタの bit7 が STOP ビット
                     23:        static const uint8 STOP         = 0x80;
                     24:        // STOP 状態を保持
                     25:        bool stop;
                     26: 
                     27:        // 分カウンタ(BCD)
                     28:        uint8 min;
                     29: 
                     30:        // 時カウンタ(BCD)
                     31:        uint8 hour;
                     32:        // 時カウンタの bit7 が KICKSTART ビット
                     33:        static const uint8 KICKSTART    = 0x80;
                     34:        // KICKSTART 状態を保持
                     35:        bool kickstart;
                     36: 
                     37:        // 曜日カウンタ
                     38:        uint8 wday;
                     39:        static const uint8 FREQTEST             = 0x40; // Frequency Test (未実装)
                     40: 
                     41:        // 日カウンタ
                     42:        uint8 mday;
                     43:        // 月カウンタ
                     44:        uint8 mon;
                     45:        // 年カウンタ (0 が 1970年)
                     46:        uint8 year;
                     47:        static const int YEAR_EPOCH = 1970;
                     48: };
                     49: 
                     50: class MK48T02Device : public RTCDevice
                     51: {
                     52:        typedef RTCDevice inherited;
                     53:  public:
                     54:        MK48T02Device();
                     55:        virtual ~MK48T02Device();
                     56: 
                     57:        virtual bool Init();
                     58:        virtual bool InitRTC();
                     59: 
                     60:        virtual bool MonitorUpdate();
                     61: 
                     62:        virtual void ClockIn();
                     63: 
1.1.1.2 ! root       64:        // 指定したアドレスからの文字列を読み出す (内蔵 ROM からのアクセス用)
        !            65:        std::string PeekString(uint32 addr) const;
        !            66:        // 指定したアドレスに文字列を書き込む (内蔵 ROM からのアクセス用)
        !            67:        bool WriteString(uint32 addr, const std::string& data);
        !            68: 
        !            69:        // BusIO インタフェース
        !            70:        // (内蔵 ROM からのアクセス用に特別に public にしてある)
        !            71:        uint64 Read(uint32 addr);
        !            72:        uint64 Write(uint32 addr, uint32 data);
        !            73:        uint64 Peek(uint32 addr);
        !            74:  protected:
        !            75:        // BusIO インタフェース
        !            76:        static const uint32 NPORT = 2048;
        !            77: 
1.1       root       78:  private:
                     79:        // バイナリ <-> BCD 変換
                     80:        static inline uint8 num2BCD(uint8);
                     81:        static inline uint8 BCD2num(uint8);
                     82: 
                     83:        // コントロールレジスタへの書き込み
                     84:        void WriteCtrl(uint32 data);
                     85: 
                     86:        std::string filename {};
                     87:        int fd = 0;
                     88: 
                     89:        // バイト順はファイルイメージそのままで、2040バイト。
                     90:        uint8 *mem = NULL;
                     91: 
                     92:        // mmap する長さ
                     93:        int memlen = 0;
                     94: 
                     95:        // 時計
                     96:        MK48T02Clock reg {};
                     97: 
                     98:        // レジスタとして読める値を定数にすることで、仮想マシン状態を
                     99:        // 常に同じ状態にするためのパフォーマンス測定用フラグ。
                    100:        // なお NVRAM 部分は影響されない。
                    101:        bool force_fixed = false;
                    102: };

unix.superglobalmegacorp.com

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