![]() |
Routines |
| Prev: BB1C | Up: Map | Next: BC37 |
|
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+00 holds the X position and IX+01 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 | BC0E | LD C,(IX+$00) | C=*IX+00. | |||||||||||||
| BC11 | LD B,(IX+$01) | B=*IX+01. | ||||||||||||||
| BC14 | LD A,C | A=C. | ||||||||||||||
| BC15 | AND %00000111 | Keep only bits 0-2. | ||||||||||||||
| BC17 | 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.
|
||||||||||||||||
| BC18 | LD A,C | A=C. | ||||||||||||||
| BC19 | RRCA | Rotate right three positions to divide X by 08. | ||||||||||||||
| BC1A | RRCA | |||||||||||||||
| BC1B | RRCA | |||||||||||||||
| BC1C | AND %00011111 | Keep only bits 0-4 (character column, 00-1F). | ||||||||||||||
| BC1E | LD L,A | L=A. | ||||||||||||||
| BC1F | LD A,B | A=B. | ||||||||||||||
| BC20 | RLCA | Rotate left two positions. | ||||||||||||||
| BC21 | RLCA | |||||||||||||||
| BC22 | AND %11100000 | Keep only bits 5-7 (low bits of Y row). | ||||||||||||||
| BC24 | OR L | Merge the column and row bits together. | ||||||||||||||
| BC25 | 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 E000 (bits 5-7 set).
|
||||||||||||||||
| BC26 | LD A,B | A=B. | ||||||||||||||
| BC27 | AND %00000111 | Keep only bits 0-2 (pixel row within character cell). | ||||||||||||||
| BC29 | LD H,A | H=A. | ||||||||||||||
| BC2A | LD A,B | A=B. | ||||||||||||||
| BC2B | AND %11000000 | Keep only bits 6-7 (screen third selector). | ||||||||||||||
| BC2D | RRCA | Rotate right three positions to move bits 6-7 into bits 3-4. | ||||||||||||||
| BC2E | RRCA | |||||||||||||||
| BC2F | RRCA | |||||||||||||||
| BC30 | OR H | Merge with the pixel row bits in H. | ||||||||||||||
| BC31 | OR %11100000 | Set bits 5-7 for the screen buffer base address (E000). | ||||||||||||||
| BC33 | 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.
|
||||||||||||||||
| BC34 | EX AF,AF' | Store the row-within-character in shadow AF. | ||||||||||||||
| BC35 | POP AF | Restore the pixel X offset from the stack. | ||||||||||||||
| BC36 | RET | Return. | ||||||||||||||
| Prev: BB1C | Up: Map | Next: BC37 |