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

  1. ;****************************************************************************
  2. ; DRAWBOX draws a box on the screen.  Its syntax is:
  3. ;
  4. ;       DRAWBOX attr width height [style]
  5. ;
  6. ; where "attr" specifies the attribute to be used, "width" specifies the
  7. ; box width in columns, "height" specifies the height of the in rows, and
  8. ; "style" is an optional parameter that specifies whether a single or
  9. ; double-line box is to be drawn (1=single, 2=double).  If "style" is
  10. ; omitted, DRAWBOX defaults to a single-line box.  The upper left corner
  11. ; of the box is drawn at the current cursor position.  The cursor can be
  12. ; positioned with the separate SETPOS utility.
  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: DRAWBOX attr width height "
  21.                 db      "[style]",13,10,"$"
  22. msg2            db      13,10,"Invalid parameter",13,10,"$"
  23.  
  24. attr            db      ?
  25. boxwidth        db      ?,0
  26. boxheight       db      ?,0
  27.  
  28. row1            db      ?
  29. col1            db      ?
  30. row2            db      ?
  31. col2            db      ?
  32.  
  33. upleft          db      218
  34. upright         db      191
  35. loleft          db      192
  36. loright         db      217
  37. horizontal      db      196
  38. vertical        db      179
  39.  
  40. altchars        db      201,187,200,188,205,186
  41.  
  42. ;****************************************************************************
  43. ; Procedure MAIN
  44. ;****************************************************************************
  45.  
  46. main            proc    near
  47.                 cld                             ;Clear direction flag
  48.                 mov     si,81h                  ;Point SI to command line
  49.                 call    findchar                ;Advance to first character
  50.                 jnc     parse                   ;Branch if found
  51.  
  52. error1:         mov     dx,offset msg1          ;Display error message
  53. error2:         mov     ah,09h
  54.                 int     21h
  55.                 mov     ax,4C01h                ;Exit with ERRORLEVEL=1
  56.                 int     21h
  57. ;
  58. ; Parse the command line.
  59. ;
  60. parse:          call    hex2bin                 ;Read "attr"
  61.                 mov     dx,offset msg2
  62.                 jc      error2
  63.                 mov     attr,bl
  64.                 call    findchar                ;Advance to next character
  65.                 jc      error1
  66.  
  67.                 call    asc2bin                 ;Read "width"
  68.                 mov     dx,offset msg2
  69.                 jc      error2
  70.                 sub     al,2                    ;Normalize "width"
  71.                 jc      error2                  ;Error if less than 2
  72.                 mov     boxwidth,al
  73.                 call    findchar                ;Advance to next character
  74.                 jc      error1
  75.  
  76.                 call    asc2bin                 ;Read "height"
  77.                 mov     dx,offset msg2
  78.                 jc      error2
  79.                 sub     al,2                    ;Normalize "height"
  80.                 jc      error2                  ;Error if less than 2
  81.                 mov     boxheight,al
  82.                 call    findchar                ;Advance to next character
  83.                 jc      drawbox                 ;Branch if there is none
  84.  
  85.                 call    asc2bin                 ;Read "style"
  86.                 mov     dx,offset msg2
  87.                 jc      error2
  88.                 cmp     al,1                    ;Error if greater than 2
  89.                 jb      error2                  ;  or less than 1
  90.                 cmp     al,2
  91.                 ja      error2
  92.                 dec     al                      ;Branch if "style"=1
  93.                 jz      drawbox
  94.  
  95.                 mov     si,offset altchars      ;Copy alternate graphics
  96.                 mov     di,offset upleft        ;  characters to table
  97.                 mov     cx,6
  98.                 rep     movsb
  99. ;
  100. ; Draw the box.
  101. ;
  102. drawbox:        mov     ah,0Fh                  ;Get active page number
  103.                 int     10h                     ;  in BH
  104.                 mov     ah,03h                  ;Get current cursor position
  105.                 int     10h                     ;  in DH and DL
  106.  
  107.                 mov     row1,dh                 ;Compute corner coordinates
  108.                 mov     col1,dl                 ;  of box and store them
  109.                 add     dh,boxheight            ;  away
  110.                 inc     dh
  111.                 mov     row2,dh
  112.                 add     dl,boxwidth
  113.                 inc     dl
  114.                 mov     col2,dl
  115.  
  116.                 mov     ah,09h                  ;Draw upper left corner
  117.                 mov     al,upleft
  118.                 mov     bl,attr
  119.                 mov     cx,1
  120.                 int     10h
  121.  
  122.                 mov     dh,row1                 ;Draw upper horizontal
  123.                 mov     dl,col1
  124.                 inc     dl
  125.                 mov     cx,word ptr boxwidth
  126.                 call    drawhorizontal
  127.  
  128.                 mov     ah,02h                  ;Draw upper right corner
  129.                 mov     dl,col2
  130.                 int     10h
  131.                 mov     ah,09h
  132.                 mov     al,upright
  133.                 mov     cx,1
  134.                 int     10h
  135.  
  136.                 inc     dh                      ;Draw right vertical
  137.                 mov     cx,word ptr boxheight
  138.                 call    drawvertical
  139.  
  140.                 mov     ah,02h                  ;Draw lower right corner
  141.                 mov     dh,row2
  142.                 int     10h
  143.                 mov     ah,09h
  144.                 mov     al,loright
  145.                 mov     cx,1
  146.                 int     10h
  147.  
  148.                 mov     dl,col1                 ;Draw lower horizontal
  149.                 inc     dl
  150.                 mov     cx,word ptr boxwidth
  151.                 call    drawhorizontal
  152.  
  153.                 mov     ah,02h                  ;Draw lower left corner
  154.                 dec     dl
  155.                 int     10h
  156.                 mov     ah,09h
  157.                 mov     al,loleft
  158.                 mov     cx,1
  159.                 int     10h
  160.  
  161.                 mov     dh,row1                 ;Draw left vertical
  162.                 inc     dh
  163.                 mov     cx,word ptr boxheight
  164.                 call    drawvertical
  165.  
  166.                 mov     ah,02h                  ;Home the cursor
  167.                 dec     dh
  168.                 int     10h
  169.  
  170.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  171.                 int     21h
  172. main            endp
  173.  
  174. ;****************************************************************************
  175. ; DRAWHORIZONTAL draws a horizontal line at the cursor position passed in
  176. ; DH and DL.  Length is specified in CX, attribute in BL, and page number in
  177. ; BH.  The line is drawn left to right.
  178. ;****************************************************************************
  179.  
  180. drawhorizontal  proc    near
  181.                 jcxz    dh_exit                 ;Exit if length=0
  182.                 mov     ah,02h                  ;Position the cursor
  183.                 int     10h
  184.                 mov     ah,09h                  ;Draw horizontal
  185.                 mov     al,horizontal
  186.                 int     10h
  187. dh_exit:        ret
  188. drawhorizontal  endp
  189.  
  190. ;****************************************************************************
  191. ; DRAWVERTICAL draws a vertical line at the cursor position passed in
  192. ; DH and DL.  Length is specified in CX, attribute in BL, and page number
  193. ; in BH.  The line is drawn top to bottom.
  194. ;****************************************************************************
  195.  
  196. drawvertical    proc    near
  197.                 jcxz    dv_exit                 ;Exit if length=0
  198. dv_loop:        mov     ah,02h                  ;Position the cursor
  199.                 int     10h
  200.                 push    cx                      ;Save CX
  201.                 mov     ah,09h                  ;Draw one character
  202.                 mov     al,vertical
  203.                 mov     cx,1
  204.                 int     10h
  205.                 inc     dh
  206.                 pop     cx                      ;Retrieve CX
  207.                 loop    dv_loop                 ;Loop until done
  208. dv_exit:        ret
  209. drawvertical    endp
  210.  
  211. ;****************************************************************************
  212. ; FINDCHAR advances SI to the next non-space or non-comma character.
  213. ; On return, carry set indicates EOL was encountered.
  214. ;****************************************************************************
  215.  
  216. findchar        proc    near
  217.                 lodsb                           ;Get the next character
  218.                 cmp     al,20h                  ;Loop if space
  219.                 je      findchar
  220.                 cmp     al,2Ch                  ;Loop if comma
  221.                 je      findchar
  222.                 dec     si                      ;Point SI to the character
  223.                 cmp     al,0Dh                  ;Exit with carry set if end
  224.                 je      eol                     ;  of line is reached
  225.  
  226.                 clc                             ;Clear carry and exit
  227.                 ret
  228.  
  229. eol:            stc                             ;Set carry and exit
  230.                 ret
  231. findchar        endp
  232.  
  233. ;****************************************************************************
  234. ; HEX2BIN converts a hex number entered in ASCII form into a binary
  235. ; value in BL.  Carry set on return indicates that an error occurred in
  236. ; the conversion.
  237. ;****************************************************************************
  238.  
  239. hex2bin         proc    near
  240.                 sub     ah,ah                   ;Initialize registers
  241.                 sub     bx,bx
  242.  
  243. h2b_loop:       lodsb                           ;Get a character
  244.                 cmp     al,20h                  ;Exit if space
  245.                 je      h2b_exit
  246.                 cmp     al,2Ch                  ;Exit if comma
  247.                 je      h2b_exit
  248.                 cmp     al,0Dh                  ;Exit if carriage return
  249.                 je      h2b_exit
  250.  
  251.                 cmp     al,"0"                  ;Check for digits "0"
  252.                 jb      h2b_error               ;  through "9"
  253.                 cmp     al,"9"
  254.                 ja      h2b2
  255.  
  256.                 sub     al,30h                  ;ASCII => binary
  257. h2b1:           mov     cl,4                    ;Multiply BX by 16 and
  258.                 shl     bx,cl                   ;  add the latest
  259.                 add     bx,ax                   ;  digit
  260.                 cmp     bx,255                  ;Error if sum > 255
  261.                 ja      h2b_error
  262.                 jmp     h2b_loop                ;Loop back for more
  263.  
  264. h2b2:           and     al,0DFh                 ;Capitalize the letter
  265.                 cmp     al,"A"                  ;Check range and exit if
  266.                 jb      h2b_error               ;  not "A" through "F"
  267.                 cmp     al,"F"
  268.                 ja      h2b_error               
  269.                 sub     al,37h                  ;ASCII => binary
  270.                 jmp     h2b1                    ;Finish and loop back
  271.  
  272. h2b_error:      dec     si                      ;Set carry and exit
  273.                 stc
  274.                 ret
  275.  
  276. h2b_exit:       dec     si                      ;Clear carry and exit
  277.                 clc
  278.                 ret
  279. hex2bin         endp
  280.  
  281. ;****************************************************************************
  282. ; ASC2BIN converts a decimal number entered in ASCII form into a binary
  283. ; value in AL.  Carry set on return indicates that an error occurred in
  284. ; the conversion.
  285. ;****************************************************************************
  286.  
  287. asc2bin         proc    near
  288.                 sub     ax,ax                   ;Initialize registers
  289.                 sub     bh,bh
  290.                 mov     dl,10
  291.  
  292. a2b_loop:       mov     bl,[si]                 ;Get a character
  293.                 inc     si
  294.                 cmp     bl,20h                  ;Exit if space
  295.                 je      a2b_exit
  296.                 cmp     bl,2Ch                  ;Exit if comma
  297.                 je      a2b_exit
  298.                 cmp     bl,0Dh                  ;Exit if carriage return
  299.                 je      a2b_exit
  300.  
  301.                 cmp     bl,"0"                  ;Error if character is not
  302.                 jb      a2b_error               ;  a number
  303.                 cmp     bl,"9"
  304.                 ja      a2b_error
  305.  
  306.                 mul     dl                      ;Multiply the value in AL by
  307.                 jc      a2b_error               ;  10 and exit on overflow
  308.                 sub     bl,30h                  ;ASCII => binary
  309.                 add     ax,bx                   ;Add latest value to AX
  310.                 cmp     ax,255                  ;Error if sum > 255
  311.                 jna     a2b_loop                ;Loop back for more
  312.  
  313. a2b_error:      dec     si                      ;Set carry and exit
  314.                 stc
  315.                 ret
  316.  
  317. a2b_exit:       dec     si                      ;Clear carry and exit
  318.                 clc
  319.                 ret
  320. asc2bin         endp
  321.  
  322. code            ends
  323.                 end     begin
  324.