' Binary file operations: OPEN BINARY, GET#, PUT#, SEEK, LOC, LOF, EOF
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL buffer AS STRING
    LOCAL val  AS LONG
    LOCAL fLen  AS LONG
    LOCAL fPos  AS LONG
    LOCAL fEof  AS LONG
    LOCAL fLoc  AS LONG
    buffer = CHR$(65) + CHR$(66) + CHR$(67) + CHR$(68)

    OPEN "test_bin.dat" FOR BINARY AS #1
        PUT #1, 1, buffer
        fLen = LOF(1)
        PRINT "File length after write:"; fLen
    CLOSE #1

    OPEN "test_bin.dat" FOR BINARY AS #1
        fLen = LOF(1)
        PRINT "File length (LOF):"; fLen
        GET #1, 1, buffer
        PRINT "First byte:"; ASC(MID$(buffer,  1, 1))
        fPos = LOC(1)
        PRINT "Current position (LOC):"; fPos
        fEof = EOF(1)
        PRINT "EOF status:"; fEof
        SEEK #1, 1
        fLoc = LOC(1)
        PRINT "After SEEK, LOC:"; fLoc
    CLOSE #1

    KILL "test_bin.dat"
    PRINT "Binary file test complete."

    FUNCTION = 0
END FUNCTION
