HScroll Tile mode

SGDK only sub forum

Moderator: Stef

Post Reply
tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

HScroll Tile mode

Post by tryphon » Mon Apr 13, 2020 6:03 pm

Hello,

I want to use Horizontal scrolling per tile mode, and I see I shuld use :

Code: Select all

VDP_setHorizontalScrollTile(VDPPlane plane, u16 tile, s16* values, u16 len, TransferMethod tm);
I read that TransferMethod tm can be :

Code: Select all

 *      Transfer method.<br>
 *      Accepted values are:<br>
 *      - CPU<br>
 *      - DMA<br>
 *      - DMA_QUEUE<br>
 *      - DMA_QUEUE_COPY
What is the difference between DMA_QUEUE and DMA_QUEUE_COPY ?

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: HScroll Tile mode

Post by tryphon » Tue Apr 14, 2020 8:59 am

I also was wondering something : I want to simulate parallax scrolling in one plane : lines above line 448 of the map must scroll at half-speed, lines below at full speed.

There can be vertical scroll, so line 448 of the map is not always at the same screen height (let's call scanline the corresponding screen line).

So tile hscroll isn't enough, I must enable line hscroll...

Wouldn't it be faster keep plane hscroll mode, to activate HInt at (scanline - 1), then change the HScroll register in HInt ?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Tue Apr 14, 2020 9:10 am

Looks like you're using last repository version, be careful it's still a bit experimental but it should work :p
I tried to document the DMA_QUEUE_COPY from the doxygen but i admit it remains obscure:
Copy the buffer and put in the DMA queue so it will be transferred at next VBlank
The difference between DMA_QUEUE and DMA_QUEUE_COPY is that the latter will copy the data you want to transfer though DMA in a temporary buffer first (doing a CPU copy for that) and this temporary buffer will be used as source when DMA will actually occurs. This is important when your source buffer may be modified before DMA actually occurs so in the end wrong data may be transferred. Of course it wastes lot of CPU time doing the software copy but what matter is to optimize VBlank usage so it's still interesting in the end.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Tue Apr 14, 2020 9:12 am

tryphon wrote:
Tue Apr 14, 2020 8:59 am
Wouldn't it be faster keep plane hscroll mode, to activate HInt at (scanline - 1), then change the HScroll register in HInt ?
Using line scroll just for a single parallax is really a waste of performance (as you need to update scroll value for each line). Of course it's *much* better to use Hint here (single hint is enough) to change global hscroll when needed :)

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: HScroll Tile mode

Post by tryphon » Tue Apr 14, 2020 11:03 am

Thanks, you confirm what I thought :)

So, is this the way to do it :

1) just after VBlank, I set register 10 with the (scanline - 1) and enable HInt (with a custom callback function) :

Code: Select all

VDP_setReg(10, scanline - 1);
SYS_setHIntCallback(my_callback)
SYS_setInterruptMaskLevel(4);
2) the callback function sets the HScroll value and disable HInt ?

Code: Select all

void my_callback() {
	VDP_setHorizontalScrollTile(new_value);
        SYS_setInterruptMaskLevel(6);
}
(I'm not totally sure about how SYS_setInterruptMaskLevel works, nor the order of doing things :P)

Am I sure not to break something when disabling HInt ? (asked differently : does SGDK use HInt in "normal" use ?)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Tue Apr 14, 2020 3:48 pm

Well, that was almost that :P

Code: Select all

SYS_setHIntCallback(my_callback);
VDP_setHInterrupt(TRUE);
VDP_setHIntCounter(scanline - 1);
No need to deal with the SYS_setInterruptMaskLevel(...) stuff, it should be fine by default.

Then in your callback :

Code: Select all

void my_callback() {
	VDP_setHorizontalScroll(new_value);
}
Use the plan scroll set function, not the tile scroll here. And again you don't need to care about the interrupt level stuff, SGDK handle that for you. it's safer to not touch it ;)

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: HScroll Tile mode

Post by tryphon » Tue Apr 14, 2020 3:59 pm

Thanks :)

But don't I need to disable HInt at the end of my_callback() ?

If I don't do it, won't HInt be triggered at every line after scanline ?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Tue Apr 14, 2020 4:35 pm

Oh yeah you're right, it will be called at each "scanline - 1" so if "scanline -1" is lower than 112 (2x112=224 lines) then indeed you will have multiple calls for a single screen. I think the easiest solution is indeed to call VDP_setHInterrupt(FALSE) after the scrolling change. Then don't forget to re-enabled it after waitVSync() (or into your vint callback if you have one).

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: HScroll Tile mode

Post by tryphon » Wed Apr 15, 2020 11:56 am

Thank you, it seems to work like a charm :)

Get ready Black Turtle !

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Thu Apr 16, 2020 10:02 am

Well done !

Black Turtle ? :p

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: HScroll Tile mode

Post by tryphon » Thu Apr 16, 2020 7:33 pm

Image

(image attachment doesn't seem to work : it's the second boss of Shinobi arcade ;) )

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: HScroll Tile mode

Post by Stef » Fri Apr 17, 2020 7:38 am

Oh i never realized that was the name of second boss :p

Post Reply