Jump to content
IGNORED

New way for repositioning (all 5 objects in 1-shared code)


LS_Dracon

Recommended Posts

First, a look in "standard" repositioning code :

 

;-----------------------
  lda P0_XPos;Load desired position
  ldx #0		; Clean X
  jsr SetXPos ;Jump to repositioning code
;-------------------------
...
  sta WSYNC
  sta HMOVE
...
;------------------------------------------
SetXPos;SUBROUTINE
;------------------------------------------
sec
sta	 WSYNC
WaitObject:
sbc	 #$0f; 2
bcs	 WaitObject; 2³ waste cicles
eor	 #$07; 2   adjust nibble
asl; 2   shift bites for correct HMXX value
asl; 2   
asl; 2
asl; 2
sta	 HMP0,x; 4  store in HMXX (fine adjust)
sta.wx  RESP0,x	; 5  Then Reset Position
rts; Return to code
;-----------------------------------------------

This code you set position for P0. For others objects you need create another loop and RESXX again.

I made some motiffications, and here's the code :

;-----------------------
  lda P0_XPos;Load desired position
  jsr SetXPos ;Jump to repositioning code
  sta RESP0;But repositioning when return
  sta HMP0	;The loop can be used for all objects
;-------------------------
...
;------------------------------------------
SetXPos 
;------------------------------------------
sec
sta	 WSYNC
WaitObject:
sbc	 #$0f		 
bcs	 WaitObject
eor	 #$07		
asl					 
asl					 
asl					 
asl					
rts	;Return without sta RESXX
;-----------------------------------------------

Note, this code you don't need ldx #0.

So all players can use only 1 loop code for repositioning :

;-----------------------
  lda P0_XPos;Repositioning P0
  jsr SetXPos	
  sta RESP0	 
  sta HMP0	  
;-----------------------
  lda P1_XPos;Repositioning P1
  jsr SetXPos	
  sta RESP1	 
  sta HMP1	 
;-------------------------
  lda M0_XPos;Repositioning Missile0
  jsr SetXPos	
  sta RESM0	 
  sta HMM0	  
;-------------------------
  lda M1_XPos;Repositioning Missile1
  jsr SetXPos	
  sta RESM1	 
  sta HMM1	 
;-------------------------
  lda BL_XPos;Repositioning Ball
  jsr SetXPos	
  sta RESBL	 
  sta HMBL	  
;--------------------------
  sta WSYNC
  sta HMOVE
...
;------------------------------------------
SetXPos ;SUBROUTINE
;------------------------------------------
sec
sta	 WSYNC
WaitObject:
sbc	 #$0f		 
bcs	 WaitObject
eor	 #$07		
asl					 
asl					 
asl					 
asl					
rts;Return

That is. Tested and work in emulators and real hardware.

The standard code I copy from one demo posted here by Thomas Jenzsch.

Probably have similar codes, but I never saw, so I decide share this code.

Edited by LS_Dracon
Link to comment
Share on other sites

Hi,

 

Your code is correct, but I believe you are misunderstanding the usage of the X register in the original code. The purpose of X is to select the object you want to position horizontally. (0=P0, 1=P1, 2=M0, 3=M1, 4=Ball). So if you want to position M1 say with the original routine you would fo this:

 

	 LDA M0xPos
 LDX #3	   ; 3=M0 
 JSR SetXpos

 

You can do the same thing for the other 4 objects. Just as you did in your modified code. So you can use the exact same routine to position all 5 objects.

 

As an added bonus, if you arrange your object X positions in consecutive memory locations in RAM you can use a small loop to position them all like this:

 

	   ObjectArray EQU  $80
   P0xPos		EQU  $80
   P1xPos		EQU  $81
   M0xPos		EQU  $82
   M1xPos		EQU  $83
   BallXpos	  EQU   $84
  

PositionAllObjects
  LDX #4  ; Start with the Ball and count downwards.
.positionLoop
  LDA ObjectArray,X  ; Use indexed addressing to read the X pos of the next object to be repositioned.
  JSR SetXpos		   ; Position object X
  DEX					   ; Decrement X to point at next object
  BPL .positionLoop	; While X >= 0 go to the top of the loop.

 STA WSYNC
 STA HMOVE			 ; Apply the fine adjustment for all 5 objects.
 RTS						; All 5 objects are positioned.

 

The original code uses Indexed addressing with the X register to allow a simple loop to position any or all of the objects.

 

Cheers!

Link to comment
Share on other sites

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...
  • Recently Browsing   0 members

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