/// <summary>
 /// eject the loaded disk
 /// </summary>
 public void Eject()
 {
     disk  = null;
     state = RamAdapterState.IDLE;
     SetCycles();
     //Console.WriteLine("FDS: Disk ejected");
     DriveLightCallback?.Invoke(false);
 }
        /// <summary>
        /// clock at ~5.37mhz
        /// </summary>
        public void Clock()
        {
            cycleswaiting--;
            if (cycleswaiting == 0)
            {
                switch (state)
                {
                case RamAdapterState.RUNNING:
                    if (transferreset)                             // run head to end of disk
                    {
                        MoveDummy();
                    }
                    else if ((cached4025 & 4) != 0)                             // read mode
                    {
                        Read();
                    }
                    else
                    {
                        Write();
                    }
                    if (diskpos >= disksize)
                    {
                        //Console.WriteLine("FDS: End of Disk");
                        state = RamAdapterState.RESET;
                        //transferreset = false;
                        //numcrc = 0;
                        DriveLightCallback?.Invoke(false);
                    }
                    SetCycles();
                    break;

                case RamAdapterState.RESET:
                case RamAdapterState.INSERTING:
                    state   = RamAdapterState.IDLE;
                    diskpos = 0;
                    SetCycles();
                    //transferreset = false;
                    //numcrc = 0;
                    //Console.WriteLine("FDS: Return or Insert Complete");
                    DriveLightCallback?.Invoke(false);
                    break;

                case RamAdapterState.SPINUP:
                    state = RamAdapterState.RUNNING;
                    SetCycles();
                    //transferreset = false; // this definitely does not happen.
                    // Console.WriteLine("FDS: Spin up complete!  Disk is running");
                    DriveLightCallback?.Invoke(true);
                    break;

                case RamAdapterState.IDLE:
                    SetCycles();
                    break;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// eject the loaded disk
 /// </summary>
 public void Eject()
 {
     disk  = null;
     state = RamAdapterState.IDLE;
     SetCycles();
     Console.WriteLine("FDS: Disk ejected");
     if (DriveLightCallback != null)
     {
         DriveLightCallback(false);
     }
 }
        /// <summary>
        /// control reg
        /// </summary>
        public void Write4025(byte value)
        {
            if ((value & 1) != 0)                                  // start motor
            {
                if (state == RamAdapterState.IDLE && disk != null) // no spinup when no disk
                {
                    // this isn't right, despite the fact that without it some games seem to cycle the disk needlessly??
                    //if ((cached4025 & 1) != 0)
                    //	Console.WriteLine("FDS: Ignoring spurious spinup");
                    //else
                    //{
                    state = RamAdapterState.SPINUP;
                    SetCycles();
                    //}
                    DriveLightCallback?.Invoke(true);
                }
            }
            if ((value & 2) != 0)
            {
                transferreset = true;
            }
            else
            {
                transferreset = false;
            }

            if ((cached4025 & 0x40) == 0 && (value & 0x40) != 0)
            {
                lookingforendofgap = true;

                if ((value & 4) == 0)
                {
                    // write mode: reload and go
                    writeregpos      = 0;
                    writereg         = writereglatch;
                    bytetransferflag = true;
                    // irq?
                    // Console.WriteLine("FDS: Startwrite @{0} Reload {1:x2}", diskpos, writereglatch);
                    crc             = 0;
                    writecomputecrc = true;
                }
            }


            irq = false;             // ??

            cached4025 = value;
            //if ((cached4025 & 4) == 0)
            //	if ((cached4025 & 0x10) != 0)
            //		Console.WriteLine("FDS: Starting CRC");
        }
 /// <summary>
 /// insert a new disk.  might have to eject first???
 /// </summary>
 /// <param name="side">least significant bits appear first on physical disk</param>
 /// <param name="bitlength">length of disk in bits</param>
 /// <param name="writeprotect">disk is write protected</param>
 public void Insert(byte[] side, int bitlength, bool writeprotect)
 {
     if (side.Length * 8 < bitlength)
     {
         throw new ArgumentException("Disk too small for parameter!");
     }
     disk              = side;
     disksize          = bitlength;
     diskpos           = 0;
     this.writeprotect = writeprotect;
     state             = RamAdapterState.INSERTING;
     SetCycles();
     //Console.WriteLine("FDS: Disk Inserted");
     originaldisk = (byte[])disk.Clone();
     DriveLightCallback?.Invoke(false);
 }
Beispiel #6
0
		/// <summary>
		/// clock at ~5.37mhz
		/// </summary>
		public void Clock()
		{
			cycleswaiting--;
			if (cycleswaiting == 0)
			{
				switch (state)
				{
					case RamAdapterState.RUNNING:
						if (transferreset) // run head to end of disk
							MoveDummy();
						else if ((cached4025 & 4) != 0) // read mode
							Read();
						else
							Write();
						if (diskpos >= disksize)
						{
							// Console.WriteLine("FDS: End of Disk");
							state = RamAdapterState.RESET;
							transferreset = false;
							//numcrc = 0;
							if (DriveLightCallback != null)
								DriveLightCallback(false);
						}
						SetCycles();
						break;

					case RamAdapterState.RESET:
					case RamAdapterState.INSERTING:
						state = RamAdapterState.IDLE;
						diskpos = 0;
						SetCycles();
						transferreset = false;
						//numcrc = 0;
						// Console.WriteLine("FDS: Return or Insert Complete");
						if (DriveLightCallback != null)
							DriveLightCallback(false);
						break;
					case RamAdapterState.SPINUP:
						state = RamAdapterState.RUNNING;
						SetCycles();
						//transferreset = false; // this definitely does not happen.
						// Console.WriteLine("FDS: Spin up complete!  Disk is running");
						if (DriveLightCallback != null)
							DriveLightCallback(true);
						break;

					case RamAdapterState.IDLE:
						SetCycles();
						break;
				}
			}
		}
Beispiel #7
0
		/// <summary>
		/// control reg
		/// </summary>
		/// <param name="value"></param>
		public void Write4025(byte value)
		{
			if ((value & 1) != 0) // start motor
			{
				if (state == RamAdapterState.IDLE && disk != null) // no spinup when no disk
				{
					// this isn't right, despite the fact that without it some games seem to cycle the disk needlessly??
					//if ((cached4025 & 1) != 0)
					//	Console.WriteLine("FDS: Ignoring spurious spinup");
					//else
					//{
						state = RamAdapterState.SPINUP;
						SetCycles();
					//}
						if (DriveLightCallback != null)
							DriveLightCallback(true);
				}
			}
			if ((value & 2) != 0)
				transferreset = true;
			if ((cached4025 & 0x40) == 0 && (value & 0x40) != 0)
			{
				lookingforendofgap = true;

				if ((value & 4) == 0)
				{
					// write mode: reload and go
					writeregpos = 0;
					writereg = writereglatch;
					bytetransferflag = true;
					// irq?
					// Console.WriteLine("FDS: Startwrite @{0} Reload {1:x2}", diskpos, writereglatch);
					crc = 0;
					writecomputecrc = true;
				}
			}


			irq = false; // ??

			cached4025 = value;
			//if ((cached4025 & 4) == 0)
			//	if ((cached4025 & 0x10) != 0)
			//		Console.WriteLine("FDS: Starting CRC");
		}
Beispiel #8
0
		/// <summary>
		/// insert a new disk.  might have to eject first???
		/// </summary>
		/// <param name="side">least significant bits appear first on physical disk</param>
		/// <param name="bitlength">length of disk in bits</param>
		/// <param name="writeprotect">disk is write protected</param>
		public void Insert(byte[] side, int bitlength, bool writeprotect)
		{
			if (side.Length * 8 < bitlength)
				throw new ArgumentException("Disk too small for parameter!");
			disk = side;
			disksize = bitlength;
			diskpos = 0;
			this.writeprotect = writeprotect;
			state = RamAdapterState.INSERTING;
			SetCycles();
			Console.WriteLine("FDS: Disk Inserted");
			originaldisk = (byte[])disk.Clone();
			if (DriveLightCallback != null)
				DriveLightCallback(false);
		}
Beispiel #9
0
		/// <summary>
		/// eject the loaded disk
		/// </summary>
		public void Eject()
		{
			disk = null;
			state = RamAdapterState.IDLE;
			SetCycles();
			Console.WriteLine("FDS: Disk ejected");
			if (DriveLightCallback != null)
				DriveLightCallback(false);
		}