Annotation of nono/vm/mk48t02.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.3   root       10: #include "mappedfile.h"
1.1.1.9 ! root       11: #include "monitor.h"
1.1       root       12: #include "rtc.h"
                     13: 
                     14: // MK48T02 の時計部分のレジスタと内部状態
                     15: struct MK48T02Clock
                     16: {
                     17:        // コントロールレジスタは以下の3つを保持。
                     18:        uint8 ctrl;
                     19:        static const uint8 WRITE        = 0x80; // WRITE BIT
                     20:        static const uint8 READ         = 0x40; // READ BIT
                     21:        static const uint8 SIGN         = 0x20; // SIGN BIT (?)
                     22: 
                     23:        // 秒カウンタ(BCD)
                     24:        uint8 sec;
                     25:        // 秒カウンタの bit7 が STOP ビット
                     26:        static const uint8 STOP         = 0x80;
                     27:        // STOP 状態を保持
                     28:        bool stop;
                     29: 
                     30:        // 分カウンタ(BCD)
                     31:        uint8 min;
                     32: 
                     33:        // 時カウンタ(BCD)
                     34:        uint8 hour;
                     35:        // 時カウンタの bit7 が KICKSTART ビット
                     36:        static const uint8 KICKSTART    = 0x80;
                     37:        // KICKSTART 状態を保持
                     38:        bool kickstart;
                     39: 
                     40:        // 曜日カウンタ
                     41:        uint8 wday;
                     42:        static const uint8 FREQTEST             = 0x40; // Frequency Test (未実装)
                     43: 
                     44:        // 日カウンタ
                     45:        uint8 mday;
                     46:        // 月カウンタ
                     47:        uint8 mon;
                     48:        // 年カウンタ (0 が 1970年)
                     49:        uint8 year;
                     50:        static const int YEAR_EPOCH = 1970;
                     51: };
                     52: 
                     53: class MK48T02Device : public RTCDevice
                     54: {
1.1.1.3   root       55:        using inherited = RTCDevice;
1.1       root       56:  public:
                     57:        MK48T02Device();
1.1.1.6   root       58:        virtual ~MK48T02Device() override;
1.1       root       59: 
1.1.1.3   root       60:        bool Init() override;
1.1       root       61: 
1.1.1.3   root       62:        void ClockIn() override;
1.1       root       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);
1.1.1.9 ! root       68:        // 全域をゼロクリアする (内蔵 ROM からのアクセス用)
        !            69:        void ClearAll();
1.1.1.2   root       70: 
                     71:        // BusIO インタフェース
                     72:        // (内蔵 ROM からのアクセス用に特別に public にしてある)
1.1.1.7   root       73:        uint64 Read(uint32 offset);
                     74:        uint64 Write(uint32 offset, uint32 data);
                     75:        uint64 Peek(uint32 offset);
                     76: 
1.1.1.2   root       77:  protected:
                     78:        // BusIO インタフェース
                     79:        static const uint32 NPORT = 2048;
                     80: 
1.1       root       81:  private:
                     82:        // バイナリ <-> BCD 変換
                     83:        static inline uint8 num2BCD(uint8);
                     84:        static inline uint8 BCD2num(uint8);
                     85: 
                     86:        // コントロールレジスタへの書き込み
                     87:        void WriteCtrl(uint32 data);
                     88: 
1.1.1.9 ! root       89:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
        !            90: 
1.1.1.3   root       91:        // ファイル
1.1       root       92:        std::string filename {};
1.1.1.3   root       93:        MappedFile file {};
                     94:        uint8 *mem {};
1.1       root       95: 
                     96:        // 時計
                     97:        MK48T02Clock reg {};
                     98: 
                     99:        // レジスタとして読める値を定数にすることで、仮想マシン状態を
                    100:        // 常に同じ状態にするためのパフォーマンス測定用フラグ。
                    101:        // なお NVRAM 部分は影響されない。
1.1.1.5   root      102:        bool force_fixed {};
1.1.1.9 ! root      103: 
        !           104:        Monitor monitor { this };
1.1       root      105: };

unix.superglobalmegacorp.com

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