Paolo Amoroso's Journal

Tech projects, hobby programming, and geeky thoughts of Paolo Amoroso

To code on the Z80-MBC2 and V20-MBC homebrew computers I often transfer text files to and from their CP/M environments.

In one direction I send files from Crostini Linux by dumping them to CP/M, where PIP saves the text to CP/M files. In the opposite direction I run PIP on CP/M to print the files to the screen, where Minicom captures the text and saves it to files on Crostini.

CP/M and Unix have different line break and end of file encodings. In addition, the transfer process may introduce unwanted text. That's why the text files exchanged between the systems need some conversion, to automate which I wrote two short Bash scripts.

The first script, unix2cpm, converts line breaks and the end of file marker in the input to the CP/M encoding and prints the result to stdout. If the optional file name argument isn't supplied the script reads from stdin with a technique I researched. This is the script:

#!/usr/bin/env bash

# Convert line breaks and end of file from Unix to CP/M.
#
# Usage:
#
#   unix2cpm [filename]
#
# Reads from stdin if the optional argument is missing.

input_file="${1:-/dev/stdin}"

cat "$input_file" | unix2dos
echo -e -n '\x1a'

The script calls unix2dos distributed with the dos2unix / unix2dos tools. unix2dos converts line breaks from Unix to MS-DOS, which borrows the encoding from CP/M. unix2cpm needs only to append with echo the ^Z end of file control character.

Once converted, the file is ready to be dumped from Linux to CP/M.

I initiate file transfers in the oppostite direction by executing the Minicom command to capture the terminal output to a file, Ctrl-A L (Capture on/off). Then, at the CP/M prompt, I execute a command like this to print a file to the console:

A>a:pip con:=filename.txt

When printing ends and the A> prompt reappears, I turn off output capture in Minicom to close the capture file. The captured output contains the PIP command in the first line, then the text of the file, and finally the A> prompt in the last line.

To remove the unwanted first and last line I wrote the second script, skipfl (skip first and last). Again, the script reads from stdin if the optional file name isn't supplied and writes to stdout. The code is:

#!/usr/bin/env bash

# Skip the first and last file of the argument file
#
# Usage:
#
#   skipfl [filename]
#
# Reads from stdin if the optional argument is missing.

input_file="${1:-/dev/stdin}"

cat "$input_file" | sed '1d' | sed '$d'

The script calls sed to delete the first and last line with the d command.

No further processing of the captured CP/M output file is necessary as Minicom takes care of inserting the proper line break and end of file encodings.

#z80mbc2 #v20mbc #linux #retrocomputing

Discuss... Email | Reply @amoroso@fosstodon.org

Turbo Pascal 3.0 for CP/M has a display issue I noticed on the Z80-MBC2 and V20-MBC homebrew computers. When using the development environment, text in the terminal remained stuck with boldface turned on.

It was enough to launch Turbo Pascal and execute any command (e.g. compiler Options), or exit Turbo Pascal, to turn on boldface and leave it stuck in the IDE, in CCP, and when running other programs. Everything went bold such as code in source files edited in Turbo Pascal, CCP command lines, and the output of transient programs.

The issue occurred under CP/M 3.0 on the Z80-MBC2 and CP/M-86 1.1 on the V20-MBC, both accessed from the Minicom terminal emulator under Crostini Linux on my Chromebox.

I tried ANSI and VT102 emulation in Minicom and run the Turbo Pascal configuration utility TINST to set the terminal to ANSI, but the issue persisted. The only workaround was to resize the terminal window, which reinitializes the display.

I posted to comp.os.cpm for help and learnt Borland left the terminal reset string blank in the ANSI entry, which thus doesn't reset text attributes.

The fix was simple. I run TINST, selected the ANSI terminal, and edited the definition to insert the following reset string via the option Send a reset string to the terminal (the corresponding escape code strings and descriptions are below the hex values):

$1b $63    $1b  $5b $32 $4a

