After experimenting by trial and error many configuration of the LSPC timer interrupt feature, I finally succeded in a 60FPS parallax floor perspective effect:
The code is pure C though the NGDEV kit https://github.com/dciabrin/ngdevkit/
I share the base code, if someone want to try and find sme improvments or make some other interesting effects:
Execute this one time in your vblank callback:
// TIMER SET-UP
*REG_TIMERHIGH = 0;
*REG_IRQACK = 7;
// reload when 0 reached | reload at start frame | reload when TIMERLOW is written | enable | 0000
*REG_LSPCMODE = 80; // 0 1 0 1 0000 - start frame only
step = 0;
startEffect = 0;
The timer callback and a few variables:
u16 startEffect = 0;
u16 step = 0;
void rom_callback_Timer() {
// skip useless lines, it is the 1st condition to make it very fast
if (startEffect != 0) {
startEffect--;
return;
}
//
if (step > 1) {
// here add the code being repeated every 2 lines
// for example change a sprite X value to make a skew or distortion
step--;
return;
}
if (step == 0) {
// initialisation at start frame
*REG_LSPCMODE = 208; // 1 1 0 1 0000 - activate time reload
*REG_TIMERLOW = 767; // time corresponding to 2 lines refresh
startEffect = 65; //this value can be changed. 65 means the effect will start at middle screen
step = 130 - startEffect;
return;
}
// this code executes only when your frame is over
*REG_LSPCMODE = 80; // 0 1 0 1 0000 - back to start frame only for proper loop frame to frame
step = 0;
}