I understand now. What output does the program have if it was able to simply tell you?
I can see it happening in about 15 lines. About 5 lines of inline assembler would go a long way here,
because the file select register does not care what you or PBP is doing with RAM,
and can simply cycle the entire RAM map (switching banks inbetween) and list all of the values..

From there, if you populated all of YOUR RAM with an arbitrary value, the unused segments could
easily be identified (or the largest free space found).
An then finally, reset YOUR RAM back to zero as if the program had just started.

Off to tea right now, but if that’s what you mean, will be back later tonight.