It is also a little frustrating that OP seems to know little of both languages. Neither Pascal nor C.
Such things - that code - are really easy to translate, minutes, not hours, if you know both languages.
That's why I asked for the original C code. I think he made assumptions that are not correct.
Anyway, I could get a neat matrix on screen after cleaning up. But I'd rather have the original C sourcecode, because my working code is purely based on assumption, educated guesses if you want.
I have already volunteered to show him how such a translation should (could) be done.