home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / crosfade / fade.asm < prev    next >
Assembly Source File  |  1994-09-28  |  7KB  |  256 lines

  1. %TITLE "moduleShell"
  2. ;---------------------------------------------------------------------
  3. ; CAUTION!
  4. ;      This module is written in Ideal model, meaning you need
  5. ;      Borland Turbo Assembler to compile it.
  6. ;------------------------------------------------------------------------
  7.  
  8.        IDEAL
  9.        P286
  10.        include "model.inc"
  11.  
  12.       DATASEG
  13.  
  14.  
  15. PAL_SIZE EQU 768
  16.  
  17.  
  18.        CODESEG
  19.  
  20.  
  21.        PUBLIC   _setpal
  22.        PUBLIC   _sub_palette,_fade_between_once
  23.        PUBLIC   _fill_pal,_copyPal
  24.  
  25.  
  26.  
  27. PROC _setpal
  28. ;-----------------------------------------------------------------
  29. ; void setpal(void far *pal)
  30. ; This function simply updates hardware palette using the data
  31. ; stored in char pal[PAL_SIZE]
  32. ;  (PAL_SIZE=768)
  33. ;-----------------------------------------------------------------
  34. ARG pal:dword
  35.  
  36.      push      bp
  37.      mov       bp,sp
  38.      push      ds
  39.      push      di
  40.      push      si
  41.      lds      si,[pal]
  42.      call      SETPAL
  43.      pop       si
  44.      pop       di
  45.      pop       ds
  46.      pop       bp
  47.      ret
  48. ENDP _setpal
  49.  
  50.  
  51. PROC _sub_palette
  52. ;----------------------------------------------------------------------
  53. ; sub_palette(void *pal,void far *pal_dest)
  54. ; This routine prepares the palettes for fade_between_once()
  55. ; function.
  56. ; WARNING: pal points to char array of 768*2 bytes, not 768 bytes
  57. ;----------------------------------------------------------------------
  58. ARG pal:dword,pal_dest:dword
  59.       push   bp
  60.       mov    bp,sp
  61.       push   ds
  62.       push   di
  63.       push   si
  64.  
  65.       lds    si,[pal]          ;ds:si points to pal[]
  66.       les    di,[pal_dest]     ;es:di points to pal_dest[]
  67.  
  68.       mov    cx,PAL_SIZE       ; the following loop is basically
  69. @@l:  lodsb                    ; for(n=0;n<768;++n)
  70.       sub    [es:di],al        ;  pal_dest[n]=pal_dest[n]-pal[n];
  71.       inc    di                ;
  72.       loop   @@l
  73.  
  74.       mov    cx,PAL_SIZE/2     ; the following loop is equivalent to
  75.       xor    ax,ax
  76. @@l2: mov    [ds:si],ax        ; for(n=0;n<768;++n)
  77.       inc    si                ;  pal[n+PAL_SIZE]=0;
  78.       inc    si
  79.       loop   @@l2
  80.  
  81.       pop     si
  82.       pop     di
  83.       pop     ds
  84.       pop     bp
  85.       ret
  86. ENDP _sub_palette
  87.  
  88.  
  89.  
  90.  
  91. PROC _fade_between_once
  92. ;-------------------------------------------------------------------
  93. ; fade_between_once(void far *pal,void far *pal_dest)
  94. ; call sub_palette first
  95. ; Which will destroy original values of pal_dest,
  96. ;    but it's a necessary step.
  97. ; After calling it 63 times,the content of pal[768] will become
  98. ; identical to the original values of pal_dest anyway :)
  99. ;-------------------------------------------------------------------
  100. ARG  pal:dword,pal_dest:dword
  101.      push   bp
  102.      mov    bp,sp
  103.      push   ds
  104.      push   di
  105.      push   si
  106.      lds    si,[pal]
  107.      les    di,[pal_dest]
  108.  
  109.      cld
  110.      push   si
  111.  
  112.       mov     cx,PAL_SIZE
  113. fl2:                         ; increase the value of pallettes
  114.       mov     bl,[es:di]     ; es:di = dest_pal
  115.       cmp     bl,0
  116.       jl      fl4            ; if bl>0 then goto fl4
  117.  
  118.       add     [PAL_SIZE+si],bl
  119.       jmp     fl3
  120.  
  121. fl4:  neg     bl
  122.       add     [PAL_SIZE+si],bl
  123. fl5:  cmp     [byte ptr PAL_SIZE+si],63
  124.       jb      fl7
  125.       dec     [byte ptr si]
  126.       sub     [byte ptr PAL_SIZE+si],63
  127.       jmp     fl7
  128.  
  129. fl3:  cmp     [byte ptr PAL_SIZE+si],63
  130.       jb      fl7      ;
  131.       inc     [byte ptr si] ; increase by one
  132.       sub     [byte ptr PAL_SIZE+si],63
  133. fl7:  inc     di
  134.       inc     si
  135.       loop    fl2
  136.  
  137.  
  138.      pop     si
  139.      call    Setpal
  140.  
  141.      pop     si
  142.      pop     di
  143.      pop     ds
  144.      pop     bp
  145.      ret
  146. ENDP _fade_between_once
  147.  
  148.  
  149.  
  150. ;-------------------------------------------------------------------------
  151. ; update the hardware palette
  152. ; input: ds:si points to palette array
  153. ;-------------------------------------------------------------------------
  154.  
  155.  
  156. PROC SETPAL
  157.       mov       bh,0               ; bh=# of the first palette color to
  158.                    ; update.
  159.       mov       bl,2               ;This is the loop index.
  160.                    ;In the following codes, we are updating
  161.                    ;128 color at a time. Therefore, we need
  162.                    ;a loop that runs twice in order to update
  163.                    ;all 256 colors.
  164.  
  165.     mov     cx,128*3         ; di=128(the number of colors to update)*3
  166.  
  167. PROC SETPAL2
  168. s:
  169.     mov dx, 03DAh               ; CRT controller input status 1 register
  170. v1:
  171.     in    al, dx
  172.     test   al,08h
  173.     jnz    v1                     ; wait until vertical retrace starts
  174. v2:
  175.     in     al, dx
  176.     test   al,08h                 ; wait until vertical retrace ends
  177.         jz     v2
  178.  
  179.  ;--------- We have done waiting. Now let's update the palette
  180.     mov     al,bh            ; get first color # to process into al
  181.     mov     dx, 03c8h        ; DAC palette index register
  182.  
  183.     push    cx
  184.     out     dx, al           ; Write the register number to the dac
  185.     inc     dx
  186.     rep     outsb
  187.     pop     cx
  188.  
  189.     add     bh,128           ; color index=color index+128
  190.     dec     bl
  191.     jnz     s
  192.  
  193.       ret
  194. ;----------------------------------------
  195.  
  196. ENDP SETPAL2
  197.  
  198.  
  199.  
  200.  
  201. PROC _fill_pal
  202. ;-------------------------------------------------------------
  203. ; fill_pal(void far *pal, char red, char green, char blue);
  204. ; fills the palette array with the color data given
  205. ; does not update hardware palette
  206. ;-------------------------------------------------------------
  207. ARG pal:dword, red:byte, green:byte,blue:byte
  208.       push   bp
  209.       mov    bp,sp
  210.       push   di
  211.       les    di,[pal]
  212.       cld
  213.       mov    cx,PAL_SIZE/3
  214.       mov    al,[red]
  215.       mov    ah,[green]
  216.       mov    bl,[blue]
  217. @@fpl:mov    [es:di],al
  218.       mov    [es:di+1],ah
  219.       mov    [es:di+2],bl
  220.       add    di,3
  221.       loop   @@fpl
  222.       pop    di
  223.       pop    bp
  224.       ret
  225. ENDP _fill_pal
  226.  
  227.  
  228. PROC _copyPal
  229. ;----------------------------------------------------------------
  230. ; copyPal(void far *source,void far *dest:dword)
  231. ;
  232. ; both *source and *dest points to arrays of 768 bytes (chars)
  233. ; I know there are C functions out there to copy strings. But
  234. ; I wrote this anyway. What the heck, it only took me a minute.
  235. ;----------------------------------------------------------------
  236. ARG source:dword,dest:dword
  237.       push   bp
  238.       mov    bp,sp
  239.       push   ds
  240.       push   di
  241.       push   si
  242.  
  243.       cld
  244.       les    di,[dest]
  245.       lds    si,[source]
  246.       mov    cx,PAL_SIZE
  247.       rep    movsb
  248.       pop    si
  249.       pop    di
  250.       pop    ds
  251.       pop    bp
  252.       ret
  253. ENDP _copyPal
  254.  
  255.       END                     ; End of module
  256.