Skip to navigation

Elite on the BBC Micro and NES

Dashboard: DILX

[Elite-A, I/O processor]

Name: DILX [Show more] Type: Subroutine Category: Dashboard Summary: Implement the draw_bar command (update a bar-based indicator on the dashboard Deep dive: The dashboard indicators
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * tube_table calls DILX

This routine is run when the parasite sends a draw_bar command. It updates a bar-based indicator on the dashboard. The range of values shown on the indicator depends on which entry point is called. For the default entry point of DILX, the range is 0-255 (as the value passed in A is one byte). The other entry points are shown below.
.DILX JSR tube_get \ Get the parameters from the parasite for the command: STA bar_1 \ JSR tube_get \ draw_bar(value, colour, screen_low, screen_high) STA bar_2 \ JSR tube_get \ and store them as follows: STA SC \ JSR tube_get \ * bar_1 = the value to display in the indicator STA SC+1 \ \ * bar_2 = the mode 5 colour of the indicator \ \ * SC(1 0) = the screen address of the indicator LDX #&FF \ Set bar_3 = &FF, to use as a mask for drawing each row STX bar_3 \ of each character block of the bar, starting with a \ full character's width of 4 pixels LDY #2 \ We want to start drawing the indicator on the third \ line in this character row, so set Y to point to that \ row's offset LDX #3 \ Set up a counter in X for the width of the indicator, \ which is 4 characters (each of which is 4 pixels wide, \ to give a total width of 16 pixels) .DL1 LDA bar_1 \ Fetch the indicator value (0-15) from bar_1 into A CMP #4 \ If bar_1 < 4, then we need to draw the end cap of the BCC DL2 \ indicator, which is less than a full character's \ width, so jump down to DL2 to do this SBC #4 \ Otherwise we can draw a 4-pixel wide block, so STA bar_1 \ subtract 4 from bar_1 so it contains the amount of the \ indicator that's left to draw after this character LDA bar_3 \ Fetch the shape of the indicator row that we need to \ display from bar_3, so we can use it as a mask when \ painting the indicator. It will be &FF at this point \ (i.e. a full 4-pixel row) .DL5 AND bar_2 \ Fetch the 4-pixel mode 5 colour byte from bar_2, and \ only keep pixels that have their equivalent bits set \ in the mask byte in A STA (SC),Y \ Draw the shape of the mask on pixel row Y of the \ character block we are processing INY \ Draw the next pixel row, incrementing Y STA (SC),Y INY \ And draw the third pixel row, incrementing Y STA (SC),Y TYA \ Add 6 to Y, so Y is now 8 more than when we started CLC \ this loop iteration, so Y now points to the address ADC #6 \ of the first line of the indicator bar in the next TAY \ character block (as each character is 8 bytes of \ screen memory) DEX \ Decrement the loop counter for the next character \ block along in the indicator BMI DL6 \ If we just drew the last character block then we are \ done drawing, so jump down to DL6 to finish off BPL DL1 \ Loop back to DL1 to draw the next character block of \ the indicator (this BPL is effectively a JMP as A will \ never be negative following the previous BMI) .DL2 EOR #3 \ If we get here then we are drawing the indicator's end STA bar_1 \ cap, so bar_1 is < 4, and this EOR flips the bits, so \ instead of containing the number of indicator columns \ we need to fill in on the left side of the cap's \ character block, bar_1 now contains the number of \ blank columns there should be on the right side of the \ cap's character block LDA bar_3 \ Fetch the current mask from bar_3, which will be &FF \ at this point, so we need to turn bar_1 of the columns \ on the right side of the mask to black to get the \ correct end cap shape for the indicator .DL3 ASL A \ Shift the mask left so bit 0 is cleared, and then AND #%11101111 \ clear bit 4, which has the effect of shifting zeroes \ from the left into each nibble (i.e. xxxx xxxx becomes \ xxx0 xxx0, which blanks out the last column in the \ 4-pixel mode 5 character block) DEC bar_1 \ Decrement the counter for the number of columns to \ blank out BPL DL3 \ If we still have columns to blank out in the mask, \ loop back to DL3 until the mask is correct for the \ end cap PHA \ Store the mask byte on the stack while we use the \ accumulator for a bit LDA #0 \ Change the mask so no bits are set, so the characters STA bar_3 \ after the one we're about to draw will be all blank LDA #99 \ Set bar_1 to a high number (99, why not) so we will STA bar_1 \ keep drawing blank characters until we reach the end \ of the indicator row PLA \ Restore the mask byte from the stack so we can use it \ to draw the end cap of the indicator JMP DL5 \ Jump back up to DL5 to draw the mask byte on-screen .DL6 .DL9 RTS \ Return from the subroutine