Exemple #1
0
    /// <summary>
    /// Grabs a 32 bit hex value from standard input
    /// </summary>
    public static UInt32 ParseHexa(CommandMode inCommand, string inString)
    {
        string iLower = inString.ToLowerInvariant();

        iLower = iLower.Replace(inCommand.command().ToLowerInvariant(), "");

        #if DebugArgs
        Console.WriteLine("Parsing hexa " + inString);
        #endif

        // Whatever's left should be the address
        UInt32 outAddr = (UInt32)Convert.ToInt32(iLower, 16);

        Console.Write(" - Parsed hexa: 0x" + outAddr.ToString("X8") + "\n");

        return(outAddr);
    }
    /// <summary>
    /// Ensure the input args are vaguely sane
    /// - Make a list of args
    /// - Cross them off one by one as they're valid
    /// - Determine COM port
    /// - Extra args such as /monitor comms
    /// - Grab address values, filename etc
    /// </summary>
    /// <param name="inArgs">Command line args</param>
    /// <returns>Are there any unprocessed args?</returns>

    static bool VerifyArgs(string[] inArgs)
    {
        if (inArgs.Length == 0)
        {
            PrintUsage(false);
            return(false);
        }

        // Thank you, linq <3
        // We'll remove args as they're processed so they're not processed twice
        // and extra args will be left over.
        // ( we don't want extra args left over )

        List <string> remainingArgs = inArgs.ToList();

        // Specified a com port?

                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
                #endif

        // Remove the arg for the com port: COM* or /dev/tty*
        for (int i = remainingArgs.Count - 1; i >= 0; i--)
        {
            string s = remainingArgs[i];

            if (ValidPort(s))
            {
                argComPort = s;
                remainingArgs.RemoveAt(i);
                break;
            }
        }

        // Cache the com port, or load the cached value
        if (string.IsNullOrEmpty(argComPort))
        {
            try{
                if (System.IO.File.Exists("comport.txt"))
                {
                    argComPort = File.ReadAllText("comport.txt");
                }
            } catch (System.Exception e) {
                Console.Write("Error checking for cached com port...\n" + e);
            }

            if (argComPort == "")
            {
                if (!ValidPort(argComPort))
                {
                    // I think the GC can manage the hit on this one :)
                    return(Error("\nERROR! Please specify a device or COM port in the format: " + SampleCOMPortForEnvironment + "\ngot: " + argCommand));
                }
            }
            else
            {
                usingCachedComPort = true;
            }
        }
        else
        {
            // port was specified, cache it for alter
            try{
                File.WriteAllText("comport.txt", argComPort);
            } catch (System.Exception e) {
                Console.Write("Error writing cached com port!\n" + e);
            }
        }


        // Are we using secondary args only? e.g. /fast /m
        // in this case, there's no point processing the rest of the input
        allArgsAreSecondary = true;
        for (int i = remainingArgs.Count - 1; i >= 0; i--)
        {
            string lower = remainingArgs[i].ToLowerInvariant();
            if (lower == "/m")
            {
                monitorComms = true;
                remainingArgs.RemoveAt(i);
            }
            else if (lower == "/fast")
            {
                enterFastMode = true;
                remainingArgs.RemoveAt(i);
            }
            else if (lower == "/slow")
            {
                enterSlowMode = true;
                remainingArgs.RemoveAt(i);
            }
            else
            {
                allArgsAreSecondary = false;
            }
        }


#if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__COM: " + argComPort);
        Console.WriteLine("__DEBUG__FAST: " + enterFastMode);
        Console.WriteLine("__DEBUG__FAST: " + enterSlowMode);
#endif

        // Not really transferring anything, let's go
        if (allArgsAreSecondary)
        {
            return(true);
        }

        // Outer loop: Does anything resemble an command? /dump, /poke, etc?
        // Specified a command arg (or several for future-proofing)?
        for (int paramIndex = remainingArgs.Count - 1; paramIndex >= 0; paramIndex--)
        {
            string param = remainingArgs[paramIndex].ToLowerInvariant();

            // Inner loop: does it match any known commands?
            // If so, check for sub params
            // E.g. /dump <addr> <size>
            // first one is uninitialised... ignore it
            for (int argIndex = 1; argIndex < (int)CommandMode.COUNT; argIndex++)
            {
                CommandMode c = (CommandMode)argIndex;

                if (param.ToLowerInvariant() == c.command())
                {
                    // Set the current value and remove
                    // it from the list of available args
                    argCommand = c;
                    remainingArgs.RemoveAt(paramIndex);

                    // Now we've removed the /command, if there's
                    // an address after it, it will be remaningArgs[ arg ]

                    // Does the command require an address value?
                    if (argCommand.hasAttribute <NeedsAddressAttribute>())
                    {
                        // end of the array!
                        if (paramIndex >= remainingArgs.Count)
                        {
                            return(Error("Specify an address in the format 0x01234567\n"));
                        }

                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires an address ");
                                                #endif

                        // reassign it
                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        // try and get the address argument
                        try{
                            argAddr = ParseHexa(argCommand, param);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify an address in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedAddressRequirements = true;
                    }

                    // Do we need a register?
                    if (argCommand.hasAttribute <NeedsRegisterAttribute>())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a register ");
                                                #endif

                        // reassign it
                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        // TODO: verify register validity?
                        // TODO: settle on a format: R4 vs V0 vs $V0, etc
                        argRegister = param;

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedRegisterRequirements = true;
                    }

                    // On top of that... do we need a size? E.g. for dumping bios.
                    if (argCommand.hasAttribute <NeedsSizeAttribute>())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a size parameter ");
                                                #endif

                        // reassign it
                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        // try to get the size argument
                        try{
                            argSize = ParseHexa(argCommand, param);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify a size in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedSizeRequirements = true;
                    }

                    // Do we need a value? 1 - 4 bytes
                    if (argCommand.hasAttribute <NeedsValueAttribute>())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a value parameter ");
                                                #endif

                        // reassign it
                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        // try to get the size argument
                        try{
                            argValue = ParseHexa(argCommand, param);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify a 1, 2 or 4 byte hex value"));
                        }

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedValueRequirements = true;
                    }

                    if (argCommand.hasAttribute <NeedsIPAttribute>())
                    {
                        #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires an IP/host parameter!");
                        #endif

                        //param = remainingArgs[paramIndex].ToLowerInvariant();
                        argIP = param;
                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedIPRequirements = true;
                    }

                    if (argCommand.hasAttribute <NeedsPortAttribute>())
                    {
                        #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a local/remote port!");
                        #endif

                        if (remainingArgs.Count == 0)
                        {
                            return(Error("Need to specify a local TCP/IP port!"));
                        }

                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        if (!UInt32.TryParse(param, out argPort))
                        {
                            return(Error("EXCEPTION: Couldn't parse a valid port number from \"" + param + "\""));
                        }

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedPortRequirements = true;
                    }

                    // Do we need a memcard number
                    if (argCommand.hasAttribute <NeedsCardNumberAttribute>())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a memcard parameter ");
                                                #endif

                        // reassign it
                        param = remainingArgs[paramIndex].ToLowerInvariant();

                        argCard = UInt32.Parse(param);

                        /*
                         * // Working on something interesting here... hold tight.
                         * if ( _arg != "0" && _arg != "1" ){
                         *      return Error( "EXCEPTION: memory card should be 0 or 1!" );
                         * } else {
                         *      argCard = UInt32.Parse( _arg );
                         * }
                         */

                        remainingArgs.RemoveAt(paramIndex);
                        satisfiedCardRequirement = true;
                    }

                    break; // outer loop to check new args
                }
            }              // inner loop
        }                  // outer loop

                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__COM: " + argComPort);
        Console.WriteLine("__DEBUG__COMMAND: " + argCommand);
        Console.WriteLine("__DEBUG__ADDR: " + argAddr.ToString("X8"));
        Console.WriteLine("__DEBUG__VALUE: " + argValue.ToString("X8"));
                #endif

        if (argCommand == CommandMode.NOT_SET)
        {
            return(Error("Please specify a command - e.g. /r, /e /b, etc!\n\n"));
        }


        // Do we need to load an .exe, .rom, data etc?
        if (argCommand.hasAttribute <NeedsInputFileAttribute>())
        {
            // One of the args specifies a file?
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                string fName = remainingArgs[i];
                argFileName = fName;

                try{
                    inFile = File.ReadAllBytes(fName);
                } catch (System.Exception e) {
                    return(Error("Couldn't open input file " + fName + " Exception: " + e));
                }

                satisfiedInputFileRequirements = true;
                remainingArgs.RemoveAt(i);
            }
        }

        // Do we need to save somewhere?
        if (argCommand.hasAttribute <NeedsOutputFileAttribute>())
        {
            // One of the args specifies a file?
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                argFileName = remainingArgs[i];
                remainingArgs.RemoveAt(i);
                satisfiedOutputFileRequirements = true;
            }
        }

        // The /poke command for example doesn't require a filename
        // so that requirement is considered satisfied.
        if (!argCommand.hasAttribute <NeedsRegisterAttribute>())
        {
            satisfiedRegisterRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsAddressAttribute>())
        {
            satisfiedAddressRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsSizeAttribute>())
        {
            satisfiedSizeRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsValueAttribute>())
        {
            satisfiedValueRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsCardNumberAttribute>())
        {
            satisfiedCardRequirement = true;
        }
        if (!argCommand.hasAttribute <NeedsInputFileAttribute>())
        {
            satisfiedInputFileRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsOutputFileAttribute>())
        {
            satisfiedOutputFileRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsIPAttribute>())
        {
            satisfiedIPRequirements = true;
        }
        if (!argCommand.hasAttribute <NeedsPortAttribute>())
        {
            satisfiedPortRequirements = true;
        }

        // Missed something...
        if (!satisfiedAddressRequirements)
        {
            return(Error("Did you specify an address or hex value? E.g. 0x23456788\n"));
        }
        if (!satisfiedSizeRequirements)
        {
            return(Error("Did you specify a size? E.g. 0x23456788\n"));
        }
        if (!satisfiedRegisterRequirements)
        {
            return(Error("Did you specify a register? E.g. a0"));
        }
        if (!satisfiedValueRequirements)
        {
            return(Error("Specify a 1-4 byte value in the format 0x01"));
        }
        if (!satisfiedCardRequirement)
        {
            return(Error("Specify memory card 0 or 1!"));
        }
        if (!satisfiedInputFileRequirements)
        {
            return(Error("Specify an input file!"));
        }
        if (!satisfiedOutputFileRequirements)
        {
            return(Error("Specify a filename to write to!"));
        }
        if (!satisfiedIPRequirements)
        {
            return(Error("Specify a remote host/ip!"));
        }
        if (!satisfiedPortRequirements)
        {
            return(Error("Specify a local or remote port!"));
        }


                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__FILENAME: " + argFileName);
        Console.WriteLine("__DEBUG__INPUTFILE: " + inFile);
                #endif

        // there shouldn't be any arguments left!
        // (noise on the console, etc)
        if (remainingArgs.Count > 0)
        {
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                Error("Unknown arg! " + remainingArgs[i]);
            }

            return(false);
        }

        // All done
        return(true);
    }     //VerifyArgs
