Shannon Posted July 8, 2008 Share Posted July 8, 2008 I was trying to figure out how a game reads the light gun (what memory addresses for the screen location and triggers). I even looked at the source for crossbow but for some reason it seems to be eluding me.. Quote Link to comment Share on other sites More sharing options...
Eckhard Stolberg Posted July 10, 2008 Share Posted July 10, 2008 I was trying to figure out how a game reads the light gun (what memory addresses for the screen location and triggers). I even looked at the source for crossbow but for some reason it seems to be eluding me.. IIRC correctly the pin for "joystick right" goes low when the lightgun trigger gets pulled. The pin for the joystick button goes low when the lightgun is pointed at something bright. When the lightgun trigger gets pulled, the game waits for the next frame to start and then displays one frame filled completely with a bright colour. During this frame the game "races the beam" so to speak, as it keeps polling INPT4 in a short loop untill it goes low. Since a loop like that could only cover very few possible hit spots in a line, the game will repeat the loop in the next couple of lines after a 'hit' detection but shifted by one CPU cycle in each line. If you want to emulate the lightgun, you need to have the DMA cycle stealing work properly, so that the IPT4 reads happen at the right screen position. Ciao, Eckhard Stolberg Quote Link to comment Share on other sites More sharing options...
Shannon Posted July 10, 2008 Author Share Posted July 10, 2008 Ahhh ok thanks. Even though I did put in maria cycle counting. Due to the way mess processes frames it sounds like doing the lightgun wouldn't really be possible. Quote Link to comment Share on other sites More sharing options...
Bryan Posted July 12, 2008 Share Posted July 12, 2008 (edited) I know it's common to see the screen flash when the trigger is pulled on video games that use a light gun. I've never seen the "official" way to do it, but it seems the best way would be like this: When the trigger is pulled, turn off DMA during VBlank and make the background a bright color (this will help the gun see the beam). On each line, sit in a tight loop watching the triggers for detection of the beam. As long as the input it set to latch, it can be detected by counting where the state changed like this: lda #$00 ldy #80 cpy INPT4 adc #$00 cpy INPT4 adc #$00 and so on for each scan line (or you every other line or so since you won't get a lot of horizontal resolution anyway). Clear the latch between lines. Turn DMA back on at the next VBlank. You'll get quick blink of the screen, no lost cycles to worry about, and a number in A for each scanned line that tells you where the latch was hit. -Bry Edited July 12, 2008 by Bryan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.