peter nitsch.net

peternitsch.net

Textmode view for Alchemy (SDL/PDcurses)

Alchemy Textmode
Alchemy Textmode
Roguelike demo
Space Invaders demo

I’ve been talking about adding a textmode view to Alchemy for quite a while. In fact, it was the single reason I started playing with the technology in the first place. After seeing Flashterm, Scott Petersen (the lead engineer behind Alchemy) challenged me to port the classic NetHack, a roguelike text game. Since that time, I’ve played with text convertors, particles systems, and 3D graphics, but never managed to get a reasonable result for textmode – until now, that is.

The project has always been at the back of my mind, but it wasn’t until I saw Joseph Larson’s ASCIIpOrtal video, that I resolved to take another stab at it. Incidently, Joe runs a great site that has a collection of C/C++ text games that I could test against.

Adding a textmode view to Alchemy means interpreting curses, the terminal control C library for Unix-like systems, with its typical header being curses.h. There are textmode libraries for DOS and other operating systems, but curses and its cousins (ncurses, pcurses, PDcurses, etc) are the most popular. This was my starting point.

Of course porting curses is not straight forward since visually displaying text glyphs is machine specific. Fortunately I wrote AS3ANSI, an AS3 textmode interpreter which was used for Flashterm. So naturally my first approach was to write proxy C functions that send commands (e.g move cursor left 3) back to AS3ANSI to visually display. I used a simple game by Ido Yehieli called Crypt Rove for testing and here’s the result:

Alchemy Textmode
Check out Crypt Rover

It worked, but the game only used the most basic curses commands and establishing a standard would involve flushing out many more curses functions, some of which are very challenging. This approach also has a major problem with speed since every function is marshaled to AS3, but we’re dealing with textmode so it was only slightly noticeable.

After seeing this demo, Joe made a great comment, “Why reinvent the wheel? Just use PDcurses.” I was still realitively unfamiliar with PDcurses (short for Public Domain Curses), but did know that it had a SDL extension. Luckily, Ed McManus had already coded a basic port of SDL to Alchemy, so using his code as the visualizer, it just took a bit of work to attach PDcurses and I got my first ‘Hello world’. I used Jakub Wasilewskis’ roguelike game AJTH for a proper demo:

Alchemy Textmode
Check out AJTH

Awesome! With this working demo, I knew I had finally achieved a solution that requires minimal modification of native textmode programs. I wanted to try a more complicated game, so I decided to try Ascii Invaders by Thomas Munro. I love the result:

Alchemy Textmode
Check out Ascii Invaders

This is just the beginning. NetHack still hasn’t been ported and I have my eyes fixed on OpenCP, but with the foundation laid, I expect to have them working soon. The source will be released once I figure out how I want it organized. It may come as a fork to Ed’s SDL work.

Category: AS3 ANSI, Alchemy, Flash

Tagged: , , , , , ,

3 Responses

  1. Matt H says:

    Reminds me of the good ol’ QBASIC days…

  2. dVyper says:

    I almost exploded when I saw that ASCII portal video! Your ASCII games are great too :)

  3. Dominic says:

    reminds me of termcaps =)

Leave a Reply