ok so the overall flow of this should be 1: here is some pseudo code for how the y accumulator is updated 2: from this we can derive a high-level forumla (the integral one)
Each tilemap has a "Y Source" accumulator, which is in units of texture pixels (with a precision of 1/128).
At the beginning of each scanline, if Scroll Sync is set (usually on scanline 0), each tilemap's Y Source is set from its Y Global Scroll register.
At the end of the scanline, each tilemap's Y Source is incremented by its Y Zoom register.
the source of a scanline, in texture pixels is given by:
ytpx(scanline) + y_scroll_adjust[scanline]
where ytpx(scanline) = {
y_global_scroll / 128, if scroll_sync[scanline] is set
ytpx(scanline-1) + y_zoom[scanline] / 128, otherwise
the source of a scanline y, in texture pixels, is given by:
where
note: acc−1 refers to acc255 of the previous frame, etc. the initial value is undefined.
Thus, to convert a screen y position (in screen pixels) y to a source y position within a tilemap (in texture pixels), we can use:
[Show] why is this an integral instead of a summation?
Yes, it could be a Riemann sum with Δn = 1 screen pixel:
global is the tilemap's Global Scroll Y
adjust(n) is its Scroll Adjust Y at a given screen y position
zoom(n) is its Zoom Y at a given screen y position
ysync is the most recent scanline on which Scroll Sync was set (usually scanline 0).
Note that this assumes y ≥ ysync.
test ok just make a "complement if [condition]" syntax tilemap texture origin onscreen (spx relative to origin) = ((ipart - fpart/64) tpx + 18 tpx ) * inv scale (spx/tpx) + 22 spx input: spx offset output: tpx offset (x index - 22 spx) * scale (tpx/spx) - 18 tpx = (ipart - fpart/64) tpx ugh what does that even mean uh we need to calculate a correction factor uhhhhh. well ok first lets say. what is the number of texture pixels per screen pixel that would be, the scale. (after the unit conversion to tpx/spx) so. for each +1 spx, we must add, +1 spx * scale screen pixel position of texture column X (spx relative to origin) = ((ipart - fpart/64) tpx + 18 tpx ) / scale (tpx/spx) + 22 spx + (X / scale) (spx) (screen pixel position of texture column X (spx relative to origin) - (((ipart - fpart/64) tpx + 18 tpx ) / scale (tpx/spx) + 22 spx))*scale = X ( screen pixel position of texture column X * scale - (((ipart - fpart/64) tpx + 18 tpx ) / scale (tpx/spx) + 22 spx) * scale ) = X ( screen pixel position of texture column X * scale - ((ipart - fpart/64) tpx + 18 tpx ) (tpx/spx) - 22 spx * scale ) = X ( (screen pixel position of texture column X - 22 spx) * scale - ((ipart - fpart/64) tpx + 18 tpx) ) = X thusly: texture x = (screen x - 22 screen pixels) * scale - scroll + 18 texture pixels