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 :)

3 comments:

  1. $ uname -a
    Minix lyoko.lan 3.2.0 i686
    $ make
    clang -O -o wopr wopr.c
    $ ./wargames.sh















    LOGON: 000001

    IDENTIFICATION NOT RECOGNIZED BY SYSTEM
    --CONNECTION TERMINATED--

    $
    It works on Minix 3.

    ReplyDelete
    Replies
    1. Excellent - many thanks! Its also in pkgsrc which means anyone running binary package builds for Minix will get it automatically :-p

      Delete
    2. Just for fun:
      Administrator@XAVIA ~/wargames $ uname -a
      Interix XAVIA 6.0 10.0.6030.0 x86 Intel_x86_Family15_Model2_Stepping7
      Administrator@XAVIA ~/wargames $ uname -X

      System = Interix
      Node = XAVIA
      Release = 6.0
      Version = 10.0.6030.0
      Machine = x86
      Processor = Intel_x86_Family15_Model2_Stepping7
      HostSystem = Windows
      HostRelease = 6.0
      HostVersion = SP2
      Administrator@XAVIA ~/wargames $ gcc -O -o wopr wopr.c
      Administrator@XAVIA ~/wargames $ file wopr
      wopr: Windows NT PE format (EXE), dynamically linked executable not stripped Intel Posix-CUI
      Administrator@XAVIA ~/wargames $ ./wargames.sh




      LOGON: 000001

      IDENTIFICATION NOT RECOGNIZED BY SYSTEM
      --CONNECTION TERMINATED--

      Administrator@XAVIA ~/wargames $

      It also works on Interix/SFU aka Windows under the POSIX subsystem.

      Delete