
 1000  *---------------------------------
 1010  *  EDIT COMMAND FOR S-C ASSEMBLER II VERSION 4.0
 1020  *
 1030  *      WRITTEN BY MIKE LAUMER
 1040  *                 DECEMBER 6, 1980
 1050  *---------------------------------
 1060         .OR $0800
 1070         .TF B.EDIT2
 1080  *---------------------------------
 1090  *  SYSTEM EQUATES
 1100  *---------------------------------
 1110  MON.COUT   .EQ $FDED
 1120  MON.BELL   .EQ $FF3A
 1130  MON.RDKEY  .EQ $FD0C
 1140  MON.CLREOP .EQ $FC42
 1150  MON.VTAB   .EQ $FC22
 1160  CH     .EQ $24
 1170  CV     .EQ $25
 1180  DOS.REENTRY .EQ $03D0
 1190  *---------------------------------
 1200  *  ASSEMBLER EQUATES
 1210  *---------------------------------
 1220  GNL    .EQ $1026
 1230  NML    .EQ $1063
 1240  PLNO   .EQ $1779
 1250  GNB    .EQ $12C5
 1260  DOIT   .EQ $1874
 1270  SEARCH .EQ $164B
 1280  SERTXT .EQ $14F6
 1290  SERNXT .EQ $14FE
 1300  NTKN   .EQ $12AF
 1310  A0L    .EQ $3A,3B
 1320  A1L    .EQ $3C,3D
 1330  SRCP   .EQ $DD,DE
 1340  WBUF   .EQ $0200
 1350  CURRENT.LINE.NUMBER .EQ $D3,D4
 1360  *---------------------------------
 1370  *  ENTRY POINT FOR BRUN.  ACTIVATES
 1380  *  THE USR ASSEMBLER COMMAND.
 1390  *---------------------------------
 1400  ENTRY  LDA #EDIT
 1410         STA $1007    PATCH ASM USR COMMAND
 1420         LDA /EDIT
 1430         STA $1008
 1440         LDA #$60     PATCH NML TO MAKE IT
 1450         STA $1125        A SUBROUTINE
 1460         LDA #$4C
 1470         STA NML
 1480         STA $1078
 1490         LDA #NEW.NML
 1500         STA NML+1
 1510         LDA /NEW.NML
 1520         STA NML+2
 1530         JMP DOS.REENTRY
 1540  *---------------------------------
 1550  *  PATCH ROUTINES FOR ASSEMBLER
 1560  *---------------------------------
 1570  NEW.NML JSR MY.NML
 1580         JMP GNL
 1590  MY.NML LDY #0
 1600         JSR $128D
 1610         JSR $114A
 1620         JMP $1066
 1630  *---------------------------------
 1640  *  LOCAL VARIABLES FOR EDIT COMMAND
 1650  *---------------------------------
 1660  NEXT   .DA 0
 1670  END    .DA 0
 1680  CHAR   .DA #0
 1690  EDPTR  .DA #0
 1700  FKEY   .DA #0
 1710  *---------------------------------
 1720  EDIT   DEX
 1730         DEX
 1740         BMI .2       NO ARGUMENTS
 1750         BEQ .4       1 ARGUMENT
 1760         JSR .3       2 ARGUMENTS
 1770         LDX #A1L     FIND END PTR
 1780         JSR SERNXT
 1790         LDA $E6
 1800         STA END
 1810         LDA $E7
 1820         STA END+1
 1830  .1     LDA NEXT+1
 1840         STA SRCP+1
 1850         PHA
 1860         LDA NEXT
 1870         STA SRCP
 1880         CMP END
 1890         PLA
 1900         SBC END+1    PAST END LINE?
 1910         BCS .2       YES, EXIT
 1920         JSR E.LIST   NO, LIST AND EDIT
 1930         JMP .1       TRY FOR NEXT LINE
 1940  .3     LDX #A0L     FIND START PTR
 1950         JSR SERTXT
 1960         LDA $E4
 1970         STA SRCP
 1980         STA NEXT     SAVE NEXT LINE ADRS
 1990         LDA $E5
 2000         STA SRCP+1
 2010         STA NEXT+1
 2020  .2     RTS
 2030  .4     JSR .3       SEARCH FOR LINE
 2040         BCC .2       NOT FOUND EXIT
 2050  E.LIST JSR E.POSN   POSITION FOR EDIT
 2060         JSR MON.CLREOP  PREPARE DISPLAY
 2070         JSR GNB      GET LINE SIZE
 2080         CLC
 2090         ADC NEXT     COMPUTE NEXT LINE ADRS
 2100         STA NEXT
 2110         TYA
 2120         ADC NEXT+1
 2130         STA NEXT+1
 2140         JSR GNB      GET LINE NUMBER FOR DISPLAY
 2150         STA CURRENT.LINE.NUMBER
 2160         JSR GNB
 2170         STA CURRENT.LINE.NUMBER+1
 2180         SEC
 2190         ROR $F8      STUFF WBUF FLAG
 2200         JSR PLNO
 2210         LSR $F8      TURN OFF FLAG
 2220         LDA #$20     SPACE AFTER LINE #
 2230         LDX #0
 2240  .1     STX EDPTR
 2250         ORA #$80     FORCE VIDEO BIT
 2260         STA WBUF+4,X STORE INTO INPUT BUFFER
 2270         CMP #$A0     TEST FOR CONTROL CHAR
 2280         BCS .2       OK, IF NOT 
 2290         AND #$7F     OUTPUT INVERSE ALPHA
 2300  .2     JSR MON.COUT PRINT CHAR
 2310         JSR NTKN     GET NEXT TOKEN
 2320         LDX EDPTR
 2330         INX
 2340         CMP #0       END TOKEN?
 2350         BNE .1       NO, PRINT IT
 2360         STA WBUF+4,X YES, PUT IT IN TOO
 2370  E.LINE LDX #0
 2380  E.0    STX EDPTR
 2390  E.1    JSR E.INPUT  GET INPUT CHAR
 2400  E.2    LDA #EDTB
 2410         STA $2
 2420         LDA /EDTB
 2430         STA $3
 2440         LDA #CHAR
 2450         STA $12
 2460         LDA /CHAR
 2470         STA $13
 2480         JSR SEARCH   SEARCH EDIT COMMAND TABLE
 2490         BNE .2       NOT IN TABLE
 2500         LDX EDPTR
 2510         JSR DOIT     EXECUTE COMMAND ROUTINE
 2520         BCC E.0      NO DISPLAY ON RETURN
 2530         BCS .5       DISPLAY ON RETURN
 2540  .2     LDX EDPTR    MUST BE TYPE OVER
 2550         LDA CHAR
 2560         CMP #$A0
 2570         BCS .4
 2580  .3     JSR MON.BELL ERR IF CONTROL KEY
 2590         JMP E.1
 2600  .4     LDA WBUF+5,X SEE IF END OF LINE
 2610         BNE .6       TYPE OVER IF NOT
 2620         STA WBUF+6,X SHIFT OVER END OF LINE
 2630  .6     LDA CHAR     STUFF CHAR INTO BUFFER
 2640         STA WBUF+5,X
 2650         CPX #256-5-2 TEST BUFFER SIZE
 2660         BEQ .5       TYPE OVER LAST CHAR IN BUFFER
 2670         INX          INSTEAD OF BUFFER END
 2680  .5     JSR E.DISP   DISPLAY LINE
 2690         JMP E.0      GET NEXT EDIT COMMAND
 2700  *---------------------------------
 2710  E.POSN LDA #19      POSITION TO LINE 19,
 2720         STA CV
 2730         LDA #0       COLUMN 0
 2740         STA CH
 2750         JMP MON.VTAB
 2760  *---------------------------------
 2770  E.DISP STX EDPTR
 2780         JSR E.POSN   POSITION DISPLAY
 2790         LDX #$FF
 2800  .1     INX
 2810         LDA WBUF,X   GET BUFFER CHAR
 2820         BEQ .3       END OF BUFFER
 2830         CMP #$A0     CONTROL CHAR?
 2840         BCS .2       NO
 2850         AND #$7F     PRINT INVERSE ALPHA
 2860  .2     JSR MON.COUT PRINT CHAR
 2870         JMP .1       NEXT CHAR
 2880  .3     JSR MON.CLREOP CLEAN ANY REMAINING SCREEN
 2890         LDX EDPTR
 2900         RTS
 2910  *---------------------------------
 2920  E.BEG  LDX #0   SET CURSOR TO BEGINNING OF LINE
 2930         CLC
 2940         RTS
 2950  *---------------------------------
 2960  E.DEL  LDA WBUF+5,X IS THIS THEN END OF
 2970         BEQ .2
 2980  .1     INX
 2990         LDA WBUF+5,X SHIFT TO LOWER MEMORY
 3000         STA WBUF+4,X TO DELETE CHAR
 3010         BNE .1
 3020         LDX EDPTR
 3030  .2     SEC          RETURN WITH DISPLAY
 3040         RTS
 3050  *---------------------------------
 3060  E.END  LDA WBUF+5,X END OF BUFFER?
 3070         BEQ .1       YES
 3080         INX          NO
 3090         BNE E.END    TRY END AGAIN
 3100  .1     CLC          RETURN NO DISPLAY
 3110         RTS
 3120  *---------------------------------
 3130  E.FIND LDA WBUF+5,X END OF BUFFER?
 3140         BNE .2       NO
 3150  .1     STA FKEY     YES SO ERR
 3160         JSR MON.BELL RING BELL
 3170         CLC          RETURN NO DISPLAY
 3180         RTS
 3190  .2     JSR E.INPUT  GET 1 CHAR
 3200         STA FKEY     SAVE KEY TO LOCATE
 3210  .3     INX
 3220         LDA WBUF+5,X TEST BUFFER
 3230         BEQ .1       END OF BUFFER
 3240         CMP FKEY     NO, SEE IF KEY
 3250         BNE .3       NO, GO FORWARD
 3260         JSR E.INPUT  TRY ANOTHER KEY
 3270         CMP FKEY     SAME CHAR?
 3280         BEQ .3       YES, SEARCH AGAIN
 3290         PLA
 3300         PLA
 3310         STX EDPTR    NO, EXIT POINTING HERE
 3320         JMP E.2
 3330  *---------------------------------
 3340  E.BKSP TXA          AT BEGINNING?
 3350         BEQ .1       YES, STAY THERE
 3360         DEX          BACKUP
 3370  .1     CLC          RETURN NO DISPLAY
 3380         RTS
 3390  *---------------------------------
 3400  E.OVR  JSR E.INPUT  READ CHAR
 3410         JMP E.INS1   SKIP CONTROL CHECK
 3420  *---------------------------------
 3430  E.INS  JSR E.INPUT  READ CHAR
 3440         CMP #$A0     CONTROL CHAR POPS USER OUT
 3450         BCC E.INS2   OF INSERT
 3460  E.INS1 CPX #256-5-2 END OF BLOCK
 3470         BEQ .1       YES STAY THERE
 3480         INX
 3490  .1     STX EDPTR
 3500  .2     PHA          CHAR TO INSERT
 3510         LDA WBUF+4,X SAVE CHAR TO MOVE
 3520         TAY
 3530         PLA          GET CHAR TO INSERT
 3540         STA WBUF+4,X PUT OVER SAVED CHAR
 3550         INX
 3560         TYA          INSERT SAVED CHAR
 3570         BNE .2       IF NOT BUFFER END
 3580         STA WBUF+4,X STUFF END CODE
 3590         STA WBUF+256-5-1  INSURE A  END CODE
 3600         LDX EDPTR
 3610         JSR E.DISP   DISPLAY LINE
 3620         JMP E.INS    GET NEXT INSERT CHAR
 3630  E.INS2 PLA          SEND CHAR TO
 3640         PLA          COMMAND SEARCH
 3650         LDX EDPTR
 3660  *---------------------------------
 3670         JMP E.2
 3680  E.RETQ LDA #0       CLEAR REST OF LINE
 3690         STA WBUF+5,X
 3700         JSR E.DISP   DISPLAY LINE
 3710  E.RET  LDX #$FF     SUBMIT LINE TO ASSEMBLER
 3720  .1     INX          COMPUTE LINE SIZE
 3730         LDA WBUF,X
 3740         BNE .1
 3750         DEX
 3760  .2     STX $E1      SAVE SIZE
 3770         PLA
 3780         PLA
 3790         JMP MY.NML   SUBMIT THE LINE
 3800  *---------------------------------
 3810  E.TAB  CPX #20      < COL 20?
 3820         BCS .1       NO
 3830         LDA WBUF+5,X END OF BUFFER?
 3840         BEQ .1       YES
 3850         INX          MOVE FORWARD
 3860         CPX #7       TAB MATCH?
 3870         BEQ .1
 3880         CPX #11      TAB MATCH?
 3890         BNE E.TAB
 3900  .1     CLC          RETURN WITHOUT DISPLAY
 3910         RTS
 3920  *---------------------------------
 3930  E.RIT  LDA WBUF+5,X END OF BUFFER
 3940         BNE .1       NO
 3950         STA WBUF+6,X
 3960         LDA #$A0     PUT A BLANK
 3970         STA WBUF+5,X TO EXTEND LINE
 3980         CPX #256-5-2
 3990         BEQ .2
 4000  .1     INX          MOVE AHEAD
 4010  .2     CLC          RETURN NO DISPLAY
 4020         RTS
 4030  *---------------------------------
 4040  E.ABORT LDA #$DC    OUTPUT BACKSLASH
 4050         STA WBUF+5
 4060         LDA #0
 4070         STA WBUF+6
 4080         JSR E.DISP   SHOW CANCEL
 4090         JMP GNL      GET NEXT COMMAND
 4100  *---------------------------------
 4110  E.INPUT LDA #19
 4120         STA CV
 4130         TXA          POSITION TO CURSOR
 4140         CLC
 4150         ADC #5
 4160  .1     CMP #40      THIS LINE?
 4170         BCC .2       YES
 4180         SEC
 4190         SBC #40
 4200         INC CV       ON NEXT LINE
 4210         BNE .1
 4220  .2     STA CH
 4230         JSR MON.VTAB SET BASL
 4240         JSR MON.RDKEY INPUT A CHAR
 4250         STA CHAR
 4260         RTS
 4270  *---------------------------------
 4280  *  COMMAND TABLE
 4290  *---------------------------------
 4300  EDTB   .DA #3,#1    ITEM SIZE, KEY SIZE
 4310   .DA #$82,E.BEG-1   ^B
 4320   .DA #$84,E.DEL-1   ^D
 4330   .DA #$85,E.END-1   ^E
 4340   .DA #$86,E.FIND-1  ^F
 4350   .DA #$88,E.BKSP-1  ^H
 4360   .DA #$89,E.INS-1   ^I
 4370   .DA #$8D,E.RET-1   ^M
 4380   .DA #$8F,E.OVR-1   ^O
 4390   .DA #$91,E.RETQ-1  ^Q
 4400   .DA #$94,E.TAB-1   ^T
 4410   .DA #$95,E.RIT-1   ^U
 4420   .DA #$98,E.ABORT-1 ^X
 4430   .DA #0

