home *** CD-ROM | disk | FTP | other *** search
- ; find.asm
- ;----------------------------------
- ; Command: find/text/,range
- ;----------------------------------
-
-
- poker = $0016
- z61 = $0061
- runmod = $007f
- txtptr = $003d
- ierror = $0300
- chrget = $0380
- chrgot = $0386
-
- int04 = $1704
- int05 = $1705
- int0e = $170e
- stk0 = $1be7 ; CS-DOS 'main' saves stack pointer here
- tx = $1bfe ; Text/Basic mode flag
-
- linget = $50a0
- fndlin = $5064
-
- chrout = $ffd2
- stop = $ffe1
-
- star = $0b00
- .wor star
- * = star
-
- jmp find
- dw Date
-
- find lda ierror ;save ierror vector
- sta svie
- lda ierror+1
- sta svie+1
- lda #<chng ;and make a new one for now
- sta ierror
- lda #>chng
- sta ierror+1
- ldx stk0 ;recall stack at "lookup"
- txs
- lda #$40
- sta $ff00
- rts ;and return to main
-
- svie .wor 0
-
- ;-------------------------------
- ; adjust for text or basic mode
- ;-------------------------------
-
- adj bit tx ;basic mode?
- bmi adj0 ;no text. un-crunch the line
- rts
-
- adj0 ldx #0 ;copy command line back to input buffer
- jsr int04
- adj1 sta $0200,x
- inx
- jsr int05
- cmp #0
- bne adj1
- sta $0200,x
- rts
-
- ;-------------------
- ; ierror jumps here
- ;-------------------
-
- chng lda #0 ;bank 15
- sta $ff00
- sta runmod
- lda svie ;restore old error vector
- sta ierror
- lda svie+1
- sta ierror+1
- jsr adj ;adjust buf if text mode
- lda #<$01ff ;setup chrget
- sta txtptr
- lda #>$01ff
- sta txtptr+1
- fc jsr chrget ;1st non-alpha char is the delimiter
- cmp #"a"
- bcc gotdel ;got it
- cmp #"z"+1
- bcc fc
- gotdel sta delim ;save it
- ldx #0
- jsr gettxt ;get replace text
- jsr chrget ;move past closing delimiter
- beq ch1 ;no range
- cmp #","
- beq ch11
- jmp snerr
-
- ch11 jsr chrget
- ch1 jsr range ;get range
- jsr b15
- lda #13
- jsr chrout
- jmp za32a
-
- za31f iny ;bump past eol marker (0)
- tya
- clc
- adc z61
- sta z61
- bcc za32a
- inc z61+1
- za32a jsr peek ;get link high
- beq fini ;end of text...quit
- jsr stop ;stop key?
- beq fini ;yep
- jsr za431 ;test if line lower than max
- bcs za337 ;it is. test it
- fini jmp int0e ;otherwise all done
-
- za337 sty offset ;.y=0 (offset into text portion of line)
- za339 inc offset
- ldy offset ;offset into current line being tested
- ldx strend ;offset into buf for search string
- lda strend+1 ;length of search string
- sta sofs
- za343 jsr pk ;get from line
- beq za31f ;end of line. text not found
- cmp $0200,x ;same as search string?
- bne za339 ;no. move up through source line
- inx
- iny
- dec sofs
- bne za343 ;still more chars to check
- dey ;found text. save offset to end+1
- sty delim
- sty zb5
- ldx thslin
- lda thslin+1
- ldy #0
- jsr $5125
- jsr b15
- lda #13
- jsr chrout
- ldy zb5
- jmp za337
-
- ;-------------------------------------
- ; get search or replace text from buf
- ;-------------------------------------
-
- gettxt ldy txtptr
- iny
- tya
- sta strend ;offset to start of text
- lda #0
- sta strend+1 ;initialize length to zero
- gt0 lda $0200,y
- beq mbs
- cmp delim
- beq gtx
- inc strend+1 ;bump length
- iny
- bne gt0
- gtx sty txtptr ;done
- rts
-
- mbs sty txtptr
- pla
- pla
- jsr chrgot
- jmp ch1
-
- ;----------------
- ; get line range
- ;----------------
-
- range bcc r0 ;chrget got a number
- beq r0
- cmp #"-"
- beq r0
- snerr ldx #11
- jmp (ierror)
-
- r0 jsr linget ;get first line number
- jsr fndlin ;find where it is in text area (z61)
- jsr chrgot ;is it start-end?
- beq r1 ;no. just start
- cmp #"-"
- bne snerr
- jsr chrget
- jsr linget
- bne snerr
- r1 lda poker
- ora poker+1
- bne r3
- lda #$ff
- sta poker
- sta poker+1
- r3 jmp b15
-
- za431 jsr peek
- sta thslin
- jsr peek
- sta thslin+1
- sec
- lda poker
- sbc thslin
- lda poker+1
- sbc thslin+1
- rts
-
- ;----------------
- ; peek text area
- ;----------------
-
- peek inc z61
- bne pk0
- inc z61+1
- pk0 ldy #0
- pk sta $ff01
- lda (z61),y
- b15 pha
- lda #$00
- sta $ff00
- pla
- rts
-
- strend *=*+2 ;offset,length for search & replace text
- thslin *=*+2 ;temp. store current line number
- offset *=*+1 ;current offset into line
- sofs *=*+1 ;copy of source string offset into buf
- delim *=*+1
- zb5 *=*+1
-
- .end
-