USB Device Programming class project. This project allows a Python/Tk program running on a PC host to monitor/control a test-CPU programmed into an altera development board.
Dependencies: C12832_lcd USBDevice mbed-rtos mbed mmSPI
mmPython/mmUI.txt@8:db29cce17a33, 2013-09-01 (annotated)
- Committer:
- gatedClock
- Date:
- Sun Sep 01 03:55:03 2013 +0000
- Revision:
- 8:db29cce17a33
- Parent:
- 4:92539904a4ad
improve tab formatting of code under mmPython.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gatedClock | 8:db29cce17a33 | 1 | #!/usr/bin/python -tt # tt: detect mixed space/tab. |
gatedClock | 4:92539904a4ad | 2 | #---copyright-----------------------------------#------------------------------- |
gatedClock | 4:92539904a4ad | 3 | # licensed for personal and academic use. |
gatedClock | 4:92539904a4ad | 4 | # commercial use must be approved by the account-holder of |
gatedClock | 4:92539904a4ad | 5 | # gated.clock@gmail.com |
gatedClock | 4:92539904a4ad | 6 | #-------imports---------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 7 | from Tkinter import * # Tk graphics. |
gatedClock | 8:db29cce17a33 | 8 | import mmUSBserial # USB Serial object. |
gatedClock | 4:92539904a4ad | 9 | from mmUSBserial import * |
gatedClock | 8:db29cce17a33 | 10 | import time # Time object. |
gatedClock | 4:92539904a4ad | 11 | from time import time, sleep |
gatedClock | 8:db29cce17a33 | 12 | import threading # Threading object. |
gatedClock | 8:db29cce17a33 | 13 | import tkFileDialog # File-select dialog object.' |
gatedClock | 8:db29cce17a33 | 14 | import os # import os library. |
gatedClock | 4:92539904a4ad | 15 | #=======class===================================#=============================== |
gatedClock | 4:92539904a4ad | 16 | #-----------------------------------------------#------------------------------- |
gatedClock | 4:92539904a4ad | 17 | ''' |
gatedClock | 8:db29cce17a33 | 18 | licensed for personal and accedemic use. |
gatedClock | 8:db29cce17a33 | 19 | commercial use must be approved by the account-holder of |
gatedClock | 8:db29cce17a33 | 20 | gated.clock@gmail.com |
gatedClock | 4:92539904a4ad | 21 | ''' |
gatedClock | 4:92539904a4ad | 22 | #-----------------------------------------------#------------------------------- |
gatedClock | 4:92539904a4ad | 23 | ''' |
gatedClock | 8:db29cce17a33 | 24 | description: |
gatedClock | 4:92539904a4ad | 25 | |
gatedClock | 8:db29cce17a33 | 26 | python/Tk code for interfacing with the mbed.org system. |
gatedClock | 8:db29cce17a33 | 27 | this code provides a UI which is used to communicate over USB |
gatedClock | 8:db29cce17a33 | 28 | to the mbed.org processor, and in turn the toy CPU programmed |
gatedClock | 8:db29cce17a33 | 29 | into the altera device. |
gatedClock | 4:92539904a4ad | 30 | |
gatedClock | 8:db29cce17a33 | 31 | this code provides a UI which is used to monitor and write-to the |
gatedClock | 8:db29cce17a33 | 32 | toy CPU's registers and its main memory. |
gatedClock | 4:92539904a4ad | 33 | |
gatedClock | 8:db29cce17a33 | 34 | I/O capability: |
gatedClock | 4:92539904a4ad | 35 | |
gatedClock | 8:db29cce17a33 | 36 | * R0 write/read. |
gatedClock | 8:db29cce17a33 | 37 | * R1 write/read. |
gatedClock | 8:db29cce17a33 | 38 | * R2 write/read. |
gatedClock | 8:db29cce17a33 | 39 | * R3 write/read. |
gatedClock | 8:db29cce17a33 | 40 | * PC write/read. (that's 'Program Counter'.) |
gatedClock | 8:db29cce17a33 | 41 | * IR write/read. (that's 'Instruction Register'.) |
gatedClock | 8:db29cce17a33 | 42 | * MM address. (that's 'Main Memory.') |
gatedClock | 8:db29cce17a33 | 43 | * MM content. |
gatedClock | 4:92539904a4ad | 44 | |
gatedClock | 8:db29cce17a33 | 45 | Button Controls: |
gatedClock | 4:92539904a4ad | 46 | |
gatedClock | 8:db29cce17a33 | 47 | * USB Connect/Disconnect. |
gatedClock | 8:db29cce17a33 | 48 | * Register Read. |
gatedClock | 8:db29cce17a33 | 49 | * Register Write. |
gatedClock | 8:db29cce17a33 | 50 | * Main Memory Read. |
gatedClock | 8:db29cce17a33 | 51 | * Main Memory Write. |
gatedClock | 8:db29cce17a33 | 52 | * Main Memory Load-From-File. |
gatedClock | 8:db29cce17a33 | 53 | * Main Memory Dump-To-File. |
gatedClock | 8:db29cce17a33 | 54 | * Step CPU. |
gatedClock | 8:db29cce17a33 | 55 | * Run-Fast, Run-Slow, Stop CPU. |
gatedClock | 8:db29cce17a33 | 56 | * Run Test. |
gatedClock | 8:db29cce17a33 | 57 | * Exit. |
gatedClock | 4:92539904a4ad | 58 | |
gatedClock | 4:92539904a4ad | 59 | ''' |
gatedClock | 4:92539904a4ad | 60 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 61 | if (1): # allow further indentation. |
gatedClock | 8:db29cce17a33 | 62 | class mmUI: # UI class. |
gatedClock | 4:92539904a4ad | 63 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 64 | def __init__(self,masterWidget): # constructor. |
gatedClock | 4:92539904a4ad | 65 | |
gatedClock | 8:db29cce17a33 | 66 | self.__masterWidget = masterWidget # promote to object scope. |
gatedClock | 4:92539904a4ad | 67 | |
gatedClock | 8:db29cce17a33 | 68 | # master widget title. |
gatedClock | 8:db29cce17a33 | 69 | self.__masterWidget.wm_title("CPU Control") |
gatedClock | 4:92539904a4ad | 70 | |
gatedClock | 8:db29cce17a33 | 71 | self.__frame = Frame(masterWidget) # create frame widget. |
gatedClock | 8:db29cce17a33 | 72 | self.__frame.grid(column=0, row=0) # use grid packer. |
gatedClock | 4:92539904a4ad | 73 | |
gatedClock | 8:db29cce17a33 | 74 | self.__connected = 0 # not yet __connected to USB. |
gatedClock | 8:db29cce17a33 | 75 | self.__isRunning = 0 # program execution not running. |
gatedClock | 8:db29cce17a33 | 76 | self.__testRunning = 0 # test mode not runing. |
gatedClock | 8:db29cce17a33 | 77 | self.__testIter = 0 # test mode iteration count. |
gatedClock | 8:db29cce17a33 | 78 | self.__sleepVal = 0.04 # serial transceive sleep. |
gatedClock | 4:92539904a4ad | 79 | |
gatedClock | 8:db29cce17a33 | 80 | |
gatedClock | 8:db29cce17a33 | 81 | self.uiR0 (0, 1, 10) # label/entry widgets (x, y, width) |
gatedClock | 8:db29cce17a33 | 82 | self.uiR1 (0, 2, 10) |
gatedClock | 8:db29cce17a33 | 83 | self.uiR2 (0, 3, 10) |
gatedClock | 8:db29cce17a33 | 84 | self.uiR3 (0, 4, 10) |
gatedClock | 8:db29cce17a33 | 85 | self.uiPC (0, 5, 10) |
gatedClock | 8:db29cce17a33 | 86 | self.uiIR (0, 6, 10) |
gatedClock | 8:db29cce17a33 | 87 | self.uimmADR (0, 7, 10) |
gatedClock | 8:db29cce17a33 | 88 | self.uimmVAL (0, 8, 10) |
gatedClock | 4:92539904a4ad | 89 | |
gatedClock | 8:db29cce17a33 | 90 | self.uiConnect (3, 1, 8) # button widgets (x, y, width) |
gatedClock | 8:db29cce17a33 | 91 | self.uiRegRead (3, 2, 8) |
gatedClock | 8:db29cce17a33 | 92 | self.uiRegWrite(3, 3, 8) |
gatedClock | 8:db29cce17a33 | 93 | self.uimmRead (3, 4, 8) |
gatedClock | 8:db29cce17a33 | 94 | self.uimmWrite (3, 5, 8) |
gatedClock | 8:db29cce17a33 | 95 | self.uiProg (3, 6, 8) |
gatedClock | 8:db29cce17a33 | 96 | self.uimmDump (3, 7, 8) |
gatedClock | 8:db29cce17a33 | 97 | self.uiStep (3, 8, 8) |
gatedClock | 8:db29cce17a33 | 98 | self.uiRun (3, 9, 8) |
gatedClock | 8:db29cce17a33 | 99 | self.uiTest (3, 10, 8) |
gatedClock | 8:db29cce17a33 | 100 | self.uiExit (3, 11, 8) |
gatedClock | 4:92539904a4ad | 101 | |
gatedClock | 8:db29cce17a33 | 102 | self.refreshUI() # initial content display. |
gatedClock | 4:92539904a4ad | 103 | |
gatedClock | 4:92539904a4ad | 104 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 105 | def __del__(self): # destructor. |
gatedClock | 8:db29cce17a33 | 106 | print "object destroyed." |
gatedClock | 4:92539904a4ad | 107 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 108 | # WIDGETS: BEGIN LABEL/ENTRY PAIRS. #=============================== |
gatedClock | 4:92539904a4ad | 109 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 110 | def uiR0(self,dColumn,dRow,dWidth): # R0. |
gatedClock | 4:92539904a4ad | 111 | |
gatedClock | 8:db29cce17a33 | 112 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 113 | |
gatedClock | 8:db29cce17a33 | 114 | self.__R0Label = Label(self.__frame, text="R0") |
gatedClock | 8:db29cce17a33 | 115 | self.__R0Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 116 | |
gatedClock | 8:db29cce17a33 | 117 | self.__R0Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 8:db29cce17a33 | 118 | self.__R0Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 119 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 120 | def uiR1(self,dColumn,dRow,dWidth): # R1. |
gatedClock | 4:92539904a4ad | 121 | |
gatedClock | 8:db29cce17a33 | 122 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 123 | |
gatedClock | 8:db29cce17a33 | 124 | self.__R1Label = Label(self.__frame, text="R1") |
gatedClock | 8:db29cce17a33 | 125 | self.__R1Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 126 | |
gatedClock | 8:db29cce17a33 | 127 | self.__R1Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 8:db29cce17a33 | 128 | self.__R1Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 129 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 130 | def uiR2(self,dColumn,dRow,dWidth): # R2. |
gatedClock | 4:92539904a4ad | 131 | |
gatedClock | 8:db29cce17a33 | 132 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 133 | |
gatedClock | 8:db29cce17a33 | 134 | self.__R2Label = Label(self.__frame, text="R2") |
gatedClock | 8:db29cce17a33 | 135 | self.__R2Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 136 | |
gatedClock | 8:db29cce17a33 | 137 | self.__R2Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 8:db29cce17a33 | 138 | self.__R2Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 139 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 140 | def uiR3(self,dColumn,dRow,dWidth): # R3. |
gatedClock | 4:92539904a4ad | 141 | |
gatedClock | 8:db29cce17a33 | 142 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 143 | |
gatedClock | 8:db29cce17a33 | 144 | self.__R3Label = Label(self.__frame, text="R3") |
gatedClock | 8:db29cce17a33 | 145 | self.__R3Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 146 | |
gatedClock | 8:db29cce17a33 | 147 | self.__R3Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 8:db29cce17a33 | 148 | self.__R3Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 149 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 150 | def uiPC(self,dColumn,dRow,dWidth): # program counter. |
gatedClock | 4:92539904a4ad | 151 | |
gatedClock | 8:db29cce17a33 | 152 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 153 | |
gatedClock | 8:db29cce17a33 | 154 | self.__PCLabel = Label(self.__frame, text="PC") |
gatedClock | 8:db29cce17a33 | 155 | self.__PCLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 156 | |
gatedClock | 8:db29cce17a33 | 157 | self.__PCEntry = Entry(self.__frame, width=dWidth, background="ORANGE") |
gatedClock | 8:db29cce17a33 | 158 | self.__PCEntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 159 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 160 | def uiIR(self,dColumn,dRow,dWidth): # instruction register. |
gatedClock | 4:92539904a4ad | 161 | |
gatedClock | 8:db29cce17a33 | 162 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 163 | |
gatedClock | 8:db29cce17a33 | 164 | self.__IRLabel = Label(self.__frame, text="IR") |
gatedClock | 8:db29cce17a33 | 165 | self.__IRLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 166 | |
gatedClock | 8:db29cce17a33 | 167 | self.__IREntry = Entry(self.__frame, width=dWidth, background="ORANGE") |
gatedClock | 8:db29cce17a33 | 168 | self.__IREntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 169 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 170 | def uimmADR(self,dColumn,dRow,dWidth):# mmADR. |
gatedClock | 4:92539904a4ad | 171 | |
gatedClock | 8:db29cce17a33 | 172 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 173 | |
gatedClock | 8:db29cce17a33 | 174 | self.__mmADRLabel = Label(self.__frame, text="mmADR") |
gatedClock | 8:db29cce17a33 | 175 | self.__mmADRLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 176 | |
gatedClock | 8:db29cce17a33 | 177 | self.__mmADREntry = Entry(self.__frame, width=dWidth, |
gatedClock | 4:92539904a4ad | 178 | background="MAROON", foreground="WHITE") |
gatedClock | 8:db29cce17a33 | 179 | self.__mmADREntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 8:db29cce17a33 | 180 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 181 | def uimmVAL(self,dColumn,dRow,dWidth):# mmVAL. |
gatedClock | 4:92539904a4ad | 182 | |
gatedClock | 8:db29cce17a33 | 183 | dColumnPlusOne = dColumn + 1 |
gatedClock | 4:92539904a4ad | 184 | |
gatedClock | 8:db29cce17a33 | 185 | self.__mmVALLabel = Label(self.__frame, text="mmVAL") |
gatedClock | 8:db29cce17a33 | 186 | self.__mmVALLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 187 | |
gatedClock | 8:db29cce17a33 | 188 | self.__mmVALEntry = Entry(self.__frame, width=dWidth, |
gatedClock | 4:92539904a4ad | 189 | background="MAROON", foreground="WHITE") |
gatedClock | 8:db29cce17a33 | 190 | self.__mmVALEntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 191 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 192 | # WIDGETS: BEGIN BUTTONS. #=============================== |
gatedClock | 4:92539904a4ad | 193 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 194 | # generate the 'connect' button. |
gatedClock | 8:db29cce17a33 | 195 | def uiConnect(self,dColumn,dRow,dWidth): |
gatedClock | 4:92539904a4ad | 196 | |
gatedClock | 8:db29cce17a33 | 197 | self.__connectButton = Button(self.__frame, text="CONNECT", |
gatedClock | 4:92539904a4ad | 198 | command=self.selectConnectButtonPressed, |
gatedClock | 4:92539904a4ad | 199 | background="RED", |
gatedClock | 4:92539904a4ad | 200 | width = dWidth) |
gatedClock | 4:92539904a4ad | 201 | |
gatedClock | 8:db29cce17a33 | 202 | self.__connectButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 203 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 204 | # generate the register-read button. |
gatedClock | 8:db29cce17a33 | 205 | def uiRegRead(self,dColumn,dRow,dWidth): |
gatedClock | 8:db29cce17a33 | 206 | self.__RegReadButton = Button(self.__frame, text="REG READ", |
gatedClock | 4:92539904a4ad | 207 | command=self.selectRegReadButtonPressed, |
gatedClock | 4:92539904a4ad | 208 | width = dWidth) |
gatedClock | 4:92539904a4ad | 209 | |
gatedClock | 8:db29cce17a33 | 210 | self.__RegReadButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 211 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 212 | # generate the 'reg write' button. |
gatedClock | 8:db29cce17a33 | 213 | def uiRegWrite(self,dColumn,dRow,dWidth): |
gatedClock | 8:db29cce17a33 | 214 | self.__RegWriteButton = Button(self.__frame, text="REG WRITE", |
gatedClock | 4:92539904a4ad | 215 | command=self.selectRegWriteButtonPressed, |
gatedClock | 4:92539904a4ad | 216 | width = dWidth) |
gatedClock | 4:92539904a4ad | 217 | |
gatedClock | 8:db29cce17a33 | 218 | self.__RegWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 219 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 220 | # generate the mm-read button. |
gatedClock | 8:db29cce17a33 | 221 | def uimmRead(self,dColumn,dRow,dWidth): |
gatedClock | 8:db29cce17a33 | 222 | self.__mmReadButton = Button(self.__frame, text="MM READ", |
gatedClock | 4:92539904a4ad | 223 | command=self.selectmmReadButtonPressed, |
gatedClock | 4:92539904a4ad | 224 | width = dWidth) |
gatedClock | 4:92539904a4ad | 225 | |
gatedClock | 8:db29cce17a33 | 226 | self.__mmReadButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 227 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 228 | # generate the 'mm write' button. |
gatedClock | 8:db29cce17a33 | 229 | def uimmWrite(self,dColumn,dRow,dWidth): |
gatedClock | 8:db29cce17a33 | 230 | self.__mmWriteButton = Button(self.__frame, text="MM WRITE", |
gatedClock | 4:92539904a4ad | 231 | command=self.selectmmWriteButtonPressed, |
gatedClock | 4:92539904a4ad | 232 | width = dWidth) |
gatedClock | 4:92539904a4ad | 233 | |
gatedClock | 8:db29cce17a33 | 234 | self.__mmWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 235 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 236 | def uiProg(self,dColumn,dRow,dWidth): # generate the 'program' button. |
gatedClock | 8:db29cce17a33 | 237 | self.__ProgButton = Button(self.__frame, text="PROGRAM", |
gatedClock | 4:92539904a4ad | 238 | command=self.selectProgButtonPressed, |
gatedClock | 4:92539904a4ad | 239 | width = dWidth) |
gatedClock | 4:92539904a4ad | 240 | |
gatedClock | 8:db29cce17a33 | 241 | self.__ProgButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 242 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 243 | # generate the 'mm dump' button. |
gatedClock | 8:db29cce17a33 | 244 | def uimmDump(self,dColumn,dRow,dWidth): |
gatedClock | 8:db29cce17a33 | 245 | self.__mmWriteButton = Button(self.__frame, text="DUMP", |
gatedClock | 4:92539904a4ad | 246 | command=self.selectmmDumpButtonPressed, |
gatedClock | 4:92539904a4ad | 247 | width = dWidth) |
gatedClock | 4:92539904a4ad | 248 | |
gatedClock | 8:db29cce17a33 | 249 | self.__mmWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 250 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 251 | def uiStep(self,dColumn,dRow,dWidth): # generate the 'step' button. |
gatedClock | 8:db29cce17a33 | 252 | self.__StepButton = Button(self.__frame, text="STEP", |
gatedClock | 4:92539904a4ad | 253 | command=self.selectStepButtonPressed, |
gatedClock | 4:92539904a4ad | 254 | width = dWidth) |
gatedClock | 4:92539904a4ad | 255 | |
gatedClock | 8:db29cce17a33 | 256 | self.__StepButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 4:92539904a4ad | 257 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 258 | def uiRun(self,dColumn,dRow,dWidth): # generate the 'run' button. |
gatedClock | 8:db29cce17a33 | 259 | self.__runButton = Button(self.__frame, text="RUN", |
gatedClock | 4:92539904a4ad | 260 | command=self.selectRunButtonPressed,width = dWidth) |
gatedClock | 4:92539904a4ad | 261 | |
gatedClock | 8:db29cce17a33 | 262 | self.__runButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 263 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 264 | def uiTest(self,dColumn,dRow,dWidth): # generate the 'test' button. |
gatedClock | 8:db29cce17a33 | 265 | self.__testButton = Button(self.__frame, text="TEST", |
gatedClock | 4:92539904a4ad | 266 | command=self.selectTestButtonPressed,width = dWidth) |
gatedClock | 4:92539904a4ad | 267 | |
gatedClock | 8:db29cce17a33 | 268 | self.__testButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 269 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 270 | def uiExit(self,dColumn,dRow,dWidth): # generate the 'exit' button. |
gatedClock | 4:92539904a4ad | 271 | |
gatedClock | 8:db29cce17a33 | 272 | self.__isRunning = 0 # end the running thread. |
gatedClock | 8:db29cce17a33 | 273 | sleep(2.0) # give thread time to stop. |
gatedClock | 4:92539904a4ad | 274 | |
gatedClock | 8:db29cce17a33 | 275 | self.__exitButton = Button(self.__frame, text="EXIT", |
gatedClock | 4:92539904a4ad | 276 | command=sys.exit,width = dWidth) |
gatedClock | 4:92539904a4ad | 277 | |
gatedClock | 8:db29cce17a33 | 278 | self.__exitButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 4:92539904a4ad | 279 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 280 | # BEGIN EXECUTE-WHEN-BUTTON-PRESSED CODE#=============================== |
gatedClock | 4:92539904a4ad | 281 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 282 | def selectConnectButtonPressed(self): # execute CONNECT. |
gatedClock | 8:db29cce17a33 | 283 | if (self.__connected == 0): |
gatedClock | 8:db29cce17a33 | 284 | self.__iUSB = mmUSBserial(idVendor=0x1234, idProduct=0x0006) |
gatedClock | 8:db29cce17a33 | 285 | self.__connected = 1 |
gatedClock | 8:db29cce17a33 | 286 | self.__connectButton["text"] = "DISCONNECT" |
gatedClock | 8:db29cce17a33 | 287 | self.__connectButton["background"] = self.__frame.cget("background") |
gatedClock | 8:db29cce17a33 | 288 | else: |
gatedClock | 8:db29cce17a33 | 289 | del(self.__iUSB) |
gatedClock | 8:db29cce17a33 | 290 | self.__connected = 0 |
gatedClock | 8:db29cce17a33 | 291 | self.__connectButton["text"] = "CONNECT" |
gatedClock | 8:db29cce17a33 | 292 | self.__connectButton["background"] = "RED" |
gatedClock | 4:92539904a4ad | 293 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 294 | def selectRegReadButtonPressed(self): # REG READ button has been pressed. |
gatedClock | 8:db29cce17a33 | 295 | self.refreshUI() # ensure proper text formats. |
gatedClock | 4:92539904a4ad | 296 | |
gatedClock | 4:92539904a4ad | 297 | |
gatedClock | 8:db29cce17a33 | 298 | # read R0. |
gatedClock | 8:db29cce17a33 | 299 | self.__iUSB.write(self.buildReadRegisterCommand("0")) |
gatedClock | 8:db29cce17a33 | 300 | fetchTextR0 = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 301 | hexTextR0 = self.formatRegValPayload(fetchTextR0) |
gatedClock | 8:db29cce17a33 | 302 | self.__R0Entry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 303 | self.__R0Entry.insert(0,hexTextR0) |
gatedClock | 4:92539904a4ad | 304 | |
gatedClock | 8:db29cce17a33 | 305 | # read R1. |
gatedClock | 8:db29cce17a33 | 306 | self.__iUSB.write(self.buildReadRegisterCommand("1")) |
gatedClock | 8:db29cce17a33 | 307 | fetchTextR1 = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 308 | hexTextR1 = self.formatRegValPayload(fetchTextR1) |
gatedClock | 8:db29cce17a33 | 309 | self.__R1Entry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 310 | self.__R1Entry.insert(0,hexTextR1) |
gatedClock | 4:92539904a4ad | 311 | |
gatedClock | 4:92539904a4ad | 312 | |
gatedClock | 8:db29cce17a33 | 313 | # read R2. |
gatedClock | 8:db29cce17a33 | 314 | self.__iUSB.write(self.buildReadRegisterCommand("2")) |
gatedClock | 8:db29cce17a33 | 315 | fetchTextR2 = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 316 | hexTextR2 = self.formatRegValPayload(fetchTextR2) |
gatedClock | 8:db29cce17a33 | 317 | self.__R2Entry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 318 | self.__R2Entry.insert(0,hexTextR2) |
gatedClock | 4:92539904a4ad | 319 | |
gatedClock | 8:db29cce17a33 | 320 | # read R3. |
gatedClock | 8:db29cce17a33 | 321 | self.__iUSB.write(self.buildReadRegisterCommand("3")) |
gatedClock | 8:db29cce17a33 | 322 | fetchTextR3 = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 323 | hexTextR3 = self.formatRegValPayload(fetchTextR3) |
gatedClock | 8:db29cce17a33 | 324 | self.__R3Entry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 325 | self.__R3Entry.insert(0,hexTextR3) |
gatedClock | 4:92539904a4ad | 326 | |
gatedClock | 4:92539904a4ad | 327 | |
gatedClock | 8:db29cce17a33 | 328 | # read Program Counter. |
gatedClock | 8:db29cce17a33 | 329 | self.__iUSB.write(self.buildReadRegisterCommand("4")) |
gatedClock | 8:db29cce17a33 | 330 | fetchTextPC = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 331 | hexTextPC = self.formatRegValPayload(fetchTextPC) |
gatedClock | 8:db29cce17a33 | 332 | self.__PCEntry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 333 | self.__PCEntry.insert(0,hexTextPC) |
gatedClock | 4:92539904a4ad | 334 | |
gatedClock | 8:db29cce17a33 | 335 | # read Instruction Register high. |
gatedClock | 8:db29cce17a33 | 336 | self.__iUSB.write(self.buildReadRegisterCommand("5")) |
gatedClock | 8:db29cce17a33 | 337 | fetchTextIRH = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 338 | hexTextIRH = self.formatRegValPayload(fetchTextIRH) |
gatedClock | 4:92539904a4ad | 339 | |
gatedClock | 4:92539904a4ad | 340 | |
gatedClock | 8:db29cce17a33 | 341 | # read Instruction Register low. |
gatedClock | 8:db29cce17a33 | 342 | self.__iUSB.write(self.buildReadRegisterCommand("6")) |
gatedClock | 8:db29cce17a33 | 343 | fetchTextIRL = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 344 | hexTextIRL = self.formatRegValPayload(fetchTextIRL) |
gatedClock | 8:db29cce17a33 | 345 | hexTextIR = hexTextIRH + hexTextIRL[2:] |
gatedClock | 4:92539904a4ad | 346 | |
gatedClock | 4:92539904a4ad | 347 | |
gatedClock | 8:db29cce17a33 | 348 | self.__IREntry.delete(0,99) # 2-byte IR content to UI. |
gatedClock | 8:db29cce17a33 | 349 | self.__IREntry.insert(0,hexTextIR) |
gatedClock | 4:92539904a4ad | 350 | |
gatedClock | 4:92539904a4ad | 351 | #---- |
gatedClock | 8:db29cce17a33 | 352 | self.refreshUI() # ensure proper text formats |
gatedClock | 4:92539904a4ad | 353 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 354 | def selectmmReadButtonPressed(self): # MM READ button has been pressed. |
gatedClock | 8:db29cce17a33 | 355 | self.refreshUI() # ensure proper text formats. |
gatedClock | 4:92539904a4ad | 356 | |
gatedClock | 8:db29cce17a33 | 357 | transmitmmADRText = self.formatByteStringForTransmit(self.__mmADREntry.get()) |
gatedClock | 8:db29cce17a33 | 358 | commandText = self.buildReadMMCommand(transmitmmADRText) |
gatedClock | 4:92539904a4ad | 359 | |
gatedClock | 8:db29cce17a33 | 360 | self.__iUSB.write(commandText) |
gatedClock | 4:92539904a4ad | 361 | |
gatedClock | 8:db29cce17a33 | 362 | fetchTextmmVAL = self.__iUSB.read() |
gatedClock | 4:92539904a4ad | 363 | |
gatedClock | 8:db29cce17a33 | 364 | buildHextmmVALString = fetchTextmmVAL[3:7] |
gatedClock | 4:92539904a4ad | 365 | |
gatedClock | 8:db29cce17a33 | 366 | self.__mmVALEntry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 367 | self.__mmVALEntry.insert(0,buildHextmmVALString) |
gatedClock | 4:92539904a4ad | 368 | #---- |
gatedClock | 8:db29cce17a33 | 369 | self.selectRegReadButtonPressed() # because registers are affected. |
gatedClock | 8:db29cce17a33 | 370 | self.refreshUI() # ensure proper text formats |
gatedClock | 4:92539904a4ad | 371 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 372 | # before writing the register values currently displayed in the UI, |
gatedClock | 8:db29cce17a33 | 373 | # this method will first run that data through a formatter, so that |
gatedClock | 8:db29cce17a33 | 374 | # the data is transformed into '0x##' format. this is convenient for |
gatedClock | 8:db29cce17a33 | 375 | # the user. for example, the user can type '12' in a register entry |
gatedClock | 8:db29cce17a33 | 376 | # form, press the 'REG WRITE' button, and that data will be reformatted |
gatedClock | 8:db29cce17a33 | 377 | # to appear as '0x12'. |
gatedClock | 4:92539904a4ad | 378 | |
gatedClock | 8:db29cce17a33 | 379 | def selectRegWriteButtonPressed(self):# REG WRITE button has been pressed. |
gatedClock | 4:92539904a4ad | 380 | |
gatedClock | 8:db29cce17a33 | 381 | self.refreshUI() # ensure proper text formats. |
gatedClock | 4:92539904a4ad | 382 | #---- |
gatedClock | 8:db29cce17a33 | 383 | # place those values in the |
gatedClock | 8:db29cce17a33 | 384 | # standard format. |
gatedClock | 8:db29cce17a33 | 385 | R0Val = self.formatByteStringForTransmit(self.__R0Entry.get()) |
gatedClock | 8:db29cce17a33 | 386 | R1Val = self.formatByteStringForTransmit(self.__R1Entry.get()) |
gatedClock | 8:db29cce17a33 | 387 | R2Val = self.formatByteStringForTransmit(self.__R2Entry.get()) |
gatedClock | 8:db29cce17a33 | 388 | R3Val = self.formatByteStringForTransmit(self.__R3Entry.get()) |
gatedClock | 8:db29cce17a33 | 389 | PCVal = self.formatByteStringForTransmit(self.__PCEntry.get()) |
gatedClock | 8:db29cce17a33 | 390 | IRVal = self.formatWordStringForTransmit(self.__IREntry.get()) |
gatedClock | 4:92539904a4ad | 391 | #---- |
gatedClock | 8:db29cce17a33 | 392 | # write those values to the CPU. |
gatedClock | 8:db29cce17a33 | 393 | self.__iUSB.write(self.buildWriteRegisterCommand("0",R0Val)) |
gatedClock | 8:db29cce17a33 | 394 | self.__iUSB.write(self.buildWriteRegisterCommand("1",R1Val)) |
gatedClock | 8:db29cce17a33 | 395 | self.__iUSB.write(self.buildWriteRegisterCommand("2",R2Val)) |
gatedClock | 8:db29cce17a33 | 396 | self.__iUSB.write(self.buildWriteRegisterCommand("3",R3Val)) |
gatedClock | 8:db29cce17a33 | 397 | self.__iUSB.write(self.buildWriteRegisterCommand("4",PCVal)) |
gatedClock | 8:db29cce17a33 | 398 | self.__iUSB.write(self.buildWriteIRCommand ( IRVal)) |
gatedClock | 4:92539904a4ad | 399 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 400 | # before writing the main-memory values currently displayed in the UI, |
gatedClock | 8:db29cce17a33 | 401 | # this method will first run that data through a formatter, so that |
gatedClock | 8:db29cce17a33 | 402 | # the data is transformed into '0x##' or '0x####' format. |
gatedClock | 8:db29cce17a33 | 403 | # this is convenient for the user. |
gatedClock | 8:db29cce17a33 | 404 | # for example, the user can type '12' in the mmADR entry |
gatedClock | 8:db29cce17a33 | 405 | # form, press the 'MM WRITE' button, and that data will be reformatted |
gatedClock | 8:db29cce17a33 | 406 | # to appear as '0x12'. |
gatedClock | 4:92539904a4ad | 407 | |
gatedClock | 8:db29cce17a33 | 408 | def selectmmWriteButtonPressed(self): # mm WRITE button has been pressed. |
gatedClock | 4:92539904a4ad | 409 | |
gatedClock | 8:db29cce17a33 | 410 | self.refreshUI() # ensure proper text formats. |
gatedClock | 4:92539904a4ad | 411 | |
gatedClock | 8:db29cce17a33 | 412 | # obtain mm values currently |
gatedClock | 8:db29cce17a33 | 413 | # displayed in the UI. |
gatedClock | 8:db29cce17a33 | 414 | self.__transmitmmADRText = self.__mmADREntry.get() |
gatedClock | 8:db29cce17a33 | 415 | self.__transmitmmVALText = self.__mmVALEntry.get() |
gatedClock | 4:92539904a4ad | 416 | |
gatedClock | 8:db29cce17a33 | 417 | # place those values in the |
gatedClock | 8:db29cce17a33 | 418 | # standard format. |
gatedClock | 8:db29cce17a33 | 419 | mmADRVAL = self.formatByteStringForTransmit(self.__mmADREntry.get()) |
gatedClock | 8:db29cce17a33 | 420 | mmVALVal = self.formatWordStringForTransmit(self.__mmVALEntry.get()) |
gatedClock | 4:92539904a4ad | 421 | |
gatedClock | 8:db29cce17a33 | 422 | # write those values to the CPU. |
gatedClock | 8:db29cce17a33 | 423 | self.__iUSB.write(self.buildWriteMMCommand(mmADRVAL,mmVALVal)) |
gatedClock | 4:92539904a4ad | 424 | |
gatedClock | 8:db29cce17a33 | 425 | self.selectRegReadButtonPressed() # because registers are affected. |
gatedClock | 4:92539904a4ad | 426 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 427 | def selectProgButtonPressed(self): # Program button has been pressed. |
gatedClock | 4:92539904a4ad | 428 | |
gatedClock | 8:db29cce17a33 | 429 | # ask user for program source file |
gatedClock | 8:db29cce17a33 | 430 | # name using a dialog. |
gatedClock | 8:db29cce17a33 | 431 | fileName = tkFileDialog.askopenfilename(defaultextension='.txt') |
gatedClock | 4:92539904a4ad | 432 | |
gatedClock | 8:db29cce17a33 | 433 | print("memory load started.") # announce to user. |
gatedClock | 8:db29cce17a33 | 434 | self.progamMainMemory(fileName) # main part of programming. |
gatedClock | 8:db29cce17a33 | 435 | print("memory load completed.") # announce to user. |
gatedClock | 4:92539904a4ad | 436 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 437 | def selectmmDumpButtonPressed(self): # MM dump button has been pressed. |
gatedClock | 4:92539904a4ad | 438 | |
gatedClock | 8:db29cce17a33 | 439 | # obtain file-to-write-to name |
gatedClock | 8:db29cce17a33 | 440 | # from user, using a dialog. |
gatedClock | 8:db29cce17a33 | 441 | fileName = tkFileDialog.asksaveasfilename(defaultextension='.txt') |
gatedClock | 4:92539904a4ad | 442 | |
gatedClock | 8:db29cce17a33 | 443 | print("memory dump started.") # announce to user. |
gatedClock | 8:db29cce17a33 | 444 | self.dumpMainMemory(fileName) # dump main memory to file. |
gatedClock | 8:db29cce17a33 | 445 | print("memory dump completed.") # announce to user. |
gatedClock | 4:92539904a4ad | 446 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 447 | def selectStepButtonPressed(self): # STEP button has been pressed. |
gatedClock | 8:db29cce17a33 | 448 | self.__iUSB.write("50000000") # the command code. |
gatedClock | 8:db29cce17a33 | 449 | self.selectRegReadButtonPressed() # monitor the result. |
gatedClock | 4:92539904a4ad | 450 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 451 | def selectRunButtonPressed(self): # RUN/STOP button has been pressed. |
gatedClock | 4:92539904a4ad | 452 | |
gatedClock | 8:db29cce17a33 | 453 | if (self.__isRunning == 0): # start high speed run. |
gatedClock | 8:db29cce17a33 | 454 | self.__isRunning = 1 |
gatedClock | 8:db29cce17a33 | 455 | self.__runButton["text"] = "SLOW" |
gatedClock | 8:db29cce17a33 | 456 | self.t = threading.Thread(target=self.doRun) |
gatedClock | 8:db29cce17a33 | 457 | self.t.start() |
gatedClock | 4:92539904a4ad | 458 | |
gatedClock | 8:db29cce17a33 | 459 | elif (self.__isRunning == 1): # switch to a slower run. |
gatedClock | 8:db29cce17a33 | 460 | self.__isRunning = 2 |
gatedClock | 4:92539904a4ad | 461 | self.__runButton["text"] = "STOP" |
gatedClock | 4:92539904a4ad | 462 | |
gatedClock | 8:db29cce17a33 | 463 | else: # stop the CPU. |
gatedClock | 8:db29cce17a33 | 464 | self.__isRunning = 0 |
gatedClock | 8:db29cce17a33 | 465 | self.__runButton["text"] = "RUN" |
gatedClock | 4:92539904a4ad | 466 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 467 | def selectTestButtonPressed(self): # TEST/STOP button has been pressed. |
gatedClock | 4:92539904a4ad | 468 | |
gatedClock | 8:db29cce17a33 | 469 | if (self.__testRunning == 0): # start test. |
gatedClock | 8:db29cce17a33 | 470 | self.__testRunning = 1 |
gatedClock | 8:db29cce17a33 | 471 | self.__testButton["text"] = "STOP TEST" |
gatedClock | 8:db29cce17a33 | 472 | self.t = threading.Thread(target=self.doTest) |
gatedClock | 8:db29cce17a33 | 473 | self.t.start() |
gatedClock | 4:92539904a4ad | 474 | |
gatedClock | 4:92539904a4ad | 475 | |
gatedClock | 8:db29cce17a33 | 476 | else: # stop test. |
gatedClock | 8:db29cce17a33 | 477 | self.__testRunning = 0 |
gatedClock | 8:db29cce17a33 | 478 | self.__testButton["text"] = "TEST" |
gatedClock | 4:92539904a4ad | 479 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 480 | # BEGIN UTILITY CODE. #=============================== |
gatedClock | 4:92539904a4ad | 481 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 482 | # guarantee 0x## format. |
gatedClock | 8:db29cce17a33 | 483 | def formatByteStringForDisplay(self, byteText): |
gatedClock | 8:db29cce17a33 | 484 | |
gatedClock | 8:db29cce17a33 | 485 | xIndex = byteText.find("x") # eliminate any 0x, 0X prefix. |
gatedClock | 8:db29cce17a33 | 486 | XIndex = byteText.find("X") |
gatedClock | 4:92539904a4ad | 487 | |
gatedClock | 8:db29cce17a33 | 488 | theXindex = 0 |
gatedClock | 8:db29cce17a33 | 489 | if (xIndex >= 0): theXindex = xIndex + 1 |
gatedClock | 8:db29cce17a33 | 490 | if (XIndex >= 0): theXindex = XIndex + 1 |
gatedClock | 4:92539904a4ad | 491 | |
gatedClock | 8:db29cce17a33 | 492 | buildText = byteText[theXindex:] # any 0x, 0X prefix gone. |
gatedClock | 4:92539904a4ad | 493 | |
gatedClock | 8:db29cce17a33 | 494 | # build-out leading 0's. |
gatedClock | 8:db29cce17a33 | 495 | if (len(buildText) == 0): buildText = "0" + buildText |
gatedClock | 8:db29cce17a33 | 496 | if (len(buildText) == 1): buildText = "0" + buildText |
gatedClock | 4:92539904a4ad | 497 | |
gatedClock | 8:db29cce17a33 | 498 | # truncate leading characters. |
gatedClock | 8:db29cce17a33 | 499 | if (len(buildText) > 2): buildText = buildText[-2:] |
gatedClock | 4:92539904a4ad | 500 | |
gatedClock | 8:db29cce17a33 | 501 | buildText = "0x" + buildText # add leading 0x. |
gatedClock | 4:92539904a4ad | 502 | |
gatedClock | 8:db29cce17a33 | 503 | return(buildText) # 0x## format returned. |
gatedClock | 4:92539904a4ad | 504 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 505 | # guarantee 0x#### format. |
gatedClock | 8:db29cce17a33 | 506 | def formatWordStringForDisplay(self, wordText): |
gatedClock | 8:db29cce17a33 | 507 | |
gatedClock | 8:db29cce17a33 | 508 | xIndex = wordText.find("x") # eliminate any 0x, 0X prefix. |
gatedClock | 8:db29cce17a33 | 509 | XIndex = wordText.find("X") |
gatedClock | 4:92539904a4ad | 510 | |
gatedClock | 8:db29cce17a33 | 511 | theXindex = 0 |
gatedClock | 8:db29cce17a33 | 512 | if (xIndex >= 0): theXindex = xIndex + 1 |
gatedClock | 8:db29cce17a33 | 513 | if (XIndex >= 0): theXindex = XIndex + 1 |
gatedClock | 4:92539904a4ad | 514 | |
gatedClock | 8:db29cce17a33 | 515 | buildText = wordText[theXindex:] # any 0x, 0X prefix gone. |
gatedClock | 4:92539904a4ad | 516 | |
gatedClock | 8:db29cce17a33 | 517 | # build-out leading 0's. |
gatedClock | 8:db29cce17a33 | 518 | if (len(buildText) == 0): buildText = "0" + buildText |
gatedClock | 8:db29cce17a33 | 519 | if (len(buildText) == 1): buildText = "0" + buildText |
gatedClock | 8:db29cce17a33 | 520 | if (len(buildText) == 2): buildText = "0" + buildText |
gatedClock | 8:db29cce17a33 | 521 | if (len(buildText) == 3): buildText = "0" + buildText |
gatedClock | 4:92539904a4ad | 522 | |
gatedClock | 4:92539904a4ad | 523 | |
gatedClock | 8:db29cce17a33 | 524 | # truncate leading characters. |
gatedClock | 8:db29cce17a33 | 525 | if (len(buildText) > 4): buildText = buildText[-4:] |
gatedClock | 4:92539904a4ad | 526 | |
gatedClock | 8:db29cce17a33 | 527 | buildText = "0x" + buildText # add leading 0x. |
gatedClock | 4:92539904a4ad | 528 | |
gatedClock | 8:db29cce17a33 | 529 | return(buildText) # 0x## format returned. |
gatedClock | 4:92539904a4ad | 530 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 531 | # guarantee ## format. |
gatedClock | 8:db29cce17a33 | 532 | def formatByteStringForTransmit(self, byteText): |
gatedClock | 8:db29cce17a33 | 533 | buildText = self.formatByteStringForDisplay(byteText) |
gatedClock | 8:db29cce17a33 | 534 | buildText = buildText[-2:] |
gatedClock | 8:db29cce17a33 | 535 | return(buildText) |
gatedClock | 4:92539904a4ad | 536 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 537 | # guarantee #### format. |
gatedClock | 8:db29cce17a33 | 538 | def formatWordStringForTransmit(self, wordText): |
gatedClock | 8:db29cce17a33 | 539 | buildText = self.formatWordStringForDisplay(wordText) |
gatedClock | 8:db29cce17a33 | 540 | buildText = buildText[-4:] |
gatedClock | 8:db29cce17a33 | 541 | return(buildText) |
gatedClock | 4:92539904a4ad | 542 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 543 | def refreshUI(self): # reformat UI text. |
gatedClock | 4:92539904a4ad | 544 | |
gatedClock | 8:db29cce17a33 | 545 | # copy-in current form contents. |
gatedClock | 8:db29cce17a33 | 546 | originalR0Entry = self.__R0Entry.get() |
gatedClock | 8:db29cce17a33 | 547 | originalR1Entry = self.__R1Entry.get() |
gatedClock | 8:db29cce17a33 | 548 | originalR2Entry = self.__R2Entry.get() |
gatedClock | 8:db29cce17a33 | 549 | originalR3Entry = self.__R3Entry.get() |
gatedClock | 8:db29cce17a33 | 550 | originalPCEntry = self.__PCEntry.get() |
gatedClock | 8:db29cce17a33 | 551 | originalIREntry = self.__IREntry.get() |
gatedClock | 8:db29cce17a33 | 552 | originalmmADREntry = self.__mmADREntry.get() |
gatedClock | 8:db29cce17a33 | 553 | originalmmVALEntry = self.__mmVALEntry.get() |
gatedClock | 4:92539904a4ad | 554 | |
gatedClock | 8:db29cce17a33 | 555 | # reformat form contents. |
gatedClock | 8:db29cce17a33 | 556 | newR0Entry = self.formatByteStringForDisplay(originalR0Entry) |
gatedClock | 8:db29cce17a33 | 557 | newR1Entry = self.formatByteStringForDisplay(originalR1Entry) |
gatedClock | 8:db29cce17a33 | 558 | newR2Entry = self.formatByteStringForDisplay(originalR2Entry) |
gatedClock | 8:db29cce17a33 | 559 | newR3Entry = self.formatByteStringForDisplay(originalR3Entry) |
gatedClock | 8:db29cce17a33 | 560 | newPCEntry = self.formatByteStringForDisplay(originalPCEntry) |
gatedClock | 8:db29cce17a33 | 561 | newIREntry = self.formatWordStringForDisplay(originalIREntry) |
gatedClock | 4:92539904a4ad | 562 | |
gatedClock | 8:db29cce17a33 | 563 | newmmADREntry = self.formatByteStringForDisplay(originalmmADREntry) |
gatedClock | 8:db29cce17a33 | 564 | newmmVALEntry = self.formatWordStringForDisplay(originalmmVALEntry) |
gatedClock | 4:92539904a4ad | 565 | |
gatedClock | 8:db29cce17a33 | 566 | |
gatedClock | 8:db29cce17a33 | 567 | self.__R0Entry. delete(0,99) # clear form contents. |
gatedClock | 8:db29cce17a33 | 568 | self.__R1Entry. delete(0,99) |
gatedClock | 8:db29cce17a33 | 569 | self.__R2Entry. delete(0,99) |
gatedClock | 8:db29cce17a33 | 570 | self.__R3Entry. delete(0,99) |
gatedClock | 8:db29cce17a33 | 571 | self.__PCEntry. delete(0,99) |
gatedClock | 8:db29cce17a33 | 572 | self.__IREntry. delete(0,99) |
gatedClock | 8:db29cce17a33 | 573 | self.__mmADREntry.delete(0,99) |
gatedClock | 8:db29cce17a33 | 574 | self.__mmVALEntry.delete(0,99) |
gatedClock | 4:92539904a4ad | 575 | |
gatedClock | 8:db29cce17a33 | 576 | # update form contents. |
gatedClock | 8:db29cce17a33 | 577 | self.__R0Entry. insert(0,newR0Entry) |
gatedClock | 8:db29cce17a33 | 578 | self.__R1Entry. insert(0,newR1Entry) |
gatedClock | 8:db29cce17a33 | 579 | self.__R2Entry. insert(0,newR2Entry) |
gatedClock | 8:db29cce17a33 | 580 | self.__R3Entry. insert(0,newR3Entry) |
gatedClock | 8:db29cce17a33 | 581 | self.__PCEntry. insert(0,newPCEntry) |
gatedClock | 8:db29cce17a33 | 582 | self.__IREntry. insert(0,newIREntry) |
gatedClock | 8:db29cce17a33 | 583 | self.__mmADREntry.insert(0,newmmADREntry) |
gatedClock | 8:db29cce17a33 | 584 | self.__mmVALEntry.insert(0,newmmVALEntry) |
gatedClock | 4:92539904a4ad | 585 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 586 | # build the command string for |
gatedClock | 8:db29cce17a33 | 587 | # reading a value from a CPU register. |
gatedClock | 8:db29cce17a33 | 588 | def buildReadRegisterCommand(self,regNum): |
gatedClock | 4:92539904a4ad | 589 | |
gatedClock | 8:db29cce17a33 | 590 | commandText = "" # build command for read register. |
gatedClock | 8:db29cce17a33 | 591 | commandText = commandText + "2" # command-code. |
gatedClock | 8:db29cce17a33 | 592 | commandText = commandText + regNum # register number. |
gatedClock | 8:db29cce17a33 | 593 | commandText = commandText + "0000000000000" |
gatedClock | 8:db29cce17a33 | 594 | return(commandText) |
gatedClock | 4:92539904a4ad | 595 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 596 | # build the command-string for |
gatedClock | 8:db29cce17a33 | 597 | # writing a value to a CPU register. |
gatedClock | 8:db29cce17a33 | 598 | def buildWriteRegisterCommand(self,regNum,regVal): |
gatedClock | 4:92539904a4ad | 599 | |
gatedClock | 8:db29cce17a33 | 600 | commandText = "" |
gatedClock | 8:db29cce17a33 | 601 | commandText = commandText + "1" # command-code. |
gatedClock | 8:db29cce17a33 | 602 | commandText = commandText + regNum # register. |
gatedClock | 8:db29cce17a33 | 603 | commandText = commandText + regVal # content. |
gatedClock | 8:db29cce17a33 | 604 | commandText = commandText + "00000000000" |
gatedClock | 8:db29cce17a33 | 605 | return(commandText) |
gatedClock | 4:92539904a4ad | 606 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 607 | # build the command-string for |
gatedClock | 8:db29cce17a33 | 608 | # writing a value to the IR. |
gatedClock | 8:db29cce17a33 | 609 | def buildWriteIRCommand(self,regVal): |
gatedClock | 4:92539904a4ad | 610 | |
gatedClock | 8:db29cce17a33 | 611 | commandText = "" |
gatedClock | 8:db29cce17a33 | 612 | commandText = commandText + "6" # command-code. |
gatedClock | 8:db29cce17a33 | 613 | commandText = commandText + "5" # actually a placeholder. |
gatedClock | 8:db29cce17a33 | 614 | commandText = commandText + regVal # content. |
gatedClock | 8:db29cce17a33 | 615 | commandText = commandText + "000000000" |
gatedClock | 8:db29cce17a33 | 616 | return(commandText) |
gatedClock | 4:92539904a4ad | 617 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 618 | # build the command-string for |
gatedClock | 8:db29cce17a33 | 619 | # writing a main-memory value. |
gatedClock | 8:db29cce17a33 | 620 | def buildWriteMMCommand(self,mmADR,mmVAL): |
gatedClock | 8:db29cce17a33 | 621 | |
gatedClock | 8:db29cce17a33 | 622 | commandText = "" |
gatedClock | 8:db29cce17a33 | 623 | commandText = commandText + "3" # command-code. |
gatedClock | 8:db29cce17a33 | 624 | commandText = commandText + mmADR # address. |
gatedClock | 8:db29cce17a33 | 625 | commandText = commandText + mmVAL # value. |
gatedClock | 8:db29cce17a33 | 626 | commandText = commandText + "00000000" |
gatedClock | 8:db29cce17a33 | 627 | return(commandText) |
gatedClock | 4:92539904a4ad | 628 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 629 | def buildReadMMCommand(self,mmADR): # build read-mm command-string. |
gatedClock | 8:db29cce17a33 | 630 | commandText = "" # build command for read main-memory. |
gatedClock | 8:db29cce17a33 | 631 | commandText = commandText + "4" # command-code. |
gatedClock | 8:db29cce17a33 | 632 | commandText = commandText + mmADR |
gatedClock | 8:db29cce17a33 | 633 | commandText = commandText + "000000000000" |
gatedClock | 8:db29cce17a33 | 634 | return(commandText) |
gatedClock | 4:92539904a4ad | 635 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 636 | # extract reg value payload. |
gatedClock | 8:db29cce17a33 | 637 | def formatRegValPayload(self,messageVector): |
gatedClock | 8:db29cce17a33 | 638 | buildHex = "0x" + messageVector[2:4] |
gatedClock | 8:db29cce17a33 | 639 | return(buildHex) |
gatedClock | 4:92539904a4ad | 640 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 641 | def progamMainMemory(self,progFile): # core of loading program to MM. |
gatedClock | 4:92539904a4ad | 642 | |
gatedClock | 8:db29cce17a33 | 643 | hFile = open(progFile, 'r') |
gatedClock | 8:db29cce17a33 | 644 | fileLineList = hFile.readlines() # read file into a list. |
gatedClock | 8:db29cce17a33 | 645 | hFile.close() # close the file. |
gatedClock | 4:92539904a4ad | 646 | |
gatedClock | 8:db29cce17a33 | 647 | # load '0x12 0x3456' memory content |
gatedClock | 8:db29cce17a33 | 648 | # format, into a list. |
gatedClock | 8:db29cce17a33 | 649 | for listIndex in range(0, len(fileLineList)): |
gatedClock | 8:db29cce17a33 | 650 | addressStartIndex = fileLineList[listIndex].find("0x") + 2 |
gatedClock | 8:db29cce17a33 | 651 | dataStartIndex = fileLineList[listIndex].find("0x", addressStartIndex) + 2 |
gatedClock | 8:db29cce17a33 | 652 | progAddress = fileLineList[listIndex][addressStartIndex : addressStartIndex + 2] |
gatedClock | 8:db29cce17a33 | 653 | progAddress = format(listIndex,'02x') |
gatedClock | 8:db29cce17a33 | 654 | progData = fileLineList[listIndex][dataStartIndex : dataStartIndex + 4] |
gatedClock | 8:db29cce17a33 | 655 | commandText = self.buildWriteMMCommand(progAddress,progData) |
gatedClock | 4:92539904a4ad | 656 | self.__iUSB.write(commandText) |
gatedClock | 8:db29cce17a33 | 657 | print(fileLineList[listIndex][0:len(fileLineList[listIndex])-1]) |
gatedClock | 8:db29cce17a33 | 658 | sleep(self.__sleepVal) |
gatedClock | 4:92539904a4ad | 659 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 660 | def dumpMainMemory(self,dumpFile): # core of dumping MM to file. |
gatedClock | 4:92539904a4ad | 661 | |
gatedClock | 8:db29cce17a33 | 662 | hFile = open(dumpFile, 'w') |
gatedClock | 4:92539904a4ad | 663 | |
gatedClock | 8:db29cce17a33 | 664 | for loopIndex in range(0, 256): # traverse all of main-memory. |
gatedClock | 8:db29cce17a33 | 665 | transmitmmADRText = "{}".format(hex(loopIndex)) |
gatedClock | 4:92539904a4ad | 666 | transmitmmADRText = transmitmmADRText[2:] |
gatedClock | 4:92539904a4ad | 667 | if (len(transmitmmADRText) == 1): transmitmmADRText = "0" + transmitmmADRText |
gatedClock | 8:db29cce17a33 | 668 | commandText = self.buildReadMMCommand(transmitmmADRText) |
gatedClock | 8:db29cce17a33 | 669 | self.__iUSB.write(commandText) |
gatedClock | 8:db29cce17a33 | 670 | fetchTextmmVAL = self.__iUSB.read() |
gatedClock | 8:db29cce17a33 | 671 | buildHextmmVALString = fetchTextmmVAL[3:7] |
gatedClock | 8:db29cce17a33 | 672 | buildHexIndex = hex(loopIndex) |
gatedClock | 8:db29cce17a33 | 673 | buildHexIndex = buildHexIndex[2:] |
gatedClock | 8:db29cce17a33 | 674 | if (len(buildHexIndex) == 1): buildHexIndex = "0" + buildHexIndex |
gatedClock | 8:db29cce17a33 | 675 | buildHexIndex = "0x" + buildHexIndex |
gatedClock | 8:db29cce17a33 | 676 | dumpString = " {} 0x{}\n".format(buildHexIndex,buildHextmmVALString) |
gatedClock | 8:db29cce17a33 | 677 | hFile.write(dumpString) |
gatedClock | 8:db29cce17a33 | 678 | print(dumpString[0:len(dumpString)-1]) |
gatedClock | 8:db29cce17a33 | 679 | sleep(self.__sleepVal) |
gatedClock | 4:92539904a4ad | 680 | |
gatedClock | 8:db29cce17a33 | 681 | hFile.close() # close the dump file. |
gatedClock | 4:92539904a4ad | 682 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 683 | # BEGIN THREADED CODE. #=============================== |
gatedClock | 4:92539904a4ad | 684 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 685 | def doRun(self): # drives the CPU running. |
gatedClock | 8:db29cce17a33 | 686 | while(self.__isRunning): |
gatedClock | 8:db29cce17a33 | 687 | self.selectStepButtonPressed() |
gatedClock | 8:db29cce17a33 | 688 | self.__masterWidget.update_idletasks() |
gatedClock | 4:92539904a4ad | 689 | if (self.__isRunning == 2): sleep(1.0) |
gatedClock | 4:92539904a4ad | 690 | #-----------------------------------------------#------------------------------- |
gatedClock | 8:db29cce17a33 | 691 | # the test consists of loading the add-list program into main memory, |
gatedClock | 8:db29cce17a33 | 692 | # running it, dumping the result to a file, and comparing that file |
gatedClock | 8:db29cce17a33 | 693 | # to the expected result. |
gatedClock | 4:92539904a4ad | 694 | |
gatedClock | 8:db29cce17a33 | 695 | def doTest(self): # drives the test. |
gatedClock | 8:db29cce17a33 | 696 | while(self.__testRunning): |
gatedClock | 8:db29cce17a33 | 697 | # load program into main memory. |
gatedClock | 8:db29cce17a33 | 698 | self.progamMainMemory("prog_add_list.txt") |
gatedClock | 4:92539904a4ad | 699 | |
gatedClock | 8:db29cce17a33 | 700 | # clear instruction register. |
gatedClock | 8:db29cce17a33 | 701 | self.__iUSB.write(self.buildWriteIRCommand("0000")) |
gatedClock | 4:92539904a4ad | 702 | |
gatedClock | 8:db29cce17a33 | 703 | # rewind program counter. |
gatedClock | 8:db29cce17a33 | 704 | PCVal = self.formatByteStringForTransmit("0") |
gatedClock | 8:db29cce17a33 | 705 | writePCcommand = self.buildWriteRegisterCommand("4",PCVal) |
gatedClock | 8:db29cce17a33 | 706 | self.__iUSB.write(writePCcommand) |
gatedClock | 8:db29cce17a33 | 707 | self.selectRegReadButtonPressed() |
gatedClock | 4:92539904a4ad | 708 | |
gatedClock | 4:92539904a4ad | 709 | |
gatedClock | 8:db29cce17a33 | 710 | for stepIndex in range(0, 196): # step through program. |
gatedClock | 8:db29cce17a33 | 711 | self.selectStepButtonPressed() |
gatedClock | 4:92539904a4ad | 712 | |
gatedClock | 8:db29cce17a33 | 713 | # dump result to file. |
gatedClock | 8:db29cce17a33 | 714 | self.dumpMainMemory ("dump_test.txt") |
gatedClock | 4:92539904a4ad | 715 | |
gatedClock | 8:db29cce17a33 | 716 | # build and run test commands. |
gatedClock | 8:db29cce17a33 | 717 | self.__testIter = self.__testIter + 1 |
gatedClock | 8:db29cce17a33 | 718 | iterationText = "test iteration {}".format(self.__testIter) |
gatedClock | 8:db29cce17a33 | 719 | iterationText = "echo '" + iterationText + "' >> testlog.txt" |
gatedClock | 8:db29cce17a33 | 720 | os.system("echo ============================ >> testlog.txt") |
gatedClock | 8:db29cce17a33 | 721 | os.system("date >> testlog.txt") |
gatedClock | 8:db29cce17a33 | 722 | os.system(iterationText) |
gatedClock | 8:db29cce17a33 | 723 | os.system("echo 'compare dump_test.txt against dump_add_list.txt' >> testlog.txt") |
gatedClock | 8:db29cce17a33 | 724 | os.system("diff dump_add_list.txt dump_test.txt >> testlog.txt") |
gatedClock | 4:92539904a4ad | 725 | |
gatedClock | 8:db29cce17a33 | 726 | self.__masterWidget.update_idletasks() |
gatedClock | 4:92539904a4ad | 727 | #===============================================#=============================== |
gatedClock | 4:92539904a4ad | 728 | |
gatedClock | 4:92539904a4ad | 729 | |
gatedClock | 4:92539904a4ad | 730 | |
gatedClock | 4:92539904a4ad | 731 | |
gatedClock | 4:92539904a4ad | 732 | |
gatedClock | 4:92539904a4ad | 733 | |
gatedClock | 4:92539904a4ad | 734 | |
gatedClock | 4:92539904a4ad | 735 | |
gatedClock | 4:92539904a4ad | 736 | |
gatedClock | 4:92539904a4ad | 737 | |
gatedClock | 4:92539904a4ad | 738 | |
gatedClock | 4:92539904a4ad | 739 | |
gatedClock | 4:92539904a4ad | 740 |