Prev: D120 Up: Map Next: D157
D135: Display address of a pixel position
Used by the routines at RUN_CLOCK, SHOW_CARRIED, BLIT_2X8 and RENDER_DYNAMIC_OBJECTS.
Turns the game's upward y into the display's line counted from the top by complementing it: 255 - y is that line plus 64, one third of the screen too many in the top bits, which is taken back by adding 56 rather than 64 to the high byte. A' is changed. As Knight Lore's calc_vram_addr.
Input
C the pixel x
B the pixel y, counted up from the bottom of the screen
Output
DE the display address of that byte
CALC_VRAM_ADDR D135 LD A,C E = x / 8, the column
D136 RRCA
D137 RRCA
D138 RRCA
D139 AND $1F
D13B LD E,A
D13C LD A,B The line within the character row, from bits 0-2 of 255 - y, kept in A'
D13D CPL
D13E AND $07
D140 EX AF,AF'
D141 LD A,B Bits 3-5, the character row within the third, into the top of E
D142 CPL
D143 RLCA
D144 RLCA
D145 AND $E0
D147 OR E
D148 LD E,A
D149 LD A,B Bits 6-7, the third, with the line within the row, and 56 for the extra third
D14A CPL
D14B RRCA
D14C RRCA
D14D RRCA
D14E AND $18
D150 LD D,A
D151 EX AF,AF'
D152 OR D
D153 ADD A,$38
D155 LD D,A
D156 RET
Prev: D120 Up: Map Next: D157