User Tools

Site Tools


notes:atari:rainbow

Atari Rainbows

Here are a few examples of a rainbow effect on Atari 8-bit.

Example: Simple static rainbow.

; Simple static rainbow.
 
DMACTLS = $22F ; DMA control
 
COLBK	= $D01A	; background color
VCOUNT	= $D40B ; vertical counter
 
        ORG $2000
 
start	LDA #0
        STA DMACTLS
 
loop	LDA VCOUNT
        STA COLBK
        JMP loop
 
        RUN start

Example: 128 colors in the graphics mode BASIC 0. It was originally published in the Polish magazine “Komputer” in October, 1988 in the column “Mikroprogramy dla Atari XE/XL” on page 16.

; 128 colors in the graphics mode BASIC 0
 
VDSLST	= $200	; vector for a DLI procedure 
DLIST	= $230  ; vector for the ANTIC display list
COLPF2	= $D018 ; color and luminance of playfield two (710)
WSYNC 	= $D40A	; wait for horizontal synchronization
NMIEN   = $D40E ; NMI enable/disable
 
dl	= $C8 	; a temporary location to keep the address of the ANTIC display list
 
	ORG $0600
 
        ; Copy the address of the display list to a temporary location.
start   LDA DLIST
        STA dl
        LDA DLIST+1
        STA dl+1
 
        ; Modify the display list to enable DLI.
	; The display list in the graphics mode BASIC 0:
	; 112 112 112 66 64 156 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 65 32 156
        LDY #12		; skip the header of the display list and a few top lines
	LDA #130	; 2 (mode 0) + 128 (bit 7 - enable DLI starting with the next line)
	STA (dl),Y
 
	; Set the vector of our DLI procedure.
	LDA <proc
	STA VDSLST
	LDA >proc
	STA VDSLST+1
 
	; Enable DLIs.
	LDA #192
	STA NMIEN
 
	; Here we're going forever in a loop. The original program was returning to BASIC.
forever	JMP forever
 
	; The user-defined DLI procedure that changes the background color of scan lines.
proc    PHA
        TXA
        PHA
 
        LDX #0
loop	STA WSYNC
	STX COLPF2
	INX
	INX
	BNE loop
 
        PLA
        TAX
        PLA
        RTI
 
	RUN start

Example: The “famous” Atari rainbow (animated):

; Animated rainbow.
 
VDSLST	= $200	; vector for a DLI procedure 
DLIST	= $230  ; vector for the ANTIC display list
COLPF2	= $D018 ; color and luminance of playfield two (710)
WSYNC 	= $D40A	; wait for horizontal synchronization
NMIEN   = $D40E ; NMI enable/disable
 
dl	= $C8 	; a temporary location to keep the address of the ANTIC display list
col	= $CA
 
	ORG $0600
 
start	; Reset variables.        
        LDA #0
        STA col
 
        ; Copy the address of the display list to a temporary location.
	LDA DLIST
        STA dl
        LDA DLIST+1
        STA dl+1
 
        ; Modify the display list to enable DLI.
        LDY #2
	LDA #112+128	; 112 + 128 (bit 7 - enable DLI)
	STA (dl),Y
 
	; Set the vector of our DLI procedure.
	LDA <proc
	STA VDSLST
	LDA >proc
	STA VDSLST+1
 
	; Enable DLIs.
	LDA #192
	STA NMIEN
 
forever	JMP forever
 
	; The user-defined DLI procedure.
proc    PHA
        TXA
        PHA
        TYA
        PHA
 
 	LDY #0
        LDX col
loop	STA WSYNC
	STX COLPF2
	INX
	INY
	CPY #192	; 24 rows x 8 lines in each row = 192  
	BNE loop
 
 	INC col
 
 	PLA
 	TAY
        PLA
        TAX
        PLA
        RTI
 
	RUN start

Example: Rainbow letters on a background made of horizontal stripes:

; Rainbow Letters
 
VDSLST  = $200  ; vector for a DLI procedure 
DLPTRS  = $230  ; vector for the ANTIC display list
KBCODES = $2FC  ; internal hardware value of the last key pressed
 
