⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.frm

📁 简单的操作系统程序
💻 FRM
📖 第 1 页 / 共 4 页
字号:
            lblrun.Caption = "X--"
        Case &H78FF
            lblrun.Caption = "End"
        Case Else
            Select Case setHigh2(CpuZ.IR, &HFF)
                Case &H40FF
                    lblrun.Caption = "赋值X=" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case &H9FF
                    lblrun.Caption = "启动一号打印机,申请时间:" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case &HAFF
                    lblrun.Caption = "启动二号打印机,申请时间:" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case &HBFF
                    lblrun.Caption = "启动一号扫描仪,申请时间:" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case &HCFF
                    lblrun.Caption = "启动二号扫描仪,申请时间:" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case &HDFF
                    lblrun.Caption = "启动磁带机,申请时间:" + CStr(setLow2(CpuZ.IR, &HFF00))
                Case Else
                'lblrun.Caption = "未知指令"
            End Select
    End Select


End Sub

Private Sub CpuZ_InterruptEvent(ByVal Data As Byte, ByVal PSW As Byte)
    CpuZ.Halt
    MemC.Halt
    Timm.Enabled = False
        'MsgBox "psw=" + Hex$(PSW), vbOKOnly + vbExclamation, "Event"
        If setLow(PSW, &HE0) Then '设备中断
            Call DeviceRunCompleteInterrupt(setLow(PSW, &HE0))
        End If
        If setLow(PSW, &HDF) Then '时钟中断
            Call timeInterruptProc
        End If
        If setLow(PSW, &H7F) Then '计算溢出时的中断
            Open "Result.txt" For Append Access Write As #1
            Print #1, "真实世界时间" + CStr(Now) + ",进程(" + PCBs(ReadyLists(Runnings.ReadyListindex).PCBindex).ProcessorName + ")的计算溢出。"
            Call DeletePCB
            Close #1
        End If
        If setLow(PSW, &HBF) Then '软件完成时的中断
            Open "Result.txt" For Append Access Write As #1
            Print #1, "真实世界时间" + CStr(Now) + ",进程(" + PCBs(ReadyLists(Runnings.ReadyListindex).PCBindex).ProcessorName + ")的执行结果:" + CStr(Data)
            Call DeletePCB
            Close #1
        End If
        Call RlistTime
        Call DlistTime
    Timm.Enabled = True
    MemC.GoOn
    CpuZ.Start
End Sub

Private Sub CpuZ_StartDevice(ByVal TimeData As Byte, ByVal DeviceNo As Byte)
    CpuZ.Halt
    MemC.Halt
    Timm.Enabled = False
        'MsgBox "需要申请的设备使用时间为" + CStr(TimeData) + "申请设备号为" + CStr(DeviceNo), vbOKOnly + vbExclamation, "Waring"
        Dim i As Byte
        i = 0
        While ((Not (Devicelists(i).DeviceID = DeviceNo)) And i < 5)
            i = i + 1
        Wend
        If i < 5 Then
            If Devicelists(i).Used Then
                ReadyLists(Runnings.ReadyListindex).Halt = True
                ReadyLists(Runnings.ReadyListindex).NeedDevice_indexOfDevicelist = i
                ReadyLists(Runnings.ReadyListindex).NeedDevice_timeOfDevice = TimeData
                Call timeInterruptProc
            Else
                Devicelists(i).ReadyListindex = Runnings.ReadyListindex
                Devicelists(i).Used = True
                'Call timeInterruptProc
                VD(i).Runtime = TimeData
                VD(i).RunDevice
            End If
        End If
        Call DlistTime
    Timm.Enabled = True
    MemC.GoOn
    CpuZ.Start
End Sub

Private Sub StartDevice(ByVal Readlistindex As Byte) 'ByVal TimeData As Byte, ByVal DeviceNo As Byte, ByVal Readlistindex As Byte)
    CpuZ.Halt
    MemC.Halt
    Timm.Enabled = False
    PCBs(Readlistindex).CPUregPC = PCBs(Readlistindex).CPUregPC - 2
    Timm.Enabled = True
    MemC.GoOn
    CpuZ.Start
