My code is here to accommodate the boss, which is the PET built-into-ROM full screen editor. It's a total black box. Whatever silly rules it makes up, my code will just have to work with. The alternative would be to copy the screen editor into RAM and rewrite most of it, and have several different variants of it for the different editor ROM versions. Since I want it to feel exactly like a PET, leverage as much PET stuff as possible, and I'm really cheap with RAM, that is not the plan. I believe the technical term for this design pattern is
bag on the side I'm using as few non-kernel ROM addresses as possible, so PETTIL can be more easily ported to other PETs and probably the C=64.
EDIT will repeatedly send the user off into the black forest of editor ROM la-la land to collect one line of input forever. The user pressing the STOP key (outside of quotes, not in insert mode) will airlift us out from this trip to the woods, and we have an opportunity to inspect and modify the model before sending them back in. These are the interesting parts of the model that the screen editor presents
Code:
$8000-$83e7 (32768-33767) screen codes, visible portion
$83e8-$83ff (33768-33791) 24 bytes are invisible. CLR turns this into spaces but it could temporarily store a copy of $E1-$F8
$c4-$c5 pointer to physical screen address of the beginning of the current logical line
$d5 length of current logical line (always 39 or 79)
$d8 physical line of cursor (0..24)
$e0-$f8 25-byte linewrap table of these things:
7 6 5 4 3 2 1 0
+-+---------+-+-+
|a| 00000 | bb| a=1 first line a=0 second line (of logical line)
+-+---------+-+-+ bb=low order bits of screen page
Assumptions
$e0 *always* contains $80, so I can safely ignore that. The ROM will scroll only complete logical lines off the top of the screen.
the "a" bits should follow their text around when the line is moved.
the "bb" bits should remain right where they are
Moving the cursor to do anything in my add-on code is a Bad Idea(tm), and so is emitting screen control characters
I thought about doing select ranges with character pointers, but not for very long. When I use vi, I rarely venture beyond a few commands ( :q :wq i A dd p P J . ) and when I want to do something tricky, I usually have to look at the help page. I'm not proud of this, but it also seems to be just enough vi to get by on. This pidgin vi is sort of the inspiration for my editor. Without something like it, moving lines and chunks of code around in the PET screen editor would be impossible without a lot of retyping.
STOP-Z (zilch) erase the paste buffer
STOP-C (copy) nondestructively append the current logical line to the paste buffer
STOP-D (delete) append the current logical line to the paste buffer, deleting it from the screen. Scroll everything underneath up. Fill the bottom of the screen with blanks.
STOP-P (paste) insert as much of the paste buffer as will fit before the current logical line. Everything from the current logical line to the bottom of the screen moves down.
On further reflection, Paste really would have to replace physical line 25 with just the first-half-logical-line (approach A) if it's trying to insert an 80 character logical line but there's only 40 characters of room left at the bottom of the screen, for two reasons. First, if I am insertiing more paste buffer than will fit above some text already on the screen, it would look very strange to truncate the paste buffer at line 24 and show some original text on line 25. Second, approach B gives no indication to the user that something happened, unless I beep. And PETs don't have sound prior to the CRTC versions. Flashing the screen is a pain, it requires setting up IRQs.
Where I'm at today: I realized that having PASTEBUF return just the tail of the pastebuf isn't enough information. I can't do PASTEBUF PAD - and know the size, in bytes, so I can calculate how many lines I need to insert prior to the current line, because each PASTEBUF record is 41 or 81 characters, not 40 or 80. So I'm refactoring PASTEBUF to also return the size.
Code:
BEFORE:
: pastebuf ( addr ; the tail of the paste buffer )
pad
begin
dup c@ ?dup
( either the logical line length or 0, marking the end )
while
1+ +
repeat ; ( addr )
AFTER
: pastebuf ( addr size ; the tail of the paste buffer and its size in bytes )
pad 0
begin
...
while
...
repeat ; ( addr size )
https://github.com/chitselb/pettil/blob ... editor.a65I'm not sure if I'm getting on peoples' nerves with these long-winded soliloquies, but please weigh in if I am bugging you and I will just stick it on my
tumblr project blog from now on. Trying to explain it really helps me to think things through. I call it "the brick wall approach," but I'd rather tell it to people who might be interested in the project than my mom, even though the results are similar.