Information wants to be free...

Sharp IQ-7100M Linux Link

Here is a way to download data from a Sharp IQ-7100M organizer into a modern Linux system. To be able to make the connection you will need to use a USB<->UART converter that operates on a lower TTL voltage level and most importantly INVERTS the TXD and RXD logic levels. I used the SparkFun DEV-09873 which is actually 3.3V, but the 5V version probably works as well since the Sharp organizer uses 5V TTL levels. The FTDI FT232RL chip on this supports inverting the TXD and RXD logic levels by using the "FT_PROG" program to reprogram the settings.

The connection table is as follows:

|------|--------------|
| FTDI | Sharp 15-Pin |
| -----|---|----------|
| GND  | 7 | GND      |
| RXD  | 2 | TXD      |
| TXD  | 3 | RXD      |
|------|---|----------|
          


With the SparkFun adapter it is possible to just use three wires with male Dupont connectors:

Sharp IQ-7100M


Here is a small C program that will download the "MEMO" database:

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

#define TTY_DEVICE "/dev/ttyUSB0"

static const char command[] = "\x04R030000\r\nMEMO    1  \r\n";

int main(void)
{
  int fd;
  struct termios tios;
  unsigned char byte;
  const char *p;

  fd = open(TTY_DEVICE, O_RDWR | O_NOCTTY);
  if (fd == -1) {
    fprintf(stderr, "open() failed with errno: %d\n", errno);
    return EXIT_FAILURE;
  }

  if (tcgetattr(fd, &tios) == -1) {
    fprintf(stderr, "tcgetattr() failed with errno: %d\n", errno);
    close(fd);
    return EXIT_FAILURE;
  }

  cfmakeraw(&tios);
  cfsetispeed(&tios, B9600);
  cfsetospeed(&tios, B9600);

  if (tcsetattr(fd, TCSANOW, &tios) == -1) {
    fprintf(stderr, "tcsetattr() failed with errno: %d\n", errno);
    close(fd);
    return EXIT_FAILURE;
  }

  /* Send the command, using a small delay: */
  p = &command[0];
  while (*p != '\0') {
    if (write(fd, p, 1) == -1) {
      fprintf(stderr, "write() failed with errno: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }
    usleep(10000);
    p++;
  }

  /* Read the response until a EOF character appears: */
  do {
    if (read(fd, &byte, 1) != 1) {
      fprintf(stderr, "read() failed with errno: %d\n", errno);
      close(fd);
      return EXIT_FAILURE;
    }
    putc(byte, stdout);
  } while (byte != 0x1A);

  close(fd);
  return EXIT_SUCCESS;
}
          


This program just dumps the raw data, which is already in ASCII. Since there is no flow control, a sleep of 10ms was added between each byte sent to prevent the Sharp organizer from overflowing and giving up. Note that you will need to be in the "PC-Link" menu for any transfer to work, which is reached by pressing "Shift" + "Option" then "4".

Topic: Scripts and Code, by Kjetil @ 23/09-2022, Article Link

Epson HX-20 Emulator

I have made an emulator called "hex20" that emulates the Epson HX-20 Portable Computer in a Linux terminal, similar to my other Z80 CP/M, NES and C64 emulators.

The HX-20 system uses two Hitachi HD6301 CPUs (based on the Motorola 6800 family) which communicate with each other over a internal serial link. This emulator needs the ROM files for both of these to function. A CRC32 check is performed on startup to make sure that the correct version 1.0 or version 1.1 ROM files are used.

One of the main features is the emulation of the LCD panel by using curses to display each individual pixel as a '#' (or '%') on a large 120x32 terminal window. It is also possible to force a smaller 20x4 window, but then only ASCII will be displayed and none of the special pixel drawing functions will work. Most of the keyboard keys are supported and multiple international character sets can be selected.

Another feature is auto-loading of BASIC program text files. This is achieved through clever use of the HX-20 ROM software ability to do automatic key input. A '2' is injected to enter BASIC from the menu, then all the text from the file is sent, and finally a BASIC RUN command is issued to start execution. On a real HX-20 a "Ctrl/@" initialization is usually needed on a cold start, but all the necessary data is already initialized automatically by the emulator itself. The RTC is also mapped directly to the host system clock so it does not need to be set.

The initial version can be downloaded here but the code is also available in this Git repository for further development. Note that at this point several features are still missing like sound support, TF-20 floppy drive and micro-cassette emulation.

Some screenshots from the emulator running in xterm:

Main menu

Clock

Blackjack

Blimp


Development of the emulator would have been impossible without the excellent Epson HX-20 resources from F. J. Kraan's web pages.

Topic: Open Source, by Kjetil @ 02/09-2022, Article Link

Monospaced 11x10 Font

For my VT100 terminal emulator on Raspberry Pi Pico project I needed to make my own font to fit the specific requirements. For convenience, that source code only contains the font data as a static "char.rom" binary file. For completeness sake I present the font data source here.

The source data is an image, so any modifications can be done in an image editor:

11x10 Font Data


As can be seen here the image is divided into a grid of 16x16 to provide 256 characters in total.

This image needs to be converted to PGM format and then be fed into a special utility that converts it to the actual ROM binary file.

The source code for the PGM to ROM utility is provided here, which operates on stdin/stdout for the conversion:

#include <stdio.h>
#include <stdbool.h>

#define HEIGHT 10
#define WIDTH 11
#define CHAR_PER_LINE 16
#define BYTES_PER_LINE 176
#define COLLECT (HEIGHT * BYTES_PER_LINE)

static unsigned char buffer[COLLECT];

static int power_of_two(int n)
{
  if (n == 0) {
    return 1;
  } else {
    return 2 * power_of_two(n - 1);
  }
}

int main(void)
{
  int skip = 4;
  int c, n, i, j, k;
  int b;

  n = 0;
  while ((c = fgetc(stdin)) != EOF) {
    if (skip > 0) {
      if (c == '\n') {
        skip--;
      }
      continue;
    }

    buffer[n] = c;
    n++;
    if (n >= COLLECT) {
      n = 0;

      /* Store as 16 bits by 10 lines, even if 11 bits wide. */

      for (i = 0; i < CHAR_PER_LINE; i++) {
        for (j = 0; j < HEIGHT; j++) {
          b = 0;
          for (k = 0; k < 8; k++) {
            if (buffer[k + (i * WIDTH) + (j * BYTES_PER_LINE)] == 0) {
              b += power_of_two(7 - k);
            }
          }
          fputc(b, stdout);

          b = 0;
          for (k = 0; k < 3; k++) {
            if (buffer[k + 8 + (i * WIDTH) + (j * BYTES_PER_LINE)] == 0) {
              b += power_of_two(2 - k);
            }
          }
          fputc(b, stdout);
        }
      }
    }
  }

  return 0;
}
          


Topic: Scripts and Code, by Kjetil @ 19/08-2022, Article Link

CentreCOM MR820TR Hub Repair

I found a broken "Allied Telesyn CentreCOM MR820TR" network hub in the trash:

MR820TR Broken


When power was applied the power LED would just blink rapidly. The internal PSU is supposed to supply +5V and +12V on two rails, but when I measured these with the logic board connected they were just +1.6V and +8.1V. Disconnecting the logic board showed +4.8V on the +5V rail and variying voltage between +7.3V and +7.6V on the +12V rail, so likely something wrong with the internal PSU.

I measured the ESR of several electrolytic capacitors in-circuit and one of them (C06) in the center of the board had bad readings. I unsoldered this one and measured it again, and it was still bad:

MR820TR Bad Capacitor


I replaced it with a new one:

MR820TR New Capacitor


This network hub is now working again:

MR820TR Fixed


Topic: Repair, by Kjetil @ 05/08-2022, Article Link

Renesas GCC Toolchains Update

I recently installed Slackware 15.0 on a computer and I noticed that my older script no longer works well. Here is an updated script that compiles GCC version 12 and it's associated tools. The steps are also simplified, mainly because "--enable-maintainer-mode" has been removed when configuring "binutils".

I have tested with the two Renesas target architectures that I use; RX and RL78 so one of these can be selected as the argument for the script. By default the toolchains are installed at /opt/ but this can be changed with the PREFIX variable in the script. Also note that "make" as been set up to run 32 parallel jobs which greatly improves the compilation time if you have enough cores, so adjust this as needed.

Here is the updated script:

#!/bin/bash
set -e

if [ -z "$1" ]; then
  echo "Choose a target:"
  echo "1) rx-elf"
  echo "2) rl78-elf"
  exit 0
elif [ "$1" -eq 1 ]; then
  TARGET="rx-elf"
elif [ "$1" -eq 2 ]; then
  TARGET="rl78-elf"
else
  echo "Unknown target!"
  exit 1
fi

PREFIX="/opt/gcc-${TARGET}/"
BUILD_DIR="build-${TARGET}/"

export PATH="${PREFIX}bin:$PATH"

# 1) Prepare build directories:
if [ -d "${BUILD_DIR}" ]; then
  echo "Old build directory detected, please remove it."
  exit 1
else
  mkdir -p "${BUILD_DIR}/binutils"
  mkdir -p "${BUILD_DIR}/gcc"
  mkdir -p "${BUILD_DIR}/gdb"
  mkdir -p "${BUILD_DIR}/newlib"
fi

# 2) Get sources:
if [ ! -d source ]; then
  mkdir source
  cd source
  wget "https://gnuftp.uib.no/gcc/gcc-12.1.0/gcc-12.1.0.tar.xz"
  wget "https://gnuftp.uib.no/gdb/gdb-12.1.tar.xz"
  wget "https://gnuftp.uib.no/binutils/binutils-2.38.tar.xz"
  wget "ftp://sourceware.org/pub/newlib/newlib-4.1.0.tar.gz"
  tar -xvJf gcc-12.1.0.tar.xz
  tar -xvJf gdb-12.1.tar.xz
  tar -xvJf binutils-2.38.tar.xz
  tar -xvzf newlib-4.1.0.tar.gz
  cd ..
fi

# 3) Build binutils:
cd "${BUILD_DIR}"
cd binutils
../../source/binutils-2.38/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-werror
make -j32
sudo make install
cd ..

# 4) Build gcc (step 1):
cd gcc
../../source/gcc-12.1.0/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --disable-shared --with-newlib --enable-lto --disable-libstdcxx-pch --disable-nls --disable-werror
make -j32 all-gcc
sudo make install-gcc
cd ..

# 5) Build newlib:
cd newlib
../../source/newlib-4.1.0/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make -j32
sudo make install
cd ..

# 6) Build gdb:
cd gdb
../../source/gdb-12.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make -j32
sudo make install
cd ..

# 7) Build gcc (step 2):
cd gcc
make -j32
sudo make install
          


Topic: Configuration, by Kjetil @ 15/07-2022, Article Link

Terminal Mode Commodore 64 Emulator Disk Support

I have added support for D64 disk images to tmce64 and increased the version number to "0.3". In order to facilitate this several things needed to be added. The CIA emulation has been expanded to include the data ports, which are used to communicate with the disk drives. But the biggest task was to emulate the Commodore IEC serial bus that the KERNAL expects.

The disk and serial bus emulation is by no means complete, and is limited to be able to get a file listing (LOAD"$",8) and loading individual files. Fast loaders will not work and attempting to do anything fancy will probably freeze the emulator.

Stack trace support has also been added to the built-in debugger. There is even support for symbol names, but this is currently just a hardcoded list of certain serial bus functions. Bank switching for the VIC-II chip is also handled in case any programs changes the graphics memory areas.

These changes makes it possible to run the 8-Bit Guy's Attack of the PETSCII Robots in the emulator. Since conversion is done from PETSCII, the reality is closer to "ASCII Robots" though. Since sprites are not supported, use the "C64PETSCII" version of the game.

Some more screenshots:

Attack of the PETSCII Robots Menu

Attack of the PETSCII Robots In-Game


Version 0.3 can be downloaded here but the GitHub repository has also been updated.

Topic: Open Source, by Kjetil @ 02/07-2022, Article Link

VT100 Terminal Emulator on Raspberry Pi Pico

Here is another Raspberry Pi Pico project, this time a DEC VT100 Terminal emulator. Host communication goes through the "standard" UART, composite video is used for the output and a PS/2 keyboard is used for the input. I have named this program "Terminominal".

Since I'm Norwegian I have made some design choices that reflect this. The first is that the composite video uses the PAL standard at 50 Hz. The keyboard scancode handling expects the Norwegian layout, but this can be changed to US layout with a compile time define. Finally the built-in font/character set is ISO-8859-1 (latin-1) compatible.

The composite video (CVBS) is generated by one of the Pico's PIO cores running at 40 MHz, which in turn creates time slices of 0.05 microseconds that affects a lot of the architecture in this program. After taking care of overscan, there is 880 dots on 240 scanlines remaining for the "visible" picture. First I tried using a standard CGA font at 8x8 which would give 110 columns by 30 rows, but the picture was almost unreadable. Instead I designed my own 11x10 font which fits perfectly for a 80 column by 24 rows picture and is quite readable on a CRT display.

The first ARM core reads the UART for incoming bytes and processes these to emulate the VT100 behaviour. Escape codes are processed and then a "screen" array is updated which represents all the characters currently on the screen. The second ARM core fetches characters from this "screen" array, if they have changed, and converts these to scanline and dot information using the font data and puts this into a "frame" array. DMA is used by the PIO core to fetch the "frame" array and push this out on the GPIO pins.

A 2-bit DAC for the video is created by using two resistors. Since the GPIO voltage is 3.3V and the composite video input impedance (on a TV set) is 75 ohms, good values are 680 ohms and 220 ohms for these resistors. It is also possible to use 1000 ohms and 330 ohms, which gives a slightly dimmer picture. The 2 bits gives four signal levels, where one is sync and the other three shades of: black, grey and white.

The PS/2 keyboard protocol is handled by the second PIO core which generates an interrupt once the required 11 bit frame has been read. The interrupt handler converts the scancode to the appropriate byte and sends it out on the UART. Note that since the PS/2 protocol uses 5V and the Raspberry Pi Pico GPIO pins uses 3.3V a level shifter is needed in between!

The VT100 emulation has been tested with vttest and the most important features are supported. VT52 and VT102 modes are not really supported. It should work fine against a Linux host at least. The UART runs at 115200 baud, but can be changed through re-compilation to other speeds.

Here is a block diagram which shows the architecture:

Terminominal Diagram


Here is a connection/function table for the GPIO pins:

|--------|-----------|------------|-------------------------|
| Pin No | Pin Name  | Function   | Connected To            |
|--------|-----------|------------|-------------------------|
| 1      | GP0       | UART TX    |                         |
| 2      | GP1       | UART RX    |                         |
| 6      | GP4       | PS/2 Data  | 3.3V<->5V Level Shifter |
| 7      | GP5       | PS/2 Clock | 3.3V<->5V Level Shifter |
| 21     | GP16      | CVBS DAC   | 680 Ohm Resistor        |
| 22     | GP17      | CVBS DAC   | 220 Ohm Resistor        |
| 36     | 3V3 (OUT) | +3.3V      | 3.3V<->5V Level Shifter |
| 40     | VBUS      | +5V        | 3.3V<->5V Level Shifter |
|--------|-----------|------------|-------------------------|
          


Here is a breadboard layout created with Fritzing:

Terminominal Breadboard


Notice that the GPIO pins for the composite video is on the other end of the Pico. This was needed because it generates a lot of noise, so much in fact that it affects the PS/2 signalling. This would result in lost bits and parity errors.

A snapshot of version 0.1 can be downloaded here, or check the Git repository here. Check the included README.md for build instructions. It is also possible to compile an SDL version which is used for testing directly on Linux.

I appreciate the good instructions from Van Hunter Adams on how to use DMA on the Raspberry Pi Pico and Javier Valcarce on how to generate PAL video signals.

Here is a photo of Terminominal running on one Pico and connected to another Pico running the kaytil CP/M emulator:

Terminominal and Kaytil


Topic: Open Source, by Kjetil @ 03/06-2022, Article Link

Telephone Handset Connector Replacements

I have some old telephone handsets, where at least one of them seems to date back to the 1930's based on some patents ("British Patents 319837.328926.433234") that I found. All of them had strange connectors incompatible with modern equipment:

Old connection on handset #1

Old connection on handset #2

Old connection on handset #3


But since the speaker and microphone technology has remained mostly the same for over a century, I decided to simply replace the connectors with modern mini jack plugs:

Mini jack plug replacements

This makes it possible to connect them easily to a modern PC and even use them for voice chat.

On the first one the original cable disintegrated when I tried to re-use it, so I replaced the entire cable. This one also has a switch that I wired to pin 8 and 7 on a DE9 connector, so that I can use the CTS/RTS trick to read it through a standard PC serial port.

Handset #1 finished


On the second one I was able to re-use the original cable. This one also has a switch, but I did not wire that up to anything.

Handset #2 finished


On the third one I had issues with a broken wire in the original cable, so that had to be replaced as well. Here I ended up simply re-using the entire cable with connectors from a broken PC headset.

Handset #3 finished


Topic: Repair, by Kjetil @ 13/05-2022, Article Link

CP/M on the Raspberry Pi Pico

A new port is available of my "kaytil" Z80 CP/M 2.2 emulator, this time targeting the new Raspberry Pi Pico.

A snapshot of the "Version 0.2" source can be downloaded here, or check out the Git repository here. The GR-SAKURA version has now also been incorporated into the same tarball and Git repo, instead of residing on a branch.

In the same fashion as the GR-SAKURA version, the CP/M 2.2 and CBIOS binaries are embedded directly into the final binary. For the Pico version this is taken even a step further since the disk images are ALSO embedded into the final binary! This means the disk images are in fact hard-coded and needs to be provided/updated before building. The disk images provided with the source code are just dummies and should be replaced with something more useful.

I figured that embedding the disk images was the easiest way to get things up and running considering the constraints of the Raspberry Pi Pico platform. This works nicely since the Pico has 2MB of Flash and can easily hold four IBM 3740 floppy disk images, typically 256KB in size each. Embedding the disk images is done using objcopy and forcefully placed in the ".rodata" section which causes them to reside in the Pico Flash instead of the SRAM.

The console is available on the "standard" UART at pins 1 and 2 and running at 115200 baud. Conversion between ADM-3A codes to VT100/ANSI codes are done in the emulator in the same way as the other versions.

Building requires the ARM GCC toolchain, CMake and the Pico SDK; just follow the official guide on how to set this up. In typical CMake fashion, create a build folder and call cmake pointing to the "pico/" subdirectory containing the CMakeLists.txt file:

mkdir build
cd build
PICO_SDK_PATH=/path/to/pico-sdk cmake /path/to/kaytil/pico/
make
          

The resulting "kaytil.elf" file can be flashed with SWD, or the "kaytil.uf2" file can be copied through USB in the BOOTSEL mode.

Here is a photo showing it in action, using a Commodre 64 as a terminal:

Kaytil on the Pico with a C64 Terminal

For this to work I used a level shifter between the C64 user port and the Raspberry Pi Pico to convert between +5V and +3.3V. In addition I changed the baudrate to 2400 baud by calling "uart_set_baudrate(uart0, 2400)" in "console_init()".

Topic: Open Source, by Kjetil @ 22/04-2022, Article Link

Terminal Mode Commodore 64 Emulator Update

I have performed a massive overhaul of the proof-of-concept C64 emulator I published about last year. This new version,which I have dubbed "0.2" is much more usable.

A major change in the architecture is that the old version was blocking on input from stdin, which is an interesting concept, but not feasible for more advanced usage. It is now based around curses with non-blocking stdin instead. Moving to curses means there is now a lot better support for graphics, including colors if a 256-color terminal is used. Conversion is done from PETSCII to ASCII and will work best as long as the default character sets are used. There is no sprite emulation.

Pressing Ctrl-C at any time will switch to a (non-curses) debugger. In this mode it is possible to dump memory locations and get a CPU trace. In addition there is support for setting read and write breakpoints on memory addresses which breaks back into this same debugger. In order to properly exit the emulator one must also typically enter the debugger and issue a 'q' from there to quit.

The emulator can be run at close to C64 speed (for games) or in "warp mode" where 100% CPU is used (for raw BASIC programs). I also needed to add support for the timers in the CIA since some games rely on these for random number generation. One unique feature is that getting the TOD (Time of Day) registers from the CIA will return the actual clock from the host system.

As before the emulator needs the ROMs from VICE to run, but the location of these can now be specified on the command line in case they are not at the default location.

There is no Datasette (tape) or 1541 (floppy disk) support, but C64 PRG-style programs may be loaded directly from the command line (or debugger) instead. These are injected directly into memory where they are supposed to be for the BASIC "RUN" command to work. Most BASIC programs should probably work, but machine code programs are hit-and-miss.

The new version can be downloaded here and the GitHub repository has also been updated.

Finally, some color screenshots:

BASIC Prompt

Rolling Demo #1

Rolling Demo #2

Lord of the Balrogs

Oslo B0rs

Regneark

Stock Market


Topic: Open Source, by Kjetil @ 08/04-2022, Article Link

Older articles

Newer articles