Nico Posted May 26, 2012 Share Posted May 26, 2012 Hi all! I'm a bit new at this forum and I noticed a lot of great A2600 programmers here, so perhaps some of them might help me. I've started reading about the A2600 arquitecture (6507, TIA and RIOT) and I've understood most of them, I also made some simple examples using the playfield and player objects. My first goal at A2600 programming is to make a simple PONG like game but so far I havent been able to make any advances. I thought about dividing the game into 3 simple parts: 1- The score 2- The paddles 3- The ball I managed to create the 2 moving paddles but making the ball move both vertical and horizontal seems to be way more difficult than I thought. Can anyone give me some ideas how I can solve this? Thanks! Quote Link to comment Share on other sites More sharing options...
Joe Musashi Posted May 26, 2012 Share Posted May 26, 2012 (edited) Moving the ball horizontally is done the same way as with all other objects. I.e., by setting a coarse postion with the RES registers and doing refinement with HMOVE. For this you can, e.g., use the routine from Battlezone: ... ldx #4 lda BallHPos jsr HPosNoHMOVE sta WSYNC sta HMOVE ... HPosNoHMOVE: SUBROUTINE sec sta WSYNC .loop sbc #15 bcs .loop eor #7 asl asl asl asl sta.wx HMP0,x sta RESP0,x rts Moving an object vertically is a bit more tricky. Basically, this is done by enabling the object on the lines where it is visible: ldy #NUMBER_OF_LINES .loop sta WSYNC ldx #%00000010 ; set ball enable bit tya ; move line number to A sec ; set carry before subtracting sbc BallVPos ; subtract ball start line cmp #BALL_HEIGHT ; test if line is in [0, BALL_HEIGHT-1] bcc .write ; yes -> enable ball ldx #%00000000 ; no -> clear ball enable bit .write stx ENABL dey bne .loop To make it bit clearer I made a small demo that shows how this works. This is simply a moving ball object, which bounces back from the screen borders. BallDemo.asm BallDemo.bin Edited May 27, 2012 by Joe Musashi 2 Quote Link to comment Share on other sites More sharing options...
Nico Posted May 27, 2012 Author Share Posted May 27, 2012 Hi Joe, Thanks for the code its exactly what I was looking for. I'll try to understand how it works so that I can use it in my code. I have a couple of questions: what is the purpose of the word "SUBROUTINE" in this line HPosNoHMOVE: SUBROUTINE and also, I can't find this instruction sta.wx HMP0,x in the 6502 instruction set, what does it do? Quote Link to comment Share on other sites More sharing options...
Joe Musashi Posted May 27, 2012 Share Posted May 27, 2012 I have a couple of questions: what is the purpose of the word "SUBROUTINE" in this line HPosNoHMOVE: SUBROUTINE That's a pseudo-instruction of the DASM assembler. From the manual: "... the SUBROUTINE pseudo-op, which logically separates local labels (starting with a dot). This allows you to reuse label names (for example, .1 .fail) rather than think up crazy combinations of the current subroutine to keep it all unique." Basically, it establishes a local namespace, so that local lables starting with "." are valid relatively to the SUBROUTINE command. So, when you have,e.g., multiple code parts with loops, you can use ".loop" as a label in each part (provided the parts start with SUBROUTINE), without having to use unique names like "loop1", "loop2", "loop3", ... Of course this is DASM-specific. Some assemblers do not have a SUBROUTINE command and make local lables relative to the last full label. and also, I can't find this instruction sta.wx HMP0,x in the 6502 instruction set, what does it do? This instructs DASM to produce a store to a 16bit address eventhough HMP0 is a zero-page (8-bit) address. More precisely, sta.wx HMP0,x is replaced with sta $0020,x (absolute,x addressing, 3 bytes, 5 cycles) instead of sta $20,x (zero page,x addressing, 2 bytes, 4 cycles). Here in this case this is just a simple trick to delay the write to the RES registers (that follows in the next instruction) by one cycle. This is necessary to get the timing right to have objects appear at their correct positions. How this all works is discussed here. 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.