public static void SendLiterals(ref ProgramCode asmcode)
        {
            if(asmcode.literals.Length>0)
            {
                string literals = String.Join("\x00",asmcode.literals);

                byte[] packet = new byte[5+System.Text.ASCIIEncoding.ASCII.GetByteCount(literals)];
                packet[4] = (byte)RemoteProtocolMsgs.LITERALS;

                Buffer.BlockCopy(System.Text.ASCIIEncoding.ASCII.GetBytes(literals)
                    ,0,packet,5,System.Text.ASCIIEncoding.ASCII.GetByteCount(literals));
                Buffer.BlockCopy(BitConverter.GetBytes(packet.Length-4),0,packet,0,4);

                foreach(RemoteProcessor tmprp in FreeProcessors)
                    tmprp.SendPacket(packet);
            }
        }
Ejemplo n.º 2
0
        private ProgramCode LoadFile(string filename)
        {
            BinaryReader reader = new BinaryReader(new FileStream(filename,FileMode.Open,FileAccess.Read));

            ushort filecode = reader.ReadUInt16();

            if(filecode==1508)
            {
                ProgramCode asmcode = new ProgramCode();
                asmcode.memory = new double[reader.ReadInt32(),2];

                int nmlen = reader.ReadInt32();
                asmcode.numconstants = new double[nmlen/8];
                Buffer.BlockCopy(reader.ReadBytes(nmlen),0,asmcode.numconstants,0,nmlen);

                nmlen = reader.ReadInt32();

                string literal = System.Text.ASCIIEncoding.ASCII.GetString(reader.ReadBytes(nmlen));

                asmcode.literals = literal.Split(new char[]{'\x00'});

                nmlen = reader.ReadInt32();
                asmcode.instructions = new ushort[nmlen/2];
                Buffer.BlockCopy(reader.ReadBytes(nmlen),0,asmcode.instructions,0,nmlen);

                reader.Close();
                return asmcode;

            }
            else
                throw new Exception("It is not a valid File.");
        }
        public static void SendNumConstants(ref ProgramCode asmcode)
        {
            byte[] packet = new byte[9+Buffer.ByteLength(asmcode.numconstants)];
            Buffer.BlockCopy(BitConverter.GetBytes(asmcode.matrixmemory.Length),0,packet,
                                5,4);
            packet[4] = (byte)RemoteProtocolMsgs.NUMCOS;
            Buffer.BlockCopy(asmcode.numconstants,0,packet,9,Buffer.ByteLength(asmcode.numconstants));
            Buffer.BlockCopy(BitConverter.GetBytes(packet.Length-4),0,packet,0,4);

            foreach(RemoteProcessor tmprp in FreeProcessors)
                tmprp.SendPacket(packet);
        }