And if map's viewport is moved away from 0,0 (top-left corner) and occupy only part of screen (after all tile palette should go somewhere), equation would be:
GridXPosition := OffsetX + ((Mouse.X + ViewpoirtX) div GridCellWidth);

am I correct?