This is what is called #demoscene sync-code. The code runs in sync with the display and changes hardware switches at precise location of the display.
The instructions in red are the buffer switches, taking place during HBL. Every two lines of code run in exactly one scanline time.
Between them, in green, the code updates the framebuffers' content for the effect to move.