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

  1. ;void box_up(box,col,row,width,depth);
  2. ;  unsigned char  *box,*col,*row,width,depth;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _snow_protect:byte
  7.  
  8. box_seg EQU  [bp-2]
  9. box_ofs EQU  [bp-4]
  10. col_seg EQU  [bp-6]
  11. col_ofs EQU  [bp-8]
  12. row_seg EQU  [bp-10]
  13. row_ofs EQU  [bp-12]        
  14. width    EQU  [bp-14]        
  15. depth   EQU  [bp-16]        
  16. snow    EQU  [bp-18]        
  17. endofbox EQU  [bp-20]    
  18. toppos  EQU  [bp-22]        
  19. rghtpos EQU  [bp-24]        
  20.  
  21. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  22.     ASSUME CS:_TEXT
  23.     PUBLIC _box_up
  24. _box_up proc near
  25.     push bp            ;
  26.     mov  bp,sp        ;set stack frame
  27.     sub  sp,24        ;make room to hold parameters
  28.     pushf            ;
  29.     push di            ;
  30.     push si            ;
  31.     cmp  _memory_model,0    ;near or far?
  32.     jle  begin        ;jump if near
  33.     inc  bp            ;else add 2 to BP
  34.     inc  bp            ;
  35. begin:    push ds            ;save Turbo's DS
  36.     mov  dx,_video_buffer    ;grab _video_buffer
  37.     push dx            ;save it
  38.     cmp  _memory_model,2    ;data near or far?
  39.     jb   L0            ;jump if near
  40.     push [bp+6]        ;move parameters to SP offsets
  41.     push [bp+10]
  42.     push [bp+14]
  43.     push [bp+4]
  44.     push [bp+8]
  45.     push [bp+12]
  46.     push [bp+16]
  47.     push [bp+18]
  48.     jmp  short L00
  49. L0:    push ds            ;near case
  50.     push ds
  51.     push ds
  52.     push [bp+4]
  53.     push [bp+6]
  54.     push [bp+8]
  55.     mov  al,[bp+10]
  56.     sub  ah,ah
  57.     push ax
  58.     mov  al,[bp+12]
  59.     push ax
  60. L00:    cmp  _memory_model,0    ;check code model again
  61.     jle  L000        ;jump if near
  62.     dec  bp            ;unadjust BP so all BP offsets same
  63.     dec  bp            ;
  64. L000:    pop  depth        ;set intermediate values
  65.     pop  width
  66.     pop  row_ofs
  67.     pop  col_ofs
  68.     pop  box_ofs
  69.     pop  row_seg
  70.     pop  col_seg
  71.     pop  box_seg
  72.     mov  ax,col_seg        ;point ES:DI to Col
  73.     mov  es,ax        ;
  74.     mov  di,col_ofs        ;
  75.     mov  al,_snow_protect    ;grab _snow_protect
  76.     mov  snow,al        ;save it
  77.     sub  cx,cx        ;
  78.     mov  cl,es:[di]        ;get column position
  79.     jcxz F1            ;quit if column is zero
  80.     dec  cx            ;count from zero
  81.     cmp  cx,79        ;in range?
  82.     jna  G1            ;jump ahead if so
  83. F1:    jmp  M1            ;else quit
  84. G1:    mov  ax,box_seg        ;point ES:DI to byte array
  85.     mov  es,ax        ;
  86.     mov  di,box_ofs        ;
  87.     mov  ax,depth        ;depth to AX
  88.     dec  ax            ;dec for test
  89.     cmp  ax,24        ;in range?
  90.     jna  H1            ;jump ahead if so
  91.     jmp  M1            ;else quit routine
  92. H1:    inc  ax            ;readjust
  93.     mov  bx,width        ;width to BX
  94.     dec  bx            ;dec for test
  95.     cmp  bx,79        ;in range?
  96.     jna  I1            ;jump ahead if so
  97.     jmp  M1            ;else quit
  98. I1:    inc  bx            ;readjust
  99.     mul  bl            ;width times depth
  100.     shl  ax,1        ;double for attributes
  101.     add  ax,di        ;offset to end of Box
  102.     mov  endofbox,ax    ;save end of box ptr
  103.     mov  di,ax        ;pt ES:DI to end of Box
  104.     mov  ax,row_seg        ;point DS:SI to Row
  105.     mov  ds,ax        ;
  106.     mov  si,row_ofs        ;
  107.     sub  ax,ax        ;
  108.     mov  al,[si]        ;get row value
  109.     cmp  ax,1        ;top row already?
  110.     je   J1            ;quit if so
  111.     dec  ax            ;count from zero
  112.     cmp  ax,24        ;in range?
  113.     jna  K1            ;jump ahead if so
  114. J1:    jmp  M1            ;else quit
  115. K1:    mov  bx,ax        ;copy in BX
  116.     add  bx,depth        ;add depth
  117.     cmp  bx,25        ;in range?
  118.     ja   J1            ;quit if so
  119.     mov  [si],al        ;reset row variable
  120.     mov  bl,160        ;bytes per row
  121.     mul  bl            ;calculate row offset
  122.     shl  cx,1        ;col offset
  123.     add  ax,cx        ;add to row offset
  124.     mov  si,ax        ;SI pts to topleft corner
  125.     mov  toppos,si        ;save it
  126.     mov  ax,dx        ;_video_buffer
  127.     mov  ds,ax        ;move to DS        
  128.     mov  ax,depth        ;depth
  129.     mov  cl,160        ;bytes per row
  130.     mul  cl            ;times depth
  131.     add  si,ax        ;DS:SI pts to topright
  132.     mov  rghtpos,si        ;save position
  133.     pop  bx            ;_video_buffer
  134.     cld            ;set direction
  135.     mov  si,toppos        ;topright position
  136.     sub  si,160        ;row higher
  137.     mov  cx,width        ;width
  138.     shl  cx,1        ;double for MOVSB
  139.     call WriteIt        ;write a char
  140.     mov  ax,ds        ;DS to AX
  141.     mov  es,ax        ;now ES pts to screen too
  142.     mov  di,toppos        ;top left position
  143.     mov  si,di        ;copy to SI
  144.     sub  di,160        ;DI one row higher
  145.     mov  ax,depth        ;depth to AX
  146. L1:    mov  cx,width        ;width to CX
  147.     push di            ;save target ptr
  148.     push si            ;save source ptr
  149.     shl  cx,1        ;double width for MOVSB
  150.     call Writeit        ;write a char
  151.     pop  si            ;restore ptr
  152.     pop  di            ;restore ptr
  153.     add  di,160        ;ptr down one row
  154.     add  si,160        ;ditto
  155.     dec  ax            ;dec depth counter
  156.     jnz  L1            ;loop till finished
  157.     mov  ax,box_seg        ;segment of Box
  158.     mov  ds,ax        ;move to DS
  159.     mov  si,endofbox    ;offset of end of Box
  160.     mov  di,rghtpos        ;ES:DI pts to bottomleft
  161.     sub  di,160        ;one row higher
  162.     mov  dx,width        ;width
  163.     shl  dx,1        ;double for attributes
  164.     sub  si,dx        ;DS:SI pts to last row
  165.     mov  cx,dx        ;use as counter
  166.     call Writeit        ;write a char
  167.     std            ;reverse direction flag
  168.     mov  ax,ds        ;DS pts to Box
  169.     mov  es,ax        ;now ES does too
  170.     mov  di,endofbox    ;offset to end of Box
  171.     sub  di,2        ;last char of box
  172.     mov  si,di        ;copy to SI
  173.     sub  si,dx        ;offset to second row
  174.     mov  ax,depth        ;depth
  175.     dec  ax            ;minus one row
  176.     mov  cx,width        ;width
  177.     mul  cl            ;size of Box minus 1 row
  178.     mov  cx,ax        ;move to CX as counter
  179.     rep  movsw        ;shift all upwards
  180.     mov  di,box_ofs        ;offset of Box
  181.     mov  si,endofbox    ;end of box
  182.     mov  cx,width        ;width
  183.     cld            ;direction flag forward
  184.     rep  movsw        ;move new data
  185.     jmp  short N1        ;jump to end
  186. M1:    pop  bx            ;balance stack if error
  187. N1:    sti            ;reenable interrupts
  188.     pop  ds            ;
  189.     pop  si            ;
  190.     pop  di            ;
  191.     popf            ;
  192.     add  sp,24        ;restore stack pointer
  193.     pop  bp            ;
  194.     cmp  _memory_model,0    ;quit
  195.     jle  quit        ;
  196.     db   0CBh        ;RET far
  197. quit:    ret            ;RET near
  198. _box_up endp
  199. Writeit PROC
  200.     push dx            ;save DX
  201.     push ax            ;save AX
  202.     mov  dx,3dah        ;status byte address
  203.     mov  bx,es        ;get target segment
  204.     mov  ax,ds        ;get source segment
  205.     cmp  ax,bx        ;is source larger?
  206.     jna  A1            ;jump if not
  207.     mov  bx,ax        ;else use source
  208. A1:    cmp  byte ptr snow,0    ;protect against snow?
  209.     je   D1            ;jump ahead if not
  210. B1:    in   al,dx        ;get status byte
  211.     test al,1        ;test bit
  212.     jnz  B1            ;loop till 0
  213.     cli            ;disable interrupts
  214. C1:    in   al,dx        ;get status byte
  215.     test al,1        ;test bit
  216.     jz   C1            ;loop till 1
  217. D1:    movsb            ;move a character
  218.     loop A1            ;go do next
  219.     pop  ax            ;restore AX
  220.     pop  dx            ;restore DX
  221.     ret            ;
  222. Writeit  endp
  223. _TEXT    ENDS
  224.     END
  225.