Jump to content
IGNORED

REALLY dumb question. How do I move sprites horizontally?


Recommended Posts

You can (re)set the sprites to the current position of the clock within a rasterline via register. 'Just' make sure you count the cycles well. You finetune this with another register. There are very nice examples out there how to properly time this for a dynamical positioning.

Link to comment
Share on other sites

Do WSYNC to start a new line, then waste cycles(Do a loop) until you hit RESP0
Then enter a number to HMP0 for fine position your sprite. Then do a WSYNC, then HMOVE to apply the movement.

There's a subroutine that help you with that.

SetHorizPos
	sta WSYNC	; start a new line
        bit 0		; waste 3 cycles
	sec		; set carry flag
DivideLoop
	sbc #15		; subtract 15
	bcs DivideLoop	; branch until negative
	eor #7		; calculate fine offset
	asl
	asl
	asl
	asl
	sta RESP0,x	; fix coarse position
	sta HMP0,x	; set fine offset
	rts		; return to caller

register x is for what object(0-4) you want to position, example, 0 is for player0, 4 is for ball. Then 'a' for your object's x position.

example:

 	lda CutterM1X
	ldx #3
	jsr SetHorizPos
	sta WSYNC
	sta HMOVE
	sleep 22
Link to comment
Share on other sites

  • 2 months later...

When it comes to programming for the Atari 2600, I think it's safe to say that there definitely are no dumb questions -- even the simplest thing can be extremely difficult to figure out.

 

 

Just for reference, here's a quote from the Stella Programmer's Guide:

 

7.0 Horizontal Positioning

The horizontal position of each object is set by writing to its’ associated reset
register (RESP0, RESP1, RESM0, RESM1, RESBL) which are all “strobe”
registers (they trigger their function as soon as they are addressed). That
causes the object to be positioned wherever the electron bean was in its
sweep across the screen when the register was reset. for example, if the
electron beam was 60 color clocks into a scan line when RESP0 was written
to, player 0 would be positioned 60 color clocks "in” on the next scan line.
Whether or not P0 is actually drawn on the screen is a function of the data
in the GP0 register, but if it were drawn, it would show up at 60. Resets to
these registers anywhere during horizontal blanking will position objects at
the left edge of the screen (color clock 0). Since there are 3 color clocks per
machine cycle, and it can take up to 5 machine cycles to write the register,
the programmer is confined to positioning the objects at 15 color clock
intervals across the screen. This “course” positioning is “fine tuned” by the
Horizontal Motion, explained in section 8.0.

Missiles have an additional positioning command. Writing a “1” to D1 of
the reset missile-to-player register (RESMP0, RESMP1) disables that
missiles’ graphics (turns it off) and repositions it horizontally to the center
of its’ associated player. Until a “0” is written to the register, the missiles’
horizontal position is locked to the center of its’ player in preparation to be
fired again.

8.0 Horizontal Motion

Horizontal motion allows the programmer to move any of the 5 graphics
objects relative to their current horizontal position. Each object has a 4 bit
horizontal motion register (HMP0, HMP1, HMM0, HMM1, HMBL) that can
be loaded with a value in the range of +7 to -8 (negative values are
expressed in two’s complement from). This motion is not executed until the
HMOVE register is written to, at which time all motion registers move their
respective objects. Objects can be moved repeatedly by simply executing
HMOVE. Any object that is not to move must have a 0 in its motion
register. With the horizontal positioning command confined to positioning
objects at 15 color clock intervals, the motion registers fills in the gaps by
moving objects +7 to -8 color clocks. Objects can not be placed at any color
clock position across the screen. All 5 motion registers can be set to zero
simultaneously by writing to the horizontal motion clear register (HMCLR).

There are timing constraints for the HMOVE command. The HMOVE
command must immediately follow a WSYNC (Wait for SYNC) to insure the
HMOVE operation occurs during horizontal blanking. This is to allow
sufficient time for the motion registers to do their thing before the electron
beam starts drawing the next scan line. Also, for mysterious internal
hardware considerations, the motion registers should not be modified for at

least 24 machine cycles after an HMOVE command.

 

 

Really, the simplest and most straight-forward way to implement horizontal movement is to implement the SetHorizPos subroutine that Kiwi mentioned above. Lots of people use that subroutine (or a variation thereof).

Link to comment
Share on other sites

  • 2 weeks later...

You should check out SpiceWare's Collect Tutorial HERE.

 

The routine listed has a few variations - you can also fiddle with it.

 

From my understanding, RESPX needs to be set at cycle 23.

 

The way HMOVE works on the Atari 2600 is that it will automatically draw the Player Graphics at whatever horizontal location you set it.

 

So after you do a HMOVE, and when you finally draw GRP0 or GRP1 at the right VERTICAL position, the 2600 will be waiting for you to STA GRP0 and will automatically draw GRP0 at the right horizontal position.

It's a little bit like magic!

Link to comment
Share on other sites

  • 1 month later...

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...
 Share

  • Recently Browsing   0 members

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