Skip to navigation

Scanner/energy row: DrawIcon

Name: DrawIcon [Show more] Type: Subroutine Category: Scanner/energy row Summary: Draw a single icon in the top-left corner of the screen (via the icon screen buffer at iconBuffer) and move along to the right
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ClearIconsScanner calls DrawIcon * UpdateIconsScanner calls DrawIcon

Arguments: A The type of icon to draw: * 0 = Blank * 1 = Robot * 2 = Tree (left) * 3 = Tree (right) * 4 = Boulder (left) * 5 = Boulder (right) * 6 = High-energy robot * 7 = Scanner box (left) * 8 = Scanner box (middle) * 9 = Scanner box (right)
Returns: A A is preserved
.DrawIcon PHA \ Store the icon type on the stack so we can preserve it ASL A \ Set X = (A * 8) + 7 ASL A \ ASL A \ Each icon definition in iconData contains eight bytes, ORA #7 \ so we can use this as an index into iconData, where it TAX \ points to the last of the eight bytes for icon A (as \ we added 7 to A * 8 with the ORA instruction) \ We now calculate the address of the icon in the screen \ buffer at iconBuffer \ \ The icon needs to be drawn in column xIconCounter, \ where each column is eight pixels wide, and because \ the screen is split into 8x8-pixel character blocks of \ eight bytes in each, the icon is in screen memory at \ this address, which we store in (Q P): \ \ (Q P) = iconBuffer + xIconCounter * 8 \ \ This is calculated by doing half the sum first, and \ then doubling the result, like this: \ \ (iconBuffer / 2) + (xIconCounter * 4) \ \ The calculation is done this way to cater for values \ of xIconCounter between 32 and 39, as multiplying 32 \ by 8 won't fit into one byte, but multiplying by 4 \ will fit (and doubling just requires a simple shift) LDA xIconCounter \ Set P = xIconCounter * 4 + LO(iconBuffer / 2) ASL A \ ASL A \ so those are the low bytes ADC #LO(iconBuffer)/2 STA P LDA #HI(iconBuffer)/2 \ Set A = 0 + HI(iconBuffer / 2) ADC #0 \ \ and those are the high bytes, with the result of the \ half sum in (A P) ASL P \ Set (Q P) = (A P) * 2 ROL A \ = iconBuffer + xIconCounter * 8 STA Q \ \ So we now have the address within the icon screen \ buffer for the icon we want to draw LDY #7 \ We now copy eight bytes of icon data into the icon \ screen buffer at iconBuffer .deni1 LDA iconData,X \ Copy the X-th byte of icon data to the Y-th byte of STA (P),Y \ (Q P) DEX \ Decrement the source byte counter DEY \ Decrement the destination byte counter BPL deni1 \ Loop back until we have copied all eight bytes INC xIconCounter \ Increment the icon counter to move along to the right \ by one column, as we just drew an icon PLA \ Restore the icon type into A that we stored on the \ stack above RTS \ Return from the subroutine