If it doesn't work when you are at location 0,0 thats because there is no 0 in a matrix. your map is also offset in the topleft direction by one tile, right? i would just change your formula to:
c1-->
CODE |
ec1if [a](Y/8+1,X/8+1) = ... whatever you had here..c2 |
ec2
that should fix it, and your map might get a lill bigger =P it you get errors on the outer edges now, thats because your matrixes arn't the same size.