コード例 #1
0
 public ProgrammableInterruptTimer8253(ProgrammableInterruptController8259 pic)
 {
     this.pic                 = pic;
     timers                   = new Timer[TimerCount];
     timers[Irq0Timer]        = new Timer();
     timers[DramRefreshTimer] = new Timer();
     timers[PcSpeakerTimer]   = new Timer();
 }
コード例 #2
0
        public ProgrammablePeripheralInterface8255(ILogger <ProgrammablePeripheralInterface8255> logger,
                                                   EventToken eventToken,
                                                   MemoryController memoryController,
                                                   ProgrammableInterruptTimer8253 pit,
                                                   ProgrammableInterruptController8259 pic)
        {
            this.logger = logger;
            this.pic    = pic;
            this.pit    = pit;
            // IBM PC BIOS fetches the LSB of the Equipment Word from Port 0x60.
            // - Bits 5-4: 0=EGA, 1=CGA 40x25, 2=CGA 80x25, 3=MDA
            // - Bits 3-2=(value + 4) << 12 is memory size (undocumented, but used during POST).
            //   We return the max (64K) although we have much more.
            data[0] = SenseInfo;
            Console.TreatControlCAsInput = true;

            var shutdownCancellationToken = eventToken.ShutDown.Token;

            Task = Task.Run(async() =>
            {
                byte[] scanCodes;
                if (isWindows)
                {
                    scanCodes = Enumerable.Range(0, 256).Select(x => (byte)MapVirtualKey(x, 0)).ToArray();
                }
                else
                {
                    Dictionary <int, int> linuxScanCodes = ReadLinuxScanCodes();
                    scanCodes = Enumerable.Range(0, 256)
                                .Select(x => linuxScanCodes.TryGetValue(x, out var scanCode) ? (byte)scanCode : (byte)0).ToArray();
                }

                while (!shutdownCancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(50, shutdownCancellationToken).ConfigureAwait(false);

                    if (!Console.KeyAvailable)
                    {
                        continue;
                    }

                    var consoleKeyInfo = Console.ReadKey(true);

                    if (consoleKeyInfo.Modifiers == (ConsoleModifiers.Control | ConsoleModifiers.Alt))
                    {
                        if (consoleKeyInfo.Key == ConsoleKey.C)
                        {
                            eventToken.Halt.Cancel();
                        }
                        else if (consoleKeyInfo.Key == ConsoleKey.M)
                        {
                            await File.WriteAllBytesAsync(
                                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Memory.bin"),
                                memoryController.Memory, shutdownCancellationToken);
                        }
                    }

                    if (consoleKeyInfo.Modifiers.HasFlag(ConsoleModifiers.Shift))
                    {
                        PutKey(scanCodes[VK_LSHIFT]);
                        await Task.Delay(20, shutdownCancellationToken).ConfigureAwait(false);
                    }

                    PutKey(scanCodes[(byte)consoleKeyInfo.Key]);
                    if (consoleKeyInfo.Modifiers.HasFlag(ConsoleModifiers.Shift))
                    {
                        await Task.Delay(20, shutdownCancellationToken).ConfigureAwait(false);
                        PutKey((byte)(scanCodes[VK_LSHIFT] | 0x80));
                    }
                }
            });
        }