diff --git a/ALU.py b/ALU.py deleted file mode 100644 index c1eb0d5..0000000 --- a/ALU.py +++ /dev/null @@ -1,350 +0,0 @@ -from UI import * -# import tkinter as tk - - - -class ALU: - def __init__(self): - round_rectangle(74, 48, 533, 415, r=25, fill=BACK, width=0) # 绘制ALU蓝色背景 - Point = [90, 190, 120, 190, 130, 215, 205, 215, 215, 190, 245, 190, 220, 270, 115, 270] - cv.create_polygon(Point, fill=BLACK) # 绘制运算器 - self.line_init()# 在图中标记各个部件的名字 - - def show(self): - lines = ['ALU_R1', 'ALU_R2', 'ALU_R3', 'ALU_R4', 'R1_ALU1', 'R2_ALU1', - 'R3_ALU1', 'R4_ALU1', 'R1_ALU2', 'R2_ALU2', 'R3_ALU2', 'R4_ALU2'] - for l in lines: - if cpu.ALUio[l] == False: #如果ALUio中该线为False,则非高亮显示 - eval('self.' + l + '(cv, 0)') - for l in lines: - if cpu.ALUio[l] == True: #如果ALUio中该线为True,则高亮显示 - eval('self.' + l + '(cv, 1)') - - if cpu.ALUop['+'] == True: - self.opa(cv) - if cpu.ALUop['-'] == True: - self.opb(cv) - if cpu.ALUop['*'] == True: - self.opc(cv) - if cpu.ALUop['/'] == True: - self.opd(cv) - - def line_init(self): - cv.create_text(140, 183, text='ALU', font=('微软雅黑', 20), anchor=NW, fill=WORD) - cv.create_text(345, 95, text="R1", font=('微软雅黑', 18), fill=WORD) - cv.create_text(345, 185, text="R2", font=('微软雅黑', 18), fill=WORD) - cv.create_text(345, 275, text="R3", font=('微软雅黑', 18), fill=WORD) - cv.create_text(345, 365, text="R4", font=('微软雅黑', 18), fill=WORD) - lines = ['ALU_R1', 'ALU_R2', 'ALU_R3', 'ALU_R4', 'R1_ALU1', 'R2_ALU1', - 'R3_ALU1', 'R4_ALU1', 'R1_ALU2', 'R2_ALU2', 'R3_ALU2', 'R4_ALU2' ] - for l in lines: - eval('self.' + l + '(cv, 0)') - # for l in lines: - # eval('self.' + l + '(cv, -1)') - def mark(self, lines): - for i in range(5): - if i: - time.sleep(cpu.time) - if i % 2: - for l in lines: - # print('self.' + l + '(cv, 1)') - # self.init() - eval('self.' + l + '(cv, 1)') - else: - for l in lines: - # print('self.' + l + '(cv, 0)') - # self.init() - eval('self.' + l + '(cv, 0)') - cv.update() - ''' - def mark(self, lines): - for i in range(5): - if i: - time.sleep(cpu.time) - if i % 2: - for l in lines: - cpu.ALUio[l] = True - self.show() - # print('self.' + l + '(cv, 1)') - # eval('self.' + l + '(cv, 1)') - else: - for l in lines: - cpu.ALUio[l] = False - self.show() - # print('self.' + l + '(cv, 0)') - # eval('self.' + l + '(cv, 0)') - cv.update() - ''' - def init(self, cv: Canvas, root): - - self.no(cv) - - R_text = [] - for i in range(4): - R_text.append(cpu.R(i)) - - R1 = tk.Label(root, text=R_text[0], fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - R1.place(x=365, y=85, height=30, width=150) - R2 = tk.Label(root, text=R_text[1], fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - R2.place(x=365, y=175, height=30, width=150) - R3 = tk.Label(root, text=R_text[2], fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - R3.place(x=365, y=265, height=30, width=150) - R4 = tk.Label(root, text=R_text[3], fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - R4.place(x=365, y=355, height=30, width=150) - # time.sleep(cpu.time) - # R1['text'] = 'RRRRRRRRRRRRRR1' - - cv.update() - - def ALU_R1(self, cv: Canvas, flag): - if flag: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 270, 100, width=5, capstyle=ROUND, fill=RED) - cv.create_line(330, 100, 270, 100, width=5, capstyle=ROUND, arrow=FIRST, fill=RED) - else: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 270, 100, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(330, 100, 270, 100, width=5, capstyle=ROUND, arrow=FIRST, fill=NORED) - cv.update() - def ALU_R2(self, cv: Canvas, flag): - if flag: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 270, 180, width=5, capstyle=ROUND, fill=RED) - cv.create_line(330, 180, 270, 180, width=5, capstyle=ROUND, arrow=FIRST, fill=RED) - else: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 270, 180, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(330, 180, 270, 180, width=5, capstyle=ROUND, arrow=FIRST, fill=NORED) - cv.update() - def ALU_R3(self, cv: Canvas, flag): - if flag: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 270, 275, width=5, capstyle=ROUND, fill=RED) - cv.create_line(330, 275, 270, 275, width=5, capstyle=ROUND, arrow=FIRST, fill=RED) - else: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 270, 275, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(330, 275, 270, 275, width=5, capstyle=ROUND, arrow=FIRST, fill=NORED) - cv.update() - def ALU_R4(self, cv: Canvas, flag): - if flag: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=RED) - cv.create_line(270, 315, 270, 355, width=5, capstyle=ROUND, fill=RED) - cv.create_line(330, 355, 270, 355, width=5, capstyle=ROUND, arrow=FIRST, fill=RED) - else: - cv.create_line(170, 273, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 170, 315, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(270, 315, 270, 355, width=5, capstyle=ROUND, fill=NORED) - cv.create_line(330, 355, 270, 355, width=5, capstyle=ROUND, arrow=FIRST, fill=NORED) - cv.update() - - def R1_ALU1(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 80, 340, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 65, 340, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=ORANGE) - else: - cv.create_line(340, 80, 340, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 65, 340, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=NOORANGE) - cv.update() - - def R2_ALU1(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 165, 340, 155, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 155, 340, 155, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 155, 310, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=ORANGE) - else: - cv.create_line(340, 165, 340, 155, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 155, 340, 155, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 155, 310, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=NOORANGE) - cv.update() - def R3_ALU1(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 245, 340, 235, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 235, 340, 235, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 235, 310, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=ORANGE) - else: - cv.create_line(340, 245, 340, 235, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 235, 340, 235, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 235, 310, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=NOORANGE) - cv.update() - def R4_ALU1(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 335, 340, 325, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 325, 340, 325, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 325, 310, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=ORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=ORANGE) - else: - cv.create_line(340, 335, 340, 325, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 325, 340, 325, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 325, 310, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(310, 65, 100, 65, width=5, capstyle=ROUND, fill=NOORANGE) - cv.create_line(100, 190, 100, 65, width=5, capstyle=ROUND, arrow=FIRST, fill=NOORANGE) - cv.update() - def R1_ALU2(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 110, 340, 130, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 130, 340, 130, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 130, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=GREEN) - else: - cv.create_line(340, 110, 340, 130, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 130, 340, 130, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 130, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=NOGREEN) - cv.update() - - def R2_ALU2(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 200, 340, 220, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 220, 340, 220, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 220, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=GREEN) - else: - cv.create_line(340, 200, 340, 220, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 220, 340, 220, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 220, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=NOGREEN) - cv.update() - def R3_ALU2(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 290, 340, 310, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 310, 340, 310, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 310, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=GREEN) - else: - cv.create_line(340, 290, 340, 310, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 310, 340, 310, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 310, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=NOGREEN) - cv.update() - def R4_ALU2(self, cv: Canvas, flag): - if flag: - cv.create_line(340, 380, 340, 395, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 395, 340, 395, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(295, 395, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=GREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=GREEN) - else: - cv.create_line(340, 380, 340, 395, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 395, 340, 395, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(295, 395, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 295, 240, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(250, 240, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 250, 160, width=5, capstyle=ROUND, fill=NOGREEN) - cv.create_line(230, 160, 230, 190, width=5, capstyle=ROUND, arrow=LAST, fill=NOGREEN) - cv.update() - def opa(self, cv: Canvas): - #加号 - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - self.no(cv) - cv.create_text(bx2, by2 - 5, text='+', font=('微软雅黑', 16), anchor=NW, fill=GOLD) - cv.update() - def opb(self,cv:Canvas): - #减号 - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - self.no(cv) - cv.create_text(bx2, by2 - 5, text='+ -', font=('微软雅黑', 16), anchor=NW, fill=GOLD) - cv.create_text(bx2, by2 - 5, text='+', font=('微软雅黑', 16), anchor=NW, fill=GREY) - cv.update() - def opc(self,cv:Canvas): - #乘号 - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - self.no(cv) - cv.create_text(bx2, by2 - 5, text='+ - x', font=('微软雅黑', 16), anchor=NW, fill=GOLD) - cv.create_text(bx2, by2 - 5, text='+ -', font=('微软雅黑', 16), anchor=NW, fill=GREY) - cv.update() - def opd(self,cv:Canvas): - #除号 - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - self.no(cv) - cv.create_text(bx2, by2 - 5, text='+ - x ÷', font=('微软雅黑', 16), anchor=NW, fill=GOLD) - cv.create_text(bx2, by2 - 5, text='+ - x', font=('微软雅黑', 16), anchor=NW, fill=GREY) - cv.update() - - def no(self, cv:Canvas): - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - cv.create_rectangle(bx2, by2, bx2 + 100, by2 + 20, fill=BLACK, width=0) - cv.create_text(bx2, by2 - 25, text='完 成 运 算', font=('微软雅黑', 12), anchor=NW, fill=GREY) - cv.create_text(bx2, by2 - 5, text='+ - x ÷', font=('微软雅黑', 16), anchor=NW, fill=GREY) - cv.update() - - def finish(self, cv:Canvas): - bx2, by2, bw2, bh2 = 115, 245, 100, 20 - cv.create_rectangle(bx2, by2, bx2 + 100, by2 + 20, fill=BLACK, width=0) - cv.create_text(bx2, by2 - 25, text='完 成 运 算', font=('微软雅黑', 12), anchor=NW, fill=GOLD) - cv.create_text(bx2, by2 - 5, text='+ - x ÷', font=('微软雅黑', 16), anchor=NW, fill=GREY) - cv.update() - - - -if __name__ == "__main__": - - al = ALU()#实例化 - - al.init(cv, root) - al.line_init() - cv.update() - al.mark(['R3_ALU1']) - al.show() - # al.ALU_R1(cv, 1) - # al.ALU_R2(cv, 1) - # al.ALU_R3(cv, 1) - # al.ALU_R4(cv, 1) - # al.R1_ALU1(cv, 1) - # al.R2_ALU1(cv, 1) - # al.R3_ALU1(cv, 1) - # al.R4_ALU1(cv, 1) - # al.R1_ALU2(cv, 1) - # al.R2_ALU2(cv, 1) - # al.R3_ALU2(cv, 1) - # al.R4_ALU2(cv, 1) - - - def left1(event): - print(event.x,event.y) - cv.bind('', left1) - # cv.create_line(485,469+4.5,485+120+12,469+4.5,width=9,fill=RED,arrow=LAST) - # cv.create_rectangle(485, 469, 485 + 120, 469 + 9, fill=RED) - - - root.mainloop() \ No newline at end of file diff --git a/Clock.py b/Clock.py deleted file mode 100644 index 4abbb33..0000000 --- a/Clock.py +++ /dev/null @@ -1,109 +0,0 @@ -from UI import * -# import tkinter as tk -# from Instruction4 import SimMem -from tkinter import messagebox - - -class ClockStep: - def __init__(self):# 绘制控制器背景板 - round_rectangle(74, 434, 533, 642, r=25, fill=BACK, width=0) - round_rectangle(97, 525, 276, 627, r=25, fill=BLACK, width=0) - self.dx2, self.dy2, self.dw2, self.dh2 = 95, 455, 200, 40# 时钟数字间隔 - self.R, self.x0, self.y0, self.dx = 15, 113, 473, 35#时钟大小 - - - def clo_mark(self, cv:Canvas):# 依据ClockStep[]的值显示时钟元素 - for i in range(6):#遍历六个时钟刻,绘制各个时钟 - cv.create_oval(i * self.dx + self.x0 - self.R, self.y0 - self.R, i * self.dx + self.x0 + self.R, - self.y0 + self.R, width=1)#绘制时钟圆圈 - if cpu.clo[i] == True:# 如果存储结构中clo[i]为1,则该时钟高亮显示 - cv.create_oval(self.x0 - self.R + self.dx * i, self.y0 - self.R, - self.x0 + self.R + self.dx * i, self.y0 + self.R, width=1, fill=RED) - else:# 如果存储结构中clo[i]为1,则该时钟正常显示 - cv.create_oval(self.x0 - self.R + self.dx * i, self.y0 - self.R, - self.x0 + self.R + self.dx * i, self.y0 + self.R, - width=1, fill=WHITE) - cv.create_text(self.dx2 + 12, self.dy2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW)# 重新绘制各时钟编号 - cv.update()#更新画布 - - # 实现仿真控制器的各个屏幕元素,同时依据ClockStep[]的值显示节拍元素 - def show(self, cv: Canvas, root): - # 标记控制器各个部件名称 - cv.create_text(95, 434, text='Clock', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(342, 434, text='PC', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(104, 500, text='SigCtrl', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(342, 540, text='IR', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - # 根据当前控制器存储的值显示PC值 - PC = tk.Label(root, text=cpu.PC(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - PC.place(x=335, y=455, height=30, width=150) - # 根据当前控制器存储的值显示IR值 - IR = tk.Label(root, text=cpu.IR(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE) - IR.place(x=335, y=565, height=30, width=150) - # 绘制Clock背景板 - bx2, by2, bw2, bh2 = 95, 455, 200, 40 - round_rectangle(bx2, by2, bx2 + 215, by2 + 35, r=20, fill=WHITE, width=0) - # 绘制时钟名称 - cv.create_text(bx2 + 12, by2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW, ) - R = 15 - x0 = 113 - y0 = 473 - dx = 35 - # 绘制各个时钟 - for i in range(6): - cv.create_oval(i * dx + x0 - R, y0 - R, i * dx + x0 + R, y0 + R, width=1) - self.clo_mark(cv) - # 更新画布 - cv.update() - - # 实现仿真控制器的各个屏幕元素,同时依据ClockStep[]的值显示节拍元素 - def init(self, cv:Canvas, root): - cv.create_text(95, 434, text='Clock', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记PC名称 - cv.create_text(342, 434, text='PC', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记PC名称 - cv.create_text(104, 500, text='SigCtrl', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记sig_ctrl名称 - cv.create_text(342, 540, text='IR', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记IR名称 - PC = tk.Label(root, text=cpu.PC(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)# 根据cpu存储的值显示PC值 - PC.place(x=335, y=455, height=30, width=150)#放置PC值 - IR = tk.Label(root, text=cpu.IR(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)# 根据cpu存储的值显示IR值 - IR.place(x=335, y=565, height=30, width=150)#放置IR值 - bx2, by2, bw2, bh2 = 95, 455, 200, 40# Clock背景板大小 - round_rectangle(bx2, by2, bx2+215, by2+35, r=20, fill=WHITE, width=0)# 绘制Clock背景板 - self.clo_mark(cv)#绘制六个时钟 - cv.update()#更新面板 - - - def jp(self, cv:Canvas, flag, num): - if flag: - cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R, width=1, fill=RED) - else: - cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R, - width=1, fill=WHITE) - cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R, - width=1) - cv.create_text(self.dx2 + 12, self.dy2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW) - cv.update() - - - - -if __name__ == "__main__": - cl=ClockStep() - # cl.clo_mark(cv) - cl.init(cv,root) - ''' - def add_program(): - cl.init(cv, root) - # cl.show(cv, 1) - # cl.show(cv, 2) - # cl.show(cv, 3) - # cl.show(cv, 4) - # cl.show(cv, 5) - # cl.show(cv, 6) - - # si.np() - # cv.create_line(485,469+4.5,485+120+12,469+4.5,width=9,fill=RED,arrow=LAST) - # cv.create_rectangle(485, 469, 485 + 120, 469 + 9, fill=RED) - def left1(event): - print(event.x,event.y) - cv.bind('', left1) - ''' - mainloop() \ No newline at end of file diff --git a/ExecInstructWithAnim.py b/ExecInstructWithAnim.py deleted file mode 100644 index a3ce356..0000000 --- a/ExecInstructWithAnim.py +++ /dev/null @@ -1,609 +0,0 @@ -# -*- encoding: utf-8 -*- -""" - @Author: packy945 - @FileName: ExecInstructWithAnim.py - @DateTime: 2023/7/5 11:46 - @SoftWare: PyCharm -""" - -from RightPanel import * -from tkinter import scrolledtext -import collections - -class ExecInstructWithAnim:# 自动执行指令(带UI) - def step_run(self): - ''' - self.SimInstrCtrl中为SimInstrCtrl - SimInstrCtrl[] = {} - 表示<指令码,节拍,该节拍下的一条信号>。SimInstrCtrl[]用于保存一条指令在各个节拍下的信号。 - self.SimInstrCtrl为待执行的指令集合 - :return: - ''' - cur_clock = -1 - while len(self.SimInstrCtrl): # 逐个取出指令集的指令并且执行 - time.sleep(cpu.time) # 等待一段时间 - self.auto_display() # 更新操作面板 - cur_step = self.SimInstrCtrl.pop() # 取出下一条指令 - if cur_clock == -1:# 记录当前运行的时钟刻 - cur_clock = cur_step[1] - else: # 若时钟刻与记录的时钟刻不同则暂停程序的运行,等待下一次操作 - if not cur_clock == cur_step[1]: - self.SimInstrCtrl.append(cur_step) - self.play = 0 - break - cpu.CLO(cur_step[1] - 1) # 根据指令设置时钟刻 - cl.clo_mark(cv) # 显示当前时钟刻 - print(cur_step[2]) - eval(cur_step[2]) # 执行当前指令 - self.auto_display() # 更新操作面板 - if self.play: # 若没有停机,解析当前指令 - self.solve_step() - - def SimGoto(self): - # 001001跳转指令 SimGoto - self.SimInstrCtrl.appendleft(['001001', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['001001', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['001001', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['001001', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['001001', 4, 'self.SimSigCtrl_PC()']) - self.SimInstrCtrl.appendleft(['001001', 4, 'self.SimMcontent_PC()']) - self.SimInstrCtrl.appendleft(['001001', 4, 'self.ShowSimGoto()']) - - - def solve(self): - ''' - 解析一条指令 - 并将解析后的步骤加入到self.SimInstrCtrl中 - :return: - ''' - if self.play == 0: - return - self.auto_display()# 更新自动运行面板 - code = cpu.code# 读取当前指令 - if code == 0:# 000000取指令 - self.get() - elif code % 16 == 1:# 000001取数指令(R1) - self.SimGet(code // 16) - elif code % 16 == 2:# 000010存数指令(R1) - self.SimPut(code // 16) - elif code % 16 == 3:# 000011加法指令 - self.SimAddr(code // 16) - - elif code % 16 == 4:# 000100乘法指令 - self.SimProduct(code // 16) - elif code == 5:# 打印指令000101 - self.SimPrint() - elif code == 6:# 停机指令000110 - self.SimStop() - elif code % 16 == 7:# 000111减法指令 op = 1(R1) - self.SimMinus(code // 16) - elif code % 16 == 8:# 001000除法指令 op = 3(R1) - self.SimDiv(code // 16) - elif code == 9:# 001001跳转指令Simgoto - self.SimGoto() - else:#无法解析指令视为停机指令 - self.SimStop() - # 更新画布 - si.init(cv, root) - self.exec_instruct_with_anim()#开始执行指令 - - def exec_instruct_with_anim(self): - ''' - self.SimInstrCtrl中为SimInstrCtrl - SimInstrCtrl[] = {} - 表示<指令码,节拍,该节拍下的一条信号>。SimInstrCtrl[]用于保存一条指令在各个节拍下的信号。 - self.SimInstrCtrl为待执行的指令集合 - :return: - ''' - while len(self.SimInstrCtrl):# 逐个取出指令集的指令并且执行 - time.sleep(cpu.time)# 等待一段时间 - self.auto_display()# 更新操作面板 - cur_step = self.SimInstrCtrl.pop()# 取出下一条指令 - cpu.CLO(cur_step[1] - 1)# 根据指令设置时钟刻 - cl.clo_mark(cv)# 显示当前时钟刻 - eval(cur_step[2])# 执行当前指令 - self.auto_display()# 更新操作面板 - if self.play:# 若没有停机,解析当前指令 - self.solve() - - - - def get(self):# 000000为取指令 - self.SimInstrCtrl.appendleft(['000000', 1, 'self.PC_Maddr()']) # PC->Maddr - self.SimInstrCtrl.appendleft(['000000', 1, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['000000', 2, 'self.SimMaddr_Memory()']) # Maddr->Memory - self.SimInstrCtrl.appendleft(['000000', 2, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['000000', 2, 'self.SimSigCtrl_IR()']) # SigCtrl->IR - self.SimInstrCtrl.appendleft(['000000', 2, 'self.SimMcontent_IR()']) # Mcontent->IR - self.SimInstrCtrl.appendleft(['000000', 2, 'self.SimIR_SigCtrl()']) # IR->SigCtrl - self.SimInstrCtrl.appendleft(['000000', 3, 'self.SimPC_1()']) # PC+1 - self.SimInstrCtrl.appendleft(['000000', 3, 'self.Showget()']) # 显示输出信息 - - def SimGet(self, n): - # 000001取数指令(R1) n = 0 - # 010001取数指令(R2) n = 1 - # 100001取数指令(R3) n = 2 - # 110001取数指令(R4) n = 3 - self.SimInstrCtrl.appendleft(['000001', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000001', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - - self.SimInstrCtrl.appendleft(['000001', 4, 'self.SimMaddr_Memory()']) # Maddr->Memory - self.SimInstrCtrl.appendleft(['000001', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - - self.SimInstrCtrl.appendleft(['000001', 4, 'self.SimSigCtrl_R(' + str(n) + ')']) # SigCtrl->Rn - self.SimInstrCtrl.appendleft(['000001', 4, 'self.SimMcontent_R(' + str(n) + ')']) # Mcontent->Rn - self.SimInstrCtrl.appendleft(['000001', 4, 'self.ShowSimget(' + str(n) + ')']) # 显示信息到输出框 - - def SimPut(self, n): - # 000010存数指令(R1) - # 010010存数指令(R2) - # 100010存数指令(R3) - # 110010存数指令(R4) - self.SimInstrCtrl.appendleft(['000010', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000010', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - - self.SimInstrCtrl.appendleft(['000010', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['000010', 4, 'self.SimR_Mcontent(' + str(n + 1) + ')']) # Rn->Mcontent - self.SimInstrCtrl.appendleft(['000010', 4, 'self.SimMcontent_Memory()']) # Mcontent_Memory - self.SimInstrCtrl.appendleft(['000010', 4, 'self.ShowSimPut(' + str(n + 1) + ')']) # 显示信息到输出框 - - def SimAddr(self, n): - # 加法指令000011 - self.SimInstrCtrl.appendleft(['000011', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000011', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['000011', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['000011', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['000011', 4, 'self.SimMcontent_R(' + str(n + 1) + ')']) # Mcontent->Rn+1 - - self.SimInstrCtrl.appendleft(['000011', 5, 'self.SimR_ALU1(' + str(n) + ')']) # Rn->ALU1 - self.SimInstrCtrl.appendleft(['000011', 5, 'self.SimR_ALU2(' + str(n) + ')']) # Rn+1->ALU2 - self.SimInstrCtrl.appendleft(['000011', 5, 'self.SimSigCtrl_ALU']) # SigCtrl->ALU - - self.SimInstrCtrl.appendleft(['000011', 6, 'self.SimALU_R("+",' + str(n) + ')']) # ALU->Rn,并计算Rn+Rn+1 - self.SimInstrCtrl.appendleft(['000011', 6, 'self.ShowSimAddr(' + str(n) + ')']) # 输出信息到综合输出框 - - def SimProduct(self, n): - # 乘法指令000100 - self.SimInstrCtrl.appendleft(['000100', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000100', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['000100', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['000100', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['000100', 4, 'self.SimMcontent_R(' + str(n + 1) + ')']) # Mcontent->Rn+1 - - self.SimInstrCtrl.appendleft(['000100', 5, 'self.SimR_ALU1(' + str(n) + ')']) # Rn->ALU1 - self.SimInstrCtrl.appendleft(['000100', 5, 'self.SimR_ALU2(' + str(n) + ')']) # Rn+1->ALU2 - self.SimInstrCtrl.appendleft(['000100', 5, 'self.SimSigCtrl_ALU']) # SigCtrl->ALU - - self.SimInstrCtrl.appendleft(['000100', 6, 'self.SimALU_R("*",' + str(n) + ')']) # ALU->Rn,并计算Rn*Rn+1 - self.SimInstrCtrl.appendleft(['000100', 6, 'self.ShowSimAddr(' + str(n) + ')']) # 输出信息到综合输出框 - - def __init__(self): - self.out = '' - self.play = 0 - self.SimInstrCtrl = collections.deque() - - - - def solve_step(self): - ''' - 解析一条指令 - 并将解析后的步骤加入到self.SimInstrCtrl中 - :return: - ''' - if self.play == 0: - return - self.auto_display()# 更新自动运行面板 - code = cpu.code# 读取当前指令 - if code == 0:# 000000取指令 - self.get() - elif code % 16 == 1:# 000001取数指令(R1) - self.SimGet(code // 16) - elif code % 16 == 2:# 000010存数指令(R1) - self.SimPut(code // 16) - elif code % 16 == 3:# 000011加法指令 - self.SimAddr(code // 16) - elif code % 16 == 4:# 000100乘法指令 - self.SimProduct(code // 16) - elif code == 5:# 打印指令000101 - self.SimPrint() - elif code == 6:# 停机指令000110 - self.SimStop() - elif code % 16 == 7:# 000111减法指令 op = 1(R1) - self.SimMinus(code // 16) - elif code % 16 == 8:# 001000除法指令 op = 3(R1) - self.SimDiv(code // 16) - elif code == 9:# 001001跳转指令Simgoto - self.SimGoto() - else:#无法解析指令视为停机指令 - self.SimStop() - # 更新画布 - si.init(cv, root) - self.step_run()#开始执行指令 - - - - - def out_clear(self): - self.out = '' - self.auto_display() - - def PC_Maddr(self): - # PC_SIG - line.mark(['PC_SIG']) - PC = cpu.PC() - code = 0 - for i in range(6): - code *= 2 - code += int(PC[i]) - cpu.code = code - si.init(cv, root) - - line.mark(['PC_MAD']) - time.sleep(cpu.time) - PC = cpu.PC() - sum = 0 - for i in range(11): - if PC[i + 6] == ' ': - continue - sum *= 2 - sum += int(PC[i + 6]) - cpu.MAD_int = sum - mem.show(cv, root) - si.init(cv, root) - - def SimSigCtrl_Memory(self): - # 将地址传到MAD并且SIG发出信号 - si.MEM(cv, 1) - line.mark(['SIG_MEM']) - time.sleep(cpu.time) - si.MEM(cv, 0) - - def SimMaddr_Memory(self): - # 将MAD指定地址的内容取到MCO中 - num = cpu.MAD_int - line.mark(["MAD_MEM"]) - for j in range(20): - cpu.SimMARK[j] = False - cpu.SimMARK[num] = True - mem.mark(cv) - cpu.SimMARK[num] = False - mem.mark(cv) - - def SimMemory_Mcontent(self): - line.mark(["MEM_MCO"]) - cpu.MCO_int = cpu.str_int(cpu.SimMem[cpu.MAD_int]) - mem.show(cv, root) - - def SimSigCtrl_IR(self): - si.IR(cv, 1) - line.mark(['SIG_IR']) - time.sleep(cpu.time) - si.IR(cv, 0) - - def SimMcontent_IR(self): - line.mark(['MCO_IR']) - cpu.IR_int = cpu.MCO_int - si.init(cv, root) - cl.init(cv, root) - - def SimIR_SigCtrl(self): - line.mark(['IR_SIG']) - time.sleep(cpu.time) - IR = cpu.IR() - code = 0 - for i in range(6): - code *= 2 - code += int(IR[i]) - # print(code) - cpu.code = code - si.init(cv, root) - - def SimPC_1(self): - # PC+1 - si.PC(cv, 1) - time.sleep(cpu.time) - line.mark(['SIG_PC']) - time.sleep(cpu.time) - si.PC(cv, 0) - cpu.PC_int += 1 - cl.init(cv, root) - - def Showget(self): - self.out += '取指令:' + '\n' + cpu.CODE() + '\n' # 添加打印信息到综合输出框 - self.auto_display() # 显示输出信息 - - - def SimIR_Maddr(self): - line.mark(['IR_MAD']) - IR = cpu.IR() - sum = 0 - for i in range(11): - if IR[i + 6] == ' ': - continue - sum *= 2 - sum += int(IR[i + 6]) - # 将IR的后六位(操作对应的存储单元地址)取到Maddr中 - cpu.MAD_int = sum - - mem.show(cv, root) - si.init(cv, root) - - def SimSigCtrl_R(self, n): - # SIG通知R1接受数据 - eval('si.R' + str(n + 1) + '(cv, 1)') - eval("line.mark(['SIG_R" + str(n + 1) + "', 'MCO_R" + str(n + 1) + "'])") - time.sleep(cpu.time) - eval('si.R' + str(n + 1) + '(cv, 0)') - si.init(cv, root) - - def SimMcontent_R(self, n): - # 将Mcontent中的数字存到R中 - cpu.R_int[n] = cpu.MCO_int - alu.init(cv, root) - - def ShowSimget(self, n): - # 输出信息到综合输出框 - self.out += '取数指令:' + '\n' - self.out += 'SimMem[' + str(cpu.MAD_int) + '] -> R' + str(n + 1) + '\n' - cpu.code = 0 - - - - def SimR_Mcontent(self, n): - # R1->MCO - eval('line.mark(["R' + str(n + 1) + '_MCO"])') - # line.mark(["R1_MCO"]) - cpu.MCO_int = cpu.R_int[n] - mem.show(cv, root) - alu.init(cv, root) - - def SimMcontent_Memory(self): - time.sleep(cpu.time) - line.mark(["MCO_MEM"]) - - cpu.SimMem[cpu.MAD_int] = bin(cpu.MCO_int).replace('0b', '').zfill(16) - mem.show(cv, root) - time.sleep(cpu.time) - cpu.SimMARK[cpu.MAD_int] = False - mem.mark(cv) - - def ShowSimPut(self, n): - # 输出信息到综合输出框 - self.out += '存数指令:' + '\n' - self.out += 'R' + str(n + 1) + ' -> SimMem[' + str(cpu.MAD_int) + ']' + '\n' - cpu.code = 0 - - - - def SimR_ALU1(self, n): - # 高亮显示R1->ALU - eval('alu.mark(["R' + str(n + 1) + '_ALU1"])') - - def SimR_ALU2(self, n): - # 高亮显示R2->ALU - eval('alu.mark(["R' + str(n + 2) + '_ALU2"])') - - def SimSigCtrl_ALU(self): - # SIG向ALU运算器发出指令 - si.ALU(cv, 1) - line.mark(["SIG_ALU"]) - time.sleep(cpu.time) - si.ALU(cv, 0) - - def SimALU_R(self, op, n): - #op运算符 - #n存储器 - eval('alu.mark(["ALU_R' + str(n + 1) + '"])') - # alu.mark(["ALU_R1"]) - time.sleep(cpu.time) - # 将运算结果存入R1中 - - cpu.R_int[n] = eval('cpu.R_int[n]' + op + 'cpu.R_int[n + 1]') - alu.init(cv, root) - - - def ShowSimAddr(self, n): - # 输出信息到综合输出框 - self.out += '加法指令:' + '\n' - self.out += 'R' + str(n + 1) + ' + R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' - cpu.code = 0 - - - def ShowSimProduct(self, n): - # 输出信息到综合输出框 - self.out += '乘法指令:' + '\n' - self.out += 'R' + str(n + 1) + ' x R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' - cpu.code = 0 - - - - def ShowPrint(self): - # 添加信息到综合输出框 - self.out += '打印指令:' + '\n' - self.out += cpu.MCO() + '\n' - cpu.code = 0 - - def SimPrint(self): - # 打印指令000101 - self.SimInstrCtrl.appendleft(['000101', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000101', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['000101', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['000101', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - - self.SimInstrCtrl.appendleft(['000101', 4, 'self.ShowPrint()']) - - def ShowStop(self): - self.out += '停机指令:\n' - self.out += '停机\n' - cpu.__init__() - self.play = 0 - cpu.code = 0 - - def SimStop(self): - # 停机指令000110 - self.SimInstrCtrl.appendleft(['000110', 4, 'self.ShowStop()']) - - def ShowSimMinus(self, n): - # 输出信息到综合输出框 - self.out += '减法指令:' + '\n' - self.out += 'R' + str(n + 1) + ' - R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' - cpu.code = 0 - - def SimMinus(self, n): - # 减法指令000111 - self.SimInstrCtrl.appendleft(['000111', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['000111', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['000111', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['000111', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['000111', 4, 'self.SimMcontent_R(' + str(n + 1) + ')']) # Mcontent->Rn+1 - - self.SimInstrCtrl.appendleft(['000111', 5, 'self.SimR_ALU1(' + str(n) + ')']) # Rn->ALU1 - self.SimInstrCtrl.appendleft(['000111', 5, 'self.SimR_ALU2(' + str(n) + ')']) # Rn+1->ALU2 - self.SimInstrCtrl.appendleft(['000111', 5, 'self.SimSigCtrl_ALU']) # SigCtrl->ALU - - self.SimInstrCtrl.appendleft(['000111', 6, 'self.SimALU_R("-",' + str(n) + ')']) # ALU->Rn,并计算Rn-Rn+1 - self.SimInstrCtrl.appendleft(['000111', 6, 'self.ShowSimMinus(' + str(n) + ')']) # 输出信息到综合输出框 - - def ShowSimDiv(self, n): - # 输出信息到综合输出框 - self.out += '除法指令:' + '\n' - self.out += 'R' + str(n + 1) + ' / R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' - cpu.code = 0 - - def SimDiv(self, n): - # 除法指令001000 - self.SimInstrCtrl.appendleft(['001000', 3, 'self.SimIR_Maddr()']) # IR->Maddr - self.SimInstrCtrl.appendleft(['001000', 3, 'self.SimSigCtrl_Memory()']) # SigCtrl->Memory - self.SimInstrCtrl.appendleft(['001000', 4, 'self.SimMaddr_Memory()']) # Maddr_Memory - self.SimInstrCtrl.appendleft(['001000', 4, 'self.SimMemory_Mcontent()']) # Memory->Mcontent - self.SimInstrCtrl.appendleft(['001000', 4, 'self.SimMcontent_R(' + str(n + 1) + ')']) # Mcontent->Rn+1 - - self.SimInstrCtrl.appendleft(['001000', 5, 'self.SimR_ALU1(' + str(n) + ')']) # Rn->ALU1 - self.SimInstrCtrl.appendleft(['001000', 5, 'self.SimR_ALU2(' + str(n) + ')']) # Rn+1->ALU2 - self.SimInstrCtrl.appendleft(['001000', 5, 'self.SimSigCtrl_ALU']) # SigCtrl->ALU - - self.SimInstrCtrl.appendleft(['001000', 6, 'self.SimALU_R("/",' + str(n) + ')']) # ALU->Rn,并计算Rn/Rn+1 - self.SimInstrCtrl.appendleft(['001000', 6, 'self.ShowSimDiv(' + str(n) + ')']) # 输出信息到综合输出框 - - def SimSigCtrl_PC(self): - # SIG通知PC接受数据 - si.PC(cv, 1) - line.mark(['SIG_PC']) - time.sleep(cpu.time) - si.PC(cv, 0) - - def SimMcontent_PC(self): - line.mark(['MCO_PC']) - cpu.PC_int = cpu.MCO_int - si.init(cv, root) - - def ShowSimGoto(self): - # 添加信息到综合输出框 - self.out += '跳转指令:' + '\n' - self.out += 'SimMem[' + str(cpu.MAD_int) + ']' + '\n' - cpu.code = 0 - - - - def Begin_step(self): - self.play = 1 - self.step_run() - - # 执行一条指令(不仅改变寄存器,并且使得信号线高亮显示) - - - def Begin(self): - self.play = 1 - self.exec_instruct_with_anim() - - def auto_display(self): - # 自动运行窗口 - for w in root_right.winfo_children(): - w.destroy() - # 清除右侧组件 - lab = tk.Label(root_right, text="执行指令(带UI)", bg=WHITE, fg=BLACK, font=('微软雅黑', 18)) - lab.place(relx=0, rely=0.02, width=250, height=30) - y0 = 0.1 - start = tk.Button(root_right, text="自动运行程序(连续)", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), - command=lambda: self.Begin()) - start.place(relx=0.1, rely=0.0 + y0, width=200, height=30) - start = tk.Button(root_right, text="自动运行程序(分节拍)", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), - command=lambda: self.Begin_step()) - start.place(relx=0.1, rely=0.05 + y0, width=200, height=30) - lab = tk.Label(root_right, text="当前节拍:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.1 + y0, width=120, height=30) - clo = 0 - for i in range(6): - if cpu.clo[i]: - clo = i - break - lab2 = tk.Label(root_right, text=str(clo + 1), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.4, rely=0.1 + y0, width=50, height=30) - - y0 += 0.1 - lab = tk.Label(root_right, text="当前操作码:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.1 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=cpu.CODE(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.15 + y0, width=200, height=30) - command = ['取指令', '取数指令', '存数指令', '加法指令', '乘法指令', '打印指令', '停机指令', '减法指令', - '除法指令', '跳转指令'] - lab = tk.Label(root_right, text="正在执行指令:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.2 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=command[cpu.code % 16], bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.25 + y0, width=200, height=30) - lab = tk.Label(root_right, text="综合输出框:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.3 + y0, width=120, height=30) - scr = scrolledtext.ScrolledText(root_right, fg=BLACK, font=('微软雅黑', 12,)) - scr.place(relx=0.1, rely=0.35 + y0, width=200, height=300) - scr.insert('end', self.out) # 末尾插入 - scr.config(state=DISABLED) # 设置文本框为 “不能编辑” - scr.see(END) # 设置视图为最后一行 - B = tk.Button(root_right, text="清空", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), - command=lambda: self.out_clear()) - B.place(relx=0.5, rely=0.3 + y0, width=50, height=30) - - - - def get_mem(self, num): - # 将MAD指定地址的内容取到MCO中 - line.mark(["MAD_MEM"]) - for j in range(20): - cpu.SimMARK[j] = False - cpu.SimMARK[num] = True - mem.mark(cv) - cpu.SimMARK[num] = False - mem.mark(cv) - -def exec_test_program(): - Program = [ - '0000010000001000', - '0000110000001010', - '0001000000001001', - '0001000000001000', - '0000110000001011', - '0000100000001100', - '0001010000001100', - '0001100000000000', - '0000000000000101', - '0000000000001001', - '0000000000000110', - '0000000000001000' - ] # 输入题目要求的程序 - - for i in range(len(Program)): - cpu.SimMem[i] = Program[i] # 将上述程序装载入仿真存储器中 - - cpu.PC_int = 0 # 设置PC值为“00000000 00000000” - init(cv) # 初始化cpu - a = ExecInstructWithAnim() - a.auto_display() - root.mainloop() - - -if __name__ == '__main__': - cpu.time = 0.1 - exec_test_program() - - - - diff --git a/ExecInstructWithText.py b/ExecInstructWithText.py deleted file mode 100644 index fdd7ea6..0000000 --- a/ExecInstructWithText.py +++ /dev/null @@ -1,429 +0,0 @@ -# -*- encoding: utf-8 -*- -""" - @Author: packy945 - @FileName: ExecInstructWithText.py - @DateTime: 2023/6/30 16:49 - @SoftWare: PyCharm -""" - -from RightPanel import * -from tkinter import scrolledtext - - -class ExecInstructWithText: - def __init__(self): - self.out = '' # 初始化综合输出框 - self.play = 0 # 初始化程序运行状态 - - def SimDiv(self, n): - # 除法指令001000 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - self.SimSIG_Rn(n + 2) # SIG通知R2接受数据 - - # 开始计算 - self.clock(5) # 第五个节拍 - self.SimR_ALU(n) # R1 R2 进入ALU中 - - self.clock(6) # 第六个节拍 - ans = cpu.R_int[n] // cpu.R_int[n + 1] # 进行计算 - self.SimANS_Rn(ans, n) # ALU将计算结果存到R[n] - - self.out += '除法指令:' + '\n' # 输出信息到综合输出框 - self.out += 'R' + str(n + 1) + ' / R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' # 输出信息到综合输出框 - - def SimMinus(self, n): - # 减法指令000111 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - self.SimSIG_Rn(n + 2) # SIG通知R2接受数据 - - # 开始计算 - self.clock(5) # 第五个节拍 - self.SimR_ALU(n) # R1 R2 进入ALU中 - - self.clock(6) # 第六个节拍 - ans = cpu.R_int[n] - cpu.R_int[n + 1] # 进行计算 - self.SimANS_Rn(ans, n) # ALU将计算结果存到R[n] - - self.out += '减法指令:' + '\n' # 输出信息到综合输出框 - self.out += 'R' + str(n + 1) + ' - R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' # 输出信息到综合输出框 - - def SimStop(self): - # 停机指令000110 - self.out += '停机指令:\n' + '停机\n' # 添加打印信息到综合输出框 - cpu.__init__() # 重置cpu各项数据 - init(cv) # 显示复位 - self.play = 0 # 标记为未运行 - self.auto_display() # 显示输出信息 - - def Simprint(self): - # 打印指令000101 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - - self.out += '打印指令:' + '\n' + cpu.MCO() + '\n' # 添加打印信息到综合输出框 - self.auto_display() # 显示输出信息 - - def SimProduct(self, n): - # 乘法指令000100 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - self.SimSIG_Rn(n + 2) # SIG通知R2接受数据 - - # 开始计算 - self.clock(5) # 第五个节拍 - self.SimR_ALU(n) # R1 R2 进入ALU中 - - self.clock(6) # 第六个节拍 - ans = cpu.R_int[n] * cpu.R_int[n + 1] # 进行计算 - self.SimANS_Rn(ans, n) # ALU将计算结果存到R[n] - - self.out += '乘法指令:' + '\n' # 输出信息到综合输出框 - self.out += 'R' + str(n + 1) + ' x R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' # 输出信息到综合输出框 - - def SimAddr(self, n): - # 加法指令000011 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - self.SimSIG_Rn(n + 2) # SIG通知Rn+1接受数据 - - # 开始计算 - self.clock(5) # 第五个节拍 - self.SimR_ALU(n) # R[n] R[n+1] 进入ALU中 - - self.clock(6) # 第六个节拍 - # 记录计算结果到ans中 - ans = cpu.R_int[n] + cpu.R_int[n + 1] - self.SimANS_Rn(ans, n) # ALU将计算结果存到Rn - - self.out += '加法指令:' + '\n' # 输出信息到综合输出框 - self.out += 'R' + str(n + 1) + ' + R' + str(n + 2) + ' -> R' + str(n + 1) + '\n' # 输出信息到综合输出框 - - def SimPut(self, n): - # 000010存数指令(R1) - # 010010存数指令(R2) - # 100010存数指令(R3) - # 110010存数指令(R4) - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.mark_MEM() # 标记MAD对应的存储单元 - self.SinRn_MCO(n) # Rn->MCO - self.SimMCO_MEM() # MCO->对应的存储单元 - - self.out += '存数指令:' + '\n' # 输出信息到综合输出框 - self.out += 'R' + str(n + 1) + ' -> SimMem[' + str(cpu.MAD_int) + ']' + '\n' # 输出信息到综合输出框 - - def SimGet(self, n): - # 000001取数指令(R1) n = 0 - # 010001取数指令(R2) n = 1 - # 100001取数指令(R3) n = 2 - # 110001取数指令(R4) n = 3 - self.clock(3) # 第三个节拍 - self.SimIR_MAD() # 将地址从IR传到MAD并且SIG发出信号 - - self.clock(4) # 第四个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - - self.SimSIG_Rn(n + 1) # SIG通知R1接受数据 - - self.out += '取数指令:' + '\n' # 输出信息到综合输出框 - self.out += 'SimMem[' + str(cpu.MAD_int) + '] -> R' + str(n + 1) + '\n' # 输出信息到综合输出框 - - def clock(self, n): - cpu.CLO(n - 1) # 更改cpu内时钟刻的信息 - cl.clo_mark(cv) # 根据cpu显示时钟刻 - time.sleep(cpu.time) # 定格一段时间 - - def print_mark(self, lines): - for l in lines: # 遍历要输出的线的信息 - self.out += l.replace('_', '->') + '\n' # 将信息显示到综合输出框 - self.auto_display() # 显示综合输出框 - time.sleep(cpu.time) # 定格一段时间 - - def auto_display(self): - # 自动运行窗口 - for w in root_right.winfo_children(): - w.destroy() - # 清除右侧组件 - # 右侧窗口标题 - lab = tk.Label(root_right, text="执行指令(仅寄存器)", bg=WHITE, fg=BLACK, font=('微软雅黑', 18)) - lab.place(relx=0, rely=0.02, width=250, height=30) - y0 = 0.1 - # 开始运行程序按钮 - start = tk.Button(root_right, text="自动运行程序", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), - command=lambda: self.exec_instruct_with_text()) - start.place(relx=0.1, rely=0.05 + y0, width=200, height=30) - if self.play == 1: - start['state'] = DISABLED - else: - start['state'] = NORMAL - # 显示当时正在进行的操作码(INSCODE) - lab = tk.Label(root_right, text="当前操作码:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.1 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=cpu.CODE(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.15 + y0, width=200, height=30) - # 显示当时正在进行的操作名称 - command = ['取指令', '取数指令', '存数指令', '加法指令', '乘法指令', '打印指令', '停机指令', '减法指令', - '除法指令', '跳转指令'] - lab = tk.Label(root_right, text="正在执行指令:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.2 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=command[cpu.code % 16], bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.25 + y0, width=200, height=30) - # 综合输出框,进行打印指令与停机指令的相应输出 - lab = tk.Label(root_right, text="综合输出框:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.3 + y0, width=120, height=30) - - scr = scrolledtext.ScrolledText(root_right, fg=BLACK, font=('微软雅黑', 12,)) - scr.place(relx=0.1, rely=0.35 + y0, width=200, height=300) - scr.insert('end', self.out) # 末尾插入 - scr.config(state=DISABLED) # 设置文本框为 “不能编辑” - scr.see(END) # 设置视图为最后一行 - - # lab2 = tk.Label(root_right, text=self.out, bg=BLUE, fg=BLACK, font=('微软雅黑', 12), anchor=N) - # lab2.place(relx=0.1, rely=0.35 + y0, width=200, height=150) - # 清空中和输出框按钮 - B = tk.Button(root_right, text="清空", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), - command=lambda: self.out_clear()) - B.place(relx=0.5, rely=0.3 + y0, width=50, height=30) - - def out_clear(self): - self.out = '' - self.auto_display() - - # 执行一条指令 - def exec_instruct_with_text(self): - while 1: - self.play = 1 # 更新系统状态为正在运行 - self.auto_display() # 显示自动执行的输出框 - self.get() # 执行取数指令(时钟前2个节拍) - code = cpu.code # 读取当前指令 - self.auto_display() # 显示自动执行的输出框 - - if code % 16 == 1: # 000001取数指令(R1) - self.SimGet(code // 16) - elif code % 16 == 2: # 000010存数指令(R1) - self.SimPut(code // 16) - elif code % 16 == 3: # 000011加法指令 op = 0(R1) - self.SimAddr(code // 16) - elif code % 16 == 4: # 000100乘法指令 op = 2 - self.SimProduct(code // 16) - elif code == 5: # 打印指令000101 - self.Simprint() - elif code == 6: # 停机指令000110 - self.SimStop() - break - elif code % 16 == 7: # 000111减法指令 op = 1 - self.SimMinus(code // 16) - elif code % 16 == 8: # 001000除法指令 op = 3 - self.SimDiv(code // 16) - else: - self.SimStop() - break - cpu.code = 0 # 更新指令为取数指令 - si.init(cv, root) - - def SimIR_MAD(self): - si.MEM(cv, 1) - self.print_mark(['IR_MAD', 'SIG_MEM']) - time.sleep(cpu.time) - si.MEM(cv, 0) - - IR = cpu.IR() - sum = 0 - for i in range(11): - if IR[i + 6] == ' ': - continue - sum *= 2 - sum += int(IR[i + 6]) - cpu.MAD_int = sum - mem.show(cv, root) - si.init(cv, root) - - def SimMEM_MCO(self): - cpu.MCO_int = cpu.str_int(cpu.SimMem[cpu.MAD_int]) - mem.show(cv, root) - - def SimPC_SIG(self): - self.print_mark(['PC_SIG']) - PC = cpu.PC() - code = 0 - for i in range(6): - code *= 2 - code += int(PC[i]) - cpu.code = code - si.init(cv, root) - - def SimPC_MAD(self): - PC = cpu.PC() - sum = 0 - for i in range(11): - if PC[i + 6] == ' ': - continue - sum *= 2 - sum += int(PC[i + 6]) - cpu.MAD_int = sum - mem.show(cv, root) - si.init(cv, root) - - def SimMCO_IR(self): - time.sleep(cpu.time) - si.IR(cv, 1) - self.print_mark(['MCO_IR', 'SIG_IR']) - time.sleep(cpu.time) - si.IR(cv, 0) - - cpu.IR_int = cpu.MCO_int - si.init(cv, root) - cl.init(cv, root) - - def SimIR_SIG(self): - self.print_mark(['IR_SIG']) - time.sleep(cpu.time) - IR = cpu.IR() - code = 0 - for i in range(6): - code *= 2 - code += int(IR[i]) - # print(code) - cpu.code = code - si.init(cv, root) - - def PC_1(self): - si.PC(cv, 1) - time.sleep(cpu.time) - self.print_mark(['SIG_PC']) - time.sleep(cpu.time) - si.PC(cv, 0) - cpu.PC_int += 1 - cl.init(cv, root) - - def SimSIG_MAD(self): - si.MEM(cv, 1) - self.print_mark(['PC_MAD', 'SIG_MEM']) - time.sleep(cpu.time) - si.MEM(cv, 0) - - def get(self): # 000000为取指令 - self.clock(1) # 第一个节拍 - self.SimPC_SIG() # PC->SIG - self.SimSIG_MAD() # 将地址传到MAD并且SIG发出信号 - self.SimPC_MAD() # PC传参数给MAD - self.clock(2) # 第二个节拍 - self.get_mem(cpu.MAD_int) # 将MAD指定地址的内容取到MCO中 - self.SimMCO_IR() # mco把值传给IR - self.SimIR_SIG() # IR把CODE值传给SIG - self.clock(3) # 第三个节拍 - self.PC_1() # PC+1 - self.out += '取指令:' + '\n' + cpu.CODE() + '\n' # 添加打印信息到综合输出框 - self.auto_display() # 显示输出信息 - - def SimSIG_Rn(self, n): - # SIG->R[n] - eval('si.R' + str(n) + '(cv, 1)') - eval("self.print_mark(['SIG_R" + str(n) + "', 'MCO_R" + str(n) + "'])") - time.sleep(cpu.time) - eval('si.R' + str(n) + '(cv, 0)') - si.init(cv, root) - # 将Mcontent中的数字存到R中 - cpu.R_int[n - 1] = cpu.MCO_int - alu.init(cv, root) - - def mark_MEM(self): - self.print_mark(["MAD_MEM"]) - for j in range(20): - cpu.SimMARK[j] = False - cpu.SimMARK[cpu.MAD_int] = True - mem.mark(cv) - - def SinRn_MCO(self, n): - eval('self.print_mark(["R' + str(n + 1) + '_MCO"])') - # self.print_mark(["R1_MCO"]) - cpu.MCO_int = cpu.R_int[n] - mem.show(cv, root) - alu.init(cv, root) - time.sleep(cpu.time) - self.print_mark(["MCO_MEM"]) - - def SimMCO_MEM(self): - cpu.SimMem[cpu.MAD_int] = bin(cpu.MCO_int).replace('0b', '').zfill(16) - mem.show(cv, root) - time.sleep(cpu.time) - cpu.SimMARK[cpu.MAD_int] = False - mem.mark(cv) - - def SimR_ALU(self, n): - # 高亮显示R1->ALU, R2->ALU - eval('self.print_mark(["R' + str(n + 1) + '_ALU1", "R' + str(n + 2) + '_ALU2"])') - time.sleep(cpu.time) - alu.init(cv, root) - time.sleep(cpu.time) - # SIG向ALU运算器发出指令 - self.print_mark(["SIG_ALU"]) - - def SimANS_Rn(self, ans, n): - eval('self.print_mark(["ALU_R' + str(n + 1) + '"])') - time.sleep(cpu.time) - # 将运算结果存入R1中 - cpu.R_int[n] = ans - alu.init(cv, root) - - def get_mem(self, num): - # 将MAD指定地址的内容取到MCO中 - self.print_mark(["MAD_MEM"]) - for j in range(20): - cpu.SimMARK[j] = False - cpu.SimMARK[num] = True - mem.mark(cv) - self.print_mark(["MEM_MCO"]) - self.SimMEM_MCO() - cpu.SimMARK[num] = False - mem.mark(cv) - - -def exec_test_program(): - Program = [ - '0000010000001000', - '0000110000001010', - '0001000000001001', - '0001000000001000', - '0000110000001011', - '0000100000001100', - '0001010000001100', - '0001100000000000', - '0000000000000101', - '0000000000001001', - '0000000000000110', - '0000000000001000' - ] # 输入题目要求的程序 - - for i in range(len(Program)): - cpu.SimMem[i] = Program[i] # 将上述程序装载入仿真存储器中 - - cpu.PC_int = 0 # 设置PC值为“00000000 00000000” - init(cv) # 初始化cpu - run_text = ExecInstructWithText() # 实例化类 - run_text.auto_display() # 开始执行完整一段程序 - root.mainloop() # 执行可视化 - - -if __name__ == "__main__": - cpu.time = 0.05 - exec_test_program() diff --git a/LICENSE b/LICENSE deleted file mode 100644 index baee873..0000000 --- a/LICENSE +++ /dev/null @@ -1,170 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International - - Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. - -Using Creative Commons Public Licenses - -Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. - -Considerations for licensors: Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. More considerations for licensors. - -Considerations for the public: By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. More considerations for the public. - -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -Section 1 – Definitions. - - a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. - - b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. - - c. BY-NC-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License. - - d. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. - - e. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. - - f. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. - - g. License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. - - h. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. - - i. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. - - j. Licensor means the individual(s) or entity(ies) granting rights under this Public License. - - k. NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. - - l. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. - - m. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. - - n. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. - -Section 2 – Scope. - - a. License grant. - - 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: - - A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and - - B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. - - 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. - - 3. Term. The term of this Public License is specified in Section 6(a). - - 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. - - 5. Downstream recipients. - - A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. - - B. Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. - - C. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. - - 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). - - b. Other rights. - - 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. - - 2. Patent and trademark rights are not licensed under this Public License. - - 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. - -Section 3 – License Conditions. - -Your exercise of the Licensed Rights is expressly made subject to the following conditions. - - a. Attribution. - - 1. If You Share the Licensed Material (including in modified form), You must: - - A. retain the following if it is supplied by the Licensor with the Licensed Material: - - i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); - - ii. a copyright notice; - - iii. a notice that refers to this Public License; - - iv. a notice that refers to the disclaimer of warranties; - - v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; - - B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and - - C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. - - 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. - - 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. - - b. ShareAlike.In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. - - 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. - - 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. - - 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. - -Section 4 – Sui Generis Database Rights. - -Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: - - a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; - - b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and - - c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. -For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. - -Section 5 – Disclaimer of Warranties and Limitation of Liability. - - a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. - - b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. - - c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. - -Section 6 – Term and Termination. - - a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. - - b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: - - 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or - - 2. upon express reinstatement by the Licensor. - - For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. - - c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. - - d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. - -Section 7 – Other Terms and Conditions. - - a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. - - b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. - -Section 8 – Interpretation. - - a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. - - b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. - - c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. - - d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. - -Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. - -Creative Commons may be contacted at creativecommons.org. diff --git a/Print.py b/Print.py deleted file mode 100644 index 0d5a0c7..0000000 --- a/Print.py +++ /dev/null @@ -1,463 +0,0 @@ -from UI import * -# import tkinter as tk - - -class Print_line: - def show(self): - lines = ['PC_MAD', 'SIG_MEM', 'SIG_IR', 'IR_SIG', 'IR_MCO', 'MCO_IR', 'MCO_MEM', 'MEM_MCO', 'MAD_MEM', - 'PC_SIG', 'SIG_PC', 'MCO_PC', 'IR_MAD', 'SIG_R1', 'SIG_R2', 'SIG_R3', 'SIG_R4', 'MCO_R1', - 'MCO_R2', 'MCO_R3', 'MCO_R4', 'R1_MCO', 'R2_MCO', 'R3_MCO', 'R4_MCO', 'SIG_ALU'] - for l in lines: - if cpu.SigObj[l][1] == False: - eval('self.' + l + '(cv, -1)') - for l in lines: - if cpu.SigObj[l][1] == True: - eval('self.' + l + '(cv, 1)') - - # print(cpu.SigObj[l][1]) - - def all(self): - lines = ['PC_MAD', 'SIG_MEM', 'SIG_IR', 'IR_SIG', 'IR_MCO', 'MCO_IR', 'MCO_MEM', 'MEM_MCO', 'MAD_MEM', - 'PC_SIG', 'SIG_PC', 'MCO_PC', 'IR_MAD', 'SIG_R1', 'SIG_R2', 'SIG_R3', 'SIG_R4', 'MCO_R1', - 'MCO_R2', 'MCO_R3', 'MCO_R4', 'R1_MCO', 'R2_MCO', 'R3_MCO', 'R4_MCO', 'SIG_ALU'] - for l in lines: - eval('self.' + l + '(cv, 1)') - - def init(self): - lines = ['PC_MAD', 'SIG_MEM', 'SIG_IR', 'IR_SIG', 'IR_MCO', 'MCO_IR', 'MCO_MEM', 'MEM_MCO', 'MAD_MEM', - 'PC_SIG', 'SIG_PC', 'MCO_PC', 'IR_MAD', 'SIG_R1', 'SIG_R2', 'SIG_R3', 'SIG_R4', 'MCO_R1', - 'MCO_R2', 'MCO_R3', 'MCO_R4', 'R1_MCO', 'R2_MCO', 'R3_MCO', 'R4_MCO', 'SIG_ALU'] - # for l in lines: - # eval('self.' + l + '(cv, 0)') - for l in lines: - eval('self.' + l + '(cv, -1)') - - - def mark(self, lines): - for i in range(5): - if i: - time.sleep(cpu.time) - if i % 2: - for l in lines: - # print('self.' + l + '(cv, 1)') - # self.init() - eval('self.' + l + '(cv, 1)') - else: - for l in lines: - # print('self.' + l + '(cv, 0)') - # self.init() - eval('self.' + l + '(cv, -1)') - cv.update() - - - def PC_MAD(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(500, 469 + 4.5, 480 + 120 + 12, 469 + 4.5, width=9, arrow=LAST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(500, 469 + 4.5, 480 + 120 + 12, 469 + 4.5, width=9, arrow=LAST, capstyle=ROUND, fill=NOMARK) - cv.update() - def SIG_MEM(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(185 + 4.5, 635, 185 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(185 + 4.5, 660, 635, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(635, 550 - 5, 635, 660, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(185 + 4.5, 635, 185 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(185 + 4.5, 660, 635, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(635, 550 - 5, 635, 660, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def SIG_IR(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(281 + 10, 575 + 4.5, 334, 575 + 4.5, width=9, arrow=LAST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(281 + 10, 575 + 4.5, 334, 575 + 4.5, width=9, arrow=LAST, capstyle=ROUND, fill=NOMARK) - cv.update() - - def IR_SIG(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(281, 575 + 4.5, 334 - 10, 575 + 4.5, width=9, arrow=FIRST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(281, 575 + 4.5, 334 - 10, 575 + 4.5, width=9, arrow=FIRST, capstyle=ROUND, fill=NOMARK) - cv.update() - - def IR_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(500, 580, 580, 580, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 180 + 4.5, 580, 580, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(500, 580, 580, 580, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 580, 580, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def MCO_IR(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(490, 580, 580, 580, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - cv.create_line(580, 180 + 4.5, 580, 580, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=color1) - - else: - cv.create_line(490, 580, 580, 580, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 580, 580, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.update() - - def MCO_MEM(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(780, 245, 780, 273, width=9, capstyle=ROUND, arrow=LAST, fill=color1) - - else: - cv.create_line(780, 245, 780, 273, width=9, capstyle=ROUND, arrow=LAST, fill=NOMARK) - - cv.update() - - def MEM_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(820, 245, 820, 273, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(820, 245, 820, 273, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - - cv.update() - - def PC_SIG(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(230 + 5, 510, 230 + 5, 525, width=10, arrow=LAST, capstyle=ROUND, fill=color1) - cv.create_line(230 + 5, 505 + 5, 230 + 180, 505 + 5, width=10, capstyle=ROUND, fill=color1) - cv.create_line(405 + 5, 497, 405 + 5, 510, width=10, capstyle=ROUND, fill=color1) - - else: - cv.create_line(230 + 5, 510, 230 + 5, 525, width=10, arrow=LAST, capstyle=ROUND, fill=NOMARK) - cv.create_line(230 + 5, 505 + 5, 230 + 180, 505 + 5, width=10, capstyle=ROUND, fill=NOMARK) - cv.create_line(405 + 5, 497, 405 + 5, 510, width=10, capstyle=ROUND, fill=NOMARK) - cv.update() - - def SIG_PC(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(230 + 5, 510, 230 + 5, 518, width=10, capstyle=ROUND, fill=color1) - cv.create_line(230 + 5, 505 + 5, 230 + 180, 505 + 5, width=10, capstyle=ROUND, fill=color1) - cv.create_line(405 + 5, 490, 405 + 5, 490 + 20, width=10, arrow=FIRST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(230 + 5, 510, 230 + 5, 518, width=10, capstyle=ROUND, fill=NOMARK) - cv.create_line(230 + 5, 505 + 5, 230 + 180, 505 + 5, width=10, capstyle=ROUND, fill=NOMARK) - cv.create_line(405 + 5, 490, 405 + 5, 490 + 20, width=10, arrow=FIRST, capstyle=ROUND, fill=NOMARK) - cv.update() - - def IR_MAD(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(500, 580, 580, 580, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 510, 580, 580, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 510, 610, 510, width=9, capstyle=ROUND, fill=color1, arrow=LAST) - - else: - cv.create_line(500, 580, 580, 580, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 510, 580, 580, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 510, 610, 510, width=9, capstyle=ROUND, fill=NOMARK, arrow=LAST) - cv.update() - - def SIG_R1(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 30, 620, 103, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 103, 620, 103, width=10, arrow=FIRST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 30, 620, 103, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 103, 620, 103, width=10, arrow=FIRST, capstyle=ROUND, fill=NOMARK) - cv.update() - - def SIG_R2(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 30, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 190, 515, 190, width=9, capstyle=ROUND, arrow=LAST, fill=color1) - - else: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 30, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 190, 515, 190, width=9, capstyle=ROUND, arrow=LAST, fill=NOMARK) - cv.update() - - def SIG_R3(self, cv: tk.Canvas, flag): - if flag == 1: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 30, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 280, 550, 280, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 30, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 280, 550, 280, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def SIG_R4(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=color1) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 30, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(120 + 4.5, 635, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 660, 120 + 4.5, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 40, 660, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(40, 30, 620, 30, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 30, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def MCO_R1(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 103, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 103, 620, 103, width=10, arrow=FIRST, capstyle=ROUND, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 103, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 103, 620, 103, width=10, arrow=FIRST, capstyle=ROUND, fill=NOMARK) - cv.update() - - def R1_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=color1, arrow=FIRST) - cv.create_line(620, 145, 620, 103, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515 + 10, 103, 620, 103, width=10, capstyle=ROUND, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=NOMARK, arrow=FIRST) - cv.create_line(620, 145, 620, 103, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515 + 10, 103, 620, 103, width=10, capstyle=ROUND, fill=NOMARK) - cv.update() - - def MCO_R2(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 190, 515, 190, width=9, capstyle=ROUND, arrow=LAST, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 190, 515, 190, width=9, capstyle=ROUND, arrow=LAST, fill=NOMARK) - cv.update() - - def R2_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=color1, arrow=FIRST) - cv.create_line(620, 145, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=color1) - cv.create_line(538, 190, 525, 190, width=9, capstyle=ROUND, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=NOMARK, arrow=FIRST) - cv.create_line(620, 145, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 620, 120, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 120, 538, 190, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(538, 190, 525, 190, width=9, capstyle=ROUND, fill=NOMARK) - cv.update() - - def MCO_R3(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 280, 550, 280, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 280, 550, 280, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def R3_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=color1, arrow=FIRST) - cv.create_line(620, 145, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=color1) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=color1) - cv.create_line(525, 280, 550, 280, width=9, capstyle=ROUND, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=NOMARK, arrow=FIRST) - cv.create_line(620, 145, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 620, 140, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(550, 140, 550, 280, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(525, 280, 550, 280, width=9, capstyle=ROUND, fill=NOMARK) - cv.update() - - def MCO_R4(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=color1) - cv.create_line(515, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 10, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(515, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def R4_MCO(self,cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=color1, arrow=FIRST) - cv.create_line(620, 145, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=color1) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=color1) - cv.create_line(525, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - - else: - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 215, 770, 145, width=9, capstyle=ROUND, fill=NOMARK, arrow=FIRST) - cv.create_line(620, 145, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 620, 160, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(565, 160, 565, 370, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(525, 370, 565, 370, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.update() - - def SIG_ALU(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(85, 578, 55, 578, width=9, capstyle=ROUND, fill=color1) - cv.create_line(55, 232, 55, 578, width=9, capstyle=ROUND, fill=color1) - cv.create_line(55, 232, 90, 232, width=9, capstyle=ROUND, fill=color1, arrow=LAST) - - else: - cv.create_line(85, 578, 55, 578, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(55, 232, 55, 578, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(55, 232, 90, 232, width=9, capstyle=ROUND, fill=NOMARK, arrow=LAST) - cv.update() - - def MAD_MEM(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(635, 353, 635, 320, width=9, capstyle=ROUND, fill=color1) - cv.create_line(670, 320, 635, 320, width=9, capstyle=ROUND, fill=color1, arrow=FIRST) - - else: - cv.create_line(635, 353, 635, 320, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(670, 320, 635, 320, width=9, capstyle=ROUND, fill=NOMARK, arrow=FIRST) - cv.update() - - def MCO_PC(self, cv:tk.Canvas, flag): - if flag == 1: - cv.create_line(490, 469 + 4.5, 580, 469 + 4.5, width=9, capstyle=ROUND, arrow=FIRST, fill=color1) - cv.create_line(580, 180 + 4.5, 580, 469 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=color1) - cv.create_line(770, 220 - 15, 770, 145, width=9, capstyle=ROUND, fill=color1) - - else: - cv.create_line(490, 469 + 4.5, 580, 469 + 4.5, width=9, capstyle=ROUND, arrow=FIRST, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 580, 469 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(580, 180 + 4.5, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(620, 145, 620, 180 + 4.5, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 145, 620, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.create_line(770, 220 - 15, 770, 145, width=9, capstyle=ROUND, fill=NOMARK) - cv.update() - -if __name__ == '__main__': - from ALU import * - # al = ALU() - # al.init(cv, root) - - co = Print_line() - # co.all() - # co.init() - # co.MCO_IR(cv, 1) - cpu.SigObj['MCO_PC'][1] = True - cpu.SigObj['MCO_IR'][1] = True - # co.mark(['PC_SIG']) - co.show() - # co.mark(['SIG_PC']) - # co.init() - - - - def left1(event): - print(event.x,event.y) - cv.bind('', left1) - root.mainloop() - - - - diff --git a/RightPanel.py b/RightPanel.py deleted file mode 100644 index fb3cb5f..0000000 --- a/RightPanel.py +++ /dev/null @@ -1,478 +0,0 @@ -import tkinter - -from Print import Print_line -from ALU import ALU -from Clock import * -from SIG_ctrl import SIG -from memory import MEM - -#初始化 -cl = ClockStep() -alu = ALU() -si = SIG() -mem = MEM() -line = Print_line() -def init(cv:Canvas): - cl.init(cv, root) - alu.init(cv, root) - si.init(cv, root) - mem.show(cv, root) - line.init() -init(cv) - -class RightPanel: - - def R_set(self, num): - result = tkinter.simpledialog.askstring(title='修改R' + str(num + 1), prompt='请输入修改后的R值:', - initialvalue=cpu.R(num))#显示输入提示 - if not result:#若没有输入则直接返回 - return - if not len(result) == len(cpu.R(num)):#输入错误则警告 - messagebox.showwarning('警告', 'R值不合法') - return - for i in range(16):#输入错误则警告 - if (not result[i] == '0' and not result[i] == '1'): - messagebox.showwarning('警告', 'R值不合法') - return - sum = 0#计算输入的值 - for i in range(16): - sum *= 2 - sum += int(result[i]) - - cpu.R_int[num] = sum# 修改相应寄存器的值 - self.CAL_display()#重新显示面板 - alu.init(cv, root)#修改仿真界面 - cv.update()#更新画布 - - def op_set(self, num): - cpu.alu = num#修改cpu记录中的符号 - if num == 1:#修改为+ - alu.opa(cv) - elif num == 2:#修改为- - alu.opb(cv) - elif num == 3:#修改为* - alu.opc(cv) - elif num == 4:#修改为/ - alu.opd(cv) - else:#修改为空 - alu.no(cv) - self.CAL_display()#重新显示面板 - - - def MEM_display(self):# 存储器操作面板 - for w in root_right.winfo_children(): - w.destroy()# 清除所有组件 - # 显示标题 - lab = tk.Label(root_right, text="存储器", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.15, rely=0.02, width=200, height=30) - y0 = 0.1 - # 显示Mcontent与更改按钮 - lab = tk.Label(root_right, text="当前Mcontent:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.05 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=cpu.MCO(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.1 + y0, width=200, height=30) - B = tk.Button(root_right, text="更改", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: self.MCO_set()) - B.place(relx=0.7, rely=0.05 + y0, width=50, height=30) - # 显示Maddr与更改按钮 - lab = tk.Label(root_right, text="当前Maddr:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab.place(relx=0.1, rely=0.15 + y0, width=120, height=30) - lab2 = tk.Label(root_right, text=cpu.MAD(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.2 + y0, width=200, height=30) - B = tk.Button(root_right, text="更改", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: self.MAD_set()) - B.place(relx=0.7, rely=0.15 + y0, width=50, height=30) - # 逐个设置存储单元按钮 - B = tk.Button(root_right, text="设置存储器", command=lambda: self.set_memory()) - B.place(relx=0.1, rely=0.2 + y0, width=200, height=30) - # 装载一段程序按钮 - B = tk.Button(root_right, text="装载一段程序", command=lambda: self.write_memory()) - B.place(relx=0.1, rely=0.25 + y0, width=200, height=30) - - def CAL_display(self): # 运算器操作面板 - for w in root_right.winfo_children(): - w.destroy() # 清除右侧组件 - lab = tk.Label(root_right, text="运算器", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.15, rely=0.02, width=200, height=30) - y0 = 0.1 - # 显示运算符与更改按钮 - PC = tk.Label(root_right, text="当前运算:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - PC.place(relx=0.1, rely=0.05 + y0, width=80, height=30) - lab2 = tk.Label(root_right, text=cpu.ALU(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.5, rely=0.05 + y0, width=20, height=30) - lab2 = tk.Label(root_right, text="更改运算符", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - lab2.place(relx=0.1, rely=0.1 + y0, width=120, height=30) - B = tk.Button(root_right, text='+', command=lambda: self.op_set(1), state=NORMAL) # 更改为+ - B.place(relx=0.05 + 0 * 0.15, rely=0.15 + y0, relwidth=0.15, relheight=0.05) - B = tk.Button(root_right, text='-', command=lambda: self.op_set(2), state=NORMAL) # 更改为- - B.place(relx=0.05 + 1 * 0.15, rely=0.15 + y0, relwidth=0.15, relheight=0.05) - B = tk.Button(root_right, text='x', command=lambda: self.op_set(3), state=NORMAL) # 更改为* - B.place(relx=0.05 + 2 * 0.15, rely=0.15 + y0, relwidth=0.15, relheight=0.05) - B = tk.Button(root_right, text='÷', command=lambda: self.op_set(4), state=NORMAL) # 更改为/ - B.place(relx=0.05 + 3 * 0.15, rely=0.15 + y0, relwidth=0.15, relheight=0.05) - B = tk.Button(root_right, text='无', command=lambda: self.op_set(0), state=NORMAL) # 更改为无 - B.place(relx=0.05 + 4 * 0.15, rely=0.15 + y0, relwidth=0.15, relheight=0.05) - R_text = [] - for i in range(4): # 读取寄存器的值 - R_text.append(cpu.R(i)) - for i in range(4): # 显示各个寄存器的值与更改按钮 - RN = tk.Label(root_right, text="R" + str(i + 1) + ':', bg=WHITE, fg=BLACK, font=('微软雅黑', 12)) - RN.place(relx=0.05, rely=0.2 + y0 + 0.1 * i, width=80, height=30, anchor=NW) - lab1 = tk.Label(root_right, text=R_text[i], bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab1.place(relx=0.1, rely=0.25 + y0 + 0.1 * i, width=150, height=30, anchor=NW) - B = tk.Button(root_right, text='设置R' + str(i + 1), command=lambda num=i: self.R_set(num), state=NORMAL) - B.place(relx=0.3, rely=0.2 + y0 + 0.1 * i, relwidth=0.2, relheight=0.05) - - def SIG_display(self):#控制器操作面板 - for w in root_right.winfo_children(): - w.destroy()# 清除右侧组件 - lab = tk.Label(root_right, text="控制器", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.15, rely=0.02, width=200, height=30) - y0 = 0.1 - # 显示PC值与更改按钮 - PC = tk.Label(root_right, text="当前PC:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - PC.place(relx=0.1, rely=0.05 + y0, width=80, height=30) - lab2 = tk.Label(root_right, text=cpu.PC(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.1 + y0, width=200, height=30) - B = tk.Button(root_right, text="设置PC值", command=lambda: self.pc_set()) - B.place(relx=0.5, rely=0.05 + y0, width=80, height=30) - # 显示IR值与更改按钮 - IR = tk.Label(root_right, text="当前IR:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - IR.place(relx=0.1, rely=0.15 + y0, width=80, height=30) - lab2 = tk.Label(root_right, text=cpu.IR(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.2 + y0, width=200, height=30) - B = tk.Button(root_right, text="设置IR值", command=lambda: self.ir_set()) - B.place(relx=0.5, rely=0.15 + y0, width=80, height=30) - # 显示CLOCK与更改按钮 - CLO = tk.Label(root_right, text="当前时钟:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - CLO.place(relx=0.1, rely=0.25 + y0, width=80, height=30) - lab2 = tk.Label(root_right, text=str(cpu.clostep + 1), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.45, rely=0.25 + y0, width=50, height=30) - lab = tk.Label(root_right, text="设置时钟刻:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12)) - lab.place(relx=0.1, rely=0.3 + y0, width=150, height=30) - for i in range(6):#遍历时钟刻 - if cpu.clostep == i:#若是当前时钟刻则高亮显示,按钮禁用 - B = tk.Button(root_right, text=str(i + 1), command=lambda n=i: self.clo_set(n), bg=YELLOW, state=DISABLED) - else:#若不是当前时钟刻则正常显示,按钮启用 - B = tk.Button(root_right, text=str(i + 1), command=lambda n=i: self.clo_set(n), state=NORMAL) - B.place(relx=0.05 + i * 0.15, rely=0.35 + y0, relwidth=0.15, relheight=0.05) - # 显示Inscode与更改按钮 - INS = tk.Label(root_right, text="当前Inscode:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=W) - INS.place(relx=0.1, rely=0.4 + y0, width=130, height=30) - lab2 = tk.Label(root_right, text=cpu.CODE(), bg=BLUE, fg=BLACK, font=('微软雅黑', 12)) - lab2.place(relx=0.1, rely=0.45 + y0, width=100, height=30) - B = tk.Button(root_right, text="设置Inscode", command=lambda: self.code_set()) - B.place(relx=0.55, rely=0.45 + y0, width=80, height=30) - - - - - def write_memory(self): - init(cv) - top = tk.Toplevel() - top.title('载入程序') - width = 1000 - height = 700 - top.geometry(f'{width}x{height}') - top.config(bg=WHITE) - lab = tk.Label(top, text="载入程序,用逗号隔开指令", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.05, rely=0.05, relwidth=0.4, relheight=0.1) - E = tk.Text(top, bg=GREY, fg=BLACK, font=('微软雅黑', 12)) - E.place(relx=0.05, rely=0.15, relheight=0.6, relwidth=0.4) - - B = tk.Button(top, text="载入程序", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: get_text()) - B.place(relx=0.05, rely=0.75, relwidth=0.4, relheight=0.05) - - user = E.get(1.0, 'end') - user_command = [] - user.replace(' ', '') - user.replace('\n', '') - - t = list(user) - for i in range(len(t)): - if t[i] == ',': - t[i] = ',' - elif not t[i] == '0' and not t[i] == '1' and not t[i] == ',': - t[i] = '' - user = ''.join(t) - - users = user.split(',') - - # print(users) - for u in users: - if len(u) == 16: - user_command.append(u) - # print(user_command) - lab = tk.Label(top, text="程序载入预览", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.55, rely=0.05, relwidth=0.4, relheight=0.1) - u_text = '' - for u in user_command: - u_text += u - u_text += '\n' - L = tk.Label(top, text=u_text, bg=GREY, fg=BLACK, font=('微软雅黑', 12)) - L.place(relx=0.55, rely=0.15, relheight=0.6, relwidth=0.4) - B = tk.Button(top, text="确认载入程序", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: write()) - B.place(relx=0.55, rely=0.75, relwidth=0.4, relheight=0.05) - def w_init(): - for w in top.winfo_children(): - w.destroy() - # 清除原有组件 - lab = tk.Label(top, text="载入程序,用逗号隔开指令", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.05, rely=0.05, relwidth=0.4, relheight=0.1) - E = tk.Text(top, bg=GREY, fg=BLACK, font=('微软雅黑', 12)) - E.place(relx=0.05, rely=0.15, relheight=0.6, relwidth=0.4) - - B = tk.Button(top, text="载入程序", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: get_text()) - B.place(relx=0.05, rely=0.75, relwidth=0.4, relheight=0.05) - - def get_text(): - # L.destroy() - - user = E.get(1.0, 'end') - user_command = [] - user.replace(' ', '') - user.replace('\n', '') - t = list(user) - for i in range(len(t)): - if t[i] == ',': - t[i] = ',' - elif not t[i] == '0' and not t[i] == '1' and not t[i] == ',': - t[i] = '' - user = ''.join(t) - - - users = user.split(',') - # print(users) - for u in users: - if len(u) == 16: - user_command.append(u) - # print(user_command) - # lab = tk.Label(top, text="程序载入预览", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - # lab.place(relx=0.55, rely=0.05, relwidth=0.4, relheight=0.1) - u_text = '' - i = 0 - for u in user_command: - u_text += bin(i).replace('0b', '').zfill(16) - u_text += ' ' - u_text += u - u_text += '\n' - i += 1 - L = tk.Label(top, text=u_text, bg=GREY, fg=BLACK, font=('微软雅黑', 12), anchor=N) - L.place(relx=0.55, rely=0.15, relheight=0.6, relwidth=0.4) - - def write(): - user = E.get(1.0, 'end') - user_command = [] - user.replace(' ', '') - user.replace('\n', '') - t = list(user) - for i in range(len(t)): - if t[i] == ',': - t[i] = ',' - elif not t[i] == '0' and not t[i] == '1' and not t[i] == ',': - t[i] = '' - user = ''.join(t) - - users = user.split(',') - # print(users) - for u in users: - if len(u) == 16: - user_command.append(u) - # print(user_command) - for i in range(20): - cpu.SimMem[i] = bin(0).replace('0b', '').zfill(16) - for i in range(len(user_command)): - cpu.SimMem[i] = user_command[i] - mem.show(cv, root) - top.destroy() - - def set_memory(self): - init(cv) - top = tk.Toplevel() - top.title('编辑存储器') - width = 500 - height = 600 - top.geometry(f'{width}x{height}') - top.config(bg=WHITE) - Texts = [] - def show(): - for w in top.winfo_children(): - w.destroy() - # 清除原有组件 - Texts.clear() - lab = tk.Label(top, text="设置存储器", bg=WHITE, fg=BLACK, font=('微软雅黑', 20)) - lab.place(relx=0.25, rely=0.02, width=200, height=30) - y0 = 50 - lab = tk.Label(top, text="当前存储器:", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=CENTER) - lab.place(y=y0, width=120, height=30) - - for i in range(20): - lab = tk.Label(top, text="00000000 " + bin(i).replace('0b', '').zfill(8), bg=WHITE, fg=BLACK, font=('微软雅黑', 12), anchor=CENTER) - lab.place(x=30, y=30 + y0 + i * 20, width=180, height=20) - - text = tkinter.Entry(top, bg=GREY, fg=BLACK, font=('微软雅黑', 12), bd=2) - text.place(x=200, y=30 + y0 + i * 20, width=180, height=20) - text.insert(0, cpu.SimMem[i]) - Texts.append(text) - B = tk.Button(top, text="设置Memory", bg=WHITE, fg=BLACK, font=('微软雅黑', 12), command=lambda: set_mem()) - B.place(x=100, y=450 + y0, width=280, height=20) - show() - - def set_mem(): - for T in Texts: - txt = T.get() - # print(txt) - if not len(txt) == len(cpu.SimMem[0]): - messagebox.showwarning('警告', '修改不合法') - show() - return - for l in range(len(txt)): - if (not txt[l] == '0') and (not txt[l] == '1'): - messagebox.showwarning('警告', '修改不合法') - show() - return - i = 0 - for T in Texts: - txt = T.get() - # print (Texts[i].get()) - cpu.SimMem[i] = txt - i += 1 - show() - mem.show(cv, root) - - - - - - def SIG_info(self): - pass - - - - def MCO_set(self): - result = tkinter.simpledialog.askstring(title='修改Mcontent', prompt='请输入修改后的Mcontent:', initialvalue=cpu.MCO()) - if not result: - return - if not len(result) == len(cpu.MCO()): - messagebox.showwarning('警告', 'Mcontent不合法') - return - for i in range(8): - if (not result[i] == '0' and not result[i] == '1') or (not result[i + 9] == '0' and not result[i + 9] == '1'): - messagebox.showwarning('警告', 'Mcontent不合法') - return - sum = 0 - for i in range(8): - sum *= 2 - sum += int(result[i]) - for i in range(8): - sum *= 2 - sum += int(result[i + 9]) - # 将更改后的的值放到Mcontent中 - cpu.MCO_int = sum - self.MEM_display() - mem.show(cv, root) - cv.update() - - def MAD_set(self): - result = tkinter.simpledialog.askstring(title='修改Maddr', prompt='请输入修改后的Maddr:', - initialvalue=cpu.MAD()) - if not result: - return - if not len(result) == len(cpu.MAD()): - messagebox.showwarning('警告', 'Maddr不合法') - return - for i in range(8): - if (not result[i] == '0' and not result[i] == '1') or ( - not result[i + 9] == '0' and not result[i + 9] == '1'): - messagebox.showwarning('警告', 'Maddr不合法') - return - sum = 0 - for i in range(8): - sum *= 2 - sum += int(result[i]) - for i in range(8): - sum *= 2 - sum += int(result[i + 9]) - cpu.MAD_int = sum - self.MEM_display() - mem.show(cv, root) - cv.update() - - def code_set(self): - result = tkinter.simpledialog.askstring(title='修改Inscode', prompt='请输入修改后的Inscode:', initialvalue=cpu.CODE()) - if not result: - return - if not len(result) == len(cpu.CODE()): - messagebox.showwarning('警告', 'Inscode不合法') - return - for i in range(6): - if (not result[i] == '0' and not result[i] == '1'): - messagebox.showwarning('警告', 'Inscode不合法') - return - sum = 0 - for i in range(6): - sum *= 2 - sum += int(result[i]) - # 修改INSCODE值 - cpu.code = sum - - self.SIG_display() - si.init(cv, root) - cv.update() - - def pc_set(self): - result = tkinter.simpledialog.askstring(title='修改PC值', prompt='请输入修改后的PC值:', initialvalue=cpu.PC()) - if not result: - return - if not len(result) == len(cpu.PC()): - messagebox.showwarning('警告', 'PC值不合法') - return - for i in range(8): - if (not result[i] == '0' and not result[i] == '1') or (not result[i + 9] == '0' and not result[i + 9] == '1'): - messagebox.showwarning('警告', 'PC值不合法') - return - sum = 0 - for i in range(8): - sum *= 2 - sum += int(result[i]) - for i in range(8): - sum *= 2 - sum += int(result[i + 9]) - cpu.PC_int = sum - self.SIG_display() - cv.update() - - def ir_set(self): - result = tkinter.simpledialog.askstring(title='修改IR值', prompt='请输入修改后的IR值:', initialvalue=cpu.IR()) - if not result: - return - if not len(result) == len(cpu.IR()): - messagebox.showwarning('警告', 'IR值不合法') - return - for i in range(8): - if (not result[i] == '0' and not result[i] == '1') or (not result[i + 9] == '0' and not result[i + 9] == '1'): - messagebox.showwarning('警告', 'IR值不合法') - return - sum = 0 - for i in range(8): - sum *= 2 - sum += int(result[i]) - for i in range(8): - sum *= 2 - sum += int(result[i + 9]) - cpu.IR_int = sum - self.SIG_display() - cv.update() - - def clo_set(self, clo): - cpu.CLO(clo) - self.SIG_display() - -if __name__ == "__main__": - r = RightPanel()#实例化类 - r.MEM_display()#显示存储器操作面板 - # r.CAL_display() - # r.SIG_display() - - # r.set_memory() - # r.write_memory() - # init(cv) - root.mainloop() \ No newline at end of file diff --git a/SIG_ctrl.py b/SIG_ctrl.py deleted file mode 100644 index 06271d6..0000000 --- a/SIG_ctrl.py +++ /dev/null @@ -1,106 +0,0 @@ -from UI import * -import tkinter as tk -from Clock import ClockStep - -class SIG: - def __init__(self): - self.bx2, self.by2, self.dx, self.dy = 105, 558, 120, 16#设置sig_ctrl文字间隔 - - - def show(self):# 依据SigObj[]的值显示控制信号(SigCtrl部件内的信号) - words = ['SigCtrl->ALU', 'SigCtrl->IR', 'SigCtrl->PC', 'SigCtrl->MEMORY', - 'SigCtrl->R1', 'SigCtrl->R2', 'SigCtrl->R3', 'SigCtrl->R4']# 对于每个控制信号进行判断 - for w in words:# 如果SigObj中该文字为False,则该文字非高亮显示 - if cpu.SigObj[w][1] == False: - eval('self.' + w + '(cv, 0)') - for w in words:# 如果SigObj中该文字为True,则该文字高亮显示 - if cpu.SigObj[w][1] == True: - eval('self.' + w + '(cv, 1)') - cv.update()# 更新画布 - - def init(self, cv: Canvas, root): - INS = tk.Label(root, text=cpu.CODE(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)# 根据参数显示INSCODE - INS.place(x=184, y=535, height=20, width=80, anchor=NW)#放置INSCODE - # 显示sig_ctrl各部分的名字 - cv.create_text(110, 535, text="insCode", font=('微软雅黑', 12), fill=GOLD, anchor=NW) - cv.create_text(self.bx2, self.by2, text='->ALU', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2, self.by2 + self.dy, text='->IR', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2, self.by2 + self.dy * 2, text='->PC + 1', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2, self.by2 + self.dy * 3, text='->MEMORY', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2 + self.dx, self.by2, text='->R1', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy, text='->R2', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 2, text='->R3', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 3, text='->R4', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update()#更新画布 - def ALU(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2, self.by2, text='->ALU', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2, self.by2, text='->ALU', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def IR(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2, self.by2 + self.dy, text='->IR', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2, self.by2 + self.dy, text='->IR', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def PC(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2, self.by2 + self.dy * 2, text='->PC + 1', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2, self.by2 + self.dy * 2, text='->PC + 1', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def MEM(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2, self.by2 + self.dy * 3, text='->MEMORY', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2, self.by2 + self.dy * 3, text='->MEMORY', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - - def R1(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2 + self.dx, self.by2, text='->R1', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2 + self.dx, self.by2, text='->R1', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def R2(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy, text='->R2', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy, text='->R2', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def R3(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 2, text='->R3', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 2, text='->R3', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - def R4(self, cv: Canvas, flag): - if flag: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 3, text='->R4', font=('微软雅黑', 10), anchor=NW, fill=GOLD) - else: - cv.create_text(self.bx2 + self.dx, self.by2 + self.dy * 3, text='->R4', font=('微软雅黑', 10), anchor=NW, fill=GREY) - cv.update() - - -if __name__ == "__main__": - cpu = CPU() - cl = ClockStep() - cl.init(cv, root) - si=SIG() - # si.show() - - # si.SIG_display() - si.init(cv, root) - mainloop() - time.sleep(cpu.time) - si.R4(cv,1) - time.sleep(cpu.time) - si.MEM(cv,1) - # bx2, by2, bw2, bh2 = 105, 560, 100, 20 - # cv.create_rectangle(bx2, by2, bx2 + 170, by2 + 65, fill=BLACK, width=0) - # cv.create_rectangle(485, 469, 485 + 120, 469 + 9, fill=RED) - def left1(event): - print(event.x,event.y) - cv.bind('', left1) - root.mainloop() \ No newline at end of file diff --git a/UI.py b/UI.py deleted file mode 100644 index 847c174..0000000 --- a/UI.py +++ /dev/null @@ -1,98 +0,0 @@ -import tkinter as tk -from tkinter import * -from data import CPU -import time - -cpu = CPU() - -WORD = '#00f5ff' -color1 = '#ee28a3' -color2 = '#668B8B' -NOMARK = '#c5c9c5' -NOMARK1 = NOMARK -BLUE = "#0080FF" -BLACK = "#000000" -WHITE = "#FFFFFF" -RED = "#FFAAAA" -NORED = NOMARK1 # '#ffdddd' -YELLOW = "#FFFACD" -GREY = '#808080' -GOLD = '#FFD700' -GREEN = '#00FA9A' -NOGREEN = NOMARK1 # '#00321f' -BACK = '#0153d2' -ORANGE = '#d3b719' -NOORANGE = NOMARK1 # '#ede2a3' -MEMBACK = '#fba651' -MEMMARK = '#fd280f' -MEMWORD = '#000000' - -width = 1000 #设置窗口宽度 -height = 700 #设置窗口高度 -root = tk.Tk() #设置主框架 -root.title("CPU可视化") #设置标题 -root.config(bg=BLACK) #设置背景颜色 -root.geometry(f'{width + 300}x{height}') #设置大小 -cv = tk.Canvas(root, bg='white', bd=2, relief="sunken", width=width + 300, height=height, background=BLACK, - borderwidth=0, highlightthickness=0) #设置画布 -cv.place(x=0, y=0, anchor=NW) #放置画布 - - -def round_rectangle(x1, y1, x2, y2, r=25, **kwargs): - points = ( - x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, y2, - x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, y1) - return cv.create_polygon(points, **kwargs, smooth=True) - - -# cv.grid(row=1,column=0) - -# cv.create_oval(20,20,40, 40, fill='red',width=0) - -# image = Image.open('image/CPU2.png') -# im = ImageTk.PhotoImage(image) - -root_right = tk.Frame(root, bg=WHITE, relief="groove", width=250, height=height - 80) -root_right.place(x=width + 20, y=40, anchor=NW) # 右边栏 -round_rectangle(width + 20, 15, width + 270, height - 25, r=25, fill=WHITE, width=0) -round_rectangle(20, 15, 970, height - 25, r=25, fill=WHITE, width=0) - - -# cv.create_image(0, 0, anchor=NW, image=im) -# cv.create_rectangle(0, 0, width, 10, fill=WHITE, width=0) -# cv.create_rectangle(20, 14, 30, 674, fill=WHITE, width=0) -# -# cv.create_rectangle(710, 24, 925, 140, fill=WHITE, width=0) -# cv.create_rectangle(77, 434, 533, 642, fill=color1, width=0) - - -def use_rgb(rgb): - """ - 将rgb转十六进制 - Args: - rgb: rgb颜色 - Returns: 十六进制 - """ - rgb = str(rgb) - RGB = rgb.replace('(', '').replace(")", '').split(',') # 将RGB格式划分开来 - color = "#" - for i in RGB: - num = int(i) - # 将R、G、B分别转化为16进制拼接转换并大写 hex() 函数用于将10进制整数转换成16进制,以字符串形式表示 - color += str(hex(num))[-2:].replace('x', '0') - - # for i in range(len(color)): - # if color[i] >= 'a' and color[i] <= 'z': - # c = int(color[i]) + int('A') - int('a') - # color[i] = str[c] - return color.upper() - - -if __name__ == "__main__": - # print(use_rgb((225, 225, 225))) - def left1(event): - print(event.x, event.y) - - - cv.bind('', left1) - mainloop()#执行GUI界面 diff --git a/data.py b/data.py deleted file mode 100644 index a066e99..0000000 --- a/data.py +++ /dev/null @@ -1,152 +0,0 @@ -import random - - -class CPU: - def __init__(self): - self.time = 0.2 - # 每步间隔时间 - self.ALUio, self.ALUop = self.ALU_init() - self.clo, self.SigObj = self.Ctrl_init() - self.Sim_init() - self.SimMARK = [] - for i in range(20): - self.SimMARK.append(False) - self.PC_int = 0 - self.IR_int = 0 - self.clostep = 0 - self.alu = 0 - - self.code = 0 - # self.code = '000000' - # self.R_int = [0, 0, 0, 0] - self.R_int = [] - for i in range(4): - self.R_int.append(random.randint(0, pow(2, 16) - 1)) - self.MAD_int = 0 - self.MCO_int = 0 - - def ALU_init(self): - ALUio = {'ALU_R1': False, 'ALU_R2': False, 'ALU_R3': False, 'ALU_R4': False, - 'R1_ALU1': False, 'R2_ALU1': False, 'R3_ALU1': False, 'R4_ALU1': False, - 'R1_ALU2': False, 'R2_ALU2': False, 'R3_ALU2': False, 'R4_ALU2': False} - ALUop = {'+': False, '-': False, '*': False, '/': False} - return ALUio, ALUop - - def Ctrl_init(self): - ClockStep = [1, 0, 0, 0, 0, 0] - SigObj = {'PC->Maddr': ['PC->Maddr', False, 'DataSig'], - 'SigCtrl->Memory': ['SigCtrl->Memory', False, 'CtrlSig'], - 'SigCtrl->IR': ['SigCtrl->IR', False, 'CtrlSig'], - 'IR->SigCtrl': ['IR->SigCtrl', False, 'CtrlSig'], - 'IR->Mcontent': ['IR->Mcontent', False, 'DataSig'], - 'Maddr->IR': ['Maddr->IR', False, 'DataSig'], - 'Mcontent->Memory': ['Mcontent->Memory', False, 'DataSig'], - 'Memory->Mcontent': ['Memory->Mcontent', False, 'DataSig'], - 'PC->SigCtrl': ['PC->SigCtrl', False, 'CtrlSig'], - 'SigCtrl->PC': ['SigCtrl->PC', False, 'CtrlSig'], - 'Mcontent_PC': ['Mcontent_PC', False, 'DataSig'], - 'IR->Maddr': ['IR->Maddr', False, 'DataSig'], - 'SigCtrl->R1': ['SigCtrl->R1', False, 'CtrlSig'], - 'SigCtrl->R2': ['SigCtrl->R2', False, 'CtrlSig'], - 'SigCtrl->R3': ['SigCtrl->R3', False, 'CtrlSig'], - 'SigCtrl->R4': ['SigCtrl->R4', False, 'CtrlSig'], - 'Mcontent->R1': ['Mcontent->R1', False, 'DataSig'], - 'Mcontent->R2': ['Mcontent->R2', False, 'DataSig'], - 'Mcontent->R3': ['Mcontent->R3', False, 'DataSig'], - 'Mcontent->R4': ['Mcontent->R4', False, 'DataSig'], - 'R1->Mcontent': ['R1->Mcontent', False, 'DataSig'], - 'R2->Mcontent': ['R2->Mcontent', False, 'DataSig'], - 'R3->Mcontent': ['R3->Mcontent', False, 'DataSig'], - 'R4->Mcontent': ['R4->Mcontent', False, 'DataSig'], - 'SigCtrl->ALU': ['SigCtrl->ALU', False, 'CtrlSig'], - - } - - return ClockStep, SigObj - - def Sim_init(self): - try: - self.SimMem - # 如果SimMem存在则说明已经初始化完毕,不做操作 - except AttributeError: - # 如果SimMem不存在则说明未初始化,则将存储器所有值初始为0000000000000000 - self.SimMem = [] - for i in range(20): - self.SimMem.append('0000000000000000') - - def CODE(self): - return bin(self.code).replace('0b', '').zfill(6) - - def PC(self): - ans = bin(self.PC_int).replace('0b', '').zfill(16) - # print(ans) - pc = '' - for i in range(8): - pc += ans[i] - pc += ' ' - for i in range(8): - pc += ans[i + 8] - # print(pc) - return pc - - def IR(self): - ans = bin(self.IR_int).replace('0b', '').zfill(16) - # print(ans) - ir = '' - for i in range(8): - ir += ans[i] - ir += ' ' - for i in range(8): - ir += ans[i + 8] - # print(pc) - return ir - - def CLO(self, num): - self.clostep = num - for i in range(6): - self.clo[i] = False - self.clo[self.clostep] = True - - def ALU(self): - AL = ['无', '+', '-', 'x', '÷'] - return AL[self.alu] - - def R(self, num): - return bin(self.R_int[num]).replace('0b', '').zfill(16) - - def MAD(self): - sum = bin(self.MAD_int).replace('0b', '').zfill(16) - # print(ans) - ans = '' - for i in range(8): - ans += sum[i] - ans += ' ' - for i in range(8): - ans += sum[i + 8] - return ans - - def MCO(self): - sum = bin(self.MCO_int).replace('0b', '').zfill(16) - # print(ans) - ans = '' - for i in range(8): - ans += sum[i] - ans += ' ' - for i in range(8): - ans += sum[i + 8] - return ans - - def str_int(self, ans): - if ans[0] == ' ': - return -1 - sum = 0 - for i in range(len(ans)): - if ans[i] == ' ': - continue - sum *= 2 - sum += int(ans[i]) - return sum - -if __name__ == "__main__": - cpu = CPU() - cpu.PC() \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index 6894625..0000000 --- a/main.py +++ /dev/null @@ -1,72 +0,0 @@ -# from program import * -from ExecInstructWithAnim import * -from ExecInstructWithText import * - -r = RightPanel() -run_ani = ExecInstructWithAnim() -run_text = ExecInstructWithText() - -bw, bh = 150, 45 -# 按钮1 -bx1, by1 = 750, 30 -Button1 = tk.Button(root, text='自动执行指令(仅寄存器)', background=GOLD, command=lambda: Program1(), state=NORMAL) -Button1.place(x=bx1, y=by1, width=bw, height=bh) - - -def Program1(): - if run_text.play == 1 or run_ani.play == 1: - messagebox.showwarning('警告', '程序正在运行') - return - run_text.auto_display() - - -# 按钮2 -bx2, by2 = 750, 90 -Button2 = tk.Button(root, text='自动执行指令(带UI)', background=GOLD, command=lambda: Program2(), state=NORMAL) -Button2.place(x=bx2, y=by2, width=bw, height=bh) - - -def Program2(): - if run_text.play == 1 or run_ani.play == 1: - messagebox.showwarning('警告', '程序正在运行') - return - run_ani.auto_display() - - -# 按钮3 -bx2, by2 = 820, 150 -WR = tk.Button(root, text='装载程序', background=RED, command=lambda: r.write_memory(), state=NORMAL) -WR.place(x=bx2, y=by2, width=80, height=bh) - - -def main(): - # 右键菜单 - def onRightButtonUp(event): - menu.post(event.x_root, event.y_root) - - menu = tk.Menu(root, tearoff=0) - menu.add_command(label='运算器', command=lambda: r.CAL_display()) - menu.add_command(label='控制器', command=lambda: r.SIG_display()) - menu.add_command(label='存储器', command=lambda: r.MEM_display()) - - cv.bind('', onRightButtonUp) - root.mainloop() - - -if __name__ == "__main__": - from pycallgraph2 import PyCallGraph - from pycallgraph2.output import GraphvizOutput - from pycallgraph2 import Config - from pycallgraph2 import GlobbingFilter - - output = GraphvizOutput(font_size=30) - output.output_file = "basic.png" - output.group_font_size = 40 - config = Config() - config.trace_filter = GlobbingFilter(include=[ - 'RightPanel.*', - 'ExecInstructWithAnim.*', - 'ExecInstructWithText.*', - ]) - with PyCallGraph(output=output, config=config): - main() diff --git a/memory.py b/memory.py deleted file mode 100644 index 7495815..0000000 --- a/memory.py +++ /dev/null @@ -1,99 +0,0 @@ -import random - -from UI import * -# import tkinter as tk - - -class MEM: - def __init__(self): - # 绘制存储器背景板 - round_rectangle(597, 205, 928, 670, r=25, fill=BACK, width=0) - round_rectangle(675, 275, 910, 660, r=25, fill=BLACK, width=0) - - def mark(self, cv:Canvas): - for i in range(20): - # 如果SimMARK中该存储单元为False,则非高亮显示 - if cpu.SimMARK[i] == False: - cv.create_rectangle(810, 282 + 18.5 * i, 897, 298 + 18.5 * i, width=3, outline=MEMBACK) - for i in range(20): - # 如果SimMARK中该存储单元为True,则高亮显示 - if cpu.SimMARK[i] == True: - cv.create_rectangle(810, 282 + 18.5 * i, 897, 298 + 18.5 * i, width=3, outline=MEMMARK) - cv.update() - - - - # 根据当前的存储数据绘制当前的存储器 - def show(self, cv: Canvas, root): - # 标记cpu各部分的名称 - cv.create_text(670, 219, text='Mcontent', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(611, 356, text='Maddr', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(690, 255, text='地址(编号)', font=('time', 12,), anchor=NW, fill='#ffd700') - cv.create_text(830, 255, text='在选单元', font=('time', 12,), anchor=NW, fill='#ffd700') - # 根据存储的数据显示当前Maddr的值 - cv.create_rectangle(619, 383, 648, 541, fill=WHITE, width=0) - cv.create_text(620, 390, text=cpu.MAD(), font=('微软雅黑', 12), angle=90, anchor=NE, fill=BLACK) - # 根据存储的数据显示当前Mcotent的值 - cv.create_rectangle(753, 218, 910, 242, fill=WHITE, width=0) - cv.create_text(830, 230, text=cpu.MCO(), fill=BLACK, font=('微软雅黑', 12)) - # 根据存储的数据显示当前Memory中各个存储单元的值 - cv.create_rectangle(685, 281, 791, 647, fill=BLACK) - for i in range(20):# 显示存储器各个单元的地址 - cv.create_text(688, 282 + 18.5 * i, text="00000000 " + bin(i).replace('0b', '').zfill(8), - font=('微软雅黑', 8), anchor=NW, fill=GOLD) - cv.create_rectangle(808, 281, 897, 649, fill=MEMBACK, width=0) - for i in range(20):# 显示存储器各个单元的内容 - cv.create_text(852, 290 + 18.5 * i, text=cpu.SimMem[i], font=('微软雅黑', 6), anchor=CENTER, - fill=MEMWORD) - self.mark(cv)# 更新画布 - - # 根据当前的存储数据绘制当前的存储器 - def init(self, cv:Canvas, root): - # 标记cpu各部分的名称 - cv.create_text(670, 219, text='Mcontent', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(611, 356, text='Maddr', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD) - cv.create_text(690, 255, text='地址(编号)', font=('time', 12, ), anchor=NW, fill='#ffd700') - cv.create_text(830, 255, text='在选单元', font=('time', 12, ), anchor=NW, fill='#ffd700') - # 根据存储的数据显示当前Maddr的值 - cv.create_rectangle(619, 383, 648, 541, fill=WHITE, width=0) - cv.create_text(620, 390, text=cpu.MAD(), font=('微软雅黑', 12), angle=90, anchor=NE, fill=BLACK) - # 根据存储的数据显示当前Mcotent的值 - cv.create_rectangle(753, 218, 910, 242, fill=WHITE, width=0) - cv.create_text(830, 230, text=cpu.MCO(), fill=BLACK, font=('微软雅黑', 12)) - # 根据存储的数据显示当前Memory中各个存储单元的值 - # 显示存储器各个单元的地址 - cv.create_rectangle(685, 281, 791, 647, fill=BLACK) - for i in range(20): - cv.create_text(688, 282 + 18.5 * i, text="00000000 " + bin(i).replace('0b', '').zfill(8), font=('微软雅黑', 8), anchor=NW, fill=GOLD) - # 显示存储器各个单元的内容 - cv.create_rectangle(808, 281, 897, 649, fill=MEMBACK, width=0) - for i in range(20): - cv.create_text(852, 290 + 18.5 * i, text=cpu.SimMem[i], font=('微软雅黑', 6), anchor=CENTER, fill=MEMWORD) - # 更新画布 - self.mark(cv) - - -if __name__ == "__main__": - mem = MEM()#实例化 - mem.show(cv, root)#显示存储器界面 - bw, bh = 150, 45 - # 按钮1 - bx1, by1 = 750, 95 - B1 = tk.Button(root, text='添加程序', background=BLUE, command=lambda: test(), state=NORMAL) - B1.place(x=bx1, y=by1, width=bw, height=bh) - - def test(): - for i in range(20): - time.sleep(cpu.time) - for j in range(20): - cpu.SimMARK[j] = False - cpu.SimMARK[random.randint(0,19)] = True - mem.mark(cv) - - cv.update() - - - def left1(event): - print(event.x,event.y) - cv.bind('', left1) - root.mainloop() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1cb0de0..0000000 Binary files a/requirements.txt and /dev/null differ diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/cpu_data.py b/src/cpu_data.py new file mode 100644 index 0000000..7ce9258 --- /dev/null +++ b/src/cpu_data.py @@ -0,0 +1,130 @@ + + +def alu_op(): + ALUop = dict() + for i in '+-x÷': + ALUop[i] = False + return ALUop + +def alu_io(): + ALUio = dict() + Register = ["R1","R2","R3","R4"] + for reg in Register: + ALUio[f"{reg}_ALU_1"] = False + ALUio[f"{reg}_ALU_2"] = False + ALUio[f"ALU_{reg}"] = False + return ALUio + +def clock_step(): + ClockStep = dict() + for i in range(6): + ClockStep[str(i+1)] = False + return ClockStep + +def sig_obj(): + SigObj = dict() + Register = ["R1", "R2", "R3", "R4", "IR"] + ctrl = ["ALU_1", "ALU_2", "PC+1", "Memory"] + for r in Register: + SigObj[f"Mcontent->{r}"] = [f"Mcontent->{r}", False, "DataSig"] + SigObj[f"->{r}"] = [f"->{r}", False, "CtrlSig"] + for ct in ctrl: + SigObj[f"->{ct}"] = [f"->{ct}", False, "CtrlSig"] + SigObj["IR->SigCtrl"] = ["IR->SigCtrl", False, "CtrlSig"] + SigObj["PC->Maddr"] = ["IR->Maddr", False, "DataSig"] + SigObj["IR->Maddr"] = ["IR->Maddr", False, "DataSig"] + SigObj["Memory->Mcontent"] = ["Memory->Mcontent", False, "DataSig"] + return SigObj + +def sim_mem(): + sim_mem_ls = [] + for i in range(20): + sim_mem_ls.append(f"{0:016b}") + return sim_mem_ls + +def bin_to_dec(binary_string, bit_width=16): + """ + 将补码二进制字符串转换为有符号数10进制,处理溢出。 + + 参数: + binary_string (str): 补码二进制字符串,例如 "1101100101101110"。 + bit_width (int): 位宽,默认为16位。 + + 返回: + int: 转换后的有符号数10进制。 + """ + if len(binary_string) > bit_width: + # 如果二进制字符串长度超出位宽,截断超出部分 + binary_string = binary_string[-bit_width:] + + # 如果最高位为1,说明是负数,先取反再加1得到绝对值的原码 + if binary_string[0] == '1': + inverted_string = ''.join('1' if bit == '0' else '0' for bit in binary_string) + absolute_value = -(int(inverted_string, 2) + 1) + else: + # 如果最高位是0,则直接转换为正数 + absolute_value = int(binary_string, 2) + + return absolute_value + + +def dec_to_bin(decimal_value, bit_width=16): + """ + 将有符号数10进制转换为补码二进制字符串,处理溢出。 + + 参数: + decimal_value (int): 有符号数10进制。 + bit_width (int): 位宽,默认为16位。 + + 返回: + str: 转换后的补码二进制字符串。 + """ + # 如果输入数据超出位宽,截断超出部分 + decimal_value = decimal_value & ((1 << bit_width) - 1) + + # 如果是负数,获取其绝对值的原码 + if decimal_value < 0: + absolute_value_binary = bin(abs(decimal_value))[2:] + + # 如果位数不足,需要在左侧补0 + if len(absolute_value_binary) < bit_width: + absolute_value_binary = '0' * (bit_width - len(absolute_value_binary)) + absolute_value_binary + + # 对绝对值的原码进行按位取反 + inverted_representation = ''.join('1' if bit == '0' else '0' for bit in absolute_value_binary) + + # 将取反后的二进制表示加上1,得到补码表示 + binary_representation = format(int(inverted_representation, 2) + 1, f'0{bit_width}b') + else: + # 如果是正数,直接转换为二进制 + binary_representation = bin(decimal_value)[2:] + + # 如果位数不足,需要在左侧补0 + if len(binary_representation) < bit_width: + binary_representation = '0' * (bit_width - len(binary_representation)) + binary_representation + + return binary_representation + + +ALUio = alu_io() +ALUop = alu_op() +ClockStep = clock_step() +SigObj = sig_obj() +SimMem = sim_mem() + + +if __name__ == '__main__': + ALUio = alu_io() + print(ALUio) + ALUop = alu_op() + print(ALUop) + ClockStep = clock_step() + print(ClockStep) + SigObj = sig_obj() + print(SigObj) + SimMem = sim_mem() + print(SimMem) + + + + diff --git a/src/execute_instruction.py b/src/execute_instruction.py new file mode 100644 index 0000000..20ba908 --- /dev/null +++ b/src/execute_instruction.py @@ -0,0 +1,1003 @@ +# -*- encoding: utf-8 -*- +""" +@File : execute_instruction.py +@License : (C)Copyright 2021-2023 + +@Modify Time @Author @Version @Description +------------ ------- -------- ----------- +2023/11/10 17:14 zart20 1.0 None +""" +import re +import time +from tkinter import filedialog, ttk + +from gui import * + + +def insert_char(original_str, char, position): + # 在指定位置之前插入字符 + modified_str = original_str[:position] + char + original_str[position:] + return modified_str + + +inscode_map = { + '取数': '000001', '存数': '000010', '加法': '000011', '减法': '000111', + '乘法': '000100', '除法': '001000', '打印': '000101', '停机': '000110', + '跳转': '001001' +} + + + + +class ExecInstructWithText: + def __init__(self): + self.wait_time = 1 # 节拍计时 + self.gui = GUISim() # 主界面显示 + self.alu = self.gui.alu # alu实例化 + self.memo = self.gui.memo # memo 实例化 + self.sing = self.gui.sigctrl # 信号实例化 + self.textbox = self.gui.textbox # 信息输入框实例化 + self.regs = {"R1": self.alu.r1, "R2": self.alu.r2, "R3": self.alu.r3, "R4": self.alu.r4} # 寄存器值槽 + self.sing_times1 = 0 # 取数指令的节拍计数变量 + self.sing_times2 = 0 # 存数指令的节拍 + self.menu_test() + self.show_msg() # 显示消息框 + self.manual_opera_step = 0 # 手动控制步骤 + self.entry_replace(self.sing.pc_reg, f"{0:016b}") + self.ctrl_stop = False # 暂停控制 + + self.register_mapping = { + "01": (self.alu.r2, "mco-r2"), + "10": (self.alu.r3, "mco-r3"), + "11": (self.alu.r4, "mco-r4"), + "00": (self.alu.r1, "mco-r1"), + } + + # self.textbox.msg_box("kkxs") + + def reset(self): + self.reg_update() + self.textbox.clear() + self.textbox.info_text.config(fg="#000000") + self.manual_opera_step = 0 # 手动控制步骤 + self.entry_replace(self.sing.pc_reg, f"{0:016b}") + self.ctrl_stop = False # 暂停控制 + self.next_button.config(state=tk.NORMAL) + + + + def stop_exec(self): + if self.ctrl_stop == True: + self.ctrl_stop = False + self.ctrl_exec.config(text="暂停指令") + self.exec_auto() + else: + self.ctrl_stop = True + self.ctrl_exec.config(text="继续指令") + + def show_msg(self): + """显示固定信息""" + self.textbox.canvas.delete("button") + self.textbox.main_msg_box("系统控制", 30) + self.textbox.main_msg_box("系统消息", 265) + self.textbox.create_button("顺序执行", x=1045, y=65, font=('微软雅黑', 12), command=self.exec_auto) + self.ctrl_exec = self.textbox.create_button("暂停指令", x=1170, y=65, font=('微软雅黑', 12), + command=self.stop_exec) + self.textbox.create_button("↺", x=1035, y=250, font=('微软雅黑', 12), command=self.reset) + + # self.textbox.create_button("手动执行", x=1180, y=65, font=('微软雅黑', 12), command=self.) + # self.prev_button = self.textbox.create_button("上一步", x=1045, y=118, font=('微软雅黑', 12), command=self.prev) + self.next_button = self.textbox.create_button("单节拍执行", x=1100, y=130, font=('微软雅黑', 12), + command=self.exec_next) + + # self.textbox.create_button_with_image("img.png", x=1120, y=100, command=lambda:self.exe_one_instruct( + # "000001")) + + def menu_test(self): + menu_bar = tk.Menu(root) + root.config(menu=menu_bar) + + font = ("son", 12) + + lode_menu = tk.Menu(menu_bar, tearoff=0) + menu_bar.add_cascade(label="装载程序", menu=lode_menu, font=font) + lode_menu.add_command(label="从文件装载", command=self.read_file, font=font) + lode_menu.add_command(label="手动输入", command=self.manual_input, font=font) + + file_menu = tk.Menu(menu_bar, tearoff=0) + menu_bar.add_cascade(label="单指令执行", menu=file_menu, font=font) + file_menu.add_command(label="取数", command=lambda: self.exe_one_instruct("000001"), font=font) + file_menu.add_command(label="存数", command=lambda: self.exe_one_instruct("000010"), font=font) + file_menu.add_command(label="跳转", command=lambda: self.exe_one_instruct("001001"), font=font) + file_menu.add_command(label="加法", command=lambda: self.exe_one_instruct("000011"), font=font) + file_menu.add_command(label="减法", command=lambda: self.exe_one_instruct("000111"), font=font) + file_menu.add_command(label="乘法", command=lambda: self.exe_one_instruct("000100"), font=font) + file_menu.add_command(label="除法", command=lambda: self.exe_one_instruct("001000"), font=font) + file_menu.add_command(label="打印", command=lambda: self.exe_one_instruct("000101"), font=font) + file_menu.add_command(label="停机", command=lambda: self.exe_one_instruct("000110"), font=font) + file_menu.add_command(label="顺序执行", command=lambda: self.exec_auto(), font=font) + + def entry_replace(self, entry: tk.Entry, value): + entry.delete(0, tk.END) + entry.insert(0, value) + + def binary_addition(self, num1, num2): + result = bin_to_dec(num1) + bin_to_dec(num2) # 转为10进制的加 + result_binary = dec_to_bin(result) + return result_binary + + def binary_subtraction(self, num1, num2): + result = bin_to_dec(num1) - bin_to_dec(num2) # 转为10进制的减 + result_binary = dec_to_bin(result) + return result_binary + + def binary_multiplication(self, num1, num2): + result = bin_to_dec(num1) * bin_to_dec(num2) # 转为10进制的加 + result_binary = dec_to_bin(result) + return result_binary + + def binary_division(self, dividend, divisor): + if bin_to_dec(divisor) == 0: + self.textbox.send_msg("zero division error!!!", "#FF0000") + return False + quotient = bin_to_dec(dividend) // bin_to_dec(divisor) + result_binary = dec_to_bin(quotient) + return result_binary + # remainder = bin(int(dividend, 2) % int(divisor, 2))[2:] + + def reg_enhance_display(self, rx): + """强化显示R1-R4""" + self.alu.canvas.delete("reg") + for i in range(4): + if rx == f"R{i + 1}": + self.alu.canvas.create_line(365, 120 + i * 90, 513, 120 + i * 90, width=8, fill="#00FF00", tag="reg") + self.alu.canvas.create_line(365, 75 + i * 90, 513, 75 + i * 90, width=8, fill="#00FF00", tag="reg") + + def gen_opera(self, rx=None, ry=None, op=None, sing_num=None): # 一般计算规则 + """ + rx为小号寄存器,ry为大号寄存器 + 寄存器字母一定要填大小 + """ + if op is not None: + cpu_data.ALUop[op] = True + + alu_line = [] + rt1, rt2 = None, None + for reg, entry in self.regs.items(): # 遍历寄存器编号和寄存器实体框 + entry.config(bg=WHITE) # 寄存器恢复 + if reg == rx: + rt1 = entry + alu_line.append(f"{rx}_ALU_1") + cpu_data.ALUio[f"{rx}_ALU_1"] = True + # entry.config(bg=RED) + if reg == ry: + rt2 = entry + alu_line.append(f"{ry}_ALU_2") + cpu_data.ALUio[f"{rx}_ALU_1"] = True + # entry.config(bg=RED) + if rx is not None and ry is not None: + v1 = rt1.get() # 获取R1的值 + v2 = rt2.get() # 获取R2的值 + + if sing_num == 4: + self.alu.show_alu_line(alu_line) # 节拍5时显示寄存器到ALU的路线 + self.alu.alu_operation() # 显示符号 + rt1.config(bg=RED) + rt2.config(bg=RED) + + # rt1.config(bg=WHITE) + # rt2.config(bg=WHITE) + alu_line = [] + if sing_num == 5: + if op == "+": + v = self.binary_addition(v1, v2) # 二进制加 + elif op == "-": + v = self.binary_subtraction(v1, v2) # 二进制减法 + elif op == "x": + v = self.binary_multiplication(v1, v2) # 二进制乘法 + elif op == "÷": + v = self.binary_division(v1, v2) # 二进制除法 + else: + v = None + alu_line.append(f"ALU_{rx}") + + self.alu.alu_operation() # 显示符号 + self.alu.show_alu_line(alu_line) # 显示数据控制线 + self.entry_replace(rt1, f"{v}") # 替换R1中的值 + rt1.config(bg=RED) + + def pc_add_one(self, b16): + v = int(b16, 2) + return f"{v + 1:016b}" + + def reg_update(self): + self.sing.pc_reg.config(bg=WHITE) # 更新PC寄存器的背景显示 + self.sing.ins.config(bg=WHITE) # 更新ins背景 + self.sing.ir_reg.config(bg=WHITE) # 更新IR的颜色 + self.alu.r1.config(bg=WHITE) + self.alu.r2.config(bg=WHITE) + self.alu.r3.config(bg=WHITE) + self.alu.r4.config(bg=WHITE) + + # 储存寄存器在储存类中已经处理,这里不再重复处理 + + def SimGet(self, sing_num, reg_code=None): + """取数指令""" + self.textbox.send_instr("取数") + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() # 恢复寄存器 + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.addr_line() # 更新地址线 + self.alu.show_alu_line() # 更新alu的数据线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.singe_ctrl_line(["MCO"]) # 显示控制线 + + if reg_code in self.register_mapping: # 选择寄存器 + register, data_line = self.register_mapping[reg_code] + self.gui.data_line(data_line) + self.entry_replace(register, self.memo.mco.get()) + register.config(bg=RED) + canvas.update() + + def SimPut(self, sing_num, reg_code=None): + """存数指令""" + self.textbox.send_instr("存数") + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + if reg_code in self.register_mapping: # 选择寄存器 + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + + self.reg_update() # 恢复寄存器 + self.sing.clo_mark(sing_num) + self.sing.show_singe(["MEMORY"]) + self.gui.singe_ctrl_line(["MCO"]) + self.gui.addr_line() + # self.gui.data_line("r1-mco") + self.alu.show_alu_line() # 更新alu的数据线 + self.gui.data_line(f"{reg}-{mco}") # 重构参数 + # self.memo.mco_to_memo() # 更新储存的显示显示 + + + self.entry_replace(self.memo.mco, register.get()) + register.config(bg=RED) + + self.memo.mco_to_memo() # 更新储存的显示显示 + canvas.update() + + def SimAddr(self, sing_num, reg_code=None): + """加法指令""" + self.textbox.send_instr("加法") + + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + if reg_code in self.register_mapping: # 选择寄存器 + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1])+1 + + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MCO", f"R{reg}"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line(f"mco-r{reg}") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + # self.memo.mad_to_memo() # 显示memo动画 + self.entry_replace(eval(f'self.alu.r{reg}'), self.memo.mco.get()) # 更新显示R1中的值 + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + if reg_code in self.register_mapping: # 选择寄存器 + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1])+1 + + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["ALU"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["ALU"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}", "+", sing_num) + canvas.update() + + if sing_num == 5: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + if reg_code in self.register_mapping: # 查找寄存器 + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1])+1 + + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe() # 显示控制器信号 + self.gui.singe_ctrl_line() # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}", "+", sing_num) + canvas.update() + + def SimMinus(self, sing_num, reg_code): + """减法指令""" + self.textbox.send_instr(f"减法") + + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1]) + 1 + + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MCO", f"R{reg}"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line(f"mco-r{reg}") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + self.entry_replace(eval(f"self.alu.r{reg}"), self.memo.mco.get()) # 更新显示R2中的值 + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["ALU"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["ALU"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}", "-", sing_num) + canvas.update() + + if sing_num == 5: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe() # 显示控制器信号 + self.gui.singe_ctrl_line() # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}","-", sing_num) + canvas.update() + + def SimProduct(self, sing_num, reg_code): + """乘法指令""" + self.textbox.send_instr(f"乘法") + + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1]) + 1 + + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MCO", f"R{reg}"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line(f"mco-r{reg}") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + self.entry_replace(eval(f"self.alu.r{reg}"), self.memo.mco.get()) # 更新显示R2中的值 + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["ALU"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["ALU"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}", "x", sing_num) + canvas.update() + + if sing_num == 5: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe() # 显示控制器信号 + self.gui.singe_ctrl_line() # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}","x", sing_num) + canvas.update() + + def SimDiv(self, sing_num, reg_code): + """除法指令""" + self.textbox.send_instr(f"除法") + + register, data_line = self.register_mapping[reg_code] + mco, reg = data_line.split("-") + reg = int(reg[-1]) + 1 + + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MCO", f"R{reg}"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line(f"mco-r{reg}") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + self.entry_replace(eval(f"self.alu.r{reg}"), self.memo.mco.get()) # 更新显示R2中的值 + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["ALU"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["ALU"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.gen_opera(f"R{reg-1}", f"R{reg}", "÷", sing_num) + canvas.update() + + if sing_num == 5: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe() # 显示控制器信号 + self.gui.singe_ctrl_line() # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线0. + + + self.gen_opera(f"R{reg-1}", f"R{reg}", "÷", sing_num) + canvas.update() + + def SimPrint(self, sing_num): + self.textbox.send_instr("打印") + + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MCO", "R1"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line("mco-r1") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + self.entry_replace(self.alu.r1, self.memo.mco.get()) # 更新显示R2中的值 + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["R1"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["R1"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + val = self.alu.r1.get() + self.textbox.send_msg(f"打印输出:\n'{val}'") + binary_string = bin_to_dec(val) + self.textbox.send_msg(f"10进制转换:'{binary_string}'") + canvas.update() + + # print(self.alu.r1.get()) + + def SimStop(self, sing_num): + self.textbox.send_instr("停机") + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["PC+1"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["PC+1"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.sing.pc_value = f"{0:016b}" # PC 置0 + self.sing.pc_reg_value() + self.textbox.send_msg("PC = 0") + self.sing.pc_reg.config(bg=RED) + self.sing.ins.config(bg=RED) + canvas.update() + + if sing_num == 4: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark() # 显示节拍 + self.sing.show_singe() # 显示控制器信号 + self.gui.singe_ctrl_line() # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + self.textbox.send_msg("系统停机") + canvas.update() + + def SimGoto(self, sing_num): + self.textbox.send_instr("跳转") + if sing_num == 3: + self.textbox.send_msg(f"======Step{sing_num + 1}======") + self.reg_update() + self.sing.clo_mark(sing_num) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MAD", "MCO", "PC+1"]) # 显示控制线 + self.gui.addr_line() # 更新地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line("mco-pc") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + mco_value = self.memo.mco.get() + self.entry_replace(self.sing.pc_reg, mco_value) + self.memo.mco.config(bg=RED) + self.sing.pc_reg.config(bg=RED) + canvas.update() + + def lw_(self, one_inscode=None, is_meter=None, step=None): + ''' + 取指令 + :param one_inscode: 执行模式,分单指令自动执行,和分节拍手动执行 + :param is_meter: 控制是否为分节拍模式 True则表示分节拍执行 + :param step: 节拍步骤 + :return: 停机指令 + ''' + + + if step <= 2: # 前三节拍都更新取指令,后面的节拍更新其他指令 + self.textbox.send_instr("取指令") + + # if i == 0: + if step == 0: + self.textbox.send_msg(f"\n\n\n======Step{step + 1}======") + self.reg_update() # 更新各个寄存器颜色为白色 + self.sing.clo_mark(step) # 显示节拍 + self.sing.show_singe(["MEMORY"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["MAD"]) # 显示信号控制线 + self.gui.addr_line(["PC-MAD"]) # 显示地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线 + self.alu.show_alu_line() # 更新alu的数据线 + + self.alu.alu_operation() # 更新alu的符号 + # self.gen_opera() # 更新寄存器显示 + + maddr = self.sing.pc_reg.get() # 获取pc寄存器的值 + self.sing.pc_reg.config(bg=RED) # 更新PC寄存器的背景显示 + self.memo.show_maddr(maddr, 1) # 更新maddr的显示和值 + + canvas.update() # 刷新显示 + if is_meter is None: # 不分节拍执行时,增加等待时间 + time.sleep(self.wait_time) + + # if i == 1: + if step == 1: + self.textbox.send_msg(f"======Step{step + 1}======") + self.reg_update() # 更新各个寄存器颜色为白色 + self.sing.clo_mark(step) # 显示节拍 + self.sing.show_singe(["IR"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["IR"]) # 显示控制线 + self.gui.addr_line() # 更新显示地址线 + self.memo.mad_to_memo(1) # 更新mad-mome的地址线,参数为真则显示 + self.gui.data_line("mco-ir") # 更新数据线 + self.alu.show_alu_line() # 更新alu的数据线 + + data = self.memo.mco.get() # 取得mco中的值 + self.sing.ir_value = data # 更新 ir的值 + self.sing.ir_reg_value() # 显示IR + self.sing.ir_reg.config(bg=RED) # 更新IR的颜色 + + canvas.update() # 刷新显示 + if is_meter is None: # 不分节拍执行时,增加等待时间 + time.sleep(self.wait_time) + + # if i == 2: + if step >= 2: + global inscode + if step == 2: + self.textbox.send_msg(f"======Step{step + 1}======") + self.reg_update() # 更新各个寄存器颜色为白色 + self.sing.clo_mark(step) # 显示节拍 + self.sing.show_singe(["PC+1", "IR"]) # 显示控制器信号 + self.gui.singe_ctrl_line(["PC+1", "IR"]) # 显示控制线 + self.gui.addr_line(["IR-MAD"]) # 更新地址线 + self.gui.data_line() # 更新数据线 + self.memo.mad_to_memo() # 更新mad-mome的地址线,参数为真则显示 + self.alu.show_alu_line() # 更新alu的数据线 + + self.sing.pc_value = self.sing.pc_reg.get() + self.sing.pc_value = self.pc_add_one(self.sing.pc_value) # pc+1 + self.sing.pc_reg_value() # 更新PC显示 + self.sing.pc_reg.config(bg=RED) # 更新PC背景 + + inscode, addr = self.sing.ir_value[:6], self.sing.ir_value[6:] # 拆分操作码和指令地址 + self.sing.ir_reg.config(bg=RED) # 更新IR背景 + self.entry_replace(self.sing.ins, inscode) # 更新 inscode值 + self.sing.ins.config(bg=RED) # 更新insCode背景 + self.memo.mad_value = f"{int(addr, 2):016b}" # 更新 maddr值 + self.memo.show_maddr(self.memo.mad_value, 1) # 显示maddr值 + + canvas.update() # 刷新显示 + if is_meter is None: # 不分节拍执行时,增加等待时间 + time.sleep(self.wait_time) + + if one_inscode is not None: # 如果有单指令,直接执行该指令 + self.instruct(one_inscode) + else: # 如果没有单指令,执行读取到的指令 + if is_meter: # 如果是分节拍执行。 + stop_tag = self.instruct(inscode, step) # 加入步骤参数 + return stop_tag + else: # 否则是自动执行 + stop_tag = self.instruct(inscode) # 不加步骤参数 + if stop_tag == "stop": return "stop" + + def instruct(self, inscode, step=None): + dec = int(inscode, 2) # + com_code = inscode[2:] + reg_code = inscode[:2] + + if com_code == '0001': # 取数指令 + if step is not None: # 当有手动指令时执行手动指令 + self.SimGet(step, reg_code) + if step >= 3: + return "end" + else: + for i in range(3, 4): + self.SimGet(i, reg_code) + time.sleep(self.wait_time) + + if com_code == "0010": # 存数指令 + if step is not None: + self.SimPut(step, reg_code) + if step >= 3: + return "end" + else: + for i in range(3, 4): + self.SimPut(i, reg_code) + time.sleep(self.wait_time) + + if com_code == "0011": + if reg_code!="11": # 加法指令 + if step is not None: + self.SimAddr(step, reg_code) + if step >= 5: + return "end" + else: + for i in range(3, 6): + self.SimAddr(i, reg_code) + time.sleep(self.wait_time) + else: + self.textbox.send_msg("寄存器超限!!!", fg="#FF0000") + + + if com_code == "0111": # 减法指令 + if reg_code != "11": # 加法指令 + if step is not None: + self.SimMinus(step, reg_code) + if step >= 5: + return "end" + else: + for i in range(3, 6): + self.SimMinus(i,reg_code) + time.sleep(self.wait_time) + else: + self.textbox.send_msg("寄存器超限!!!", fg="#FF0000") + + + if com_code == "0100": # 乘法指令 + if reg_code != "11": + if step is not None: + self.SimProduct(step, reg_code) + if step >= 5: + return "end" + else: + for i in range(3, 6): + self.SimProduct(i, reg_code) + time.sleep(self.wait_time) + else: + self.textbox.send_msg("寄存器超限!!!", fg="#FF0000") + + if com_code == "1000": # 除法指令 + if reg_code!= "11": + if step is not None: + self.SimDiv(step,reg_code) + if step >= 5: + return "end" + else: + for i in range(3, 6): + self.SimDiv(i, reg_code) + time.sleep(self.wait_time) + else: + self.textbox.send_msg("寄存器超限!!!", fg="#FF0000") + + if com_code == "1001": # 跳转指令 + if step is not None: + self.SimGoto(step) + if step >= 3: + return "end" + else: + for i in range(3, 4): + self.SimGoto(i) + time.sleep(self.wait_time) + + if com_code == "0101": # 打印指令 + if step is not None: + self.SimPrint(step) + if step >= 4: + return "end" + else: + for i in range(3, 5): + self.SimPrint(i) + time.sleep(self.wait_time) + + if com_code == "0110": # 停机指令 + if step is not None: + self.SimStop(step) + if step >= 4: + return "stop" + else: + for i in range(3, 5): + self.SimStop(i) + time.sleep(self.wait_time) + if i >= 4: + return "stop" # 停机标志 + + def exe____________________________________(self): + pass + + def exe_one_instruct(self, inscode): + """单指令执行""" + for i in range(3): + self.lw_(inscode, step=i) + + def exec_auto(self): # 自动执行储存程序 + while True: + instr_stute = None # 指令状态为"stop"时退出循环。 + for i in range(3): + if self.ctrl_stop: + instr_stute = "stop" + break + instr_stute = self.lw_(step=i) + if instr_stute == "stop": + break + + def exec_next(self): + statu = self.lw_(is_meter=True, step=self.manual_opera_step) # 执行指令 + self.manual_opera_step += 1 + if statu == "end" or self.manual_opera_step > 5: # 指令结束或者节拍序号大于5都将节拍重置鱼0 + self.manual_opera_step = 0 + + elif statu == "stop": # 若上一条指令返回停机指令,则disable下一步按键 + self.next_button.config(state=tk.DISABLED) + + def read_file(self): + initial_dir = "/data/workspace/myshixun/src" + filename = filedialog.askopenfilename(title="选择文件",initialdir=initial_dir, filetypes=[("TXT文件", "*.txt")]) + if filename: + with open(filename, "r", encoding="utf8") as f: + memo_line = f.readlines() # 按行读取文件信息 + for index, line in enumerate(memo_line): + line = line.replace("\n", "") # 去掉换行符 + if index < 20 and re.match("^[01]{16}$", line): + self.memo.mem_save(index, line, load=True) + else: + self.textbox.send_msg(f"【{index:02X}】数据异常请检查") + if index > 19: + break + self.textbox.send_msg("装载完成") + self.entry_replace(self.sing.pc_reg, f"{0:016b}") + + def manual_input(self): + self.child_window = tk.Toplevel(root) + self.child_window.title("手动输入程序") + self.child_window.geometry("350x360") + + fram_down = tk.Frame(self.child_window) + tk.Label(fram_down, text="指令输入", font=("微软雅黑", 16, "bold")).grid(row=0, column=0, columnspan=3) + + fram_down.place(x=0, y=0, width=350, height=360) + offset_label = tk.Label(fram_down, text="地址", font=("微软雅黑", 16)) + offset_label.grid(row=1, column=0, sticky="nsew") + + inscode_label = tk.Label(fram_down, text="指令", font=("微软雅黑", 16)) + inscode_label.grid(row=1, column=1, sticky="nsew") + + o_value_label = tk.Label(fram_down, text="寻址地址", font=("微软雅黑", 16)) + o_value_label.grid(row=1, column=2, sticky="nsew") + + hex_options = [f"{i:02X}" for i in range(20)] # 生成00-13的16进制选项 + offset_input = ttk.Combobox(fram_down, values=hex_options, font=("微软雅黑", 12), width=1) + offset_input.grid(row=2, column=0, sticky="nsew", padx=5) + + inscode_options = list(inscode_map.keys()) + self.inscode_input = ttk.Combobox(fram_down, values=inscode_options, font=("微软雅黑", 12), width=6) + self.inscode_input.grid(row=2, column=1, sticky="nsew", padx=5) + self.inscode_input.bind("<>", self.on_inscode_select) + + bin_options = [f"{i:02X}" for i in range(20)] # 生成00-13的16进制选项 + self.o_value_input = ttk.Combobox(fram_down, values=bin_options, font=("微软雅黑", 12), width=10) + self.o_value_input.grid(row=2, column=2, sticky="nsew", padx=5) + self.o_value_input.bind("<>", self.on_offset_select) + + save_b = tk.Button(fram_down, text="确认", bg=RED, font=("微软雅黑", 12), + command=lambda: self.save_to_mome(offset_input.get())) + save_b.grid(row=3, column=0, columnspan=3, sticky="nsew", padx=10, pady=4) + + tk.Label(fram_down, text="*" * 300, font=("微软雅黑", 16)).grid(row=4, column=0, columnspan=3) + + # 地址输入 + tk.Label(fram_down, text="数据输入", font=("微软雅黑", 16, "bold")).grid(row=5, column=0, columnspan=3) + + d_off = tk.Label(fram_down, text="地址", font=("微软雅黑", 16)) + d_off.grid(row=6, column=0, sticky="nsew") + + d_value_lb = tk.Label(fram_down, text="数据", font=("微软雅黑", 16)) + d_value_lb.grid(row=6, column=1, columnspan=2, sticky="nsew") + + hex_options = [f"{i:02X}" for i in range(20)] # 生成00-13的16进制选项 + d_off_in = ttk.Combobox(fram_down, values=hex_options, font=("微软雅黑", 12), width=1) + d_off_in.grid(row=7, column=0, sticky="nsew", padx=5) + + self.d_value = tk.Entry(fram_down, font=("微软雅黑", 12)) + self.d_value.grid(row=7, column=1, columnspan=2, sticky="nsew") + self.d_value.insert(0, "支持10进制和16位进制") + + d_save = tk.Button(fram_down, text="确认", bg=RED, font=("微软雅黑", 12), + command=lambda: self.data_to_mome(d_off_in.get())) + d_save.grid(row=8, column=0, columnspan=3, sticky="nsew", padx=10, pady=4) + + # 配置列权重,使它们按比例占据整个宽度 + fram_down.columnconfigure(0, weight=2) + fram_down.columnconfigure(1, weight=6) + fram_down.columnconfigure(2, weight=10) + + finish = tk.Button(fram_down, text="装载完成", bg=GOLD, font=("微软雅黑", 12), command=self.load_finish) + finish.grid(row=9, column=2, sticky="nsew", padx=10) + + def load_finish(self): + self.child_window.destroy() + self.entry_replace(self.sing.pc_reg, f"{0:016b}") + + def on_offset_select(self, event): + ox16 = self.o_value_input.get() + value = int(ox16, 16) + self.o_value_input.set(f"{value:010b}") + + def on_inscode_select(self, event): + # 获取选择的值 + selected_value = self.inscode_input.get() + inscode = inscode_map.get(selected_value) + self.inscode_input.set(inscode) + print(selected_value) + + def data_to_mome(self, offset_input): + data_input = self.d_value.get() + if offset_input and data_input: + offset = int(offset_input, 16) + if re.match("^-?[01]{16}$", data_input): + self.memo.mem_save(offset, data_input, load=True) + elif re.match("^-?\d+$", data_input) and len(data_input) < 7: # 如果是10进制数不可能多于7位 + # data_input = f"{int(data_input):016b}" + data_input = cpu_data.dec_to_bin(int(data_input)) + self.memo.mem_save(offset, data_input, load=True) + else: + if len(data_input) > 16: + self.textbox.send_msg(f"{data_input}不是16位数。") + else: + self.textbox.send_msg(f"{data_input}不是规范的二进制数。") + + def save_to_mome(self, offset): + inscode = self.inscode_input.get() + value = self.o_value_input.get() + if offset: + offset = int(offset, 16) + if inscode and value: + value = inscode + value + + self.memo.mem_save(offset, value, load=True) + + # tk.Label(child_window,text="预览",font=('aril', 18)).place(x=15,y=10) + # tk.Label(child_window,text="操作",font=('aril', 18)).place(x=290,y=10) + # tk.Button(child_window,text="00-09",font=('aril', 12),command = lambda :self.yulan(child_window, SimMem)).place(x=145,y=10) + # tk.Button(child_window,text="0A-13",font=('aril', 12)).place(x=200,y=10) + # + # + # for i in range(10): + # self.offset = tk.Label(child_window, text=f"{i:02X}", font=('aril', 14)) + # self.offset.place(x=10, y=50+30*i) + # bin_str = insert_char(memo[i], " ", 8) + # self.value = tk.Label(child_window, text=bin_str, font=('aril', 14)) + # self.value.place(x=40, y=50+30*i) + # self.delete_val = tk.Button(child_window, text=f"x", font=('aril', 12)) + # self.delete_val.place(x=230, y=50+30*i) + # + # + # def on_click(event=None): + # print(event.x, event.y) + # child_window.bind("", on_click) + # + # def yulan(self, child_window:tk.Toplevel, memo): # 预览 + # for i in range(10): + # self.offset = tk.Label(child_window, text=f"{i:02X}", font=('aril', 14)) + # self.offset.place(x=10, y=50+30*i) + # bin_str = insert_char(memo[i], " ", 8) + # self.value = tk.Label(child_window, text=bin_str, font=('aril', 14)) + # self.value.place(x=40, y=50+30*i) + # self.delete_val = tk.Button(child_window, text=f"x", font=('aril', 12)) + # self.delete_val.place(x=230, y=50+30*i) + + # def prev(self): + # self.next_button.config(state=tk.NORMAL) + # if self.manual_opera_step > 0: + # self.manual_opera_step -= 1 + # self.lw_(is_meter=True, step=self.manual_opera_step) + # else: + # self.prev_button.config(state=tk.DISABLED) + + # def exec_manual_operation(self): + # '''分节拍顺序执行''' + # self.lw_(is_meter=True, step=self.manual_opera_step) + + +if __name__ == '__main__': + # SimMem[0] = f"0000010000001010" # SimMem[10] => r1 + # SimMem[1] = f"0000110000001011" # r1+SimMem[11] => r1 + # SimMem[2] = f"0001000000001100" # r1*SimMem[12] => r1 + # SimMem[3] = f"0010000000001101" # r1//SimMem[13] => r1 + # SimMem[4] = f"0001110000001110" # r1-SimMem[14] => r1 + # SimMem[5] = f"0000100000001111" # 存数到15地址 r1 => SimMem[15] + # SimMem[6] = f"0001010000001111" # 打印 SimMem[15] + # SimMem[7] = f"0001100000000000" # 停机 + # # SimMem[0] = f"0001100000000000" # 停机 + # + # SimMem[10] = dec_to_bin(9) # 10 地址数据 + # SimMem[11] = dec_to_bin(11) # 11 地址数据 + # SimMem[12] = dec_to_bin(5) # 12 地址数据 + # SimMem[13] = dec_to_bin(10) # 13 号位的值 + # SimMem[14] = dec_to_bin(11) # 14 地址数据 + + # for ss in SimMem: + # print(ss) + + exe = ExecInstructWithText() + + + def main(): + pass + + + root.mainloop() diff --git a/src/gui.py b/src/gui.py new file mode 100644 index 0000000..c680ac9 --- /dev/null +++ b/src/gui.py @@ -0,0 +1,919 @@ +# -*- encoding: utf-8 -*- +""" +@File : gui.py +@License : (C)Copyright 2021-2023 + +@Modify Time @Author @Version @Description +------------ ------- -------- ----------- +2023/11/1 13:37 zart20 1.0 None +""" + +import tkinter as tk +from tkinter import scrolledtext + +import cpu_data +from cpu_data import * + +WORD = '#00f5ff' +BLACK = "#000000" +WHITE = "#F0F0F0" +DATALINE= "#0CB90C" +ADDRLINE = "#f35555" +RED = "#FFAAAA" +GREY = '#808080' +GOLD = '#FFD700' +GREEN = '#00FA9A' +BACK = '#0153d2' +ORANGE = '#d3b719' +MEMBACK = '#fba651' +width = 1000 # 设置窗口宽度 +height = 700 +root = tk.Tk() +root.title("16位简易CPU可视化") +root.geometry(f"{1300}x{700}") + +canvas = tk.Canvas(root, bg='white', bd=2, relief="sunken", width=width + 300, height=height, background=BLACK, + borderwidth=0, highlightthickness=0) +canvas.place(x=0, y=0, anchor=tk.NW, width=1300, height=700) + + +# root_right = tk.Frame(root, bg=WHITE, relief="groove", width=240, height=height - 40) +# root_right.place(x=width+25, y=15, anchor=tk.NW) # 右边栏 + + +def round_rectangle(x1, y1, x2, y2, r=25, **kwargs): + points = ( + x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, + y2, + x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, + y1) + return canvas.create_polygon(points, **kwargs, smooth=True) + + +round_rectangle(width + 20, 15, width + 270, height - 25, r=25, fill=WHITE, width=0) +round_rectangle(20, 15, 970, height - 25, r=25, fill=WHITE, width=0) + + +class TextBox: + def __init__(self, canvas): + self.canvas = canvas + self.l_x = 1020 + self.r_x = 1027 + self.m_x = 1145 # 消息区X轴中线位置 + self.m_y = 265 # 消息区y轴分割位置 + self.create_text_box() # 显示消息框 + self.create_button("X", 1235, 255, self.clear, "") + self.instr_label() + + def main_msg_box(self, msg: str, y: int): + # 在Canvas上创建主要消息框 + self.canvas.create_text(self.m_x, y, text=msg, font=('微软雅黑', 20), fill="black") + + def create_button(self, text: str, x: int, y: int, command: callable, tags="button", **kwargs) -> tk.Button: + # 创建文本按钮 + + button = tk.Button(self.canvas, text=text, command=command, **kwargs) + self.canvas.create_window(x, y, anchor=tk.NW, window=button, tags=tags) + return button + + def instr_label(self) -> None: + self.label = tk.Label(self.canvas, font=('微软雅黑', 16), width=10) + self.canvas.create_window(self.m_x, 220, anchor=tk.CENTER, window=self.label) + + def send_instr(self,text: str) -> None: + formatted_text = f"指令:{text}" + # 如果你想更新 Label 的文本,使用 configure 而不是再次创建 Label + self.label.config(text=formatted_text, bg=RED) + + + + + def create_button_with_image(self, image_path: str, x: int, y: int, command: callable, **kwargs) -> None: + # 加载图片 + image = tk.PhotoImage(file=image_path) + + # 创建带有图片的按钮 + button = tk.Button(self.canvas, image=image, command=command, **kwargs) + button.image = image # 保持对图片的引用,防止被垃圾回收 + + # 在Canvas上创建带有图片的按钮 + self.canvas.create_window(x, y, anchor=tk.NW, window=button, tags="button") + + def create_text_box(self): + """创建多行输入框""" + self.info_text = scrolledtext.ScrolledText(self.canvas, wrap=tk.WORD, height=15, width=20) + self.info_text.place(x=1025, y=290, anchor=tk.NW) + self.info_text.config(font=("微软雅黑", 14)) + + def send_msg(self, text: str, fg=None) -> None: + '''向输入框发送系统消息''' + self.info_text.insert(tk.END, text + "\n") + if fg is not None: + self.info_text.config(fg=fg) + self.info_text.see(tk.END) + + def clear(self) -> None: + '''清空系统消息框''' + if self.info_text.get("1.0", tk.END).strip() != "": # 检查文本框内容是否非空 + self.info_text.delete("1.0", tk.END) + + +textbox = TextBox(canvas) # 全局化消息框 + + +class GUISim: + def __init__(self): + self.canvas = canvas + self.canvas.bind("", self.on_left_click) + # root_right.bind("", self.on_left_click) + self.alu = ALU() + self.memo = MEMO() + self.sigctrl = SIGCtrl() + self.textbox = textbox # 为了让引用GUIsim类的对象来使用消息框 + self.singe_ctrl_line() + self.addr_line() + self.data_line() + self.line_explain() + # self.show_msg() + + def round_rectangle(self, x1, y1, x2, y2, r=25, **kwargs): + points = ( + x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, + y2, + x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, + y1) + return self.canvas.create_polygon(points, **kwargs, smooth=True) + + def on_left_click(self, event): + print(event.x, ",", event.y) + + def singe_ctrl_line(self, sings=None): # 控制线 + if sings is None: + sings = [] + self.canvas.delete("ctrl_line") + # alu + line_points = [90, 575, 65, 575, 65, 235, 98, 235] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + self.alu.draw_circle(103, 235, 5, fill=GREY, tags="ctrl_line") + + # maddr + line_points = [205, 630, 205, 660, 630, 660, 630, 545] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # r1 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 95, 515, 95] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # r2 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 189, 515, 189] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # r3 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 276, 515, 276] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # r4 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 368, 515, 368] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # Mcontent + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 885, 30, 885, 215] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # pc + line_points = [280, 540, 350, 540, 350, 485] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # IR + line_points = [225, 630, 225, 650, 350, 650, 350, 590] + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, + tags="ctrl_line", dash=(10, 10)) + + # IR -> inscode + line_points = [332, 575, 275, 575] + self.canvas.create_line(line_points, width=2, fill="black", arrow=tk.LAST, + tags="ctrl_line") + + # clock -> inscode + line_points = [200, 495, 200, 523] + self.canvas.create_line(line_points, width=2, fill="black", arrow=tk.LAST, + tags="ctrl_line") + + for sing in sings: + if sing == "ALU": + # alu + line_points = [90, 575, 65, 575, 65, 235, 98, 235] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.alu.draw_circle(103, 235, 5, fill=GREEN, tags="ctrl_line") + self.textbox.send_msg("Sig->ALU") + if sing == "MAD": + # maddr + line_points = [205, 630, 205, 660, 630, 660, 630, 545] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->MAD") + if sing == "R1": + # r1 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 95, 515, 95] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->R1") + if sing == "R2": + # r2 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 189, 515, 189] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->R2") + if sing == "R3": + # r3 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 276, 515, 276] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->R3") + if sing == "R4": + # r4 + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 560, 368, 515, 368] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->R4") + if sing == "MCO": + # Mcontent + line_points = [135, 630, 135, 660, 45, 660, 45, 30, 560, 30, 885, 30, 885, 215] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->MCO") + if sing == "PC+1": + # pc + line_points = [280, 540, 350, 540, 350, 485] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->PC+1") + if sing == "IR": + # IR + line_points = [225, 630, 225, 650, 350, 650, 350, 590] + self.canvas.create_line(line_points, width=5, fill="red", arrow=tk.LAST, tags="ctrl_line", + dash=(10, 10)) + self.textbox.send_msg("Sig->IR") + + def addr_line(self, sings=None): # 地址线 + if sings is None: + sings = [] + self.canvas.delete("addr_line") + # IR -> Maddr + line_points = [400, 560, 400, 515, 560, 515, 614, 515] + self.canvas.create_line(line_points, width=4, fill=GREY, arrow=tk.LAST, tags="addr_line") + + # pc -> Maddr + line_points = [485, 465, 615, 465] + self.canvas.create_line(line_points, width=4, fill=GREY, arrow=tk.LAST, tags="addr_line") + + for sing in sings: + if sing == "IR-MAD": + # IR -> Maddr + line_points = [400, 560, 400, 515, 560, 515, 614, 515] + self.canvas.create_line(line_points, width=4, fill=ADDRLINE, arrow=tk.LAST, tags="addr_line") + self.textbox.send_msg("IR->MAD") + if sing == "PC-MAD": + # pc -> Maddr + line_points = [485, 465, 615, 465] + self.canvas.create_line(line_points, width=4, fill=ADDRLINE, arrow=tk.LAST, tags="addr_line") + self.textbox.send_msg("PC->MAD") + + def data_line(self, singe=None): # 数据线 + self.canvas.delete("data_line") + # mco -> r1 + line_points = [765, 218, 765, 175, 570, 175, 570, 108, 518, 108] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # r1 -> mco + line_points = [765, 218, 765, 175, 570, 175, 570, 108, 518, 108] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # mco -> r2 + line_points = [765, 218, 765, 175, 570, 175, 570, 198, 518, 198] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # r2 -> mco + line_points = [765, 218, 765, 175, 570, 175, 570, 198, 518, 198] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # mco -> r3 + line_points = [765, 218, 765, 175, 570, 175, 570, 288, 518, 288] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # r3 -> mco + line_points = [765, 218, 765, 175, 570, 175, 570, 288, 518, 288] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # mco -> r4 + line_points = [765, 218, 765, 175, 570, 175, 570, 378, 518, 378] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # r4 -> mco + line_points = [765, 218, 765, 175, 570, 175, 570, 378, 518, 378] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # mco -> ir + line_points = [765, 218, 765, 175, 570, 175, 570, 575, 495, 575] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + # mco -> pc + line_points = [765, 218, 765, 175, 570, 175,570,475, 485, 475] + self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + + + # # memo -> mco + # line_points = [855, 245, 855, 275] + # self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="data_line") + # # mco -> memo + # line_points = [875, 245, 875, 275] + # self.canvas.create_line(line_points, width=5, fill=GREY, tags="data_line") + + # mco -> r1 + if singe == "mco-r1": + line_points = [765, 218, 765, 175, 570, 175, 570, 108, 518, 108] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->R1") + self.alu.r1.config(bg=RED) + # r1 -> mco + if singe == "r1-mco": + line_points = [765, 218, 765, 175, 570, 175, 570, 108, 518, 108] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.FIRST, tags="data_line") + self.textbox.send_msg("R1->MCO") + self.memo.mco.config(bg=RED) + # mco -> r2 + if singe == "mco-r2": + line_points = [765, 218, 765, 175, 570, 175, 570, 198, 518, 198] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->R2") + self.alu.r2.config(bg=RED) + # r2 -> mco + if singe == "r2-mco": + line_points = [765, 218, 765, 175, 570, 175, 570, 198, 518, 198] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.FIRST, tags="data_line") + self.textbox.send_msg("R2->MCO") + self.memo.mco.config(bg=RED) + # mco -> r3 + if singe == "mco-r3": + line_points = [765, 218, 765, 175, 570, 175, 570, 288, 518, 288] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->R3") + self.alu.r3.config(bg=RED) + # r3 -> mco + if singe == "r3-mco": + line_points = [765, 218, 765, 175, 570, 175, 570, 288, 518, 288] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.FIRST, tags="data_line") + self.textbox.send_msg("R3->MCO") + self.memo.mco.config(bg=RED) + # mco -> r4 + if singe == "mco-r4": + line_points = [765, 218, 765, 175, 570, 175, 570, 378, 518, 378] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->R4") + self.alu.r4.config(bg=RED) + # r4 -> mco + if singe == "r4-mco": + line_points = [765, 218, 765, 175, 570, 175, 570, 378, 518, 378] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.FIRST, tags="data_line") + self.textbox.send_msg("R4->MCO") + self.memo.mco.config(bg=RED) + # mco -> ir + if singe == "mco-ir": + line_points = [765, 218, 765, 175, 570, 175, 570, 575, 495, 575] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->IR") + self.sigctrl.ir_reg.config(bg=RED) + + # mco -> pc + if singe == "mco-pc": + line_points = [765, 218, 765, 175, 570, 175, 570, 475, 485, 475] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="data_line") + self.textbox.send_msg("MCO->PC") + + def line_explain(self): + """线的类型标签""" + line_points = [640, 60, 705, 60] + self.canvas.create_line(line_points, width=3, fill="red", tags="line", dash=(10, 10)) + self.canvas.create_text(737, 60, text="控制线", anchor=tk.CENTER, font=('微软雅黑', 12)) + + line_points = [640, 90, 705, 90] + self.canvas.create_line(line_points, width=4, fill=ADDRLINE, tags="line", ) + self.canvas.create_text(737, 90, text="地址线", anchor=tk.CENTER, font=('微软雅黑', 12)) + + line_points = [640, 120, 705, 120] + self.canvas.create_line(line_points, width=5, fill=DATALINE, tags="line", ) + self.canvas.create_text(737, 120, text="数据线", anchor=tk.CENTER, font=('微软雅黑', 12)) + + +class ALU: + def __init__(self): + self.canvas = canvas + self.r1_entry() + self.r2_entry() + self.r3_entry() + self.r4_entry() + self.alu_draw() # alu 图样 + self.alu_line_init() # alu 的描述 + self.show_alu_line() # alu 数据线 + self.show_alu_reg() # alu r1-r4 + self.alu_operation() # alu 符号 + + def draw_circle(self, x, y, r, fill=None, tags=None): + """根据圆心坐标和半径画圆""" + # 圆外接矩形 + x1, y1, x2, y2 = x - r, y - r, x + r, y + r + self.canvas.create_oval(x1, y1, x2, y2, width=1, fill=fill, tags=tags) + + def round_rectangle(self, x1, y1, x2, y2, r=25, **kwargs): + points = ( + x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, + y2, + x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, + y1) + return self.canvas.create_polygon(points, **kwargs, smooth=True) + + def alu_draw(self): + """画alu形状""" + # 定义倒梯形的顶点坐标 + self.round_rectangle(74, 48, 533, 415, fill="#226DDD", width=0, ) + Point = [90, 190, 120, 190, 130, 215, 205, 215, 215, 190, 245, 190, 220, 270, 115, 270] + self.canvas.create_polygon(Point, fill="black") # 绘制运算器 + self.draw_circle(103, 235, 5, fill=GREY, tags="alu_status") + + def alu_line_init(self): + """ALU模块命名""" + self.canvas.create_text(140, 183, text='ALU', font=('微软雅黑', 20), anchor=tk.NW, fill=WORD) + self.canvas.create_text(345, 95, text="R1", font=('微软雅黑', 18), fill=WORD) + self.canvas.create_text(345, 185, text="R2", font=('微软雅黑', 18), fill=WORD) + self.canvas.create_text(345, 275, text="R3", font=('微软雅黑', 18), fill=WORD) + self.canvas.create_text(345, 365, text="R4", font=('微软雅黑', 18), fill=WORD) + + def alu_operation(self): + """加减乘除""" + side = 30 + n = 0 + for i in "+-x÷": + if cpu_data.ALUop[i]: + cpu_data.ALUop[i] = False + self.canvas.create_text(115 + n * side, 240, text=f'{i}', font=('微软雅黑', 16), anchor=tk.NW, + fill="#FFFFCC") + textbox.send_msg(f"运算符: {i}") + else: + self.canvas.create_text(115 + n * side, 240, text=f'{i}', font=('微软雅黑', 16), anchor=tk.NW, + fill=GREY) + n += 1 + + def alu_r1(self, singed=None): + line_points = [170, 273, 170, 315, 270, 315, 270, 100, 330, 100, ] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def alu_r2(self, singed=None): + line_points = [170, 273, 170, 315, 270, 315, 270, 180, 330, 180, ] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def alu_r3(self, singed=None): + line_points = [170, 273, 170, 315, 270, 315, 270, 275, 330, 275, ] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def alu_r4(self, singed=None): + line_points = [170, 273, 170, 315, 270, 315, 270, 355, 330, 355, ] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r1_alu1(self, singed=None): + line_points = [340, 80, 340, 65, 310, 65, 100, 65, 100, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r2_alu1(self, singed=None): + line_points = [340, 165, 340, 155, 310, 155, 310, 65, 100, 65, 100, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r3_alu1(self, singed=None): + line_points = [340, 245, 340, 235, 310, 235, 310, 65, 100, 65, 100, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r4_alu1(self, singed=None): + line_points = [340, 335, 340, 325, 310, 325, 310, 65, 100, 65, 100, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r1_alu2(self, singed=None): + line_points = [340, 110, 340, 130, 295, 130, 295, 240, 250, 240, 250, 160, 230, 160, 230, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r2_alu2(self, singed=None): + line_points = [340, 200, 340, 220, 295, 220, 295, 240, 250, 240, 250, 160, 230, 160, 230, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r3_alu2(self, singed=None): + line_points = [340, 290, 340, 310, 295, 310, 295, 240, 250, 240, 250, 160, 230, 160, 230, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r4_alu2(self, singed=None): + line_points = [340, 380, 340, 395, 295, 395, 295, 240, 250, 240, 250, 160, 230, 160, 230, 190] + if singed: + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="alu_r_line") + else: + self.canvas.create_line(line_points, width=5, fill=GREY, arrow=tk.LAST, tags="alu_r_line") + + def r1_entry(self, str=f"{0:016b}"): + self.r1 = tk.Entry(self.canvas) + self.r1.insert(0, str) + self.r1.config(width=16, font=('微软雅黑', 12)) + ent_win = self.canvas.create_window(365, 85, window=self.r1, anchor=tk.NW) + ent_win.conjugate() + + def r2_entry(self, str=f"{0:016b}"): + self.r2 = tk.Entry(self.canvas) + self.r2.insert(0, str) + self.r2.config(width=16, font=('微软雅黑', 12)) + ent_win = self.canvas.create_window(365, 175, window=self.r2, anchor=tk.NW) + ent_win.conjugate() + + def r3_entry(self, str=f"{0:016b}"): + self.r3 = tk.Entry(self.canvas) + self.r3.insert(0, str) + self.r3.config(width=16, font=('微软雅黑', 12)) + ent_win = self.canvas.create_window(365, 265, window=self.r3, anchor=tk.NW) + ent_win.conjugate() + + def r4_entry(self, str=f"{0:016b}"): + self.r4 = tk.Entry(self.canvas) + self.r4.insert(0, str) + self.r4.config(width=16, font=('微软雅黑', 12)) + ent_win = self.canvas.create_window(365, 355, window=self.r4, anchor=tk.NW) + ent_win.conjugate() + + def show_alu_line(self, singed=None): + if singed is None: + singed = [] + self.canvas.delete("alu_r_line") + self.alu_r1() + self.alu_r2() + self.alu_r3() + self.alu_r4() + self.r1_alu1() + self.r2_alu1() + self.r3_alu1() + self.r4_alu1() + self.r1_alu2() + self.r2_alu2() + self.r3_alu2() + self.r4_alu2() + for singe in singed: + if singe == "ALU_R1": + self.alu_r1("ALU_R1") + textbox.send_msg("ALU->R1") + if singe == "ALU_R2": + self.alu_r2("ALU_R2") + textbox.send_msg("ALU->R2") + if singe == "ALU_R3": + self.alu_r3("ALU_R3") + textbox.send_msg("ALU->R3") + if singe == "ALU_R4": + self.alu_r4("ALU_R4") + textbox.send_msg("ALU->R4") + if singe == "R1_ALU_1": + self.r1_alu1("R1_ALU_1") + textbox.send_msg("R1->ALU1") + if singe == "R2_ALU_1": + self.r2_alu1("R2_ALU_1") + textbox.send_msg("R2->ALU1") + if singe == "R3_ALU_1": + self.r3_alu1("R3_ALU_1") + textbox.send_msg("R3->ALU1") + if singe == "R4_ALU_1": + self.r4_alu1("R4_ALU_1") + textbox.send_msg("R4->ALU1") + if singe == "R1_ALU_2": + self.r1_alu2("R1_ALU_2") + textbox.send_msg("R1->ALU2") + if singe == "R2_ALU_2": + self.r2_alu2("R2_ALU_2") + textbox.send_msg("R2->ALU2") + if singe == "R3_ALU_2": + self.r3_alu2("R3_ALU_2") + textbox.send_msg("R3->ALU2") + if singe == "R4_ALU_2": + self.r4_alu2("R4_ALU_2") + textbox.send_msg("R4->ALU2") + + def show_alu_reg(self, reg=None, str=None): + if reg == "r1": + self.r1.delete(0, tk.END) + self.r1.insert(0, str) + elif reg == "r2": + self.r2.delete(0, tk.END) + self.r2.insert(0, str) + elif reg == "r3": + self.r3.delete(0, tk.END) + self.r3.insert(0, str) + elif reg == "r4": + self.r4.delete(0, tk.END) + self.r4.insert(0, str) + + +class MEMO: + def __init__(self): + self.canvas = canvas + self.round_rectangle(597, 205, 928, 670, r=25, fill="#0153d2", width=0) + self.round_rectangle(675, 275, 910, 660, r=25, fill="black", width=0) + + self.canvas.create_rectangle(720, 281, 903, 654, fill=MEMBACK, width=0) + + self.mad_value = f"{0:016b}" + self.original_value = 9999 # 保存变量mad_value的原来值,用于检查值是否更新 + + self.show() + self.show_maddr(self.mad_value) + self.show_mco() + self.show_offset() + self.load_memo_data() + + def draw_circle(self, x, y, r, fill=None, tags=None): + """根据圆心坐标和半径画圆""" + # 圆外接矩形 + x1, y1, x2, y2 = x - r, y - r, x + r, y + r + self.canvas.create_oval(x1, y1, x2, y2, width=1, fill=fill, tags=tags) + + def round_rectangle(self, x1, y1, x2, y2, r=25, **kwargs): + points = ( + x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, + y2, + x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, + y1) + return self.canvas.create_polygon(points, **kwargs, smooth=True) + + def mad_to_memo(self, value=None): # value 用来控制地址线的显示 + """mad指向内存""" + self.show_maddr(self.mad_value) # 刷新Maddr的显示 + if value: + offset = int(self.mad_value, 2) # 转换为int + self.show_maddr(self.mad_value, 1) # 显示Maddr的变化 + else: + offset = None + self.mem_get(offset) # 从内存中获取响应地址的二进制值 + + def mco_to_memo(self): + """mco指向内存""" + offset = int(self.mad_value, 2) # int二进制转换 + value = self.mco.get() + self.mem_save(offset, value) + # textbox.send_msg("MCO->memo") + + def show(self): + self.canvas.create_text(670, 219, text='Mcontent', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + self.canvas.create_text(611, 356, text='Maddr', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + self.canvas.create_text(700, 260, text='地址', font=('微软雅黑', 14,), anchor=tk.CENTER, fill='#ffd700') + self.canvas.create_text(790, 260, text='在选单元', font=('微软雅黑', 14,), anchor=tk.CENTER, fill='#ffd700') + + def show_mco(self): + self.mco = tk.Entry(self.canvas) + self.mco.insert(0, f"{0:016b}") + self.mco.config(width=16, font=('微软雅黑', 12)) + ent_win = self.canvas.create_window(753, 218, window=self.mco, anchor=tk.NW) + ent_win.conjugate() + + def show_offset(self): + for i in range(20): # 显示存储器各个单元的地址 + self.canvas.create_text(688, 282 + 18.5 * i, text=f"{i:02X}", + font=('微软雅黑', 12), anchor=tk.NW, fill=GOLD) + + def load_memo_data(self): # 程序单元 + self.canvas.delete("bin_code") + for i in range(20): + bin_str = SimMem[i] + bin_str_spa = " ".join([bin_str[i:i + 8] for i in range(0, len(bin_str), 8)]) + self.canvas.create_text(735, 282 + 18.5 * i, text=bin_str_spa, + font=('微软雅黑', 12), anchor=tk.NW, fill="black", tags="bin_code") + self.draw_circle(675, 293 + 18.5 * i, 5, fill=GREY, tags="bin_code") + + def mem_save(self, offset, value, load=None): + self.canvas.delete("bin_code") + SimMem[offset] = value + for i in range(20): + bin_str = SimMem[i] + bin_str_spa = " ".join([bin_str[i:i + 8] for i in range(0, len(bin_str), 8)]) + self.canvas.create_text(735, 282 + 18.5 * i, text=bin_str_spa, + font=('微软雅黑', 12), anchor=tk.NW, fill="black", tags="bin_code") + if i == offset: + y = 293 + 18.5 * i + self.draw_circle(675, y, 7, fill=GREEN, tags="bin_code") + # Maddr -> memo + line_points = [650, y, 669, y] + self.canvas.create_line(line_points, width=4, fill=ADDRLINE, arrow=tk.LAST, tags="bin_code") + if load is None: + textbox.send_msg(f"MAD->memo[{i:02X}]") + # moo -> memo + line_points = [855, 245, 855, 275] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.LAST, tags="bin_code") + if load is None: + textbox.send_msg(f"MCO->memo[{i:02X}]") + else: + self.draw_circle(675, 293 + 18.5 * i, 5, fill=GREY, tags="bin_code") + + def mem_get(self, offset): + """获取offset地址的值""" + self.canvas.delete("bin_code") + # 更新内存显示值 + self.mco.config(bg=WHITE) + for i in range(20): + bin_str = SimMem[i] + bin_str_spa = " ".join([bin_str[i:i + 8] for i in range(0, len(bin_str), 8)]) + self.canvas.create_text(735, 282 + 18.5 * i, text=bin_str_spa, + font=('微软雅黑', 12), anchor=tk.NW, fill="black", tags="bin_code") + # 当传入地址时,显示数据线指示 + if i == offset: + y = 293 + 18.5 * i + self.draw_circle(675, y, 7, fill=RED, tags="bin_code") # 显示寻址单位激活态圆 + # Maddr -> memo + line_points = [650, y, 669, y] + self.canvas.create_line(line_points, width=4, fill=ADDRLINE, arrow=tk.LAST, tags="bin_code") + textbox.send_msg(f"MAD->memo[{offset:02X}]") + # memo -> Mco + line_points = [875, 245, 875, 275] + self.canvas.create_line(line_points, width=5, fill=DATALINE, arrow=tk.FIRST, tags="bin_code") + textbox.send_msg(f"memo[{offset:02X}]->MCO") + self.mco.delete(0, tk.END) # 更新mco的值 + self.mco.insert(0, SimMem[offset]) + self.mco.config(bg=RED) + else: + self.draw_circle(675, 293 + 18.5 * i, 5, fill=GREY, tags="bin_code") + + # if offset != None: # 如果有值则更新mco + # self.mco.delete(0, tk.END) # 更新mco的值 + # self.mco.insert(0,SimMem[offset]) + # self.mco.config(bg=RED) + + def show_maddr(self, get_pc, col_tag=None): + # 根据存储的数据显示当前Maddr的值 + self.mad_value = get_pc + self.canvas.delete("maddr") + if col_tag is not None: + self.canvas.create_rectangle(619, 383, 648, 541, fill=RED, width=0, tags="maddr") + else: + self.canvas.create_rectangle(619, 383, 648, 541, fill=WHITE, width=0, tags="maddr") + self.canvas.create_text(620, 380, text=self.mad_value, font=('微软雅黑', 12), anchor=tk.NE, fill=BLACK, + angle=90,tags="maddr") + + + + +class SIGCtrl: + def __init__(self): + self.canvas = canvas + self.round_rectangle(74, 434, 533, 642, r=25, fill=BACK, width=0) + self.round_rectangle(97, 525, 276, 627, r=25, fill=BLACK, width=0) + self.x0, self.y0, self.r = 113, 473, 15 # 时钟大小 + self.bx2, self.by2, self.dx, self.dy = 105, 558, 120, 16 # 设置sig_ctrl文字间隔 + self.ir_value = f"{0:016b}" + self.pc_value = f"{0:016b}" + self.clo_mark() + self.show_tags() + self.pc_reg_value() + self.ir_reg_value() + self.show_singe() + self.insCode() + + def round_rectangle(self, x1, y1, x2, y2, r=25, **kwargs): + """画圆角矩形""" + points = ( + x1 + r, y1, x1 + r, y1, x2 - r, y1, x2 - r, y1, x2, y1, x2, y1 + r, x2, y1 + r, x2, y2 - r, x2, y2 - r, x2, + y2, + x2 - r, y2, x2 - r, y2, x1 + r, y2, x1 + r, y2, x1, y2, x1, y2 - r, x1, y2 - r, x1, y1 + r, x1, y1 + r, x1, + y1) + return self.canvas.create_polygon(points, **kwargs, smooth=True) + + def draw_circle(self, x, y, r, fill=WHITE, tags=None): + """根据圆心坐标和半径画圆""" + # 圆外接矩形 + x1, y1, x2, y2 = x - r, y - r, x + r, y + r + self.canvas.create_oval(x1, y1, x2, y2, width=1, fill=fill, tags=tags) + + def clo_mark(self, time_series: int = None): # 依据时钟周期显示时钟周期 + self.canvas.delete("time") + self.round_rectangle(95, 455, 95 + 213, 455 + 37, fill=WHITE, width=0, tags="time") + + for i in range(6): # 遍历六个时钟刻,绘制各个时钟 + ClockStep[i] = True + x = i * 35 + self.x0 + self.draw_circle(x, self.y0, self.r, fill=WHITE, tags="time") + if i == time_series: + self.draw_circle(x, self.y0, self.r, fill=RED, tags="time") + self.canvas.create_text(x, self.y0, text=f"{i + 1}", font=('微软雅黑', 16, 'bold'), anchor=tk.CENTER, + fill=BLACK, tags='time') + + def show_tags(self): # 显示标签 + self.canvas.create_text(95, 434, text='Clock', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + self.canvas.create_text(342, 434, text='PC', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + self.canvas.create_text(104, 500, text='SigCtrl', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + self.canvas.create_text(342, 540, text='IR', font=('微软雅黑', 12, 'bold'), anchor=tk.NW, fill=WORD) + + def pc_reg_value(self): + self.pc_reg = tk.Entry(self.canvas) # PC 寄存器 + self.pc_reg.config(width=16, font=('微软雅黑', 12)) + self.pc_reg.insert(0, self.pc_value) + self.canvas.create_window(335, 455, window=self.pc_reg, anchor=tk.NW) + + def ir_reg_value(self): + value = self.ir_value + self.canvas.delete("ir_reg") + self.ir_reg = tk.Entry(self.canvas) # IR 寄存器 + self.ir_reg.config(width=17, font=('微软雅黑', 12)) + self.ir_reg.insert(0, value[:6] + " " + value[6:]) + self.canvas.create_window(335, 565, window=self.ir_reg, anchor=tk.NW, tags="ir_reg") + + def insCode(self): + self.ins = tk.Entry(self.canvas) + self.ins.config(width=6, font=('微软雅黑', 12)) + self.ins.insert(0, f"{0:06b}") + self.canvas.create_window(203, 532, window=self.ins, anchor=tk.NW, tags="ins_code") + + def show_singe(self, sings=None): + if sings is None: + sings = [] + self.canvas.delete("sig_ctrl") + self.canvas.create_text(110, 535, text="insCode", + font=('微软雅黑', 12), fill=GOLD, anchor=tk.NW, tags="sig_ctrl") + self.canvas.create_text(self.bx2, self.by2, text='->ALU', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2, self.by2 + self.dy, text='->IR', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2, self.by2 + self.dy * 2, text='->PC + 1', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2, self.by2 + self.dy * 3, text='->MEMORY', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2 + self.dx, self.by2, text='->R1', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy, text='->R2', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy * 2, text='->R3', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy * 3, text='->R4', + font=('微软雅黑', 10), anchor=tk.NW, tags="sig_ctrl", fill=GREY) + + for sing in sings: + if sing == "ALU": + self.canvas.create_text(self.bx2, self.by2, text='->ALU', font=('微软雅黑', 10), anchor=tk.NW, + tags="sig_ctrl", fill=GOLD) + if sing == "IR": + self.canvas.create_text(self.bx2, self.by2 + self.dy, text='->IR', font=('微软雅黑', 10), anchor=tk.NW, + tags="sig_ctrl", fill=GOLD) + if sing == "PC+1": + self.canvas.create_text(self.bx2, self.by2 + self.dy * 2, text='->PC + 1', font=('微软雅黑', 10), + anchor=tk.NW, tags="sig_ctrl", fill=GOLD) + if sing == "MEMORY": + self.canvas.create_text(self.bx2, self.by2 + self.dy * 3, text='->MEMORY', font=('微软雅黑', 10), + anchor=tk.NW, tags="sig_ctrl", fill=GOLD) + if sing == "R1": + self.canvas.create_text(self.bx2 + self.dx, self.by2, text='->R1', font=('微软雅黑', 10), anchor=tk.NW, + tags="sig_ctrl", fill=GOLD) + if sing == "R2": + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy, text='->R2', font=('微软雅黑', 10), + anchor=tk.NW, tags="sig_ctrl", fill=GOLD) + if sing == "R3": + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy * 2, text='->R3', font=('微软雅黑', 10), + anchor=tk.NW, tags="sig_ctrl", fill=GOLD) + if sing == "R4": + self.canvas.create_text(self.bx2 + self.dx, self.by2 + self.dy * 3, text='->R4', font=('微软雅黑', 10), + anchor=tk.NW, tags="sig_ctrl", fill=GOLD) + + +if __name__ == '__main__': + gui = GUISim() + alu = ALU() + memo = MEMO() + # memo.mem_get(12) + sig = SIGCtrl() + root.mainloop() diff --git a/src/hello.py b/src/hello.py new file mode 100644 index 0000000..00950d9 --- /dev/null +++ b/src/hello.py @@ -0,0 +1 @@ +print('hello world') \ No newline at end of file diff --git a/src/program.txt b/src/program.txt new file mode 100644 index 0000000..1f71dcf --- /dev/null +++ b/src/program.txt @@ -0,0 +1,18 @@ +0000010000001010 +0000110000001011 +0001000000001100 +0010000000001101 +0001110000001110 +0000100000001111 +0001010000001111 +0001100000000000 +0000000000000001 +0000000000000000 +0000000000001001 +0000000000001011 +0000000000000101 +0000000000001010 +0000000000001011 +0000000000000000 +0000000000000000 +0000000000000000 \ No newline at end of file diff --git a/src/run.sh b/src/run.sh new file mode 100644 index 0000000..08770b1 --- /dev/null +++ b/src/run.sh @@ -0,0 +1,6 @@ +xrandr --addmode VNC-0 "1920x1200" +xrandr --output VNC-0 --mode "1920x1200" +nohup python3 /home/headless/Desktop/workspace/myshixun/src/execute_instruction.py +echo "执行开始" +echo "过程正确" +echo "执行完成" \ No newline at end of file