-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.cs
81 lines (58 loc) · 2.08 KB
/
Display.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
abstract class Display : Device
{
private DateTime _prev_ts = DateTime.UtcNow;
private int _prev_clock;
private int _clock;
private int _last_hsync;
public Display()
{
TerminalClear();
}
protected void TerminalClear()
{
Console.Write((char)27); // clear screen
Console.Write($"[2J");
}
public abstract override String GetName();
public override void SyncClock(int clock)
{
DateTime now_ts = DateTime.UtcNow;
TimeSpan elapsed_time = now_ts.Subtract(_prev_ts);
_prev_ts = now_ts;
double target_cycles = 14318180 * elapsed_time.TotalMilliseconds / 3000;
int done_cycles = clock - _prev_clock;
int speed_percentage = (int)(done_cycles * 100.0 / target_cycles);
Console.Write((char)27);
Console.Write($"[1;82H{speed_percentage}% ");
_prev_clock = _clock;
_clock = clock;
}
public override List<PendingInterrupt> GetPendingInterrupts()
{
return null;
}
public abstract override void RegisterDevice(Dictionary <ushort, Device> mappings);
public abstract override bool HasAddress(uint addr);
public abstract override bool IO_Write(ushort port, byte value);
protected bool IsHsync()
{
// 14318180Hz system clock
// 18432Hz mda clock
// 50Hz refreshes per second
bool hsync = Math.Abs(_clock - _last_hsync) >= (14318180 / 18432 / 50);
_last_hsync = _clock;
return hsync;
}
public abstract override (byte, bool) IO_Read(ushort port);
protected void EmulateTextDisplay(uint x, uint y, byte character, byte attributes)
{
// attribute, character
// Log.DoLog($"Display::WriteByte {x},{y} = {(char)character}", true);
Console.Write((char)27); // position cursor
Console.Write($"[{y + 1};{x + 1}H");
Console.Write((char)character);
}
public abstract override void WriteByte(uint offset, byte value);
public abstract override byte ReadByte(uint offset);
public abstract override bool Tick(int cycles);
}