![]() |
Routines |
| Prev: 47900 | Up: Map | Next: 48183 |
|
Used by the routine at Draw_Sprites.
Converts a screen coordinate stored at IX into a screen buffer address and pixel offset. The coordinate is stored as a two-byte value where IX+0 holds the X position and IX+1 holds the Y position. Returns with HL pointing to the screen buffer address, A (shadow) holding the row within the character cell (bits 0-2 of Y), and A holding the pixel offset within the byte (bits 0-2 of X).
|
||||||||||||||||
| CalculateScreenBufferAddress | 48142 | LD C,(IX+0) | C=*IX+0. | |||||||||||||
| 48145 | LD B,(IX+1) | B=*IX+1. | ||||||||||||||
| 48148 | LD A,C | A=C. | ||||||||||||||
| 48149 | AND %00000111 | Keep only bits 0-2. | ||||||||||||||
| 48151 | PUSH AF | Stash the pixel X offset on the stack. | ||||||||||||||
|
Calculate the low byte of the screen buffer address. This combines the character column (X / 8) with the Y pixel row bits.
|
||||||||||||||||
| 48152 | LD A,C | A=C. | ||||||||||||||
| 48153 | RRCA | Rotate right three positions to divide X by 8. | ||||||||||||||
| 48154 | RRCA | |||||||||||||||
| 48155 | RRCA | |||||||||||||||
| 48156 | AND %00011111 | Keep only bits 0-4 (character column, 0-31). | ||||||||||||||
| 48158 | LD L,A | L=A. | ||||||||||||||
| 48159 | LD A,B | A=B. | ||||||||||||||
| 48160 | RLCA | Rotate left two positions. | ||||||||||||||
| 48161 | RLCA | |||||||||||||||
| 48162 | AND %11100000 | Keep only bits 5-7 (low bits of Y row). | ||||||||||||||
| 48164 | OR L | Merge the column and row bits together. | ||||||||||||||
| 48165 | LD L,A | L=A. | ||||||||||||||
|
Calculate the high byte of the screen buffer address. This encodes the character row and third-of-screen into the high byte, with the base address of 57344 (bits 5-7 set).
|
||||||||||||||||
| 48166 | LD A,B | A=B. | ||||||||||||||
| 48167 | AND %00000111 | Keep only bits 0-2 (pixel row within character cell). | ||||||||||||||
| 48169 | LD H,A | H=A. | ||||||||||||||
| 48170 | LD A,B | A=B. | ||||||||||||||
| 48171 | AND %11000000 | Keep only bits 6-7 (screen third selector). | ||||||||||||||
| 48173 | RRCA | Rotate right three positions to move bits 6-7 into bits 3-4. | ||||||||||||||
| 48174 | RRCA | |||||||||||||||
| 48175 | RRCA | |||||||||||||||
| 48176 | OR H | Merge with the pixel row bits in H. | ||||||||||||||
| 48177 | OR %11100000 | Set bits 5-7 for the screen buffer base address (57344). | ||||||||||||||
| 48179 | LD H,A | H=A. | ||||||||||||||
|
Store the Y pixel row (character cell row) in shadow AF and restore the pixel X offset as the return value in A.
|
||||||||||||||||
| 48180 | EX AF,AF' | Store the row-within-character in shadow AF. | ||||||||||||||
| 48181 | POP AF | Restore the pixel X offset from the stack. | ||||||||||||||
| 48182 | RET | Return. | ||||||||||||||
| Prev: 47900 | Up: Map | Next: 48183 |