I checked out how to do some simple tile handling for OSM. The map can be displayed using OpenLayers. This JavaScript stuff uses AJAX to get and display tiles that can be dragged around, zoomed in or zoomed out. The basis of the map are the tiles. They are 256px square. Each zoom level is twice the linear detail of the previous one, so a tile at zoom level 12 expands to 4 tiles (2×2) on zoom 13. All of this fits over a world mapped with longitude and latitude.

So one useful idea is that for any given tile, what is the long & lat of the edges of the tile. I was working on this when I tripped over the code on the OSM wiki, in any (code) language you want, so I copied it into a simple class and it worked well.