Try this. Somewhere in the middle of your screen draw a dot. Do this with the GRP0 register. Specifically:
- wait 80 or so scanlines with a loop.
- load GRP0 with a value that you choose.
- do a WSYNC
- clear GRP0 by storing a 0 to it.
- draw the 80 or so remaining scanlines with another loop.
The end result is you should have a dot somewhere in the middle of the screen. But there are some things we ignored!
1. We didn't set a color for GRP0, and if it's the same color as the background we won't see it. So write some code to update the COLUP0 register.
2. We didn't tell the Atari how many copies to make. It could be anything right now. So look at the Stella's programmer guide for values to load into NUSIZ0.
3. We didn't position the dot on the screen. So right now it could be anywhere. We need to use RESP0 to reset the position, and then fine tune it with HMP0.
So here is a famous routine for repositioning. It is very elegant in that it can be used to reposition anything (ball, missiles, players), and doesn't take many bytes of rom space:
HorizPositioning
sec
sta WSYNC
;---------------------------------------
.divideBy15:
sbc #15 ;2
bcs .divideBy15 ;2³
eor #7 ;2
asl ;2
asl ;2
asl ;2
asl ;2
sta HMP0,X ;4
sta RESP0,X ;4
rts ;6
Place this code somewhere
outside all of your main code. It is a subroutine, which of course is a bit of code that you jump to, and then return from. You'll see RTS at the bottom of it. That means return from subroutine. To jump to it you'll use "JSR HorizPositioning" where JSR means jump to subroutine. Okay, now what you need to do:
- load the accumulator LDA with a value (0 - 255). This is the
horizontal position you want (the value is your choice).
- load X (LDX) with 0. X is only used in this case to choose between missiles, balls, players.
- JSR HorizPositioning
- finally do a WSYNC followed by a HMOVE.
Finally if you can get this working you are on your way! Post any problems you have. Common sources of error (these are just examples):
- confusing LDA #$80 with LDA $80. One means load a value, the other means load from a ram location. Very different results indeed.
- forgeting that X and A have been modified during the routine. In other words if X was previously holding your scanline count, then it will no longer as it was loaded with 0.
- putting JSR all the way to left on your source code. You need indentation! This is an instruction, not a label.
- putting the subroutine in your main loop. Put it within the 4k romsize, but outside all other code.
- crossing a page boundary (more on that later).
This is a lot to chew, but you can do it. Just work your way through it slowly, and ask questions if you don't understand. Once it works try changing the values that you load for horizontal positioning, and observe the results.