Re: Odp: [stella] AOTM AFOS problems

Subject: Re: Odp: [stella] AOTM AFOS problems
From: Manuel Rotschkar <cybergoth@xxxxxxxx>
Date: Fri, 02 Jul 2004 00:14:56 +0200
Hi there!

I completely don't understand these routines that you have written.

Hm... the problem is that I'm not good at teaching stuff like that. Andrew can do that way better than I ;-)


Well, I'll give it a try anyway. Let's have a look at what you do now for the missiles:

UfoMissileActive
    LDY #0              ;+2 71
    SEC                 ;+2 73
    TXA                 ;+2 75
    SBC Ufo_Missile_Y   ;+3 78
    ADC #6              ;+2 80
    BCC SkipUfoMissileActive ;+2 82
    LDY #2              ;+2 84
 SkipUfoMissileActive
    STY ENAM1           ;+3 87

So you're drawing a missile that is 6 pixels tall, starting at Ufo_Missile_Y.
X holds the linecounter and in Y you prepare the value for ENAM1.
Also, the code is running 17/18 cycles.


Well, a missile height of 6 is almost worst case. Better would be any value from 1-4 or any power of 2.

Now, even this can be sped up.

Observe the following:

The descission wether you enable ENAM or not, depends on the state of the carry after the subtraction.

When it's set   - Enable the missile.
When it's clear - Disable the missile.

Now, to dis/enable the missile you need to clear/set the second bit of the Enam register.

Wow! Here we get an idea: Couldn't we just write the Carry Bit to ENAM?

Have a look at this:

UfoMissileActive
    SEC                 ;+2 Set carry for subtraction
    TXA                 ;+2 Move line counter into A
    SBC Ufo_Missile_Y   ;+3 Subtract missile position
    ADC #6              ;+2 Add missile height
    ROL			;+2 Move Carry into the first bit
    ROL			;+2 Move Carry into the second bit
    STA ENAM1           ;+3 Store second bit into ENAM

See, that little tweak uses _always_ 16 cycles and also frees Y for you.

Greetings,
	Manuel

Current Thread