End Sub


Private Sub DMATimer_Timer()
    If TimerLock Then
        TimerLock = False
        Call MemC.WriteData(DMAV.MemAdd + DMAV.DMATimerCount, HD.ReadData(DMAV.HDAdd + DMAV.DMATimerCount))
        Dim TempIndex As Integer
        TempIndex = Showindex(DMAV.HDAdd + DMAV.DMATimerCount)
        Call Pen.Draw(TempIndex, RGB(0, 255, 0))
        If HDreadoldAdd <> TempIndex Then
            PenRefreshIndex (HDreadoldAdd)
            HDreadoldAdd = TempIndex
        End If
        DiskPicture.Refresh
        DMAV.DMATimerCount = DMAV.DMATimerCount + 1
        If DMAV.DMATimerCount = DMAV.DMACOUNT Then
            PenRefreshIndex (HDreadoldAdd)
            DMATimer.Enabled = False
            MemC.GoOn
            If Option1.Value Then Timm.Enabled = True
        End If
        TimerLock = True

    End If
End Sub

Private Function DeviceIDtoDevicelistIndex(ID As Byte) As Byte
    Dim i As Integer
    i = 0
    While ((Not (Devicelists(i).DeviceID = ID)) And i < 5)
        i = i + 1
    Wend
    DeviceIDtoDevicelistIndex = i
End Function

'*******************************************************
'以下为操作系统的函数
'*******************************************************

Private Sub FileOS(ByVal index As Byte, ByVal Switch As Boolean)
    If Switch Then
        If index = 0 Or index = 3 Or index = 4 Or index = 5 Or index = 6 Then
            Runcode(1).Enabled = True
            Runcode(2).Enabled = True
            Runcode(8).Enabled = True
            Runcode(9).Enabled = True
        End If
        
        If index = 8 Then
            Runcode(0).Enabled = True
            Runcode(1).Enabled = True
            Runcode(2).Enabled = True
            Runcode(3).Enabled = True
            Runcode(4).Enabled = True
            Runcode(5).Enabled = True
            Runcode(6).Enabled = True
            Runcode(7).Enabled = True
            Runcode(9).Enabled = True
            Runcode(10).Enabled = True
            Runcode(11).Enabled = True
        End If
        If index = 9 Then
            Runcode(0).Enabled = True
            Runcode(1).Enabled = True
            Runcode(2).Enabled = True
            Runcode(3).Enabled = True
            Runcode(4).Enabled = True
            Runcode(5).Enabled = True
            Runcode(6).Enabled = True
            Runcode(7).Enabled = True
            Runcode(8).Enabled = True
            Runcode(10).Enabled = True
            Runcode(11).Enabled = True
        End If

        If index = 7 Then
            Runcode(10).Enabled = True
            Runcode(11).Enabled = True
        End If
    
        If index = 10 Or index = 11 Then
            Runcode(1).Enabled = True
            Runcode(2).Enabled = True
            Runcode(7).Enabled = True
            Runcode(8).Enabled = True
            Runcode(9).Enabled = True
        End If
        If index = 1 Or index = 2 Then
            Runcode(0).Enabled = True
            Runcode(9).Enabled = True
            Runcode(3).Enabled = True
            Runcode(4).Enabled = True
            Runcode(5).Enabled = True
            Runcode(6).Enabled = True
            Runcode(7).Enabled = True
            Runcode(8).Enabled = True
            Runcode(10).Enabled = True
            Runcode(11).Enabled = True
        End If
        
    Else
        If index = 0 Or index = 3 Or index = 4 Or index = 5 Or index = 6 Then
            Runcode(1).Enabled = False
            Runcode(2).Enabled = False
            Runcode(8).Enabled = False
            Runcode(9).Enabled = False
        End If
        If index = 8 Then
            Runcode(0).Enabled = False
            Runcode(1).Enabled = False
            Runcode(2).Enabled = False
            Runcode(3).Enabled = False
            Runcode(4).Enabled = False
            Runcode(5).Enabled = False
            Runcode(6).Enabled = False
            Runcode(7).Enabled = False
            Runcode(9).Enabled = False
            Runcode(10).Enabled = False
            Runcode(11).Enabled = False
        End If
        If index = 7 Then
            Runcode(1).Enabled = False
            Runcode(2).Enabled = False
            Runcode(8).Enabled = False
            Runcode(9).Enabled = False
            Runcode(10).Enabled = False
            Runcode(11).Enabled = False
        End If
    
        If index = 10 Or index = 11 Then
            Runcode(1).Enabled = False
            Runcode(2).Enabled = False
            Runcode(7).Enabled = False
            Runcode(8).Enabled = False
            Runcode(9).Enabled = False
        End If
        If index = 9 Then
            Runcode(0).Enabled = False
            Runcode(1).Enabled = False
            Runcode(2).Enabled = False
            Runcode(3).Enabled = False
            Runcode(4).Enabled = False
            Runcode(5).Enabled = False
            Runcode(6).Enabled = False
            Runcode(7).Enabled = False
            Runcode(8).Enabled = False
            Runcode(10).Enabled = False
            Runcode(11).Enabled = False
        End If
        If index = 1 Or index = 2 Then
            Runcode(0).Enabled = False
            Runcode(9).Enabled = False
            Runcode(3).Enabled = False
            Runcode(4).Enabled = False
            Runcode(5).Enabled = False
            Runcode(6).Enabled = False
            Runcode(7).Enabled = False
            Runcode(8).Enabled = False
            Runcode(10).Enabled = False
            Runcode(11).Enabled = False
        End If
    End If
