Inari figures

ZX Spectrum retro game programming

If you are a child of the 1980’s, you maybe remember the Sinclair ZX Spectrum. It was an affordable home computer that could be connected to a color TV set, and used compact cassettes as mass storage.

My first computer was a Sinclair ZX-81. I learned BASIC and also Z80 assembler on it. Soon the ZX-81 was replaced by a ZX Spectrum. I programmed a lot, wrote all kind of tools and a few demos. I always wanted to write a game together with my friends, but as teenagers we lacked the necessary persistence to bring such a project to the end. Then, on the day I got my Amiga 500, I quickly lost any interest in my good old Spectrum.

But it’s never too late... I just started a tiny little game project called Coredump, written in Z80 assembler for the good old ZX Spectrum. Why? Just because I can. Because I always wanted to. And because retro programming also means a lot of fun!

This first article is about the tool chain I am using. I will add more articles as the game grows and is (hopefully) completed some day.

Back in the 80’s, programming assembler on the ZX Spectrum was a very tedious task. I had to deal with cassette tapes (and their very slow access), an assembler that already consumed some of the scarce RAM, and I had no tools that simplified the development process. When I did a mistake and crashed the Spectrum, I needed to reload the assembler, the source code and the resources from tape. Often I also lost some of my work because when dealing with tapes, saving a source code is much more work than just pressing Ctrl-S, so I rather risked having to retype the changes after a crash.

Today it’s much easier to write retro software. I can develop it on my Linux machine, which is very fast and has a lot of storage space. I use a modern text editor and a lot of powerful tools. For testing, I just need to assemble a snapshot file and run it on an emulator, which takes less than a second. If the emulator crashes, no work is lost.

These are the tools I use for programming. All of them are available for Linux and MacOS, some also for Windows.

  • Fuse is an excellent ZX Spectrum emulator, with a very precise timing.
  • A decent editor. I started with Atom, but now I am using Eclipse because it fits better to my workflow. Just use your favorite editor.
  • zasm is a nice Z80 cross assembler that is also able to generate SNA files that run on the emulator.
  • Multipaint is an open source drawing tool that handles the limitations of the ZX Spectrum graphics (and believe me, there are limitations). It turned out not to be so useful for sprite and tile generation, because it does not offer a precise control of the paper and ink color that is used in the generated screen file.
  • So I also use Gimp for pixeling sprites and tiles. Maybe I will also use Inkscape later.
  • Tiled is an excellent map editor. I use it to design the world of my game.
  • Some self made helper tools convert the graphics and the world into the binary format that is used in the game. I use Java for these tools, just because I am most proficient with Java. There is no technical reason for that, just use the language you feel most comfortable with.
  • Finally, I use ant to stitch all the parts together and run the snapshot file.

The ZX Spectrum hardware is very simple and easy to understand (which also means that you have to do a lot of things without hardware aid). The Z80 processor has a simple instruction set. So retro programming is not just for the old-agers, but also for the young generation who is interested in a first approach to the hardware level of computers. It is also fun to get the most out of a limited and slow hardware.

There is a lot of documentation available in the net:

  • World of Spectrum has a lot of hardware documentation in the references section.
  • A quick overview of all Z80 instructions and their timings.
  • A commented ROM disassembly gives a first look at the Z80 assembler, and also offers some useful functions (like multiplication, the Z80 itself does not offer any multiply or divide instructions).

When I started looking for resources to the ZX Spectrum, I was surprised about how active the retro scene is. There are a lot of blogs offering tutorials that explain hardware tricks, and there is even a demo scene showing you things you’d never thought to be possible on that machine. After all, the Speccy is almost 35 years old now, and wasn’t famous for a powerful hardware even back at its time.

NetCologne VoIP einrichten

Seit Februar 2019 bin ich nicht mehr Kunde von NetCologne. Ich lasse den Artikel als Referenz hier stehen, weise aber darauf hin, dass er nicht mehr aktualisiert wird.

Vorab: Wenn möglich, sollte bei einer FritzBox bei den Internet-Zugangsdaten als Internetanbieter "weiterer Internetanbieter" – "NetCologne / NetAachen" ausgewählt werden. Die FritzBox holt sich dann alle Konfigurationsdaten vollautomatisch, inklusive der Konfiguration für die Telefonie. Falls euer Router diese Option nicht anbietet, findet ihr im folgenden Text vielleicht Hilfe.

Seit heute habe ich endlich VDSL, der ADSL-Anschluss mit Splitter und paralleler ISDN-Telefonie gehört damit endgültig der Vergangenheit an.

Leider war die Einrichtung von NetCologne-SIP auf meiner eigenen FritzBox alles andere als einfach, da ich nirgendwo im Internet brauchbare Informationen fand. Nach einigem Experimentieren hat es aber doch geklappt.

Auf der NetCologne-Einstellungsseite kann man sich ein SIP-Passwort generieren lassen und auch gleich die Login-Daten abholen. Das Generieren des Passworts dauert einen Augenblick, also Geduld. Wenn man mehrmals klickt, kann es sein, dass das angezeigte Passwort nicht das Richtige ist. Wenn man mehrere Rufnummern hat, braucht man für jede ein eigenes Passwort.

Für die fiktive Telefonnummer 0221-123456 erzeugt man dann auf der FritzBox eine neue Rufnummer mit folgenden Parametern:

