diff --git a/floppy.cs b/floppy.cs index a10a8f6..4ceebf8 100644 --- a/floppy.cs +++ b/floppy.cs @@ -16,6 +16,7 @@ class FloppyDisk : Device private int [] _cylinder = new int[4]; private int [] _head = new int[4]; private int _cylinder_seek_result = 0; + private static readonly System.Threading.Lock _filenames_lock = new(); public FloppyDisk(List filenames) { @@ -23,6 +24,38 @@ public FloppyDisk(List filenames) _filenames = filenames; } + public int GetUnitCount() + { + return _filenames.Count(); + } + + public string GetUnitFilename(int unit) + { + lock(_filenames_lock) + { + if (unit < _filenames.Count()) + { + return _filenames[unit]; + } + } + + return null; + } + + public bool SetUnitFilename(int unit, string filename) + { + lock(_filenames_lock) + { + if (unit < _filenames.Count()) + { + _filenames[unit] = filename; + return true; + } + } + + return false; + } + public override int GetIRQNumber() { return _irq_nr; @@ -123,29 +156,33 @@ public override (byte, bool) IO_Read(ushort port) private byte [] GetFromFloppyImage(int unit, int cylinder, int head, int sector, int n) { - long file_size = new System.IO.FileInfo(_filenames[unit]).Length; - int sectors_per_track = 9; - if (file_size >= 819200) - sectors_per_track = 18; - - if (sector > sectors_per_track) - Log.DoLog($"Floppy-ReadData: reading beyond sector-count? ({sector} > {sectors_per_track})"); - byte[] b = new byte[256 * n]; - int lba = (cylinder * 2 + head) * sectors_per_track + sector - 1; - long offset = lba * b.Length; - Log.DoLog($"Floppy-ReadData LBA {lba}, offset {offset}, n {n} C {cylinder} H {head} S {sector} ({sectors_per_track})", true); - for(int nr=0; nr= 819200) + sectors_per_track = 18; + + if (sector > sectors_per_track) + Log.DoLog($"Floppy-ReadData: reading beyond sector-count? ({sector} > {sectors_per_track})"); + + int lba = (cylinder * 2 + head) * sectors_per_track + sector - 1; + long offset = lba * b.Length; + Log.DoLog($"Floppy-ReadData LBA {lba}, offset {offset}, n {n} C {cylinder} H {head} S {sector} ({sectors_per_track})", true); + + for(int nr=0; nr= _filenames.Count()) - return false; + lock(_filenames_lock) + { + if (unit >= _filenames.Count()) + return false; + } int sector = _data[4]; int head = (_data[1] & 4) == 4 ? 1 : 0; diff --git a/main.cs b/main.cs index f200ebb..71249ff 100644 --- a/main.cs +++ b/main.cs @@ -216,8 +216,7 @@ Console.Write("==>"); string line = Console.ReadLine(); - - //Log.DoLog(line); + Log.DoLog(line, true); string[] parts = line.Split(' '); @@ -399,9 +398,7 @@ { p.ResetCrashCounter(); - while(p.Tick()) - { - } + runner(p); } else if (line != "") { @@ -413,6 +410,49 @@ } else { + Thread thread = new Thread(runner); + thread.Name = "runner"; + thread.Start(p); + + for(;;) + { + Console.Write("==>"); + + string line = Console.ReadLine(); + Log.DoLog(line, true); + if (line == "") + continue; + + if (line == "quit") + break; + + if (line == "help") + { + Console.WriteLine("quit terminate application"); +// Console.WriteLine("lsfloppy list configured floppies"); + // Console.WriteLine("setfloppy x y set floppy unit x (0 based) to file y"); + } + // else if (line == "lsfloppy") + // { + // } + else + { + Console.WriteLine($"\"{line}\" is not understood"); + } + } +} + +Log.EmitDisassembly(); + +if (test != "" && mode == TMode.Binary) + System.Environment.Exit(p.GetSI() == 0xa5ee ? 123 : 0); + +System.Environment.Exit(0); + +void runner(object p_in) +{ + P8086 p = (P8086)p_in; + try { long prev_time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; @@ -441,10 +481,3 @@ Log.DoLog(msg); } } - -Log.EmitDisassembly(); - -if (test != "" && mode == TMode.Binary) - System.Environment.Exit(p.GetSI() == 0xa5ee ? 123 : 0); - -System.Environment.Exit(0);