Exemplo n.º 1
0
        /**
         * Writes one memory bank.
         */
        public static void WriteBank()
        {
            // Get size
            int bankSize = CSpectSocket.GetRemainingDataCount() - 1;

            if (bankSize != 0x2000)
            {
                // Only supported is 0x2000
                string errorString = "Bank size incorrect!";
                int    length      = 1 + errorString.Length + 1;
                InitData(length);
                SetByte(1);   // Error
                SetString(errorString);
                CSpectSocket.SendResponse(Data);
            }

            // Get bank number
            byte bankNumber = CSpectSocket.GetDataByte();
            // Calculate physical address
            // Example: phys. address $1f021 = ($1f021&$1fff) for offset and ($1f021>>13) for bank.
            Int32 physAddress = bankNumber * bankSize;
            // Write memory
            var cspect = Main.CSpect;

            if (Log.Enabled)
            {
                Log.WriteLine("WriteBank: bank={0}", bankNumber);
            }
            for (int i = bankSize; i > 0; i--)
            {
                byte value = CSpectSocket.GetDataByte();
                cspect.PokePhysical(physAddress++, new byte[] { value });
            }

            // Respond
            InitData(2);
            SetByte(0);   // No error
            SetByte(0);
            CSpectSocket.SendResponse(Data);
        }