Beispiel #1
0
 public void Initialize(FloppyController FloppyController, InterruptManager InterruptManager, Tape Tape, Printer Printer)
 {
     floppyController = FloppyController;
     intMgr           = InterruptManager;
     tape             = Tape;
     printer          = Printer;
     Reset();
 }
Beispiel #2
0
        private byte FetchByte(ref int TrackIndex, ref ushort Crc, bool AllowResetCRC, bool DoubleDensityMode)
        {
            if (GetDensity(TrackIndex) != DoubleDensityMode)
            {
#if DEBUG
                throw new NotImplementedException("TODO: Handle case where reading from wrong density.");
#endif
            }
            byte b = 0;
            if (TrackIndex < data.Length)
            {
                b   = data[TrackIndex];
                Crc = FloppyController.UpdateCRC(Crc, b, AllowResetCRC, DoubleDensityMode);
            }
            TrackIndex++;
            if (!DoubleDensityMode)
            {
                TrackIndex++;
            }
            return(b);
        }
Beispiel #3
0
        // CONSTRUCTOR

        public Computer(IScreen Screen, ISound Sound, ITimer Timer, ISettings Settings, IDialogs Dialogs)
        {
            ulong ticksPerSoundSample = Clock.TICKS_PER_SECOND / (ulong)Sound.SampleRate;

            HasRunYet = false;

            screen   = Screen;
            settings = Settings;
            dialogs  = Dialogs;
            sound    = Sound;

            Storage.Initialize(settings, dialogs);

            memory    = new Memory();
            intMgr    = new InterruptManager(this);
            this.tape = new Tape(this);
            ports     = new PortSet(this);
            cpu       = new Z80.Z80(this);
            printer   = new Printer();

            if (sound.Stopped)
            {
                sound = new SoundNull();
            }
            else
            {
                sound.SampleCallback = ports.CassetteOut;
            }

            clock = new Clock(this,
                              cpu,
                              Timer,
                              intMgr,
                              ticksPerSoundSample,
                              Sound.Sample);

            clock.SpeedChanged += () => Sound.Mute = clock.ClockSpeed != ClockSpeed.Normal;

            DiskUserEnabled = Settings.DiskEnabled;

            floppyController = new FloppyController(this, ports, clock, intMgr, Sound, DiskUserEnabled);

            intMgr.Initialize(ports, this.tape);
            this.tape.Initialize(clock, intMgr);
            ports.Initialize(floppyController, intMgr, this.tape, printer);

            for (byte i = 0; i < 4; i++)
            {
                LoadFloppy(i);
            }

            var tape = Storage.LastTapeFile;

            if (tape.Length > 0 && File.Exists(tape))
            {
                TapeLoad(tape);
            }

            DriveNoise   = Settings.DriveNoise;
            BreakPoint   = Settings.Breakpoint;
            BreakPointOn = Settings.BreakpointOn;
            SoundOn      = Settings.SoundOn;
            ClockSpeed   = Settings.ClockSpeed;
            Ready        = true;
        }
Beispiel #4
0
        private List <SectorDescriptor> GetSectorDescriptorCache()
        {
            var sds = new List <SectorDescriptor>();

            for (int SectorIndex = 0; SectorIndex < HEADER_LENGTH && Header[SectorIndex] > 0; SectorIndex++)
            {
                bool density      = Header[SectorIndex] >= DOUBLE_DENSITY_MASK;
                int  byteMultiple = density ? 1 : 2;
                int  offset       = (Header[SectorIndex] & OFFSET_MASK) - HEADER_LENGTH_BYTES;
                if (data[offset] != Floppy.IDAM)
                {
                    continue;
                }

                byte trackNum  = data[offset + 1 * byteMultiple];
                bool sideOne   = data[offset + 2 * byteMultiple] > 0;
                byte sectorNum = data[offset + 3 * byteMultiple];

                byte dam       = 0x00;
                int  dataStart = 0x00;
                bool deleted   = false;
                for (int i = offset + 7 * byteMultiple; i < offset + (7 + (density ? 43 : 30)) * byteMultiple; i += byteMultiple)
                {
                    if (FloppyController.IsDAM(data[i], out deleted))
                    {
                        dam       = data[i];
                        dataStart = i + byteMultiple;
                        break;
                    }
                }

                var  sizeCode   = data[offset + 4 * byteMultiple];
                var  dataLength = Floppy.GetDataLengthFromCode(sizeCode);
                var  sectorData = new byte[dataLength];
                bool crcError;
                bool inUse;
                if (dam == 0x00)
                {
                    crcError = true;
                    inUse    = false;
                }
                else
                {
                    inUse = !deleted;
                    ushort actualCrc = Lib.Crc(density ? Floppy.CRC_RESET_A1_A1_A1 : Floppy.CRC_RESET, dam);
                    for (int i = 0; i < dataLength; i++)
                    {
                        sectorData[i] = data[dataStart + i * byteMultiple];
                        actualCrc     = Lib.Crc(actualCrc, sectorData[i]);
                    }
                    ushort recordedCrc = Lib.CombineBytes(data[dataStart + (dataLength + 1) * byteMultiple], data[dataStart + dataLength * byteMultiple]);
                    crcError = actualCrc != recordedCrc;
                }
                sds.Add(new SectorDescriptor(trackNum,
                                             sectorNum,
                                             sideOne,
                                             density,
                                             dam,
                                             sectorData,
                                             inUse,
                                             crcError));
            }
            return(sds.OrderBy(s => s.SectorNumber).ToList());
        }