home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / PALROT.ZIP / PALROT.ASM next >
Assembly Source File  |  1993-03-07  |  4KB  |  170 lines

  1.         DOSSEG
  2.         .286
  3.         .MODEL SMALL
  4.         .STACK 200h
  5.         .CODE
  6.  
  7.         ASSUME CS:@code, DS:@code
  8.  
  9. ;====- DATA -=====
  10.     VgaSeg      dw  0a000h  ;segment for VGA
  11.     SegCode     dw  ?
  12.  
  13.     Numcolors   dw  200     ;# of colors to rotate
  14.     NumColors3  dw  200*3   ;# of colors*3
  15.     StartAt     db  1       ;color to start rotate at
  16.     PalIndex    dw  0       ;color to start write at- increased every time
  17.                             ;to produce the rotating effect
  18.     PalIndexVel dw  1       ;amount PalIndex Changes for each screen
  19.  
  20.     Palette     LABEL BYTE
  21.         i=0 
  22.       REPT 63
  23.                 db i,i/2,i/3    ;63 increasing colors
  24.         i=i+1
  25.       ENDM
  26.  
  27.         i=63 
  28.       REPT 63
  29.                 db i,i/2,i/3    ;63 decreasing colors
  30.         i=i-1
  31.       ENDM
  32.  
  33.         i=0 
  34.       REPT 32
  35.                 db i/2,i/3,i    ;32 incr colors
  36.         i=i+2
  37.       ENDM
  38.  
  39.         i=63 
  40.       REPT 32
  41.                 db i/2,i/3,i    ;32 decr colors
  42.         i=i-2
  43.       ENDM
  44.                 db  10*3 dup (0) ;buffer out to 200 colors total
  45.  
  46. ;========- SubRoutines -========
  47.  
  48. WriteLines  PROC NEAR
  49.     pusha
  50.     mov   es,cs:[VgaSeg]
  51.  
  52.     mov   di,10*320
  53.     mov   al,200-20
  54. WrLiLoop:
  55.     mov   ah,al
  56.     mov   cx,160
  57.     rep   stosw
  58.  
  59.     dec   al
  60.     jne   WrLiLoop
  61.  
  62.     popa
  63.     ret
  64. WriteLines  ENDP
  65.  
  66. RotatePalette PROC NEAR
  67.     pusha
  68.  
  69.     call  WritePalette
  70.  
  71.     mov   ds,cs:[SegCode]
  72.  
  73.     mov   ax,[PalIndexVel]
  74.     add   [PalIndex],ax    ;change the palette index
  75.  
  76.     mov   ax,[PalIndex]    ;are we over the number of colors?
  77.     mov   bx,[NumColors]
  78.  
  79.     cmp   ax,bx
  80.     jl    NotTooHigh
  81.     sub   [PalIndex],bx    ;add [Numcolors] to the index
  82.     jmp   NotTooLow
  83. NotTooHigh:
  84.     cmp   ax,0
  85.     jge   NotTooLow
  86.     add   [PalIndex],bx    ;subtract [Numcolors] to the index
  87. NotTooLow:
  88.  
  89.     popa
  90.     ret
  91. RotatePalette ENDP
  92.  
  93. WritePalette PROC NEAR        
  94.     mov   ds,cs:[SegCode]
  95.     cld
  96.  
  97.     mov   dx,[PalIndex]
  98.     mov   bx,dx
  99.     add   bx,bx           ;This just multiplies
  100.     add   bx,dx           ;bx by three ( bx = bx + 2*bx )
  101.  
  102.     mov   si,offset Palette
  103.     mov   dx,03c8h
  104.     mov   ax,[PalIndex]
  105.     add   al,[StartAt]
  106.     out   dx,al           ;start writing at [PalIndex]+[StartAt]
  107.     inc   dx
  108.     mov   cx,[NumColors3]
  109.     sub   cx,bx           ;get the number of colors to write
  110.     rep outsb
  111.  
  112.     mov   al,[StartAt]
  113.     dec   dx              ;point to palette index
  114.     out   dx,al           ;out the number we want to start writing at 
  115.     inc   dx
  116.     mov   cx,bx           ;get the number of colors to write
  117.     rep outsb             ;note that SI is already where we want it
  118.  
  119.     ret
  120. WritePalette ENDP         ;well, that's all there is to it
  121.  
  122. ;====- CODE -====
  123.  
  124. Start:
  125.     mov     ax,cs
  126.     mov     ds,ax
  127.     mov     es,ax
  128.     mov     [SegCode],ax
  129.  
  130.     mov     ax,0013h    ;changes to 320x200x256 graphics mode
  131.     int     10h
  132.  
  133.     call    WriteLines
  134. MainLoop:
  135.  
  136.     mov     dx,3dah
  137. VRT:
  138.     in      al,dx
  139.     test    al,8
  140.     jnz     VRT         ;wait until Verticle Retrace starts
  141.  
  142.     call    RotatePalette
  143.     
  144.     mov     dx,3dah
  145. NoVRT:
  146.     in      al,dx
  147.     test    al,8
  148.     jz      NoVRT       ;wait until Verticle Retrace ends
  149.                         ;so that we dont rotate more than once a frame
  150.  
  151.     mov     ah,1        ;wait for a keypress
  152.     int     16h
  153.     jz      MainLoop
  154.  
  155.     mov     ah,0
  156.     int     16h         ;get the key
  157.     neg     cs:[PalIndexVel]
  158.     cmp     al," "
  159.     je      MainLoop
  160.  
  161.     mov     ax,0003h    ;changes to 80x25x16 text mode
  162.     int     10h
  163.     mov     ax,4c00h    ;terminate process and
  164.     int     21h         ;return control to DOS
  165.  
  166. End START
  167.         
  168.  
  169.  
  170.