
 1000  *SAVE S.FILENAME.EDITOR
 1010  *--------------------------------
 1020  MON.YSAVE    .EQ $34
 1030  CONTROL.LINE .EQ $6D7
 1040  EDIT.BUFFER  .EQ $757
 1050  CURSOR.LINE  .EQ $7D7
 1060  MON.BELL     .EQ $FF3A
 1070  *--------------------------------
 1080  RENAME.FILE
 1090         JSR MOVE.FILE.INTO.BUFFER
 1100         LDY #$FF
 1110         STY MASK.ONE      INITIALIZE
 1120         INY
 1130         STY INPUT.MODE    VARIABLES
 1140         STY MASK.TWO
 1150         STY MASK.MODE
 1160         LDA #$DE          ^
 1170         STA CURSOR
 1180  *--------------------------------
 1190  E.START
 1200         JSR DISPLAY.EDIT.BUFFER  UPDATE DISPLAY
 1210  *                               AND GET KEYSTROKE
 1220   
 1230  REENTRY
 1240         CMP #$A0                 CONTROL?
 1250         BCS E.INPUT              NO, INPUT IT
 1260         LDA #ZERO                YES,
 1270         STA INPUT.MODE           TURN OFF INSERT
 1280         LDA #$DE                 ^
 1290         STA CURSOR
 1300         LDX #ZERO
 1310         JSR SEARCH.AND.PERFORM   GO DO SOMETHING
 1320         JMP E.START
 1330  *--------------------------------
 1340  E.INPUT
 1350         AND MASK.ONE         CONDITION
 1360         ORA MASK.TWO         CHARACTER
 1370         STA CURRENT.CHAR
 1380         BIT INPUT.MODE       INSERT OR OVERTYPE?
 1390         BPL PLACE.CHARACTER
 1400   
 1410  INSERT.CHARACTER
 1420         STY MON.YSAVE        SAVE CURSOR
 1430         LDX #29              START AT END OF BUFFER
 1440  .1     CPX MON.YSAVE        TO CURSOR YET?
 1450         BEQ PLACE.CHARACTER  YES
 1460         LDA EDIT.BUFFER-1,X  NO, MOVE CHAR UP
 1470         STA EDIT.BUFFER,X    TO MAKE HOLE
 1480         DEX                  NEXT CHAR
 1490         BPL .1            ...ALWAYS
 1500   
 1510  PLACE.CHARACTER
 1520         LDA CURRENT.CHAR
 1530         STA EDIT.BUFFER,Y
 1540         CPY #29              END OF BUFFER?
 1550         BCS .1               YES, RETURN
 1560         INY                  NO, MOVE CURSOR
 1570  .1     JMP E.START
 1580  *--------------------------------
 1590  E.OVERRIDE
 1600         PLA
 1610         PLA
 1620         LDA #$A2             SET CURSOR
 1630         STA CURSOR.LINE,Y    TO "
 1640         JSR GETKEY
 1650         JMP INSERT.CHARACTER
 1660  *--------------------------------
 1670  E.LEFT.ARROW
 1680         DEY          MOVE CURSOR LEFT
 1690         BPL .1       IF IT WENT NEGATIVE
 1700         INY          RESTORE IT TO 0
 1710  .1     RTS
 1720  *--------------------------------
 1730  E.RIGHT.ARROW
 1740         CPY #29      AT END YET?
 1750         BCS .1       YES, IGNORE
 1760         INY          NO, MOVE CURSOR RIGHT
 1770  .1     RTS
 1780  *--------------------------------
 1790  E.INSERT
 1800         LDA #$FF        TURN INSERT ON
 1810         STA INPUT.MODE
 1820         LDA #$DC        \
 1830         STA CURSOR
 1840         RTS
 1850  *--------------------------------
 1860  E.DELETE
 1870         TYA               SET X TO
 1880         TAX               CURSOR
 1890  .1     CPX #29           AT END?
 1900         BEQ .2            BRANCH IF SO
 1910         LDA EDIT.BUFFER+1,X
 1920         STA EDIT.BUFFER,X MOVE ONE CHAR
 1930         INX               NEXT
 1940         BCC .1         ...ALWAYS
 1950  .2     LDA #SPACE        PUT SPACE
 1960         STA EDIT.BUFFER,X ON END
 1970         RTS
 1980  *--------------------------------
 1990  E.BEGINNING
 2000         LDY #ZERO         ZERO CURSOR
 2010         RTS
 2020  *--------------------------------
 2030  E.END
 2040         LDY #29           START AT END OF BUFFER
 2050  .1     LDA EDIT.BUFFER,Y
 2060         CMP #SPACE        SPACE?
 2070         BNE .2            NO, WE'RE AT END OF NAME
 2080         DEY               YES, MOVE LEFT
 2090         BPL .1            AND TRY AGAIN
 2100  .2     CPY #29           STILL AT END OF BUFFER?
 2110         BEQ .3            YES, STAY THERE
 2120         INY               NO, RIGHT ONE SPACE
 2130  .3     RTS
 2140  *--------------------------------
 2150  E.RESTORE
 2160         PLA               POP A RETURN
 2170         PLA               ADDRESS AND
 2180         JMP RENAME.FILE   START OVER
 2190  *--------------------------------
 2200  E.SET.MODE
 2210         INC MASK.MODE        NEXT MODE
 2220         LDA MASK.MODE        IF MODE = 4
 2230         AND #3               MAKE IT ZERO
 2240         STA MASK.MODE
 2250         TAX                  USE MODE FOR INDEX
 2260         LDA MASK.ONE.TABLE,X AND SET
 2270         STA MASK.ONE         MASKS
 2280         LDA MASK.TWO.TABLE,X
 2290         STA MASK.TWO
 2300         RTS
 2310  *--------------------------------
 2320  E.ZAP
 2330         TYA               START AT
 2340         TAX               CURSOR
 2350         LDA #SPACE
 2360  .1     STA EDIT.BUFFER,X
 2370         INX
 2380         CPX #30           DONE?
 2390         BCC .1
 2400         RTS
 2410  *--------------------------------
 2420  E.FIND
 2430         JSR GETKEY        GET SEARCH KEY
 2440         STA SEARCH.KEY
 2450  .1     TYA
 2460         TAX
 2470  .2     INX               START AT CURSOR+1
 2480         CPX #30           END?
 2490         BCS .3            YES, NOT FOUND
 2500         LDA EDIT.BUFFER,X
 2510         CMP SEARCH.KEY    MATCH?
 2520         BNE .2            NO, NEXT X
 2530         TXA               YES, MOVE CURSOR
 2540         TAY
 2550         JSR DISPLAY.EDIT.BUFFER
 2560  *                        NEXT KEYPRESS
 2570         CMP SEARCH.KEY    SAME CHARACTER?
 2580         BEQ .1            YES, FIND IT AGAIN
 2590         PLA               NO, PULL A RETURN
 2600         PLA               ADDRESS AND GO
 2610         LDA CURRENT.CHAR
 2620         JMP REENTRY       PROCESS THIS KEY
 2630   
 2640  .3     JMP MON.BELL      RETURN THROUGH BELL
 2650  *--------------------------------
 2660  E.RETURN
 2670         JSR MOVE.BUFFER.INTO.ARRAY
 2680   
 2690  E.ESCAPE
 2700         PLA               POP ONE RETURN
 2710         PLA               ADDRESS AND RETURN
 2720         RTS               TO ARRANGING
 2730  *--------------------------------
 2740  MOVE.FILE.INTO.BUFFER
 2750         LDA ACTIVE.ELEMENT  SET
 2760         JSR POINT.TO.A      POINTER
 2770         LDY #3
 2780  .1     LDA (POINTER),Y     MOVE
 2790         STA EDIT.BUFFER-3,Y NAME
 2800         INY
 2810         CPY #$21
 2820         BCC .1
 2830         RTS
 2840  *--------------------------------
 2850  MOVE.BUFFER.INTO.ARRAY
 2860         LDA ACTIVE.ELEMENT  MAKE
 2870         JSR POINT.TO.A      POINTER
 2880         LDY #3
 2890  .1     LDA EDIT.BUFFER-3,Y MOVE
 2900         STA (POINTER),Y     NAME
 2910         INY
 2920         CPY #$21
 2930         BCC .1
 2940         RTS
 2950  *--------------------------------
 2960  DISPLAY.EDIT.BUFFER
 2970         LDA #$DD           ]
 2980         STA EDIT.BUFFER-1  LEFT END
 2990         LDA #$DB           [
 3000         STA EDIT.BUFFER+30 RIGHT END
 3010         LDX #29
 3020  .1     LDA #SPACE
 3030         STA CONTROL.LINE,X REMOVE OLD CONTROL
 3040         STA CURSOR.LINE,X  BAR AND CURSOR
 3050         LDA EDIT.BUFFER,X
 3060         CMP #$A0
 3070         BCS .2             CONTROL?
 3080         CMP #$80
 3090         BCC .2
 3100         LDA #$DF    _      YES, PUT BAR
 3110         STA CONTROL.LINE,X
 3120  .2     DEX
 3130         BPL .1
 3140         LDA CURSOR         GET CURSOR,
 3150         AND MASK.ONE       CONDITION IT,
 3160         ORA MASK.TWO
 3170         STA CURSOR.LINE,Y  AND SHOW IT
 3180  *--------------------------------
 3190  GETKEY LDA KEYBOARD
 3200         BPL GETKEY
 3210         STA KEYSTROBE
 3220         STA CURRENT.CHAR
 3230         RTS
 3240  *--------------------------------
 3250  SEARCH.AND.PERFORM.NEXT
 3260         INX                 NEXT ENTRY
 3270         INX
 3280         INX
 3290   
 3300  SEARCH.AND.PERFORM
 3310         LDA EDIT.TABLE,X    GET VALUE FROM TABLE
 3320         BEQ .1              NOT IN TABLE
 3330         CMP CURRENT.CHAR
 3340         BNE SEARCH.AND.PERFORM.NEXT
 3350  .1     LDA EDIT.TABLE+2,X  LOW BYTE OF ADDRESS
 3360         PHA
 3370         LDA EDIT.TABLE+1,X  HIGH BYTE
 3380         PHA
 3390         RTS                 GO DO IT!
 3400  *--------------------------------
 3410  EDIT.TABLE
 3420         .DA #$82,E.BEGINNING-1     ^B
 3430         .DA #$84,E.DELETE-1        ^D
 3440         .DA #$85,E.END-1           ^E
 3450         .DA #$86,E.FIND-1          ^F
 3460         .DA #$88,E.LEFT.ARROW-1   <--
 3470         .DA #$89,E.INSERT-1        ^I
 3480         .DA #$8D,E.RETURN-1    RETURN
 3490         .DA #$8F,E.OVERRIDE-1      ^O
 3500         .DA #$92,E.RESTORE-1       ^R
 3510         .DA #$93,E.SET.MODE-1      ^S
 3520         .DA #$95,E.RIGHT.ARROW-1  -->
 3530         .DA #$9A,E.ZAP-1           ^Z
 3540         .DA #$9B,E.ESCAPE-1       ESC
 3550         .DA #$00,MON.BELL-1    OTHERS
 3560  *--------------------------------
 3570  MASK.ONE.TABLE
 3580         .DA #$FF,#$3F,#$7F,#$FF
 3590   
 3600  MASK.TWO.TABLE
 3610         .DA #$00,#$00,#$40,#$20
 3620  *--------------------------------
 3630  CURRENT.CHAR .BS 1
 3640  SEARCH.KEY   .BS 1
 3650  INPUT.MODE   .BS 1 (0 OR $FF)
 3660  MASK.MODE    .BS 1 (0 TO 3)
 3670  MASK.ONE     .BS 1 (FROM TABLE ABOVE
 3680  MASK.TWO     .BS 1 (  "    "     "  )
 3690  CURSOR       .BS 1 ($DE, $DC, OR $A2)
 3700  *                  ( ^ ,  \ , OR  " )
 3710  *--------------------------------

