Jump to content
  • entries
    334
  • comments
    900
  • views
    258,315

7800 sprite to display list idea


EricBall

786 views

One of the frustrating aspects of 7800 coding is constructing the display lists. On paper it sounds like a great plan - a list of pointers to sprites with width and horizontal positioning info. Very powerful and flexible, but damn difficult to use in practice.

 

My balldemo code has, what I thought, to be as efficient way of doing this as possible. The pseudo code goes something like this:

For each sprite determine which display list based on the vertical position. Add sprite pointer etc to the end of the display list and the next display list. (Each display list controls 1-16 rasters, thus sprites which move vertically need to be in more than one list.) Once all the sprites have been added, add a termination flag to the end of every list.

 

The main problem with this method is the 6502 is an 8 bit processor, so the code has to use indexed indirect ( aka (ZP),Y ) addressing. So there's a lot of data movement steps, copying data from lookup tables, loading the current end of list offset etc. Ugh. The vertical position fiddling is also not pleasant (although probably unavoidable).

 

Anyway, it occurred to me this morning that a more efficient way might be to flip the order. So:

For each display list, scan the list of sprites to determine whether they need to be added based on vertical position. Add sprite pointer etc to the end of the display list. Once all the sprites have been added, add a termination flag to the end of the current list.

 

Now, I haven't tried to code this yet (I want to but I'm trying to work on Leprechaun) but this should be somewhat more efficient because a lot of the mucking around with pointers isn't required. You set up the pointer only once for each display list. Now, it does require scanning through the list of sprites multiple times, but that should be simple comparisons. (Although there may still be some vertical position fiddling required.)

 

The other advantage is it should be possible in this case to compact the display lists so each one follows the other. This would be particularly useful if the game double-buffered the display list updates since it would save RAM. (With the sprite -> display list routine each display list has a fixed length and starts at a fixed position.)

 

Just thought I'd put it here so I wouldn't forget.

4 Comments


Recommended Comments

On paper it sounds like a great plan - a list of pointers to sprites with width and horizontal positioning info. Very powerful and flexible, but damn difficult to use in practice.

Sounds kinda like what I did with the Dragon where I have pointers to 3 lists, 2 containing images(wings, body) and the 3rd containing the horizontal positioning for both sprites(this used to be in 2 lists, I combined them to save ROM at the expense of CPU cycles). Uses up a lot of critical cycles, so I can see the benefit if the video hardware is doing the work for you. But likewise, I can see where that would be troublesome if you're not dealing with static images like I have.

Link to comment

So if I read this right are you thinking of something similar to a flicker sort on the VCS?

 

I think I see what you're saying. This is what I'm gathering.

 

1) Have your sprites sorted is an array based on vertical position

2) Cycle through the display list (which is sorted)

3) Place the sprite in the appropriate display list.

4) Once sprite is placed in the list remove the sprite from the array so sort of like a merge sort.

 

Am I reading your thoughts correctly?

Link to comment

Nope. Don't even bother trying to sort the sprite list. Just scan through the list for each display list looking for ones with Y values in the appropriate range.

 

Actually, the sprites are sorted - back to front (although the front ones may flicker if there are too many sprites on the line).

 

I'm betting that the Y value comparison is a simple enough operation that it can be done very quickly. So the fact that you have to scan through the sprite list N times isn't a big deal.

Link to comment

I coded up most of the routine then did some cycle counting. Unfortunately, it's worse than the "find the display list" routine I used in BallDemo. It's a simpler routine and the not-in-list checking is fairly quick. However, when you multiply the 26 cycles each sprite takes by the number of display lists you end up with a larger number of cycles. Sigh

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