         .OUTPI ALFRES
         .ENTRY FMTBUF
         .VIRT8 OPTR

;Format_buffers allocates the input and output buffers. We use all
;the memory there is to be had.
FMTBUF   LDA $02E5   ;High memory
         SEC
         SBC #.LO.PGEND
         STA MAXBUF
         LDA $02E6
         SBC #.HI.PGEND
         STA MAXBUF+1 ;Total buffer size
         LSR MAXBUF+1 ;Split it into 2
         ROR MAXBUF ;evenly matched buffers
         LDA MAXBUF+1
         CMP #$1F
         BCC FMT001
         LDA #0
         STA MAXBUF
         LDA #$1F
         STA MAXBUF+1
FMT001   LDA #.LO.PGEND
         STA INBUFF
         LDA #.HI.PGEND
         STA INBUFF+1
         LDA #.LO.PGEND
         CLC
         ADC MAXBUF
         STA OUTBUF ;Allocate the output buffer
         STA OPTR    ;Initialize the pointer
         LDA #.HI.PGEND
         ADC MAXBUF+1
         STA OUTBUF+1
         STA OPTR+1
         RTS
