Prev: DD73 Up: Map Next: DE69
DE51: Calculate Screen Address
Used by the routines at Print_HelperPreviewImage, Draw_Tile and E1A1.
Input
HL X/Y Co-ordinates
Output
DE Screen buffer address
CalculateScreenAddress DE51 LD A,L Load the X co-ordinate into A.
DE52 AND %11000000 Keep only bits 6-7.
DE54 RRA Rotate the result right through the carry flag.
DE55 SCF Set the carry flag.
DE56 RRA Rotate right through the carry flag.
DE57 RRCA Rotate right (no carry flag).
DE58 XOR L Combine the bits with the original X co-ordinate.
DE59 AND %11111000 Keep only bits 3-7.
DE5B XOR L Combine the bits with the original X co-ordinate again.
DE5C LD D,A Store the result in D (high byte of the screen buffer address).
DE5D LD A,H Load the Y co-ordinate into A.
DE5E RLCA Multiply by 08.
DE5F RLCA
DE60 RLCA
DE61 XOR L Combine the bits with the original X co-ordinate.
DE62 AND %11000111 Keep only bits 0-2, 6-7.
DE64 XOR L Combine the bits with the original X co-ordinate again.
DE65 RLCA Multiply by 04.
DE66 RLCA
DE67 LD E,A Store result in E (low byte of the screen buffer address).
DE68 RET Return.
Prev: DD73 Up: Map Next: DE69