Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. COMMENT |
  2.  
  3. copper.asm
  4.  
  5. This file was released into the Public Domain by Doug Mansell
  6. (3:690/613.11) on 29jul92.
  7.  
  8. On every horizontal retrace the same DAC is changed to the next colour
  9. in a colour table.
  10.  
  11. C callable as:
  12.  
  13.     void pascal copper(int lines, unsigned char DACnum,
  14.                        void *colourtable, int count);
  15.  
  16.     'lines' is the number of scanlines on the screen (note that in some
  17.     modes the number of scanlines may be twice as much as the number of
  18.     pixel rows).  By using a value slightly higher, or slightly lower
  19.     than the actual number of scanlines, you can get the colours to roll
  20.     up or down the screen!
  21.  
  22.     'DACnum' is the DAC to mess with.
  23.  
  24.     'colourtable' points to an array of RGB values, something like:
  25.         struct _rgb {
  26.             unsigned char red, green, blue;
  27.         } colourtable[480];
  28.  
  29.     'count' is the number of retraces to do.
  30.  
  31. IMPORTANT:
  32.     - Interrupts are disabled for a long time: at least, your DOS clock
  33.       will stop!
  34.     - An 80186 instruction (OUTS) is used to help speed up the DAC
  35.       setting, thus a 186 or better is required to call copper.
  36.     - copper uses the CRTC status port of the _colour_ VGA.
  37.  
  38. My mileage:
  39.     This assembles with TASM 2.01 and works under DOS on my 286 with ye
  40.     olde VGA card.
  41.  
  42. |
  43.  
  44.         .MODEL SMALL
  45.         .CODE
  46.  
  47.                 PUBLIC COPPER
  48.  
  49.                 .186
  50.  
  51. COPPER          PROC
  52.                 ARG count:WORD, colours:DATAPTR, DACnum:BYTE:2, lines:WORD = retbytes
  53.                 push bp
  54.                 mov  bp,sp
  55.  
  56.                 push si                 ; save C register variables
  57.                 push di
  58.  
  59.                 ; setup registers and stuff
  60.                 mov  ah,[DACnum]
  61.                 xor  ch,ch
  62.                 mov  dx,003dah          ; 3da = crtc status port
  63.                 mov  bx,0dac8h          ; 3c8 = DAC port
  64.                 cld                     ; increment si through colours
  65.                 cli                     ; keeps things stable
  66.  
  67. vsync1:         in   al,dx              ; wait for vsync to happen
  68.                 test al,8
  69.                 jz   vsync1
  70. vsync2:         in   al,dx              ; wait for vsync to finish
  71.                 test al,8
  72.                 jnz  vsync2
  73.  
  74. ALIGN 2
  75. colourstart:    mov  di,[lines]         ; set line counter
  76.                 mov  si,[colours]       ; point si to colour table
  77.  
  78. ALIGN 2
  79. dolines:        mov  cl,3               ; prepare cx for OUTS
  80.                 mov  dl,bh              ; dx = CRTC status port
  81.  
  82. hsync1:         in   al,dx              ; wait for display on
  83.                 test al,1
  84.                 jnz  hsync1
  85. hsync2:         in   al,dx              ; wait for display off
  86.                 test al,1
  87.                 jz   hsync2
  88.  
  89.                 mov  dl,bl              ; dx = DAC index port (?)
  90.                 mov  al,ah              ; load DAC number
  91.                 out  dx,al              ; tell VGA which DAC we want to change
  92.                 inc  dx                 ; RGB stuff goes to next port
  93.                 rep  outsb              ; DAC is set!
  94.  
  95.                 dec  di                 ; count a line
  96.                 jnz  dolines            ; do all lines
  97.  
  98.                 dec  [count]            ; count another pass
  99.                 jnz  colourstart        ; do all passes
  100.  
  101.                 sti                     ; enable interrupts
  102.  
  103.                 pop  di                 ; restore register variables
  104.                 pop  si
  105.  
  106.                 pop  bp
  107.                 ret  retbytes
  108.  
  109. COPPER          ENDP
  110.  
  111.                 END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement