Yes, I know. But it is a bit sluggish on the ST too. The guy who wrote it said he'd just hacked a useable tool and wasn't really interested in refining it further, so it tends to use a sort of brute force approach rather than optimised elegance. Despite this, it does work very well, and if you use vim on Linux, you are using its direct descendant I believe.
But back to file I/O. CP/M loads files one sector at a time (in blocks of 128 bytes) according to what I read. So optimising the read so it a) does it in chunks on one block at a time, and b) reads the file straight into the edit buffer yields a significant performance gain.
It is also trying to
insert into the edit buffer, so each character it reads entails additional operations to open a character wide space in the buffer prior to insert. Even at the end of the buffer it is making this check. This is so the vi :r (read into buffer) command will work properly.
The solution is to use fseek() and ftell() to get the file length, then open the buffer up with memmove() if it already contains text and the insert point is not at the end. However, an intermediate buffer may be required here because Montezuma CP/M reports the characters used to pad the last sector as part of the file length. You can see this if you use DUMP.COM to list a text file - the last sector is padded with SUBs. Or I could use the unused space at the end of the edit buffer to load the file, then truncate the SUBs, then copy into the opened buffer.
Another interesting point about the original code is that it doesn't use memcpy() or memmove(). I presume this is because these were not available in the compiler the author used. Certainly, it isn't on my ST C compiler, although Aztec C on CP/M does have memmov() but not memcpy().
I could yak on about this stuff all day but I would rather cut some code!
@tingo: can you tell me what terminal escape codes you need, or the terminal type your CP/M box is using / emulating, please? I need clear screen, home cursor and set cursor position (row, col) sequences as a minimum. I can then compile a version for you to try.