I have been working for the past 15 hrs trying to figure this out, but I can't! I have pasted the code below, please tell me where I am wrong,
I have made a sub-routine "poll" which stores a 1 in "whitevar' variable whenever a white color is detected. Then the subroutine "change_white" would make all the sprites black except 1 in one NMI, it then polls it in the same NMI trying to detect a white. Then in the next NMI a second object is turned white and rest all are made black, then poll is called to detect white and so on
The whole code is here:
http://www.sendspace.com/file/zqtlqa
/* here I keep sprite zero at bottom right of the screen so that the subroutine knows when to stop polling */
poll:
jsr update_sprites
poll1:
lda $4017
and #%00001000
beq white
lda $2002 ; detecting sprite 0
and #%01000000
bne nothing
JMP poll1
white:
lda #1
sta whitevar
rts
/*this is executed every NMI
in first NMI, the first object becomes white, then the second in second NMI and so on till 4 objects (and hence 4 NMI's)*/
change_white:
lda trig ; trig is set in the code which detects the pulling of trigger
cmp #17
bne sex
lda white_var
cmp #0
bne check1
lda #1
sta $512
sta $50e
sta $50a
lda #0
sta $506
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $507 ; simply just to see if it works
INC $507
INC $507
INC $507
INC $507
INC $507
INC $507
rts
check1:
cmp #1
bne check2
lda #1
sta $50e
sta $506
sta $512
lda #0
sta $50a
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $50b
INC $50b
INC $50b
INC $50b
INC $50b
rts
check2:
cmp #2
bne check3
lda #1
sta $512
sta $506
sta $50a
lda #0
sta $50e
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $50f
INC $50f
INC $50f
INC $50f
INC $50f
doo1:
rts
check3:
cmp #3
bne comp1
lda #1
sta $50e
sta $506
sta $50a
lda #0
sta $512
sta white_var
jsr poll
lda whitevar
cmp #1
bne comp11
INC $513
INC $513
INC $513
INC $513
INC $513
comp1:
rts
comp11:
lda #0
sta trig
jsr backs ; this subroutine bring backs the original screen
rts
I have made a sub-routine "poll" which stores a 1 in "whitevar' variable whenever a white color is detected. Then the subroutine "change_white" would make all the sprites black except 1 in one NMI, it then polls it in the same NMI trying to detect a white. Then in the next NMI a second object is turned white and rest all are made black, then poll is called to detect white and so on
The whole code is here:
http://www.sendspace.com/file/zqtlqa
/* here I keep sprite zero at bottom right of the screen so that the subroutine knows when to stop polling */
poll:
jsr update_sprites
poll1:
lda $4017
and #%00001000
beq white
lda $2002 ; detecting sprite 0
and #%01000000
bne nothing
JMP poll1
white:
lda #1
sta whitevar
rts
/*this is executed every NMI
in first NMI, the first object becomes white, then the second in second NMI and so on till 4 objects (and hence 4 NMI's)*/
change_white:
lda trig ; trig is set in the code which detects the pulling of trigger
cmp #17
bne sex
lda white_var
cmp #0
bne check1
lda #1
sta $512
sta $50e
sta $50a
lda #0
sta $506
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $507 ; simply just to see if it works
INC $507
INC $507
INC $507
INC $507
INC $507
INC $507
rts
check1:
cmp #1
bne check2
lda #1
sta $50e
sta $506
sta $512
lda #0
sta $50a
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $50b
INC $50b
INC $50b
INC $50b
INC $50b
rts
check2:
cmp #2
bne check3
lda #1
sta $512
sta $506
sta $50a
lda #0
sta $50e
inc white_var
jsr poll
lda whitevar
cmp #1
bne doo1
INC $50f
INC $50f
INC $50f
INC $50f
INC $50f
doo1:
rts
check3:
cmp #3
bne comp1
lda #1
sta $50e
sta $506
sta $50a
lda #0
sta $512
sta white_var
jsr poll
lda whitevar
cmp #1
bne comp11
INC $513
INC $513
INC $513
INC $513
INC $513
comp1:
rts
comp11:
lda #0
sta trig
jsr backs ; this subroutine bring backs the original screen
rts