OpenCores
URL https://opencores.org/ocsvn/tms1000/tms1000/trunk

Subversion Repositories tms1000

[/] [tms1000/] [trunk/] [sr16/] [tms1000.tcl] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 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 SR-16
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
    update_display .topwindow.disp.display_7 [ run_command examine_display_7 ]
49
    update_display .topwindow.disp.display_8 [ run_command examine_display_8 ]
50
    update_display .topwindow.disp.display_9 [ run_command examine_display_9 ]
51
    update_display .topwindow.disp.display_10 [ run_command examine_display_10 ]
52
    update_display .topwindow.disp.display_11 [ run_command examine_display_11 ]
53
    # update_display .topwindow.disp.display_12 [ run_command examine_display_12 ]
54
    # update_display .topwindow.disp.display_13 [ run_command examine_display_13 ]
55
 
56
}
57
 
58
 
59
proc CreateWindow. {args} {
60
 
61
 
62
  # Window manager configurations
63
  destroy     .topwindow
64
  toplevel    .topwindow -width 700 -height 350
65
 
66
  wm title .topwindow "Calculator Simulator"
67
  wm protocol .topwindow WM_DELETE_WINDOW close_window
68
 
69
#  wm geometry .topwindow 80000+100+100
70
 
71
#  Create_Menubar  .topwindow menubar 
72
 
73
  set height 20
74
  frame .topwindow.disp -width 880 -height 120 -borderwidth 4
75
  pack .topwindow.disp -side top
76
 
77
# create the sevensegment displays
78
  create_display .topwindow.disp.display_1
79
  create_display .topwindow.disp.display_2
80
  create_display .topwindow.disp.display_3
81
  create_display .topwindow.disp.display_4
82
  create_display .topwindow.disp.display_5
83
  create_display .topwindow.disp.display_6
84
  create_display .topwindow.disp.display_7
85
  create_display .topwindow.disp.display_8
86
  create_display .topwindow.disp.display_9
87
  create_display .topwindow.disp.display_10
88
  create_display .topwindow.disp.display_11
89
  # create_display .topwindow.disp.display_12
90
  # create_display .topwindow.disp.display_13
91
 
92
  # place  .topwindow.disp.display_13  -relx 0.0
93
  # place  .topwindow.disp.display_12  -relx 0.07
94
  place  .topwindow.disp.display_11  -relx 0.14
95
  place  .topwindow.disp.display_10  -relx 0.21
96
  place  .topwindow.disp.display_9  -relx 0.28
97
  place  .topwindow.disp.display_8  -relx 0.35
98
  place  .topwindow.disp.display_7  -relx 0.42
99
  place  .topwindow.disp.display_6  -relx 0.49
100
  place  .topwindow.disp.display_5  -relx 0.56
101
  place  .topwindow.disp.display_4  -relx 0.63
102
  place  .topwindow.disp.display_3  -relx 0.70
103
  place  .topwindow.disp.display_2  -relx 0.77
104
  place  .topwindow.disp.display_1  -relx 0.84
105
  set kbd .topwindow.keyboard
106
  frame $kbd -width 450 -height 800 -borderwidth 4
107
  pack $kbd -side top
108
 
109
  # build widget .pb1
110
  button $kbd.pb1   -background {#AEAEB2B2C3C3} -font {Helvetica 10} \
111
    -foreground {#000000000000}     -text {Start}
112
 
113
  button $kbd.exit \
114
    -background {#AEAEB2B2C3C3}    -font {Helvetica 10} \
115
    -foreground {#000000000000}    -text {exit} -command {run_command exit}
116
 
117
 
118
   bind $kbd.pb1    <Button>        { run_command pb1pressed  }
119
   bind $kbd.pb1    <ButtonRelease> { run_command pb1released  }
120
 
121
  button $kbd.num0 -text 0 -font {Helvetica 14}
122
  button $kbd.num1 -text 1 -font {Helvetica 14}
123
  button $kbd.num2 -text 2 -font {Helvetica 14}
124
  button $kbd.num3 -text 3 -font {Helvetica 14}
125
  button $kbd.num4 -text 4 -font {Helvetica 14}
126
  button $kbd.num5 -text 5 -font {Helvetica 14}
127
  button $kbd.num6 -text 6 -font {Helvetica 14}
128
  button $kbd.num7 -text 7 -font {Helvetica 14}
129
  button $kbd.num8 -text 8 -font {Helvetica 14}
130
  button $kbd.num9 -text 9 -font {Helvetica 14}
131
 
132
  button $kbd.add  -text {+}    -font {Helvetica 14}
133
  button $kbd.sub  -text {-}    -font {Helvetica 14}
134
  button $kbd.mul  -text {*}    -font {Helvetica 14}
135
  button $kbd.div  -text {/}    -font {Helvetica 14}
136
  button $kbd.c    -text {C}    -font {Helvetica 14}
137
  button $kbd.ce   -text {CE}   -font {Helvetica 14}
138
  button $kbd.eq   -text {=}    -font {Helvetica 14}
139
 
140
  button $kbd.sum  -text {SUM}    -font {Helvetica 14}
141
  button $kbd.1byx -text {1/x}    -font {Helvetica 14}
142
  button $kbd.x2   -text {x2}    -font {Helvetica 14}
143
  button $kbd.10x  -text {10x}    -font {Helvetica 14}
144
  button $kbd.sqrt -text {sqrt}    -font {Helvetica 14}
145
  button $kbd.log  -text {log}   -font {Helvetica 14}
146
  button $kbd.rcl  -text {RCL}    -font {Helvetica 14}
147
  button $kbd.plmi -text {+/-}    -font {Helvetica 14}
148
  button $kbd.dp   -text {.}    -font {Helvetica 14}
149
  button $kbd.ee   -text {ee}    -font {Helvetica 14}
150
  button $kbd.sto  -text {STO}    -font {Helvetica 14}
151
  button $kbd.yx   -text {yx}    -font {Helvetica 14}
152
  button $kbd.ex   -text {EX}   -font {Helvetica 14}
153
  button $kbd.lnx  -text {lnx}   -font {Helvetica 14}
154
 
155
   grid $kbd.ce $kbd.1byx $kbd.x2 $kbd.sqrt $kbd.c -row 1 -ipadx 20 -ipady 10
156
   grid $kbd.lnx $kbd.ex $kbd.log $kbd.10x $kbd.yx -row 2 -ipadx 20 -ipady 10
157
   grid $kbd.sto $kbd.rcl $kbd.sum $kbd.ee $kbd.div -row 3 -ipadx 20 -ipady 10
158
   grid $kbd.num7 $kbd.num8 $kbd.num9 $kbd.mul -row 4 -ipadx 20 -ipady 10
159
   grid $kbd.num4 $kbd.num5 $kbd.num6 $kbd.sub -row 5 -ipadx 20 -ipady 10
160
   grid $kbd.num1 $kbd.num2 $kbd.num3 $kbd.add -row 6 -ipadx 20 -ipady 10
161
   grid $kbd.num0 $kbd.dp $kbd.plmi $kbd.eq -row 7 -ipadx 20 -ipady 10
162
   grid  $kbd.pb1 $kbd.exit -row 8 -ipadx 20 -ipady 10
163
 
164
  bind $kbd.num0 <Button> { run_command num0pressed  }
165
  bind $kbd.num0 <ButtonRelease> { run_command num0released  }
166
  bind $kbd.num1 <Button> { run_command num1pressed  }
167
  bind $kbd.num1 <ButtonRelease> { run_command num1released  }
168
  bind $kbd.num2 <Button> { run_command num2pressed  }
169
  bind $kbd.num2 <ButtonRelease> { run_command num2released  }
170
  bind $kbd.num3 <Button> { run_command num3pressed  }
171
  bind $kbd.num3 <ButtonRelease> { run_command num3released  }
172
  bind $kbd.num4 <Button> { run_command num4pressed  }
173
  bind $kbd.num4 <ButtonRelease> { run_command num4released  }
174
  bind $kbd.num5 <Button> { run_command num5pressed  }
175
  bind $kbd.num5 <ButtonRelease> { run_command num5released  }
176
  bind $kbd.num6 <Button> { run_command num6pressed  }
177
  bind $kbd.num6 <ButtonRelease> { run_command num6released  }
178
  bind $kbd.num7 <Button> { run_command num7pressed  }
179
  bind $kbd.num7 <ButtonRelease> { run_command num7released  }
180
  bind $kbd.num8 <Button> { run_command num8pressed  }
181
  bind $kbd.num8 <ButtonRelease> { run_command num8released  }
182
  bind $kbd.num9 <Button> { run_command num9pressed  }
183
  bind $kbd.num9 <ButtonRelease> { run_command num9released  }
184
 
185
  bind $kbd.add  <Button> { run_command addpressed  }
186
  bind $kbd.add  <ButtonRelease> { run_command addreleased  }
187
  bind $kbd.sub  <Button> { run_command subpressed  }
188
  bind $kbd.sub  <ButtonRelease> { run_command subreleased  }
189
  bind $kbd.mul  <Button> { run_command mulpressed  }
190
  bind $kbd.mul  <ButtonRelease> { run_command mulreleased  }
191
  bind $kbd.div  <Button> { run_command divpressed  }
192
  bind $kbd.div  <ButtonRelease> { run_command divreleased  }
193
  bind $kbd.c    <Button> { run_command cpressed  }
194
  bind $kbd.c    <ButtonRelease> { run_command creleased  }
195
  bind $kbd.ce   <Button> { run_command cepressed  }
196
  bind $kbd.ce   <ButtonRelease> { run_command cereleased  }
197
  bind $kbd.eq   <Button> { run_command eqpressed  }
198
  bind $kbd.eq   <ButtonRelease> { run_command eqreleased  }
199
 
200
   bind $kbd.sum  <Button> { run_command sumpressed  }
201
   bind $kbd.sum  <ButtonRelease> { run_command sumreleased  }
202
   bind $kbd.1byx <Button> { run_command 1byxpressed  }
203
   bind $kbd.1byx <ButtonRelease> { run_command 1byxreleased  }
204
   bind $kbd.x2   <Button> { run_command x2pressed  }
205
   bind $kbd.x2   <ButtonRelease> { run_command x2released  }
206
   bind $kbd.10x  <Button> { run_command 10xpressed  }
207
   bind $kbd.10x  <ButtonRelease> { run_command 10xreleased  }
208
   bind $kbd.sqrt <Button> { run_command sqrtpressed  }
209
   bind $kbd.sqrt <ButtonRelease> { run_command sqrtreleased  }
210
   bind $kbd.log  <Button> { run_command logpressed  }
211
   bind $kbd.log  <ButtonRelease> { run_command logreleased  }
212
   bind $kbd.rcl  <Button> { run_command rclpressed  }
213
   bind $kbd.rcl  <ButtonRelease> { run_command rclreleased  }
214
   bind $kbd.plmi <Button> { run_command plmipressed  }
215
   bind $kbd.plmi <ButtonRelease> { run_command plmireleased  }
216
   bind $kbd.dp   <Button> { run_command dppressed  }
217
   bind $kbd.dp   <ButtonRelease> { run_command dpreleased  }
218
   bind $kbd.ee   <Button> { run_command eepressed  }
219
   bind $kbd.ee   <ButtonRelease> { run_command eereleased  }
220
   bind $kbd.sto  <Button> { run_command stopressed  }
221
   bind $kbd.sto  <ButtonRelease> { run_command storeleased  }
222
   bind $kbd.yx   <Button> { run_command yxpressed  }
223
   bind $kbd.yx   <ButtonRelease> { run_command yxreleased  }
224
   bind $kbd.ex   <Button> { run_command expressed  }
225
   bind $kbd.ex   <ButtonRelease> { run_command exreleased  }
226
   bind $kbd.lnx  <Button> { run_command lnxpressed  }
227
   bind $kbd.lnx  <ButtonRelease> { run_command lnxreleased  }
228
 
229
# paint_displays
230
}
231
 
232
proc Create_Menubar { toplevel menubar } {
233
 
234
        global tk_version
235
 
236
        if { $tk_version >= 8.0 } {
237
                menu $menubar -type menubar
238
                $toplevel configure -menu $menubar
239
        } else {
240
 
241
                frame $menubar -borderwidth 1 -relief raised
242
                pack $menubar -side top -fill x -expand true
243
        }
244
 
245
 
246
}
247
 
248
proc Create_Menu { menubar basename text mnemonic } {
249
 
250
#       global
251
}
252
 
253
proc close_window {} {
254
  global clock_running
255
  set clock_running 0
256
  after 100 {
257
        quit -sim; noview wave
258
        destroy .topwindow
259
  }
260
}
261
 
262
proc create_display { display_widget } {
263
 
264
# a black canvas with seven different rectangles to form an 8
265
 
266
  canvas $display_widget -bg #000000 -width 80 -height 120
267
   $display_widget create poly 30 20 35 15 65 15 69 19 63 25 35 25 -fill IndianRed -tag  segment0
268
   $display_widget create poly 70 21 74 25 71 55 66 59 61 53 64 26 -fill IndianRed -tag  segment1
269
   $display_widget create poly 66 61 69 64 66 95 62 99 56 94 59 66 -fill IndianRed -tag  segment2
270
   $display_widget create poly 60 101 56 105 25 105 21 101 27 95 54 95 -fill IndianRed -tag segment3
271
   $display_widget create poly 19 99 16 96 19 65 24 61 29 66 26 94 -fill IndianRed -tag  segment4
272
   $display_widget create poly 25 59 21 55 24 25 28 21 34 26 31 54 -fill IndianRed -tag  segment5
273
   $display_widget create poly 27 60 31 65 58 65 64 60 60 55 32 55 -fill IndianRed -tag  segment6
274
   $display_widget create poly 70 95 80 95 78 105 68 105 -fill IndianRed -tag segment7
275
}
276
 
277
proc update_display { display_widget pattern } {
278
  global colours
279
  foreach bit { 0 1 2 3 4 5 6 7} {
280
#      $display_widget itemconfigure segment$bit -fill [lindex $colours [string index $pattern [expr 7 - $bit]]]
281
      $display_widget itemconfigure segment$bit -fill [lindex $colours [string index $pattern $bit]]
282
  }
283
}
284
 
285
proc run_command {command {param 0} } {
286
 
287
global tb clock_running
288
set tb tms1000_tb
289
set sec 1ns
290
 
291
switch $command {
292
 
293
        exit  { close_window }
294
 
295
        pb1pressed {            start_running           }
296
        pb1released {           force /$tb/reset_n      1'b1    }
297
 
298
        pb2pressed {            force /$tb/reset_n 1'b0 }
299
        pb2released {           after 100 force /$tb/reset_n 1'b1 }
300
 
301
        clock0          { force /$tb/clk  1'b0  }
302
        clock1          { force /$tb/clk  1'b1  }
303
 
304
        examine_display_1       { examine -value -radix bin /$tb/d0 }
305
        examine_display_2       { examine -value -radix bin /$tb/d1 }
306
        examine_display_3       { examine -value -radix bin /$tb/d2 }
307
        examine_display_4       { examine -value -radix bin /$tb/d3 }
308
        examine_display_5       { examine -value -radix bin /$tb/d4 }
309
        examine_display_6       { examine -value -radix bin /$tb/d5 }
310
        examine_display_7       { examine -value -radix bin /$tb/d6 }
311
        examine_display_8       { examine -value -radix bin /$tb/d7 }
312
        examine_display_9       { examine -value -radix bin /$tb/d8 }
313
        examine_display_10      { examine -value -radix bin /$tb/d9 }
314
        examine_display_11      { examine -value -radix bin /$tb/d10 }
315
        # examine_display_12    { examine -value -radix bin /$tb/d11 }
316
        # examine_display_13    { examine -value -radix bin /$tb/d12 }
317
 
318
        num0pressed   { force /$tb/key0 1'b1 }
319
        num0released  { force /$tb/key0 1'b0 }
320
        num1pressed   { force /$tb/key1 1'b1 }
321
        num1released  { force /$tb/key1 1'b0 }
322
        num2pressed   { force /$tb/key2 1'b1 }
323
        num2released  { force /$tb/key2 1'b0 }
324
        num3pressed   { force /$tb/key3 1'b1 }
325
        num3released  { force /$tb/key3 1'b0 }
326
        num4pressed   { force /$tb/key4 1'b1 }
327
        num4released  { force /$tb/key4 1'b0 }
328
        num5pressed   { force /$tb/key5 1'b1 }
329
        num5released  { force /$tb/key5 1'b0 }
330
        num6pressed   { force /$tb/key6 1'b1 }
331
        num6released  { force /$tb/key6 1'b0 }
332
        num7pressed   { force /$tb/key7 1'b1 }
333
        num7released  { force /$tb/key7 1'b0 }
334
        num8pressed   { force /$tb/key8 1'b1 }
335
        num8released  { force /$tb/key8 1'b0 }
336
        num9pressed   { force /$tb/key9 1'b1 }
337
        num9released  { force /$tb/key9 1'b0 }
338
 
339
        addpressed   { force /$tb/keyplus 1'b1 }
340
        addreleased  { force /$tb/keyplus 1'b0 }
341
        subpressed   { force /$tb/keyminus 1'b1 }
342
        subreleased  { force /$tb/keyminus 1'b0 }
343
        mulpressed   { force /$tb/keymul 1'b1 }
344
        mulreleased  { force /$tb/keymul 1'b0 }
345
        divpressed   { force /$tb/keydiv 1'b1 }
346
        divreleased  { force /$tb/keydiv 1'b0 }
347
        cpressed     { force /$tb/keyc 1'b1 }
348
        creleased    { force /$tb/keyc 1'b0 }
349
        cepressed    { force /$tb/keyce 1'b1 }
350
        cereleased   { force /$tb/keyce 1'b0 }
351
        eqpressed    { force /$tb/keyeq 1'b1 }
352
        eqreleased   { force /$tb/keyeq 1'b0 }
353
 
354
        sumpressed    { force /$tb/keysum 1'b1 }
355
        sumreleased   { force /$tb/keysum 1'b0 }
356
        1byxpressed   { force /$tb/key1byx 1'b1 }
357
        1byxreleased  { force /$tb/key1byx 1'b0 }
358
        x2pressed     { force /$tb/keyx2 1'b1 }
359
        x2released    { force /$tb/keyx2 1'b0 }
360
        10xpressed    { force /$tb/key10x 1'b1 }
361
        10xreleased   { force /$tb/key10x 1'b0 }
362
        sqrtpressed   { force /$tb/keysqrt 1'b1 }
363
        sqrtreleased  { force /$tb/keysqrt 1'b0 }
364
        logpressed    { force /$tb/keylog 1'b1 }
365
        logreleased   { force /$tb/keylog 1'b0 }
366
        rclpressed    { force /$tb/keyrcl 1'b1 }
367
        rclreleased   { force /$tb/keyrcl 1'b0 }
368
        plmipressed   { force /$tb/keyplmi 1'b1 }
369
        plmireleased  { force /$tb/keyplmi 1'b0 }
370
        dppressed     { force /$tb/keydp 1'b1 }
371
        dpreleased    { force /$tb/keydp 1'b0 }
372
        eepressed     { force /$tb/keyee 1'b1 }
373
        eereleased    { force /$tb/keyee 1'b0 }
374
        stopressed    { force /$tb/keysto 1'b1 }
375
        storeleased   { force /$tb/keysto 1'b0 }
376
        yxpressed     { force /$tb/keyyx 1'b1 }
377
        yxreleased    { force /$tb/keyyx 1'b0 }
378
        expressed     { force /$tb/keyex 1'b1 }
379
        exreleased    { force /$tb/keyex 1'b0 }
380
        lnxpressed    { force /$tb/keylnx 1'b1 }
381
        lnxreleased   { force /$tb/keylnx 1'b0 }
382
 
383
 
384
        run100          { run $sec }
385
        default { puts " This option $command not enabled " }
386
 
387
        }
388
### display_l and pb2_pressed to be made options... 
389
# commands for dip3 to dip8 can also be added in the above switch
390
}
391
 
392
proc initialize {} {
393
    global tb
394
    set tb tms1000_tb
395
 
396
    if { ![file exists work]} {
397
        vlib work
398
    }
399
    #vmap work work
400
    vlog +acc tms1000.v tms1000_tb.v
401
    vsim +acc work.tms1000_tb
402
    CreateWindow.
403
 
404
    view wave
405
    onerror {resume}
406
    quietly WaveActivateNextPane {} 0
407
    add wave -noupdate -format Logic /$tb/clk
408
    add wave -noupdate -format Logic /$tb/reset_n
409
    add wave -noupdate -format Literal -radix hexadecimal /$tb/q
410
    add wave -noupdate -format Literal -radix hexadecimal /$tb/k
411
    add wave -noupdate -format Literal -radix hexadecimal /$tb/r
412
    add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_0
413
    add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_1
414
    add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_2
415
    add wave -noupdate -format Literal -radix hexadecimal /$tb/tms1000/ram/Xreg_3
416
    add wave -noupdate -format Literal -radix hexadecimal /$tb/count
417
    add wave -noupdate -format Logic  /$tb/clk_60
418
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d0
419
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d1
420
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d2
421
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d3
422
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d4
423
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d5
424
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d6
425
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d7
426
    add wave -noupdate -format Literal -radix hexadecimal /$tb/d8
427
 
428
    run -all
429
#    paint_displays
430
}
431
 
432
set clock_running 0
433
set clk_count 0
434
set colours {#330000 #cc0000}
435
 
436
initialize
437
 
438
#uncomment this next line to start the right display with a value; 
439
#update_display .topwindow.display_r 0111101
440
 
441
 
442
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.