home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CEXPRESS.ZIP / GRAPHIC.ASM / DRAWBOX.ASM < prev    next >
Assembly Source File  |  1989-05-03  |  5KB  |  165 lines

  1. ;void  draw_box(hrz_char,vrt_char,top_x,top_y,width,depth,color);
  2. ;  unsigned char  hrz_char,vrt_char,top_x,top_y,width,depth,color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _video_buffer:word
  7.     EXTRN  _snow_protect:byte
  8.  
  9. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC _draw_box
  12. _draw_box proc near
  13.     jmp  short D1
  14. WriteIt    PROC            ;procedures writes char,
  15.     push dx            ;  takes care of snow problem
  16.     push bx            ;save DX and BX
  17.     cld            ;set direction flag
  18.     cmp  _snow_protect,0    ;protect against snow?
  19.     jle  C1            ;jump ahead if not
  20.     mov  dx,3dah        ;status byte address
  21.     mov  bx,ax        ;store AX contents
  22. A1:    in   al,dx        ;get status byte
  23.     test al,1        ;test bit
  24.     jnz  A1            ;loop till 0
  25.     cli            ;disable interrupts
  26. B1:    in   al,dx        ;get status byte
  27.     test al,1        ;test bit
  28.     jz   B1            ;loop till 1
  29.     mov  ax,bx        ;restore AX contents
  30. C1:    stosw            ;write the character
  31.     dec  di            ;pull ptr back
  32.     dec  di            ;again
  33.     pop  bx            ;restore BX
  34.     pop  dx            ;restore DX and return
  35.     ret            
  36. WriteIt    endp
  37. D1:    push bp            ;
  38.     mov  bp,sp        ;set up stack frame
  39.     push di            ;
  40.     mov  _error_code,1    ;1 = row out of range
  41.     cmp  _memory_model,0    ;near or far?
  42.     jle  begin        ;jump if near
  43.     inc  bp            ;else add 2 to BP
  44.     inc  bp            ;
  45. begin:    mov  al,[bp+4]        ;horz double or single?
  46.     mov  dh,205        ;assume double line
  47.     cmp  al,'D'        ;double line?
  48.     je   E1            ;jump ahead if so
  49.     cmp  al,'d'        ;double line?
  50.     je   E1            ;jump ahead if so
  51.     mov  dh,196        ;else single line
  52. E1:    mov  al,[bp+6]        ;vert double or single?
  53.     mov  dl,186        ;assume double line
  54.     cmp  al,'D'        ;double line?
  55.     je   G1            ;jump ahead if so
  56.     cmp  al,'d'        ;double line?
  57.     je   G1            ;jump ahead if so
  58.     mov  dl,179        ;else single line
  59.     cmp  dh,196        ;horizontal single?
  60.     jne  F1            ;jump ahead if not
  61.     mov  ax,0DaBFh        ;top sngl vert, sngl horz
  62.     mov  bx,0c0d9h        ;bot sngl vert, sngl horz
  63.     jmp  short I1        ;registers set
  64. F1:    mov  ax,0d5b8h        ;top sngl vert, dbl horz
  65.     mov  bx,0d4beh        ;bot sngl vert, dbl horz
  66.     jmp  short I1        ;registers set
  67. G1:    cmp  dh,196        ;horizontal single?
  68.     jne  H1            ;jump ahead if not
  69.     mov  ax,0d6b7h        ;top dbl vert, sngl horz
  70.     mov  bx,0d3bdh        ;bot dbl vert, sngl horz
  71.     jmp  short I1        ;registers set
  72. H1:    mov  ax,0c9bbh        ;top dbl vert, dbl horz
  73.     mov  bx,0c8bch        ;bot dbl vert, dbl horz
  74. I1:    mov  [bp+4],ax        ;save top corners
  75.     mov  [bp+6],bx        ;save bottom corners
  76.     mov  ax,_video_buffer    ;get ptr to videobuffer
  77.     mov  es,ax        ;move to ES
  78.     sub  ax,ax        ;
  79.     mov  al,[bp+10]        ;row to AX
  80.     dec  ax            ;count from 0
  81.     cmp  ax,24        ;in range?
  82.     jbe  J1            ;jump ahead if so
  83.     jmp  O1            ;else quit routine
  84. J1:    inc  _error_code    ;2 = column out of range
  85.     mov  cl,160        ;bytes in a row
  86.     mul  cl            ;times rows
  87.     sub  cx,cx        ;
  88.     mov  cl,[bp+8]        ;column to CX
  89.     dec  cx            ;count from 0
  90.     cmp  cx,79        ;in range?
  91.     jna  K1            ;jump ahead if OK
  92.     jmp  O1            ;else quit
  93. K1:    inc  _error_code    ;3 = width out of range
  94.     shl  cx,1        ;double for attributes
  95.     add  ax,cx        ;buffer offset
  96.     mov  di,ax        ;ES:DI pts to offset
  97.     sub  bx,bx        ;
  98.     mov  bl,[bp+12]        ;width to BX
  99.     dec  bx            ;count from 0
  100.     dec  bx            ;ready for test
  101.     cmp  bx,78        ;out of range?
  102.     ja   O1            ;quit if so
  103.     inc  _error_code    ;4 = depth out of range
  104.     inc  bx            ;readjust after test
  105.     shl  bx,1        ;double for attributes
  106.     mov  ah,[bp+16]        ;attribute to AH
  107.     mov  al,[bp+5]        ;topleft corner to AL
  108.     call WriteIt        ;write the character
  109.     add  di,bx        ;add offset to scrn ptr
  110.     mov  al,[bp+4]        ;topright corner to AL
  111.     call WriteIt        ;write the character
  112.     sub  di,bx        ;sub offset from scrn ptr
  113.     sub  cx,cx        ;
  114.     mov  cl,[bp+14]        ;get box depth
  115.     dec  cx            ;minus 2
  116.     dec  cx            ;  for corners
  117.     cmp  cx,23        ;test length
  118.     ja   O1            ;quit if out of range
  119.     mov  _error_code,0    ;else no error
  120.     push di            ;save initial position
  121.     add  di,160        ;forward screen ptr
  122.     jcxz M1            ;jump if no chr to write
  123.     mov  al,dl        ;vertical char to AL
  124. L1:    call WriteIt        ;write the character
  125.     add  di,bx        ;add offset to scrn ptr
  126.     call WriteIt        ;write the character
  127.     sub  di,bx        ;sub offset from scrn ptr
  128.     add  di,160        ;forward screen ptr
  129.     loop L1            ;on to next vert chars
  130. M1:    mov  al,[bp+7]        ;bottomleft corner to AL
  131.     call WriteIt        ;write the character
  132.     mov  al,[bp+6]        ;bottomright corner to AL
  133.     add  di,bx        ;add offset to scrn ptr
  134.     call WriteIt        ;write the character
  135.     sub  di,bx        ;sub offset from scrn ptr
  136.     mov  bx,di        ;save bottom left pos
  137.     pop  di            ;restore top left pos
  138.     mov  al,dh        ;horizontal char to AL
  139.     sub  cx,cx        ;
  140.     mov  cl,[bp+12]        ;get width
  141.     dec  cx            ;minus 2
  142.     dec  cx            ;  for corners
  143.     jcxz O1            ;quit if no chrs to print
  144.     inc  di            ;forward scrn ptr
  145.     inc  di            ;  to 1st position on top
  146. N1:    call WriteIt        ;write the character
  147.     inc  di            ;forward base ptr
  148.     inc  di            ;...again
  149.     inc  bx            ;forward scrn ptr
  150.     inc  bx            ;  for bottom line
  151.     xchg di,bx        ;get ready to write
  152.     call WriteIt        ;write the character
  153.     xchg di,bx        ;restore scrn ptr
  154.     loop N1            ;go do next char
  155. O1:    sti            ;reenable interrupts
  156.     pop  di            ;
  157.     pop  bp            ;
  158.     cmp  _memory_model,0    ;quit
  159.     jle  quit        ;
  160.     db   0CBh        ;RET far
  161. quit:    ret            ;RET near
  162. _draw_box endp
  163. _TEXT    ENDS
  164.     END
  165.