Repository navigation
Expand file tree
/
Copy pathXTServer.cs
More file actions
158 lines (137 loc) · 4.89 KB
/
Copy pathXTServer.cs
File metadata and controls
158 lines (137 loc) · 4.89 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using DotXT;
using System.Text;
internal class XTServer : Device
{
private int _irq_nr = -1;
private string _bin_file;
private uint _bin_file_load_address = 0;
private Display _d = null;
private string _trace_file = null;
public static void AddXTServerBootROM(Bus b)
{
uint start_addr = 0xd000 * 16 + 0x0000;
uint addr = start_addr;
byte [] option_rom = new byte[] {
0x55, 0xaa, 0x01, 0xba, 0x01, 0xf0, 0xb0, 0xff, 0xee, 0x31, 0xc0, 0x8e,
0xd8, 0xbe, 0x80, 0x01, 0xb9, 0x0b, 0x00, 0xc7, 0x04, 0x5a, 0x00, 0xc7,
0x44, 0x02, 0x00, 0xd0, 0x83, 0xc6, 0x04, 0xe0, 0xf2, 0xbe, 0x80, 0x01,
0xc7, 0x04, 0x5b, 0x00, 0xc7, 0x44, 0x02, 0x00, 0xd0, 0xbe, 0x8c, 0x01,
0xc7, 0x04, 0x71, 0x00, 0xc7, 0x44, 0x02, 0x00, 0xd0, 0xbe, 0x90, 0x01,
0xc7, 0x04, 0x7e, 0x00, 0xc7, 0x44, 0x02, 0x00, 0xd0, 0xbe, 0x94, 0x01,
0xc7, 0x04, 0x91, 0x00, 0xc7, 0x44, 0x02, 0x00, 0xd0, 0xea, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xcf, 0xa3, 0x56, 0x00, 0x89, 0x16,
0x58, 0x00, 0xba, 0x01, 0xf0, 0xb8, 0x01, 0x60, 0xef, 0x8b, 0x16, 0x58,
0x00, 0xa1, 0x56, 0x00, 0xcf, 0x89, 0x16, 0x58, 0x00, 0xba, 0x63, 0xf0,
0xef, 0x8b, 0x16, 0x58, 0x00, 0xcf, 0x89, 0x16, 0x58, 0x00, 0xba, 0x64,
0xf0, 0x8a, 0x04, 0x46, 0xee, 0x49, 0xe0, 0xf9, 0x8b, 0x16, 0x58, 0x00,
0xcf, 0x89, 0x16, 0x58, 0x00, 0xba, 0x65, 0xf0, 0xee, 0x8b, 0x16, 0x58,
0x00, 0xcf
};
for(int i=0; i<option_rom.Length; i++)
b.WriteByte(addr++, option_rom[i]);
byte checksum = 0;
for(int i=0; i<512; i++)
checksum += b.ReadByte((uint)(start_addr + i)).Item1;
b.WriteByte(start_addr + 511, (byte)(~checksum));
}
public XTServer(string bin_file, uint bin_file_load_address, Display d, string trace_file)
{
Log.Cnsl("XTServer instantiated");
_bin_file = bin_file;
_bin_file_load_address = bin_file_load_address;
_d = d;
_trace_file = trace_file;
}
public override int GetIRQNumber()
{
return _irq_nr;
}
public override String GetName()
{
return "XTServer";
}
public override void RegisterDevice(Dictionary <ushort, Device> mappings)
{
mappings[0xf001] = this;
mappings[0xf063] = this;
mappings[0xf064] = this;
mappings[0xf065] = this;
}
public override byte IO_Read(ushort port)
{
return 0xaa;
}
public override bool IO_Write(ushort port, byte value)
{
Log.DoLog($"XTServer emulation {value:X2}", LogLevel.DEBUG);
if (port == 0xf001)
{
if (value == 0x6001) // screenshot
{
if (_d != null)
{
try
{
var frame = _d.GetFrame(false);
var bmp = Tools.GraphicalFrameToBmp(frame);
using (FileStream stream = new FileStream($"{DateTime.Now.Ticks}.bmp", FileMode.Create, FileAccess.Write))
{
stream.Write(bmp, 0, bmp.Length);
}
}
catch(Exception e)
{
Log.DoLog($"Failed to write screenshot: {e}", LogLevel.ERROR);
}
}
}
else if (value == 0xff) // load test code
{
Tools.LoadBin(_b, _bin_file, _bin_file_load_address);
}
}
else if (port == 0xf063)
{
if (_trace_file != null)
{
using (FileStream stream = new FileStream(_trace_file, FileMode.Append, FileAccess.Write))
{
byte[] data = new UTF8Encoding(true).GetBytes($"{value:X4}");
stream.Write(data, 0, data.Length);
}
}
}
else if (port == 0xf064 || port == 0xf065)
{
// f065 has special escape codes TODO
if (_trace_file != null)
{
using (FileStream stream = new FileStream(_trace_file, FileMode.Append, FileAccess.Write))
{
byte[] data = new byte[] { value };
stream.Write(data, 0, data.Length);
}
}
}
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;
}
}