Fastest way to fill the visible part of a background layer?

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Fastest way to fill the visible part of a background layer?

Post by djcouchycouch » Thu May 03, 2012 2:48 am

Hi,

At the very first frame of my game, I fill out the visible tiles of the A plane. (when the screen scrolls around, I just fill out the edges that become visible) Currently this plane fill function, which I've only done a first pass on, is noticeably slow. I'm calling VDP_setTileMap for every tile and you can see the screen filling up. So my function is an obvious candidate for optimization. So what's a faster way of doing this?

My first thought was to use VDP_setTileMapRect but it assumes that the source data is no bigger than the plane. My demo level is 256 x 64 which is larger than the 64 x 64 A plane I've configured. And future levels will be bigger than that. I can always make a new version of the function to work for my case but I'm not sure if that's the fastest available method.

Would it be faster to do DMA transfers of the visible rows from the game's level background data to the plane? Are there any other techniques available?

Thanks,
DJCC

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Thu May 03, 2012 5:15 am

You supposed to turn the screen off while putting all needed data (graphics, initial nametable data) into the VRAM. When the screen is turned off, there is no need to fit into the vblank time, so you can fill up the VRAM much faster.

Nemesis
Very interested
Posts: 791
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Post by Nemesis » Thu May 03, 2012 6:03 am

Also, DMA transfers will be significantly faster than writing the data to the VDP data port. For the best performance, use a DMA transfer while the VDP is in vblank, or the display is disabled.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu May 03, 2012 7:55 am

DMA is your friend, and auto increment is your other friend. I could update all needed in my pattern table update by just doing 2x VRAM transfers combined with right auto increment value.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu May 03, 2012 12:59 pm

Shiru wrote:You supposed to turn the screen off while putting all needed data (graphics, initial nametable data) into the VRAM. When the screen is turned off, there is no need to fit into the vblank time, so you can fill up the VRAM much faster.
Ah, I didn't know you could turn off the screen! I'll try that tonight.

When turning off the screen, does it keep the last visible image? Or does it just go black or whatever the default background color is?
TmEE co.(TM) wrote:DMA is your friend, and auto increment is your other friend. I could update all needed in my pattern table update by just doing 2x VRAM transfers combined with right auto increment value.
Does the DMA transfer use the auto increment in any way on its own?

DJCC

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu May 03, 2012 4:44 pm

Auto increment increases the VDP address pointer on any VRAM access, be it CRAM, VRAM, VSRAM, done by 68K or DMA. It only increments though, no decrement.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu May 03, 2012 5:12 pm

TmEE co.(TM) wrote:Auto increment increases the VDP address pointer on any VRAM access, be it CRAM, VRAM, VSRAM, done by 68K or DMA. It only increments though, no decrement.
Okay! I'll try that out, thanks!

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue May 08, 2012 11:52 am

I haven't had the chance to try this yet, but I was wondering about using DMA and auto-increment together.

Does auto-increment increment only after the completion of the DMA transfer or for every byte/word DMA does?


So, for a DMA transfer of 4 bytes to index 0 and an auto increment of 2 bytes, will it be:

DMA writes be to 0, 2, 4, 6 with auto increment pointer at 8?

or

DMA writes to 0,1,2,3 with auto increment pointer at 5?

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue May 08, 2012 12:04 pm

It increments the address pointer by value in the register on every word/byte it transfers
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue May 08, 2012 12:10 pm

TmEE co.(TM) wrote:It increments the address pointer by value in the register on every word/byte it transfers
Does it apply the auto increment to the source location as well as the destination?

If I DMA 4 bytes from address 0 to address 8, will reads be from source address be 0,1,2,3 or 0,2,4,6? (destination addresses, from your answer, will be 8,10,12,14)

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue May 08, 2012 12:14 pm

Only destination is affected
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue May 08, 2012 12:39 pm

TmEE co.(TM) wrote:Only destination is affected
ok, thanks!

Post Reply