home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / slyce110.zip / RC.ASM < prev    next >
Assembly Source File  |  1989-05-13  |  9KB  |  209 lines

  1.  
  2. page          60,133
  3. %noincl
  4. include       macro.lib
  5. include       equates.lib
  6. .sall
  7. code          segment     word 'code'
  8.               assume      cs:code,ds:code,es:code
  9.               org         100H
  10. ;
  11. ;             Programmer: T. G. Browning
  12. ;
  13. Main          proc        near
  14.               mov         bx,CmdTailOffs
  15.               call        argc
  16.               cmp         ax,2
  17.               jne         ErrExit
  18.               mov         ax,0001
  19.               mov         bx,CmdTailOffs
  20.               call        argv
  21.               call        Asc2Bin
  22.               push        ax
  23.               mov         ax,0002
  24.               mov         bx,CmdTailOffs
  25.               call        argv
  26.               call        Asc2Bin
  27.               pop         dx
  28.               xchg        dh,dl
  29.               dec         dh
  30.               cmp         dh,24
  31.               jg          ErrExit
  32.               mov         dl,al
  33.               dec         dl
  34.               cmp         dl,79
  35.               jg          ErrExit
  36.               xor         bx,bx
  37.               @dos10      02H
  38. DOSOut:
  39.               @dosExit
  40. ErrExit:
  41.               mov         dx,OffSet Syntax
  42.               @dos21      09H
  43.               jmp         DOSOut
  44. Main          endp
  45. ;
  46. ;  DATA
  47. Syntax        db          'RC.COM.  Batch utility by MorganSoft.  Released to the Public Domain.',CR,LF
  48.               db          'Syntax:  rc row col.',CR,LF,'$'
  49. Bin1          dw          ?
  50. MultVal       dw          ?
  51. TenPower      db          10
  52. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  53. argc          proc        near
  54. ;
  55. ;    Count command line arguments.
  56. ;    Call with ES:BX = command line
  57. ;    Returns AX = argument count
  58. ;
  59.               Public      argc
  60.               push        bx                      ; save bx and cx
  61.               push        cx
  62.               mov         ax,0                    ; force count = 0
  63.  
  64. argc1:        mov         cx,-1                   ; set flag = outside argument
  65.  
  66. argc2:        inc         bx                      ; point to next characterf
  67.               cmp         byte ptr es:[bx],cr
  68.               je          argc3                   ; exit if carriage return
  69.               cmp         byte ptr es:[bx],blank
  70.               je          argc1                   ; outside argument if ASCII blank
  71.               cmp         byte ptr es:[bx],tab
  72.               je          argc1                   ;\ outside argument if ASCII tab
  73.  
  74.                                                   ; otherwise not blank or tab.
  75.               jcxz        argc2                   ; jump if alread inside argument
  76.  
  77.               inc         ax                      ; else found argument.  Count it
  78.               not         cx                      ; set flag = inside argument
  79.               jmp         argc2                   ; and look at next character
  80.  
  81. argc3:        pop         cx                      ; restore original bx and cx
  82.               pop         bx
  83.               ret                                 ; ax = argument count
  84.  
  85. argc          endp
  86. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  87. argv          proc        near
  88. ;
  89. ;  Get address and length of command line arguments
  90. ;  Call with ES:BX = Command line
  91. ;            AX    = Argument #
  92. ;  Returns:  ES:BX = address
  93. ;            ax    = length
  94. ;
  95.               Public      argv
  96.               push        cx                      ; save original cx,di
  97.               push        di
  98.  
  99.               or          ax,ax                   ; is it argument 0?
  100.               jz          argv8                   ;  yes, jumpt to program name
  101.  
  102.               xor         ah,ah                   ; initialize argument counter
  103.  
  104. argv1:        mov         cx,-1                   ; set flag = outside argument
  105.  
  106. argv2:        inc         bx                      ; point to next character
  107.               cmp         byte ptr es:[bx],cr
  108.               je          argv7                   ; exit if carriage return
  109.               cmp         byte ptr es:[bx],blank
  110.               je          argv1                   ; outside argument if ASCII blank
  111.               cmp         byte ptr es:[bx],tab
  112.               je          argv1                   ; outside argument if ASCII tab
  113.  
  114.                                                   ; if not blank or tab,
  115.               jcxz        argv2                   ; jump if alread inside argument
  116.  
  117.               inc         ah                      ; else count arguments found
  118.               cmp         ah,al                   ; is this the one we're looking for
  119.               je          argv4                   ; yes, go find length
  120.               not         cx                      ; no, set flag = inside argument
  121.               jmp         argv2                   ; and look at next character
  122.  
  123. argv4:                                            ; found desired argument, now
  124.                                                   ; determine the length
  125.               mov         ax,bx                   ; save param starting address
  126. argv5:
  127.               inc         bx                      ; point to next char
  128.               cmp         byte ptr es:[bx],cr
  129.               je          argv6                   ; found end if carriage return
  130.               cmp         byte ptr es:[bx],blank
  131.               je          argv6                   ; found end if space
  132.               cmp         byte ptr es:[bx],tab
  133.               jne         argv5                   ; found end if tab
  134.  
  135. argv6:        xchg        bx,ax                   ; set es:bx = argument address
  136.               sub         ax,bx                   ; and ax = argument length
  137.               jmp         argvx                   ; return to caller
  138.  
  139. argv7:        xor         ax,ax                   ; set ax = 0 argument not found
  140.               jmp         argvx                   ; return to caller
  141.  
  142. argv8:                                            ; special handling for argv = 0
  143.               mov         ax,3000H                ; check if DOS 3.0 or later
  144.               int         21H                     ; (force al= 0 in case DOS 1)
  145.               cmp         al,3
  146.               jb          argv7                   ; DOS 1 or 2, return a null string
  147.               mov         es,es:[2ch]             ; get environment segment from PSP
  148.               xor         di,di                   ; find the program name by
  149.               xor         al,al                   ; first skipping over all the
  150.               mov         cx,-1                   ; environment variables
  151.               cld
  152. argv9:
  153.               repne       scasb                   ; scan for double null (can't use
  154.               scasb                               ; stasw, might be odd addr
  155.               jne         argv9                   ; loop if it was a single null
  156.               add         di,2                    ; skip word count
  157.               mov         bx,di                   ; save program name address.
  158.               mov         cx,-1                   ; now fin its length....
  159.               repne       scasb                   ; scan for another null byte
  160.               not         cx                      ; convert CX to length
  161.               dec         cx
  162.               mov         ax,cx                   ; return length in ax
  163. argvx:                                            ; comman exit point
  164.               pop         di                      ; restore original cx and di
  165.               pop         dx
  166.               ret
  167. argv          endp
  168. ;==================================================
  169. ;   Asc2Bin:  Procedure to convert an ASCII value ;
  170. ;             to Binary.                          ;
  171. ;             Requires ax=length, bx = offset     ;
  172. ;                                                 ;
  173. ;             Returns ax: Binary Value            ;
  174. ;==================================================
  175. Asc2Bin       proc        near
  176.               push        bx
  177.               push        cx
  178.               push        dx
  179.               push        si
  180.               mov         Bin1,0
  181.               mov         MultVal,1
  182.               mov         cx,ax
  183.               mov         si,bx
  184.               add         si,cx
  185.               dec         si
  186.               xor         ax,ax
  187. A2B10:
  188.               mov         al,[si]
  189.               and         al,0FH
  190.               mul         MultVal
  191.               add         Bin1,ax
  192.               mov         ax,MultVal
  193.               mul         TenPower
  194.               mov         MultVal,ax
  195.               dec         si
  196.               loop        A2B10
  197.               mov         ax,Bin1
  198.               pop         si
  199.               pop         dx
  200.               pop         cx
  201.               pop         bx
  202.               clc
  203.               ret
  204. Asc2Bin       endp
  205.  
  206. Code          ends
  207.               end Main
  208. 
  209.