Jump to content

Photo

Newbie struggling -> looking for some clarification on YPOS.


2 replies to this topic

#1 arkleyjoe OFFLINE  

arkleyjoe

    Combat Commando

  • 2 posts

Posted Tue Apr 4, 2017 6:22 AM

Hi,

 

I am a reasonably experienced developer but totally new to ASM and making games for Atari 2600.

 

I have decided to tackle this as a bit of a challenge. I specifically want to focus on ASM rather than bB.

 

I seem to be getting on "ok" with the complex stuff but I am really struggling to visualise how to handle Vertical Positioning.  It should be simple enough. I have a hundred examples of working code I can make work but I am not sure I completely understand how the code works. 

 

Can someone help clarify I am on the right track here.

 

Here is what I think is going on:

 

*Lets assume my sprite is 20 lines high. 

*Lets assume my YPos0 is 80 (from the bottom of the screen)

 

-- I am looping down through my 192 visible scan lines.

-- On each scan line I am checking of see if we have reached the line where I would like to start to display my sprite.

-- i.e 80+20 being the top of my sprite and 80+1 being the last line.

-- On each of the lines where my sprite intersects the scan line I set the relevant value to GP0 and then when we reach line 79 I set it back to empty.

 

For some reason in the examples I am working from I can not ever see the calculation / test I am expecting. 

 

in pseudo code I am expecting to see:

 

if the Current Scanline is equal to or less than YPos0 + Spright Height and Current Scanline is equal to or greater then YPos0 then DRAW THE SPRITE.

 

Here is one example I have found of code I have running and working but do not understand.

; Get next bitmap byte of sprite 0
        MAC DRAW_SPRITE0
	sec			; ensure carry set for subtraction
	lda #SpriteHeight
        INC YP0
        SBC YP0
        ;isb YP0                 ; INC yp0, then SBC yp0
        tay
        bcs .DoDraw             ; outside bounds?
	lda #0			; clear bitmap
	.byte $2c               ; (BIT aaaa, skips next 2 bytes)
.DoDraw
        lda (SpritePtr0),y	; lookup sprite bitmap
        sta GRP0		; A -> GRP0
        ENDM 

Any pointers hugely appreciated, sorry if I have made something simple really convoluted, but it is just not going in to my brain.

 

X position on the other hand, seems simple despite the need to position and then fine position.

 

Joe

 

 

 



#2 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 11,306 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Tue Apr 4, 2017 7:24 AM

I put rather detailed comments in my Collect series, way more than I normally would due to it being a tutorial.  The Y positioning happens in Step 4, though I would recommend you start from the beginning with Let's Make a Game! as it explains the goals.

 

Do note that the blog entries are listed newest first, so you'll have to go to the bottom of page 2 for the start.



#3 BNE Jeff OFFLINE  

BNE Jeff

    Moonsweeper

  • 286 posts
  • Location:Virginia, USA

Posted Thu Apr 20, 2017 10:51 AM

Hi,

 

I am a reasonably experienced developer but totally new to ASM and making games for Atari 2600.

 

I have decided to tackle this as a bit of a challenge. I specifically want to focus on ASM rather than bB.

 

I seem to be getting on "ok" with the complex stuff but I am really struggling to visualise how to handle Vertical Positioning.  It should be simple enough. I have a hundred examples of working code I can make work but I am not sure I completely understand how the code works. 

 

Can someone help clarify I am on the right track here.

 

Here is what I think is going on:

 

*Lets assume my sprite is 20 lines high. 

*Lets assume my YPos0 is 80 (from the bottom of the screen)

 

-- I am looping down through my 192 visible scan lines.

-- On each scan line I am checking of see if we have reached the line where I would like to start to display my sprite.

-- i.e 80+20 being the top of my sprite and 80+1 being the last line.

-- On each of the lines where my sprite intersects the scan line I set the relevant value to GP0 and then when we reach line 79 I set it back to empty.

 

For some reason in the examples I am working from I can not ever see the calculation / test I am expecting. 

 

in pseudo code I am expecting to see:

 

if the Current Scanline is equal to or less than YPos0 + Spright Height and Current Scanline is equal to or greater then YPos0 then DRAW THE SPRITE.

 

Here is one example I have found of code I have running and working but do not understand.

; Get next bitmap byte of sprite 0
        MAC DRAW_SPRITE0
	sec			; ensure carry set for subtraction
	lda #SpriteHeight
        INC YP0
        SBC YP0
        ;isb YP0                 ; INC yp0, then SBC yp0
        tay
        bcs .DoDraw             ; outside bounds?
	lda #0			; clear bitmap
	.byte $2c               ; (BIT aaaa, skips next 2 bytes)
.DoDraw
        lda (SpritePtr0),y	; lookup sprite bitmap
        sta GRP0		; A -> GRP0
        ENDM 

Any pointers hugely appreciated, sorry if I have made something simple really convoluted, but it is just not going in to my brain.

 

X position on the other hand, seems simple despite the need to position and then fine position.

 

Joe

 

 

 

 

If you are looking to dive into Assembly, I also suggest Assembly In One Step http://atariage.com/...cs/onestep.html  .  You can get a basic grasp of assembly in a weekend. 

 

bcs is the test you are looking for above.  Are you familiar with the processor status register?  When a math result (from your sbc) causes the carry flag to be set in that register, the program takes the branch and loads your graphics.  If your carry flag is not set, the program proceeds to that strange .byte $2c.  That's a trick that makes your program skip over the following lda.  Therefore, the previously loaded zero stays in your accumulator and that's what gets stored in the graphics register instead.

 

Also, this is a good reference to bookmark http://www.6502.org/...codes.html#WRAP


Edited by BNE Jeff, Thu Apr 20, 2017 11:01 AM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users