1 |
2 |
nand_gates |
# This file is part of TMS1000 CPU
|
2 |
|
|
#
|
3 |
|
|
# tms1000.tcl - Run script and GUI frontend of the TMS1000
|
4 |
|
|
# processor based calculator
|
5 |
|
|
#
|
6 |
|
|
# Written By - Nand Gates (2021)
|
7 |
|
|
#
|
8 |
|
|
# This program is free software; you can redistribute it and/or modify it
|
9 |
|
|
# under the terms of the GNU General Public License as published by the
|
10 |
|
|
# Free Software Foundation; either version 2, or (at your option) any
|
11 |
|
|
# later version.
|
12 |
|
|
#
|
13 |
|
|
# This program is distributed in the hope that it will be useful,
|
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
# GNU General Public License for more details.
|
17 |
|
|
#
|
18 |
|
|
# In other words, you are welcome to use, share and improve this program.
|
19 |
|
|
# You are forbidden to forbid anyone else to use, share and improve
|
20 |
|
|
# what you give them. Help stamp out software-hoarding!
|
21 |
|
|
|
22 |
|
|
proc start_running {} {
|
23 |
|
|
global clock_running
|
24 |
|
|
if { $clock_running == 0 } {
|
25 |
|
|
set clock_running 1
|
26 |
|
|
run_clock
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
proc run_clock {} {
|
31 |
|
|
|
32 |
|
|
global clock_running clk_count
|
33 |
|
|
|
34 |
|
|
if { $clock_running == 1 } {
|
35 |
|
|
paint_displays
|
36 |
|
|
after 20 run_clock
|
37 |
|
|
}
|
38 |
|
|
# changed to 50 for demo
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
proc paint_displays {} {
|
42 |
|
|
update_display .topwindow.disp.display_1 [ run_command examine_display_1 ]
|
43 |
|
|
update_display .topwindow.disp.display_2 [ run_command examine_display_2 ]
|
44 |
|
|
update_display .topwindow.disp.display_3 [ run_command examine_display_3 ]
|
45 |
|
|
update_display .topwindow.disp.display_4 [ run_command examine_display_4 ]
|
46 |
|
|
update_display .topwindow.disp.display_5 [ run_command examine_display_5 ]
|
47 |
|
|
update_display .topwindow.disp.display_6 [ run_command examine_display_6 ]
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
proc CreateWindow. {args} {
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
# Window manager configurations
|
55 |
|
|
destroy .topwindow
|
56 |
|
|
toplevel .topwindow -width 700 -height 350
|
57 |
|
|
|
58 |
|
|
wm title .topwindow "Calculator Simulator"
|
59 |
|
|
wm protocol .topwindow WM_DELETE_WINDOW close_window
|
60 |
|
|
|
61 |
|
|
# wm geometry .topwindow 80000+100+100
|
62 |
|
|
|
63 |
|
|
# Create_Menubar .topwindow menubar
|
64 |
|
|
|
65 |
|
|
set height 20
|
66 |
|
|
frame .topwindow.disp -width 640 -height 120 -borderwidth 4
|
67 |
|
|
pack .topwindow.disp -side top
|
68 |
|
|
|
69 |
|
|
# create the sevensegment displays
|
70 |
|
|
create_display .topwindow.disp.display_1
|
71 |
|
|
create_display .topwindow.disp.display_2
|
72 |
|
|
create_display .topwindow.disp.display_3
|
73 |
|
|
create_display .topwindow.disp.display_4
|
74 |
|
|
create_display .topwindow.disp.display_5
|
75 |
|
|
create_display .topwindow.disp.display_6
|
76 |
|
|
|
77 |
|
|
place .topwindow.disp.display_6 -relx 0.1
|
78 |
|
|
place .topwindow.disp.display_5 -relx 0.2
|
79 |
|
|
place .topwindow.disp.display_4 -relx 0.3
|
80 |
|
|
place .topwindow.disp.display_3 -relx 0.4
|
81 |
|
|
place .topwindow.disp.display_2 -relx 0.5
|
82 |
|
|
place .topwindow.disp.display_1 -relx 0.6
|
83 |
|
|
|
84 |
|
|
frame .topwindow.keyboard -width 450 -height 800 -borderwidth 4
|
85 |
|
|
pack .topwindow.keyboard -side top
|
86 |
|
|
|
87 |
|
|
# build widget .pb1
|
88 |
|
|
button .topwindow.keyboard.pb1 -background {#AEAEB2B2C3C3} -font {Helvetica 10} \
|
89 |
|
|
-foreground {#000000000000} -text {Start}
|
90 |
|
|
|
91 |
|
|
button .topwindow.keyboard.exit \
|
92 |
|
|
-background {#AEAEB2B2C3C3} -font {Helvetica 10} \
|
93 |
|
|
-foreground {#000000000000} -text {exit} -command {run_command exit}
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
bind .topwindow.keyboard.pb1 <Button> { run_command pb1pressed }
|
97 |
|
|
bind .topwindow.keyboard.pb1 <ButtonRelease> { run_command pb1released }
|
98 |
|
|
|
99 |
|
|
button .topwindow.keyboard.num0 -text 0 -font {Helvetica 14}
|
100 |
|
|
button .topwindow.keyboard.num1 -text 1 -font {Helvetica 14}
|
101 |
|
|
button .topwindow.keyboard.num2 -text 2 -font {Helvetica 14}
|
102 |
|
|
button .topwindow.keyboard.num3 -text 3 -font {Helvetica 14}
|
103 |
|
|
button .topwindow.keyboard.num4 -text 4 -font {Helvetica 14}
|
104 |
|
|
button .topwindow.keyboard.num5 -text 5 -font {Helvetica 14}
|
105 |
|
|
button .topwindow.keyboard.num6 -text 6 -font {Helvetica 14}
|
106 |
|
|
button .topwindow.keyboard.num7 -text 7 -font {Helvetica 14}
|
107 |
|
|
button .topwindow.keyboard.num8 -text 8 -font {Helvetica 14}
|
108 |
|
|
button .topwindow.keyboard.num9 -text 9 -font {Helvetica 14}
|
109 |
|
|
|
110 |
|
|
button .topwindow.keyboard.add -text {+} -font {Helvetica 14}
|
111 |
|
|
button .topwindow.keyboard.sub -text {-} -font {Helvetica 14}
|
112 |
|
|
button .topwindow.keyboard.mul -text {*} -font {Helvetica 14}
|
113 |
|
|
button .topwindow.keyboard.div -text {/} -font {Helvetica 14}
|
114 |
|
|
button .topwindow.keyboard.clr -text {C} -font {Helvetica 14}
|
115 |
|
|
button .topwindow.keyboard.clk -text {CLK} -font {Helvetica 14}
|
116 |
|
|
button .topwindow.keyboard.ent -text {ENT} -font {Helvetica 14}
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
grid .topwindow.keyboard.num0 .topwindow.keyboard.num1 .topwindow.keyboard.num2 .topwindow.keyboard.add -row 1 -ipadx 20 -ipady 10
|
120 |
|
|
grid .topwindow.keyboard.num3 .topwindow.keyboard.num4 .topwindow.keyboard.num5 .topwindow.keyboard.sub -row 2 -ipadx 20 -ipady 10
|
121 |
|
|
grid .topwindow.keyboard.num6 .topwindow.keyboard.num7 .topwindow.keyboard.num8 .topwindow.keyboard.mul -row 3 -ipadx 20 -ipady 10
|
122 |
|
|
grid .topwindow.keyboard.num9 .topwindow.keyboard.clr .topwindow.keyboard.ent .topwindow.keyboard.div -row 4 -ipadx 20 -ipady 10
|
123 |
|
|
|
124 |
|
|
grid .topwindow.keyboard.clk .topwindow.keyboard.pb1 .topwindow.keyboard.exit -row 5 -ipadx 20 -ipady 10
|
125 |
|
|
|
126 |
|
|
bind .topwindow.keyboard.num0 <Button> { run_command num0pressed }
|
127 |
|
|
bind .topwindow.keyboard.num0 <ButtonRelease> { run_command num0released }
|
128 |
|
|
bind .topwindow.keyboard.num1 <Button> { run_command num1pressed }
|
129 |
|
|
bind .topwindow.keyboard.num1 <ButtonRelease> { run_command num1released }
|
130 |
|
|
bind .topwindow.keyboard.num2 <Button> { run_command num2pressed }
|
131 |
|
|
bind .topwindow.keyboard.num2 <ButtonRelease> { run_command num2released }
|
132 |
|
|
bind .topwindow.keyboard.num3 <Button> { run_command num3pressed }
|
133 |
|
|
bind .topwindow.keyboard.num3 <ButtonRelease> { run_command num3released }
|
134 |
|
|
bind .topwindow.keyboard.num4 <Button> { run_command num4pressed }
|
135 |
|
|
bind .topwindow.keyboard.num4 <ButtonRelease> { run_command num4released }
|
136 |
|
|
bind .topwindow.keyboard.num5 <Button> { run_command num5pressed }
|
137 |
|
|
bind .topwindow.keyboard.num5 <ButtonRelease> { run_command num5released }
|
138 |
|
|
bind .topwindow.keyboard.num6 <Button> { run_command num6pressed }
|
139 |
|
|
bind .topwindow.keyboard.num6 <ButtonRelease> { run_command num6released }
|
140 |
|
|
bind .topwindow.keyboard.num7 <Button> { run_command num7pressed }
|
141 |
|
|
bind .topwindow.keyboard.num7 <ButtonRelease> { run_command num7released }
|
142 |
|
|
bind .topwindow.keyboard.num8 <Button> { run_command num8pressed }
|
143 |
|
|
bind .topwindow.keyboard.num8 <ButtonRelease> { run_command num8released }
|
144 |
|
|
bind .topwindow.keyboard.num9 <Button> { run_command num9pressed }
|
145 |
|
|
bind .topwindow.keyboard.num9 <ButtonRelease> { run_command num9released }
|
146 |
|
|
|
147 |
|
|
bind .topwindow.keyboard.add <Button> { run_command addpressed }
|
148 |
|
|
bind .topwindow.keyboard.add <ButtonRelease> { run_command addreleased }
|
149 |
|
|
bind .topwindow.keyboard.sub <Button> { run_command subpressed }
|
150 |
|
|
bind .topwindow.keyboard.sub <ButtonRelease> { run_command subreleased }
|
151 |
|
|
bind .topwindow.keyboard.mul <Button> { run_command mulpressed }
|
152 |
|
|
bind .topwindow.keyboard.mul <ButtonRelease> { run_command mulreleased }
|
153 |
|
|
bind .topwindow.keyboard.div <Button> { run_command divpressed }
|
154 |
|
|
bind .topwindow.keyboard.div <ButtonRelease> { run_command divreleased }
|
155 |
|
|
bind .topwindow.keyboard.clr <Button> { run_command clrpressed }
|
156 |
|
|
bind .topwindow.keyboard.clr <ButtonRelease> { run_command clrreleased }
|
157 |
|
|
bind .topwindow.keyboard.clk <Button> { run_command clkpressed }
|
158 |
|
|
bind .topwindow.keyboard.clk <ButtonRelease> { run_command clkreleased }
|
159 |
|
|
bind .topwindow.keyboard.ent <Button> { run_command entpressed }
|
160 |
|
|
bind .topwindow.keyboard.ent <ButtonRelease> { run_command entreleased }
|
161 |
|
|
# paint_displays
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
proc Create_Menubar { toplevel menubar } {
|
165 |
|
|
|
166 |
|
|
global tk_version
|
167 |
|
|
|
168 |
|
|
if { $tk_version >= 8.0 } {
|
169 |
|
|
menu $menubar -type menubar
|
170 |
|
|
$toplevel configure -menu $menubar
|
171 |
|
|
} else {
|
172 |
|
|
|
173 |
|
|
frame $menubar -borderwidth 1 -relief raised
|
174 |
|
|
pack $menubar -side top -fill x -expand true
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
proc Create_Menu { menubar basename text mnemonic } {
|
180 |
|
|
# global
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
proc close_window {} {
|
184 |
|
|
global clock_running
|
185 |
|
|
set clock_running 0
|
186 |
|
|
after 100 {
|
187 |
|
|
quit -sim; noview wave
|
188 |
|
|
destroy .topwindow
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
proc create_display { display_widget } {
|
193 |
|
|
# a black canvas with seven different rectangles to form an 8
|
194 |
|
|
canvas $display_widget -bg #000000 -width 80 -height 120
|
195 |
|
|
$display_widget create poly 30 20 35 15 65 15 69 19 63 25 35 25 -fill IndianRed -tag segment0
|
196 |
|
|
$display_widget create poly 70 21 74 25 71 55 66 59 61 53 64 26 -fill IndianRed -tag segment1
|
197 |
|
|
$display_widget create poly 66 61 69 64 66 95 62 99 56 94 59 66 -fill IndianRed -tag segment2
|
198 |
|
|
$display_widget create poly 60 101 56 105 25 105 21 101 27 95 54 95 -fill IndianRed -tag segment3
|
199 |
|
|
$display_widget create poly 19 99 16 96 19 65 24 61 29 66 26 94 -fill IndianRed -tag segment4
|
200 |
|
|
$display_widget create poly 25 59 21 55 24 25 28 21 34 26 31 54 -fill IndianRed -tag segment5
|
201 |
|
|
$display_widget create poly 27 60 31 65 58 65 64 60 60 55 32 55 -fill IndianRed -tag segment6
|
202 |
|
|
$display_widget create poly 70 95 80 95 78 105 68 105 -fill IndianRed -tag segment7
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
proc update_display { display_widget pattern } {
|
206 |
|
|
global colours
|
207 |
|
|
foreach bit { 0 1 2 3 4 5 6 7} {
|
208 |
|
|
$display_widget itemconfigure segment$bit -fill [lindex $colours [string index $pattern $bit]]
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
proc run_command {command {param 0} } {
|
213 |
|
|
|
214 |
|
|
global tb clock_running
|
215 |
|
|
set tb tms1000_tb
|
216 |
|
|
set sec 1ns
|
217 |
|
|
|
218 |
|
|
switch $command {
|
219 |
|
|
|
220 |
|
|
exit { close_window }
|
221 |
|
|
|
222 |
|
|
pb1pressed { start_running }
|
223 |
|
|
pb1released { force /$tb/reset_n 1'b1 }
|
224 |
|
|
|
225 |
|
|
pb2pressed { force /$tb/reset_n 1'b0 }
|
226 |
|
|
pb2released { after 100 force /$tb/reset_n 1'b1 }
|
227 |
|
|
|
228 |
|
|
clock0 { force /$tb/clk 1'b0 }
|
229 |
|
|
clock1 { force /$tb/clk 1'b1 }
|
230 |
|
|
|
231 |
|
|
examine_display_1 { examine -value -radix bin /$tb/d0 }
|
232 |
|
|
examine_display_2 { examine -value -radix bin /$tb/d1 }
|
233 |
|
|
examine_display_3 { examine -value -radix bin /$tb/d2 }
|
234 |
|
|
examine_display_4 { examine -value -radix bin /$tb/d3 }
|
235 |
|
|
examine_display_5 { examine -value -radix bin /$tb/d4 }
|
236 |
|
|
examine_display_6 { examine -value -radix bin /$tb/d5 }
|
237 |
|
|
|
238 |
|
|
num0pressed { force /$tb/key0 1'b1 }
|
239 |
|
|
num0released { force /$tb/key0 1'b0 }
|
240 |
|
|
num1pressed { force /$tb/key1 1'b1 }
|
241 |
|
|
num1released { force /$tb/key1 1'b0 }
|
242 |
|
|
num2pressed { force /$tb/key2 1'b1 }
|
243 |
|
|
num2released { force /$tb/key2 1'b0 }
|
244 |
|
|
num3pressed { force /$tb/key3 1'b1 }
|
245 |
|
|
num3released { force /$tb/key3 1'b0 }
|
246 |
|
|
num4pressed { force /$tb/key4 1'b1 }
|
247 |
|
|
num4released { force /$tb/key4 1'b0 }
|
248 |
|
|
num5pressed { force /$tb/key5 1'b1 }
|
249 |
|
|
num5released { force /$tb/key5 1'b0 }
|
250 |
|
|
num6pressed { force /$tb/key6 1'b1 }
|
251 |
|
|
num6released { force /$tb/key6 1'b0 }
|
252 |
|
|
num7pressed { force /$tb/key7 1'b1 }
|
253 |
|
|
num7released { force /$tb/key7 1'b0 }
|
254 |
|
|
num8pressed { force /$tb/key8 1'b1 }
|
255 |
|
|
num8released { force /$tb/key8 1'b0 }
|
256 |
|
|
num9pressed { force /$tb/key9 1'b1 }
|
257 |
|
|
num9released { force /$tb/key9 1'b0 }
|
258 |
|
|
|
259 |
|
|
addpressed { force /$tb/keyplus 1'b1 }
|
260 |
|
|
addreleased { force /$tb/keyplus 1'b0 }
|
261 |
|
|
subpressed { force /$tb/keyminus 1'b1 }
|
262 |
|
|
subreleased { force /$tb/keyminus 1'b0 }
|
263 |
|
|
mulpressed { force /$tb/keymul 1'b1 }
|
264 |
|
|
mulreleased { force /$tb/keymul 1'b0 }
|
265 |
|
|
divpressed { force /$tb/keydiv 1'b1 }
|
266 |
|
|
divreleased { force /$tb/keydiv 1'b0 }
|
267 |
|
|
clrpressed { force /$tb/keyc 1'b1 }
|
268 |
|
|
clrreleased { force /$tb/keyc 1'b0 }
|
269 |
|
|
clkpressed { force /$tb/keyclk 1'b1 }
|
270 |
|
|
clkreleased { force /$tb/keyclk 1'b0 }
|
271 |
|
|
entpressed { force /$tb/keyent 1'b1 }
|
272 |
|
|
entreleased { force /$tb/keyent 1'b0 }
|
273 |
|
|
|
274 |
|
|
run100 { run $sec }
|
275 |
|
|
default { puts " This option $command not enabled " }
|
276 |
|
|
|
277 |
|
|
}
|
278 |
|
|
### display_l and pb2_pressed to be made options...
|
279 |
|
|
# commands for dip3 to dip8 can also be added in the above switch
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
proc initialize {} {
|
283 |
|
|
global tb
|
284 |
|
|
set tb tms1000_tb
|
285 |
|
|
if { [file exists work]== 0} {
|
286 |
|
|
vlib work
|
287 |
|
|
}
|
288 |
|
|
#vmap work work
|
289 |
|
|
vlog +acc tms1000.v tms1000_tb.v
|
290 |
|
|
vsim +acc work.tms1000_tb
|
291 |
|
|
CreateWindow.
|
292 |
|
|
|
293 |
|
|
view wave
|
294 |
|
|
onerror {resume}
|
295 |
|
|
quietly WaveActivateNextPane {} 0
|
296 |
|
|
add wave -noupdate -format Logic /$tb/clk
|
297 |
|
|
add wave -noupdate -format Logic /$tb/reset_n
|
298 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/q
|
299 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/k
|
300 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/r
|
301 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_0
|
302 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_1
|
303 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_2
|
304 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_3
|
305 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/count
|
306 |
|
|
add wave -noupdate -format Logic /$tb/clk_60
|
307 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d0
|
308 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d1
|
309 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d2
|
310 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d3
|
311 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d4
|
312 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d5
|
313 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d6
|
314 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d7
|
315 |
|
|
add wave -noupdate -format Literal -radix hexadecimal /$tb/d8
|
316 |
|
|
|
317 |
|
|
run -all
|
318 |
|
|
# paint_displays
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
set clock_running 0
|
322 |
|
|
set clk_count 0
|
323 |
|
|
set colours {#330000 #cc0000}
|
324 |
|
|
|
325 |
|
|
initialize
|
326 |
|
|
|
327 |
|
|
#uncomment this next line to start the right display with a value;
|
328 |
|
|
#update_display .topwindow.display_r 0111101
|