Example #1
0
        public CBM1541(C64Interfaces.IFile kernel, IO.SerialPort serial)
        {
            _driveCpu = new CPU.MOS6502(_memory, 0);
            _driveClock.OpFactory = _driveCpu.OpFactory;

            _driveVias = new VIA[2]
            {
                new VIA((ushort)Map.Via1RegistersAddress, (ushort)Map.Via1RegistersSize, _driveCpu.IRQ),
                new VIA((ushort)Map.Via2RegistersAddress, (ushort)Map.Via2RegistersSize, _driveCpu.IRQ)
            };

            _drive = new DiskDrive.Drive(_driveVias[1]);
            _drive.OnDataReady += new DiskDrive.Drive.DateReadyDelegate(drive_OnDataReady);

            _ram = new Memory.RAM((ushort)Map.RamAddress, (ushort)Map.RamSize);
            _rom = new Memory.ROM((ushort)Map.RomAddress, (ushort)Map.RomSize, kernel);

            _rom.Patch(IDLE_TRAP_ADDRES, IDLE_TRAP_OPCODE);
            for (int i = 0; i < PATCH_MAP.Length; i++)
                _rom.Patch(PATCH_MAP[i], NOP_OPCODE);

            _memory.Map(_ram, true);
            _memory.Map(_driveVias[0], true);
            _memory.Map(_driveVias[1], true);
            _memory.Map(_rom, Memory.MemoryMapEntry.AccessType.Read, true);

            _serial = serial;

            _sAtnaConn = new IO.SerialPort.BusLineConnection(_serial.DataLine);
            _sDataConn = new IO.SerialPort.BusLineConnection(_serial.DataLine);
            _sClockConn = new IO.SerialPort.BusLineConnection(_serial.ClockLine);

            _serial.OnAtnLineChanged += new IO.SerialPort.LineChangedDelegate(serial_OnAtnLineChanged);
            _serial.ClockLine.OnLineChanged += new IO.SerialPort.LineChangedDelegate(ClockLine_OnLineChanged);
            _serial.DataLine.OnLineChanged += new IO.SerialPort.LineChangedDelegate(DataLine_OnLineChanged);

            _driveVias[0].PortB.OnPortOut += new IO.IOPort.PortOutDelegate(PortB_OnPortOut);

            _driveCpu.Restart(_driveClock, 0);
            _driveClock.QueueOpsStart(_driveVias[0].CreateOps(), 1);
            _driveClock.QueueOpsStart(_driveVias[1].CreateOps(), 2);
            _driveClock.QueueOpsStart(_drive.CreateOps(), 3);
        }
Example #2
0
        public GCRImage(C64Interfaces.IFile diskImage)
        {
            ushort id = 0;

            byte[] sector = new byte[RAW_SECT_LEN];
            int offset = 0;

            _tracks = new byte[TRACK_COUNT][];
            for (byte i = 0; i < TRACK_COUNT; i++)
            {
                byte track = (byte)(i >> 1);
                _tracks[i] = new byte[SPT[track] * GCR_SECTOR_LEN];

                if ((i & 1) == 0)
                {
                    if ((ulong)offset < diskImage.Size)
                    {
                        ushort start = 0;
                        for (byte j = 0; j < SPT[track]; j++)
                        {
                            diskImage.Read(sector, offset, RAW_SECT_LEN);
                            ConvertSectorToGCR(sector, _tracks[i], ref start, j, (byte)(track + 1), id);

                            offset += RAW_SECT_LEN;
                        }
                    }
                }
                else
                {
                    ushort start = 0;

                    for (byte j = 0; j < SPT[track]; j++)
                        ConvertSectorToGCR(sector, _tracks[i], ref start, j, (byte)(track + 1), id);
                }
            }
        }
Example #3
0
 public void ReadDeviceState(C64Interfaces.IFile stateFile)
 {
     _atnLine = stateFile.ReadBool();
     _dataLine.ReadDeviceState(stateFile);
     _clockLine.ReadDeviceState(stateFile);
 }
Example #4
0
 public void ReadDeviceState(C64Interfaces.IFile stateFile)
 {
     _localState = stateFile.ReadBool();
 }
Example #5
0
 public void WriteDeviceState(C64Interfaces.IFile stateFile)
 {
     stateFile.Write(_stateOut);
     stateFile.Write(_stateIn);
     stateFile.Write(_direction);
 }
Example #6
0
 public void WriteToStateFile(C64Interfaces.IFile stateFile)
 {
     stateFile.Write((byte)0);
 }
Example #7
0
 public ClockEntryRep(C64Interfaces.IFile stateFile, ClockOpFactory factory)
     : base(stateFile, factory)
 {
     _length = stateFile.ReadByte();
     _cycle = stateFile.ReadByte();
 }
Example #8
0
 public ClockEntry(C64Interfaces.IFile stateFile, ClockOpFactory factory)
 {
     _op = factory.CreateFromStateFile(stateFile);
     _comboNext = stateFile.ReadBool();
 }
Example #9
0
 public void WriteToStateFile(C64Interfaces.IFile stateFile)
 {
     stateFile.Write((byte)MOS6502_OpFactory.Ops.DecodeAddressing);
 }
Example #10
0
 public void WriteToStateFile(C64Interfaces.IFile stateFile)
 {
     stateFile.Write((byte)MOS6502_OpFactory.Ops.WriteResult);
 }
Example #11
0
 public void WriteToStateFile(C64Interfaces.IFile stateFile)
 {
     stateFile.Write((byte)MOS6502_OpFactory.Ops.Reset);
     stateFile.Write(_readBuffer);
 }
Example #12
0
 public ResetOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu)
 {
     _readBuffer = stateFile.ReadByte();
 }
Example #13
0
 public DecodeAddressOp(MOS6502 cpu, C64Interfaces.IFile stateFile)
     : this(cpu, (AddressingMode)null)
 {
     _addressing = DecodingTable.Opcodes[cpu.Opcode]._addressing;
 }
Example #14
0
        public Clock.ClockOp CreateFromStateFile(C64Interfaces.IFile stateFile)
        {
            switch (stateFile.ReadByte())
            {
                case (byte)Ops.Stall:
                    return new Clock.StallOp();

                case (byte)Ops.DecodeOpcode:
                    return new DecodeOpcodeOp(_cpu);

                case (byte)Ops.DecodeAddressing:
                    return new DecodeAddressOp(_cpu, stateFile);

                case (byte)Ops.ExecuteOpcode:
                    return new ExecuteOpcodeOp(_cpu, stateFile);

                case (byte)Ops.WriteResult:
                    return new WriteResultOp(_cpu);

                case (byte)Ops.Interrupt:
                    return new InterruptOp(_cpu, stateFile);

                case (byte)Ops.Reset:
                    return new ResetOp(_cpu, stateFile);
            }

            return null;
        }
Example #15
0
        public virtual void WriteDeviceState(C64Interfaces.IFile stateFile)
        {
            stateFile.Write(_state.A.Value);
            stateFile.Write(_state.X.Value);
            stateFile.Write(_state.Y.Value);
            stateFile.Write(_state.PC.Value);
            stateFile.Write(_state.S.Value);
            stateFile.Write(_state.P.Value);

            stateFile.Write(_opcode);
            stateFile.Write(_result);

            _target.WriteToStateFile(stateFile);

            _irq.WriteDeviceState(stateFile);
            _nmi.WriteDeviceState(stateFile);
        }
Example #16
0
        protected void ReadPhaseFromDeviceState(C64Interfaces.IFile stateFile, byte phase)
        {
            ClockEntry previousOp = null;
            byte opCount = stateFile.ReadByte();
            for (byte i = 0; i < opCount; i++)
            {
                ClockEntry op = stateFile.ReadByte() == 0 ? new ClockEntry(stateFile, _opFactory) : new ClockEntryRep(stateFile, _opFactory);

                if (previousOp == null)
                    _currentOps[phase] = op;
                else
                    previousOp.Next = op;

                previousOp = op;
            }
        }
Example #17
0
        protected void WritePhaseToDeviceState(C64Interfaces.IFile stateFile, byte phase)
        {
            byte opCount = 0;
            for (ClockEntry op = _currentOps[phase]; op != null; op = op.Next)
                opCount++;

            stateFile.Write(opCount);

            for (ClockEntry op = _currentOps[phase]; op != null; op = op.Next)
                op.WriteToStateFile(stateFile);
        }
