*``````````````````````````````*
* BINSAVE ::       BINARY SAVE *
*-                            -*
* SIMPLY DOES A BINARY SAVE    *
* WITH THE COMMAND LINE PARAMS *
* SPECIFIED IN THE STRING AT   *
* THE GIVEN ADDRESS.           *
*-                            -*
* CLOBBERS:                    *
*                              *
* FLAGS:  ????----  REG: AXYM  *
*-                            -*
* CYCLES: ???                  *
* SIZE:                        *
*-                            -*
* USAGE:                       *
*                              *
*  LDA #>SADDR ; STRING ADDR   *
*  PHA                         *
*  LDA #<SADDR                 *
*  PHA                         *
*  JSR BINSAVE                 *
*-                            -*
* ENTRY                        *
*                              *
* TOP OF STACK                 *
*                              *
* LOW BYTE OF RETURN ADDRESS   *
* HI BYTE OF RETURN ADDRESS    *
* LO BYTE OF STRING ADDRESS    *
* HI BYTE OF STRING ADDRESS    *
*-                            -*
* EXIT                         *
*                              *
* TOP OF STACK                 *
*                              *
* LOW BYTE OF RETURN ADDRESS   *
* HI BYTE OF RETURN ADDRESS    *
*                              *
* .Y = UNCHANGED               *
* .X = UNCHANGED               *
* .A = CLOBBERED; TRASH        *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
BINSAVE
*
** GET RETURN ADDRESS
*
         PLA
         STA   RETADR
         PLA
         STA   RETADR+1
*
** GET PARAMETERS
*
         PLA
         STA   ADDR2      ; CMD STRING ADDR
         PLA
         STA   ADDR2+1
*
*
** FIRST, TELL DOS TO GO INTO APPLESOFT MODE
*
         LDA   #1
         STA   $AAB6      ; DOS LANG FLAG
         STA   $75+1      ; NOT IN DIRECT MODE
         STA   $33        ; NOT IN DIRECT MODE
*
********************************
*
*  ERROR CONTROL
*
********************************
*
         LDA   ERRCTRL
         CMP   #1
         BEQ   :CHKERR0
         JMP   :ERREND
:CHKERR0
*
** NOW TURN ON ONERR
*
         LDA   #$FF ; TURN ON LOCAL ERR HANDLING
         STA   $D8
*
** NOW SET ONERR ADDR TO :CHKERR ROUTINE
*
         LDA   #<:CHKERR
         STA   $9D5A      ; DOS ERROR HANDLING ADDR
         LDA   #>:CHKERR
         STA   $9D5B
         JMP   :ERREND
:CHKERR
         LDY   #0
         STY   $D8        ; RESUME NORMAL ERROR CTRL
         _ERR  #:E_SID;#:E_MSG;#:E_DUMP;#ADDR2;#2
         BRK
*
********************************
*
:ERREND
*
********************************
*
         LDA   #$8D
         JSR   FCOUT
         LDA   #$84       ; CTRL-D
         JSR   FCOUT
         LDA   #$C2       ; B
         JSR   FCOUT
         LDA   #$D3       ; S
         JSR   FCOUT
         LDA   #$C1       ; A
         JSR   FCOUT
         LDA   #$D6       ; V
         JSR   FCOUT
         LDA   #$C5       ; E
         JSR   FCOUT
         LDA   #$A0       ; [SPACE]
         JSR   FCOUT
*
** NOW SEND STRING TO COUT
*
         LDY   #0
         LDA   (ADDR2),Y
         STA   :SLEN
         LDY   #1
:LP
         LDA   (ADDR2),Y
         JSR   FCOUT
         INY
         CPY   :SLEN
         BCC   :LP
         BEQ   :LP
*
** NOW PRESS RETURN
*
         LDA   #$8D
         JSR   FCOUT
*
** RESTORE RETURN ADDRESS
*
         LDA   RETADR+1
         PHA
         LDA   RETADR
         PHA
*
         RTS
*
** DATA
*
:SLEN    DS    1
*
:E_SID   ASC   "BINSAVE (BSAV MACRO)",00
:E_DUMP  ASC   "DUMPING STRING ADDRESS...",00
:E_MSG   ASC   "INPUT/OUTPUT ERROR!!!",00
*
