home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c011 / 1.ddi / SOURCE / FXPC.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-06-01  |  20.7 KB  |  652 lines

  1.   PAGE    60,132
  2.   TITLE   fxPC.ASM -- PCX Effects
  3.   SUBTTL  Copyright (c) Genus Microprogramming, Inc. 1988-89
  4.  
  5. ; fxPC.ASM                                                                   ;
  6. ; Copyright (c) Genus Microprogramming, Inc. 1988-89  All Rights Reserved.   ;
  7.  
  8. ;****************************************************************************;
  9. ;                                                                            ;
  10. ; This file contains procedures for taking a display palette and changing    ;
  11. ; it with a special effect.                                                  ;
  12. ;                                                                            ;
  13. ; Procedures: fxPaletteCycle                                                 ;
  14. ;             fxPaletteFade                                                  ;
  15. ;                                                                            ;
  16. ;                                                                            ;
  17. ; Microsoft ASM 5.x version.              Programmer: Chris Howard  4/15/89  ;
  18. ;                                                                            ;
  19. ;****************************************************************************;
  20.  
  21. ; Include files
  22.   INCLUDE ..\inc\pcxDefs.inc
  23.   INCLUDE ..\inc\pcxMacs.inc
  24.   INCLUDE ..\inc\pcxErrs.inc
  25.  
  26.   INCLUDE ..\inc\fxDefs.inc
  27.   INCLUDE ..\inc\fxMacs.inc
  28.   INCLUDE ..\inc\fxErrs.inc
  29.  
  30.   @SetModel
  31.  
  32.   @BegData
  33.  
  34.           EXTRN     pcxFBuff                : BYTE
  35.  
  36.   @EndData
  37.  
  38.   @BegCode
  39.  
  40.           EXTRN     pcxGetDisplay           : FAR
  41.           EXTRN     pcxGetDispStruc         : FAR
  42.           EXTRN     pcxSetDisplayPalette    : FAR
  43.  
  44.           EXTRN     fxEffectDelay           : FAR
  45.  
  46.           PUBLIC    fxPaletteCycle 
  47.           PUBLIC    fxPaletteFade  
  48.  
  49. ;**********
  50.  
  51. ;
  52. ; This procedure simply sets the palette for the given display type and
  53. ; palette.
  54. ;
  55. ;
  56.  
  57. ;Define variable locations on the stack  (pascal model)
  58. sptype   equ        <[bp+10]>
  59. sppalseg equ        <[bp+ 8]>
  60. sppalofs equ        <[bp+ 6]>
  61. spparm   equ        6
  62.  
  63. ;Define local variables
  64. spret    equ        <[bp-2]>                ;return code
  65. splocal  equ        2                       ;Total local space needed
  66.  
  67. fxSetPalette        PROC FAR
  68.  
  69.           @Entry    splocal                 ;Set up frame and save regs
  70.  
  71.           mov       bx,sptype               ;Get the palette type
  72.  
  73.           @@LoadSeg ds,sppalseg             ;Point to decoded palette buffer
  74.           mov       si,sppalofs
  75.  
  76.           cmp       bx,pal1                 ;Now determine the palette type
  77.           je        fxSP_pal1
  78.  
  79.           cmp       bx,pal2
  80.           je        fxSP_pal1
  81.  
  82.           cmp       bx,pal3
  83.           je        fxSP_pal3
  84.  
  85.           cmp       bx,pal4
  86.           je        fxSP_pal4
  87.  
  88.           cmp       bx,pal5
  89.           jne       fxSP_palerr             ;Change je/jmp order, since not
  90.                                             ; close enough
  91.           jmp       fxSP_pal5
  92.  
  93. fxSP_palerr:
  94.  
  95.           @SetRet   spret,fxERR_BADPAL      ;Bad display type
  96.           jmp       fxSP_exit
  97.  
  98. fxSP_pal1:
  99.  
  100.           mov       dh,ds:[si]              ;Get the background color
  101.                                             ; in case we need intensity
  102.           mov       al,ds:[si][1]           ;Get the palette type
  103.  
  104.           cmp       al,4                    ;Supposedly 8 palettes, but only 4
  105.           jl        fxSP_pal1det            ; are supported
  106.           sub       al,4
  107.  
  108. fxSP_pal1det:
  109.  
  110.           cmp       al,0                    ;Palette 0? (Red, Green, Brown)
  111.           jne       fxSP_pal11
  112.  
  113.           mov       dl,0                    ;Select palette
  114.  
  115.           jmp       SHORT fxSP_pal1set
  116.  
  117. fxSP_pal11:
  118.  
  119.           cmp       al,1                    ;Palette 1? (Lt Red, Lt Green, Yell)
  120.           jne       fxSP_pal12
  121.  
  122.           mov       dl,0                    ;Select palette
  123.           or        dh,00010000B            ; (Background bit 4=hi intensity)
  124.  
  125.           jmp       SHORT fxSP_pal1set
  126.  
  127. fxSP_pal12:
  128.  
  129.           cmp       al,2                    ;Palette 2? (Cyan, Magenta, Lt Gray)
  130.           jne       fxSP_pal13
  131.  
  132.           mov       dl,1                    ;Select palette
  133.  
  134.           jmp       SHORT fxSP_pal1set
  135.  
  136. fxSP_pal13:
  137.  
  138.                                             ;Palette 3 (Lt Cyan, Lt Mag, White)
  139.           mov       dl,1                    ;Select palette
  140.           or        dh,00010000B            ; (Background bit 4=hi intensity)
  141.  
  142. fxSP_pal1set:
  143.  
  144.           mov       bh,1                    ;Select palette function
  145.           mov       bl,dl                   ; and palette
  146.           @BIOS     SETCGAPAL               ; and set it
  147.  
  148.           mov       bh,0                    ;Select background function
  149.           mov       bl,dh                   ; and background
  150.           @BIOS     SETCGAPAL               ; and set it
  151.  
  152.           @SetRet   spret,fxSUCCESS
  153.           jmp       SHORT fxSP_exit
  154.  
  155. fxSP_pal2:
  156.  
  157.           mov       bl,ds:[si]              ;Get the foreground color
  158.           mov       bh,0                    ;Select palette function
  159.           @BIOS     SETCGAPAL               ; and set it
  160.  
  161.           @SetRet   spret,fxSUCCESS         ;If so, we are done
  162.           jmp       SHORT fxSP_exit
  163.  
  164. fxSP_pal3:
  165.  
  166.           @@LoadSeg es,ds                   ;Point to palette
  167.           mov       dx,si
  168.  
  169.           mov       al,2                    ;Select palette function (all)
  170.           @BIOS     SETPAL                  ; and set it
  171.  
  172.           @SetRet   spret,fxSUCCESS
  173.           jmp       SHORT fxSP_exit
  174.  
  175. fxSP_pal4:
  176.  
  177.           mov       bx,15                   ;First palette reg (work back)
  178.           @@LoadSeg es,ds                   ;Point to palette table
  179.           mov       di,si
  180.           add       di,2*15                 ;Adjust for triples
  181.                                             ;  ie, palptr+(15)+(2*15) is last
  182.                                             ;  reg in table of 3*16 DAC's
  183. fxSP_pal4loop:
  184.  
  185.           mov       dh,es:[di][bx]          ;Get DAC values
  186.           mov       ch,es:[di][bx+1]
  187.           mov       cl,es:[di][bx+2]
  188.  
  189.           push      bx                      ;Save palette number
  190.           mov       al,7                    ;Get palette reg
  191.           @BIOS     SETPAL
  192.  
  193.           mov       bl,bh                   ;Move value down
  194.           xor       bh,bh                   ; so BX = desired DAC reg number
  195.  
  196.           mov       al,10H                  ;Now set it
  197.           @BIOS     SETPAL
  198.           pop       bx                      ;Retrieve palette
  199.  
  200.           dec       di                      ;Point to next DAC entry
  201.           dec       di                                                       
  202.           dec       bx                      ; by bumping back total of 3
  203.           jns       fxSP_pal4loop           ;Loop until done
  204.  
  205.           @SetRet   spret,fxSUCCESS         ;Set success code
  206.           jmp       SHORT fxSP_exit
  207.  
  208. fxSP_pal5:
  209.  
  210.           @@LoadSeg es,ds                   ;Point to palette
  211.           mov       dx,si
  212.           mov       cx,256                  ;Set 256 registers
  213.           mov       bx,0                    ; starting at register 0
  214.           mov       al,12H                  ;Select update palette function
  215.           @BIOS     SETPAL                  ; and set
  216.  
  217.           @SetRet   spret,fxSUCCESS
  218.  
  219. fxSP_exit:
  220.  
  221.           @Exit     spret,spparm            ;Return
  222.  
  223. fxSetPalette        ENDP
  224.  
  225. ;**********
  226.  
  227. ;
  228. ; This procedure cycles through a set of palette registers, repeating for 
  229. ; the given number of times, and delaying between each set.           
  230. ;
  231. ;
  232.  
  233. ;Define variable locations on the stack  (pascal model)
  234. pcpalseg  equ       <[bp+16]>               ;Palette pointer
  235. pcpalofs  equ       <[bp+14]>        
  236. pcstart   equ       <[bp+12]>               ;Starting palette number
  237. pctotal   equ       <[bp+10]>               ;Total number to cycle
  238. pcrepeat  equ       <[bp+ 8]>               ;Number of times to repeat
  239. pcdelay   equ       <[bp+ 6]>               ;Time Delay    
  240. pcparm    equ       12
  241.  
  242. ;Define local variables
  243. pcret     equ       <[bp- 2]>               ;Return code
  244. pcpaltype equ       <[bp- 4]>               ;Palette type
  245. pclocal   equ       4                       ;Total local space needed
  246.  
  247. fxPaletteCycle      PROC FAR
  248.  
  249.           @Entry    pclocal                 ;Set up frame and save regs
  250.  
  251.           @@LoadSeg ds,pcpalseg             ;Point to the palette
  252.           mov       si,pcpalofs
  253.  
  254.           @@Data    es                      ; and use the toolkit buffer
  255.           mov       di,OFFSET pcxFBUFF
  256.  
  257.           mov       cx,800                  ;Copy 800 bytes, regardless
  258.           rep       movsb
  259.  
  260.           @@Data    ds                      ;Restore our data pointer
  261.           mov       si,OFFSET pcxFBUFF      ; and point back to the new pal
  262.  
  263.           call      pcxGetDisplay           ;Get the current display type
  264.           cmp       ax,0
  265.           jge       fxPC_getstruc           ;If no error, continue
  266.  
  267.           @SetRet   pcret,ax                ;Bad Display type
  268.           jmp       fxPC_exit               ; so exit
  269.  
  270. fxPC_getstruc:  
  271.  
  272.           push      ax                      ;Argument is display type
  273.           call      pcxGetDispStruc         ;Get the display structure (dx:ax)
  274.           cmp       ax,0
  275.           jae       fxPC_detproc            ;Successful?
  276.  
  277.           @SetRet   pcret,pcxERR_GENERAL    ;General error,
  278.           jmp       fxPC_exit               ; so exit
  279.  
  280. fxPC_detproc:  
  281.  
  282.           mov       di,ax                   ;Put returned pointer into regs
  283.           @@LoadSeg es,dx
  284.  
  285.           mov       bx,es:[di].dpal         ;Get the palette type
  286.           mov       pcpaltype,bx            ; and store
  287.  
  288.           cmp       bx,pal3                 ;EGA type palette?
  289.           je        fxPC_pal3               
  290.  
  291.           cmp       bx,pal4                 ;VGA type palette (16)?
  292.           je        fxPC_pal4
  293.  
  294.           cmp       bx,pal5                 ;VGA type palette (256)?
  295.           jne       fxPC_palerr
  296.           jmp       SHORT fxPC_pal5
  297.  
  298. fxPC_palerr:
  299.  
  300.           @SetRet   pcret,fxERR_BADPAL      ;No, so can't do anything
  301.           jmp       fxPC_exit
  302.  
  303. fxPC_pal3:
  304.  
  305.           mov       cx,pcrepeat             ;Get the repeat count
  306.  
  307.           cmp       cx,0                    ;If zero, break out early
  308.           jbe       fxPC_pal3exit
  309.  
  310. fxPC_pal3loop:
  311.  
  312.           push      cx                      ;Save outer loop count
  313.  
  314.           mov       cx,pctotal              ;Get number of regs to update
  315.  
  316.           mov       bx,pcstart              ;Get the starting number
  317.           add       bx,cx                   ; and build a pointer out of it
  318.           dec       bx
  319.  
  320.           mov       dl,ds:[si][bx]          ;Save final register
  321.  
  322. fxPC_pal3mod:
  323.  
  324.           mov       al,ds:[si][bx-1]        ;Get the previous register
  325.           mov       ds:[si][bx],al          ; and store
  326.  
  327.           dec       bx                      ;Bump pointer
  328.  
  329.           loop      fxPC_pal3mod
  330.  
  331.           mov       ds:[si][bx],dl          ;And wrap last to first
  332.  
  333.           mov       ax,pcpaltype            ;Now set the palette
  334.           push      ax
  335.           push      ds                      
  336.           push      si
  337.           call      fxSetPalette
  338.  
  339.           mov       ax,pcdelay              ;Delay
  340.           push      ax
  341.           call      fxEffectDelay
  342.                     
  343.           pop       cx                      ;Restore outer loop count
  344.  
  345.           loop      fxPC_pal3loop
  346.  
  347. fxPC_pal3exit:
  348.  
  349.           @SetRet   pcret,fxSUCCESS
  350.           jmp       SHORT fxPC_exit
  351.  
  352. fxPC_pal4:
  353.  
  354. fxPC_pal5:
  355.  
  356.           mov       cx,pcrepeat             ;Get the repeat count
  357.  
  358.           cmp       cx,0                    ;If zero, break out early
  359.           jbe       fxPC_pal4exit
  360.  
  361. fxPC_pal4loop:
  362.  
  363.           push      cx                      ;Save outer loop count
  364.  
  365.           mov       cx,pctotal              ;Get number of regs to update
  366.           mov       ax,cx                   ; and multiply by triples
  367.           shl       ax,1
  368.           add       cx,ax                   
  369.  
  370.           mov       bx,pcstart              ;Get the starting number
  371.           dec       bx
  372.  
  373.           mov       ax,bx                   ;We point at triples,
  374.           shl       ax,1                    ; so mult by two 
  375.           add       bx,ax                   ; and add to get three
  376.  
  377.           add       bx,cx                   ;Build a pointer out of it
  378.  
  379.           mov       dl,ds:[si][bx]          ;Save final register
  380.           push      dx
  381.           mov       dl,ds:[si][bx+1]
  382.           push      dx
  383.           mov       dl,ds:[si][bx+2]
  384.           push      dx
  385.  
  386. fxPC_pal4mod:
  387.  
  388.           mov       al,ds:[si][bx-1]        ;Get the previous register
  389.           mov       ds:[si][bx+2],al        ; and store
  390.  
  391.           dec       bx                      ;Bump pointer
  392.  
  393.           loop      fxPC_pal4mod
  394.  
  395.           pop       dx                      ;And wrap last to first
  396.           mov       ds:[si][bx+2],dl          
  397.           pop       dx                      
  398.           mov       ds:[si][bx+1],dl          
  399.           pop       dx                      
  400.           mov       ds:[si][bx],dl          
  401.  
  402.           mov       ax,pcpaltype            ;Now set the palette
  403.           push      ax
  404.           push      ds   
  405.           push      si
  406.           call      fxSetPalette
  407.  
  408.           mov       ax,pcdelay              ;Delay
  409.           push      ax
  410.           call      fxEffectDelay
  411.                     
  412.           pop       cx                      ;Restore outer loop count
  413.  
  414.           loop      fxPC_pal4loop
  415.  
  416. fxPC_pal4exit:
  417.  
  418.           @SetRet   pcret,fxSUCCESS
  419.  
  420. fxPC_exit:
  421.  
  422.           @Exit     pcret,pcparm            ;Return
  423.  
  424. fxPaletteCycle      ENDP
  425.  
  426. ;**********
  427.  
  428. ;
  429. ; This procedure fades a given set of palette registers by the given      
  430. ; increment, repeatedly. It then delays for the specified amount of ms. 
  431. ;
  432. ;
  433.  
  434. ;Define variable locations on the stack  (pascal model)
  435. pfpalseg  equ       <[bp+18]>               ;Palette pointer
  436. pfpalofs  equ       <[bp+16]>        
  437. pfstart   equ       <[bp+14]>               ;Starting palette number
  438. pftotal   equ       <[bp+12]>               ;Total number to fade 
  439. pfinc     equ       <[bp+10]>               ;Increment value          
  440. pfrepeat  equ       <[bp+ 8]>               ;Repeat value
  441. pfdelay   equ       <[bp+ 6]>               ;Time Delay    
  442. pfparm    equ       14
  443.  
  444. ;Define local variables
  445. pfret     equ       <[bp- 2]>               ;Return code
  446. pfpaltype equ       <[bp- 4]>               ;Palette type
  447. pflocal   equ       4                       ;Total local space needed
  448.  
  449. fxPaletteFade       PROC FAR
  450.  
  451.           @Entry    pflocal                 ;Set up frame and save regs
  452.  
  453.           @@LoadSeg ds,pfpalseg             ;Point to the palette
  454.           mov       si,pfpalofs
  455.  
  456.           @@Data    es                      ; and use the toolkit buffer
  457.           mov       di,OFFSET pcxFBUFF
  458.  
  459.           mov       cx,800                  ;Copy 800 bytes, regardless
  460.           rep       movsb
  461.  
  462.           @@Data    ds                      ;Restore our data pointer
  463.           mov       si,OFFSET pcxFBUFF      ; and point back to the new pal
  464.  
  465.           call      pcxGetDisplay           ;Get the current display type
  466.           cmp       ax,0
  467.           jge       fxPF_getstruc           ;If no error, continue
  468.  
  469.           @SetRet   pfret,ax                ;Bad Display type
  470.           jmp       fxPF_exit               ; so exit
  471.  
  472. fxPF_getstruc:  
  473.  
  474.           push      ax                      ;Argument is display type
  475.           call      pcxGetDispStruc         ;Get the display structure (dx:ax)
  476.           cmp       ax,0
  477.           jae       fxPF_detproc            ;Successful?
  478.  
  479.           @SetRet   pfret,pcxERR_GENERAL    ;General error,
  480.           jmp       fxPF_exit               ; so exit
  481.  
  482. fxPF_detproc:  
  483.  
  484.           mov       di,ax                   ;Put returned pointer into regs
  485.           @@LoadSeg es,dx
  486.  
  487.           mov       bx,es:[di].dpal         ;Get the palette type
  488.           mov       pfpaltype,bx            ; and store
  489.  
  490.           cmp       bx,pal4                 ;VGA type palette (16)?
  491.           je        fxPF_pal4
  492.  
  493.           cmp       bx,pal5                 ;VGA type palette (256)?
  494.           jne       fxPF_palerr
  495.           jmp       SHORT fxPF_pal5
  496.  
  497. fxPF_palerr:
  498.  
  499.           @SetRet   pfret,fxERR_BADPAL      ;No, so can't do anything
  500.           jmp       fxPF_exit
  501.  
  502. fxPF_pal4:
  503.  
  504. fxPF_pal5:
  505.  
  506.           @@LoadSeg es,pfpalseg             ;Point to the palette
  507.           mov       di,pfpalofs
  508.  
  509.           mov       cx,pfrepeat             ;Get the repeat count
  510.  
  511.           cmp       cx,0                    ;If zero, break out early
  512.           jne       fxPF_chktype
  513.  
  514.           jmp       fxPF_pal4exit
  515.  
  516. fxPF_chktype:
  517.  
  518.           cmp       cx,fxFADEOUT            ;Fading out?
  519.           jne       fxPF_chkin   
  520.  
  521.           mov       ax,64                   ;Get the maximum repeat
  522.           mov       bx,pfinc                ; and divide by the increment
  523.           div       bl
  524.  
  525.           xor       ah,ah                   ;Store as the count
  526.           mov       cx,ax
  527.  
  528. fxPF_chkin:
  529.  
  530.           cmp       cx,fxFADEIN             ;Fading in?
  531.           jne       fxPF_pal4loop
  532.  
  533.           mov       cx,pftotal              ;Get number of regs to update
  534.           mov       ax,cx                   ; and multiply by triples
  535.           shl       ax,1
  536.           add       cx,ax                   
  537.  
  538.           mov       bx,pfstart              ;Get the starting number
  539.  
  540.           mov       ax,bx                   ;We point at triples,
  541.           shl       ax,1                    ; so mult by two 
  542.           add       bx,ax                   ; and add to get three
  543.  
  544.           add       bx,cx                   ;Build a pointer out of it
  545.  
  546.           xor       ax,ax
  547.  
  548. fxPF_zero:
  549.  
  550.           mov       ds:[si][bx],al          ;Zero the register
  551.           dec       bx
  552.           loop      fxPF_zero
  553.  
  554.           mov       ax,64                   ;Get the maximum repeat
  555.           mov       bx,pfinc                ; and divide by the increment
  556.           div       bl
  557.  
  558.           xor       ah,ah                   ;Store as the count
  559.           mov       cx,ax
  560.  
  561. fxPF_pal4loop:
  562.  
  563.           push      cx                      ;Save outer loop count
  564.  
  565.           mov       cx,pftotal              ;Get number of regs to update
  566.           mov       ax,cx                   ; and multiply by triples
  567.           shl       ax,1
  568.           add       cx,ax                   
  569.  
  570.           mov       bx,pfstart              ;Get the starting number
  571.  
  572.           mov       ax,bx                   ;We point at triples,
  573.           shl       ax,1                    ; so mult by two 
  574.           add       bx,ax                   ; and add to get three
  575.  
  576.           add       bx,cx                   ;Build a pointer out of it
  577.  
  578. fxPF_pal4mod:
  579.  
  580.           mov       al,ds:[si][bx]          ;Get the register
  581.           mov       dl,pfinc                ;Get the increment
  582.  
  583.           cmp       WORD PTR pfrepeat,fxFADEOUT  ;Fading out?
  584.           jne       fxPF_pal4chkin
  585.  
  586.           cmp       al,0                    ;Already zero?
  587.           je        fxPF_pal4set
  588.  
  589.           sub       al,dl                   ;If not, bump down
  590.           jns       fxPF_pal4set
  591.  
  592.           mov       al,0
  593.           jmp       SHORT fxPF_pal4set
  594.  
  595. fxPF_pal4chkin:
  596.  
  597.           cmp       WORD PTR pfrepeat,fxFADEIN   ;Fading in?
  598.           jne       fxPF_pal4norm
  599.  
  600.           cmp       al,es:[di][bx]          ;Are we at max yet?
  601.           je        fxPF_pal4set
  602.  
  603.           add       al,dl                   ;If not, bump up
  604.           cmp       al,es:[di][bx]
  605.           jbe       fxPF_pal4set
  606.  
  607.           mov       al,es:[di][bx]
  608.           jmp       SHORT fxPF_pal4set
  609.  
  610. fxPF_pal4norm:
  611.  
  612.           add       al,dl                   ; add from current pal value
  613.  
  614. fxPF_pal4set:
  615.  
  616.           mov       ds:[si][bx],al          ; and store
  617.  
  618. fxPF_pal4chkloop:
  619.  
  620.           dec       bx                      ;Bump pointer
  621.  
  622.           loop      fxPF_pal4mod
  623.  
  624.           mov       ax,pfpaltype            ;Now set the palette
  625.           push      ax
  626.           push      ds   
  627.           push      si
  628.           call      fxSetPalette
  629.  
  630.           mov       ax,pfdelay              ;Delay
  631.           push      ax
  632.           call      fxEffectDelay
  633.                     
  634.           pop       cx                      ;Restore outer loop count
  635.  
  636.           loop      fxPF_pal4loop
  637.  
  638. fxPF_pal4exit:
  639.  
  640.           @SetRet   pfret,fxSUCCESS
  641.  
  642. fxPF_exit:
  643.  
  644.           @Exit     pfret,pfparm            ;Return
  645.  
  646. fxPaletteFade       ENDP
  647.  
  648.   @EndCode
  649.  
  650.           END
  651.  
  652.