 
*  ED:/PEXSD    40 col        Jul / 16 / 93
 
*  LOAD/SAVE Module Utility
*----------------------------
*  Subroutines for VDP access
 
*  Clear VDP buffer
*------------------
 
VINIT  EQU  $
       MOV  @PABBAD,R9        Target current PAB buffer
       B    @VFILH            Do it and return
 
*  Transfer record to VDP
*------------------------
 
C2V    EQU  $
       LI   R8,LINBUF         Write from LINBUF to PAB buffer
       ABS  @LFLAG            Include line #s ?
       JEQ  C2V10             No
LINSTT EQU  $+2
       LI   R8,LINBF0         Set after line # in LINBUF
C2V10  MOV  @PABBAD,R9        Buffer in PAB
       BLWP @SETVDW
       LI   R9,80
       B    @VMBW10
 
 
*  SD switch code
*----------------
 
SD01   EQU  $
DRCODE LI   R6,SDATA
DRCODF LI   R9,SDATV          VDP storage
       LI   R8,SDATA          CPU location in text buffer
 
*  Byte for byte swap code   V <--> C
*-------------------------------------
*  Code returns to DRCODF or alternate
*   with R6 loaded with continuation.
 
SWLOOP BL   @SETRDA           VDP read
       STWP R10               Load pointer to R0
       AI   R10,26            Advance to R13
       LI   R11,VDPRD         Byte saver
       MOVB *R11,*R10+        Fetch byte
       MOVB *R11,*R10+        Fetch another byte
       MOVB *R11,*R10+        And so on
       MOVB *R11,*R10+
       MOVB *R11,*R10+
       MOVB *R11,*R10         Fills R13 - R15
       BL   @SETWDA           Now set VDP write
       ANDI R9,>3FFF          Mask back
       LI   R11,VDPWD         Byte saver
       MOVB *R8+,*R11         CPU RAM byte to VDP
       MOVB *R8+,*R11         Another
       MOVB *R8+,*R11         CPU RAM byte to VDP
       MOVB *R8+,*R11
       MOVB *R8+,*R11
       MOVB *R8,*R11          8 bytes worth
       AI   R8,-5             back up pointer
       MOV  R13,*R8+          And the others
       MOV  R14,*R8+
       MOV  R15,*R8+
       AI   R9,6              Advance to next block
       CI   R9,SDVEND         End of SD code ?
       JL   SWLOOP            More to go
       B    *R6               Branch to code
 
 
 
*  More L/S/P subroutines
*---------------------------------
*  Initialize flags for Save/Print
*---------------------------------
 
INIFLA EQU  $
       LI   R6,UFTAB
INIFLB CLR  *R6+
       CI   R6,UFTBN
       RT
 
*--------------------------------------
*  Treat 80 chr record from text buffer
*--------------------------------------
 
TRECRD EQU  $
       MOV  R11,R13           Save return
       CLR  R15               Initialize record length
       MOV  @LINSTT,@BUFADR   Set up buffer address for GETLiNe
       C    @LINENO,@NUM2     End of save ?
       JH   TREC99            Yes, quit
 
       BLWP @GETLN            Get line
       MOV  R0,R0             Error?
       JNE  TREC99            Yes, probably EoF
 
*  Eliminate trailing blanks
 
       MOV  @LINENO,R9
       BL   @LNDISP
       LI   R14,80            Scan line for last blank.
       ABS  @FFLAG            Fixed 80?
       JNE  TREC20            Yes - no check for length
 
TREC10 CB   @LNBFM1(R14),@DSPACE  Trailing blank ?
       JNE  TREC20            No - quit search
 
       DEC  R14               Back one char
       JNE  TREC10            Some left still
 
       INC  R14               Blank line - give it 1 blank
 
*  Strip control characters
 
TREC20 ABS  @CFLAG            Strip out control?
       JEQ  TREC50            No
 
       MOV  R14,R6            Yes, get count
TREC30 CB   @LNBFM1(R6),@DSPACE  Control ?
       JGT  TREC40            No
 
       MOVB @DSPACE,@LNBFM1(R6)   Replace with space
TREC40 DEC  R6                Back 1 char
       JGT  TREC30            Some left
 
*  Add line #s ?
 
TREC50 ABS  @LFLAG            Line #s flagged
       JEQ  TREC60            No
 
       AI   R14,6             Add 6 to length
       CI   R14,80            Too long ?
       JLT  TREC60            No
 
       LI   R14,80            Truncate record length then
TREC60 MOV  R14,R15           For MSDOS DF/128
       SWPB R14               Adjust count in PAB
       INCT R13               Step over EoF return
TREC99 AI   R15,LINBUF        Leaves pointing to end of record
       B    *R13
 
 
*------------------------------------
*  Construct and write out TAB record
*------------------------------------
 
CONWTB EQU  $
       MOV  R11,R15
       BL   @MOVE             Fetch Tab list
       DATA TABBUV            VDP storage
       DATA LINBUF,66         3 sets worth
       MOVB @MASK80,R11       Set bitmask
       LI   R6,66             Tab records
       MOV  R6,R10            Copy length
       ABS  @TABTYP           Is it USA tabs ?
       JEQ  CONW10            No
 
       CLR  R11               Clear bitmask
       INC  R6                For shuffle
 
*  Misk or shuffle
 
CONW10 MOVB @LNBFM1(R10),@LNBFM1(R6)
       SOCB R11,@LNBFM1(R6)
       DEC  R6                Previous target byte
       DEC  R10               Previous source byte
       JGT  CONW10            loop on it
 
       SWPB R6                Remainder to MSB
       MOV  R6,R14            Null if USA, >0100 if Euro
       JEQ  CONW20            Must be USA
 
*  Write out TAB record as last one
 
       MOVB @BFC,@LINBUF      Euro tab record flag
CONW20 AI   R14,>4200         TAB record length
       B    @WRECE            Write out record
 
 
 
*  Program file loader for Help & Exit
*-------------------------------------
 
LPROGF EQU  $
       LI   R9,VDPPAB+9       Load for DSR
LPROGR MOV  R9,@SCNAME        Also
       BLWP @TWDSLK           Call DSR
       DATA 8
       JEQ  LPROGG            Failure - back up
       AI   R9,-8             Check error return
       BLWP @SETVDR           Get byte with flags
       MOVB @VDPRD,R9         To CPU register
       SRL  R9,13             Check error bits
       JNE  LPROGG            Failure - back up
       INCT R11               Step over failure return
LPROGG RT
 
 
*  Help file loader
*------------------
 
HELDR  EQU  $
       MOV  @INXADR,R15       Get name index pointer
HLP30  BL   @VMBWD            PAB to VDP
       DATA VDPPAB,PABHLD,>20
       BL   @LPROGF           Load program file
       JMP  HLP70             Failure
HLP40  BLWP @SCANKY           Check keyboard to force raise
       SZCB @ANTI20,@GPLST    Same key ?
       JEQ  HLP40             No
 
       BL   @KWAIT            Key loop
       JMP  HLP50             <key>
       B    @CMDXIT           Exit
 
HLP50  BL   @CNVLC            Convert to UC
       CB   *R8,@UCA          Advance one ?
       JNE  HLP60             Check next
       AB   @ONE,*R15         Advance pointer
       JMP  HLP30             Try to load it
HLP60  CB   *R8,@ASCQ         Back one ?
       JNE  HLP40             Loop on key
HLP70  CB   *R15,@UCA         Already far enough ?
       JLE  HLP40             Yes
       SB   @ONE,*R15         Back up
       JMP  HLP30             Load it
 
*------------------------------------------------------
 
