Skip to navigation

Aviator on the BBC Micro

Drawing lines: ModifyDrawRoutine

Name: ModifyDrawRoutine [Show more] Type: Subroutine Category: Drawing lines Summary: Modify the drawing routines to draw in the correct colour for the current colour cycle
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawCanopyView calls ModifyDrawRoutine * EraseCanopyLines calls ModifyDrawRoutine * ResetLineLists calls ModifyDrawRoutine

This routine modifies the DrawCanopyLine routine, depending on the value of the colourLogic and colourCycle variables. See the DrawCanopyView routine for details of the colour-cycling system that this forms part of. This is what the ModifyDrawRoutine routine does: If colourLogic = %00000000 (erase lines): * Modify the drawing logic in DrawCanopyLine to AND * Modify DrawCanopyLine so it fetches bit patterns from: * colour1Row if colourCycle = %00001111 * colour2Row if colourCycle = %11110000 In other words, the bit pattern it fetches is always the same as the value of colourCycle, as colour1Row contains %00001111 and colour2Row contains %11110000 * Modify DrawCanopyLine (part 3) so it pokes the value of colourCycle as a bit pattern in the screen-updating routine at dlin50 If colourLogic = %01000000 (draw lines in colour 2): * Modify the drawing logic in DrawCanopyLine to OR (the default) * Modify DrawCanopyLine so it fetches bit patterns from colour2L2R and colour2R2L (colour 2) instead of colour1L2R and colour1R2L (colour 1) If colourLogic = %10000000 (draw lines in colour 1): * Modify the drawing logic in DrawCanopyLine to OR (the default) * Restore the DrawCanopyLine routine back to its default code, so we draw in colour 1
.ModifyDrawRoutine LDA colourLogic \ If colourLogic is non-zero, jump to modd3 BNE modd3 \ If we get here then colourLogic is %00000000 LDA #&31 \ Set A to the opcode for the AND (P),Y instruction STA dlin24 \ Modify the following instruction in DrawCanopyLine \ (part 4): \ \ ORA (P),Y -> AND (P),Y STA dlin29 \ Modify the following instruction in DrawCanopyLine \ (part 5): \ \ ORA (P),Y -> AND (P),Y STA dlin34 \ Modify the following instruction in DrawCanopyLine \ (part 6): \ \ ORA (P),Y -> AND (P),Y STA dlin51 \ Modify the following instruction in DrawCanopyLine \ (part 8): \ \ ORA (P),Y -> AND (P),Y LDA colourCycle \ If bit 7 of colourCycle is set, i.e. %11110000, jump BMI modd1 \ jump down to modd1 LDA #LO(colour1Row) \ Bit 7 of colourCycle is clear, i.e. %00001111, so set \ A to LO(colour1Row) so the instructions below are \ modified to the following: \ \ LDA #LO(colour1L2R) -> LDA #LO(colour1Row) \ LDA colour1L2R,X -> LDA colour1Row,X \ LDA #LO(colour1R2L) -> LDA #LO(colour1Row) \ LDA colour1R2L,X -> LDA colour1Row,X BNE modd2 \ Jump down to modd2 (this BNE is effectively a JMP as \ A is never zero) .modd1 LDA #LO(colour2Row) \ Bit 7 of colourCycle is set, i.e. %11110000, so set \ A to LO(colour2Row) so the instructions below are \ modified to the following: \ \ LDA #LO(colour1L2R) -> LDA #LO(colour2Row) \ LDA colour1L2R,X -> LDA colour2Row,X \ LDA #LO(colour1R2L) -> LDA #LO(colour2Row) \ LDA colour1R2L,X -> LDA colour2Row,X .modd2 \ Modify the following instruction in DrawCanopyLine \ (part 2) where LO(colourA) is the value of A: \ STA dlin2+1 \ LDA #LO(colour1L2R) -> LDA #LO(colourA) \ Modify the following instruction in DrawCanopyLine \ (part 4) where colourA is the value of A: \ STA dlin23+1 \ LDA colour1L2R,X -> LDA colourA,X \ Modify the following instruction in DrawCanopyLine \ (part 2) where LO(colourA) is the value of A: \ STA dlin4+1 \ LDA #LO(colour1R2L) -> LDA #LO(colourA) \ Modify the following instruction in DrawCanopyLine \ (part 5) where colourA is the value of A: \ STA dlin28+1 \ LDA colour1R2L,X -> LDA colourA,X LDA colourCycle \ Modify the following instruction in DrawCanopyLine STA dlin50+1 \ (part 2): LDA #&A9 \ STA dlin50 \ LDA H -> LDA #colourCycle \ \ as the opcode for the LDA #n instruction is &A9 RTS \ Return from the subroutine .modd3 \ If we get here then colourLogic is non-zero LDA #&11 \ Set A to the opcode for the ORA (P),Y instruction STA dlin24 \ Modify the following instruction in DrawCanopyLine \ (part 4): \ \ ORA (P),Y -> ORA (P),Y \ \ i.e. set them back to the default STA dlin29 \ Modify the following instruction in DrawCanopyLine \ (part 5): \ \ ORA (P),Y -> ORA (P),Y \ \ i.e. set them back to the default STA dlin34 \ Modify the following instruction in DrawCanopyLine \ (part 6): \ \ ORA (P),Y -> ORA (P),Y \ \ i.e. set them back to the default STA dlin51 \ Modify the following instruction in DrawCanopyLine \ (part 8): \ \ ORA (P),Y -> ORA (P),Y \ \ i.e. set them back to the default LDA colourLogic \ If bit 7 of colourLogic is set, i.e. %10000000, jump BMI modd4 \ to modd4 \ If we get here then colourLogic is %01000000 \ Modify the following instructions in DrawCanopyLine \ (parts 2 and 4): LDA #LO(colour2L2R) \ STA dlin2+1 \ LDA #LO(colour1L2R) -> LDA #LO(colour2L2R) STA dlin23+1 \ LDA colour1L2R,X -> LDA colour2L2R,X \ Modify the following instructions in DrawCanopyLine \ (parts 2 and 5): LDA #LO(colour2R2L) \ STA dlin4+1 \ LDA #LO(colour1R2L) -> LDA #LO(colour2R2L) STA dlin28+1 \ LDA colour1R2L,X -> LDA colour2R2L,X \ Modify the following instructions in DrawCanopyLine \ (part 8): LDA #%10000000 \ STA dlin47+1 \ LDA #%00001000 -> LDA #%10000000 LDA #%00001000 \ STA dlin58+1 \ CMP #%00000000 -> CMP #%00001000 LDA #%10000000 \ STA dlin59+1 \ LDA #%00001000 -> LDA #%10000000 LDA #00000000 \ STA dlin62+1 \ CMP #%00010000 -> CMP #%00000000 LDA #%00010000 \ STA dlin63+1 \ LDA #%00000001 -> LDA #%00010000 BNE modd5 \ Jump down to modd5 (this BNE is effectively a JMP as \ A is never zero) .modd4 \ If we get here then colourLogic is %10000000 \ Modify the following instructions in DrawCanopyLine \ (parts 2 and 4): LDA #LO(colour1L2R) \ STA dlin2+1 \ LDA #LO(colour1L2R) -> LDA #LO(colour1L2R) STA dlin23+1 \ LDA colour1L2R,X -> LDA colour1L2R,X \ \ i.e. set them back to the default \ Modify the following instructions in DrawCanopyLine \ (parts 2 and 5): LDA #LO(colour1R2L) \ STA dlin4+1 \ LDA #LO(colour1R2L) -> LDA #LO(colour1R2L) STA dlin28+1 \ LDA colour1R2L,X -> LDA colour1R2L,X \ \ i.e. set them back to the default \ Modify the following instructions in DrawCanopyLine \ (part 8): LDA #%00001000 \ STA dlin47+1 \ LDA #%00001000 -> LDA #%00001000 LDA #%00000000 \ STA dlin58+1 \ CMP #%00000000 -> CMP #%00000000 LDA #%00001000 \ STA dlin59+1 \ LDA #%00001000 -> LDA #%00001000 LDA #%00010000 \ STA dlin62+1 \ CMP #%00010000 -> CMP #%00010000 LDA #%00000001 \ STA dlin63+1 \ LDA #%00000001 -> LDA #%00000001 \ \ i.e. set them back to the default .modd5 \ Modify the following instructions in DrawCanopyLine \ (part 2): LDA #&A5 \ STA dlin50 \ LDA H -> LDA H LDA #&79 \ STA dlin50+1 \ as the opcode for the LDA n instruction is &A5 RTS \ Return from the subroutine