Telefonie-Anbieter:Anderer Anbieter
Rufnummer für die Anmeldung:123456← Die Rufnummer ohne Vorwahl
Interne Rufnummer:123456← Ebenfalls nur die Rufnummer ohne Vorwahl
Benutzername:221123456← SIP-Username wie auf der Einstellungsseite
Kennwort:●●●●●●●●← Das SIP-Passwort von der Einstellungsseite
Registrar:sip.netcologne.de← SIP-Server von der Einstellungsseite
Proxy-Server:sip.netcologne.de← SIP-Server von der Einstellungsseite
STUN-Server:← Leer lassen

Die anderen Parameter lässt man am besten einfach, wie sie sind. Bei mir waren sie nach der automatischen Konfiguration wie folgt:

DTMF-ÜbertragungRTP oder Inband
Rufnummerunterdrückung:CLIR über *31
Rufnummerübermittlung:Deaktiviert← Rufnummer wird trotzdem übermittelt
Rufnummer für die Anmeldung verwenden:← kein Häkchen
Anbieter unterstützt Rückruf bei Besetzt:← kein Häkchen
Paketgröße in Millisekunden:20
Anmeldung immer über eine Internetverbindung:← kein Häkchen
Der Anbieter unterstützt MWI:← kein Häkchen
Der Anbieter unterstützt kein REGISTER-fetch:← Häkchen gesetzt
Anbieter kontaktieren über:nur via IPv4

Bei dem VDSL-Bitstream-Anschluss muss außerdem die VLAN-ID für Internettelefonie auf 7 eingestellt werden. Bei einem VDSL-Anschluss (ohne Bitstream) ist die VLAN-ID für Telefonie offenbar 10 (das kann ich bei mir aber nicht ausprobieren). Welche Anschlussart man hat, steht im Schreiben, das man von NetCologne bekommen hat.

Bei mir hat das so funktioniert. Aber die Werte wurden experimentell ermittelt. Im Zweifelsfall sollte man die NetCologne-Hotline anrufen (wie auch immer man das mit einem nicht funktionierenden Telefonanschluss schaffen möchte).


Nachtrag, 22.08.2017: Für den SIP-Server sollte sip.netcologne.de (oder was bei dir auf der Netcologne-Einstellungsseite steht) verwendet werden. Vorher stand hier im Artikel eine feste IP-Adresse, die aber anscheinend nicht mehr aktuell ist. Danke an Ralph für den Stuppser in die richtige Richtung.


Nachtrag, 12.11.2018: Durch eine Neukonfiguration meiner FritzBox wurden die Telefoniedaten automatisch von NetCologne bezogen. Ich habe die Angaben entsprechend zu dem geändert, was ich danach in meiner FritzBox vorfand.

Alter USB-Scanner mag keinen Strom sparen

Wieder einmal hatte ich Probleme mit meinem altgedienten Canon LiDE 20-Scanner. Diesmal wurde er zwar per USB erkannt, aber wenn ich etwas scannen wollte, erhielt ich nur Fehlermeldungen oder schwarze Seiten.

Der Grund liegt in den USB-Stromsparmaßnahmen moderner Linux-Kernel. Alte USB-Geräte haben ihre Probleme damit, einfach zwischendurch den Saft abgedreht zu bekommen.

Zum Glück kann man es bei Fedora leicht ausschalten:

echo -1 >/sys/module/usbcore/parameters/autosuspend

Der USB auto suspend ist dann für alle USB-Geräte abgeschaltet, die von jetzt an angeschlossen werden, also sollte man seinen Scanner erst danach einstecken. Beim nächsten Reboot ist der Effekt auch schon wieder vorbei.

Stream trouble

I just had a stream of objects I wanted to sort and convert to a list. Optionally it should also be limited to a maximum number of entries. Piece of cake with Java 8:

Stream<T> stream = collection.stream().sorted(comparator);
if (max >= 0) {
  stream.limit(max);
}
List<T> result = stream.collect(Collectors.toList());

Or so I thought... The code above throws an IllegalStateException at runtime, stating that the "stream has already been operated upon or closed".

The cause should be obvious. However it took me a while to find it, so I am posting it in case other people (possibly you when you came here via search engine) get stuck at the same place. Stream operations are very likely to return a different Stream object. The limit() method is such an example. In my code above, limit() operates on the stream and returns a limited stream. However I just throw away the returned stream and invoke collect() on the original stream, which was now already operated upon.

The solution is simple:

if (max >= 0) {
  stream = stream.limit(max);
}
Setting up TP-Link TL-SG108E with Linux

UPDATE: It seems that starting with hardware version 2, these switches have an actual web interface. Too sad my ones are version 1. 😢

Frankly, I didn't expect it and I was somewhat disappointed when I found out that the TP-Link TL-SG108E Easy Smart Switch (and its little brother TL-SG105E) cannot be configured via web browser. And I was even more disappointed when I found out that, even though Linux and MacOS were listed on the retail box, the configuration tool Easy Smart Configuration Utility runs on Windows only. And they mean it! When started in a Windows VM, the utility does not see any switches.

So the devices are rather cheap for a smart switch, but they still come with a price: no web interface.

However, thanks to some help in the interwebs, I was finally able to run the Configuration Utility on Fedora Linux. It's not that easy, though.

Continue reading...