Monday, June 8, 2026

Implementing and testing the overtyping behavior in the 1052 Emulator - part 1

OVERTYPING IS A FEATURE OF THE 1052 THAT I WANTED TO EMULATE

The 1052 Console Printer is based on the IBM Selectric typewriter and uses interchangeable type elements to print on paper that is tractor fed using pinholes on the sides. The 1052 types across 120 columns, although the user can set the left and right margins to constrain the starting and ending column used. It types through a bicolor ribbon, allowing the program to select between red and black printing.

Because this typewriter puts ink on paper, it is possible to backspace and type a different character in the same column. This may be used to obscure text, such as a password that somebody typed into a program, or to form composite characters by combining more than one character from the typeball. 

Some programs in the IBM 1130 make use of this. For example, the APL/1130 system creates additional printed characters beyond the 88 available on the typeball by using overtyping, combining the quad (⎕) and quote (') characters to form the quote-quad () character. The 1052 diagnostic program prints, as I remember, a row of zero characters in one color then backspaces and prints a row of asterisk characters in the other color; this visually demonstrates the accuracy of spacing and backspacing as the asterisk should be inside the zero in all cases. 

SUPPORT IN PUTTY DEPENDS ON A SPECIAL CHARACTER

It appears that Putty, the terminal emulator I recommend for use with this emulator, can combine the foreground pixels of multiple characters but only if a special character is issued between the two. This is a unicode character called Zero Width Join (ZWJ). It is \u200D entered as a character in C. 

STRATEGY OF THE EMULATOR CODE TO IMPLEMENT THIS

The emulator will maintain a line buffer holding the selection codes for up to five characters overtyped in each of 120 columns. This is zeroed out whenever we move to a new line. As a request comes into the emulator to print a character, we add it to the line buffer in the current column position and then type everything at that column.

That is, we type the first character and then for each subsequent selection code that might be in that column of the buffer, we emit a ZWJ character followed by the next character. Thus we could combine up to five characters in any column.

When we backspace, we just move the cursor back but do not change what is displayed by the terminal program yet. If we are printing a character and we already had something in the column, because we have backspaced, then we add that to the buffer and print the new combination there. 

Spacing forward, as well as tabbing forward, will send a blank to the terminal program if the buffer does not contain a selection code for that column. Spacing forward over characters that were already typed should not emit a blank, it should redisplay the contents of the buffer for that column. 

TESTING ON WOKWI.COM TO VERIFY BEHAVIOR

I put the code on the Arduino Mega 2560 simulator at Wokwi.com and set up buttons to type characters, backspace and space so that I could test the logic. The simulated serial monitor at Wokwi.com does NOT support the ZWJ or combined graphics, but it does support Unicode characters. Thus I can't really be sure how this works until I run it on a real Arduino feeding the Putty terminal program. 

My initial method just saved the selection code but I soon discovered the flaw in that approach. The same selection code is used for both hemispheres of a typeball. We might have printed from the lower case hemisphere, then backed up and typed from the upper case side. The buffer must remember the hemisphere as well as the selection code in order to properly print the sequence whenever needed. I just added 100 to the selection code when we are using the upper case hemisphere, then separated the values when typing. 

Finally, it all appeared to be working properly. What I saw with Wokwi.com is the sequence of characters printed rather than overtyping, with no complaint about the ZWJ character in between them. If Putty does work like it is said to and will work with the APL 385 font, this should add my one missing capability to the emulator. I don't see why it won't work if it does blend emojis as well as handling languages like Arabic with composite characters, but we shall have to verify with testing. 

TESTING ON 1130 WITH PUTTY

I updated the emulator box with the new Arduino code and fired up the IBM 1130 system. I set up a sequence of print characters that include the quad-quote composite character and gave it a try. 

It printed the two characters in sequence, it did not combine them.  I then attempted some other combinations but had the same result. 

Finally, I tested the ability to back up quite a bit, overprint a character and then space forward without obscuring the previously entered text. That works correctly. 

I was understandably disappointed that the ZWJ didn't seem to work even though many references insist this works in Putty. I did some digging and discovered that the font you use with the ZWJ has to have that character slot defined as a zero width, in order to trigger the combining behavior of the two characters. 

I then grabbed FontForge and opened the APL385 Unicode font file. I found the slot for the ZWJ and saw that its width was indeed set to 600, not zero. I edited the width and saved the font. After replacing it on my windows system, I did some tests to see if this enables the composite character support I need. 

First, I added the ZWJ between two APL characters in a text processing program using the APL385 font. I seemed to have the zero width character sitting there in the string, but the program itself does not have the functionality to combine them. I then wrote the string out in the startup of my emulator program, so that I can verify immediately under Putty if the composite character will be produced. That is probably the only software I have that will render it properly. 

I am heading back to the workshop to test this out. If I can't turn on the behavior I want from Putty, I will disable the attempts in my emulator and just replace whatever was in a column previously with the newly typed character. That way I can get the emulator into productive use at the System Source Museum while I continue to look into the stretch goal of modeling overtyping. 

No comments:

Post a Comment