Example #18
0
        public void ReadDeviceState(C64Interfaces.IFile stateFile)
        {
            _systemRam.ReadDeviceState(stateFile);
            _systemCpu.ReadDeviceState(stateFile);
            _systemVic.ReadDeviceState(stateFile);
            _systemCias[0].ReadDeviceState(stateFile);
            _systemCias[1].ReadDeviceState(stateFile);
            _serial.ReadDeviceState(stateFile);
            _sDataConn.ReadDeviceState(stateFile);
            _sClockConn.ReadDeviceState(stateFile);

            CpuPort_OnMemoryMapChanged(stateFile.ReadByte());

            _systemClock.ReadDeviceState(stateFile);
        }
Example #19
0
        public virtual void WriteToStateFile(C64Interfaces.IFile stateFile)
        {
            stateFile.Write((byte)0);

            _op.WriteToStateFile(stateFile);
            stateFile.Write(_comboNext);
        }
Example #20
0
        public void SaveState(C64Interfaces.IFile stateFile)
        {
            lock (_systemClock)
            {
                if (_currentStateFile != null)
                    throw new System.InvalidOperationException();

                _currentStateFile = stateFile;
                _pendingStateOperation = PendingStateOperations.Save;
            }
        }
Example #21
0
        public override void WriteToStateFile(C64Interfaces.IFile stateFile)
        {
            stateFile.Write((byte)1);

            _op.WriteToStateFile(stateFile);

            stateFile.Write(_comboNext);
            stateFile.Write(_length);
            stateFile.Write(_cycle);
        }
Example #22
0
        public void WriteDeviceState(C64Interfaces.IFile stateFile)
        {
            _systemRam.WriteDeviceState(stateFile);
            _systemCpu.WriteDeviceState(stateFile);
            _systemVic.WriteDeviceState(stateFile);
            _systemCias[0].WriteDeviceState(stateFile);
            _systemCias[1].WriteDeviceState(stateFile);
            _serial.WriteDeviceState(stateFile);
            _sDataConn.WriteDeviceState(stateFile);
            _sClockConn.WriteDeviceState(stateFile);

            stateFile.Write(_currentMap);

            _systemClock.WriteDeviceState(stateFile);
        }
Example #23
0
 public void ReadDeviceState(C64Interfaces.IFile stateFile)
 {
     _stateOut = stateFile.ReadByte();
     _stateIn = stateFile.ReadByte();
     _direction = stateFile.ReadByte();
 }
Example #24
0
 public override void ReadDeviceState(C64Interfaces.IFile stateFile)
 {
     ReadPhaseFromDeviceState(stateFile, 1);
 }
Example #25
0
 public void ReadDeviceState(C64Interfaces.IFile stateFile)
 {
     _state = stateFile.ReadByte();
 }
Example #26
0
 public override void WriteDeviceState(C64Interfaces.IFile stateFile)
 {
     WritePhaseToDeviceState(stateFile, 1);
 }
Example #27
0
 public void WriteDeviceState(C64Interfaces.IFile stateFile)
 {
     stateFile.Write(_localState);
 }
