Ok I'll try to sketch my idea about the main + deatail sprite management
Assume that the SAT is in RAM with:
N active positions (planes)
M main sprites
N-M detail sprites
In case of no 5thsprite, you copy directly from ram to vram N sprite positions [0,N-1]-> [0,N-1].
Assume now that there is 5thsprite.
Let S0 be the 5th sprite plane from the VDP.
Assume S0<M (i.e. S0<=M-1)
We want to scramble the main sprites and leave the details where they are.
RAM VRAM
0 0
P S0
M-1 M-1
N-1 N-1
S0 in VRAM corresponds to plane P in ram
We copy :
[P,M-1] -> [0,M-1-P]
[0,P-1] -> [M-P,M-1]
[M,N-1] -> [M,N-1]
0 0
P
M-1 M-1
N-1 N-1
Now, sprite that was in S0 in VRAM, and in P in RAM is at plane 0 ad is displayed for sure.
Now probably some other sprite is hidden
Let S0 be the 5th sprite again.
Assume always S0<M
We want to scramble the main sprites again and leave the details where they are.
Now S0 does not correspond to P but to we have two cases
1)
If S0<M-P then the new P’ = P + S0
This is because in the previous step we moved [P,M-1] -> [0,M-1-P]
2)
if M-P<= S0 <M then the new P’ = S0 – (M - P) = P + S0 – M
this is because in the previous step we moved [0,P-1] -> [M-P,M-1]
in both cases now we do
P=P’
And we copy again
[P,M-1] -> [0,M-1-P]
[0,P-1] -> [M-P,M-1]
[M,N-1] -> [M,N-1]
0 0
P
M-1 M-1
N-1 N-1
Now the main sprites have been scrambled the 5th sprite is again moved on top and we can continue the loop again and again.
----------------------------------------
Assume now that at a certain point we get S0>=M
Now we want to scramble the details leaving the main sprites unaltered.
0 0
M-1 M-1
P S0
N-1 N-1
Again at first step P = S0
We copy
[0,M-1] -> [0,M-1]
[P,N-1] -> [M,N-P-1]
[M,P-1] -> [N-P+M,N-1]
0 0
M M
P N-P+M
N-1 N-1
Now let S0>=M again
Again S0 and P do not correspond anymore and we have two cases,
1)
if S0<N-P+M then P’ = P + S0-M
This because we moved at previous step [P,N-1] -> [M,N-P-1]
2)
If S0>=N-P+M then P’ = S0 – (N-P+M) +M = S0 –N +P
This because we moved at previous step [M,P-1] -> [N-P+M,N-1]
Now we do
P=P’
And we copy again
[0,M-1] -> [0,M-1]
[P,N-1] -> [M,N-P-1]
[M,P-1] -> [N-P+M,N-1]
in this way details have been scrambled and if S0 stay >= M we can continue with this part of code
Do you see the idea ?
Note that each time we pass from mode “scramble main sprites” to “scramble details” be need to reset the variable P.
This is a draft code of the idea above
di();
v99 = SAT & 255;
v99 = SAT/256 | 64;
if (vdps0 & 64) {
u_char s = (vdps0 & 31)*4;
if (s<M) {
if (P>=M) {P=0;}
if (s<M-P) {P += s;}
else
{P += s-M;}
vcopy(P,M-1); // [P,M-1] -> 0
vcopy(0,P-1); // [0,P-1] -> M-P
vcopy(M,N-1); // [M,N-1] -> M
}
else {
if (P<M) {P=0;}
if (s<M+N-P) {P += s-M;}
else
{P += s-N;}
Q+=4;
if (Q>=M) {
Q=0;
vcopy(0,M-1); // [0,M-1] -> 0
}
else
{
vcopy(Q,M-1); // [Q,M-1] -> 0
vcopy(0,Q-1); // [0,Q-1] -> M-Q
}
vcopy(P,N-1); // [P,N-1] -> M
vcopy(M,P-1); // [M,P-1] -> M+N-P
}
}
else
{
P = 0;
otir(p_sprt,N);
}
v98 = 208;
ei();
}