Exemplo n.º 1
0
        /// FUNCTION: - Add the number of rows requested to memory panel starting at <startAddress>
        ///           - Show 2 rows in memory panel previous to <startAddress> to see what instructions are before PC
        ///           - Don't show these previous 2 rows if <startAddress> is within 16 bytes from byte zero to avoid invalid
        ///             access in array.
        /// RECEIVES CALLS FROM: -updatePanelsAndResetMenuItems()
        ///                      -goButton_Click()
        private void updateMemoryPanel(uint startAddress)
        {
            int rowToHighlight = 0; // hightlight first row to show starting address

            this.memoryDataGridView.Rows.Clear();

            uint wordSizeInBytes  = 4;                   // 4 bytes = 1 word
            uint oneMemRowInBytes = wordSizeInBytes * 4; // 4 words = 1 row

            uint[] fourWordsFromMemory;

            // set up to show previous 2 rows if <startAddress> is within 16 bytes from byte zero
            if ((startAddress - (oneMemRowInBytes * 2)) >= 0)
            {
                startAddress   = startAddress - (oneMemRowInBytes * 2); // show the first two rows previous to PC (program counter).
                rowToHighlight = 2;
            }


            // Add the number of rows requested to memory panel.
            // Add 2 rows in memory previous to PC
            // TODO: catch excess of rows requested when the RAM doesn't have a lot of memory to display that fits in the all the requested rows
            for (int i = 0; i < this.memoryPanelNoRowsToShow; i++)
            {
                fourWordsFromMemory = computer.getFourWordsFromMemory(startAddress);

                // TODO: for now if out of range in memory address, print 0. Add a handler for out of bound memory address later.
                // add one row in GridViewin order: address, hex1, hex2, hex3, h4, contents
                //string currentHexAddress = "0x" + startAddress.ToString("X").PadLeft(8, '0');
                this.memoryDataGridView.Rows.Add("0x" + startAddress.ToString("X").PadLeft(8, '0'),
                                                 fourWordsFromMemory[0].ToString("x").PadLeft(8, '0'),
                                                 fourWordsFromMemory[1].ToString("x").PadLeft(8, '0'),
                                                 fourWordsFromMemory[2].ToString("x").PadLeft(8, '0'),
                                                 fourWordsFromMemory[3].ToString("x").PadLeft(8, '0'));

                //increment startAddress to get the next four words from registers
                startAddress += oneMemRowInBytes;
            }

            // highlight feature for the start address row
            if (memoryDataGridView.Rows.Count > 1)
            {
                memoryDataGridView.Rows[rowToHighlight].DefaultCellStyle.BackColor = Color.Blue;
            }
        }