Jump to content



0

quickest check for a missle


6 replies to this topic

#1 grafixbmp OFFLINE  

grafixbmp

    Dragonstomper

  • 659 posts
  • Location:South Central US

Posted Tue Oct 13, 2009 12:02 AM

I have aprox 7 cycles to check the Y index (used as a line counter) for a single missle and draw it. Can the pros do it in this length of time? I probably squeeze an extra cycle making it 8.
I am finding myself doing part of a display routine like checking for an object or positioning it one scanline and then doing the actual loading and displaying of the object the next avaliable one. Or preloading data for display but storing it as a temp in RAM for a call back when the time is right on a scanline.are these ever common practices?

Edited by grafixbmp, Tue Oct 13, 2009 12:13 AM.


#2 Omegamatrix OFFLINE  

Omegamatrix

    River Patroller

  • 4,795 posts
  • Location:Oh, Canada

Posted Tue Oct 13, 2009 1:26 AM

Oh boy.


Okay, I seem to remember a trick for this that was first done in Combat. I think it went like this, IIRC.

1. Have the scanline you want the missile to appear on stored in ram.
2. Compare the scanline you are on the the scanline the missile is on.
3. Push the processor status onto the enable register. The **trick** (why this works) is the Zero Flag is set when the compare is equal to the scanline. Since the Missile Enable and Zero Flag occupy the same bit xxxx xxXx the processor status can be used to enable/disable the missle.

7-8 cycles though?

;stack pointer has to be adjusted before hand, it needs to point to the enable register (ie ENAM1, ENAM2, etc..) so you need to find more cycles before it happens.

CPY scanline ;3
PHP ;4 (already at 7 cycles)


however, you need to readjust the stack register back each time you do this! So you again you need to find more cycles. :(


The simple way to adjust the stack pointer is to waste 4 more cycles (when you can) with a PLA. This will trash the accumulator, so do it when you are not needing, or about to reload the accumulator.

i.e.
PLA ;4 (reset stack to the missile, but trashes the accumulator)
LDA #whatever (ahhhh, now it doesn't matter.)


The minimum needed for this method is 11 cycles (split into 7 cycles, and 4 cycles), plus the stack pointer adjusted before hand (more cycles), plus a ram register (to compare the scanline to), plus the stack pointer free (i.e. you are not jumping to a subroutine during the kernel, or using the stack pointer for other things.)

Edited by Omegamatrix, Tue Oct 13, 2009 1:37 AM.


#3 grafixbmp OFFLINE  

grafixbmp

    Dragonstomper

  • 659 posts
  • Location:South Central US

Posted Tue Oct 13, 2009 1:39 AM

Very nice. I think I can fit this in. Thanks. I just had another thought, but think it would be best as a new topic.

Edited by grafixbmp, Tue Oct 13, 2009 1:40 AM.


#4 bogax OFFLINE  

bogax

    Star Raider

  • 61 posts

Posted Tue Oct 13, 2009 5:45 AM

View PostOmegamatrix, on Tue Oct 13, 2009 1:26 AM, said:

Oh boy.


Okay, I seem to remember a trick for this that was first done in Combat. I think it went like this, IIRC.

1. Have the scanline you want the missile to appear on stored in ram.
2. Compare the scanline you are on the the scanline the missile is on.
3. Push the processor status onto the enable register. The **trick** (why this works) is the Zero Flag is set when the compare is equal to the scanline. Since the Missile Enable and Zero Flag occupy the same bit xxxx xxXx the processor status can be used to enable/disable the missle.

7-8 cycles though?

;stack pointer has to be adjusted before hand, it needs to point to the enable register (ie ENAM1, ENAM2, etc..) so you need to find more cycles before it happens.

CPY scanline ;3
PHP ;4 (already at 7 cycles)


however, you need to readjust the stack register back each time you do this! So you again you need to find more cycles. :(


The simple way to adjust the stack pointer is to waste 4 more cycles (when you can) with a PLA. This will trash the accumulator, so do it when you are not needing, or about to reload the accumulator.

i.e.
PLA ;4 (reset stack to the missile, but trashes the accumulator)
LDA #whatever (ahhhh, now it doesn't matter.)


The minimum needed for this method is 11 cycles (split into 7 cycles, and 4 cycles), plus the stack pointer adjusted before hand (more cycles), plus a ram register (to compare the scanline to), plus the stack pointer free (i.e. you are not jumping to a subroutine during the kernel, or using the stack pointer for other things.)

PHP is three cycles

Assuming you were willing to use self modifying code and reserve the X register
to the pupose you could

TSX
CPY #
PHP

#5 cd-w OFFLINE  

cd-w

    Stargunner

  • 1,195 posts
  • Juno First!
  • Location:Glasgow, UK

Posted Tue Oct 13, 2009 6:23 AM

You can use the stack trick as described above, or if you have plenty of ROM to burn, you could just use:
lda (MPTR),y   + 5
sta ENAM0      + 3
You would need a large table consisting of zeros for every scanline other than the one on which you want to display the missile (which would contain the value 0x10). You can then move the missile vertically by changing the value of MPTR.

Not very efficient, but if you are really stuck for cycles ...

Chris

#6 bogax OFFLINE  

bogax

    Star Raider

  • 61 posts

Posted Fri Oct 16, 2009 3:13 AM

View Postbogax, on Tue Oct 13, 2009 5:45 AM, said:

Assuming you were willing to use self modifying code and reserve the X register
to the pupose you could

TSX
CPY #
PHP

oops, that should be

TXS
CPY #
PHP

#7 Ben_Larson OFFLINE  

Ben_Larson

    Moonsweeper

  • 336 posts
  • Location:Columbus, OH, USA

Posted Fri Oct 16, 2009 6:11 PM

You don't have to reserve the X register. Before the kernel starts, you can do a:

LDX #$1F
TXS

Then inside the kernel, on each line you want to display the missile, you do:

CPY MissileYPos
PHP
PLA

Although that does take longer. After the kernel, you'll probably want to restore the pointer stack.

Edited by Ben_Larson, Fri Oct 16, 2009 6:13 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users