Sprite data management

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

Posts: 6
Joined: Thu Sep 10, 2020 8:13 pm

Sprite data management

Postby Holmanix » Sat Mar 20, 2021 5:56 pm

Hi Everyone,

I managed to get the sprite engine to work with assembly code today, which I'm over the moon about. I see that the data to load a full set of 8-bit sprite patterns into the engine comes in at a healthy 16K which is enormous by speccy standards and not something you'd want hanging around in ram for any length of time. What I'd like to do at the start of the program is to switch a bank of memory in containing the sprite pattern data, stream the data into the sprite engine and then switch the memory bank back out again. This seems pretty straightforward although I've got one glaring issue that I don't understand, and that's how to get the data into the memory bank in the first place in order to page it in.

It's something I didn't really understand when I was looking at the 128K's memory paging system and I sort of brushed it under the carpet a bit, but any cheap and cheerful arcade knockoff I might turn my hand to making is going to need me to learn how to manage this properly. It can obviously be done, I just don't know really where to look to find out!

Any pointers would be really appreciated.


Posts: 256
Joined: Mon Jul 16, 2018 7:11 pm

Re: Sprite data management

Postby Ped7g » Sat Mar 20, 2021 8:18 pm

If you are using sjasmplus and NEX file format, you can pre-load the sprite data into target page during assembling, and make it part of the NEX file.

Then at runtime you need just to switch the page mapping, as the loading is done by the OS before executing your code.

For other file formats (dot file, classic TAP) you may eventually need to load the data manually, ie. page-in the target page, and use the disk/tape loading routine to load the 16ki of sprite gfx there, and switch memory back. (or if you use other assembler or NEX file creator, you need to check what is the control scheme for it to prepare the data into NEX file into desired pages).

(for sjasmplus I have example in SpecBong - although the sprite pixel upload is done by CPU, not by DMA, so it could be further improved: https://github.com/ped7g/SpecBong/wiki/ ... t-(Part-2) )

Posts: 186
Joined: Tue May 30, 2017 1:06 am
Location: Bristol, UK

Re: Sprite data management

Postby dave18 » Sun Mar 21, 2021 8:39 am

Don't forget to make sure you stack is located somewhere safe when paging in and transferring data. It's an easy mistake to accidentally page out the stack.

My Bubble Bobble source dynamically pages in data for any sprite it needs and DMAs it into the correct pattern. Data is preloaded using the SNX format. Source is a bit messy and not that well commented but it is here https://github.com/dave18/BubNext
Sprite routine starts on line 8213 in game.asm

Posts: 6
Joined: Thu Sep 10, 2020 8:13 pm

Re: Sprite data management

Postby Holmanix » Sun Mar 21, 2021 12:00 pm

Thanks Gents, this should keep me going for a while! I'm creating everything as .SNA through sjasmplus at the moment so my first task is to start using NEX and understand how it's all nailed together, another 'I'll worry about that another day' topic that now needs some proper attention.

Cheers for the help

Who is online

Users browsing this forum: No registered users and 1 guest