Showing posts with label wargames. Show all posts
Showing posts with label wargames. Show all posts

Monday, 16 July 2012

wargames meets Linux (and Dreamcast VGA)


When I wrote a small script to simulate the W.O.P.R. computer from wargames, little did I expect it to help me learn some new things about Linux (specifically Fedora in this case).

One criticism often cast towards people writing software on Linux is that they only write it for Linux, not caring about basic portability to other systems. Sometimes there has obviously been a pass to make it run on OS/X also, though earlier versions of XBMC were my go-to case for "portability" code which only cthulhu could love (So, if #ifdef _LINUX and #ifdef APPLE then... no, wait, what?)

Anyway, My Little Pony-I-mean-Wargames script was written on NetBSD, for my own use, but not intentionally using any NetBSD specific features.

Since I had the temerity to host it on github, of course someone is going to come along and try to build it on their $OS_of_choice, in this case Fedora.

So, lets count my portability fails
  1. I used "tput up" to move the cursor up, rather than "tput cuu1" (both work on NetBSD). To be fair "cuu1" does sound more like something a standards committee would define, probably short hand for "CursorUnproportionablyUpOneLineOnly"
  2. I used "{.TARGET}" and "${.ALLSRC}" in the Makefile. Gmake does not support these, which is interestingly as I thought the gmake project mission statement was to make bash look like a lean, minimally functional application. Still, easy enough to hardcode the values & we're portable
  3. I include a getopt(3) using program for outputting text called wopr, which at one point was called as 'wopr "IDENTIFICATION NOT RECOGNIZED BY SYSTEM" "--CONNECTION TERMINATED--" ""'. Traditional getopt() usage has option parsing stop when the first non '-' prefixed argument is reached. Linux is more... helpful... in this respect and happily picks up options from anywhere in the arguments... and quite possibly from the environment and your dotfiles. Wait... (check online), No, apparently I only *thought* I was kidding:
ENVIRONMENT VARIABLES
_<PID>_GNU_nonoption_argv_flags_
This variable was used by bash 2.0 to communicate to GNU libc which arguments are the results of wildcard expansion and so should not be considered as options. This behaviour was removed in bash version 2.01, but the support remains in GNU libc.
 So, now wargames now runs on Linux. Anyone with a Solaris/Illuminos machine want to take a pass? :)

(I'd like to thank the person on github who took the time to try wargames, and then fix it up to run on Fedora, and who should not take anything of the above as ingratitude :)

... meanwhile, on planet Dreamcast

In an earlier posting I may have commented on the quality of the construction of a newly acquired Dreamcast SD+VGA adaptor in a fashion which might have been construed as potentially disparaging. I am now delighted to revise that previous comment and to be able to state positively that indeed, it is a bit sh*t. By repeatedly pressing the plug into the back of the Dreamcast, and - god help me yes - by tilting to engage the assistance of gravity, I now have a clear and fully usable display. As before, walking heavily, sneezing, or careless placing of coffee cups near the machine is strictly prohibited.

I appear to be getting carried away in mentioning previous postings, in this case why gxemul was not able to mount the CD as a root filesystem while booted. I am lightly disappointed to say it does not appear to be some boneheaded mistake in my script as the CD image runs fine on real hardware, so if I want to use gxemul to test root-on-cd9660 Dreamcast image I'm going to have to poke into the gxemul source. Definitely still retrochallenge 2012 material, though only just :)

Saturday, 7 July 2012

Wargames for the masses

Yesterday for Retrochallenge 2012 I wrote a little shell script to simulate the interaction with the WOPR computer in wargames. (Connect link)

It was quite incomplete, and bodged into the telnet port on the VAXstation, so tonight I polished it a little, and then a little more, adjusted the output timings, made it very generous when accepting input (so you could type "fine", rather than "I'm fine. How are you"), and finally made it go back and rewrite what the user typed in such cases to match the film.

Finally I got over-enthusiastic and put it up on github and added an entry to pkgsrc.

Notice, at no point in this process did I ask myself "why?".

Along the way I found out how easy it was to setup telnetd to automatically run a program instead of asking for login, and found a java telnet app to add to wopr's home page to make it easier for random web users to connect to the script. I also tweaked the font colour and style to better match that in the film.

Its this attention to pointless detail that is probably quite worrying.

Its like building a perfect matchstick model of a chair with a broken leg, who's only purpose is to be put on a bonfire.

Learning how to setup telnetd to autorun a program instead of login would be potentially useful... if it was 1992 and anyone still had any use for telnet.
(for reference just set the telnetd arguments in inetd.conf to "-g foo -a off -h" and in gettytab copy default to foo and replace the im= with lo=/path/to/app).

Still, after dropping into an email thread on the simh list I've submitted a request to pullup a commit from Matt Thomas' so simh will be able to detect when a NetBSD-6 vax guest is idle and save CPU cycles.

So... looked at it from the right perspective, that will reduce energy use and carbon emissions, so in a tiny way I just may have done something today which will help save the planet! ... or mabye not.


Friday, 6 July 2012

The only winning move is...

Taking a break from a playing directly with retro-hardware, last night I watched wargames and took a few notes on the interaction with the WOPR computer.

The result, lovingly crafted into a simple shell script was connected up to the telnet port in inetd whereupon three issues immediately sprung up
  1. Since there is no local telnetd, the script gets to see the initial IAC command codes (called for a little sed hackery)
  2. Calling 'system("sleep 0.1") from awk on an amd64 box sleeps for about 1/10 of a second. On a VAX... its more like 1/5 a second with overhead. Cue writing a small C program to handle outputting the text
  3. I'm pretty sure TCP Nagle is kicking in and making the output blocky, but its late & I'll come back to that
Anyway - the result should be visible by "telnet wopr.absd.org" (If your client tries SRA login you may need "telnet -K wopr.absd.org"). It turns out there was quite a lot of interaction with WOPR in the film. I suspect I have about 60-75% of it complete (mainly towards the start), and I've tried to be relatively generous in what it accepts (checking for a matching key word rather than an entire sentence).

So, how much do you remember from Lightman's typed conversations with WOPR? telnet to wopr.absd.org and test your memory :)

(In other news I upgraded the Dreamcast to NetBSD-6, which went fine apart from the fact I'd forgotten the kernel had been set to prompt for a root device, which meant my decision to run a final reboot *after* leaving the office was... unhelpful)