Page 1 of 1

HScroll Tile mode

Posted: Mon Apr 13, 2020 6:03 pm
by tryphon
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 ?

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 8:59 am
by tryphon
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 ?

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 9:10 am
by Stef
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.

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 9:12 am
by Stef
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 :)

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 11:03 am
by tryphon
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 ?)

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 3:48 pm
by Stef
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 ;)

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 3:59 pm
by tryphon
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 ?

Re: HScroll Tile mode

Posted: Tue Apr 14, 2020 4:35 pm
by Stef
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).

Re: HScroll Tile mode

Posted: Wed Apr 15, 2020 11:56 am
by tryphon
Thank you, it seems to work like a charm :)

Get ready Black Turtle !

Re: HScroll Tile mode

Posted: Thu Apr 16, 2020 10:02 am
by Stef
Well done !

Black Turtle ? :p

Re: HScroll Tile mode

Posted: Thu Apr 16, 2020 7:33 pm
by tryphon
Image

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

Re: HScroll Tile mode

Posted: Fri Apr 17, 2020 7:38 am
by Stef
Oh i never realized that was the name of second boss :p