|
|
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 root 11: #include "rtc.h"
12:
13: // MK48T02 の時計部分のレジスタと内部状態
14: struct MK48T02Clock
15: {
16: // コントロールレジスタは以下の3つを保持。
17: uint8 ctrl;
18: static const uint8 WRITE = 0x80; // WRITE BIT
19: static const uint8 READ = 0x40; // READ BIT
20: static const uint8 SIGN = 0x20; // SIGN BIT (?)
21:
22: // 秒カウンタ(BCD)
23: uint8 sec;
24: // 秒カウンタの bit7 が STOP ビット
25: static const uint8 STOP = 0x80;
26: // STOP 状態を保持
27: bool stop;
28:
29: // 分カウンタ(BCD)
30: uint8 min;
31:
32: // 時カウンタ(BCD)
33: uint8 hour;
34: // 時カウンタの bit7 が KICKSTART ビット
35: static const uint8 KICKSTART = 0x80;
36: // KICKSTART 状態を保持
37: bool kickstart;
38:
39: // 曜日カウンタ
40: uint8 wday;
41: static const uint8 FREQTEST = 0x40; // Frequency Test (未実装)
42:
43: // 日カウンタ
44: uint8 mday;
45: // 月カウンタ
46: uint8 mon;
47: // 年カウンタ (0 が 1970年)
48: uint8 year;
49: static const int YEAR_EPOCH = 1970;
50: };
51:
52: class MK48T02Device : public RTCDevice
53: {
1.1.1.3 root 54: using inherited = RTCDevice;
1.1 root 55: public:
56: MK48T02Device();
1.1.1.6 root 57: virtual ~MK48T02Device() override;
1.1 root 58:
1.1.1.3 root 59: bool Init() override;
60: bool InitRTC() override;
1.1 root 61:
1.1.1.4 root 62: void MonitorUpdate(TextScreen&) override;
1.1 root 63:
1.1.1.3 root 64: void ClockIn() override;
1.1 root 65:
1.1.1.2 root 66: // 指定したアドレスからの文字列を読み出す (内蔵 ROM からのアクセス用)
67: std::string PeekString(uint32 addr) const;
68: // 指定したアドレスに文字列を書き込む (内蔵 ROM からのアクセス用)
69: bool WriteString(uint32 addr, const std::string& data);
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.3 root 89: // ファイル
1.1 root 90: std::string filename {};
1.1.1.3 root 91: MappedFile file {};
92: uint8 *mem {};
1.1 root 93:
94: // 時計
95: MK48T02Clock reg {};
96:
97: // レジスタとして読める値を定数にすることで、仮想マシン状態を
98: // 常に同じ状態にするためのパフォーマンス測定用フラグ。
99: // なお NVRAM 部分は影響されない。
1.1.1.5 root 100: bool force_fixed {};
1.1 root 101: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.