* *``````````````````````````````* * SUBDEL :: DELETE SUBSTRING * *- -* * DELETE A SUBSTRING FROM A * * STRING. * *- -* * CLOBBERS: * * * * FLAGS: ????---- REG: AXYM * *- -* * CYCLES: ??? * * SIZE: * *- -* * USAGE: * * * * LDA #>STR ; STRING ADDRESS * * PHA * * LDA # 255 STA :SIDX ; SAVE INDEX + COUNT AS ; THE SOURCE INDEX TAX ; X = INDEX + COUNT DEX CPX :S1LEN BCC :CNTOK ; BR IF IND + CNT - 1 ; < __S1LEN ; ELSE JUST TRUNC STRING BEQ :TRUNC ; TRUNC BUT NO ERROR-- ; EXACTLY ENOUGH CHARS LDA #$0FF STA :SCERR ; INDICATE ERROR - NOT ; ENOUGH CHARS TO DELETE * ** TRUNCATE THE STRING - NO COMPACTING NECESSARY * :TRUNC LDX :SINDEX ; STRING LENGTH = ; START INDEX - 1 DEX STX :S1LEN LDA :SCERR BEQ :OKEXIT BNE :ERREXIT * ** DELETE THE SUBSTRING BY COMPACTING ** MOVE ALL CHARS ABOVE THE DELETED AREA DOWN * :CNTOK * ** CALCULATE NUMBER OF CHARS TO MOVE ** (SLEN - SIDX + 1) * LDA :S1LEN ; GET STR LENGTH SEC SBC :SIDX ; SUBTRACT START INDEX TAX INX BEQ :OKEXIT ; ADD 1 TO INCLUDE LAST ; CHAR; BR IF CNT = 0 :MVLP LDY :SIDX LDA (ADDR1),Y ; GET NEXT CHAR LDY :SINDEX STA (ADDR1),Y ;MOVE IT DOWN INC :SINDEX INC :SIDX ; INC DEST, SRC INDEXES DEX BNE :MVLP ; CONT UNTIL CNT = 0 LDX :SINDEX DEX ; START LENGTH = FINAL ; DEST INDEX -1 STX :S1LEN * ** GOOD EXIT * :OKEXIT CLC BCC :EXIT :ERREXIT SEC * :EXIT LDA :S1LEN LDY #0 STA (ADDR1),Y ; SET LENGTH OF STRING RTS * ** DATA * :S1LEN DS 1 :SCNT DS 1 :SINDEX DS 1 :SIDX DS 1 :SCERR DS 1 *