Note, that the above "fix" can still disagree with drawStuff by 1 pixel due to the roundoff (though in rather small percentage of cases). So
for (int i = startY; i < startY + h; i++) // hori
gfx.lineRelative(0, i * TILE*scale + pan.y, gfx.screenX, 0, col);
is probably preferred, as it should agree with drawStuff completely (assuming compiler optimizations didn't break it).