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

   Case 2:

     Open App.Path & "\I9497.txt" For Input As #isprime9497

     fileNum = isprime9497

   Case 3:

     Open App.Path & "\F5.txt" For Input As #fact5

     fileNum = fact5

   Case 4:

     Open App.Path & "\F12.txt" For Input As #fact12

     fileNum = fact12

   Case 5:

     Open App.Path & "\S50.txt" For Input As #sieve50

     fileNum = sieve50

   Case 6:

     Open App.Path & "\S9500.txt" For Input As #sieve9500

     fileNum = sieve9500

  End Select

   Input #fileNum, numInstructions

   jobLen(fileNum) = numInstructions

   Input #fileNum, iNum

   For i = 1 To numInstructions - 1

    Input #fileNum, whatdo, ref

    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

          rangelo(fileNum, i) = nxtMem \ pageSize

          Input #fileNum, nxtVal

          While nxtVal = 0

            Input #fileNum, nxtMem, nxtVal

          Wend

          rangehi(fileNum, i) = nxtMem \ pageSize

          iNum = nxtVal

       End Select

    End Select

   Next i

    Input #fileNum, whatdo, ref

    page1(fileNum, i) = ref \ pageSize

    action(fileNum, i) = 6

   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