[stella] 262 scanline kernel is rolling

Subject: [stella] 262 scanline kernel is rolling
From: "Zach M" <zach_in_sac@xxxxxxxxxxx>
Date: Fri, 25 Mar 2005 19:11:07 -0500
Hello all, my first homebrew kernel looks good in emulators, and z26 reports
that it displays 262 scanlines, but when I test on a TV the image rolls
slowly, almost like a scrolling background in a Xevious-type game.

I used Andrew Davie's "Our First Kernel" as a template. I can still count 30
lines in the overscan, and 3 in the vertical sync. I figure the vertical
blank + picture must be 229 lines.

I'm attaching the code, and I have a feeling someone will know right away
what the problem is. Thanks for your help.

Zach

p.s. Oh, you want to know what the kernel is? It's a 9x9 Go board. :-)

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://stella.biglist.com
9x9 Go kernel by Zach Matley
Work in Progress. Last updated March 25, 2005

            processor 6502
     include "vcs.h" 
     include "macro.h" 

BKCOLOR   = $27
STX_OP = $86
STXW_OP = $8e
STY_OP = $84
STYW_OP = $8c
DYNAMIC_CODE_LEN = 45

pf0_2       = $80
pf1_2       = $81
pf2_2       = $82
mid_pf0     = $83
mid_pf1     = $84
mid_pf2     = $85
mid_pf0_2   = $86
mid_pf1_2   = $87
mid_pf2_2   = $88
lo_pf0      = $89 ; low playfield data same as top, except top and bottom rows
lo_pf1      = $8a
lo_pf2      = $8b
lo_pf0_2    = $8c
lo_pf1_2    = $8d
lo_pf2_2    = $8e
stone1color_opposite = $90
stone1color = $91
stone1equals9 = $92
stone9color = $93
savestack   = $94

;twenty-seven bytes to record the board position
; e = 00, b = 01, w = 11
row1cols321  = $95
row1cols3456 = $96
row1cols6789 = $97
row2cols321  = $98
row2cols3456 = $99
row2cols6789 = $9a
row3cols321  = $9b
row3cols3456 = $9c
row3cols6789 = $9d
row4cols321  = $9e
row4cols3456 = $9f
row4cols6789 = $a0
row5cols321  = $a1
row5cols3456 = $a2
row5cols6789 = $a3
row6cols321  = $a4
row6cols3456 = $a5
row6cols6789 = $a6
row7cols321  = $a7
row7cols3456 = $a8
row7cols6789 = $a9
row8cols321  = $aa
row8cols3456 = $ab
row8cols6789 = $ac
row9cols321  = $ad
row9cols3456 = $ae
row9cols6789 = $af


dynamic = $b0
pf0    = $b1
pf1    = $b5
pf2    = $b9
stone1op = $be ; op as in opcode
stone2op = $c2
stone3op = $c6
stone4op = $c8
stone5op = $cd
stone6op = $d1
stone7op = $d3
stone8op = $d8
jumpaddr_lo = $dd
jumpaddr_hi = $de

currentcols321 = $df
currentcols3456 = $e0
currentcols6789 = $e1
framecount      = $e2
temp            = $e3


            SEG
            ORG $F000

Reset
                ldy #DYNAMIC_CODE_LEN
copy:           lda dynamiccode-1,Y
                sta dynamic-1,Y
                dey
                bne copy
                sta WSYNC
                ldx #BKCOLOR
                stx COLUBK
                ldy #27
setup:          lda setup_board-1,Y
                sta row1cols321-1,Y
                dey
                bne setup


StartOfFrame

    ; Start of vertical blank processing

            lda #0
            sta VBLANK

            lda #2
            sta VSYNC
           
                ; 3 scanlines of VSYNCH signal...

                sta WSYNC
                sta WSYNC
                sta WSYNC

            lda #0
            sta VSYNC           

                ; 37 scanlines of vertical blank...
                lda #BKCOLOR
                sta COLUP0
                sta COLUP1
                lda #%11111111
                sta GRP0
                lda #%11111111
                sta GRP1
                lda #%10
                sta ENAM0
                sta ENAM1
                lda #%110011
                sta NUSIZ0
                lda #%110001
                sta NUSIZ1
                sta WSYNC
                ;--------------------
                SLEEP 18
                sta RESM0
                SLEEP 14
                sta RESP1
                SLEEP 8
                sta RESM1
                SLEEP 7
                sta RESP0
                nop
                sta WSYNC
                ;----------------------------
                lda #$10
                sta HMP1
                sta HMM1
                sta HMBL
                SLEEP 33
                sta RESBL
                sta WSYNC
                ;----------------------------
                sta HMOVE
                lda #%100000
                sta CTRLPF
                
                ldx #26 ; this number adjusted until kernel has 262 scanlines.