Example #28
0
        public Board(C64Interfaces.IVideoOutput video, C64Interfaces.IFile kernel, C64Interfaces.IFile basic, C64Interfaces.IFile charGen)
        {
            _systemCpu = new CPU.MOS6510((ushort)Map.CpuIOAddress, (ushort)Map.CpuIOSize, _memoryMaps[_currentMap], 1);
            _systemClock.OpFactory = _systemCpu.OpFactory;

            _systemCpu.Port.IOPort.OnPortOut += new IO.IOPort.PortOutDelegate(CpuPort_OnMemoryMapChanged);

            _systemCias = new IO.CIA[]
            {
                new IO.CIA((ushort)Map.Cia1RegistersAddress, (ushort)Map.Cia1RegistersSize, _systemCpu.IRQ, 0x00, 0x00),
                new IO.CIA((ushort)Map.Cia2RegistersAddress, (ushort)Map.Cia2RegistersSize, _systemCpu.IRQ, 0x3f, 0x06)
            };

            _systemVic = new Video.VIC((ushort)Map.VicRegistersAddress, (ushort)Map.VicRegistersSize, (ushort)Map.ColorRamAddress, (ushort)Map.ColorRamSize,
                _systemCpu.IRQ, video);

            _systemSid = new Audio.SID((ushort)Map.SidRegistersAddress, (ushort)Map.SidRegistersSize);

            _systemCias[1].PortA.OnPortOut += new IO.IOPort.PortOutDelegate(Cia1_PortA_OnPortOut);

            _serial = new IO.SerialPort();
            _sDataConn = new IO.SerialPort.BusLineConnection(_serial.DataLine);
            _sClockConn = new IO.SerialPort.BusLineConnection(_serial.ClockLine);

            _serial.ClockLine.OnLineChanged += new IO.SerialPort.LineChangedDelegate(ClockLine_OnLineChanged);
            _serial.DataLine.OnLineChanged += new IO.SerialPort.LineChangedDelegate(DataLine_OnLineChanged);

            _systemRam = new Memory.RAM(0, 0x10000);

            _kernelRom = new Memory.ROM((ushort)Map.KernelRomAddress, (ushort)Map.KernelRomSize, kernel);
            _basicRom = new Memory.ROM((ushort)Map.BasicRomAddress, (ushort)Map.BasicRomSize, basic);
            _charRom = new Memory.ROM((ushort)Map.CharRomAddress, (ushort)Map.CharRomSize, charGen);

            _charRomVic1 = new Memory.ROM((ushort)Map.CharRomAddress_Vic1, (ushort)Map.CharRomSize, charGen);
            _charRomVic2 = new Memory.ROM((ushort)Map.CharRomAddress_Vic2, (ushort)Map.CharRomSize, charGen);

            for (int i = 0; i < _memoryMaps.Length; i++)
            {
                _memoryMaps[i].Map(_systemRam, true);
                _memoryMaps[i].Map(_systemCpu.Port, true);

                if ((i & 2) != 0)
                {
                    _memoryMaps[i].Map(_kernelRom, Memory.MemoryMapEntry.AccessType.Read, true);

                    if ((i & 1) != 0)
                        _memoryMaps[i].Map(_basicRom, Memory.MemoryMapEntry.AccessType.Read, true);
                }

                if ((i & 3) != 0)
                {
                    if ((i & 4) != 0)
                    {
                        _memoryMaps[i].Map(_systemVic, true);
                        _memoryMaps[i].Map(_systemSid, true);
                        _memoryMaps[i].Map(_systemVic.ColorRam, true);
                        _memoryMaps[i].Map(_systemCias[0], true);
                        _memoryMaps[i].Map(_systemCias[1], true);
                    }
                    else
                        _memoryMaps[i].Map(_charRom, Memory.MemoryMapEntry.AccessType.Read, true);
                }
            }

            _systemVic.Memory.Map(_systemRam, true);
            _systemVic.Memory.Map(_charRomVic1, Memory.MemoryMapEntry.AccessType.Read, true);
            _systemVic.Memory.Map(_charRomVic2, Memory.MemoryMapEntry.AccessType.Read, true);

            _systemClock.QueueOpsStart(_systemVic.RasterLine.CreateOps(), 0);
            _systemCpu.Restart(_systemClock, 1);
            _systemClock.QueueOpsStart(_systemCias[0].CreateOps(), 2);
            _systemClock.QueueOpsStart(_systemCias[1].CreateOps(), 3);

            _systemClock.OnTimeSlice += new Clock.Clock.PhaseEndDelegate(_systemCias[0].IncrementTod);
            _systemClock.OnTimeSlice += new Clock.Clock.PhaseEndDelegate(_systemCias[1].IncrementTod);

            _systemClock.OnTimeSlice += new Clock.Clock.PhaseEndDelegate(_checkPendingStateOperations_OnTimeSlice);
        }
Example #29
0
 public void WriteDeviceState(C64Interfaces.IFile stateFile)
 {
     stateFile.Write(_atnLine);
     _dataLine.WriteDeviceState(stateFile);
     _clockLine.WriteDeviceState(stateFile);
 }
Example #30
0
 public abstract void WriteDeviceState(C64Interfaces.IFile stateFile);