Guest User

Untitled

a guest
Jul 19th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Palette_DisplayedBuffer:    equ $FF0100
  2. Palette_TargetBuffer:       equ $FF0180
  3. Palette_Status:             equ $FF0200
  4.  
  5. ;---------------------------------------------------------------------------------------------------
  6. ; Loads a palette to the buffer.
  7. ;
  8. ; Inputs:
  9. ;     - d0: Palette number
  10. ;
  11. ; Output:
  12. ;     None
  13.  
  14. PalLoad:
  15.         lea     PalettePointers, a0                 ; Load palette pointer table address to a0.
  16.         lsl.b   #3, d0                              ; Multiply d0 by eight.
  17.         add.l   d0, a0                              ; Add to the pointer to get the address of the palette.
  18.        
  19.         move.b  4(a0), d0                           ; Copy the size of the palette to d0.
  20.         lsr.b   #1, d0                              ; Divide by two
  21.         subq.b  #1, d0                              ; Subtract one.
  22.        
  23.         lea     Palette_TargetBuffer, a1            ; Load the target buffer to a0.
  24.         moveq   #0, d1                              ; Clear d1.
  25.         move.b  6(a0), d1                           ; Copy palette row to d1.
  26.         lsl.b   #5, d1                              ; Multiply by $20
  27.         add.l   d1, a1                              ; Add to the pointer.
  28.        
  29.         move.l  (a0), a2                            ; Load palette offset to a2.
  30.        
  31. @copyPaletteWord:
  32.         move.w  (a2)+, (a1)+                        ; Copy a word of palette data.
  33.         dbf     d0, @copyPaletteWord                ; Loop until all palette data has been copied.
  34.        
  35.         rts
  36.        
  37. ;---------------------------------------------------------------------------------------------------
  38. ; Copies the current display buffer to the VDP through the use of DMA.
  39. ;
  40. ; Inputs:
  41. ;     None
  42. ;
  43. ; Output:
  44. ;     None
  45.  
  46. TransferPaletteToCRAM:
  47.         btst    #0, Palette_Status                  ; Do we need to reload the palette data?
  48.         beq.s   @noPaletteRefresh                   ; If not, branch.
  49.  
  50.         lea     $C00004, a6                         ; Load the VDP data port to a0
  51.         move.l  #((((($0080/$02)<<$08)&$FF0000)+(($0080/$02)&$FF))+$94009300),(a6)
  52.         move.l  #((((((Palette_DisplayedBuffer&$FFFFFF)/$02)<<$08)&$FF0000)+(((Palette_DisplayedBuffer&$FFFFFF)/$02)&$FF))+$96009500),(a6)
  53.         move.l  #(((((Palette_DisplayedBuffer&$FFFFFF)/$02)&$FF0000)+$97000000)+(($C0000000>>$10)&$FFFF)),(a6)
  54.         move.w  #(($C0000000&$FF7F)|$80),(a6)
  55.        
  56.         bclr    #0, Palette_Status                  ; Clear the "needs reload" bit
  57.        
  58. @noPaletteRefresh:
  59.         rts
  60.        
  61. ;---------------------------------------------------------------------------------------------------
  62. ; Fades the currently displayed palette to black.
  63. ;
  64. ; Inputs:
  65. ;     None
  66. ;
  67. ; Output:
  68. ;     None
  69.  
  70. Pal_FadeFrom:
  71.         moveq   #0, d2                              ; Clear d2
  72.         moveq   #$7, d0                             ; Loop over every entry in the buffer 7 times.
  73.        
  74. @processFadeOut:
  75.         lea     Palette_DisplayedBuffer, a0         ; Load the displayed buffer to a0 (a0 gets destroyed constantly)
  76.        
  77. @processPaletteEntry:
  78.         move.w  (a0), d2                            ; Copy the palette value to d2.
  79.         move.w  d2, -(sp)                           ; Back up d2 to the stack.
  80.         moveq   #0, d3                              ; Clear d3.
  81.        
  82.         bsr.w   FadeOut_Blue                        ; Fade out blue.
  83.         bsr.w   FadeOut_Green                       ; Fade out green.
  84.         bsr.w   FadeOut_red                         ; Fade out red.
  85.        
  86.         move.w  d3, (a0)+                           ; Copy back into the display buffer.
  87.        
  88.         dbf     d1, @processPaletteEntry            ; Keep looping through all entries in the palette buffer.
  89.  
  90.         stop    #$2500                              ; Wait for VBlank.
  91.  
  92.         dbf     d0, @processFadeOut                 ; Loop through all entries in the buffer.
  93.         rts                                         ; Return to caller.
  94.        
  95. FadeOut_Blue:
  96.         and.w   #$0F00, d2                          ; Get the blue channel by itself.
  97.         cmp.w   #$0000, d2                          ; Has the blue channel been 0'd out yet?
  98.         beq.s   @bReturn                            ; If so, return.
  99.        
  100.         sub.w   #$0200, d2                          ; Subtract d2.
  101.        
  102. @bReturn:
  103.         add.w   d2, d3                              ; Add to the final result.
  104.         rts
  105.        
  106.        
  107. FadeOut_Green:
  108.         move.w  (sp), d2                            ; Copy colour from the stack.
  109.  
  110.         and.w   #$00F0, d2                          ; Get the green channel by itself.
  111.         cmp.w   #$0000, d2                          ; Has the green channel been 0'd out yet?
  112.         beq.s   @gReturn                            ; If so, return.
  113.        
  114.         sub.w   #$0020, d2                          ; Subtract d2.
  115.  
  116. @gReturn:
  117.         add.w   d2, d3                              ; Add to the final result.
  118.         rts
  119.        
  120.        
  121. FadeOut_Red:
  122.         move.w  -(sp), d2                           ; Copy colour from the stack and decrement pointer.
  123.  
  124.         and.w   #$000F, d2                          ; Get the green channel by itself.
  125.         cmp.w   #$0000, d2                          ; Has the green channel been 0'd out yet?
  126.         beq.s   @rReturn                            ; If so, return.
  127.        
  128.         sub.w   #$0002, d2                          ; Subtract d2.
  129.  
  130. @rReturn:
  131.         add.w   d2, d3                              ; Add to the final result.
  132.         rts
Add Comment
Please, Sign In to add comment