    OPT r+

;---------------------------------------------------
; Zpage variables
    .zpvar temp_w           .word = $80
    .zpvar temp_b           .byte
    .zpvar dli_counter      .byte
    .zpvar DLI_A            .byte
    .zpvar DLI_X            .byte
    
;---------------------------------------------------
    icl 'lib/ATARISYS.ASM'
    icl 'lib/MACRO.ASM'
;---------------------------------------------------
    org $2000
    
DL
    .by SKIP8, SKIP8+DLII, SKIP8
    .by LMS+MODE2+SCH
scrl1_ptr
    .wo scroll1 
    .by SKIP1+DLII, SKIP1
    .by LMS+MODE2+SCH+DLII
scrl2_ptr
    .wo scroll2
    
    .by JVB <DL >DL
;---------------------------------------------------
DLI
    sta DLI_A
    stx DLI_X
    ldx dli_counter
    lda col1_tab,x
    sta COLPF1
    lda col2_tab,x
    sta COLPF2    
    inc dli_counter
    lda hscr_tab,x
    sta HSCROL
    LDX DLI_X
    LDA DLI_A
    rti
;---------------------------------------------------
VBL
    dec hscr_tab
    bpl @+
    ;move pointer and reset HSCROL
    adw scrl1_ptr #4
    mva #$f hscr_tab
    cpw scrl1_ptr #scroll1_end
    scc:mwa #scroll1 scrl1_ptr
@
    lda RTCLOK+2
    and #%00000001  ; every second frame
    bne @+
    dec hscr_tab+1
    bpl @+
    ;move pointer and reset HSCROL
    adw scrl2_ptr #4
    mva #$f hscr_tab+1
    cpw scrl2_ptr #scroll2_end
    scc:mwa #scroll2 scrl2_ptr
@
    
    mva #0 dli_counter
    jmp XITVBV
;---------------------------------------------------

START
    mwa #dl DLPTRS
    lda #@dmactl(standard|dma|players|missiles|lineX1) ; normal screen width, DL on, P/M on
    sta dmactls

    VMAIN VBL, 7
    VDLI DLI

    halt

col1_tab
    .by $0f, $0d, $0b, $09, $07, $05
col2_tab
    .by $00, $02, $04, $06, $08, $0a
hscr_tab
    .by $f $f
    
scroll1
    :48 dta d" "  ; wrap buffer
    dta d"First scroll scrolly going on and on and on. Still going strong. Will it ever end?"
scroll1_end
scroll2
    :48 dta d" "  ; wrap buffer
    dta d'Second scroll scrolly going on and on and on. Still going strong. Will it ever end?'
scroll2_end
    :48 dta d" "  ; wrap buffer
    

    run START