
 1000  *--------------------------------
 1010  *      AUTOMATIC SAVE PROGRAM
 1020  *      THIS PROGRAM CHECK'S FOR A TITLE
 1030  *      AND IF ONE IS FOUND, THE CURRENT PROGRAM
 1040  *      IS SAVED UNDER THE TITLE
 1050  *      ALSO, IF THE VERSION NUMBER IS APPENDED
 1060  *      IT IS UPDATED BEFORE EACH SAVE
 1070  *--------------------------------
 1080  *      SYSTEM EQUATES
 1090  *--------------------------------
 1100  MON.COUT   .EQ $FDED
 1110  MON.CROUT  .EQ $FD8E
 1120  MON.BELL1  .EQ $FBDD
 1130  IN.BUF     .EQ $200
 1140  SRC.END    .EQ $4C,4D
 1150  SRC.START  .EQ $CA,CB
 1160  NEXT       .EQ $1D
 1170  SEARCH     .EQ $1E,1F
 1180  *--------------------------------
 1190         .OR $800
 1200         .TF AUTO.SAVE.OBJECT A$800
 1210  *--------------------------------
 1220  *      INITIALIZE SEARCH REGISTERS AND 
 1230  *      DETERMINE IF AT END OF SOURCE PROGRAM
 1240  *--------------------------------
 1250  AUTO.SAVE
 1260         LDA SRC.START     GET START OF SOURCE PROGRAM ADDRESS
 1270         STA SEARCH        AND MOVE TO THE SEARCH ADDRESS REGISTER
 1280         LDA SRC.START+1
 1290         STA SEARCH+1
 1300         CLD
 1310  ADDRESS.END.CMP
 1320         LDA SEARCH
 1330         CMP SRC.END       SEE IF AT END OF SOURCE PROGRAM
 1340         BNE .1
 1350         LDA SEARCH+1
 1360         CMP SRC.END+1
 1370         BEQ ERROR1        DIDN'T FIND TITLE
 1380  *--------------------------------
 1390  *      SEARCH LINE FOR OP CODE
 1400  *--------------------------------
 1410  .1     LDY #0       Y OFFSET FOR LINE EXAMINATION
 1420         LDA (SEARCH),Y    NEXT LINE OFFSET
 1430         STA NEXT
 1440         LDY #3       POINT TO CHARACTER AFTER LINE NUMBER
 1450         LDA (SEARCH),Y
 1460         CMP #'*      COMMENT LINE?
 1470         BEQ NEW.LINE      YEP
 1480  .5     CMP #$C0     COMPRESSED CODE?
 1490         BNE .2       NOPE
 1500  .4     INY          MOVE OFFSET PAST COMPRESSED INFO
 1510         INY
 1520         CLV
 1530         BVC .3       ...ALWAYS
 1540  .2     CMP #$80     SPACE(S)?
 1550         BCS OPCHK    YES, CHECK THE OP-CODE
 1560  .3     INY
 1570         LDA (SEARCH),Y
 1580         BEQ NEW.LINE      END OF LINE (EOL) IS 0
 1590         BNE .5       ...ALWAYS
 1600  *--------------------------------
 1610  *      CALCULATE ADDRESS OF NEXT LINE
 1620  *--------------------------------
 1630  NEW.LINE
 1640         CLC
 1650         LDA SEARCH   MOVE SEARCH ADDRESS TO NEXT LINE
 1660         ADC NEXT
 1670         STA SEARCH
 1680         BCC ADDRESS.END.CMP
 1690         INC SEARCH+1
 1700         BNE ADDRESS.END.CMP   ...ALWAYS
 1710  *--------------------------------
 1720  *      ERROR ROUTINES
 1730  *--------------------------------
 1740  ERROR1
 1750         LDY #0       POINT TO NO TITLE ERROR
 1760  PRTERR LDA NO.TTL,Y
 1770         BMI ERREND
 1780         ORA #$80
 1790         JSR MON.COUT
 1800         INY
 1810         BNE PRTERR
 1820  ERREND JSR MON.COUT
 1830         JSR MON.BELL1
 1840         JSR MON.BELL1
 1850         JSR MON.CROUT
 1860         RTS
 1870  ERROR2
 1880         LDY #18      POINT TO ILLEGAL CHAR. ERROR
 1890         BNE PRTERR   ...ALWAYS
 1900  *--------------------------------
 1910  *      CHECK THE OP CODE FOR .TI
 1920  *--------------------------------
 1930  OPCHK  LDX #0
 1940  .1     INY
 1950         LDA (SEARCH),Y
 1960         BEQ NEW.LINE      EOL
 1970         CMP OPS,X    COMPARE OP CODE
 1980         BNE NEW.LINE THAT'S NOT IT
 1990         INX
 2000         CPX #3       IF ALL 3 COMPARE, FOUND OP CODE
 2010         BNE .1
 2020  *--------------------------------
 2030  *      NOW LOOK FOR TITLE
 2040  *--------------------------------
 2050  TITLE  INY
 2060         LDA (SEARCH),Y
 2070         BEQ ERROR1   NO TITLE?
 2080         CMP #',      LOOKING FOR COMMA (TITLE FOLLOWS)
 2090         BNE TITLE
 2100  .1     INY
 2110         LDA (SEARCH),Y
 2120         BEQ ERROR1   NO TITLE?
 2130         CMP #$C0     COMPRESSED?
 2140         BEQ COMP.CODE1
 2150         CMP #$80     SPACE?
 2160         BCS .1       YEP--SKIP
 2170         CMP #'A      MAKE SURE 1ST CHAR. IS LETTER
 2180         BCC ERROR2   NOT LETTER
 2190         CMP #$5B     1 MORE THAN "Z"
 2200         BCS ERROR2
 2210  *--------------------------------
 2220  *      TITLE FOUND
 2230  *      OUTPUT CTRL-D, "SAVE" AND TITLE
 2240  *--------------------------------
 2250         PHA
 2260         LDX #0
 2270  .2     LDA SAVE,X
 2280         JSR MON.COUT
 2290         INX
 2300         CPX #5
 2310         BNE .2
 2320         PLA
 2330  NEXT.CHAR1     
 2340         ORA #$80
 2350         JSR MON.COUT
 2360         INX          X KEEPS TRACK OF INPUT BUFFER OFFSET
 2370  NEXT.CHAR2
 2380         INY
 2390         LDA (SEARCH),Y
 2400         BEQ GOT.TTL2 EOL--GOT THE TITLE
 2410         CMP #',      NO COMMAS ALLOWED
 2420         BNE .1
 2430         LDA #'-      REPLACE COMMA WITH DASH
 2440         BNE NEXT.CHAR1    ...ALWAYS
 2450  .1     CMP #$C0
 2460         BEQ COMP.CODE2
 2470         CMP #$80
 2480         BCC NEXT.CHAR1
 2490         INY          CHECK FOR CHARACTER AFTER SPACE
 2500         LDA (SEARCH),Y
 2510         BEQ GOT.TTL1 DROP TRAILING SPACES
 2520         DEY          MOVE POINTER BACK TO CORRECT POSITION
 2530         LDA #$20     SPACE--SPACES IN TITLE COMPRESSED TO 1
 2540         BNE NEXT.CHAR1    ...ALWAYS
 2550  *--------------------------------
 2560  *      COMPRESSED CHARACTER ROUTINES
 2570  *--------------------------------
 2580  COMP.CODE1
 2590         INY
 2600         LDA (SEARCH),Y    THIS IS NUMBER OF CHARACTERS COMPRESSED
 2610         STA NEXT
 2620         INY
 2630         LDA (SEARCH),Y    ACTUAL CHARACTER
 2640         CMP #'A      MAKE SURE IT'S A LETTER
 2650         BCC ERROR2
 2660         CMP #$5B
 2670         BCS ERROR2
 2680         PHA
 2690         LDX #0
 2700  .1     LDA SAVE,X
 2710         JSR MON.COUT
 2720         INX
 2730         CPX #5
 2740         BNE .1
 2750         PLA
 2760         BNE STORE    ...ALWAYS
 2770  COMP.CODE2
 2780         INY
 2790         LDA (SEARCH),Y
 2800         STA NEXT
 2810         INY
 2820         LDA (SEARCH),Y
 2830         CMP #',
 2840         BNE STORE
 2850         LDA #'-
 2860  STORE
 2870         ORA #$80
 2880         JSR MON.COUT
 2890         INX
 2900         DEC NEXT
 2910         BNE STORE
 2920         BEQ NEXT.CHAR2
 2930  *--------------------------------
 2940  *      SEARCH FOR VERSION NUMBER AND CHANGE IF FOUND
 2950  *--------------------------------
 2960  GOT.TTL1
 2970         DEY
 2980  GOT.TTL2
 2990         DEY          MOVE Y POINTER TO THIRD NON-BLANK
 3000         DEY          CHARACTER FROM THE END OF LINE
 3010         DEY
 3020         DEX
 3030         LDA (SEARCH),Y    THIRD CHAR. FROM END
 3040         CMP #'0
 3050         BCC DOS.OP
 3060         CMP #':      ASCII ":" IS 1 MORE THAN ASCII 9
 3070         BCS DOS.OP
 3080         INY
 3090         LDA (SEARCH),Y    2ND CHAR. FROM END
 3100         CMP #'.      SHOULD BE PERIOD
 3110         BNE DOS.OP
 3120         INY
 3130         LDA (SEARCH),Y    LAST CHARACTER
 3140         CMP #'0
 3150         BCC DOS.OP
 3160         CMP #':
 3170         BCS DOS.OP
 3180         ADC #1
 3190         CMP #':
 3200         BNE STORIT
 3210         LDA #'0
 3220         STA (SEARCH),Y    CHANGE DIGIT IN SOURCE CODE
 3230         ORA #$80
 3240         STA IN.BUF,X      CHANGE DIGIT IN DOS COMMAND
 3250         DEX
 3260         DEX
 3270         DEY
 3280         DEY
 3290         LDA (SEARCH),Y
 3300         CLC
 3310         ADC #1
 3320         CMP #':
 3330         BNE STORIT
 3340         LDA #'0
 3350  STORIT STA (SEARCH),Y
 3360         ORA #$80
 3370         STA IN.BUF,X
 3380  *--------------------------------
 3390  *      CR OUTPUT CAUSES DOS TO PERFORM SAVE
 3400  *      AFTERWARDS, RETURN TO ASSEMBLER
 3410  *--------------------------------
 3420  DOS.OP JSR MON.CROUT
 3430  END    RTS
 3440  *--------------------------------
 3450  *      MESSAGES
 3460  *--------------------------------
 3470  OPS    .AS /.TI/
 3480  SAVE   .HS 84       CTRL-D
 3490         .AS -/SAVE/
 3500  NO.TTL .AT /*** NO TITLE ERROR/
 3510         .AT /*** ILLEGAL TITLE FIRST CHARACTER/
 3520  ZZZEND .EQ *
 3530  ZZZLEN .EQ ZZZEND-AUTO.SAVE

