Code for
Project #3 ::
Paging
CIS343
Option Explicit
Dim action(1 To 6, 1 To 136000) As Integer
Dim page1(1 To 6, 1 To 136000) As Integer
Dim page2(1 To 6, 1 To 136000) As Integer
Dim rangelo(1 To 6, 1 To 136000) As Integer
Dim rangehi(1 To 6, 1 To 136000) As Integer
Dim jobLen(1 To 6) As Long
Private Type anEvent
time As Long
pid As Integer
whEvent As
String * 8
End Type
Dim mtk(1 To 30) As anEvent
Private Type job_pcb
state As String *
7
entryTime As
Integer
progNum As
Integer
IC As Long
End Type
Dim job(1 To 30) As job_pcb
Const isprime900 = 1
Const isprime9497 = 2
Const fact5 = 3
Const fact12 = 4
Const sieve50 = 5
Const sieve9500 = 6
Const pageSize = 25
Dim cpuJob As Integer
Dim ReadyQ(0 To 5) As Integer
Dim readyQHead As Integer
Dim readyQTail As Integer
Const rqSize = 6
Dim NewQ(0 To 25) As Integer
Dim newQHead As Integer
Dim newQTail As Integer
Const newqSize = 26
Dim jobsInSystem As Integer
Dim numberOfEvents
Dim currentTime As Long
Dim secondPhase As Boolean
Private Sub cmdInit_Click()
Call ReadTraces
Call InitGlobals
End Sub
Public Sub ReadTraces()
Dim i As Long
Dim iNum As Long
Dim whatdo As Integer
Dim ref As Integer
Dim nxt As Long
Dim nxtVal As Long
Dim nxtMem As Integer
Dim fileNo As Integer
Dim fileNum As Integer
Dim numInstructions As Long
For fileNo = 1 To
6
Select Case
fileNo
Case 1:
Open App.Path
& "\I900.txt" For Input As #isprime900
fileNum =
isprime900
Debug.Print
"File is IsPrime 900"
Case 2:
Open App.Path
& "\I9497.txt" For Input As #isprime9497
fileNum =
isprime9497
Debug.Print
"File is IsPrime 9497"
Case 3:
Open App.Path
& "\F5.txt" For Input As #fact5
fileNum =
fact5
Debug.Print
"File is Fact 5"
Case 4:
Open App.Path &
"\F12.txt" For Input As #fact12
fileNum =
fact12
Debug.Print
"File is Fact 12"
Case 5:
Open App.Path
& "\S50.txt" For Input As #sieve50
fileNum =
sieve50
Debug.Print
"File is Sieve 50"
Case 6:
Open App.Path
& "\S9500.txt" For Input As #sieve9500
fileNum =
sieve9500
Debug.Print
"File is Sieve 9500"
End Select
Input #fileNum,
numInstructions
jobLen(fileNum)
= numInstructions
Input #fileNum,
iNum
For i = 1 To
numInstructions - 1
If -iNum
<> i Then
Debug.Print
"Error - iNum "; iNum; " does not match i "; i
Stop
End If
Input #fileNum,
whatdo, ref
If whatdo
<> 0 Then
Debug.Print
"Error - Should be read - is: "; whatdo
Stop
End If
page1(fileNum,
i) = ref \ pageSize
Input #fileNum,
nxt
Select Case nxt
Case Is <
0:
action(fileNum, i) = 1
iNum = nxt
Case 0:
Input
#fileNum, ref
page2(fileNum, i) = ref \ pageSize
action(fileNum, i) = 2
Input
#fileNum, iNum
Case 10000:
Input
#fileNum, ref
page2(fileNum, i) = ref \ pageSize
action(fileNum, i) = 3
Input
#fileNum, iNum
Case 500:
Input
#fileNum, ref
Select Case
ref
Case 1, 2:
action(fileNum,
i) = 4
Input
#fileNum, iNum
Case 3:
action(fileNum, i) = 5
Input
#fileNum, nxtVal, nxtMem
If nxtVal
<> 0 Then
Debug.Print "Error - should be READ, i.e., 0 - is: "; nxtVal
Stop
End If
rangelo(fileNum, i) = nxtMem \ pageSize
Input
#fileNum, nxtVal
While
nxtVal = 0
Input
#fileNum, nxtMem, nxtVal
Wend
rangehi(fileNum, i) = nxtMem \ pageSize
iNum =
nxtVal
Case Else:
Debug.Print "Error - No such syscall val "; ref; "at
:"; i
End Select
Case Else:
Debug.Print
"Error - No such action val "; nxt; "at :"; i
End Select
Next i
If -iNum
<> i Then
Debug.Print
"Error - no match at "; i
Stop
End If
Input #fileNum,
whatdo, ref
If whatdo
<> 0 Then
Debug.Print
"Error - Should be read - is: "; whatdo
Stop
End If
page1(fileNum,
i) = ref \ pageSize
action(fileNum,
i) = 6
Debug.Print
whatdo, ref
Close #fileNum
Next fileNo
lblMesg.Caption =
"DONE!"
End Sub
Public Sub InitGlobals()
Dim i As Integer
For i = 1 To 30
job(i).IC = 1
job(i).state =
"null"
Next i
Call
SetSubmissionTimes
Call InitMTK
Call InitQs
jobsInSystem = 0
cpuJob = 0
End Sub