Skip to navigation

Revs on the BBC Micro

Drawing the track: UpdateBackground

Name: UpdateBackground [Show more] Type: Subroutine Category: Drawing the track Summary: Update the background colour table for when we draw a verge edge off the left edge of the screen
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * StopDrawingEdge calls UpdateBackground

Arguments: Y The track line we are drawing on (0 to 79)
.UpdateBackground LDA vergeOnScreenEdge \ If bit 7 of vergeOnScreenEdge is set then the edge we BMI upba1 \ are drawing is partially off-screen, so jump to upba1 \ to skip the following \ If we get here then the edge we are drawing is fully \ on-screen LDA backgroundRight \ Set A = backgroundRight, which is in the format \ %010vv0ab: \ \ * %vv is the verge we are currently drawing, from \ vergeType \ \ * %ab is the colour in the first verge pixel mask \ for the verge \ \ * %010xx0xx denotes that this value is being set to \ backgroundRight by the UpdateBackground routine JMP upba2 \ Jump to upba2 .upba1 \ If we get here then the edge we are drawing is \ partially off-screen DEY \ Decrement the track line in Y LDA backgroundColour,Y \ Set A to the contents of the background colour table \ for track line Y BNE upba4 \ If the background colour currently in the table is \ non-zero, jump to upba4 to return from the subroutine LDA backgroundLeft \ The background colour currently in the table is zero, \ so set A = backgroundLeft, which is in the format \ %100vv0ab: \ \ * %vv is the verge we are currently drawing, from \ vergeType \ \ * %ab is the colour of the first three pixels in the \ verge pixel mask for the verge in objectPalette+3 \ \ * %100xx0xx denotes that this value is being set to \ backgroundLeft by the UpdateBackground routine .upba2 CPY #80 \ If Y >= 80, then this is not a valid track line BCS upba4 \ number, so jump to upba4 to return from the subroutine LDX playerSideways \ If playerSideways < 40, then the player's car is CPX #40 \ facing along the track rather than sideways, so jump BCC upba3 \ to upba3 to store A in the background colour table \ If we get here then the player's car is facing \ sideways, relative to the track direction, so we set \ the background colour to either black or green, \ ignoring the colour of the verge marks STA T \ Store A in T so we can retrieve it below AND #%00000011 \ If bits 0-1 of A >= 3, i.e. bits 0-1 of A = 3, set the CMP #3 \ C flag LDA T \ Retrieve the value of A that we stored in T above BCS upba3 \ If bits 0-1 of A = 3, jump to upba3 to store green as \ the background colour AND #%11111100 \ Otherwise clear bits 0 and 1 of A, to store black as \ the background colour .upba3 STA backgroundColour,Y \ Store A as the background colour for track line Y .upba4 RTS \ Return from the subroutine