Esempio n. 1
0
        // debug helper
        public static void Monitor(ushort memIndex, bool printState = false)
        {
            if (!doMonitor)
            {
                return;
            }

            List <string> _memstr = new List <string>();
            Operation     debugOp = Disassembler.Disassembly(memIndex);
            string        dasm    = debugOp.DebugText;

            dasm += debugOp.Operands.Count() > 0 ? " " + debugOp.Operands[0].DebugText : string.Empty;
            dasm += debugOp.Operands.Count() > 1 ? "," + debugOp.Operands[1].DebugText : string.Empty;
            if (!printState)
            {
                dasm = "PC:" + Convert.ToString(State.PC, 16).ToUpper().PadLeft(4, '0') + " " + dasm;
                _memstr.Add(dasm);
            }
            else
            {
                string _state = string.Format(stateDebugString,
                                              Convert.ToString(State.PC, 16).ToUpper().PadLeft(4, '0'),
                                              Convert.ToString(State.SP, 16).ToUpper().PadLeft(4, '0'),
                                              StatusRegisterValue(),
                                              Convert.ToString(State.X, 16).ToUpper().PadLeft(4, '0'),
                                              string.Format("A{0}:{1} {2}  A{3}:{4} {5}", 0, Convert.ToString(State.A[0], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[0], 2).PadLeft(16, '0'), 1, Convert.ToString(State.A[1], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[1], 2).PadLeft(16, '0')),
                                              string.Format("A{0}:{1} {2}  A{3}:{4} {5}", 2, Convert.ToString(State.A[2], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[2], 2).PadLeft(16, '0'), 3, Convert.ToString(State.A[3], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[3], 2).PadLeft(16, '0')),
                                              string.Format("A{0}:{1} {2}  A{3}:{4} {5}", 4, Convert.ToString(State.A[4], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[4], 2).PadLeft(16, '0'), 5, Convert.ToString(State.A[5], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[5], 2).PadLeft(16, '0')),
                                              string.Format("A{0}:{1} {2}  A{3}:{4} {5}", 6, Convert.ToString(State.A[6], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[6], 2).PadLeft(16, '0'), 7, Convert.ToString(State.A[7], 16).ToUpper().PadLeft(4, '0'), Convert.ToString(State.A[7], 2).PadLeft(16, '0'))
                                              );

                // dump memory
                _memstr = new List <string>()
                {
                    _state,
                    dasm,
                    "--------------------------------------------------"
                };
            }
            File.AppendAllLines(Utilities.RegDumpFilename, _memstr, Encoding.ASCII);

            /*
             * _memstr.Add("       0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
             * int cnt = 0;
             * // dump the first $200 bytes, 64K are too much and in debug we can write to rom for test
             * while (cnt < 0x0200)
             * {
             *  string _log = Convert.ToString(cnt, 16).ToUpper().PadLeft(4, '0') + ": ";
             *  for (int __c = 0; __c < 16; __c++)
             *      _log += Convert.ToString(Memory.Data[cnt + __c], 16).ToUpper().PadLeft(2, '0') + " ";
             *  _memstr.Add(_log.Trim());
             *  cnt += 16;
             * }
             */
            //File.WriteAllLines("dump.txt", _memstr, Encoding.ASCII);

            if (doMonitor)
            {
                //doMonitor = false;
            }
        }