Jump to content
IGNORED

How is the light gun read in the 7800


Shannon

Recommended Posts

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.. :ponder: :dunce:

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

Link to comment
Share on other sites

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 by Bryan
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...