当前位置: 首页>>代码示例>>Python>>正文


Python Memory.operate方法代码示例

本文整理汇总了Python中memory.Memory.operate方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.operate方法的具体用法?Python Memory.operate怎么用?Python Memory.operate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.operate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Orion

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import operate [as 别名]
class Orion(QWidget):
    def __init__(self):
        super(Orion, self).__init__()
        self.ui = Ui_window()
        self.ui.setupUi(self)
        self.ui.tableWidget.setHorizontalHeaderLabels(['Endereço', 'Palavra'])
        self._memory = Memory()
        load_program(self._memory)
        self.ui.tableWidget.setRowCount(len(self._memory))
        self._init_cpu()
        self._fill_table()
        self._connect_edits()
        self.ui.pushButtonNext.clicked.connect(self.next_cpu)
        self.ui.tableWidget.itemChanged.connect(self._update_word)

    def next_cpu(self):
        try:
            info = self.gen.send(None)
            self.ui.lineEditStatus.setText(info)
            self.ui.lineEditPC.setText(hex(self.cpu.pc))
            self.ui.lineEditIR.setText(hex(self.cpu.ir))
            self.ui.lineEditAH.setText(hex(self.cpu.ula.ah))
            self.ui.lineEditBH.setText(hex(self.cpu.ula.bh))
            self.ui.lineEditAC.setText(hex(self.cpu.ula.ac))
            self.ui.lineEditAX.setText(hex(self.cpu.ax))
            self.ui.lineEditBX.setText(hex(self.cpu.bx))
            self.ui.lineEditCX.setText(hex(self.cpu.cx))
            self.ui.lineEditDX.setText(hex(self.cpu.dx))
            self.ui.lineEditSTS.setText(bin(self.cpu.sts))
            self.ui.lineEditInstruction.setText(instrucoes[self.cpu.ir])
            if self.cpu.ir == 0x8:
                self._update_table()
            self._select_row(hex(self.cpu.pc))
        except StopIteration:
            QMessageBox.information(self, "Orion", "Execução Finalizada")

    def _init_cpu(self):
        bus = Bus(self._memory)
        self.cpu = Cpu(bus)
        self.cpu.pc = 0x200
        self.gen = self.cpu.start()

    def _fill_table(self):
        for i in range(1, len(self._memory)):
            item_endereco = QTableWidgetItem(hex(i))
            item_endereco.setFlags(item_endereco.flags() ^ Qt.ItemIsEditable)
            data = self._memory.operate(i, None, 0)
            if data is not None:
                data = hex(data)
            item_palavra = QTableWidgetItem(data)
            self.ui.tableWidget.setItem(i-1, 0, item_endereco)
            self.ui.tableWidget.setItem(i-1, 1, item_palavra)

    def _update_table(self):
        for i in range(1, len(self._memory)):
            item_palavra = self.ui.tableWidget.item(i-1, 1)
            data = self._memory.operate(i, None, 0)
            if data is not None:
                data = hex(data)
            item_palavra.setText(data)

    def _select_row(self, pc):
        item = self.ui.tableWidget.findItems(pc, Qt.MatchExactly)[0]
        self.ui.tableWidget.selectRow(item.row())
        self.ui.tableWidget.scrollToItem(item)

    def _update_word(self, item):
        self.cpu.bus.transfer(int(self.ui.tableWidget.item(item.row(), 0).text(), 16), int(item.text(), 16), 1)

    def _connect_edits(self):
        self.ui.lineEditAH.editingFinished.connect(self._update_register)
        self.ui.lineEditBH.editingFinished.connect(self._update_register)
        self.ui.lineEditAC.editingFinished.connect(self._update_register)

    def _update_register(self):
        sender = self.sender().objectName()
        value = int(self.sender().text(), 16)
        if sender == 'lineEditAH':
            self.cpu.ula.ah = value
        elif sender == 'lineEditBH':
            self.cpu.ula.bh = value
        elif sender == 'lineEditAC':
            self.cpu.ula.ac = value
开发者ID:gabrielmldantas,项目名称:Orion,代码行数:85,代码来源:orion.py


注:本文中的memory.Memory.operate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。