Exemple #3
0
    static UInt32 checkSum = 0;     // in or out

    static bool VerifyArgs(string[] inArgs)
    {
        //   - Make a list of args
        //   - Remove them from the list when they've been processed
        // 1 - Determine COM port
        // 2 - Grab any /r /e /b commands
        // 3 - Get the address value if required
        // 4 - Get the other address value?
        // 5 - File name!
        //

        if (inArgs.Length == 0)
        {
            PrintUsage(false);
            return(false);
        }

        // Thank you, linq <3
        // We'll remove args as they're processed so they're not processed twice
        // and extra args will be left over.

        List <string> remainingArgs = inArgs.ToList();

        // Specified a com port?

                #if DebugArgs
        Console.WriteLine("__TEST__Argsleft: " + remainingArgs.Count);
                #endif

        for (int i = remainingArgs.Count - 1; i >= 0; i--)
        {
            string s = remainingArgs[i];

            Regex COM     = new Regex(@"\b(COM(.*))\b", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match COMPORT = COM.Match(s);

            Regex DEV    = new Regex(@"\b(dev(.*))\b", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match NIXDEV = DEV.Match(s);

            if (COMPORT.Success)
            {
                argComPort = s.ToUpperInvariant();
                // Console.WriteLine( " - Using port " + argComPort );
                remainingArgs.RemoveAt(i);
                break;
            }
            else if (NIXDEV.Success)
            {
                argComPort = s;
                remainingArgs.RemoveAt(i);
                break;
            }
        }

        if (argComPort == "")
        {
            return(Error("\nERROR! Please specify a COM port!"));
        }

        // going straight into monitor mode?
        if (remainingArgs.Count == 1 && remainingArgs[0].ToLowerInvariant() == "/m")
        {
            return(true);
        }


                #if DebugArgs
        Console.WriteLine("__TEST__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__TEST__COM: " + argComPort);
                #endif

        // Specified a command arg (or severay for future-proofing)?

        for (int arg = remainingArgs.Count - 1; arg >= 0; arg--)
        {
            string argVal = remainingArgs[arg].ToLowerInvariant();

            if (argVal == "/m")
            {
                                #if DebugArgs
                Console.WriteLine("__TEST__CommsMonitor Enabled: ");
                                #endif

                monitorComms = true;
                remainingArgs.RemoveAt(arg);
                continue;
            }

            // first one is uninitialised... ignore it
            for (int j = 1; j < (int)CommandMode.COUNT; j++)
            {
                CommandMode c = (CommandMode)j;

                if (argVal.ToLowerInvariant() == c.command())
                {
                    // Set the current value and remove
                    // it from the list of available args
                    argCommand     = c;
                    needInputFile  = c.needsInputFile();
                    needOutputFile = c.needsOutputFile();
                    remainingArgs.RemoveAt(arg);

                    // Now we've removed the /command, if there's
                    // an address after it, it will be remaningArgs[ arg ]

                    // end of the array!
                    if (arg >= remainingArgs.Count)
                    {
                        return(Error("Specify an address in the format 0x01234567\n"));
                    }

                    // found the command... do we need to find an address?
                    if (argCommand.needsAddress())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__TEST__Command " + c + " requires an address ");
                                                #endif

                        // reassign it
                        argVal = remainingArgs[arg].ToLowerInvariant();

                        // try and get the address argument
                        try{
                            argAddr = ParseAddress(argCommand, argVal);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify an address in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(arg);
                        satisfiedAddressRequirements = true;
                    }

                    // On top of that... do we need a size? E.g. for dumping bios.
                    if (argCommand.needsSize())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__TEST__Command " + c + " requires a size parameter ");
                                                #endif

                        // reassign it
                        argVal = remainingArgs[arg].ToLowerInvariant();

                        // try to get the size argument
                        try{
                            argSize = ParseAddress(argCommand, argVal);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify a size in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(arg);
                        satisfiedSizeRequirements = true;
                    }

                    break; // outer loop to check new args
                }
            }              // inner loop
        }                  // outer loop

                #if DebugArgs
        Console.WriteLine("__TEST__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__TEST__COM: " + argComPort);
        Console.WriteLine("__TEST__COMMAND: " + argCommand);
        Console.WriteLine("__TEST__ADDR: " + argAddr.ToString("X8"));
        Console.WriteLine("__TEST__NEEDSADDR: " + argCommand.needsAddress());
        Console.WriteLine("__TEST__NEEDSINPUT: " + argCommand.needsInputFile());
        Console.WriteLine("__TEST__NEEDSOUTPUT: " + argCommand.needsOutputFile());
                #endif

        if (argCommand == CommandMode.NOT_SET)
        {
            return(Error("Please specify a command - e.g. /r, /e /b, etc!\n\n"));
        }

        if (!argCommand.needsAddress())
        {
            satisfiedAddressRequirements = true;
        }

        if (!argCommand.needsSize())
        {
            satisfiedSizeRequirements = true;
        }

        if (!satisfiedAddressRequirements)
        {
            return(Error("Did you specify an address? E.g. 0x23456788\n"));
        }

        if (!satisfiedSizeRequirements)
        {
            return(Error("Did you specify a size? E.g. 0x23456788\n"));
        }


        // We've parsed the arguments, the addresses and the COM port
        // Finish up by finding the file, if necessary

        if (!needInputFile && !needOutputFile)
        {
            satisfiedFileRequirements = true;
        }
        else
        {
            // One of the args specifies a file?
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                string fName = remainingArgs[i];

                if (needInputFile)
                {
                    argFileName = fName;

                    try {
                        inFile = File.ReadAllBytes(fName);
                    } catch (System.Exception e) {
                        return(Error("Couldn't open input file " + fName + " Exception: " + e));
                    }

                    satisfiedFileRequirements = true;
                    remainingArgs.RemoveAt(i);
                }
            }
        }

        if (!satisfiedFileRequirements)
        {
            return(Error("Specify a filename!"));
        }

                #if DebugArgs
        Console.WriteLine("__TEST__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__TEST__FILENAME: " + argFileName);
        Console.WriteLine("__TEST__INPUTFILE: " + inFile);
        //Console.WriteLine( "__TEST__OUTPUTFILE: " + argOutFile );
                #endif

        // there shouldn't be any arguments left!
        if (remainingArgs.Count > 0)
        {
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                Error("Unknown arg! " + remainingArgs[i]);
            }

            return(false);
        }

        // All done
        return(true);
    }     //VerifyArgs
    //static UInt32 checkSum = 0; // in or out


    // Ensure the input is vaguely sane.
    //
    // - Make a list of args
    // - Remove them from the list when they've been processed
    // - Determine COM port
    // - Grab any /r /e /b commands
    // - Get the address value if required
    // - Get the other address value?
    // - File name!
    //


    static bool VerifyArgs(string[] inArgs)
    {
        if (inArgs.Length == 0)
        {
            PrintUsage(false);
            return(false);
        }

        // Thank you, linq <3
        // We'll remove args as they're processed so they're not processed twice
        // and extra args will be left over.

        List <string> remainingArgs = inArgs.ToList();

        // Specified a com port?

                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
                #endif

        for (int i = remainingArgs.Count - 1; i >= 0; i--)
        {
            string s = remainingArgs[i];

            if (ValidPort(s))
            {
                argComPort = s;
                remainingArgs.RemoveAt(i);
                break;
            }
        }

        // Likewise get the "/FAST" parameter out of the way

        for (int i = remainingArgs.Count - 1; i >= 0; i--)
        {
            string s = remainingArgs[i].ToUpperInvariant();

            if (s == "/FAST")
            {
                fastMode = true;
                remainingArgs.RemoveAt(i);
            }
        }



        if (argComPort == "")
        {
            try{
                if (System.IO.File.Exists("comport.txt"))
                {
                    argComPort = File.ReadAllText("comport.txt");
                }
            } catch (System.Exception e) {
                Console.Write("Error checking for cached com port...\n" + e);
            }

            if (argComPort == "")
            {
                if (POSIXEnvironment)
                {
                    return(Error("\nERROR! Please specify a device - e.g. /dev/ttyUSB0\n"));
                }
                else
                {
                    return(Error("\nERROR! Please specify a COM port - e.g. COM8\n"));
                }
            }
            else
            {
                usingCachedComPort = true;
            }
        }
        else
        {
            try{
                File.WriteAllText("comport.txt", argComPort);
            } catch (System.Exception e) {
                Console.Write("Error writing cached com port!\n" + e);
            }
        }


        // is /m the last remaining arg?
        if (remainingArgs.Count == 1 && remainingArgs[0].ToLowerInvariant() == "/m")
        {
            monitorComms = true;
            return(true);
        }


                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__COM: " + argComPort);
        Console.WriteLine("__DEBUG__FAST: " + fastMode);
                #endif

        // Specified a command arg (or severay for future-proofing)?

        for (int arg = remainingArgs.Count - 1; arg >= 0; arg--)
        {
            string argVal = remainingArgs[arg].ToLowerInvariant();

            if (argVal == "/m")
            {
                                #if DebugArgs
                Console.WriteLine("__DEBUG__CommsMonitor Enabled: ");
                                #endif

                monitorComms = true;
                remainingArgs.RemoveAt(arg);
                continue;
            }

            // first one is uninitialised... ignore it
            for (int j = 1; j < (int)CommandMode.COUNT; j++)
            {
                CommandMode c = (CommandMode)j;

                if (argVal.ToLowerInvariant() == c.command())
                {
                    // Set the current value and remove
                    // it from the list of available args
                    argCommand     = c;
                    needInputFile  = c.needsInputFile();
                    needOutputFile = c.needsOutputFile();
                    remainingArgs.RemoveAt(arg);

                    // On top of that... do we need a size? E.g. for dumping bios.
                    if (argCommand.needsRegister())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a register ");
                                                #endif

                        // reassign it
                        argVal = remainingArgs[arg].ToLowerInvariant();

                        // TODO: verify it's a register, I guess.
                        argRegister = argVal;

                        remainingArgs.RemoveAt(arg);
                        satisfiedRegisterRequirements = true;
                    }

                    // Now we've removed the /command, if there's
                    // an address after it, it will be remaningArgs[ arg ]

                    // found the command... do we need to find an address?
                    if (argCommand.needsAddress())
                    {
                        // end of the array!
                        if (arg >= remainingArgs.Count)
                        {
                            return(Error("Specify an address in the format 0x01234567\n"));
                        }

                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires an address ");
                                                #endif

                        // reassign it
                        argVal = remainingArgs[arg].ToLowerInvariant();

                        // try and get the address argument
                        try{
                            argAddr = ParseAddress(argCommand, argVal);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify an address in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(arg);
                        satisfiedAddressRequirements = true;
                    }

                    // On top of that... do we need a size? E.g. for dumping bios.
                    if (argCommand.needsSize())
                    {
                                                #if DebugArgs
                        Console.WriteLine("__DEBUG__Command " + c + " requires a size parameter ");
                                                #endif

                        // reassign it
                        argVal = remainingArgs[arg].ToLowerInvariant();

                        // try to get the size argument
                        try{
                            argSize = ParseAddress(argCommand, argVal);
                        } catch (System.Exception) {
                            return(Error("EXCEPTION: Specify a size in the format 0x01234567"));
                        }

                        remainingArgs.RemoveAt(arg);
                        satisfiedSizeRequirements = true;
                    }



                    break; // outer loop to check new args
                }
            }              // inner loop
        }                  // outer loop

                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__COM: " + argComPort);
        Console.WriteLine("__DEBUG__COMMAND: " + argCommand);
        Console.WriteLine("__DEBUG__ADDR: " + argAddr.ToString("X8"));
        Console.WriteLine("__DEBUG__NEEDSADDR: " + argCommand.needsAddress());
        Console.WriteLine("__DEBUG__NEEDSINPUT: " + argCommand.needsInputFile());
        Console.WriteLine("__DEBUG__NEEDSOUTPUT: " + argCommand.needsOutputFile());
                #endif

        if (argCommand == CommandMode.NOT_SET)
        {
            return(Error("Please specify a command - e.g. /r, /e /b, etc!\n\n"));
        }

        if (!argCommand.needsRegister())
        {
            satisfiedRegisterRequirements = true;
        }

        if (!argCommand.needsAddress())
        {
            satisfiedAddressRequirements = true;
        }

        if (!argCommand.needsSize())
        {
            satisfiedSizeRequirements = true;
        }

        if (!satisfiedAddressRequirements)
        {
            return(Error("Did you specify an address or hex value? E.g. 0x23456788\n"));
        }

        if (!satisfiedSizeRequirements)
        {
            return(Error("Did you specify a size? E.g. 0x23456788\n"));
        }

        if (!satisfiedRegisterRequirements)
        {
            return(Error("Did you specify a register? E.g. a0"));
        }


        // We've parsed the arguments, the addresses and the COM port
        // Finish up by finding the file, if necessary

        if (!needInputFile && !needOutputFile)
        {
            satisfiedFileRequirements = true;
        }
        else
        {
            // One of the args specifies a file?
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                string fName = remainingArgs[i];

                if (needInputFile)
                {
                    argFileName = fName;

                    try {
                        inFile = File.ReadAllBytes(fName);
                    } catch (System.Exception e) {
                        return(Error("Couldn't open input file " + fName + " Exception: " + e));
                    }

                    satisfiedFileRequirements = true;
                    remainingArgs.RemoveAt(i);
                }
            }
        }

        if (!satisfiedFileRequirements)
        {
            return(Error("Specify a filename!"));
        }

                #if DebugArgs
        Console.WriteLine("__DEBUG__Argsleft: " + remainingArgs.Count);
        Console.WriteLine("__DEBUG__FILENAME: " + argFileName);
        Console.WriteLine("__DEBUG__INPUTFILE: " + inFile);
        //Console.WriteLine( "__DEBUG__OUTPUTFILE: " + argOutFile );
                #endif

        // there shouldn't be any arguments left!
        if (remainingArgs.Count > 0)
        {
            for (int i = remainingArgs.Count - 1; i >= 0; i--)
            {
                Error("Unknown arg! " + remainingArgs[i]);
            }

            return(false);
        }

        // All done
        return(true);
    }     //VerifyArgs