-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDA.cs
82 lines (61 loc) · 1.79 KB
/
MDA.cs
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
class MDA : Display
{
private byte [] _ram = new byte[16384];
private bool _hsync = false;
public MDA()
{
}
public override String GetName()
{
return "MDA";
}
public override void RegisterDevice(Dictionary <ushort, Device> mappings)
{
Log.DoLog("MDA::RegisterDevice", true);
for(ushort port=0x3b0; port<0x3c0; port++)
mappings[port] = this;
}
public override bool HasAddress(uint addr)
{
return addr >= 0xb0000 && addr < 0xb8000;
}
public override bool IO_Write(ushort port, byte value)
{
Log.DoLog($"MDA::IO_Write {port:X4} {value:X2}", true);
return false;
}
public override (byte, bool) IO_Read(ushort port)
{
byte rc = 0;
if (port == 0x03ba)
{
rc = (byte)(_hsync ? 9 : 0);
_hsync = !_hsync;
}
Log.DoLog($"MDA::IO_Read {port:X4}: {rc:X2}", true);
return (rc, false);
}
public override void WriteByte(uint offset, byte value)
{
// Log.DoLog($"MDA::WriteByte({offset:X6}, {value:X2})", true);
uint use_offset = (offset - 0xb0000) & 0x3fff;
_ram[use_offset] = value;
if (use_offset < 80 * 25 * 2)
{
uint y = use_offset / (80 * 2);
uint x = (use_offset % (80 * 2)) / 2;
uint mask = uint.MaxValue - 1;
uint char_base_offset = use_offset & mask;
EmulateTextDisplay(x, y, _ram[char_base_offset + 0], _ram[char_base_offset + 1]);
}
}
public override byte ReadByte(uint offset)
{
// Log.DoLog($"MDA::ReadByte({offset:X6})", true);
return _ram[(offset - 0xb0000) & 0x3fff];
}
public override bool Tick(int cycles)
{
return false;
}
}