        Program ORIGIN :6400

        Dim A$[0],Line$(100)
        Dim Temp$(4)

        Print "Test Binary Value conversion routines"
        Print CopyRight$

Def BVAL(BVALarg$)
        Let A$="XXXX"
        Return val(BVALarg$)
End

Def BVAL$(BVALarg)
        Let A$="YYYY"
        Return num$(BVALarg)
End

FindVAL: ! Find "XXXX" string
        For pointer=:6400 to :7000
            For i=0 to 3
                If peek(pointer+i)<>asc("X")
                then cycle pointer
            Next i
            Print "Found XXXX at ";hex$(pointer)
            Goto InstallBVAL
        Next pointer
        Print "??? can't find XXXX"
        Exit

InstallBVAL:
        For pointer=pointer to :7000
            If peek(pointer)=:7A
            Then
                Print "Found OPEXTENDED at ";hex$(pointer)
                Poke Pointer+1,:22 \ ! convert VAL opcode to BVAL opcode
                Goto FindNUM
            Fi
        Next pointer
        Print "Can't find OPEXTENDED opcode"
        Exit

FindNUM: ! Find "YYYY" string
        For pointer=:6400 to :7000
            For i=0 to 3
                If peek(pointer+i)<>asc("Y")
                then cycle pointer
            Next i
            Print "Found YYYY at ";hex$(pointer)
            Goto InstallBSTR
        Next pointer
        Print "??? can't find YYYY"
        Exit

InstallBSTR:
        For pointer=pointer to :7000
            If peek(pointer)=:7A
            Then
                Print "Found OPEXTENDED at ";hex$(pointer)
                Poke Pointer+1,:23 \ ! convert NUM$ opcode to BSTR opcode
                Goto Test
            Fi
        Next pointer
        Print "Can't find OPEXTENDED opcode"
        Exit

Test:   Print "Ready to run diagnostic."

        Repeat
             Input "Value to BVAL$: " Value
             Let Line$=BVAL$(Value)
             Print ":";
             For i=1 to len(Line$) do print hex$(Line$(i))[4,2];
             Print
        Unless Value<0 End


        Repeat
             Input "How many bytes to BVAL? " X
             Let Len(Line$)=X
             For i=1 to X
                 Print "Enter";i;"th byte: ";
                 Input "" Line$(i)
             Next i
             Print "BVAL result is:";BVAL(Line$)
        End
        Print "Diagnostic completed."
        Exit
END
