Hi,
Z-order is a concept that is present since the beginning of videogames: in a 3d world, sprites that are far away of the camera are drawed behind the ones closer to the camera. This concept can also be applied to a 2d world, if we're using depth in our scene.
The code is available at https://github.com/antoniocmateus/z88dk_sp1_zorder and is fully commented.
António