I must not have a grip on branch instructions or something. Can someone tell me what I am doing wrong in my code for Exercise 4?
; Andrew Davie's "Atari 2600 Programming for Newbies"
; Session 20 - Asymmetrical Playfields - Part 3
; Playfield Graphics Code Cleaned up by Thomas Jentzsch
; Exercise 4 - Color Boxes in RGB
processor 6502
include "vcs.h"
include "macro.h"
;--------------------------------------------------------------------------
SEG
ORG $F000
Reset
; Clear RAM and all TIA registers
ldx #0
ldy #0
lda #0
Clear
sta 0,x
inx
bne Clear
;--------------------------------------------------------------------
; Once-only initialisation...
;--------------------------------------------------------------------
StartOfFrame
; Start of new frame
; Start of vertical blank processing
lda #%00000000
sta CTRLPF ; don't mirror playfield
lda #$00
sta COLUBK ; set the background color
lda #0
sta VBLANK
lda #2
sta VSYNC
sta WSYNC
sta WSYNC
sta WSYNC ; 3 scanlines of VSYNC signal
lda #0
sta VSYNC
;------------------------------------------------------------------
; 37 scanlines of vertical blank...
ldx #0
VerticalBlank
sta WSYNC
inx
cpx #37
bne VerticalBlank
;------------------------------------------------------------------
; Do 192 scanlines of color-changing (our picture)
ldx #0 ; this counts our scanline number
cpy #00
beq RedSet
cpy #01
beq GreenSet
cpy #02
beq BlueSet
;--------------------------------------------------------------------------
RedLine ; @07
; left PF:
lda BOX_RED_STRIP_0,x ; 4
sta PF0 ; 3 @14 @ < 22, ok
lda BOX_RED_STRIP_1,x ; 4
sta PF1 ; 3 @21 @ < 27, ok
lda BOX_RED_STRIP_2,x ; 4
sta PF2 ; 3 @28 @ < 38, ok
; right PF:
lda BOX_RED_STRIP_3,x ; 4
sta PF0 ; 3 @47 26 < @ < 48, just ok
lda BOX_RED_STRIP_4,x ; 4
sta PF1 ; 3 @62 37 < @ < 54, too late
lda BOX_RED_STRIP_5,x ; 4
sta PF2 ; 3 @69 47 < @ < 64, too late
sta WSYNC ; 3
;---------------------------------------
inx ; 2
cpx #192 ; 2
bne RedLine ; 2³
jmp ClearVar
GreenLine ; @07
; left PF:
lda BOX_GREE_STRIP_0,x ; 4
sta PF0 ; 3 @14 @ < 22, ok
lda BOX_GREE_STRIP_1,x ; 4
sta PF1 ; 3 @21 @ < 27, ok
lda BOX_GREE_STRIP_2,x ; 4
sta PF2 ; 3 @28 @ < 38, ok
; right PF:
lda BOX_GREE_STRIP_3,x ; 4
sta PF0 ; 3 @47 26 < @ < 48, just ok
lda BOX_GREE_STRIP_4,x ; 4
sta PF1 ; 3 @62 37 < @ < 54, too late
lda BOX_GREE_STRIP_5,x ; 4
sta PF2 ; 3 @69 47 < @ < 64, too late
sta WSYNC ; 3
;---------------------------------------
inx ; 2
cpx #192 ; 2
bne GreenLine ; 2³
jmp ClearVar
BlueLine ; @07
; left PF:
lda BOX_BLUE_STRIP_0,x ; 4
sta PF0 ; 3 @14 @ < 22, ok
lda BOX_BLUE_STRIP_1,x ; 4
sta PF1 ; 3 @21 @ < 27, ok
lda BOX_BLUE_STRIP_2,x ; 4
sta PF2 ; 3 @28 @ < 38, ok
; right PF:
lda BOX_BLUE_STRIP_3,x ; 4
sta PF0 ; 3 @47 26 < @ < 48, just ok
lda BOX_BLUE_STRIP_4,x ; 4
sta PF1 ; 3 @62 37 < @ < 54, too late
lda BOX_BLUE_STRIP_5,x ; 4
sta PF2 ; 3 @69 47 < @ < 64, too late
sta WSYNC ; 3
;---------------------------------------
inx ; 2
cpx #192 ; 2
bne BlueLine ; 2³
;--------------------------------------------------------------------------
ClearVar
; CLEAR THE PLAYFIELD REGISTERS
lda #0
sta PF0
sta PF1
sta PF2
;--------------------------------------------------------------------------
lda #%01000010
sta VBLANK ; end of screen - enter blanking
; 30 scanlines of overscan...
ldx #0
Overscan
sta WSYNC
inx
cpx #30
bne Overscan
jmp StartOfFrame
include "BOX_RED.asm"
include "BOX_BLUE.asm"
include "BOX_GREE.asm"
;---------------------------------------------------------------------------------
ORG $FFFA
InterruptVectors
.word Reset ; NMI
.word Reset ; RESET
.word Reset ; IRQ
;-------------------------------------------------------------------------
RedSet
lda #$34
sta COLUPF ; set the playfield color
iny
jmp RedLine
GreenSet
lda #$C6
sta COLUPF
iny
jmp GreenLine
BlueSet
lda #$72
sta COLUPF
ldy #0
jmp BlueLine
END
I have attached my Red, Green and Blue graphics data in a ZIP file in case you want to play around with it. The final result should be neat if I can get the code working correctly.