home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / copper.asm < prev    next >
Assembly Source File  |  1995-07-28  |  4KB  |  127 lines

  1. extrn waitretrace:far
  2. data segment public
  3.   maxrow dw (?)
  4. data ends
  5.  
  6. code segment public
  7. public makecopper
  8.  
  9. assume cs:code,ds:data
  10.  
  11. MakeCopper proc pascal y_pos1,y_pos2,overlay_mask:word
  12. ; draws 2 copper beams at positions y_pos1 (red) and y_pos2 (green)
  13. ; overlay_mask: 0ff00h : Copper 2 in foreground
  14. ;                000ffh : copper 1 in foreground
  15. ;                00000h : penetration of both coppers
  16.  
  17. height equ 88                   ;total height per copper
  18.  
  19.  
  20.   mov ax,y_pos1                 ;define maximum y-coordinate
  21.   cmp ax,y_pos2
  22.   ja ax_high
  23.   mov ax,y_pos2
  24. ax_high:
  25.   add ax,height                 ;add height
  26.   mov maxrow,ax                 ;maximum row to be taken into consideration
  27.  
  28.   xor cx,cx                     ;start row counter with 0
  29.  
  30.   call waitretrace              ;wait for retrace for synchronization
  31.  
  32. next_line:
  33.   inc cx                        ;increment row counter
  34.  
  35.   mov bx,cx                     ;calculate color 1
  36.   sub bx,y_pos1                 ;in addition, get position relative to copper start
  37.   cmp bx,height/2 -1            ;2nd half ?
  38.   jle copper1_up
  39.   sub bx,height -1              ;then bx:=127-bx
  40.   neg bx
  41. copper1_up:
  42.   or bx,bx
  43.   jns copper1_ok                ;positive, then color
  44.   xor bl,bl
  45. copper1_ok:
  46.   mov ax,cx                     ;calculate color 2
  47.   sub ax,y_pos2                 ;calculate position relatively
  48.   cmp ax,height/2 -1            ;2nd half
  49.   jle copper2_up
  50.   sub ax,height -1              ;then ax:=127-ax
  51.   neg ax
  52. copper2_up:
  53.   or ax,ax                      ;positive, then color
  54.   jns copper2_ok
  55.   xor al,al
  56. copper2_ok:
  57.   mov bh,al                     ;bl now has color copper 1 / bh copper 2
  58.  
  59.   mov ax,bx                     ;calculate overlay
  60.   and ax,overlay_mask           ;mask out copper 1 or 2
  61.   or al,al                      ;copper 1 priority
  62.   je copper1_back
  63.   xor bh,bh                     ;then clear copper 2
  64. copper1_back:
  65.   or ah,ah                      ;copper 2 priority
  66.   je copper2_back
  67.   xor bl,bl                     ;then clear copper 1
  68. copper2_back:
  69.  
  70.   xor al,al                     ;select color 0 in DAC
  71.   mov dx,3c8h
  72.   out dx,al
  73.  
  74.   or bl,bl                      ;if copper 1 black -> leave as is
  75.   je bl_0
  76.   add bl,(128-height) / 2       ;otherwise lighten to achieve maximum
  77. bl_0:                           ;brightness
  78.   or bh,bh                      ;the same for copper 2
  79.   je bh_0
  80.   add bh,(128-height) / 2
  81. bh_0:
  82.  
  83. ;now wait for horizontal retrace and enable copper
  84.  
  85.   cli                           ;clear interrupts, because it is VERY time-critical
  86.   mov dx,3dah                   ;select Input Status Register 1
  87. in_retrace:
  88.   in al,dx                      ;wait for display
  89.   test al,1
  90.   jne in_retrace
  91.  
  92. in_display:
  93.   in al,dx                      ;wait for (horizontal) retrace
  94.   test al,1
  95.   je in_display
  96.  
  97.   mov al,bl                     ;load color 1
  98.   mov dx,3c9h                   ;and set
  99.   out dx,al                     ;set red percentage for copper 1
  100.   mov al,bh
  101.   out dx,al                     ;set green percentage for copper 2
  102.   xor al,al
  103.   out dx,al
  104.  
  105.   cmp cx,maxrow                 ;last row generated ?
  106.   jne next_line
  107.  
  108.   mov dx,3dah                   ;yes -> end
  109. wait_hret:                      ;before switching off, wait for retrace
  110.   in al,dx                      ;otherwise flickering in last row
  111.   test al,1
  112.   je wait_hret
  113.  
  114.   xor al,al                     ;select color 0 in DAC
  115.   mov dx,3c8h
  116.   out dx,al
  117.   inc dx                        ;set all to 0: black
  118.   out dx,al
  119.   out dx,al
  120.   out dx,al
  121.  
  122.   sti
  123.   ret
  124. makecopper endp
  125. code ends
  126. end
  127.