home *** CD-ROM | disk | FTP | other *** search
/ Multimedia & CD-ROM 3 / mmcd03-jun1995-cd.iso / utils / various / utils-1 / clrscr.asm < prev    next >
Assembly Source File  |  1991-06-24  |  10KB  |  228 lines

  1. ;****************************************************************************
  2. ; CLRSCR clears the screen or a specified region of the screen using the
  3. ; attribute specified.  Its syntax is:
  4. ;
  5. ;       CLRSCR attr [row1 col1 row2 col2]
  6. ;
  7. ; where "attr" is the attribute to be used, "row1" and "column1" are
  8. ; the row and column numbers of the upper left corner of the region to
  9. ; be cleared, and "row2" and "col2" are the row and column numbers of the
  10. ; lower right corner.  Row and column numbers are zero-based, so the upper
  11. ; left corner of the screen is 0,0.  If row and column numbers are omitted,
  12. ; the entire screen is cleared.
  13. ;****************************************************************************
  14.  
  15. code            segment
  16.                 assume  cs:code,ds:code
  17.                 org     100h
  18. begin:          jmp     short main
  19.  
  20. msg1            db      13,10,"Syntax: CLRSCR attr [row1 col1 "
  21.                 db      "row2 col2",13,10,"$"
  22. msg2            db      13,10,"Invalid parameter",13,10,"$"
  23. attr            db      ?
  24. row1            db      0
  25. col1            db      0
  26. row2            db      24
  27. col2            db      ?
  28.  
  29. ;****************************************************************************
  30. ; Procedure MAIN
  31. ;****************************************************************************
  32.  
  33. main            proc    near
  34.                 cld                             ;Clear direction flag
  35.                 mov     si,81h                  ;Point SI to command line
  36.                 call    findchar                ;Advance to first character
  37.                 jnc     parse                   ;Branch if found
  38.  
  39. error1:         mov     dx,offset msg1          ;Display error message
  40. error2:         mov     ah,09h
  41.                 int     21h
  42.                 mov     ax,4C01h                ;Exit with ERRORLEVEL=1
  43.                 int     21h
  44. ;
  45. ; Parse the command line for attribute and row and column entries.
  46. ;
  47. parse:          call    hex2bin                 ;Get attribute value and
  48.                 mov     dx,offset msg2          ;  save it
  49.                 jc      error2
  50.                 mov     attr,bl
  51.  
  52.                 call    findchar                ;Advance to next character
  53.                 jnc     readcoords              ;Branch if found
  54. ;
  55. ; Determine the coordinates for the lower left corner of the screen.
  56. ;
  57.                 mov     ah,0Fh                  ;Get the number of columns
  58.                 int     10h                     ;  displayed (minus 1)
  59.                 dec     ah
  60.                 mov     col2,ah
  61.  
  62.                 mov     ah,12h                  ;Check for an EGA with
  63.                 mov     bl,10h                  ;  video function 12H
  64.                 int     10h
  65.                 cmp     bl,10h                  ;Branch if no EGA detected
  66.                 je      clrscr
  67.                 mov     ax,40h                  ;Get number of rows from
  68.                 mov     es,ax                   ;  the BIOS Data Area
  69.                 mov     al,es:[84h]
  70.                 mov     row2,al
  71.                 jmp     short clrscr
  72. ;
  73. ; Read row and column coordinates from the command line
  74. ;
  75. readcoords:     call    asc2bin                 ;Read "row1" parameter
  76.                 mov     dx,offset msg2
  77.                 jc      error2
  78.                 mov     row1,al
  79.                 call    findchar
  80.                 jc      error1
  81.  
  82.                 call    asc2bin                 ;Read "col1" parameter
  83.                 mov     dx,offset msg2
  84.                 jc      error2
  85.                 mov     col1,al
  86.                 call    findchar
  87.                 jc      error1
  88.  
  89.                 call    asc2bin                 ;Read "row2" parameter
  90.                 mov     dx,offset msg2
  91.                 jc      error2
  92.                 mov     row2,al
  93.                 call    findchar
  94.                 jc      error1
  95.  
  96.                 call    asc2bin                 ;Read "col2" parameter
  97.                 mov     dx,offset msg2
  98.                 jc      error2
  99.                 mov     col2,al
  100. ;
  101. ; Clear the region.
  102. ;
  103. clrscr:         mov     ax,0600h                ;Use DOS function 06H
  104.                 mov     bh,attr                 ;BH = attribute
  105.                 mov     ch,row1                 ;CH = upper left row
  106.                 mov     cl,col1                 ;CL = upper left column
  107.                 mov     dh,row2                 ;DH = lower right row
  108.                 mov     dl,col2                 ;DL = lower right column
  109.                 int     10h                     ;Do it
  110.  
  111.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  112.                 int     21h
  113. main            endp
  114.  
  115. ;****************************************************************************
  116. ; FINDCHAR advances SI to the next non-space or non-comma character.
  117. ; On return, carry set indicates EOL was encountered.
  118. ;****************************************************************************
  119.  
  120. findchar        proc    near
  121.                 lodsb                           ;Get the next character
  122.                 cmp     al,20h                  ;Loop if space
  123.                 je      findchar
  124.                 cmp     al,2Ch                  ;Loop if comma
  125.                 je      findchar
  126.                 dec     si                      ;Point SI to the character
  127.                 cmp     al,0Dh                  ;Exit with carry set if end
  128.                 je      eol                     ;  of line is reached
  129.  
  130.                 clc                             ;Clear carry and exit
  131.                 ret
  132.  
  133. eol:            stc                             ;Set carry and exit
  134.                 ret
  135. findchar        endp
  136.  
  137. ;****************************************************************************
  138. ; HEX2BIN converts a hex number entered in ASCII form into a binary
  139. ; value in BL.  Carry set on return indicates that an error occurred in
  140. ; the conversion.
  141. ;****************************************************************************
  142.  
  143. hex2bin         proc    near
  144.                 sub     ah,ah                   ;Initialize registers
  145.                 sub     bx,bx
  146.  
  147. h2b_loop:       lodsb                           ;Get a character
  148.                 cmp     al,20h                  ;Exit if space
  149.                 je      h2b_exit
  150.                 cmp     al,2Ch                  ;Exit if comma
  151.                 je      h2b_exit
  152.                 cmp     al,0Dh                  ;Exit if carriage return
  153.                 je      h2b_exit
  154.  
  155.                 cmp     al,"0"                  ;Check for digits "0"
  156.                 jb      h2b_error               ;  through "9"
  157.                 cmp     al,"9"
  158.                 ja      h2b2
  159.  
  160.                 sub     al,30h                  ;ASCII => binary
  161. h2b1:           mov     cl,4                    ;Multiply BX by 16 and
  162.                 shl     bx,cl                   ;  add the latest
  163.                 add     bx,ax                   ;  digit
  164.                 cmp     bx,255                  ;Error if sum > 255
  165.                 ja      h2b_error
  166.                 jmp     h2b_loop                ;Loop back for more
  167.  
  168. h2b2:           and     al,0DFh                 ;Capitalize the letter
  169.                 cmp     al,"A"                  ;Check range and exit if
  170.                 jb      h2b_error               ;  not "A" through "F"
  171.                 cmp     al,"F"
  172.                 ja      h2b_error               
  173.                 sub     al,37h                  ;ASCII => binary
  174.                 jmp     h2b1                    ;Finish and loop back
  175.  
  176. h2b_error:      dec     si                      ;Set carry and exit
  177.                 stc
  178.                 ret
  179.  
  180. h2b_exit:       dec     si                      ;Clear carry and exit
  181.                 clc
  182.                 ret
  183. hex2bin         endp
  184.  
  185. ;****************************************************************************
  186. ; ASC2BIN converts a decimal number entered in ASCII form into a binary
  187. ; value in AL.  Carry set on return indicates that an error occurred in
  188. ; the conversion.
  189. ;****************************************************************************
  190.  
  191. asc2bin         proc    near
  192.                 sub     ax,ax                   ;Initialize registers
  193.                 sub     bh,bh
  194.                 mov     dl,10
  195.  
  196. a2b_loop:       mov     bl,[si]                 ;Get a character
  197.                 inc     si
  198.                 cmp     bl,20h                  ;Exit if space
  199.                 je      a2b_exit
  200.                 cmp     bl,2Ch                  ;Exit if comma
  201.                 je      a2b_exit
  202.                 cmp     bl,0Dh                  ;Exit if carriage return
  203.                 je      a2b_exit
  204.  
  205.                 cmp     bl,"0"                  ;Error if character is not
  206.                 jb      a2b_error               ;  a number
  207.                 cmp     bl,"9"
  208.                 ja      a2b_error
  209.  
  210.                 mul     dl                      ;Multiply the value in AL by
  211.                 jc      a2b_error               ;  10 and exit on overflow
  212.                 sub     bl,30h                  ;ASCII => binary
  213.                 add     ax,bx                   ;Add latest value to AX
  214.                 cmp     ax,255                  ;Error if sum > 255
  215.                 jna     a2b_loop                ;Loop back for more
  216.  
  217. a2b_error:      dec     si                      ;Set carry and exit
  218.                 stc
  219.                 ret
  220.  
  221. a2b_exit:       dec     si                      ;Clear carry and exit
  222.                 clc
  223.                 ret
  224. asc2bin         endp
  225.  
  226. code            ends
  227.                 end     begin
  228.