; 256 palette show

; Program starts ANTIC MODE F in GTIA gr. 9 mode,
;   draws 16 columns of all 16 shades and then
;   it starts DLI routine to set the base color to each of 16, every 4 scanlines

; Look at label 'start' for the program init routine.

; DLI routine does 2 steps for each line:
;  1. sets the main color of ANTIC MODE F GTIA gr. 9 to each value,
;      every 4 scanlines (making nice squares 4x4 as palette fields)
;  2. reverts the line color back to black as fast as possible
;      on the right of the palette picture

dli:      0600: 48        PHA
          0601: 8A        TXA
          0602: 48        PHA
          0603: A9 00     LDA #$00        ; #basecolor
          0605: A2 00     LDX #$00        ; #basecolor2 ; back to black
pltrow:   0607: 38         ┌> SEC
          0608: E9 10      │  SBC #$10
                           │
          060A: 8D 0A D4   │  STA WSYNC
          060D: 8D 1A D0   │  STA COLBK
          0610: 20 40 06   │  JSR $0640   ; waitcols
          0613: 8E 1A D0   │  STX COLBK
                           │
          0616: 8D 0A D4   │  STA WSYNC
          0619: 8D 1A D0   │  STA COLBK
          061C: 20 40 06   │  JSR $0640   ; waitcols
          061F: 8E 1A D0   │  STX COLBK
                           │
          0622: 8D 0A D4   │  STA WSYNC
          0625: 8D 1A D0   │  STA COLBK
          0628: 20 40 06   │  JSR $0640   ; waitcols
          062B: 8E 1A D0   │  STX COLBK
                           │
          062E: 8D 0A D4   │  STA WSYNC
          0631: 8D 1A D0   │  STA COLBK
          0634: 20 40 06   │  JSR $0640   ; waitcols
          0637: 8E 1A D0   │  STX COLBK
                           │
          063A: D0 CB      └─ BNE $0607   ; pltrow
          063C: 68        PLA
          063D: AA        TAX
          063E: 68        PLA
          063F: 40        RTI

waitcols: 0640: EA        NOP
          0641: EA        NOP
          0642: EA        NOP
          0643: EA        NOP
          0644: EA        NOP
          0645: EA        NOP
          0646: EA        NOP
          0647: EA        NOP
          0648: 60        RTS


start:    0650: A9 00     LDA #$00        ; ; set DL of ANTIC MODE F
          0652: 8D 30 02  STA SDLSTL
          0655: A9 07     LDA #$07
          0657: 8D 31 02  STA SDLSTH
          065A: AD 6F 02  LDA GPRIOR      ; ; start GTIA MODE for gr. 9
          065D: 29 3F     AND #$3F
          065F: 09 40     ORA #$40
          0661: 8D 6F 02  STA GPRIOR
          0664: A9 78     LDA #$78        ; ; $8178 = a beginning of the palette image in VRAM
          0666: 8D 75 06  STA $0675       ;cpaltl  ; self-modifing code is always useful :)
          0669: A9 81     LDA #$81
          066B: 8D 76 06  STA $0676       ;cpalth
          066E: A0 3F     LDY #$3F        ; ; $3F to 0 = 64 lines (16 colors x 4 scanlines)
nxtrow:   0670: A9 10     ┌>LDA #$10      ; ; first TWO colors (0 and 1: each nibble is a color)
          0672: A2 07     │ LDX #$07      ; ; 7 to 0 = 8 steps = 16 colors (2 colors in a step)
nxtcol:   0674: 9D 50 8B  │ ┌>STA $8B50,X ; <arg>=cpalt
          0677: 18        │ │ CLC
          0678: 69 22     │ │ ADC #$22    ; ; 10 -> 32 ->... makes "76543210" row of colors
          067A: CA        │ │ DEX
          067B: D0 F7     │ └─BNE $0674   ;nxtcol
          067D: AD 75 06  │ LDA $0675     ;cpaltl
          0680: 18        │ CLC
          0681: 69 28     │ ADC #$28      ; ; #$28 = bytes per line
          0683: 8D 75 06  │ STA $0675     ;cpaltl
          0686: 90 03     │ ┌─BCC $068B
          0688: EE 76 06  │ │ INC $0676   ;cpalth
          068B: 88        │ └>DEY
          068C: D0 E2     └─BNE $0670     ;nxtrow
; ; set DLI
          068E: A9 00     LDA #$00
          0690: 8D 00 02  STA VDSLST
          0693: A9 06     LDA #$06
          0695: 8D 01 02  STA VDSLST+1
          0698: A9 C0     LDA #$C0
          069A: 8D 0E D4  STA NMIEN
; ; hide the non-perfect ANTIC timing by a PMG player on each palette side
          069D: A9 14     LDA #$14
          069F: 8D 00 D0  STA HPOSP0
          06A2: A9 50     LDA #$50
          06A4: 8D 01 D0  STA HPOSP1
          06A7: A9 FF     LDA #$FF
          06A9: 8D 0D D0  STA GRAFP0
          06AC: 8D 0E D0  STA GRAFP1
          06AF: A9 03     LDA #$03
          06B1: 8D 08 D0  STA SIZEP0
          06B4: 8D 09 D0  STA SIZEP1
          06B7: A9 00     LDA #$00
          06B9: 8D C0 02  STA PCOLR0
          06BC: 8D C1 02  STA PCOLR1
          06BF: F0 FE     BEQ $06BF   ; ; EOGW - End of Good Work


; ; DLIST
          0700: 3x 8 BLANK
          0703: DLI LMS 8150 MODE F
          0706: 93x MODE F
          0763: LMS 9000 MODE F
          0766: 97x MODE F
          07C7: JVB 0700

