Jump to content
  • entries
    657
  • comments
    2,692
  • views
    898,348

Fixed the jitter


SpiceWare

959 views

Before the fix, when three AI players were alive, INTIM would have 1 +/- remaining at the end of VB when one fireball was in the air. When the second fireball was released there would often be insufficient time and the screen would jitter.

 

After the fix, with three AI players alive, INTIM has 7 +/- remaining when one fireball is in the air, 5 +/- when two are in the air and 3 +/- when three are in the air.

 

What's amazing is this was accomplished by commenting out a single line of source code!

 

Back in March, vdub_bobby suggested I use this routine to solve my object positioning problems:

PosObject
  sec
  sta WSYNC
DivideLoop
  sbc #15
  bcs DivideLoop;+4	4
  eor #7
  asl
  asl
  asl
  asl		  ;+10  14
  sta.wx HMP0,X;+5   19
  sta RESP0,X  ;+4   23
  sta WSYNC
;   sta HMOVE
  rts
 

I commented out the HMOVE because I positioned all 5 objects in a row like this:

		ldx #0
	lda Player1X,x
	jsr PosObject; position P0

	inx
	lda Player1X,x
	jsr PosObject; position P1

	inx
	ldy Player1X,x
	iny
	tya
	jsr PosObject; position M0

	inx
	ldy Player1X,x
	iny
	tya
	jsr PosObject; position M1

	inx
	ldy Player1X,x
	iny
	tya
	jsr PosObject; position BL
	sta WSYNC
	sta HMOVE
 

I commented out the 2nd WSYNC, like this

PosObject
  sec
  sta WSYNC
DivideLoop
  sbc #15
  bcs DivideLoop;+4	4
  eor #7
  asl
  asl
  asl
  asl		  ;+10  14
  sta.wx HMP0,X;+5   19
  sta RESP0,X  ;+4   23
;   sta WSYNC
;   sta HMOVE
  rts
 

which bought me back about 5 scan lines worth of CPU time.

12 Comments


Recommended Comments

What happens if objects are near the right edge of the screen? I don't think there's time after a near-right right RESP0 to RTS, bump X, load Y, increment it, JSR, and set carry, all before the next WSYNC deadline. I can't see how you'd avoid using two scan lines per object much of the time, nor how you would have been using more than that with the extra WSYNC in there.

 

My inclination would be to expand out the motion routine to eliminate the JSR/RTS and indexed operations. This should allow the WSYNC for the next horizontal loop to run without wasting a scan line first.

Link to comment

Hmm, good point. One object will always be on the left, but it's possible for the other 4 to be on the right edge at the same time. I'm running out of room to expand the code in the VB bank, so I've moved this code to the bank that handles "top castles". That'll let me remove the JSR/RTS and indexed ops.

Link to comment

You could also rewrite the positioning code like this (untested):

PosObjectSubroutine
  ldx #4
  sta WSYNC		;------begin line 1
  SLEEP 3
  sec			  ;+5	5
PosObjectLoop
  lda Player1X,X   ;+4	9
DivideLoop
  sbc #15
  bcs DivideLoop   ;+4   13
  sta TempRAM,X	;+4   17
  sec			  ;+2   19
  sta RESP0,X	  ;+4   23
  sta WSYNC		;+3   76	begin lines 2, 3, 4, 5, 6
  dex			  ;+2	2
  bpl PosObjectLoop;+3	5 
				;	  4
  ldx #4		   ;+2	6
FinePosLoop
  ldy TempRAM,X
  lda HMOVETable,Y
  sta HMP0,X
  dex
  bpl FinePosLoop  ;+17  23, 40, 57, 74, 14 (of line 7)

  sta WSYNC		;------begin line 8
  sta HMOVE

  rts

Just a hair over 8 scanlines. Need a 15-byte table of HMOVE values.

Link to comment

Just a hair over 8 scanlines. Need a 15-byte table of HMOVE values.

Even works without a table:

 lda TempRAM,X
 eor #$07
 asl		  
 asl		  
 asl		  
 asl	  
 sta HMP0,X

Untested. :lol:

Link to comment

Just a hair over 8 scanlines. Need a 15-byte table of HMOVE values.

Even works without a table:

 lda TempRAM,X
 eor #$07
 asl		  
 asl		  
 asl		  
 asl	  
 sta HMP0,X

Untested. :lol:

Well sure, but then it takes *way* longer. :)

Link to comment

don't have my op code notes handy, though I suspect the ASL method would take an extra scan line.

 

Thomas - weren't you into the C= 64? Did you happen to watch the video I posted of my BBS software in action?

Link to comment
I think just an extra half a scanline.

 

Since the routine ends with WSYNC/HMOVE, unless you have something useful you want to stick before that WSYNC it's going to be a whole scan line.

Link to comment

Takes longer than the original normally takes; however, it doesn't take as long as the original's worse case scenerio. Also uses less ROM to boot!

Link to comment
don't have my op code notes handy, though I suspect the ASL method would take an extra scan line.

A few extra cylces, yes.

 

BTW: Depending on the minimum and maximum possible positions, you may be able to set HMxx directly after the DivideLoop.

 

Did you happen to watch the video I posted of my BBS software in action?

Nope, must have missed that. Link?

Link to comment

The HMxx can always be set for the left side player, but for the other 4 objects it depends on their screen location. The old routines tried to set it each line and the time remaining in INTIM would vary from $06-$0A when one fireball was active and there were 3 AI players. If the 2nd fireball came out the time remaing would run out if enough objects moved to the right. The new way isn't as fast as the fastest of the old routine, but it's not as slow as the worst case which is a plus.

 

The video's in the next blog entry

Link to comment
Guest
Add a comment...

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