!pr1
Allow BSAVE to New Non-Binary Files in BASIC.SYSTEM 1.1
                                ................Mark Jackson
                                           Chicago, Illinois

I consider it a bug:  BASIC.SYSTEM doesn't allow BSAVEing to a new file unless the type is binary.  Yet it is equally desirable to be able to BSAVE to non-binary files without first CREATEing them.

I discovered this problem while implementing FIG-FORTH in ProDOS when I wanted to save the data blocks using as little code as possible, and at the same time allow use of standard text-file word processors.

BSAVEing would solve the code length problem, but to make a text file I would have had to CREATE the file first, thus decreasing speed and increasing code length.  Therefore I looked for the BSAVE code inside BASIC.SYSTEM to fix the bug.

As it comes from Apple, BASIC.SYSTEM's parser puts the specified type in $BE6A and then the BSAVE processor places it there again.  I used the space this redundant code took for my patch.

There seems to be no good reason for Apple to purposely prevent BSAVEing to new non-binary files, so I think my patch is both worthwhile and safe.

The following applies only to Apple's BASIC.SYSTEM version 1.1, which is the latest as far as I know.  The addresses shown are the actual running position.  If you want to patch the SYS file by BLOADing at A$2000, then addresses $ADxx will be at $37xx and addresses $AExx will be at $38xx.

The following is in the CREATE code.

Now is:

     AD41- A9 0F    LDA #$0F     DEFAULT SYS FILE
     AD43- 8D 6A BE STA $BE6A    PUT IN GLOBAL PAGE

Change to:

     AD41- A2 0F    LDX #$0F
     AD43- 8E 6A BE STX $BE6A

The following is in the BSAVE code, and is only reached if it is a new file:

Now is:

     ADF5- A9 06    LDA #$06     ASSUME TYPE IS BIN
     ADF7- 8D 6A BE STA $BE6A    PUT IN GLOBAL PAGE
     ADFA- 8D B8 BE STA $BEB8    SET-FILE-INFO LIST
     ADFD- AD 56 BE LDA $BE56    CHECK IF TYPE GIVEN
     AE00- 29 04    AND #$04
     AE02- D0 0E    BNE $AE12    IF YES, THEN ERROR
     AE04- 20 46 AD JSR $AD46    CREATE NEW FILE

Change to:

     ADF5- AE 6A BE LDX $BE6A    FILE TYPE FROM PARSING
     ADF8- AD 56 BE LDA $BE56    CHECK IF TYPE GIVEN
     ADFB- 29 04    AND #$04
     ADFD- D0 02    BNE $AE01    IF YES SKIP DEFAULT
     ADFF- A2 06    LDX #$06     DEFAULT BIN FILE
     AE01- 8E B8 BE STX $BEB8    SET-FILE-INFO LIST
     AE04- 20 43 AD JSR $AD43    GO CREATE FILE

Thanks to Don Worth and Pieter Lechner for their help in dis-assembling, through their book "Supplement to Beneath Apple ProDOS."  (This is the book you get by sending in $10 and a coupon from Beneath Apple ProDOS.)
