  Function ProcessInstruction()

        If GoFlag = 1 Then
            Valid = False

            'Seek(1, ProgramCounter + 1)
            'FileGet(1, Instruction1)
            'FileGet(1, Instruction2)
            Instruction1 = FileByteCode(ProgramCounter)
            Instruction2 = FileByteCode((ProgramCounter) + 1)


            Instruction = Instruction1
            Instruction = (Instruction << 8) + Instruction2

            ProgramCounter = ProgramCounter + 2
            If DelayTimer > 0 Then
                DelayTimer = DelayTimer - 1
            End If
            'check for instruction recognition

            If (Instruction And &HFFFF) = &HEE Then   '00EE
                StackCounter = StackCounter - 1
                ProgramCounter = Stack(StackCounter)
                Valid = True
            End If

            If (Instruction And &HF000) = &H1000 Then '1NNN
                ProgramCounter = (Instruction And &HFFF) - &H200
                Valid = True

            End If

            If (Instruction And &HF000) = &H2000 Then '2NNN
                Stack(StackCounter) = ProgramCounter
                ProgramCounter = (Instruction And &HFFF) - &H200
                StackCounter = StackCounter + 1
                Valid = True

            End If

            If (Instruction And &HF000) = &H3000 Then '3NNN
                Valid = True
                If Vary(Instruction1 And &HF) = Instruction2 Then
                    ProgramCounter = ProgramCounter + 2
                End If
            End If

            If (Instruction And &HF000) = &H4000 Then '4XNN
                If Vary(Instruction1 And &HF) <> Instruction2 Then
                    ProgramCounter = ProgramCounter + 2
                End If
                Valid = True

            End If

            If (Instruction And &HF000) = &H6000 Then      '6xxx
                Vary((Instruction1 And &HF)) = (Instruction2)         'vX = NN
                Valid = True
            End If

            If (Instruction And &HF000) = &H7000 Then '7XNN
                Valid = True
                Vary(Instruction1 And &HF) = Vary(Instruction1 And &HF) + Instruction2
                If Vary(Instruction1 And &HF) > 255 Then
                    Vary(Instruction1 And &HF) = Vary(Instruction1 And &HF) - 256

                End If

            End If

            If (Instruction And &HF00F) = &H8000 Then '8XY0
                Valid = True
                Vary(Instruction1 And &HF) = Vary((Instruction2 And &HF0) >> 4)

            End If

            If (Instruction And &HF00F) = &H8002 Then '8XY2
                Valid = True
                Vary(Instruction1 And &HF) = Vary(Instruction1 And &HF) And Vary((Instruction2 And &HF0) >> 4)
            End If

            If (Instruction And &HF00F) = &H8003 Then '8XY3
                Vary(Instruction1 And &HF) = Vary(Instruction1 And &HF) Xor Vary((Instruction2 And &HF0) >> 4)
                Valid = True

            End If

            If (Instruction And &HF00F) = &H8004 Then '8XY4
                Dim number As Short
                number = Vary(Instruction1 And &HF) + Vary((Instruction2 And &HF0) >> 4)
                If number > 255 Then
                    number = number - 256
                    Vary(15) = 1
                Else
                    Vary(15) = 0
                End If
                Vary(Instruction1 And &HF) = number
                Valid = True

            End If

            If (Instruction And &HF00F) = &H8005 Then '8XY5
                Dim number As Short
                number = Vary(Instruction1 And &HF) - Vary((Instruction2 And &HF0) >> 4)
                If number < 0 Then
                    number = number + 256
                    Vary(15) = 0
                Else
                    Vary(15) = 1
                End If
                Vary(Instruction1 And &HF) = number
                Valid = True
            End If

            If (Instruction And &HF000) = &HA000 Then 'ANNN
                I = (Instruction And &HFFF) - &H200
                Valid = True
            End If

            If (Instruction And &HF000) = &HC000 Then 'CXNN
                Vary(Instruction1 And &HF) = CInt(Int(((Instruction2) - 0 + 1) * Rnd() + 0))
                Valid = True

            End If

            If (Instruction And &HF000) = &HD000 Then 'DXYN
                Dim x
                Dim y
                Dim n
                Dim SpriteLine As Byte
                Dim flag = 0
                x = Vary(Instruction1 And &HF)
                y = Vary((Instruction2 And &HF0) >> 4)
                n = (Instruction2 And &HF)
                Dim Ydraw = 0
                Dim Xdraw = 0
                While Ydraw < n

                    If I = 65535 Then
                        SpriteLine = FontCode(FontCharacter * 5 + Ydraw)
                    Else
                        Seek(1, I + 1 + Ydraw)
                        FileGet(1, SpriteLine)
                    End If

                    While Xdraw < 8

                        If (SpriteLine And (128 / (2 ^ Xdraw))) Then
                            If (x + Xdraw + (y + Ydraw) * 64) < 2048 Then


                                If ScreenBuffer(x + Xdraw + (y + Ydraw) * 64) = &H0 Then
                                    ScreenBuffer(x + Xdraw + (y + Ydraw) * 64) = &HFFFFFF
                                    'If x + Xdraw < 64 Then
                                    'screenBitmap.SetPixel(x + Xdraw, y + Ydraw, Color.White)
                                    'End If

                                Else
                                    ScreenBuffer(x + Xdraw + (y + Ydraw) * 64) = &H0
                                    'If x + Xdraw < 64 Then
                                    '    screenBitmap.SetPixel(x + Xdraw, y + Ydraw, Color.Black)
                                    'End If
                                    flag = 1
                                End If

                            End If

                        End If

                        Xdraw = Xdraw + 1
                    End While
                    Xdraw = 0
                    Ydraw = Ydraw + 1
                End While

                Vary(&HF) = flag


                Valid = True

                DrawScreen()

            End If

            If (Instruction And &HF0FF) = &HE0A1 Then 'EXA1
                If CurrentKey <> Vary(Instruction1 And &HF) Then
                    ProgramCounter = ProgramCounter + 2
                End If
                Valid = True

            End If


            If (Instruction And &HF0FF) = &HF007 Then 'FX07
                Valid = True
                Vary(Instruction1 And &HF) = DelayTimer

            End If



            If (Instruction And &HF0FF) = &HF015 Then 'FX15
                Valid = True
                DelayTimer = Vary(Instruction1 And &HF)

            End If

            If (Instruction And &HF0FF) = &HF018 Then 'FX18
                SoundTimer = Vary(Instruction And &HF)
                Valid = True

            End If

            If (Instruction And &HF0FF) = &HF01E Then
                I = I + Vary(Instruction1 And &HF)
                Valid = True

            End If

            If (Instruction And &HF0FF) = &HF029 Then 'FX29
                Valid = True
                I = 65535
                FontCharacter = Vary(Instruction1 And &HF)

            End If

            If (Instruction And &HF0FF) = &HF033 Then 'FX33
                Dim number As Byte
                number = Vary(Instruction1 And &HF)
                FileByteCode(I) = CInt(Fix(number / 100))
                FileByteCode(I + 1) = CInt(Fix((number - (FileByteCode(I) * 100)) / 10))
                FileByteCode(I + 2) = CInt(Fix(number - FileByteCode(I) * 100 - FileByteCode(I + 1) * 10))

                Valid = True

            End If


            If (Instruction And &HF0FF) = &HF065 Then ' FX65
                Valid = True
                Dim counter = 0
                Dim runner As Byte = (Instruction1 And &HF)
                While counter < runner + 1
                    Vary(counter) = FileByteCode(I + counter)
                    counter = counter + 1
                End While

            End If



            'UpdateV()

            UpdateKeys()








        End If

        If Valid = False And GoFlag = 1 Then

            GoFlag = 0
            ProgramTimer.Enabled = False
            MsgBox("Error! Unhandled Opcode: " + Hex(Instruction), MsgBoxStyle.OKOnly, "Oh No!")

        End If



    End Function