Showing posts with label G3 iBook. Show all posts
Showing posts with label G3 iBook. Show all posts

Tuesday, 15 May 2012

More Xubuntu-based Emulation: xz81

My experience with getting a ZX Spectrum emulator to run on my iBook 600 led me to wonder how easy it would be to get a ZX81 emulator to run. The tricky part was finding a suitable X11-based emulator. There wasn't an obvious port like FUSE or Xspectemu, but after a while I found one, the z81 emulator by Russell Marks.

This emulator can be compiled for svgalib or plain X11, which is the version I chose. It's easy to compile, you just unpack it and type: make xz81 then sudo make install xz81 . You also need to download a ZX81 ROM - I used the Shoulders of Giants ROM.

xz81 was only about 300Kb unpacked and 100Kb of that was a directory of ZX81 games. It compiled in about 1 minute on my iBook. What I'm most impressed by is the fact that not only didn't I require the involved .configure step, but that the compile was so quick and it worked despite it being last updated about 7 years ago. XZ81 is really quite nice and quirky:

  quirky mostly because the keyboard help screen is rendered as a ZX81 bitmapped image and the file-selector option is managed as a ZX81 program (though it's really written in C as part of the emulator).

xz81 is pretty crude though - it needs to be recompiled to run in a different scale (the normal scale is 2x) and although it supports some typical ZX81 hardware (like the printer, by producing .pbm files)
It doesn't support proper high-resolution ZX81 graphics, so some programs don't work so well.

Since I'd had a comment from a previous user about a ZX81 Forth ROM I thought I'd try it, but the h4th.rom is quite hard to track down and in the process I found an alternative, a recently written (2011) ZX81 version of Forth called Toddy Forth.

It's also quite nice and simple, though as standard it doesn't include ZX81 features, such as INKEY, PLOT or AT. It's based on Camel Forth and since it's a DTC Forth it's actually pretty fast. I benchmarked it using the same benchmarks I used for FIGnition:

 Benchmark
 Jupiter-Ace (fast mode)
 Toddy Forth (slow mode)
 FIGnition  Ratio  FIGnition KIPS
 BM1  0.16  0.21  0.02  8  50
 BM2  0.54  0.54  0.088  6.14  56.82
 BM3  7.66  7.87  0.41  18.5  36.23
 BM4  6.46  7.94  0.47  13.69  31.78
 BM5  6.52  8.22  0.51  12.78  33.33
 BM6  7.38  9.78  0.64  11.53  39.06
 BM7  12.98  15.12  1.27 10.22  25.98
 BM3L  1.0  1.58  0.05  20  200
Mean Ratio (ZX81:Ace) 0.82  Mean 12.61


 (w/o BM3L)  11.55

 Although Toddy Forth in slow mode is merely 82% of the speed of the Jupiter Ace we must remember that in ZX81 slow mode, the computer spends about 75% of its time just generating a display: in fast mode the ZX81 should be about 3 or 4 times faster; easily beating the Jupiter Ace.

Toddy Forth's download includes some extra definitions in a library. I added its plot command so that I could time plot operations.

 Benchmark
 Jupiter-Ace (fast mode)
 Toddy Forth (slow mode)
 ZX81/Ace Ratio  FIGnition  Ratio  FIGnition KIPS
 Plot Full Screen  3.02 (2816 pixels)  4.66 (3072 pixels)  0.65  0.10 (2400 pixels)  29.61  94.1

Here, Toddy Forth is significantly slower, though not outrageously so.

Here are the benchmarks themselves (in Toddy Forth):

: bm1
  cr ." S"
  1000 0 do loop
  ." E" ;

: bm2
  cr ." S"
  0 begin
    1+ dup 999 >
  until
  ." E" drop ;



: bm3
  cr ." S"
  0 begin
    1+ dup dup / over
    * over + over -
    drop dup 999 >
  until ." E"
  drop ;
 : bm4
  cr ." S"
  0 begin
    1+ dup 2 / 3
    * 4 + 5 - drop dup
  999 > until
  ." E" drop ;

: bm5sub ;
: bm5
  cr ." S" 0 begin
    1+ dup 2 / 3
    * 4 + 5 - drop bm5sub
  dup 999 > until
  ." E" drop ;


 : bm6
  cr ." S" 0 begin
   1+ dup 2 / 3 * 4 + 5 -
   drop bm5sub
   5 0 do loop
  dup 999 > until
  ." E" drop ;

: array
  create 2 * allot
  does> over + + ;

5 array m

: bm7
  cr ." S" 0 begin
   1+ dup 2 / 3 * 4 + 5 -
   drop bm5sub
   5 0 do dup i m ! loop
  dup 999 > until
  ." E" drop ;
 : bm3l 0 10000 0 do i +
  minus i and i or i xor
  loop drop ;


 : bm1g
  48 0 do i
    50 0 do
      i over 3 plot
    loop drop
  loop
;



16436 constant clock

: time-bm
  find
  clock @ swap execute
  clock @ swap - . ;



Tuesday, 8 May 2012

Should Have Gone To Xspect Savers!

I'm an old-time ZX Spectrum owner from 1982 and since it was the machine's 30th birthday just last week I figured it's mandatory to run an emulator on every Mac of mine, including my cranky, old, 600MHz Xubuntu-running G3 iBook. I had no idea how much effort would be involved!

For lots of more modern systems it's just pretty easy to install FUSE, the Free Unix Spectrum Emulator; but it's not readily available as a package for my iBook, so I had to recompile it, and when I did: for the SDL library and then just for plain X I found it would crash with an 'illegal instruction' message before doing anything.

My overall impression of compiling FUSE though was of the immensity of the work involved, and the size of the code, the download expands to 10.3Mb and then I needed SDL at a whopping 29.8Mb - you can't get much more simple than that eh!?

And of course, in the end it didn't work.

However, I managed to find an alternative: Spectemu-X11, which wonderfully I could download as a package for my machine. Unfortunately, that too didn't quite work - on my iBook I found that I couldn't generate a Symbol Shift since the keyboard didn't support the Right-Shift key-code. So, then I downloaded the source (which when expanded and compiled uses 1.7Mb, almost small!) plus the diff for the 0.94a-9 version; and then had to learn how to apply the diff to a folder: place the diff file in the root directory of the package (in my case just inside my spectemu-0.94 folder) and then type patch -p1 < theNameOfThePatchFile.diff 

And it did it!

Then I compiled SpectEmu, which it duly did and left me with the same problem, no Symbol Shift. So I did some tracking on why that's the case. It's entirely due to the key codes defined in spkey_p.h. The definition for Symbol Shift is derived from SK_Shift_R which is:

#define SK_Shift_R        0xFFE2    /* Right shift */

With a bit of debugging I found out that the command key on my Mac generated 0xFFEB, so all I had to do was replace the above line with:

#define SK_Shift_R        0xFFEB    /* Right shift */

touch all the files that #include spkey_p.h and then make it again. Easy, and now I have a Spectrum Emulator on my lowly (but lovely) iBook!

Next, back to working on my own project, the FIGnition DIY 8-bit computer!