Skip to content

Commit

Permalink
speed throtling
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed Feb 25, 2025
1 parent 7bfcbfa commit 40bb3d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions XT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public P8086(ref Bus b, string test, TMode t_mode, uint load_test_at, bool termi
_flags |= 2;
}

public int GetClock()
{
return _clock;
}

public string SegmentAddr(ushort seg, ushort a)
{
return $"{seg:X04}:{a:X04}";
Expand Down
29 changes: 27 additions & 2 deletions main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
string key_mda = "mda";
string key_cga = "cga";

List<string> ide = new();

Dictionary<string, List<Tuple<string, int> > > consoles = new();

bool throttle = false;

for(int i=0; i<args.Length; i++)
{
if (args[i] == "-h") {
Expand All @@ -39,13 +43,17 @@
Console.WriteLine("-D file disassemble to file");
Console.WriteLine("-I disable I/O ports");
Console.WriteLine("-d enable debugger");
Console.WriteLine("-S try to run at real speed");
Console.WriteLine("-P skip prompt");
Console.WriteLine("-X file add an XT-IDE harddisk (must be 614/4/17 CHS)");
Console.WriteLine($"-p device,type,port port to listen on. type must be \"telnet\", \"http\" or \"vnc\" for now. device can be \"{key_cga}\" or \"{key_mda}\".");
Console.WriteLine("-o cs,ip start address (in hexadecimal)");
System.Environment.Exit(0);
}
else if (args[i] == "-t")
test = args[++i];
else if (args[i] == "-S")
throttle = true;
else if (args[i] == "-T")
load_test_at = (uint)Convert.ToInt32(args[++i], 16);
else if (args[i] == "-p")
Expand Down Expand Up @@ -85,6 +93,8 @@
System.Environment.Exit(1);
}
}
else if (args[i] == "-X")
ide.Add(args[++i]);
else if (args[i] == "-l")
Log.SetLogFile(args[++i]);
else if (args[i] == "-L")
Expand Down Expand Up @@ -178,8 +188,8 @@
if (floppies.Count() > 0)
devices.Add(new FloppyDisk(floppies));

string [] drives = new string[] { "ide.img" };
devices.Add(new XTIDE(drives));
if (ide.Count() > 0)
devices.Add(new XTIDE(ide));

devices.Add(new MIDI());

Expand Down Expand Up @@ -405,8 +415,23 @@
{
try
{
long prev_time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
int prev_clock = 0;
while(p.Tick())
{
if (!throttle)
continue;

int now_clock = p.GetClock();
if (now_clock - prev_clock >= 4770000 / 50)
{
long now_time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long diff_time = now_time - prev_time;
if (diff_time < 20)
Thread.Sleep((int)(20 - diff_time));
prev_time = now_time;
prev_clock = now_clock;
}
}
}
catch(Exception e)
Expand Down

0 comments on commit 40bb3d2

Please sign in to comment.