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 - . ;



No comments: