Sunday, November 17, 2013

Serial port communication on Apple IIc.

Apple II was a very good and quite popular 8-bit machine in its time. It features a hardware UART for RS-232 port communication that can still be used today. Even from the BASIC language level, it is quite simple to make the use of that feature. I happen to own Apple IIc, which I did not own in the 80-s. I bought the set of the computer, monitor, printer and software on e-bay out of curiosity. I have to admit I also like the look of the little machine which was advertised as a portable Apple II. It would no pass the standards of portability today, however in the early to mid 1980-s it was enough if the computer had a carrying handle and/or some sort of a case. Apple IIc has an UART/RS-232 built in permanently as it does not feature the expansion bus as its bigger brother Apple II does.

The basics are as follows:

On the PC side setup port to 300 baud (default apple 2c speed), 8 bit, no parity, 1 stop bit, no flow control. Your terminal may or may not offer customization of the parameters listed below. I used the Hyper Terminal Private Edition. Other emulators may offer the customization of the listed below properties in the different form. Follow you terminal emulator's documentation:
Terminal setup: ANSI
ASCII setup: append line feed to incoming line ends, force incoming data to 7-bit ASCII.

Apple IIc side - issue command PR#2.

Now all the output goes via serial wire to a PC.

Alternative baud setup:

Apple 2c:

After PR#2 command, press CTRL-A and then the baud code:

1B   50
2B   75
3B   110
4B   135
5B   150
6B   300
7B   600
8B   1200
9B   1800
10B  2400
11B  3600
12B  4800
13B  7200
14B  9600
15B  19200
16B  115k

To setup the serial port speed from basic, use print chr$(1) followed by the speed code, e.g:

10 pr# 2
15 print chr$(1);"15b"
20 print "hello world!"
30 goto 20

Above program will redirect output to serial port and setup transmission speed to 19200 baud.

PC side - follow manual of your terminal emulator software to match the baud rate of the Apple 2c.

The automatic line trace in BASIC is automatically on (seems to be a feature) when the output is redirected to a serial line. Perhaps because such mode of working was intended for development/debugging purpose. Anyway, it is good to include NOTRACE just after PR#2 in your program to turn this feature off. There are several other (than baud rate) parameters that can be setup for serial port after IN#2 or PR#2. Just use PRINT CHR$(1);"{command_code}" to set them up.
Here are the command codes:

Data format
Code Data Length Stop bits
0D   8           1
1D   7           1
2D   6           1
3D   5           1
4D   8           2
5D   7           2
6D   6           2
7D   5           2

ASCII setup:
Code Effect
I echo output to the screen
K do not send line feed after carriage return
L send line feed after carriage return

Code Parity Check Mode
0P   none
1P   odd
2P   none
3P   even
4P   none
5P   MARK(1)
6P   none
7P   SPACE(0)

Example BASIC program setting up 9600 baud, 8-N-1, send LF after CR:

20 PR#2
40 PRINT CHR$(1);"14b"
50 PRINT CHR$(1);"0d"
60 PRINT CHR$(1);"0p"
70 PRINT CHR$(1);"l":rem it is small "L".

For some reason, I have to setup 7 bit data length, 1 stop bit on the PC side, even though Apple works in 8-1 mode. I will have to look into this later, for now I don't understand why the discrepancy.

On Linux (R-Pi) I used 'putty' or just plain "cat /dev/ttyUSB0" to receive data from apple.

To redirect input and output to serial port, so you can work on apple from remote terminal, type on apple:


From this moment, whatever you type in the terminal emulator on the PC workstation is really happening on Apple. The PC workstation acts a a dumb terminal for the Apple computer. Pretty cool. You can actually create a boot diskette for the Apple to load up and execute all necessary serial port initialization commands at the boot time and with a PC/laptop connected to the Apple via serial port (or USB with USB to serial converter) you do not need a display monitor with the Apple computer. This way of working with Apple II of course may have some limitations, which I am sure user would discover very quickly. However it is possible to work with BASIC and text based programs in this manner.

Happy retro-computing!

Thank you for reading.

Marek Karcz, 11/17/2013

Saturday, November 16, 2013

Apple IIc as a dumb text terminal.

Using you old computer hardware with modern equipment.

If you happen to have Apple II (IIc) computer and you think it is just taking space, do not put it in the trash, sell or donate just yet. The thing is, you own it because perhaps you purchased it long time ago, or got it as a gift and at some time liked it. It gave you hours of fun and helped to introduce you into the computing world. Whatever the reason, it may make your heart heavy to let it go. Well, you can still use it! Consider this - Apple IIc has a good serial port hardware driver and can be easily interfaced with modern equipment that is also equipped with a serial or USB ports (with USB to serial converter). All that is needed on the Apple side is a terminal emulation software and a serial null-modem cable adaptor that converts the Apple's mini-din to the DB-9 connector seen on modern PC computers. All the information I needed in order to turn my Apple IIc into the serial dumb terminal I found here:

and here:

First I prepared 3 blank floppy disks for Modem MGR software. I used AppleWorks software which I happen to have purchased with my Apple IIc. To transfer the Modem MGR images to Apple, you need ADT Pro client on the Apple side and a server on the PC side. Both are available on the internet as well as detailed instructions how to install and configure them, so I will not duplicate it here. Just check out the web site:

After the transfer of Modem MGR software, I had 3 disks: Installation, Utilities and Work. First I inserted and booted the Installation disk on my Apple and follow the instructions. I configured the software to work in 80-column mode (menu option 2) video driver, non-smart modem (menu option 10) and saved the configuration back to the work disk.
Next I connected the Apple's serial port to my DSL (Damn Small Linux) server. The server runs a script:


while true
/sbin/getty -L 9600 ttyS1 vt100

The connection via standard serial cable and the mini-din to DB-9 adapter requires no null-modem connector, since the mini-din to DB-9 adapter cable is already a NULL modem. However I used the null modem serial cable and wondered for some time why this did not work. Then I had to add extra null-modem adapter.

Once computers were connected, I booted Modem MGR work disk on the Apple. It displays a bunch of options that can be accessed by pressing ESC key followed by the letter. At any time, I can press ESC and Shift-? to re-display the list of available options.

The first step is to setup the modem baud rate, which in my case is 9600. Next, the data format - number of bits, the parity and the number of stop bits: 8-N-1. The last step is to enter the Modem MGR into the terminal emulation mode, which is achieved by pressing ESC and ':' (colon) and then pressing V for loading the VT220 terminal emulation mode. Then I pressed enter and voila! - the login prompt appeared. Even though on the server side 'getty' runs in vt100 mode, I experienced no issues. This of course is easily adjusted on the server side.


Image 1: Transferring Modem MGR images to Apple 2c diskettes - client side.

Image 2: Transferring disk images - server side.

Image 3: A working text terminal emulator on Apple IIc.

Image 4: The output from 'top' command - it ran well and there were no emulation issues.
It was a fun little project. Now whenever I want to  have retro computing experience I can connect to my DSL server with Apple IIc and run Z-machine emulator to play one of the Infocom's text adventures.

Thank you for reading.

Marek Karcz, 11/16/2013