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

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 uint64 Read8(uint32 addr);
                     61:        virtual uint64 Read16(uint32 addr);
                     62:        virtual uint64 Read32(uint32 addr);
                     63:        virtual uint64 Write8(uint32 addr, uint32 data);
                     64:        virtual uint64 Write16(uint32 addr, uint32 data);
                     65:        virtual uint64 Write32(uint32 addr, uint32 data);
                     66:        virtual uint64 Peek8(uint32 addr);
                     67: 
                     68:        virtual bool MonitorUpdate();
                     69: 
                     70:        virtual void ClockIn();
                     71: 
                     72:  private:
                     73:        // バイナリ <-> BCD 変換
                     74:        static inline uint8 num2BCD(uint8);
                     75:        static inline uint8 BCD2num(uint8);
                     76: 
                     77:        // コントロールレジスタへの書き込み
                     78:        void WriteCtrl(uint32 data);
                     79: 
                     80:        std::string filename {};
                     81:        int fd = 0;
                     82: 
                     83:        // バイト順はファイルイメージそのままで、2040バイト。
                     84:        uint8 *mem = NULL;
                     85: 
                     86:        // mmap する長さ
                     87:        int memlen = 0;
                     88: 
                     89:        // 時計
                     90:        MK48T02Clock reg {};
                     91: 
                     92:        // レジスタとして読める値を定数にすることで、仮想マシン状態を
                     93:        // 常に同じ状態にするためのパフォーマンス測定用フラグ。
                     94:        // なお NVRAM 部分は影響されない。
                     95:        bool force_fixed = false;
                     96: };

unix.superglobalmegacorp.com

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