End Sub
Private Function FindNextReadylistIndex(ByVal index As Byte) As Byte
    Dim i As Byte
    For i = 0 To 9
        index = index + 1
        If index = 11 Then index = 1
        If ReadyLists(index).Presence And ReadyLists(index).Halt = False Then
            FindNextReadylistIndex = index
            Exit Function
        End If
    Next
    FindNextReadylistIndex = &H0
End Function

Private Function DeviceRunCompleteInterrupt(ByVal Data As Byte) As Boolean 'no.1
    Dim index As Integer
    Dim j As Integer
    Dim tData As Byte
    
    tData = setLow(Data, &HFE) '1号机器
    If tData Then
        index = DeviceIDtoDevicelistIndex(tData)
        If Devicelists(index).Used Then
            Devicelists(index).Used = False
            Devicelists(index).ReadyListindex = 255
            For j = 1 To 10
                If ReadyLists(j).NeedDevice_indexOfDevicelist = index Then
                    ReadyLists(j).Halt = False
                    ReadyLists(j).NeedDevice_indexOfDevicelist = 255
                    Call StartDevice(j) 'ReadyLists(j).NeedDevice_timeOfDevice, Devicelists(index).DeviceID, j)
                End If
            Next j
        End If
    End If
    
    tData = setLow(Data, &HFD) '2号机器
    If tData Then
        index = DeviceIDtoDevicelistIndex(tData)
        If Devicelists(index).Used Then
            Devicelists(index).Used = False
            Devicelists(index).ReadyListindex = 255
            For j = 1 To 10
                If ReadyLists(j).NeedDevice_indexOfDevicelist = index Then
                    ReadyLists(j).Halt = False
                    ReadyLists(j).NeedDevice_indexOfDevicelist = 255
                    Call StartDevice(j) 'ReadyLists(j).NeedDevice_timeOfDevice, Devicelists(index).DeviceID, j)
                End If
            Next j
        End If
    End If
    
    tData = setLow(Data, &HFB) '3号机器
    If tData Then
        index = DeviceIDtoDevicelistIndex(tData)
        If Devicelists(index).Used Then
            Devicelists(index).Used = False
            Devicelists(index).ReadyListindex = 255
            For j = 1 To 10
                If ReadyLists(j).NeedDevice_indexOfDevicelist = index Then
                    ReadyLists(j).Halt = False
                    ReadyLists(j).NeedDevice_indexOfDevicelist = 255
                    Call StartDevice(j) 'ReadyLists(j).NeedDevice_timeOfDevice, Devicelists(index).DeviceID, j)
                End If
            Next j
        End If
    End If
    
    tData = setLow(Data, &HF7) '4号机器
    If tData Then
        index = DeviceIDtoDevicelistIndex(tData)
        If Devicelists(index).Used Then
            Devicelists(index).Used = False
            Devicelists(index).ReadyListindex = 255
            For j = 1 To 10
                If ReadyLists(j).NeedDevice_indexOfDevicelist = index Then
                    ReadyLists(j).Halt = False
                    ReadyLists(j).NeedDevice_indexOfDevicelist = 255
                    Call StartDevice(j) 'ReadyLists(j).NeedDevice_timeOfDevice, Devicelists(index).DeviceID, j)
                End If
            Next j
        End If
    End If
    
    tData = setLow(Data, &HEF) '5号机器
    If tData Then
        index = DeviceIDtoDevicelistIndex(tData)
        If Devicelists(index).Used Then
            Devicelists(index).Used = False
            Devicelists(index).ReadyListindex = 255
            For j = 1 To 10
                If ReadyLists(j).NeedDevice_indexOfDevicelist = index Then
                    ReadyLists(j).Halt = False
                    ReadyLists(j).NeedDevice_indexOfDevicelist = 255
                    Call StartDevice(j) 'ReadyLists(j).NeedDevice_timeOfDevice, Devicelists(index).DeviceID, j)
                End If
            Next j
        End If
    End If

