                BSAVE/BLOAD Emulation
                   copyright (C) Thomas Hanlin III, 1986




     Not all BASIC compilers support BSAVE and BLOAD.  It's easy to implement
these commands in BASIC, though, if you need them.  The following routines
will provide BSAVE and BLOAD routines that are compatible with their BASICA
counterparts.  They will need to be modified slightly to fit your particular
program (line number adjustment, file number change, variable name change,
etc).  Be warned that these routines are a bit slow!  They are also not
protected against disk errors, such as "disk full" when BSAVEing.  It is
assumed that your program already has error trapping for such problems.



BSAVE:

Set FIL$ to the filename to save to, SG% to the segment, OFS% to the offset,
and LNGTH% to the length in bytes of the area to be saved.  Then execute
the following routine:

100 OPEN "O",1,FIL$: PRINT#1,CHR$(&HFD);MKI$(SG%);MKI$(OFS%);MKI$(LNGTH%);
110 FOR BSV%=OFS% TO OFS%+LNGTH%-1: PRINT#1,CHR$(PEEK(BSV%));: NEXT: CLOSE #1



BLOAD:

Set FIL$ to the filename to load, then execute the following routine.  Note
that BBAD% will be set if the file is not in BSAVE/BLOAD format.

200 OPEN "R",1,FIL$: FIELD #1,1 AS FMODE$,2 AS SG$,2 AS OFS$,2 AS LNGTH$
210 GET#1,1: IF FMODE$<>CHR$(&HFD) THEN BBAD%=-1: GOTO 250
220 BBAD%=0: SG%=CVI(SG$): OFS%=CVI(OFS$): LNGTH%=CVI(LNGTH$): CLOSE #1
230 DEF SEG=SG%: OPEN "R",1,FIL$,1: FIELD #1,1 AS CH$: GET#1,7
240 FOR BLD%=OFS% TO OFS%+LNGTH%-1: GET#1: POKE BLD%,ASC(CH$): NEXT
250 CLOSE #1

Your program should contain a line such as the following after executing the
above routine:

300 IF BBAD% THEN PRINT"*** Error: file ";FIL$;" is not in BLOAD format!"