vblankloop      dex
                stx WSYNC
                bne vblankloop
                
                ; 192 scanlines of picture... (starts somewhere below)
                
                   lda row1cols6789
                   sta currentcols6789
                   lda row1cols3456
                   sta currentcols3456
                   lda row1cols321
                   sta currentcols321
                   jsr kernelvars
                   lda pf0
                   cmp #$80
                   bne stapf0
                   lda #0
stapf0
                   sta pf0
                   ldx pf1
                   lda toprow_pf1s,X
                   sta pf1
                   ldx pf2
                   lda toprow_pf1s,X
                   sta pf2
                   ldx pf1_2
                   lda toprow_pf1s,X
                   sta pf1_2
                   lda pf0_2
                   bit bit6
                   bne pf0_2ok
                   and #$7f
                   sta pf0_2
pf0_2ok:
                   lda pf2_2
                   bit bit3
                   bne pf2_2ok
                   and #$f7
                   sta pf2_2
pf2_2ok
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row2cols6789
                   sta currentcols6789
                   lda row2cols3456
                   sta currentcols3456
                   lda row2cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row3cols6789
                   sta currentcols6789
                   lda row3cols3456
                   sta currentcols3456
                   lda row3cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL


                   lda row4cols6789
                   sta currentcols6789
                   lda row4cols3456
                   sta currentcols3456
                   lda row4cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row5cols6789
                   sta currentcols6789
                   lda row5cols3456
                   sta currentcols3456
                   lda row5cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row6cols6789
                   sta currentcols6789
                   lda row6cols3456
                   sta currentcols3456
                   lda row6cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row7cols6789
                   sta currentcols6789
                   lda row7cols3456
                   sta currentcols3456
                   lda row7cols321
                   sta currentcols321
                   jsr kernelvars                  
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row8cols6789
                   sta currentcols6789
                   lda row8cols3456
                   sta currentcols3456
                   lda row8cols321
                   sta currentcols321
                   jsr kernelvars
                   jsr drawstones
                   lda #0
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   lda #$ff
                   sta ENABL

                   lda row9cols6789
                   sta currentcols6789
                   lda row9cols3456
                   sta currentcols3456
                   lda row9cols321
                   sta currentcols321
                   jsr kernelvars
 lda pf0
                   cmp #$80
                   bne stapf02
                   lda #0
stapf02
                   sta lo_pf0
                   ldx lo_pf1
                   lda toprow_pf1s,X
                   sta lo_pf1
                   ldx lo_pf2
                   lda toprow_pf1s,X
                   sta lo_pf2
                   ldx lo_pf1_2
                   lda toprow_pf1s,X
                   sta lo_pf1_2
                   lda lo_pf0_2
                   bit bit6
                   bne pf0_2ok2
                   and #$7f
                   sta lo_pf0_2
pf0_2ok2:
                   lda lo_pf2_2
                   bit bit3
                   bne pf2_2ok2
                   and #$f7
                   sta lo_pf2_2
pf2_2ok2

                   jsr drawstones
                   lda #BKCOLOR
                   sta COLUPF
                   lda #<jumphere
                   sta $db                                
                   lda #%10000000
                   sta PF0
                   lda #%00010001
                   sta PF1
                   lda #%00001000
                   sta PF2
                   sta VBLANK                      ; end of screen - enter blanking

                ; 30 scanlines of overscan...

            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
            sta WSYNC
              

            jmp StartOfFrame
drawstones:
; The spaghetti organization of this code has a specific reason:
; Saving cycles by loading the "jumphere" address and the data stored
; in certain registers at the same time.

                   tsx 
                   stx savestack
                   ldx #$1F ; ENABL
                   txs
                   ldx stone9color             
                   sta WSYNC
; ------------line 4 of stones----------------
                   jmp $00b0
                   ORG $F400  ; 0 stored to GRP1 on line 3
jumphere4:         stx COLUPF       ;3 67
                   lda #<jumphere5  ;2 69 ; fortunatley not zero
                   sta $db          ;3 73
                   php                    ; disable M0
; ------------line 14 of stones----------------
                   jmp $00b0
                   ORG $F420  ; $20 stored to CTRLPF on line 9
jumphere14:        stx COLUPF
                   lda #<jumphere15
                   sta $db              
                   sta WSYNC
; ------------line 3 of stones----------------
                   jmp $00b0
                   ORG $F454
jumphere3:         stx COLUPF
                   lda #<jumphere4
                   sta $db              
                   sta GRP1
; ------------line 2 of stones----------------
                   jmp $00b0
jumphere2:         stx COLUPF
                   lda #<jumphere3
                   sta $db              
                   sta CTRLPF
; ------------line 1 of stones----------------
                   jmp $00b0
jumphere:          stx COLUPF
                   lda #<jumphere2
                   sta $db
                   php ; disable ball             
; ------------line 11 of stones----------------
                   jmp $00b0
jumphere11:        stx COLUPF
                   lda #<jumphere12
                   sta $db              
                   sta GRP0
; ------------line 12 of stones----------------
                   jmp $00b0
                   ORG $F4C3
jumphere12:        stx COLUPF
                   lda #<jumphere13
                   sta $db              
                   sta GRP1;
; ------------line 13 of stones----------------
                   jmp $00b0
                   ORG $F4CF
jumphere13:        stx COLUPF
                   lda #<jumphere14
                   sta $db              
                   sta CTRLPF
; ------------line 15 of stones----------------
                   jmp $00b0
jumphere15:        stx COLUPF
                   ldx savestack
                   txs
                   
                   rts
                  
                   rts
; ------------line 5 of stones----------------
                   jmp $00b0
                   ORG $F4FF
jumphere5:         stx COLUPF
                   lda #<jumphere11
                   sta $db              
                   php ; disable M1
                   ; ---line 6: middle line--
                   ldx #BKCOLOR         ;2
                   stx COLUBK       ;3 5
                   lda stone1color  ;3 8
                   sta COLUPF       ;3 11
                   lda mid_pf0      ;3 14
                   sta PF0          ;3 17
                   lda mid_pf1      ;3 20
                   sta PF1          ;2 22 
                   lda stone1color_opposite ;3 25
                   sta COLUBK       ;3 28
                   lda mid_pf2      ;3 31
                   sta PF2          ;3 34
                   lda mid_pf0_2
                   sta PF0
                   lda mid_pf1_2
                   sta PF1
                   lda mid_pf2_2
                   sta PF2
                   lda #0             
                   sta GRP0            ;hide player0
                   ldx stone1equals9
                   lda #BKCOLOR
                   ; whether the edge color is BK or PF
                   ; depends on whether stone1 and stone9
                   ; are same color
                   sleep 3
                   sta COLUPF,X
                   sleep 3
                   sta COLUBK
                   ; ---line 7: middle line--
                   lda #BKCOLOR     ;2 ; spare cycles
                   sta COLUBK       ;3 5
                   lda stone1color  ;3 8
                   sta COLUPF       ;3 11
                   lda mid_pf0      ;3 14
                   sta PF0          ;3 17
                   lda mid_pf1      ;3 20
                   sta PF1          ;2 22 
                   lda stone1color_opposite ;3 25
                   sta COLUBK       ;3 28
                   lda mid_pf2      ;3 31
                   sta PF2          ;3 34
                   lda mid_pf0_2
                   sta PF0
                   lda mid_pf1_2
                   sta PF1
                   lda mid_pf2_2
                   sta PF2
                   nop
                   lda lo_pf1
                   sta pf1
                   lda #BKCOLOR
                   ; whether the edge color is BK or PF
                   ; depends on whether stone1 and stone9
                   ; are same color
                   sleep 3;sta COLUBK
                   sta COLUPF,X
                   lda lo_pf1_2
                   sta pf1_2
                   ; ---line 8: middle line--
                   lda #BKCOLOR
                   sta COLUBK       ;3 5
                   lda stone1color  ;3 8
                   sta COLUPF       ;3 11
                   lda mid_pf0      ;3 14
                   sta PF0          ;3 17
                   lda mid_pf1      ;3 20
                   sta PF1          ;2 22 
                   lda stone1color_opposite ;3 25
                   sta COLUBK       ;3 28
                   lda mid_pf2      ;3 31
                   sta PF2          ;3 34
                   lda mid_pf0_2
                   sta PF0
                   lda mid_pf1_2
                   sta PF1
                   lda mid_pf2_2
                   sta PF2
                   nop
                   lda lo_pf2
                   sta pf2
                   lda #BKCOLOR
                   ; whether the edge color is BK or PF
                   ; depends on whether stone1 and stone9
                   ; are same color
                   sleep 3;sta COLUBK
                   sta COLUPF,X
                   lda lo_pf2_2
                   sta pf2_2
                   ; ---line 9: middle line--
                   lda #BKCOLOR         ;2
                   sta COLUBK       ;3 5
                   lda stone1color  ;3 8
                   sta COLUPF       ;3 11
                   lda mid_pf0      ;3 14
                   sta PF0          ;3 17
                   lda mid_pf1      ;3 20
                   sta PF1          ;2 22 
                   lda stone1color_opposite ;3 25
                   sta COLUBK       ;3 28
                   lda mid_pf2      ;3 31
                   sta PF2          ;3 34
                   lda mid_pf0_2
                   sta PF0
                   lda mid_pf1_2
                   sta PF1
                   lda mid_pf2_2
                   sta PF2
                   nop
                   lda lo_pf0
                   sta pf0
                   lda #BKCOLOR
                   ; whether the edge color is BK or PF
                   ; depends on whether stone1 and stone9
                   ; are same color
                   sleep 3;sta COLUBK
                   sta COLUPF,X
                   lda lo_pf0_2
                   sta pf0_2
                   ; ---line 10, the last middle line--
                   lda #BKCOLOR         ;2
                   sta COLUBK       ;3 5
                   lda stone1color  ;3 8
                   sta COLUPF       ;3 11
                   lda mid_pf0      ;3 14
                   sta PF0          ;3 17
                   lda mid_pf1      ;3 20
                   sta PF1          ;2 22 
                   lda stone1color_opposite ;3 25
                   sta COLUBK       ;3 28
                   lda mid_pf2      ;3 31
                   sta PF2          ;3 34
                   ;SLEEP 8
                   lda mid_pf0_2
                   sta PF0
                   lda mid_pf1_2
                   sta PF1
                   lda mid_pf2_2
                   sta PF2
                   lda #$ff
                   sta ENAM0
                   sta ENAM1
                   ldx stone1equals9
                   lda #BKCOLOR
                   ; whether the edge is BK or PF
                   ; depends on whether stone1 and
                   ; stone9 are same color
                   sta COLUPF,X
                   ldx stone9color
                   sta COLUBK    
                   jmp $00b0 ; go to line 11

kernelvars
                   ;--------- calculate kernel variables ---------;
                   lda currentcols321
                   and #%00000011
                   tax
                   lda stonecolors,x
                   sta stone1color            ; = 0f if stone1 = white, 00 otherwise
                   eor #$0f
                   sta stone1color_opposite   ; = 00 if stone1 = white, 0f otherwise
                   lda pf0s,x
                   sta pf0                    ; = 80 if stone1 = empty, c0 otherwise
                   sta lo_pf0
                   sta mid_pf0
                   lda currentcols321
                   and #%00010101
                   tax
                   lda pf1s,x
                   sta pf1
                   sta lo_pf1
                   lda currentcols6789
                   and #%00000011
                   tax
                   lda stonecolors,x
                   sta stone9color
                   sec
                   sbc stone1color ; if equal, diff is 0, else diff is f1
                   and #$01
                   eor #$01
                   sta stone1equals9
                   
                   lda stone1color
                   ror ; store stone1color in carry bit
                   lda currentcols321
                   and #%00101010
                   lsr
                   tax
                   lda mid_pf1s,X
                   sta mid_pf1
                   lda currentcols3456
                   and #%01010100
                   lsr
                   lsr
                   tax 
                   lda pf2s,X
                   sta pf2
                   sta lo_pf2
                   lda currentcols3456
                   and #%00000101
                   tax
                   lda pf0_2s,X
                   sta pf0_2
                   sta lo_pf0_2
                   lda currentcols6789
                   and #%01010100
                   lsr
                   lsr
                   tax
                   lda pf1_2s,X
                   sta pf1_2
                   sta lo_pf1_2
                   lda currentcols6789
                   and #%00000101
                   tax
                   lda pf2_2s,X
                   sta pf2_2
                   sta lo_pf2_2

                   ;-- find middle sections
                   lda currentcols6789
                   and #%10101000
                   lsr
                   lsr
                   lsr
                   tax
                   lda stone1color
                   lsr
                   bcc stone1black_pf1_2
                   lda w_mid_pf1_2s,X
                   bcs stone1white_pf1_2
stone1black_pf1_2
                   lda b_mid_pf1_2s,X
stone1white_pf1_2
                   sta mid_pf1_2

                   ; middle section, PF2
                   lda currentcols3456
                   and #%10101000
                   lsr
                   lsr
                   lsr
                   tax
                   lda stone1color
                   lsr   ; I believe I could skip this and do beq instead
                   bcc stone1black_pf2
                   lda w_mid_pf2s,X
                   bcs stone1white_pf2
stone1black_pf2
                   lda b_mid_pf2s,X
stone1white_pf2
                   sta mid_pf2

                   ; middle section PF0_2
                   lda currentcols3456
                   and #%00001010
                   lsr
                   tax
                   lda stone1color
                   lsr
                   bcc stone1black_pf0_2
                   lda w_mid_pf0_2s,X
                   bcs stone1white_pf0_2
stone1black_pf0_2
                   lda b_mid_pf0_2s,X
stone1white_pf0_2
                   sta mid_pf0_2
                   
                   ;middle section PF2_2
                   lda currentcols6789
                   and #%00001010
                   lsr 
                   tax
                   lda stone1color
                   lsr
                   bcc stone1black_pf2_2
                   lda w_mid_pf2_2s,X
                   bcs stone1white_pf2_2
stone1black_pf2_2
                   lda b_mid_pf2_2s,X
stone1white_pf2_2
                   sta mid_pf2_2
                   lda currentcols6789
                   lsr
                   bcs startopcodes ; if stone9 is present, we are done
                   lda #%00010000
                   eor mid_pf2_2 ; if stone9 is blank don't draw edge of stone
                   sta mid_pf2_2 
                                                                     
startopcodes
                   lda stone9color
                   beq stone9isblack
                   jmp stone9iswhite
stone9isblack
                   ; at this point stone 9 is black, so X is black and Y is white
                   lda currentcols321
                   lsr                ;2
                   lsr                ;2
                   bcc stone1isblack ;2
                   ldx #STY_OP        ;2
                   bcs storestone1op ;2
stone1isblack      
                   ldx #STX_OP        ;2
storestone1op
                   stx stone1op       ;3
                  
                   lsr
                   lsr
                   bcc stone2isblack  ;2
                   ldx #STY_OP        ;2
                   bcs storestone2op  ;2;
stone2isblack      
                   ldx #STX_OP        ;2
storestone2op
                   stx stone2op       ;3

                   lsr
                   lsr
                   bcc stone3isblack  ;2
                   ldx #STY_OP        ;2
                   bcs storestone3op  ;2;
stone3isblack      
                   ldx #STX_OP        ;2
storestone3op
                   stx stone3op       ;3
                  
                   lda currentcols3456
                   lsr                ;2
                   lsr                ;2
                   bcc stone6isblack ;2
                   ldx #STY_OP        ;2
                   bcs storestone6op ;2
stone6isblack      
                   ldx #STX_OP        ;2
storestone6op
                   stx stone6op       ;3
                  
                   lsr
                   lsr
                   bcc stone5isblack  ;2
                   ldx #STY_OP        ;2
                   bcs storestone5op  ;2;
stone5isblack      
                   ldx #STX_OP        ;2
storestone5op
                   stx stone5op       ;3

                   lsr
                   lsr
                   bcc stone4isblack  ;2
                   ldx #STYW_OP        ;2
                   bcs storestone4op  ;2;
stone4isblack      
                   ldx #STXW_OP        ;2
storestone4op
                   stx stone4op       ;3

                   lda currentcols6789
                   lsr                ;2
                   lsr                ;2
                   lsr
                   lsr
                   bcc stone8isblack ;2
                   ldx #STY_OP        ;2
                   bcs storestone8op ;2
stone8isblack      
                   ldx #STX_OP        ;2
storestone8op
                   stx stone8op       ;3
                  
                   lsr
                   lsr
                   bcc stone7isblack  ;2
                   ldx #STYW_OP        ;2
                   bcs storestone7op  ;2;
stone7isblack      
                   ldx #STXW_OP        ;2
storestone7op
                   stx stone7op       ;3

                   ;---------- finally, load X and Y ------------
                   ldx #$00
                   ldy #$0F
                   rts
stone9iswhite
                   ; at this point stone 9 is white, so X is white and Y is black
                   lda currentcols321
                   lsr                ;2
                   lsr                ;2
                   bcc stone1isblack2 ;2
                   ldx #STX_OP        ;2
                   bcs storestone1op2 ;2
stone1isblack2      
                   ldx #STY_OP        ;2
storestone1op2
                   stx stone1op       ;3
                  
                   lsr
                   lsr
                   bcc stone2isblack2  ;2
                   ldx #STX_OP        ;2
                   bcs storestone2op2  ;2;
stone2isblack2      
                   ldx #STY_OP        ;2
storestone2op2
                   stx stone2op       ;3

                   lsr
                   lsr
                   bcc stone3isblack2  ;2
                   ldx #STX_OP        ;2
                   bcs storestone3op2  ;2;
stone3isblack2      
                   ldx #STY_OP        ;2
storestone3op2
                   stx stone3op       ;3
                  
                   lda currentcols3456
                   lsr                ;2
                   lsr                ;2
                   bcc stone6isblack2 ;2
                   ldx #STX_OP        ;2
                   bcs storestone6op2 ;2
stone6isblack2      
                   ldx #STY_OP        ;2
storestone6op2
                   stx stone6op       ;3
                  
                   lsr
                   lsr
                   bcc stone5isblack2  ;2
                   ldx #STX_OP        ;2
                   bcs storestone5op2  ;2;
stone5isblack2      
                   ldx #STY_OP        ;2
storestone5op2
                   stx stone5op       ;3

                   lsr
                   lsr
                   bcc stone4isblack2  ;2
                   ldx #STXW_OP        ;2
                   bcs storestone4op2  ;2;
stone4isblack2      
                   ldx #STYW_OP        ;2
storestone4op2
                   stx stone4op       ;3

                   lda currentcols6789
                   lsr                ;2
                   lsr                ;2
                   lsr
                   lsr
                   bcc stone8isblack2 ;2
                   ldx #STX_OP        ;2
                   bcs storestone8op2 ;2
stone8isblack2      
                   ldx #STY_OP        ;2
storestone8op2
                   stx stone8op       ;3
                  
                   lsr
                   lsr
                   bcc stone7isblack2  ;2
                   ldx #STXW_OP        ;2
                   bcs storestone7op2  ;2;
stone7isblack2      
                   ldx #STYW_OP        ;2
storestone7op2
                   stx stone7op       ;3

                   ;---------- finally, load X and Y ------------
                   ldx #$0F
                   ldy #$00
                   rts
                 

dynamiccode:
                   lda #$c0         ;2 4    2  2
                   sta PF0          ;3 7    2  4
                   lda #$bb         ;2 9    2  6
                   sta PF1          ;3 12   2  8
                   lda #$dd         ;2 14   2  10
                   sta PF2          ;3 17   2  12 
                   lda pf0_2        ;3 20   2  14 ; can optimize by setting to immediate addressing
                   sty COLUPF       ;4 24   3  17
                   sta PF0          ;3 27   2  19
                   stx COLUPF       ;3 30   2  21   
                   lda pf1_2        ;3 33   2  23 ; can optimize by setting to immediate addressing
                   sty COLUPF       ;3 36   2  25 
                   stx.w COLUPF     ;4 40   3  27
                   sta PF1          ;3 43   2  29
                   sty COLUPF       ;3 46   2  31
                   lda pf2_2        ;3 49   2  33 ; can optimize by setting to immediate addressing
                   stx COLUPF       ;3 52   2  35
                   sty.w COLUPF     ;4 56   3  38
                   sta PF2          ;3 59   2  40
                   stx COLUPF       ;3 62   2  42
                   jmp jumphere     ;2 64   3  45          