End Function

Private Function timeInterruptProc() As Boolean 'no.3
    Dim ReadlistNowindex As Byte
    Dim ReadlistNextindex As Byte
    If Runnings.ReadyListCount Then
    '!=0
        ReadlistNowindex = Runnings.ReadyListindex
        ReadlistNextindex = FindNextReadylistIndex(ReadlistNowindex)
        
        PCBs(ReadlistNowindex).CPUregIR = CpuZ.IR
        PCBs(ReadlistNowindex).CPUregDR = CpuZ.DR
        PCBs(ReadlistNowindex).CPUregPC = CpuZ.PC
        PCBs(ReadlistNowindex).CPUregPSW = CpuZ.PSW
        CpuZ.IR = PCBs(ReadlistNextindex).CPUregIR
        CpuZ.DR = PCBs(ReadlistNextindex).CPUregDR
        CpuZ.PC = PCBs(ReadlistNextindex).CPUregPC
        CpuZ.PSW = PCBs(ReadlistNextindex).CPUregPSW
        Runnings.ReadyListindex = ReadlistNextindex
        timeInterruptProc = True
    Else
    '=0
        If Runnings.PCBCount Then
            MsgBox "出错了,pcb数和readlist数不一致。", vbOKOnly + vbExclamation, "注意"
            timeInterruptProc = False
        Else
            MsgBox "出错了,没有准备好的PCB和ReadList列表。", vbOKOnly + vbExclamation, "注意"
            timeInterruptProc = False
        End If
    End If
End Function

Private Function DeletePCB() As Boolean 'no.'8
    Dim Tmpindex As Byte
    Dim i As Integer
    
    
    Tmpindex = ReadyLists(Runnings.ReadyListindex).PCBindex
    
    'Call timeInterruptProc
    
    With PCBs(Tmpindex)
        .Presence = False
    End With
    Runnings.PCBCount = Runnings.PCBCount - 1
    
    With ReadyLists(Runnings.ReadyListindex)
        .Presence = False
        .Halt = False
    End With
    Runnings.ReadyListCount = Runnings.ReadyListCount - 1
    
    'Runnings.ReadyListindex = FindNextReadylistIndex(Runnings.ReadyListindex) '?用得着么?
    Call timeInterruptProc
    
    For i = PCBs(Tmpindex).MemStartAdd To PCBs(Tmpindex).MemEndAdd
        Call MemC.WriteData(i, 0)
    Next
    Runcode(PCBs(Tmpindex).ProcessorID).Enabled = True
    Call FileOS(PCBs(Tmpindex).ProcessorID, True)
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -