I have been thinking about this off and on for a few years now and finally got around to testing it out, so far it seems to be working so I decided to see what others think about this method. What I am trying to do, is detect where on the screen (divided in to 16x16 pixel blocks for a grid of 16x15) the NES Zapper is aimed when the trigger is pulled. The major drawback about doing this how many frames it takes to do the detection. This method uses the second name table's attribute bytes to quickly display the test patterns.
For my testing, I had my palette setup as follows:
$0f, $0f, $0f, $0f
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
I set the first name table ($2000) to a blank tile showing the background color and the second name table ($2800) to a blank tile showing the second color.
Main program loop:
check for trigger and update trigger flag (set if trigger pulled, unset otherwise)
ORA the Zapper's hit bit against previous stored value
NMI:
check trigger flag, if set jump to zapper handler
otherwise, run normal NMI stuff
Zapper Handler:
-- Phase 0, set Scroll to display second name table. disable background and sprites. set zapper X and Y variables to 0
-- Phase 1, check for phase 0 hit (to check for cheating). Write Phase 1 pattern shown below to second attribute table
-- Phase 2, check for phase 1 hit. if bit set, ora $08 against Zapper Y and save. Write Phase 2 pattern shown below to second attribute table
-- Phase 3, check for phase 2 hit. if bit set, ora $04 against Zapper Y and save. Write Phase 3 pattern shown below to second attribute table
-- Phase 4, check for phase 3 hit. if bit set, ora $02 against Zapper Y and save. Write Phase 4 pattern shown below to second attribute table
-- Phase 5, check for phase 4 hit. if bit set, ora $01 against Zapper Y and save. Write Phase 5 pattern shown below to second attribute table
-- Phase 6, check for phase 5 hit. if bit set, ora $08 against Zapper X and save. Write Phase 6 pattern shown below to second attribute table
-- Phase 7, check for phase 6 hit. if bit set, ora $04 against Zapper X and save. Write Phase 7 pattern shown below to second attribute table
-- Phase 8, check for phase 7 hit. if bit set, ora $02 against Zapper X and save. Write Phase 8 pattern shown below to second attribute table
-- Phase 9, check for phase 8 hit. if bit set, ora $01 against Zapper X and save. reset scroll to show first name table. clear phase counter and trigger flag
Setup and checking for cheating (Phases 0 and 1)
Detecting Y Location (Phases 1 thru 5)
---
---
---
Detecting X Location (Phases 5 thru 9)
---
---
---
Anyway, I am curious to see what others think about this, if anyone has ideas for improvement, or if anyone things i should abandon this idea
I hope to clean up and re-write my test code tonight, after doing so I will post it here.
For my testing, I had my palette setup as follows:
$0f, $0f, $0f, $0f
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
$0f, $30, $30, $30
I set the first name table ($2000) to a blank tile showing the background color and the second name table ($2800) to a blank tile showing the second color.
Main program loop:
check for trigger and update trigger flag (set if trigger pulled, unset otherwise)
ORA the Zapper's hit bit against previous stored value
NMI:
check trigger flag, if set jump to zapper handler
otherwise, run normal NMI stuff
Zapper Handler:
-- Phase 0, set Scroll to display second name table. disable background and sprites. set zapper X and Y variables to 0
-- Phase 1, check for phase 0 hit (to check for cheating). Write Phase 1 pattern shown below to second attribute table
-- Phase 2, check for phase 1 hit. if bit set, ora $08 against Zapper Y and save. Write Phase 2 pattern shown below to second attribute table
-- Phase 3, check for phase 2 hit. if bit set, ora $04 against Zapper Y and save. Write Phase 3 pattern shown below to second attribute table
-- Phase 4, check for phase 3 hit. if bit set, ora $02 against Zapper Y and save. Write Phase 4 pattern shown below to second attribute table
-- Phase 5, check for phase 4 hit. if bit set, ora $01 against Zapper Y and save. Write Phase 5 pattern shown below to second attribute table
-- Phase 6, check for phase 5 hit. if bit set, ora $08 against Zapper X and save. Write Phase 6 pattern shown below to second attribute table
-- Phase 7, check for phase 6 hit. if bit set, ora $04 against Zapper X and save. Write Phase 7 pattern shown below to second attribute table
-- Phase 8, check for phase 7 hit. if bit set, ora $02 against Zapper X and save. Write Phase 8 pattern shown below to second attribute table
-- Phase 9, check for phase 8 hit. if bit set, ora $01 against Zapper X and save. reset scroll to show first name table. clear phase counter and trigger flag
Setup and checking for cheating (Phases 0 and 1)
Detecting Y Location (Phases 1 thru 5)
---
---
---
Detecting X Location (Phases 5 thru 9)
---
---
---
Anyway, I am curious to see what others think about this, if anyone has ideas for improvement, or if anyone things i should abandon this idea
I hope to clean up and re-write my test code tonight, after doing so I will post it here.