| Prev: 8A33 | Up: Map | Next: 8A86 |
8A4E: Calculate screen address from pixel coordinates.
|
Converts X,Y pixel coordinates to a ZX Spectrum screen memory address.
|
||||||||||||||||
| calculate_pixel_address | 8A4E | LD DE,$0800 | ||||||||||||||
| 8A51 | LD HL,$3800 | |||||||||||||||
| 8A54 | LD A,B | Load the number of the third of the screen corresponding to the vertical coordinate of the object into A. | ||||||||||||||
| 8A55 | RLCA | |||||||||||||||
| 8A56 | RLCA | |||||||||||||||
| 8A57 | AND $03 | |||||||||||||||
| 8A59 | INC A | |||||||||||||||
| calc_pixel_screen_third_loop | 8A5A | ADD HL,DE | Load the starting address of the third of the screen into HL. | |||||||||||||
| 8A5B | DEC A | |||||||||||||||
| 8A5C | JP NZ,calc_pixel_screen_third_loop | |||||||||||||||
| 8A5F | LD A,B | Leave only the 6 lowest bits in B which define the coordinate of the object relative to its third of the screen. | ||||||||||||||
| 8A60 | AND $3F | |||||||||||||||
| 8A62 | LD B,A | |||||||||||||||
| 8A63 | AND $38 | Unset the 3 lowest bits, so now A contains the coordinate of starting tile relative to its third of the screen. | ||||||||||||||
| 8A65 | PUSH HL | |||||||||||||||
| 8A66 | LD H,$00 | Multiply the value of A by 4 and put into DE which makes the offset of the starting tile address from its third of the screen. | ||||||||||||||
| 8A68 | LD L,A | |||||||||||||||
| 8A69 | ADD HL,HL | |||||||||||||||
| 8A6A | ADD HL,HL | |||||||||||||||
| 8A6B | EX DE,HL | |||||||||||||||
| 8A6C | POP HL | Now HL contains the screen address of the tile. | ||||||||||||||
| 8A6D | ADD HL,DE | |||||||||||||||
| 8A6E | LD A,B | Leave only the 3 lowest bits in B which define the coordinate of the object relative to it tile. | ||||||||||||||
| 8A6F | AND $07 | |||||||||||||||
| 8A71 | LD B,A | |||||||||||||||
| 8A72 | INC B | Prepare for row loop. | ||||||||||||||
| 8A73 | DEC H | |||||||||||||||
| calc_pixel_row_loop | 8A74 | INC H | Increment H (row within tile) B times. | |||||||||||||
| 8A75 | DJNZ calc_pixel_row_loop | |||||||||||||||
| 8A77 | LD A,C | |||||||||||||||
| 8A78 | SRL A | Add column offset and extract bit position. | ||||||||||||||
| 8A7A | SRL A | |||||||||||||||
| 8A7C | SRL A | |||||||||||||||
| 8A7E | LD D,C | |||||||||||||||
| 8A7F | LD C,A | |||||||||||||||
| 8A80 | ADD HL,BC | |||||||||||||||
| 8A81 | LD A,D | |||||||||||||||
| 8A82 | AND $07 | |||||||||||||||
| 8A84 | LD B,A | |||||||||||||||
| 8A85 | RET | |||||||||||||||
| Prev: 8A33 | Up: Map | Next: 8A86 |