Primordial Ooze #26 Posted December 7, 2011 So how would i implement Cathode Ray Timing in 6508 assembly language? A simple example should be enough to get started, but i'll let you know as soon as i add it to my game code. Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
Eckhard Stolberg #27 Posted December 7, 2011 Say what????? So what i would need to do is create 2 variables. One would hold the x position of the electron beam. The other one would replace the y register for the y position of the electron beam. Is this correct or am i totally off? Also how many x and y positions are there in a CRT television screen? The 2600 can display 160 pixels in about 200 scanlines, but unfortunately you can't poll the light sensor that often. Also the Atari lightgun isn't that acurate to begin with. So a lightgun resolution of 53 x 40 seems realistic. A couple of years ago I took the lightgun routine from Sentinel, changed the values a bit to work better on my TV and made a lightgun test program out of it. It displays a grid with a resolution of 53 x 38 squares. If you pull the trigger of the lightgun in the left controller port, a hit marker should appear in one of the squares. I adjusted to position values so that, if you press the gun directly against the screen of your CRT and position it over one of the squares, the hit marker should appear in that square when you pull the trigger. It works fine on my multi-standard TV. If the marker is off on your TV, you need to adjust the position values accordingly. guntest.zip Quote Share this post Link to post Share on other sites
Primordial Ooze #28 Posted December 7, 2011 Say what????? So what i would need to do is create 2 variables. One would hold the x position of the electron beam. The other one would replace the y register for the y position of the electron beam. Is this correct or am i totally off? Also how many x and y positions are there in a CRT television screen? The 2600 can display 160 pixels in about 200 scanlines, but unfortunately you can't poll the light sensor that often. Also the Atari lightgun isn't that acurate to begin with. So a lightgun resolution of 53 x 40 seems realistic. A couple of years ago I took the lightgun routine from Sentinel, changed the values a bit to work better on my TV and made a lightgun test program out of it. It displays a grid with a resolution of 53 x 38 squares. If you pull the trigger of the lightgun in the left controller port, a hit marker should appear in one of the squares. I adjusted to position values so that, if you press the gun directly against the screen of your CRT and position it over one of the squares, the hit marker should appear in that square when you pull the trigger. It works fine on my multi-standard TV. If the marker is off on your TV, you need to adjust the position values accordingly. guntest.zip Thanks, i found this very useful. Question though, is this: CoarseTest: dex beq CEndRelay ; test is over with no hit detected nop nop nop nop nop nop nop bit INPT4 ; test lightgun sensor bpl HitX01to03 ; did we hit within the last 5 cycles bit INPT4 bpl HitX04to08 bit INPT4 bpl HitX09to13 bit INPT4 bpl HitX14to18 bit INPT4 bpl HitX19to23 bit INPT4 bpl HitX24to28 bit INPT4 bpl HitX29to33 bit INPT4 bpl HitX34to38 bit INPT4 bpl HitX39to43 bit INPT4 bpl HitX44to48 bit INPT4 bpl HitX49to53 jmp CoarseTest CEndRelay: jmp CEndFrame ; test is over with no hit detected HitX49to53: lda #158 ; hit was at pixel 158 or before bne AdjustHpos HitX44to48: lda #143 bne AdjustHpos HitX39to43: lda #128 bne AdjustHpos HitX34to38: lda #113 bne AdjustHpos HitX29to33: lda #98 bne AdjustHpos HitX24to28: lda #83 bne AdjustHpos HitX19to23: lda #68 bne AdjustHpos HitX14to18: lda #53 bne AdjustHpos HitX09to13: lda #38 bne AdjustHpos HitX04to08: lda #23 bne AdjustHpos HitX01to03: lda #8 bit INPT4 The only way to do it cause it seems to be a very messy way of doing it. Sorry if i sound rude but, i just want to know before i end up adding code that i will need to refix latter. Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
Eckhard Stolberg #29 Posted December 8, 2011 Thanks, i found this very useful. Question though, is this: The only way to do it cause it seems to be a very messy way of doing it. Sorry if i sound rude but, i just want to know before i end up adding code that i will need to refix latter. No need to apologize as this part of the code was borrowed from Sentinel. Of course you could do it differently. But in oder to get a reasonably high horizontal resolution you need to be able to check the lightgun sensor as often as possible during a scanline. And if you try to avoid all unnecessary loops and checks to be able to fit in more reads of the lightsensor, the code can get a little messy. Also you might have noticed that the AdjustHpos subroutine only is 75 cycles long. That way the reads in the scanlines following the first hit detection always happen one processor cycle before the check in the last scanline. Since the lightgun sensor would register a hit for several scanlines, you can increase the resolution of the check to single cycle precision, which is the best you can achieve on the VCS. And since you have to make sure that the reads of the lightgun sensor always happen after the same number of cycles after the last read no matter which of the branches was takes, the code gets a little more messy. Quote Share this post Link to post Share on other sites
Primordial Ooze #30 Posted December 8, 2011 (edited) Thanks, i found this very useful. Question though, is this: The only way to do it cause it seems to be a very messy way of doing it. Sorry if i sound rude but, i just want to know before i end up adding code that i will need to refix latter. No need to apologize as this part of the code was borrowed from Sentinel. Of course you could do it differently. But in oder to get a reasonably high horizontal resolution you need to be able to check the lightgun sensor as often as possible during a scanline. And if you try to avoid all unnecessary loops and checks to be able to fit in more reads of the lightsensor, the code can get a little messy. Also you might have noticed that the AdjustHpos subroutine only is 75 cycles long. That way the reads in the scanlines following the first hit detection always happen one processor cycle before the check in the last scanline. Since the lightgun sensor would register a hit for several scanlines, you can increase the resolution of the check to single cycle precision, which is the best you can achieve on the VCS. And since you have to make sure that the reads of the lightgun sensor always happen after the same number of cycles after the last read no matter which of the branches was takes, the code gets a little more messy. I just finished adding your light checking routine to my lightgun game and am having a bit of trouble. When the lightgun's trigger isn't pressed in the right port, the screen is displayed correctly. However when i press the trigger well...... As you can see something funky is going on. I have attached the latest version of my source code for your enjoyment. Any assistance in this matter would be greatly appreciated. Sincerely, Primordial Ooze Edited December 12, 2011 by Primordial Ooze Quote Share this post Link to post Share on other sites
Eckhard Stolberg #31 Posted December 9, 2011 I just finished adding your light checking routine to my lightgun game and am having a bit of trouble. When the lightgun's trigger isn't pressed in the right port, the screen is displayed correctly. However when i press the trigger well...... As you can see something funky is going on. I have attached the latest version of my source code for your enjoyment. Any assistance in this matter would be greatly appreciated. The lightgun test routine exits once it has detected the lightgun position. If you are pointing the gun at the top of the screen, that might be after 50 scanlines or something. This is not enough for a full frame and therefore the screen starts to roll. To compensate for that my program sets a timer before executing the lightgun test routine and waits for that timer to expire afterwards. After having a quick look at your code, it seems that you moved the timer handling code and forgot to set the timer to a proper value before calling the lightgun test subroutine. Quote Share this post Link to post Share on other sites
Primordial Ooze #32 Posted December 9, 2011 I just finished adding your light checking routine to my lightgun game and am having a bit of trouble. When the lightgun's trigger isn't pressed in the right port, the screen is displayed correctly. However when i press the trigger well...... As you can see something funky is going on. I have attached the latest version of my source code for your enjoyment. Any assistance in this matter would be greatly appreciated. The lightgun test routine exits once it has detected the lightgun position. If you are pointing the gun at the top of the screen, that might be after 50 scanlines or something. This is not enough for a full frame and therefore the screen starts to roll. To compensate for that my program sets a timer before executing the lightgun test routine and waits for that timer to expire afterwards. After having a quick look at your code, it seems that you moved the timer handling code and forgot to set the timer to a proper value before calling the lightgun test subroutine. Are you talking about these lines: lda INTIM ; wait for VBLANK period to end bne Check sta WSYNC lda #236 ; timer for 199 scanlines sta TIM64T lda #$00 sta WSYNC sta VBLANK Cause that is the only thing that resembles a timer for me. Please let me know if this is the timer you are talking about. Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
Eckhard Stolberg #33 Posted December 10, 2011 Are you talking about these lines: lda INTIM ; wait for VBLANK period to end bne Check sta WSYNC lda #236 ; timer for 199 scanlines sta TIM64T lda #$00 sta WSYNC sta VBLANK Cause that is the only thing that resembles a timer for me. Please let me know if this is the timer you are talking about. Yes, that code waits for the timer that I set up for the VBLANK period to expire and then sets up a new timer for the 199 scanlines of the lightgun position check. You also need the code after the CEndFrame label, because it waits for this timer to expire and discharges the capacitors for the lightgun sensor, which is needed, so that you can do another test later. Quote Share this post Link to post Share on other sites
Primordial Ooze #34 Posted December 12, 2011 Hi guys, I've managed to attached Eckhard Stolberg's and it seems to be working. The next step is going to be how should i detect collisions? There are 2 possibilities for this. One is using the bounding box method: lda DuckX cp BulletX ; if the duck's x position is greater then then bullet's x position bcc SkipNoCollision lda BulletX cp DuckX ; if the bullet's x position is less then the duck's x position bcs SkipNoCollision lda DuckX cp BulletX ; if the duck's y position is greater then then bullet's y position bcc SkipNoCollision lda BulletX cp DuckX ;if the bullet's x position is less then the duck's x position bcs SkipNoCollision The other way is the "Atari 2600 way" which is done by making a crosshair sprite, setting it's position to where the gun was fired and test for a collision. My only problem with that is that it's not gonna be faithful to the original Qwak! and Duck Hunt games. Any input would be greatly appreciated. Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
+SpiceWare #35 Posted December 12, 2011 Duck = Player 0 Crosshair = Player 1, color same as background The crosshair wouldn't be visible unless you're using the playfield to draw clouds or something. Quote Share this post Link to post Share on other sites
Primordial Ooze #36 Posted December 12, 2011 Duck = Player 0 Crosshair = Player 1, color same as background The crosshair wouldn't be visible unless you're using the playfield to draw clouds or something. This was my original idea, except then i can't use player 1 for the dog sprite Sincerely, Quacker Blaster Quote Share this post Link to post Share on other sites
+GroovyBee #37 Posted December 12, 2011 Just use the ball. It'll be the same colour as the playfield but your player sprite will be in front of it. Quote Share this post Link to post Share on other sites
Primordial Ooze #38 Posted December 12, 2011 Does player1/ ball have to be drawn in order for collisions to register or can i just position the ball and check for a collision? The reason i ask is because i plan on extending the playfield so it uses multicolors, though it's just an idea at the moment. Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
+SpiceWare #39 Posted December 12, 2011 This was my original idea, except then i can't use player 1 for the dog sprite You only need to draw the cross hairs for 1 frame after the player pulls the trigger - so just for that single frame skip drawing the dog. Or can you also shoot the dog? If so you could reuse Player 0 to draw the dog (assuming the duck is always in the air and the dog on the ground). Quote Share this post Link to post Share on other sites
Primordial Ooze #40 Posted December 12, 2011 This was my original idea, except then i can't use player 1 for the dog sprite You only need to draw the cross hairs for 1 frame after the player pulls the trigger - so just for that single frame skip drawing the dog. Or can you also shoot the dog? If so you could reuse Player 0 to draw the dog (assuming the duck is always in the air and the dog on the ground). The dog will most likely only appear after the duck is shot or gets away so most likely they will never appear at the same time. How to get the dog to show the duck being held in his hand after it drops is another question. Most kernals draw the sprites for a full frame, so how would i make it only draw for a single frame? Sincerely, Primordial Ooze Quote Share this post Link to post Share on other sites
+SpiceWare #41 Posted December 12, 2011 psuedo code if trigger just pulled sprite1 = cross hairs X1 = lightgun X location Y1 = lightgun Y location else if dog onscreen sprite1 = dog image X1 = dog X position Y1 = dog Y position else Y1 = 230 (offscreen location) endif Quote Share this post Link to post Share on other sites
Primordial Ooze #42 Posted December 12, 2011 (edited) Update: Post has been moved to the 2600 programming section to keep the thread less cluttered and on topic. Sincerely, Primordial Ooze Edited December 13, 2011 by Primordial Ooze Quote Share this post Link to post Share on other sites
Shawn #43 Posted May 10, 2016 (edited) Necro vote for yes. Edited May 10, 2016 by Shawn Quote Share this post Link to post Share on other sites