COLPF0  = $D016 ; in BASIC 2 (ANTIC 7) it is used for the uppercase letters
COLBK   = $D01A ; color and luminance of background
WSYNC   = $D40A ; wait for horizontal synchronization
NMIEN   = $D40E ; NMI enable/disable
 
cnt     = $C8   ; the number of lines in a single stripe
str     = $C9   ; the number of stripes
 
        ORG $2000
 
        ; Set our custom display list.
start   LDA <dl 
        STA DLPTRS
        LDA >dl
        STA DLPTRS+1
 
        ; Set the vector of our DLI procedure.
        LDA <proc
        STA VDSLST
        LDA >proc
        STA VDSLST+1
 
        ; Enable DLIs.
        LDA #192
        STA NMIEN
 
        ; Wait for Esc and exit if Esc is pressed.
wait    LDA KBCODES
        CMP #$1C        ; Esc key
        BNE wait
 
        RTS
 
        ;
        ; Custom DLI procedure.
        ;
proc    PHA
        TXA
        PHA
        TYA
        PHA
 
        ; Initialize variables.
        LDX #14         ; X stores the foregroud color i.e., the color of letters
        LDY #0          ; Y stores the background color (colbk) 
 
        ; Init the stripe counter.
        LDA #12         ; there are 12 stripes
        STA str
 
        ; Init the counter for the top 8 lines in a stripe (each stripe has 16 lines)
loop    LDA #8
        STA cnt
 
top     STA WSYNC
        STX COLPF0      ; set the foreground color
        STY COLBK       ; set the background color
 
        DEX             ; decrease the foreground color
        DEX
        INY             ; increase the background color
        INY
 
        DEC cnt         ; repeat the top loop block 8 times
        BNE top
 
        ; Init the counter for the bottom 8 lines in a stripe
        LDA #8
        STA cnt
 
bottom  INX             ; increase the foreground color
        INX
        DEY             ; decrease the background color
        DEY
 
        STA WSYNC
        STX COLPF0      ; set the foreground color
        STY COLBK       ; set the background color
 
        DEC cnt         ; repeat the bottom loop block 8 times
        BNE bottom
 
        ; X = X + 16 (the next foreground color)
        TXA
        CLC
        ADC #16
        TAX
 
        ; Y = Y + 16 (the next background color) 
        TYA
        CLC
        ADC #16
        TAY
 
        DEC str         ; decrease the stripe counter from 12 to 0
        BNE loop        ; repeat the loop block 12 times
 
        ; End with the black backgroud.
        LDA #0
        STA COLBK        
 
        PLA
        TAY
        PLA
        TAX
        PLA
 
        RTI
 
        ; Custom display list.
        ; In BASIC mode 2+16, +16 means that a text window at the bottom of the screen should not be displayed
        .LOCAL dl
        .BYTE $70           ; 8 blank scanlines
        .BYTE $70+$80       ; 8 blank scanlines +$80 (bit 7 enables DLI starting with the next line)
        .BYTE $70           ; 8 blank scanlines
        .BYTE $40+7         ; bit6 (load memory scan from the next two bytes) + 7 (one text line in BASIC 2+16)
        .BYTE <screen       ; screen memory
        .BYTE >screen
        .BYTE 7,7,7,7,7,7,7,7,7,7,7 ; 11 text lines in BASIC 2+16 (ANTIC 7) 
        .BYTE $41           ; $41 (JVB - Jump and wait for Vertical Blank)
        .BYTE a(dl)         ; jump to the location specified by these two bytes and wait for vertical blank 
        .ENDL
 
screen  DTA d'                    '
        DTA d'   TECZOWE LITERKI  '
        DTA d'                    '
        DTA d'     PROGRAM NA     '
        DTA d'                    '
        DTA d'     ATARI 65XE     '
        DTA d'                    '
        DTA d'--------------------'
        DTA d'WISENHEIMER         '
        DTA d'          BRAINSTORM'
        DTA d'--------------------'
 
        RUN start
notes/atari/rainbow.txt · Last modified: 2016/09/27 by admin