home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / IF.A < prev    next >
Encoding:
Text File  |  1989-12-01  |  7.0 KB  |  185 lines

  1. ;if.asm
  2. ;=========================
  3. ; Batch File Command...IF
  4. ;=========================
  5.                                   
  6. ; if [not] errorlevel value command
  7. ; if [not] exist d:name command
  8. ; if [not] string1 == string2 command
  9.                                   
  10. runmod      = $007f               
  11. stk         = $1be8               
  12. stk1        = $1bd1               
  13. shellf      = $1bd8               
  14. imain       = $0302               
  15. int0e       = $170e               
  16. int22       = $1722               
  17. errlvl      = $1be0               
  18. lpsave      = $1bc5               ; LOOP saves exec address here
  19. primm       = $ff7d               
  20.                                   
  21.                                   
  22. star        = $0b00               
  23.             .wor star             
  24.             * = star              
  25.                                   
  26.             jmp main
  27.             dw  Date
  28.                                   
  29. not         .byt 0                ; $ff=not, 0=not not
  30. p1          .byt 0                ; 1st parameter (1 if not isn't there, else 2)
  31.                                   
  32. notif       lda #0                
  33.             jmp $170e             
  34.                                   
  35. main        lda #0                ; default not=false and parameter=1
  36.             sta not               
  37.             ldx #1                ; check for %1
  38.             stx p1                
  39.             jsr $1704             
  40. ntf0        bcs notif             ; just if by itself. BASIC would give syntax error
  41.             cmp #"n"              ; check if %1 is 'not'
  42.             bne notnot            
  43.             jsr $1705             
  44.             bcs notnot            
  45.             cmp #"o"              
  46.             bne notnot            
  47.             jsr $1705             
  48.             bcs notnot            
  49.             cmp #"t"              
  50.             bne notnot            
  51.             jsr $1705             
  52.             bcc notnot            
  53.             dec not               
  54.             inc p1                
  55. notnot      ldx p1                ; check for 'errorlevel' or 'exist'
  56.             jsr $1704             
  57. ntf1        bcs ntf0              ; no %1 "if" only or "if not" only return errorlevel 0
  58.             cmp #"e"              
  59.             bne str1              ; string1 == string2
  60.             jsr $1705             
  61.             bcs str1              
  62.             cmp #"x"              
  63.             beq mbex              ; maybe exists
  64.             cmp #"r"              
  65.             bne str1              
  66.             ldx #0                
  67. mber        jsr $1705             
  68.             bcs str1              
  69.             cmp errtxt,x          
  70.             bne str1              
  71.             inx                   
  72.             cpx #extxt-errtxt     
  73.             bcc mber              
  74.             jsr $1705             
  75.             bcc str1              
  76.             jmp errdo             
  77.                                   
  78. errtxt      .asc "rorlevel"       
  79. extxt       .asc "ist"            
  80.                                   
  81. str1        jmp strdo             
  82.                                   
  83. mbex        ldx #0                
  84. mbx         jsr $1705             
  85.             bcs str1              
  86.             cmp extxt,x           
  87.             bne str1              
  88.             inx                   
  89.             cpx #str1-extxt       
  90.             bcc mbx               
  91.             jsr $1705             
  92.             bcc str1              
  93.             inc p1                ; if exists
  94.             ldx p1                
  95.             jsr $1716             ; check if it exists
  96.             jmp mbdo              ; do %p1+1 if carry=0
  97.                                   
  98. errdo       inc p1                
  99.             ldx p1                
  100.             jsr $1711             
  101.             cmp #0                
  102.             bne dont              
  103.             cpx errlvl            
  104.             bne dont              
  105.             clc                   
  106.             .byt $24              
  107. dont        sec                   
  108.             jmp mbdo              
  109.                                   
  110. ;----------------------------
  111. ; if [not] string1 = string2
  112. ;----------------------------
  113.                                   
  114. strdo       ldx p1                ; get string1 to $1b20
  115.             jsr $1704             
  116.             ldx #0                
  117. getmor      sta $1b20,x           
  118.             inx                   
  119.             cpx #64               ; illegal if length>64
  120.             bcs ntf2              
  121.             jsr $1705             
  122.             bcc getmor            
  123.             inc p1                ; check if next parameter is "="
  124.             stx len               ; save length of string1
  125.             ldx p1                
  126.             jsr $1704             
  127.             bcc str2              
  128. ntf2        jmp basic             ; not there...let basic worry about it
  129.                                   
  130. len         .byt $d0              
  131.                                   
  132. str2        cmp #"="              
  133.             bne ntf2              
  134.             jsr $1705             
  135.             bcc ntf2              
  136.             inc p1                
  137.             ldx p1                
  138.             jsr $1704             ; string2 isn't there
  139.             bcs ntf2              
  140.             ldx #0                
  141. str3        cmp $1b20,x           ; not equal
  142.             bne donot             
  143.             inx                   
  144.             jsr $1705             
  145.             bcc str3              
  146.             cpx len               
  147.             bne donot             
  148.             clc                   
  149.             .byt $24              
  150. donot       sec                   
  151. mbdo        rol a                 ; set errorlevel to 1 if test failed
  152.             eor not               
  153.             and #1                
  154.             beq doit              
  155. nix         jmp $170e             
  156.                                   
  157. doit        inc p1                ; test passed. execute tail end of command line
  158.             ldx p1                
  159.             jsr $1704             
  160.             bcs nix               
  161.             ldx #0                
  162. stuff       sta $0200,x           
  163.             inx                   
  164.             cmp #0                
  165.             beq gotoit            
  166.             jsr $1705             
  167.             jmp stuff             
  168.                                   
  169. gotoit      lda #$40              
  170.             sta shellf            
  171.             jsr runoff            
  172.             ldx stk               
  173.             txs                   
  174.             jmp (imain)           
  175.                                   
  176. basic       ldx stk1              
  177.             txs                   
  178.             lda #$40              
  179.             sta $ff00             
  180. runoff      lda #0                
  181.             sta runmod            
  182.             rts                   
  183.                                   
  184.             .end                  
  185.