Guest User

Untitled

a guest
May 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; =========================================================================
  3. ; Pallete Fading Engine
  4. ; (C) 2011, Vladikcomper
  5. ; =========================================================================
  6.  
  7. *sysPallete     equ $FFFFFB00   ;   Pallete Array
  8. *sysPalleteBuff     equ $FFFFFB80   ;   Target Pallete Array
  9.  
  10. PalEngine_FadeLen   equ $FFFFF626   ; b Fading length (bytes - 1)
  11. PalEngine_FadeFactor    equ $FFFFF627   ; b Fade Factor (max = $10)
  12.  
  13. ; =========================================================================
  14.  
  15. ; =========================================================================
  16. ; -------------------------------------------------------------------------
  17. ; Cycle to fade to target palette
  18. ; -------------------------------------------------------------------------
  19.  
  20. Pal_FadeTo  move.b  #$40-1,(PalEngine_FadeLen).w    ; -- default length
  21.         lea (sysPallete).w,a0
  22.         lea $80(a0),a1
  23. Pal_FadeTo2                     ; -- custom length
  24.  
  25.         move.b  #$10,(PalEngine_FadeFactor).w   ; do $10 frames
  26.  
  27. @FadeLoop   move.b  #$12,($FFFFF62A).w
  28.         bsr.w   DelayProgram
  29.         subq.b  #1,(PalEngine_FadeFactor).w ; decrease fading power
  30.         bmi.s   @Return             ; if fading is done, quit
  31.         bsr.s   Pal_SingleFadeTo
  32.         bra.s   @FadeLoop
  33.  
  34. @Return     rts
  35.  
  36. ; =========================================================================
  37. ; -------------------------------------------------------------------------
  38. ; Perform fading to palette in a signle frame
  39. ; -------------------------------------------------------------------------
  40. ;   a0  - Current palette
  41. ;   a1  - Target palette
  42. ; -------------------------------------------------------------------------
  43.  
  44. Pal_SingleFadeTo
  45.         moveq   #0,d5
  46.         move.b  (PalEngine_FadeLen).w,d5
  47.         move.b  (PalEngine_FadeFactor).w,d0 ; d0 -> Fade Factor
  48.         andi.b  #$E,d0              ; make sure fade factor is correct
  49.         move.b  d0,d1
  50.         lsl.b   #4,d1               ; d1 -> Fade Factor (2nd channel)
  51.         lea (a0),a2             ; current active color
  52.         lea (a1),a3             ; current target color
  53.  
  54.     @ParseColors:
  55.         move.b  (a3)+,d2    ; d2 -> B
  56.         sub.b   d0,d2       ; d2 -> B' (faded)
  57.         bcc.s   @outB
  58.         moveq   #0,d2
  59.     @outB:  move.b  d2,(a2)+    ; output B'
  60.  
  61.         move.b  (a3)+,d2    ; d2 -> GR
  62.         move.b  d2,d3
  63.         andi.b  #$E0,d3     ; d3 -> G0
  64.         sub.b   d1,d3       ; d3 -> G'0
  65.         bcc.s   @endG
  66.         moveq   #0,d3
  67.     @endG:
  68.         andi.b  #$E,d2      ; d2 -> R
  69.         sub.b   d0,d2       ; d2 -> R'
  70.         bcc.s   @endR
  71.         moveq   #0,d2
  72.     @endR:
  73.         or.b    d2,d3       ; d3 -> G'R'
  74.         move.b  d3,(a2)+    ; output G'R'
  75.        
  76.         dbf d5,@ParseColors
  77.         rts
  78.  
  79. ; =========================================================================
  80. ; -------------------------------------------------------------------------
  81. ; Cycle to fade from screen
  82. ; -------------------------------------------------------------------------
  83.  
  84. Pal_FadeFrom    move.b  #$40-1,(PalEngine_FadeLen).w    ; -- default length
  85.         lea (sysPallete).w,a0
  86. Pal_FadeFrom2                       ; -- custom length
  87.  
  88.         moveq   #$10-1,d6           ; d6 -> do 16 frames
  89.  
  90. @FadeLoop   move.b  #$12,($FFFFF62A).w
  91.         bsr.w   DelayProgram
  92.         btst    #0,d6               ; is d6 odd?
  93.         beq.s   @NextFrame          ; if not, branch
  94.         bsr.s   Pal_SingleFadeFrom
  95.  
  96. @NextFrame  dbf d6,@FadeLoop
  97.         rts
  98.        
  99. ; =========================================================================
  100. ; -------------------------------------------------------------------------
  101. ; Perform fading to palette in a signle frame
  102. ; -------------------------------------------------------------------------
  103. ;   a0  - Current palette
  104. ; -------------------------------------------------------------------------
  105.  
  106. Pal_SingleFadeFrom
  107.         lea (a0),a2             ; current color
  108.         moveq   #0,d5
  109.         move.b  (PalEngine_FadeLen).w,d5
  110.  
  111.     @ParseColors:
  112.         tst.b   (a2)+       ; is B zero?
  113.         beq.s   @Green      ; if yes, branch
  114.         subq.b  #2,-1(a2)   ; decrease B
  115.  
  116.     @Green: move.b  (a2),d2     ; d2 -> GR
  117.         move.b  d2,d3
  118.         andi.b  #$E0,d2     ; d2 -> G0
  119.         beq.s   @Red
  120.         subi.b  #$20,d2
  121.  
  122.     @Red:   andi.b  #$E,d3      ; d3 -> 0R
  123.         beq.s   @GRout
  124.         subq.b  #2,d3
  125.  
  126.     @GRout: or.b    d2,d3
  127.         move.b  d3,(a2)+
  128.         dbf d5,@ParseColors
  129.  
  130.         rts
Add Comment
Please, Sign In to add comment