-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
209 lines (167 loc) · 8.51 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
"""
Additional features to add: -The ability to view registers in different
formats (eg, decimal, ascii etc)
- Implement more memory view options such as:
* Display different types
* Display a range of values
* Add more "monitors"
"""
from tkinter import *
from unparser import AssemblyFileReader
from CPU import CPU
class simulator_gui:
def __init__(self, master):
self.CPU = CPU()
self.master = master
master.title("ColdFire Simulator")
# master.resizeable(width=False, height=False)
master.geometry('{}x{}'.format(1400, 889)) # width x height
# Text box for code
self.Code_View_lbl = Text(master, width=100, height=60)
self.Code_View_lbl.insert(END, "Test")
self.Code_View_lbl.grid(row=0, column=0, rowspan=20, pady=20, padx=20)
# CCR label
self.CCR_lbl = Label(master, text="CCR", font=("FreeSans", 15))
self.CCR_lbl.config(anchor="e", justify="right")
self.CCR_lbl.grid(row=0, column=1, sticky=E)
self.CCR_value_lbl = Label(master, text="1 0 0 1 0", font=("FreeSans", 15),
relief=SUNKEN)
self.CCR_value_lbl.grid(row=0, column=2, padx=20, sticky=W)
# OP code labels - row 0-3
self.OP_lbl = Label(master, text="OP Code", font=("FreeSans", 15))
self.OP_lbl.grid(row=1, column=1, columnspan=2)
self.OP_value_lbl = Label(master, text="123456789012345", font=("FreeSans", 15),
relief=SUNKEN)
self.OP_value_lbl.grid(row=2, column=1, columnspan=2)
self.extension1_lbl = Label(master, text="Extension 1:", font=("FreeSans", 15))
self.extension1_lbl.grid(row=3, column=1)
self.extension1_value_lbl = Label(master, text="123456789012345",
font=("FreeSans", 15))
self.extension1_value_lbl.grid(row=3, column=2)
self.extension2_lbl = Label(master, text="Extension 2:", font=("FreeSans", 15))
self.extension2_lbl.grid(row=4, column=1)
self.extension2_lbl = Label(master, text="123456789012345", font=("FreeSans", 15))
self.extension2_lbl.grid(row=4, column=2)
# Address Register Labels - rows 5-9, cols 1-2,
# hardcoded constants: spacer = 7th row + offset, columns = 1 or 2
# Also note spacer is based on counter
self.addressReg_lbl = Label(master, text="Address Registers:",
font=("FreeSans", 15))
self.addressReg_lbl.grid(row=5, column=1, columnspan=2)
self.addressRegisters = []
for _ in range(7):
self.addressRegisters.append(Label(master, text="0x12345678901234567890123456789012",
font=("FreeSans", 12), padx=10, relief=SUNKEN))
counter = 0
for label in self.addressRegisters:
if counter < 3:
spacer = 6+counter
label.grid(row=spacer, column=1)
else:
spacer = 3+counter
label.grid(row=spacer, column=2)
counter += 1
self.addressRegisters[6].grid(row=9, column=1)
# self.addressRegisters[0].config(text="test1")
# self.addressRegisters[6].config(text="test2")
# Data Register Labels - rows 10-14, col = 1,2
# hardcoded constants: spacer = 13th row + offset, columns
# Also note spacer is based on counter.
self.dataReg_lbl = Label(master, text="Data Registers:", font=("FreeSans", 12))
self.dataReg_lbl.grid(row=10, column=1, columnspan=2)
self.dataRegisters = []
for _ in range(7):
self.dataRegisters.append(Label(master, text="0x12345678",
font=("FreeSans", 12)))
counter = 0
for label in self.dataRegisters:
if counter < 3:
spacer = 11+counter
label.grid(row=spacer, column=1)
else:
spacer = 8+counter
label.grid(row=spacer, column=2)
counter += 1
self.dataRegisters[6].grid(row=14, column=1)
# Memory Scroll box
self.memory_display_lbl = Label(master, text="Memory: ",
font=("FreeSans", 12))
self.memory_display_lbl.grid(row=15, column=1, columnspan=2)
self.memory_display_list = Listbox(master)
self.memory_display_list.grid(row=16, column=1)
for item in ["one", "two", "three", "four"]:
self.memory_display_list.insert(END, item)
self.memory_display2_list = Listbox(master)
self.memory_display2_list.grid(row=16, column=2)
for item in ["one", "two", "three", "four"]:
self.memory_display2_list.insert(END, item)
# TODO: Implement change memory view button
self.add_memory_btn = Button(master, text="Add")
self.add_memory_btn.grid(row=17, column=1)
self.remove_memory_btn = Button(master, text="Remove")
self.remove_memory_btn.grid(row=17, column=2)
# Next/Prev Line Buttons
# TODO: Add functionality to buttons as well.
self.current_line_number = 1
self.next_btn = Button(master, text="Next Line", command=self.next_line)
self.next_btn.grid(row=18, column=1)
self.reset_btn = Button(master, text="Reset", command=self.reset_line)
self.reset_btn.grid(row=18, column=2)
# Menu bar
# TODO: Add additional functionality to "Load file"
self.menubar = Menu(master)
self.menubar.add_command(label="Load file", command=self.loadfile)
self.menubar.add_command(label="Quit", command=master.quit)
self.master.config(menu=self.menubar)
self.dataRegister_menu = Menu(self.menubar, tearoff=0)
self.dataRegister_menu.add_command(label="View in Bin")
self.dataRegister_menu.add_command(label="View in Hex")
self.dataRegister_menu.add_command(label="View in Dec")
self.menubar.add_cascade(label="Data Register",
menu=self.dataRegister_menu)
self.addressRegister_menu = Menu(self.menubar, tearoff=0)
self.addressRegister_menu.add_command(label="View in Bin")
self.addressRegister_menu.add_command(label="View in Hex")
self.addressRegister_menu.add_command(label="View in Dec")
self.menubar.add_cascade(label="Address Register",
menu=self.dataRegister_menu)
def windowsize(self): # DEBUG Purposes
print("height", self.master.winfo_height())
print("width", self.master.winfo_width())
def reset_line(self):
self.current_line_number = 1
self.Code_View_lbl.tag_remove("current_line", 1.0, "end")
self.Code_View_lbl.tag_add("current_line", 1.0, 2.0)
def next_line(self): # TODO: Constrain next line to max num of lines
self.CPU.execute_line(self.current_line_number)
changes = self.CPU.check_for_change()
if changes: # If there are changes, display and highlight them
self.display_register_changes(changes)
self.current_line_number += 1
highlight_start = str(self.current_line_number) + ".0"
highlight_end = str(self.current_line_number + 1) + ".0"
self.Code_View_lbl.tag_remove("current_line", 1.0, "end")
self.Code_View_lbl.tag_add("current_line", highlight_start,
highlight_end)
def loadfile(self):
"""
Loads in a .s file at that is currently in the same directory as
SimulatorMain.py and displays the text in the Text widget, additionally
it calls an unparser to process the file.
"""
assembler = AssemblyFileReader('test.s')
assembler.read_into_list()
file_data = ''
for e in assembler._file: # Create a large formatted string to be disp
file_data += e
self.Code_View_lbl.delete(1.0, END) # Clear text
self.Code_View_lbl.insert(END, file_data) # Insert the file text
self.Code_View_lbl.tag_configure("current_line", background="#e9e9e9")
self.Code_View_lbl.tag_remove("current_line", 1.0, "end")
self.Code_View_lbl.tag_add("current_line", 1.0, 2.0)
def display_register_changes(self, changes):
for change in changes:
if change[0] == "D":
self.dataRegisters[int(change[1])].config(text=changes[change])
elif change[0] == "A":
self.addressRegisters[int(change[1])].config(text=changes[change])