Repository navigation
Expand file tree
/
Copy pathRTC.cs
More file actions
127 lines (109 loc) · 3.24 KB
/
Copy pathRTC.cs
File metadata and controls
127 lines (109 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
internal class RTC : Device
{
private int _irq_nr = -1;
private byte _cmos_ram_index = 0;
private bool _busy = false;
private byte [] _ram = new byte[128];
public RTC()
{
Log.Cnsl("RTC instantiated");
}
public override int GetIRQNumber()
{
return _irq_nr;
}
public override String GetName()
{
return "RTC";
}
public override void RegisterDevice(Dictionary <ushort, Device> mappings)
{
mappings[0x0070] = this;
mappings[0x0071] = this;
mappings[0x0240] = this;
mappings[0x0241] = this;
mappings[0x02c0] = this;
mappings[0x02c1] = this;
}
private byte ToBCD(int v)
{
int d1 = v / 10;
int d2 = v % 10;
return (byte)((d1 << 4) | d2);
}
public override byte IO_Read(ushort port)
{
byte rc = 0xff;
if (port == 0x71 || port == 0x241 || port == 0x2c1)
{
DateTime now = DateTime.Now;
if (_cmos_ram_index == 0)
rc = ToBCD(now.Second);
else if (_cmos_ram_index == 2)
rc = ToBCD(now.Minute);
else if (_cmos_ram_index == 4)
rc = ToBCD(now.Hour);
else if (_cmos_ram_index == 6)
rc = ToBCD((int)now.DayOfWeek);
else if (_cmos_ram_index == 7)
rc = ToBCD(now.Day);
else if (_cmos_ram_index == 8)
rc = ToBCD(now.Month);
else if (_cmos_ram_index == 9)
rc = ToBCD(now.Year % 100);
else if (_cmos_ram_index == 0x32)
rc = ToBCD(now.Year / 100);
else if (_cmos_ram_index == 0x0b)
rc = 2; // 24h mode
else if (_cmos_ram_index == 0x10)
rc = 0x11; // 2x 360 kB floppy drive
else if (_cmos_ram_index == 0x0a)
{
rc = _ram[_cmos_ram_index];
//rc |= (byte)(_busy ? 128 : 0);
_busy = !_busy;
}
else
{
rc = _ram[_cmos_ram_index];
Log.DoLog($"RTC register {_cmos_ram_index:X02} not implemented", LogLevel.WARNING);
}
}
else
{
Log.DoLog($"RTC reading from {port:X04} not implemented", LogLevel.WARNING);
}
Log.DoLog($"RTC IN {port:X04} (index: {_cmos_ram_index:X02}), returning {rc:X02}", LogLevel.TRACE);
return rc;
}
public override bool IO_Write(ushort port, byte value)
{
Log.DoLog($"RTC OUT {port:X04}, value {value:X02} (index: {_cmos_ram_index:X02})", LogLevel.TRACE);
if (port == 0x070 || port == 0x240 || port == 0x2c0)
_cmos_ram_index = (byte)(value & 127);
else
{
_ram[_cmos_ram_index] = value;
}
return false;
}
public override List<Tuple<uint, int> > GetAddressList()
{
return new() { };
}
public override void WriteByte(uint offset, byte value)
{
}
public override byte ReadByte(uint offset)
{
return 0xee;
}
public override bool Ticks()
{
return false;
}
public override bool Tick(int ticks, long ignored)
{
return false;
}
}