Skip to navigation

Graphics: SetColourPalette

Name: SetColourPalette [Show more] Type: Subroutine Category: Graphics Summary: Set the logical colours for each of the four physical colours in screen mode 5
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainGameLoop calls SetColourPalette * MainTitleLoop calls SetColourPalette * PlayGame calls SetColourPalette * SecretCodeError calls SetColourPalette

Arguments: A Defines how the four physical colours in the mode 5 palette are set: * If bit 7 is clear then bits 0-6 contain the physical colour to set for all four logical colours (so the screen is effectively blanked to this colour) * If bit 7 is set then bits 0-6 contain the offset within the colourPalettes table of the last of the four physical colours to set for logical colours 3, 2, 1 and 0 (so we work backwards through the table from the offset in bits 0-6)
.SetColourPalette STA T \ Store the argument in T AND #%01111111 \ Extract bits 0-6 of the argument into Y TAY LDA #3 \ We now work through the logical colours from 3 down STA U \ to 0, setting the physical colour for each one in \ turn, so set a logical colour counter in U .pall1 LDX T \ Set X to the argument in T BPL pall2 \ If bit 7 of the argument in T is clear, skip the \ following instruction, so X contains the physical \ colour in the routine's argument (i.e. the colour to \ which we set all four logical colours) \ If we get here then bit 7 of the argument in T is set, \ which means bits 0-6 contain the offset within the \ colourPalettes table of the four physical colours in \ the palette \ \ We set Y above to the value of bits 0-6, so we can use \ this as the index into the colourPalettes table (we \ will decrement Y below for each of the four colours, \ so we end up setting all four logical colours to the \ four values in the table) LDX colourPalettes,Y \ Fetch the physical colour from the Y-th entry in \ colourPalettes, which we now want to allocate to \ logical colour U .pall2 LDA #19 \ Start a VDU 19 command, which sets a logical colour to JSR OSWRCH \ a physical colour using the following format: \ \ VDU 19, logical, physical, 0, 0, 0 \ \ which we output as follows: \ \ VDU 19, U, X, 0, 0, 0 LDA U \ Write the value in U, which is the logical colour we JSR OSWRCH \ want to define TXA \ Set A to the value in X LDX #4 \ Set X = 4 to use as a byte counter as we output the \ physical colour and three zeroes .pall3 JSR OSWRCH \ Write the value in A, which is the physical colour we \ want to set (in the first iteration of the loop), or \ one of three trailing zeroes (in later iterations) LDA #0 \ Set A = 0 so the remaining three iterations of the \ loop output the trailing zeroes DEX \ Decrement the byte counter BNE pall3 \ Loop back until we have output the whole VDU command DEY \ Decrement the colourPalettes index in Y DEC U \ Decrement the logical colour counter in U BPL pall1 \ Loop back until we have defined the logical colours \ for all four physical colours RTS \ Return from the subroutine