Skip to navigation


Stardust: FLIP

[Commodore 64 version]

Name: FLIP [Show more] Type: Subroutine Category: Stardust Summary: Reflect the stardust particles in the screen diagonal and redraw the stardust field
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * LOOK1 calls FLIP

Swap the x- and y-coordinates of all the stardust particles and draw the new set of particles. Called by LOOK1 when we switch views. This is a quick way of making the stardust field in the new view feel different without having to generate a whole new field. If you look carefully at the stardust field when you switch views, you can just about see that the new field is a reflection of the previous field in the screen diagonal, i.e. in the line from bottom left to top right. This is the line where x = y when the origin is in the middle of the screen, and positive x and y are right and up, which is the coordinate system we use for stardust).
.FLIP ;LDA MJ ; These instructions are commented out in the original ;BNE FLIP-1 ; source. They would have the effect of not swapping the ; stardust if we had mis-jumped into witchspace LDY NOSTM ; Set Y to the current number of stardust particles, so ; we can use it as a counter through all the stardust .FLL1 LDX SY,Y ; Copy the Y-th particle's y-coordinate from SY+Y into X LDA SX,Y ; Copy the Y-th particle's x-coordinate from SX+Y into STA Y1 ; both Y1 and the particle's y-coordinate STA SY,Y TXA ; Copy the Y-th particle's original y-coordinate into STA X1 ; both X1 and the particle's x-coordinate, so the x- and STA SX,Y ; y-coordinates are now swapped and (X1, Y1) contains ; the particle's new coordinates LDA SZ,Y ; Fetch the Y-th particle's distance from SZ+Y into ZZ STA ZZ JSR PIXEL2 ; Draw a stardust particle at (X1,Y1) with distance ZZ DEY ; Decrement the counter to point to the next particle of ; stardust BNE FLL1 ; Loop back to FLL1 until we have moved all the stardust ; particles RTS ; Return from the subroutine