Re: [stella] Intelligent Job-System idea

Subject: Re: [stella] Intelligent Job-System idea
From: Manuel Polik <cybergoth@xxxxxxxx>
Date: Sat, 04 Jan 2003 11:16:54 +0100
Hi there Christopher!


Hey, thanks for your insights! This really seems to be 
one funny little machine!

> For your purposes, I'd suggest a table for low-
> priority routines, ones that don't need to be called 
> every frame. And then your NextRoutine offset variable 
> would only be reset when the end of the table is 
> reached. So calling the routines could be spread out 
> over several frames. Something like:

This is a really excellent idea!

>     CMP #$05       ; more than 6*64 cycles left?
>     BCS end_VBLANK
>     lda NextLowPriorityRoutine
>     cmp NumberOfLowPriorityRoutines
>     beq done_low_priority_routines
>     asl
>     tay
>     lda LowPriorityRoutineTable,y
>     sta RoutineOffset
>     lda LowPriorityRoutineTable+1,y
>     sta RoutineOffset+1
>     inc NumberOfLowPriorityRoutines
>     jmp (RoutineOffset)   ;Routines need to end by 
with: jmp low_priority_routine_handler
>     lda #0
>     sta NextLowPriorityRoutine
>;... (BTW - This is off the top of my head, may be 
buggy as hell...)
> LowPriorityRoutineTable: 
> .word FirstLowPriorityRoutineStartingAddress
> .word SecondLowPriorityRoutineStartingAddress
> .word ThirdLowPriorityRoutineStartingAddress
> .word FourthLowPriorityRoutineStartingAddress

This is an excellent mechanism!

> You are adding the overhead of around 30 cycles per 
> routine plus 1 byte RAM over you original idea, but 
> otherwise you're probably going to be adding:
>     CMP #$05       ; more than 6*64 cycles left?
>     BCC Continue
>     RTS

Well, I have to carefully consider this. A great deal of 
routines I do are really required every frame.

Remember I have a scenario like this:
(Pseudo C code)

    if (IDObject(i)==METEOR)
        JSR dothis1
        JSR dothis2
        JSR dothis3
        JSR dothis4
    if (IDObject(i)==SHIP)
        JSR dothis1
        JSR dothis2
        JSR dothat
        JSR dothis4
    if (IDObject(i)==MOTHERSHIP)

So one of the first not so trivial issues is finding the 
proper XX here:

>     CMP #$XX       ; more than X*64 cycles left?
>     BCC Continue
>     RTS

It's like this: For the first 5 objects, I can execute 
"dothis4", but for the other 5 ships I should bail out. 
They still should all excute dothis1-3 in time though.

Now, I can only estimate how long executing dothis1-3 
takes - it's depending on the actual situation and on 
the distribution of objects. For example dothis2 might 
be done quicker for meteors than for ships...

Second thing is, that I don't know the order of the 
objects. The more heavy calculation things might come 
all first or all at the end...

Well, in the end XX just needs to be big _enough_. Being 
the suicidal try & error coder, I think I will find a 
proper value here :-)

> To the start of a bunch of routines (it'll only take a 
> few before you're using more ROM than my routine) and 
> you may have some problems ensuring that all those 
> routines get called in a timely manor (Supposed you 
> have 6 of those routines, each with the above timer 
> check, it may sometimes take several frames to get 
> down to the last couple routines while the first 
> couple routines get called every frame. With my table 
> you at least know they'll get called as part of the 
> sequence of routines...)

Now here is a small advantage I have: Since my Objects 
are constantly swapping their positions, I think their 
lowlevel stuff will be executed just "often enough".

I think again I have to just test & balance my system 

>Anyway, there's my two cents...

Thanks for the brill concept. Maybe I should've known 
that _before_ I started. :-)

Well, I'm wiser now, but this time I've just to live 
with what I've got so far...


Archives (includes files) at
Unsub & more at

Current Thread