Ejemplo n.º 1
0
        public void BytesShouldBeSame()
        {
            string      sourceFile = "../../../../Brents6502/Resources/snake.asm";
            SourceCode  code       = new SourceCode();
            List <byte> byteCode   = code.ProcessCode(sourceFile);

            string n   = Path.GetFileName(sourceFile);
            string p   = Path.GetFullPath(sourceFile);
            string cmp = File.ReadAllText(p.Remove(p.Length - n.Length) + "snake-hex.txt");

            string[]    cmpHex      = cmp.Split(' ');
            List <byte> cmpByteCode = new List <byte>();

            foreach (string h in cmpHex)
            {
                cmpByteCode.Add(Convert.ToByte(h, 16));
            }
            for (int i = 0; i < byteCode.Count; i++)
            {
                Assert.AreEqual(cmpByteCode[i], byteCode[i]);
            }
            Assert.AreEqual(cmpByteCode.Count, byteCode.Count);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            string sourceFile = args[0];

            try
            {
                SourceCode  code     = new SourceCode();
                List <byte> byteCode = code.ProcessCode(sourceFile);

                string outFileName  = Path.GetFileName(sourceFile);
                int    extensionPos = outFileName.LastIndexOf('.');
                if (extensionPos >= 0)
                {
                    outFileName = outFileName.Substring(0, extensionPos);
                }
                outFileName = outFileName + ".prg";
                File.WriteAllBytes(outFileName, byteCode.ToArray());
                Console.WriteLine($"Successfully created program file at {outFileName}, program code is {byteCode.Count} bytes");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"There was an error assembling your program: {ex.Message}");
            }
        }