;license:MIT ;(c) 2021 by 4am !cpu 6502 !to "build/FX.INDEXED/SHR.FADEIN",plain *=$A000 color = $F7 ; byte fracv = $F8 ; byte fracv_hi = $F9 incv = $FA ; byte src = $FC ; word dst = $FE ; word palettes = $BD00 ; $200 bytes !source "src/fx/macros.a" sta $C005 ldy #0 ; copy pixel data sty src sty dst lda #$20 sta src+1 ldx #$7D - lda (src), y sta (src), y iny bne - inc src+1 dex bne - ;Y=0 - lda $9D00, y ; copy SCB sta $9D00, y iny bne - sta $C004 - lda $9E00, y ; Back up palettes to alternate location in main memory. sta palettes, y ; The CPU in a 64K Apple ][+/][e w/VidHD ignores STA $C004/5 lda $9F00, y ; but VidHD respects them, so we can't clear the palettes sta palettes+$100, y ; in auxmem until we copy them in mainmem. Whee. iny bne - sta $C005 lda #0 - sta $9E00, y ; now clear the palettes sta $9F00, y iny bne - sta $C004 lda #>palettes sta src+1 ldx #$0F ; palette counter ($0F -> $00, not used as index) rb_palette_loop ldy #$00 ; byte offset within palette (00 -> 1F, used as index) rb_color_loop lda #$00 sta fracv sta fracv_hi sta color lda src sta dst lda src+1 sec sbc #>(palettes-$4000) sta dst+1 lda (src), y ; get final Red or Blue value for this color in this palette asl ; Red or Blue value is bits 0-3, shift them into bits 4-7 asl asl asl sta incv rb_step_loop lda fracv clc adc incv sta fracv bcc + lda fracv_hi eor #$01 sta fracv_hi bne + inc color + lda color sta (dst), y inc dst+1 inc dst+1 bpl rb_step_loop iny cpy #$20 bcc rb_color_loop lda src clc adc #$20 sta src bcc + inc src+1 + dex bpl rb_palette_loop lda #>palettes sta src+1 ldx #$0F ; palette counter ($0F -> $00, not used as index) g_palette_loop ldy #$00 ; byte offset within palette (00 -> 1E by 2, used as index) g_color_loop lda #$00 sta fracv sta fracv_hi sta color lda src sta dst lda src+1 sec sbc #>(palettes-$4000) sta dst+1 lda (src), y ; get final Green value for this color in this palette and #$F0 ; Green value is bits 4-7, mask out other bits sta incv g_step_loop lda fracv clc adc incv sta fracv bcc + lda fracv_hi eor #$01 sta fracv_hi bne + lda color clc adc #$10 sta color + lda color ora (dst), y ; keep existing Blue value in bits 0-3 sta (dst), y inc dst+1 inc dst+1 bpl g_step_loop iny iny ; high nibble of second color byte is always 0 so skip it cpy #$20 bcc g_color_loop lda src clc adc #$20 sta src bcc + inc src+1 + dex bpl g_palette_loop ldx #$44 stx copy1+2 inx stx copy2+2 lda #$40 sta incv ldx #$1D ldy #$00 copyloop jsr WaitForVBL sta $C005 copy1 lda $4400, y ; SMC sta $9E00, y copy2 lda $4500, y ; SMC sta $9F00, y iny bne copy1 sta $C004 inc copy1+2 inc copy1+2 inc copy2+2 inc copy2+2 lda incv jsr WaitForKeyWithTimeout bmi exit dec incv dec incv dex bpl copyloop exit jmp UnwaitForVBL !source "src/wait.a"