*** Example of Random-access File Routine ***
*** by Genji OKADA  12/07/86 ***
*** fixed 256 bytes buffer ***

        _recsize 256    :*** 256 bytes/record
        Integer rnd_buffer,rnd_handle
        Dim rnd_buffer(_recsize/2-1)

SubRoutine rnd_open(a)
        *** call by string a
        Integer a
        Value a :/Byte &92
        /Byte &B8,2,&3D,&CD,&21,&73,@10
        /Byte &31,&C9,&B4,&3C,&CD,&21
10      Value = rnd_handle
        Return
SubEnd

SubRoutine rnd_write(n)
        *** call by record# n
        Integer n
        Value _recsize*n
        /Byte &89,&D1,&92
        Value rnd_handle :/byte &93
        /Byte &B8,0,&42,&CD,&21
        Value Loc(rnd_buffer(0))
        /Byte &92,&B9
        /Word _recsize
        /Byte &B4,&40,&CD,&21
        Return
SubEnd

SubRoutine rnd_close
        Value rnd_handle :/byte &93
        /Byte &B4,&3E,&CD,&21
        Return
SubEnd

SubRoutine rnd_read(n)
        *** call by record# n
        Integer n
        Value _recsize*n
        /Byte &89,&D1,&92
        Value rnd_handle :/byte &93
        /Byte &B8,0,&42,&CD,&21,&72,@10
        Value Loc(rnd_buffer(0))
        /Byte &92,&B9
        /Word _recsize
        /Byte &B4,&3F,&CD,&21
        /Byte &72,@20,&39,&C8,&75,@20
10      Return

20      Print "out of data"
#e      /Byte &BF :/Word &8F
#c      /Byte &BF :/Word &18F
        /Byte &FF,&E7
SubEnd

SubRoutine str_put(d,a)
        *** call by address d and string a
        Integer d,a
        d=Loc(rnd_buffer(0))+d
10      Poke d,Peek(a)
        If !=0 Then Return
        a=a+1 :d=d+1
        GoTo 10
SubEnd

SubRoutine real_put(d,s)
        *** call by address d and real s
        Integer d,s
        /Byte &1E,&07
        Value s :/Byte &96
        Value Loc(rnd_buffer(0))+d
        /Byte &97,&B9,5,0,&FC,&F3,&A4
        Return
SubEnd

Function real_get(d)
        *** call by address d
        Integer d
        Value Loc(rnd_buffer(0))+d
        /Byte &93,&8B,&0F,&8B,&57,2
        /Byte &8A,&47,4,&C3
FnEnd

End
