Beginner Needs Help in 6809 code, but 6502 is fine too!
Posted: Mon Nov 05, 2012 4:54 pm
I hope it's ok to ask this here because it's 6809 code, but it's pretty similar to 6502 so i hoped it would be ok. (i cant find any 6809 forums!) I am a *complete* beginner but i am trying to write a program for the Vectrex console, hence the 6809
To Start with i wanted to just make a dot move left and right on the screen, but limit it to the borders of the screen. I normally write in a BASIC variant and to do that you would do something like this below. where XMan is the x-position of the object (or man) and Xv is the x-vector added to his x-position each frame
Here is the logic part of my 6809 program (I have taken out the initialisation + the drawing parts which arent relevant)
(sorry for the weird formatting - it looks ok in the message box, just not here)
This works, but i wanted if know if there is a faster way to do it? with the least number of cycles, because i will want to eventually move a lot of objects round the screen and then i will be checking limits on the y-axis too, so for this reason, it needs to be fast. Thanks very much for any help
if 6809 is a problem then 6502 code is fine too. I have read (beginner) books on both recently.
To Start with i wanted to just make a dot move left and right on the screen, but limit it to the borders of the screen. I normally write in a BASIC variant and to do that you would do something like this below. where XMan is the x-position of the object (or man) and Xv is the x-vector added to his x-position each frame
Code: Select all
Repeat
xMan=XMan+Xv
If Xv>20 then Xv=20 : Xv=-Xv
If Xv<-20 then Xv=-20 : Xv=-Xv
Until Escape key pressedHere is the logic part of my 6809 program (I have taken out the initialisation + the drawing parts which arent relevant)
Code: Select all
loop:
LDA XMan ;add Xv to Xman
ADDA Xv
CMPA #20 ;Check XMan >20
BLE chk2
LDA #20
BRA NegXv
chk2:
CMPA #-20 ;Check if XMan <20
BGE fin
LDA #-20
BRA NegXv
NegXv:
NEG Xv ;two's complement Xv
fin:
STA XMan
BRA loop ; and repeat foreverThis works, but i wanted if know if there is a faster way to do it? with the least number of cycles, because i will want to eventually move a lot of objects round the screen and then i will be checking limits on the y-axis too, so for this reason, it needs to be fast. Thanks very much for any help
