Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Palette_DisplayedBuffer: equ $FF0100
- Palette_TargetBuffer: equ $FF0180
- Palette_Status: equ $FF0200
- ;---------------------------------------------------------------------------------------------------
- ; Loads a palette to the buffer.
- ;
- ; Inputs:
- ; - d0: Palette number
- ;
- ; Output:
- ; None
- PalLoad:
- lea PalettePointers, a0 ; Load palette pointer table address to a0.
- lsl.b #3, d0 ; Multiply d0 by eight.
- add.l d0, a0 ; Add to the pointer to get the address of the palette.
- move.b 4(a0), d0 ; Copy the size of the palette to d0.
- lsr.b #1, d0 ; Divide by two
- subq.b #1, d0 ; Subtract one.
- lea Palette_TargetBuffer, a1 ; Load the target buffer to a0.
- moveq #0, d1 ; Clear d1.
- move.b 6(a0), d1 ; Copy palette row to d1.
- lsl.b #5, d1 ; Multiply by $20
- add.l d1, a1 ; Add to the pointer.
- move.l (a0), a2 ; Load palette offset to a2.
- @copyPaletteWord:
- move.w (a2)+, (a1)+ ; Copy a word of palette data.
- dbf d0, @copyPaletteWord ; Loop until all palette data has been copied.
- rts
- ;---------------------------------------------------------------------------------------------------
- ; Copies the current display buffer to the VDP through the use of DMA.
- ;
- ; Inputs:
- ; None
- ;
- ; Output:
- ; None
- TransferPaletteToCRAM:
- btst #0, Palette_Status ; Do we need to reload the palette data?
- beq.s @noPaletteRefresh ; If not, branch.
- lea $C00004, a6 ; Load the VDP data port to a0
- move.l #((((($0080/$02)<<$08)&$FF0000)+(($0080/$02)&$FF))+$94009300),(a6)
- move.l #((((((Palette_DisplayedBuffer&$FFFFFF)/$02)<<$08)&$FF0000)+(((Palette_DisplayedBuffer&$FFFFFF)/$02)&$FF))+$96009500),(a6)
- move.l #(((((Palette_DisplayedBuffer&$FFFFFF)/$02)&$FF0000)+$97000000)+(($C0000000>>$10)&$FFFF)),(a6)
- move.w #(($C0000000&$FF7F)|$80),(a6)
- bclr #0, Palette_Status ; Clear the "needs reload" bit
- @noPaletteRefresh:
- rts
- ;---------------------------------------------------------------------------------------------------
- ; Fades the currently displayed palette to black.
- ;
- ; Inputs:
- ; None
- ;
- ; Output:
- ; None
- Pal_FadeFrom:
- moveq #0, d2 ; Clear d2
- moveq #$7, d0 ; Loop over every entry in the buffer 7 times.
- @processFadeOut:
- lea Palette_DisplayedBuffer, a0 ; Load the displayed buffer to a0 (a0 gets destroyed constantly)
- @processPaletteEntry:
- move.w (a0), d2 ; Copy the palette value to d2.
- move.w d2, -(sp) ; Back up d2 to the stack.
- moveq #0, d3 ; Clear d3.
- bsr.w FadeOut_Blue ; Fade out blue.
- bsr.w FadeOut_Green ; Fade out green.
- bsr.w FadeOut_red ; Fade out red.
- move.w d3, (a0)+ ; Copy back into the display buffer.
- dbf d1, @processPaletteEntry ; Keep looping through all entries in the palette buffer.
- stop #$2500 ; Wait for VBlank.
- dbf d0, @processFadeOut ; Loop through all entries in the buffer.
- rts ; Return to caller.
- FadeOut_Blue:
- and.w #$0F00, d2 ; Get the blue channel by itself.
- cmp.w #$0000, d2 ; Has the blue channel been 0'd out yet?
- beq.s @bReturn ; If so, return.
- sub.w #$0200, d2 ; Subtract d2.
- @bReturn:
- add.w d2, d3 ; Add to the final result.
- rts
- FadeOut_Green:
- move.w (sp), d2 ; Copy colour from the stack.
- and.w #$00F0, d2 ; Get the green channel by itself.
- cmp.w #$0000, d2 ; Has the green channel been 0'd out yet?
- beq.s @gReturn ; If so, return.
- sub.w #$0020, d2 ; Subtract d2.
- @gReturn:
- add.w d2, d3 ; Add to the final result.
- rts
- FadeOut_Red:
- move.w -(sp), d2 ; Copy colour from the stack and decrement pointer.
- and.w #$000F, d2 ; Get the green channel by itself.
- cmp.w #$0000, d2 ; Has the green channel been 0'd out yet?
- beq.s @rReturn ; If so, return.
- sub.w #$0002, d2 ; Subtract d2.
- @rReturn:
- add.w d2, d3 ; Add to the final result.
- rts
Add Comment
Please, Sign In to add comment