Exemplo n.º 1
0
        /// <summary>
        /// Reads the Cartridge ROM
        /// </summary>
        /// <param name="startAddress">The start address</param>
        /// <param name="length">The length to read</param>
        /// <returns></returns>
        private static byte[] RomRead(uint startAddress, int length)
        {
            CommandPacketTransmit(TransmitCommand.RomRead, startAddress, length, 0);

            UsbInterface.ProgressBarTimerInterval = length > MAX_ROM_SIZE / 2 ? 0x100000 : 0x80000;
            var time = DateTime.Now.Ticks;
            var data = UsbInterface.Read(length);

            time = DateTime.Now.Ticks - time;
            Console.WriteLine($"OK. speed: {GetSpeedString(data.Length, time)}"); //TODO: this should be in the main program! or at least return the time!
            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receives a command response from the USB port
        /// </summary>
        /// <returns>the full response in bytes</returns>
        private static byte[] CommandPacketReceive()
        {
            var cmd = UsbInterface.Read(16);

            if (Encoding.ASCII.GetString(cmd).ToLower().StartsWith("cmd") || Encoding.ASCII.GetString(cmd).ToLower().StartsWith("RSP"))
            {
                switch ((ReceiveCommand)cmd[3])
                {
                case ReceiveCommand.CommsReply:
                    return(cmd);

                case ReceiveCommand.CommsReplyLegacy:     //Certain ROM's may reply that used the old OSes without case sensitivity on the test commnad, this ensures they are handled.
                    throw new Exception($"Outdated OS, please update to {MINIMUM_OS_VERSION} or above!");

                default:
                    throw new Exception("Unexpected response received from USB port.");
                }
            }
            else
            {
                throw new Exception("Corrupted response received from USB port.");
            }
        }