Making custom google map tiles from a master png:

convert -crop 160x160 full.png tile_%d.png

It numbers the tiles sequentially, so a tile at position 1,1 in a 2x2 grid will be tile_3.png (it starts numbering at zero).

Calculating the tile number is terribly easy:

(coord.y * 2^zoom) + coord.x

Where 2^zoom represents the maximum number of tiles across. (At zoom 1, there are a max of 2 tiles across.)