This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

problem with code using zapper

problem with code using zapper
by on (#67643)
hi all

our project aims to build a game which uses zapper, but unfortunately there is test code or tutorials explaining this. So, we started hunting to make a test code which just detects the white or black
when we click the mouse on screen.But I'm unable to make it work, as it is always detecting white even if we had pressed on black.
here is the code I have written.....

gun_trigger_check:

lda $4017
AND #%00010000
bne gun_triggered
rts

gun_triggered:
lda #2
sta #Detection_start
rts

check_white:
lda #Detection_start
cmp #2
bne dwn2rts

poll:
lda $4017
and #%00001000
beq white
JMP poll

white:
jsr duckmaro //// this code is executed if detected
dwn2rts rts


NMI:
jsr gun_trigger_check
jsr check_white


can anyone please tell me where the error is.....
thanks in advace....

by on (#67644)
Quote:
here is the code I have written.....
[...]
gun_triggered:
lda #2
sta #Detection_start
rts

check_white:
lda #Deetection_start

Please show the code you assembled and ran.

by on (#67645)
I don't get what you are telling....
do I need to post the source code.....???

the logic is what I have posted....

by on (#67646)
I think blargg's point was that

sta #Detection_start

Doesn't make much sense as a 6502 instruction. So rather than posting some "pen and paper" code that has typos in it you should post the actual code that you assembled and tested on your NES or emulator.

by on (#67647)
Yes, otherwise we aren't debugging what didn't work on the NES, rather your recollection of it, and how accurately you typed it. The two errors I quoted are ample evidence of the unreliability of the latter. Thus, it's courteous to post the actual code when asking for help, so as not to waste anyone's time.

Quote:
do I need to post the source code.....???

the logic is what I have posted....

The bug may not be in the logic, as you have assumed. If it's not, then only posting the logic would lead us down the same wrong path as you took. Unexamined assumptions are the bane of debugging.

by on (#67660)
I made a new topic, please have a look there :)