;data tables for loading variables


pf0s:         .byte $80,$c0,$ff,$c0
pf1s:         .byte $11,$91,$ff,$ff,$39,$b9,$ff,$ff
stonecolors:  .byte $00,$00,$ff,$0f
stxops:       .byte STX_OP,STY_OP,$ff,$ff
              .byte $13,$93,$ff,$ff,$3b,$bb  ; pf1s table continues
stxwops:      .byte STXW_OP,STYW_OP
mid_pf1s:     .byte $ff,$80,$ff,$ff,$c7,$b8,$ff,$ff
              .byte $c7,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$fc,$83,$ff,$ff,$c4
              .byte $bb,$ff
pf2s:         .byte $88,$c8,$ff,$ff,$9c,$dc,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $89,$c9,$ff,$ff,$9d,$dd
pf0_2s:       .byte $80,$c0,$ff,$ff,$90,$d0
pf1_2s:       .byte $11,$13,$ff,$ff,$39,$3b,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $91,$93,$ff,$ff,$b9,$bb
pf2_2s:       .byte $08,$1c,$ff,$ff,$09,$1d
w_mid_pf1_2s: .byte $00,$03,$ff,$ff,$38,$3b,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $80,$83,$ff,$ff,$b8,$bb
b_mid_pf1_2s: .byte $ff,$fc,$ff,$ff,$c7,$c4,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $7f,$7c,$ff,$ff,$47,$44
w_mid_pf2s:   .byte $00,$c0,$ff,$ff,$1c,$dc,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $01,$c1,$ff,$ff,$1d,$dd
b_mid_pf2s:   .byte $ff,$3f,$ff,$ff,$e3,$23,$ff,$ff
              .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
              .byte $fe,$3e,$ff,$ff,$e2,$22
b_mid_pf0_2s: .byte $f0,$30,$ff,$ff,$e0,$20
w_mid_pf0_2s: .byte $00,$c0,$ff,$ff,$10,$d0
b_mid_pf2_2s: .byte $1f,$e3,$ff,$ff,$1e,$e2
w_mid_pf2_2s: .byte $e0,$1c,$ff,$ff,$e1,$1d
stxops_stone9black:  .byte STX_OP,STY_OP
stxops_stone9white:  .byte STY_OP,STX_OP
stxwops_stone9black: .byte STXW_OP,STYW_OP
stxwops_stone9white: .byte STYW_OP,STXW_OP

toprow_pf1s: .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 00-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 08-f
             .byte $ff,$00,$ff,$03,$ff,$ff,$ff,$ff ; 10-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 18-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 20-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 28-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 30-7
             .byte $ff,$38,$ff,$3b,$ff,$ff,$ff,$ff ; 38-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 40-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 48-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 50-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 58-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 60-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 68-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 70-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 78-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; 80-7
             .byte $00,$01,$ff,$ff,$ff,$ff,$ff,$ff ; 88-f
             .byte $ff,$80,$ff,$13,$ff,$ff,$ff,$ff ; 90-7
             .byte $ff,$ff,$ff,$ff,$1c,$1d,$ff,$ff ; 98-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; a0-7
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; a8-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; b0-7
             .byte $ff,$b8,$ff,$bb,$ff,$ff,$ff,$ff ; b8-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; c0-7
             .byte $c0,$c1,$ff,$ff,$ff,$ff,$ff,$ff ; c8-f
             .byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff ; d0-7
             .byte $ff,$ff,$ff,$ff,$dc,$dd,$ff,$ff ; d8-f
bit6:        .byte $40
bit3:        .byte $04

setup_board: .byte %00001100,%00000000,%00000000
             .byte %00110101,%11111100,%00000000
             .byte %00010000,%01000011,%11000000
             .byte %00000000,%00010111,%11011100               
             .byte %00000101,%00110100,%00000000
             .byte %00010000,%01001111,%11000000                  
             .byte %00000000,%00011100,%00000001
             .byte %00010000,%01011111,%11000000                
             .byte %00010000,%01111100,%00000000

            ORG $FFFA

            .word Reset           ; NMI
            .word Reset           ; RESET
            .word Reset           ; IRQ

       END 

Current Thread