You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
5.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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('<Button-1>', left1)
root.mainloop()