home *** CD-ROM | disk | FTP | other *** search
- ;if.asm
- ;=========================
- ; Batch File Command...IF
- ;=========================
-
- ; if [not] errorlevel value command
- ; if [not] exist d:name command
- ; if [not] string1 == string2 command
-
- runmod = $007f
- stk = $1be8
- stk1 = $1bd1
- shellf = $1bd8
- imain = $0302
- int0e = $170e
- int22 = $1722
- errlvl = $1be0
- lpsave = $1bc5 ; LOOP saves exec address here
- primm = $ff7d
-
-
- star = $0b00
- .wor star
- * = star
-
- jmp main
- dw Date
-
- not .byt 0 ; $ff=not, 0=not not
- p1 .byt 0 ; 1st parameter (1 if not isn't there, else 2)
-
- notif lda #0
- jmp $170e
-
- main lda #0 ; default not=false and parameter=1
- sta not
- ldx #1 ; check for %1
- stx p1
- jsr $1704
- ntf0 bcs notif ; just if by itself. BASIC would give syntax error
- cmp #"n" ; check if %1 is 'not'
- bne notnot
- jsr $1705
- bcs notnot
- cmp #"o"
- bne notnot
- jsr $1705
- bcs notnot
- cmp #"t"
- bne notnot
- jsr $1705
- bcc notnot
- dec not
- inc p1
- notnot ldx p1 ; check for 'errorlevel' or 'exist'
- jsr $1704
- ntf1 bcs ntf0 ; no %1 "if" only or "if not" only return errorlevel 0
- cmp #"e"
- bne str1 ; string1 == string2
- jsr $1705
- bcs str1
- cmp #"x"
- beq mbex ; maybe exists
- cmp #"r"
- bne str1
- ldx #0
- mber jsr $1705
- bcs str1
- cmp errtxt,x
- bne str1
- inx
- cpx #extxt-errtxt
- bcc mber
- jsr $1705
- bcc str1
- jmp errdo
-
- errtxt .asc "rorlevel"
- extxt .asc "ist"
-
- str1 jmp strdo
-
- mbex ldx #0
- mbx jsr $1705
- bcs str1
- cmp extxt,x
- bne str1
- inx
- cpx #str1-extxt
- bcc mbx
- jsr $1705
- bcc str1
- inc p1 ; if exists
- ldx p1
- jsr $1716 ; check if it exists
- jmp mbdo ; do %p1+1 if carry=0
-
- errdo inc p1
- ldx p1
- jsr $1711
- cmp #0
- bne dont
- cpx errlvl
- bne dont
- clc
- .byt $24
- dont sec
- jmp mbdo
-
- ;----------------------------
- ; if [not] string1 = string2
- ;----------------------------
-
- strdo ldx p1 ; get string1 to $1b20
- jsr $1704
- ldx #0
- getmor sta $1b20,x
- inx
- cpx #64 ; illegal if length>64
- bcs ntf2
- jsr $1705
- bcc getmor
- inc p1 ; check if next parameter is "="
- stx len ; save length of string1
- ldx p1
- jsr $1704
- bcc str2
- ntf2 jmp basic ; not there...let basic worry about it
-
- len .byt $d0
-
- str2 cmp #"="
- bne ntf2
- jsr $1705
- bcc ntf2
- inc p1
- ldx p1
- jsr $1704 ; string2 isn't there
- bcs ntf2
- ldx #0
- str3 cmp $1b20,x ; not equal
- bne donot
- inx
- jsr $1705
- bcc str3
- cpx len
- bne donot
- clc
- .byt $24
- donot sec
- mbdo rol a ; set errorlevel to 1 if test failed
- eor not
- and #1
- beq doit
- nix jmp $170e
-
- doit inc p1 ; test passed. execute tail end of command line
- ldx p1
- jsr $1704
- bcs nix
- ldx #0
- stuff sta $0200,x
- inx
- cmp #0
- beq gotoit
- jsr $1705
- jmp stuff
-
- gotoit lda #$40
- sta shellf
- jsr runoff
- ldx stk
- txs
- jmp (imain)
-
- basic ldx stk1
- txs
- lda #$40
- sta $ff00
- runoff lda #0
- sta runmod
- rts
-
- .end
-