ESC c      ESC  [   2   J
Reset      Clear screen

ESC c is not enough as it only resets the terminal but doesn't clear the screen. With the new string the text attributes are now properly handled and the terminal is no longer stuck in boldface after using Turbo Pascal.

#z80mbc2 #v20mbc #retrocomputing

Discuss... Email | Reply @amoroso@fosstodon.org

A few years ago I bought a cheap Bluetooth keyboard from Amazon.it. At €14, it was mostly an impulse buy for exploring mobile typing on the go and similar settings, such as work stations with limited desk space. This is the device:

FREALL 7INKEYBD-BK 7" Bluetooth keyboard.

I initially used the keyboard with the Android tablet and smartphone I had at the time, a 7” Lenovo Tab E7 and a Pixel 2 XL. I later repurposed the keyboard for the devices I replaced those with, a Lenovo Tab M8 HD 8” tablet and a Pixel 4 XL smartphone. Here is the keyboard with the Lenovo Tab M8 HD:

FREALL 7INKEYBD-BK Bluetooth keyboard with a Lenovo Tab M8 HD 8" tablet.

Despite the simplicity, it took me some trial and error to figure how to pair the keyboard and what keystrokes insert the symbols I need, such as accented letters. So I’m posting these notes in case you come across the same or similar keyboards.

Hardware and packaging

The keyboard is a cheap, compact, plastic 7” chiclet unit that comes with a small foldable stand to hold a tablet or phone. To charge the keyboard I plug it into my Chromebox via the keyboard’s mini-USB port.

The product and packaging have no branding and Android identifies it simply as “Bluetooth Keyboard”. The Amazon listing indicates FREALL as the manufacturer and 7INKEYBD-BK as the model.

The instruction sheet isn’t of great help for learning how to operate the keyboard. The document is short, incomplete, and inaccurate. But reading the Amazon reviews helped me understand the pairing procedure. I discovered the rest by experimenting.

Pairing

Although the keyboard can work with different mobile and desktop operating systems, I use it only with Android and this is the experience I’m sharing here. To pair the keyboard with an Android device:

  1. turn on the keyboard
  2. on the keyboard, press CONNECT
  3. on Android, turn on Bluetooth and start the pairing flow
  4. on the keyboard, press Fn+Q
  5. on Android, tap the keyboard entry
  6. on the keyboard, type the pairing code Android prompts to enter
  7. on the keyboard, press Enter

After pairing is complete, on your Android device you’ll get a notification prompting to configure the keyboard by selecting a language and layout. This step may not be necessary.

From now on, to use the keyboard enable Bluetooth on Android and turn on the keyboard, which should connect automatically.

Keyboard shortcuts

The keys hold up to four labels for entering symbols, controlling media playback, or executing commands.

Accessing most of the symbols or functions of a key is often self-explanatory. For example, to type a blue symbol on a key, press that key while holding the modifier key with the blue Fn label.

Typing other characters or executing commands not printed on the keys is harder, so I include below some lists of useful keystrokes.

Symbols

You can directly insert the symbols in the following table by pressing the corresponding keystrokes. To type an accented character, press the keystroke that selects the accent you want and then press the character. For example, to get an e with a grave accent, è, press Alt +` and then e.

Keystroke Symbol
Alt+E é
Alt+ ` grave accent
Alt+U umlaut
Alt+I ~
Alt+S ß
Alt+c ç
Alt+N

Android commands and actions

The keyboard accepts the standard Android keyboard shortcuts. I found a few more and listed in the table below the ones that are handy, little known, or frequently used.

Launching apps

To launch one of these apps, here are the corresponding shortcuts:

Keystroke App
type search query Google Search
command Google Assistant
command+B Chrome
command+C Google Contacts
command+E Gmail
command+L Google Calendar
command+S Google Messages

Actions

The keyboard lets you invoke other Android features and navigation actions. Here are the ones I found:

Keystroke App
Alt in text field emoji selector
control+Enter set focus
command+Delete Back
command+Enter go to home screen
command+N open notifications shade

#Android

Discuss... Email | Reply @amoroso@fosstodon.org

The Fediverse presence @paolo@journal.paoloamoroso.com of this blog has some limitations and quirks, such as the way commenting is set up. Another quirk is if I edit an old blog post, a new Fediverse post ends up in the followers' Mastodon timelines.

#blogging

Discuss... Email | Reply @amoroso@fosstodon.org

The option 4: Autoboot-80 of the V20-MBC boot menu switches the Nec V20 to Intel 8080 mode and loads version 1.4 of the IMSAI 8K BASIC interpreter. In this session I typed in and run a short BASIC program to print the ASCII character set:

IMSAI BASIC on the V20-MBC homebrew computer.

The code is:

10 FOR I=32 TO 127
20 PRINT CHR$(I);
30 NEXT I

Despite the brevity, entering the code I bumped into some unexpected errors and behavior. It's been almost four decades since I used a resident BASIC on a microcomputer, and never with a terminal. No wonder interacting with IMSAI BASIC felt weird.

Reading the IMSAI BASIC manual and experimenting with the interpreter cleared the hurdles and let me make progress, though I'm not sure whether the issues may be related to the terminal settings. By the way, the commented Assembly source of the interpreter in the manual is an interesting reading.

Here are some notes on what I learned.

BASIC keywords, commands, and identifiers must be in all uppercase. Lowercase is supported only in strings assigned to variables, but printing string literals yelds uppercase text.

Pressing Backspace or Ctrl-H moves the cursor one character to the left and Del does nothing. The only ways of fixing typos or errors are deleting the whole line with Ctrl-U or entering it again.

When the environment gets messed up I execute the NEW command that clears the program and data, thus letting me start from scratch.

#v20mbc #retrocomputing

Discuss... Email | Reply @amoroso@fosstodon.org

This blog is hosted at Write.as and uses the default commenting system of the sister platform Remark.as. The Discuss... link in the footer of every post leads to the Remark.as comment box, which does the job but requires a paid account.

To provide alternate options I added to the footer a link to email me and now I'm experimenting with comments from the Fediverse.

The blog has the Fediverse presence @paolo@journal.paoloamoroso.com you can follow. On Mastodon you'll receive a toot for every new blog post. To comment, reply as usual to the toot. But be sure not to delete my Mastodon handle @amoroso@fosstodon.org prefilled in the edit box, which is different from @paolo@journal.paoloamoroso.com

This setup is motivated by a limitation of the blog's Fediverse presence and based on a workaround Write.as founder Matt Baer suggested.

The problem is the blog is unable to receive Fediverse mentions or reactions, so Matt suggested to mention a Mastodon handle anywhere in the blog posts. This way the blog posts' toots automatically include the right Mastodon account in replies, in my case @amoroso@fosstodon.org

When replying to a toot, Mastodon highlights the textual handles of any extra mentioned accounts and typing anything deletes them. That's why you need to pay attention, for example by pressing the right arrow key to un-highlight the handle and move the cursor to the right spot to begin typing the reply.

How did I set up Fediverse commenting on Write.as? In the blog settings, under Customize > Post Signature I inserted this code in the signature, i.e. the footer Write.as appends to posts:

<!-- comment -->
[Email](mailto:info@paoloamoroso.com?subject=Reply%20to%20Paolo%20Amoroso%27s%20Journal) | Reply @amoroso@fosstodon.org

The <!-- comment --> shortcode inserts the Remark.as link (I had to insert spaces to escape it, remove them in your signature). The email link has an ordinary mailto URL. And the Fediverse commenting option is just my Mastodon handle.

#blogging

Discuss... Email | Reply @amoroso@fosstodon.org

Turbo Pascal 3 for CP/M comes preinstalled with the Z80-MBC2 and V20-MBC homebrew computers. Checking out the development environment made me rediscover Turbo Pascal and realize its potential for programming these computers.

Although I owned Turbo Pascal for MS-DOS in the early 1990s, I didn't use it much. Between other languages later getting my attention and Borland losing its market leadership, I eventually forgot about Turbo Pascal. Now, with the development environment handy on the Z80-MBC2 and V20-MBC, I began checking out the Turbo Pascal CP/M version I had never played with.

Being familiar with the Turbo Pascal MS-DOS IDE, which features a nice text user interface with pull-down menus and dialogs, the CP/M version seemed spartan and primitive.

But I pressed ahead, tried the various commands, edited and compiled some code, and got familiar with the keystrokes and workflow. I soon felt at ease with Turbo Pascal for CP/M. The environment is still suprisingly usable and productive, allowing fast edit-compile-run cycles with short compilation times even on the 8-bit Z80-MBC2.

I now understand why Turbo Pascal made such a sensation at the time and revolutionized development tools.

To learn the Turbo Pascal environment and language I began reading the manual, as well as books about Turbo Pascal and Pascal. The more I used Turbo Pascal and read about it, the more I enjoyed it and wanted to learn and explore.

Next thing I knew, I was down a rabbit hole.

This experimentation and reading made me realize the potential of Turbo Pascal as an ideal tool for hobby projects with these homebrew computers.

Pascal is an easy to understand, readable, and expressive language. Despite the age and design flaws, it allows to write fairly advanced code. Pascal makes practicality win over language purity.

Sitting at a sweet spot between ease of use, features, and power, Turbo Pascal is a perfect fit for CP/M as it consumes limited resources, generates moderatly small and fast executables, and can access all the features of the system. That's why it's a good environment for quickly developing small tools or programs for the Z80-MBC2 and V20-MBC.

#pascal #retrocomputing #z80mbc2 #v20mbc

Discuss... Email | Reply @amoroso@fosstodon.org

I was a heavy user of shareware software but my experience was like a story with missing clues and no ending. Reading Shareware Heroes: The renegades who redefined gaming at the dawn of the internet by Richard Moss filled the gaps, completed the story, and gave a sense of resolution.

Android tablet with the cover of the of the Shareware Heroes ebook open in a reading app.

I encountered shareware via the Amiga Fish disk collection, and later MS-DOS productivity software and utilities such as the PC-Write word processor and the CompuShow image viewer.

As an Italian student I loved the affordable programs and the wide selection of shareware, much wider than the fewer and expensive packages by traditional American software houses local retailers carried. I assumed everyone else loved shareware, so I always found puzzling this distribution model was little known even among computer geeks. Equally puzzling was why shareware seemed to have faded since the late 1990s.

Later I realized my narrow focus on productivity software and programming tools made me miss major events, hits, and market players of gaming shareware, which I never was into.

There were other things I didn't know or understand at the time, such as why some shareware never made it to Europe. And, not having owned a Mac until well into the Internet era, I wasn't aware of the role of Mac shareware. Finally, I always wondered about the business side of shareware.

Thanks to accurate and extensive research based on original sources and interviews, Shareware Heroes puts the pieces together and presents a complete, coherent history of shareware from the early days to the Internet era. It paints the big picture, discusses shareware in the context of the computer industry, traces the evolution of shareware business models, and ties the past with the present from early shareware titles to the contemporary indie scene.

Although I'm less focused on gaming, the book has a lot of material also on the application software and utilities at the roots of shareware. But I found the coverage of gaming equally interesting even if I'm a non gamer. For example, I realized the key role of Apogee and id in both the evolution of gaming and software business models.

Interestingly, Shareware Heroes indirectly provides some historical context on the dispute between Epic Games, Apple, and Google over app store fees. Founder Tim Sweeney has always been highly competitive since the early days of Epic Games, for example in his rivarly with Apogee and id.

Sweeney is a tough leader, Apple and Google should have seen it coming. Their executives may want to read Shareware Heroes.

#retrocomputing #books

Discuss... Email | Reply @amoroso@fosstodon.org

On this blog I regularly share my retrocomputing experience and projects with the Z80-MBC2 and the V20-MBC homebrew computers. In addition, on my Mastodon account @amoroso@fosstodon.org I often post screenshots, links, videos, and other short updates grouped under the #z80mbc2 and #v20mbc hashtags.

#z80mbc2 #v20mbc

Discuss... Email | Reply @amoroso@fosstodon.org

I needed to write some Bash scripts on Linux that read the input from stdin or a file passed as an optional argument, but couldn't figure how.

Googling turned up several designs and examples, such as on StackOverflow, where the script directly processes the input. But I actually wanted the script to assemble a pipeline, feed the input into the beginning, and delegate the processing to the programs and filters in the pipeline.

More googling turned up exactly what I wanted, a reply by the user Daniel buried in a long StackExchange thread.

The trick is to assign to a variable the input stream and feed it into the first program of the pipeline. To demonstrate the technique, the script unlc (unique line count) prints the number of unique lines in the input:

#!/usr/bin/env bash

# unlc - print number of unique lines in the optional input file or stdin
#
# Usage:
#
#   unlc [input-file]

input_file="${1:-/dev/stdin}"

cat "$input_file" | sort | uniq | wc -l

The code assigns to input_file the first argument $1 passed to the script, if supplied, or the standard input. Then cat feeds the content of input_file to the rest of the pipeline. The script is invoked by passing a file as an argument or feeding the data into the script's standard input:

$ cat input-file.txt 
1
2
2
3
4
4
4
4
$ unlc input-file.txt 
4
$ cat input-file.txt | unlc
4

Simple and brilliant.

#Linux

Discuss... Email | Reply @amoroso@fosstodon.org

Enter your email to subscribe to updates.