Ok, short explanation about what's going on:
There's this game that looks like this:
http://www.tigsource.com/features/images/dwarffortress-big.png And i'm writing this to get something that looks like this:
http://www.videogames.net.au/images/dwarf-fortress-3d-visualizer-beautiful-fortress1.jpg
The game internally stores the data as 16x16 blocks of single tiles. My script grabs the current cursor position and then grabs the data around the cursor and converts it into a big unified multi-dimensional by extracting the tile type and storing it in said array. That array is then later used to render images in OpenGL.
$bx and $by are the coordinates of each 16x16 block on the 2d plane, while $bz is the z dimension that's equal for tiles and blocks. I get the data for each block as an array of 256 values, through which i cycle, and which i then insert into the "real" coordinates it would have, which is why i'm doing the ($bx*16)+$x stuff.
A diagram of the refresh loop is available here: http://dwarvis.googlecode.com/svn/trunk/lifevis/lifevis.dia
As for your suggestions: I can't even figure out what you're doing with the binary operations there and i'd like to strike a balance between readability and performance. PDL, i have never heard about that and from glancing at the linked page i also can't figure out how it would help me. Sorry if i'm being dumb here and thanks for trying.