Welcome!
Topics around here can often run for years, especially with long-lived hardware projects. We encourage members to continue adding relevant content to existing topics instead of spawning new ones and fragmenting things.
- Each block starts with a link to the previous and the next block. The lenght of the text in a block is also stored in the block.
- If the link to the previous block is NULL you are at the first block. The link to next block is NULL you are in the last block.
- A block allocation table keeps track of which blocks are in use and which are free.
- When inserting a char, the subsequent text within the block is shifted forward. This is pretty fast, as a block is 256 bytes. If the block is full, the char is pushed into the next block. If that is also full, a new empty block is linked in after the current block. This is also fast as no copying is necessary.
- When deleting a char, the trailing chars in the block are shifted to the left and the block length is decremented. If the block becomes empty it is marked as free.
- A defragmentation routine runs when the editor is idle.
What you are describing appears to be organizing the text buffer into a linked list, and is similar in principle to what others have suggested. The use of 256 byte blocks seems natural with the 6502 due to that being the largest data quantity that may be addressed without having to do pointer arithmetic.
There is never a free lunch when it comes to this stuff, especially with the 6502. Lacking the means to easily index over the full address space, pointer manipulation becomes necessary as soon as your editing buffer’s size exceeds that of one page. Fortunately, judicious use of page zero as a set of extended registers can make for reasonable performance. It also helps that the current generation of the 65C02 may be run at double digit clock speeds.
Incidentally, text buffer manipulation mechanics become less difficult with the 65C816, since it can index over hundreds of KBs or MBs with ease using the indirect-long addressing modes. Also, the MVN and MVP instructions could be used to rapidly shift the buffer during an insertion or deletion. If the principle of a localized buffer is used to collect keystrokes and then said buffer is inserted into the main buffer via use of MVN and MVP, I suspect system response would be very good, even with hundreds of KBs in the main buffer.