u/-romainl-The Patient Vimmerin r/vim • Recommends
Live coding a vi for CP/M, from scratch
Advanced. Deep dive for people who know the field.
17K views7 years ago1 recommendation
Systems programmingHistory and cultureVim, Emacs and editorsRetro computingOperating systems
Hjalfi live-codes a lightweight vi clone for the CP/M operating system in a single marathon session.
In which yr hmbl svt decides that there aren't enough shabby vi clones around, and writes one from scratch in a single sitting (not counting a dinner break). This is part of my cpmish project, which is an open source CP/M distribution --- the seminal 1977 8080/Z80 operating system which inspired MS-DOS. cowlark.com/cpmish This was a marathon. My original plan turned out to simply be not fast enough: I'm using the Amsterdam Compiler Kit (tack.sourceforge.net/) compiler, because it's the only one which will generate 8080 machine code, but the code quality isn't good and is very slow. So partway in I had to redo the entire display layer when I realised that I couldn't do screen updates fast enough. (It would totally have worked had I written it in raw machine code...) I also took several other wrong turns later, all of which wasted time. But I did eventually produce an adequate, working text editor, supporting most of the basic vi editing commands I use. - Boilerplate - First, broken version of the refresh code - Start work on the editor - Initial text rendering works; start work on command loop - Realise that I need direct BIOS access and I add support to the ACK - Continue on the command loop and cursor movement - Realisation that the screen refresh code won't work - Start ripping out the refresh code - First redraw with the new refresh code - Horizontal cursor movement works - Vertical movement works, slowly - Dinner break, decision to drastically simplify editor model - Cursor movement with the new model works - Cursor movement with the new model works _quickly_ - Insert mode works - Motion by words works - Repetition count works - Inserting newlines works - Scrolling works, up to a point - Lots of commands work, start thinking about batching redraws - Notice a hanging problem with scrolling over big lines - Tea break, remove all the batching redraw stuff - Finally figure out the horrible scrolling bug - Saving documents works - Simple colon commands work Right now it's a shade under 10kB, allowing files of up to 49kB on a Kaypro II; that's not bad. If I were to recompile it with sdcc it'd be both faster and about half the size but sdcc's CP/M support is very poor and I keep running into code generation bugs, so I'm sticking with the ACK for now. (Maybe when z88dk reaches Debian...) The main missing features are search and a yank buffer. Neither would be hard to add, although I don't think this will ever get regular expressions, and the yank buffer is most easily implemented by keeping the buffer on disk; that'd be slow, though. Since doing the video above I've done some polishing, bugfixing, and a few more features. Terminal support is now factored out inWhat people say. Highly recommended by retrocomputing and Vim enthusiasts as an impressive marathon live-coding session.
u/-romainl-The Patient Vimmerin r/vim • Recommends
u/pyratedin r/C_Programming • Mentions
On “Project ideas?”