Skip to navigation


Drawing pixels: CPIX2

[Commodore 64 version]

Name: CPIX2 [Show more] Type: Subroutine Category: Drawing pixels Summary: Draw a single-height dash on the dashboard
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * CPIX4 calls CPIX2 * DOT calls CPIX2

Draw a single-height multicolour bitmap mode dash (1 pixel high, 2 pixels wide).
Arguments: X1 The screen pixel x-coordinate of the dash Y1 The screen pixel y-coordinate of the dash COL The colour of the dash as a multicolour bitmap mode character row byte
.CPIX2 LDY Y1 ; Fetch the y-coordinate into Y LDA X1 ; Each character block contains 8 pixel rows, so to get AND #%11111000 ; the address of the first byte in the character block ; that we need to draw into, as an offset from the start ; of the row, we clear bits 0-2 CLC ; The ylookup table lets us look up the 16-bit address ADC ylookupl,Y ; of the start of a character row containing a specific STA SC ; pixel, so this fetches the address for the start of LDA ylookuph,Y ; the character row containing the y-coordinate in Y, ADC #0 ; and adds it to the row offset we just calculated in A STA SC+1 TYA ; Set Y to the y-coordinate mod 8, which will be the AND #7 ; number of the pixel row we need to draw within the TAY ; character block LDA X1 ; Set X = X1 mod 8, which is the horizontal pixel number AND #7 ; within the character block where the pixel lies (as TAX ; each pixel line in the character block is 8 pixels ; wide) LDA CTWOS2,X ; Fetch a multicolour bitmap mode 1-pixel byte with the AND COL ; pixel position at X, and AND with the colour byte so ; that pixel takes on the colour we want to draw (i.e. A ; is acting as a mask on the colour byte) ; ; Note that the CTWOS2 table contains two identical ; bitmap bytes for consecutive values of X, as each ; pixel is double-width and straddles two x-coordinates EOR (SC),Y ; Draw the pixel on-screen using EOR logic, so we can STA (SC),Y ; remove it later without ruining the background that's ; already on-screen ;JSR P%+3 ; These instructions are commented out in the original ;INX ; source LDA CTWOS2+2,X ; Fetch a multicolour bitmap mode 1-pixel byte with the ; pixel position at X+1, so we can draw the right pixel ; of the dash (we add 2 to CTWOS2 as there are two ; repeated entries for X and X+1 in the table) BPL CP1 ; The CTWOS table has an extra two rows at the end of it ; that repeat the first two value, %11000000, so if we ; have not fetched that value, then the right pixel of ; the dash is in the same character block as the left ; pixel, so jump to CP1 to draw it LDA SC ; Otherwise the left pixel we drew was at the last CLC ; position of four in this character block, so we add ADC #8 ; 8 to the screen address to move onto the next block STA SC ; along (as there are 8 bytes in a character block) BCC P%+4 ; If the addition we just did overflowed, then increment INC SC+1 ; the high byte of SC(1 0), as this means we just moved ; into the right half of the screen row LDA CTWOS2+2,X ; Re-fetch the multicolour bitmap mode 1-pixel byte, as ; we just overwrote A (the byte will still be the last ; byte from the table, which is correct as we want to ; draw the leftmost pixel in the next character along as ; the dash's right pixel) .CP1 AND COL ; Apply the colour mask to the pixel byte, as above EOR (SC),Y ; Draw the dash's right pixel according to the mask in STA (SC),Y ; A, with the colour in COL, using EOR logic, just as ; above RTS ; Return from the subroutine