/
globalFuncions.py
115 lines (89 loc) · 2.77 KB
/
globalFuncions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from Printer import Printer
def MakeCard(WordList):
'''
'''
WordCount = 0
card = list(list())
for i in range(0,len(WordList)):
WordCount += 1
card.append(WordList[i])
if i == len(WordList) - 1 and WordCount < 10:
while(WordCount != 10):
card.append(['-','-','-','-'])
WordCount += 1
return card
def MakeWord(CharList):
"""
"""
charCount = 0
word = []
wordList = list(list())
for i in range(0,len(CharList)):
charCount += 1
word.append(CharList[i])
if charCount == 4:
wordList.append(word)
charCount = 0
word = []
elif i == len(CharList) - 1 and charCount != 4:
while(charCount != 4):
word.append('-')
charCount += 1
wordList.append(word)
return wordList
def filterList(argList):
CharList = argList
if (' ' in CharList):
CharList = filter(lambda a: a != ' ',CharList)
if ('' in CharList):
CharList = filter(lambda a: a != '',CharList)
if ('$' in CharList):
CharList = filter(lambda a: a != '$',CharList)
if ('\n' in CharList):
CharList = filter(lambda a: a != '\n',CharList)
if ('\r' in CharList):
CharList = filter(lambda a: a != '\r',CharList)
return CharList
def roundOff(address):
if address % 10 != 0:
index = address - (address % 10)
else:
index = address
return index
def PutData(location,CPU,progPCB,Memory):
progPCB.TLC += 1
if(progPCB.TLC > progPCB.TLL):
CPU.Abort(ProgFile,3)
else:
index = roundOff(location)
data = ReadCard(index,Memory)
if data == '0':
print ' '
else:
print 'Data', data
Printer.enterLog(str(progPCB.PID) + '-->' +'Data: ' + data)
def ReadCard(track):
'''
Read card from passed Memory Location.
Para: Location to be Read ---> Returns: string to print (Card (10 word List))
'''
count = 0
string = ''
while(count < 10):
string += ReadWord(track[count])
if (string == '0'):
break
count += 1
return string
def ReadWord(word):
'''
Read Word from passed Memory Location.
Para: Location to be Read ---> Returns: Word (List of 4 char)
'''
if len(word) == 0:
return '0'
else:
string = ''
for char in word:
string += char
return string