ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sat Oct 31, 2020 6:22 am

lurk101 wrote:
Sat Oct 31, 2020 3:50 am
Fugaku - 158,976 nodes - 16.78 GFLOPs per kilowatt at double precision.
Summit - 4,608 nodes - 15.77 GFLOPs per kilowatt at double precision.

Don't see that inherent advantage attributable to ARM's scalable vector extension.

This reference actually shows lower power efficiency for Fugaku. Figures vary.
As problem sizes increase, the operation count in Gaussian elimination with partial pivoting scales as O(n^3) while the storage requirements scale as only O(n^2). This makes the Linpack benchmark behave differently than many common tasks in which the computational work scales almost linearly with the storage needed (subject to a logarithmic correction). In particular, as problems sizes get larger, the Flops rating on the TOP500 becomes less and less relevant for predicting actual performance on many problems of scientific interest. Be that as it is, it would appear you have written kilowatt when you meant watt.

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Birthday Present for Fido

Sat Oct 31, 2020 6:53 am

lurk101 wrote:
Sat Oct 31, 2020 12:58 am
Heater wrote:
Fri Oct 30, 2020 9:23 pm
No doubt the 68000 used more gates. Of course, it did the 16/32 bit job properly. And had great success in graphical workstations running Unix as a result.
My SparcStation was far more powerful than my 68000 based HP workstation. The HP station was a dog (no offense intended Fido). It's a pity that Sun screwed up in so many other ways, but I digress.
I'm not sure what point we are debating anymore. I was making comparisons between Intel 8086, Motorola 6800 and other contemporaneous 16/32 bit devices. You have brought up the Sparc which did not arrive until ten years later in 1989. The Sparc was not even a chip one could buy.

A decade it is a long time in micro-processor design, especially in that decade. A lot was learned about how to do it. There was the realization that RISC might be a good idea and so on. Not only that Moore's Law provided that processor designers had 8 to 16 times more transistors to make use of by then.

I know nothing about super computer design but I have read repeatedly over the years that power consumption is a major concern. Basically a show stopper for further scaling up. No surprise those guys are looking into solutions other than Intel.

Edit: That reminds me. I have two unused Motorola 68000 chips in a draw that have been waiting to be built into a computer for years. Today I find Matthew Sarnoff recently published a nice simple SBC design for the 68000 https://github.com/74hc595/68k-nano
Memory in C++ is a leaky abstraction .

lurk101
Posts: 1066
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Birthday Present for Fido

Sat Oct 31, 2020 4:27 pm

Heater wrote:
Sat Oct 31, 2020 6:53 am
I'm not sure what point we are debating anymore.
Yes, I apologize. Earlier comments triggered my baloney detector, and I reacted damn it!

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Birthday Present for Fido

Sat Oct 31, 2020 4:36 pm

Ha! No worries.

It's probably better to have a baloney detector that is over sensitive than under.
Memory in C++ is a leaky abstraction .

lurk101
Posts: 1066
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Birthday Present for Fido

Sat Oct 31, 2020 4:41 pm

Heater wrote:
Sat Oct 31, 2020 6:53 am
Today I find Matthew Sarnoff recently published a nice simple SBC design for the 68000 https://github.com/74hc595/68k-nano
Very cool. I was surprised that you can still purchase a 68000 DIP. I'm not enamored with ARM mono-culture and this encourages diversity.

ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sat Oct 31, 2020 5:00 pm

The Sun 3 was based on the 68xxx processor as were earlier models. I remember being surprised by how slowly the bitmapped console scrolled when used as a text-mode terminal without the GUI. I think I wrote code that way more often than with the GUI running. I recall that the letters were nice and big and the screen sharp.
Heater wrote:
Sat Oct 31, 2020 6:53 am
That reminds me. I have two unused Motorola 68000 chips in a draw that have been waiting to be built into a computer for years. Today I find Matthew Sarnoff recently published a nice simple SBC design for the 68000 https://github.com/74hc595/68k-nano
Since you have two 68000 chips in the drawer it seems you will need a dual CPU design. Fortunately the coming corona-closures and travel restrictions should allow sufficient time over the holidays for that and more.

Back in the present world of history making 32-bit computers, I'm having trouble getting recent versions of VICE running on 32-bit Raspberry Pi OS. It seems the code which governs the speed of the screen refresh is broken--maybe a 32-bit overflow--and starts trying to refresh at thousands of frames per second rather than the expected 50 or 60.

I'll be trying the latest 64-bit beta test soon. It's too bad the binary Gentoo release will no longer be maintained.

viewtopic.php?p=1750206#p1750206
Last edited by ejolson on Sat Oct 31, 2020 5:10 pm, edited 1 time in total.

lurk101
Posts: 1066
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Birthday Present for Fido

Sat Oct 31, 2020 5:07 pm

ejolson wrote:
Sat Oct 31, 2020 5:00 pm
I'll be trying the latest 64-bit beta test soon.
Not sure why it's still in beta. It's been solid for my applications and I suspect it might also be for yours.

ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sat Oct 31, 2020 5:14 pm

lurk101 wrote:
Sat Oct 31, 2020 5:07 pm
ejolson wrote:
Sat Oct 31, 2020 5:00 pm
I'll be trying the latest 64-bit beta test soon.
Not sure why it's still in beta. It's been solid for my applications and I suspect it might also be for yours.
I think it's in beta because it's not yet ready for use in schools.

I'll agree that 64-bit seems stable. I hope it solves the problem with the SuperPET emulator so Fido's birthday present doesn't get delayed. It seems strange one might need a full 64-bit OS to emulate an 8-bit processor.

ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sat Oct 31, 2020 7:08 pm

Heater wrote:
Sat Oct 31, 2020 6:53 am
lurk101 wrote:
Sat Oct 31, 2020 12:58 am
Heater wrote:
Fri Oct 30, 2020 9:23 pm
No doubt the 68000 used more gates. Of course, it did the 16/32 bit job properly. And had great success in graphical workstations running Unix as a result.
My SparcStation was far more powerful than my 68000 based HP workstation. The HP station was a dog (no offense intended Fido). It's a pity that Sun screwed up in so many other ways, but I digress.
I'm not sure what point we are debating anymore. I was making comparisons between Intel 8086, Motorola 6800 and other contemporaneous 16/32 bit devices. You have brought up the Sparc which did not arrive until ten years later in 1989.
For a bit of local history, the Sage II

Image
http://www.sageandstride.org/

was the fastest 68000 based system in the world until the Sage IV. Before the BARK™ Consortium, that was the first and only computer manufacturer that existed here on the liberal frontier.

Now that modern systems include device memory, persistent memory and network memory, the patented three-level tiered segments of the BARK™ with composable MEOW™ attachment can be used to map the available address space in a natural way. In my opinion, the licensing opportunities may be lucrative enough to provide the dog developer a lifetime supply of baloney.

ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sat Oct 31, 2020 8:48 pm

ejolson wrote:
Sat Oct 31, 2020 5:14 pm
lurk101 wrote:
Sat Oct 31, 2020 5:07 pm
ejolson wrote:
Sat Oct 31, 2020 5:00 pm
I'll be trying the latest 64-bit beta test soon.
Not sure why it's still in beta. It's been solid for my applications and I suspect it might also be for yours.
I think it's in beta because it's not yet ready for use in schools.

I'll agree that 64-bit seems stable. I hope it solves the problem with the SuperPET emulator so Fido's birthday present doesn't get delayed. It seems strange one might need a full 64-bit OS to emulate an 8-bit processor.
Woohoo! I've just launched a fresh 64-bit instance on the Pi cloud

viewtopic.php?f=36&t=279176

using the lite August 24 image downloaded from

https://downloads.raspberrypi.org/raspi ... 64/images/

That seems to be the latest version, so maybe the reason this hasn't moved out of beta test is that there are no new releases. At any rate, the idea is to install xorgxrdp and set it to immediately launch an emulated SuperPET when Fido connects through remote desktop from a Windows computer. That way there isn't much that can go wrong when the real super pet logs in.

One could also use RealVNC, except I'm not sure that's available on the 64-bit beta test of Raspberry Pi OS. Another advantage in using remote desktop is that no additional software needs to be installed on Windows.
Last edited by ejolson on Sat Oct 31, 2020 10:58 pm, edited 1 time in total.

User avatar
rpdom
Posts: 19283
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: A Birthday Present for Fido

Sat Oct 31, 2020 9:01 pm

The only 68000 series machine I've "owned" was a custom built Bull DPX2/300 system with a 33MHz 68040 CPU and 240MB of RAM. I salvaged it from some kit at work that was being dumped due to Y2K things.

It was my first personal Unix system and I managed to build a web server for it (can't remember the name, but it evolved into Apache later). I had to patch it a bit to get it working and it didn't support threading.
Unreadable squiggle

Heater
Posts: 18758
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Birthday Present for Fido

Sat Oct 31, 2020 9:36 pm

Luckily I find that those few hardy Motorola 68000 supporters that are still around saved the 68000 back end from being dropped from GCC last year. https://www.phoronix.com/scan.php?page= ... 8k-Is-Safe

So if I ever get my 68000 chips into a working machine I have some chance of getting them to do something interesting!

Sadly they have not had so much success with clang, yet...
https://www.phoronix.com/scan.php?page= ... eries-2020

Although there is an LLVM for 68000: https://github.com/M680x0/M680x0-llvm

Somebody was even working on Rust for the 68000: https://lists.debian.org/debian-68k/201 ... 00003.html How cool would that be?!
Memory in C++ is a leaky abstraction .

ejolson
Posts: 8628
Joined: Tue Mar 18, 2014 11:47 am

Re: A Birthday Present for Fido

Sun Nov 01, 2020 3:48 am

ejolson wrote:
Sat Oct 31, 2020 8:48 pm
Another advantage in using remote desktop is that no additional software needs to be installed on Windows.
While this thread is entitled A Birthday Present for Fido, other suitable titles might be
  • 32-bit Arithmetic with 16-bit Integers
  • The Battle of Waterloo Basic
  • The Dodecahedron Detector
  • A SuperPET for the Super Pet
  • An Excuse to Talk about Motorola CPUs
On a personal note, my wife used to work for Motorola. Yes, it was the semiconductor division. Just like Apollo, Cray, Data General, DEC, Sun, and maybe soon IBM, the last assets of Motorola were acquired, split or sold long ago. It looks like the rights to use the Motorola brand name--as with Nokia--has been licensed in order to sell cheaply made phones and other electronics.

https://www.motorola.com/

I actually bought a Moto Play after dropping my Nexus on a granite floor. It would have been a good phone, except the GPS never worked well enough for Pokemon Go. Then it caught a virus.

At any rate, since it appears recent Raspberry Pi kernels are no longer gzip compressed, some changes were needed to the Pi-cloud provisioning script which recreates the initial RAM file system before I was able to perform the commands

Code: Select all

# apt update; apt dist-upgrade
# adduser ejolson
# sync
# sync
# sync
# reboot
and update the non-virtualized Pi 4B to the latest kernel.

Code: Select all

$ uname -a
Linux m4 5.4.72-v8+ #1356 SMP PREEMPT Thu Oct 22 13:58:52 BST 2020 aarch64 GNU/Linux
After this, installing xrdp and xorgxrdp from source was easy.

I'll describe what I did for reference and in case anyone wants to follow along exactly. Note the rest of this post is not specific to SuperPET emulation and should work on any Raspberry Pi, even one running in 32-bit mode or a Zero.

Get the code.

Code: Select all

$ mkdir work
$ cd work
$ wget https://github.com/neutrinolabs/xrdp/releases/download/v0.9.14/xrdp-0.9.14.tar.gz
$ tar zxf xrdp-0.9.14.tar.gz
$ wget https://github.com/neutrinolabs/xorgxrdp/releases/download/v0.2.14/xorgxrdp-0.2.14.tar.gz
$ tar zxf xorgxrdp-0.2.14.tar.gz
First build the xrdp front end.

Code: Select all

$ cd xrdp-0.9.14
Comment out the -Werror flag in configure.ac so the relevant part of the file looks like

Code: Select all

# bsd has warnings that have not been fixed yet
#AM_COND_IF([LINUX],
#  [AX_APPEND_COMPILE_FLAGS([-Werror])]) 
as there is a warning in log.c generated by the system C compiler related to a particular use of snprintf that needs to be ignored.

Install the needed dependencies with

Code: Select all

# apt-get install libssl-dev libpam0g-dev libjpeg-dev libmp3lame-dev
# apt-get install libpixman-1-dev libx11-dev libxfixes-dev libxrandr-dev
# apt-get install autoconf
Switch to user mode to configure and build the system.

Code: Select all

$ ./configure --enable-jpeg --enable-mp3lame --enable-pixman
$ make -j4
Then as root type

Code: Select all

# make install
Now install the xorgxrdp back end.

There is a race in recent versions of xorgxrdp that causes screen repainting to sometime omit the foreground text. This happens particularly on ARM architecture machines due to lack of optimized SIMD assembler for detecting changes in the display. Fortunately, a patch is available at

https://github.com/neutrinolabs/xorgxrdp/issues/171

but it isn't part of the current release. Download the patch as xorgxrdp.patch and then apply it as

Code: Select all

$ cd /work/xorgxrdp-0.2.14
$ patch -p1 <../xorgxrdp.patch
patching file module/rdp.h
Hunk #1 succeeded at 325 (offset -4 lines).
patching file xrdpdev/xrdpdev.c
Before compiling install some more packages.

Code: Select all

# apt-get install xserver-xorg-dev yasm nasm
Note that I've included yasm and nasm out of wishful thinking in case they ever support ARM. Also note that xserver-xorg-dev pulls in a lot of other stuff--maybe more than actually needed--but to keep with the spirit of open source we follow the more is always better approach.

Configure and build by typing

Code: Select all

$ ./configure
$ make -j4
Finally, install the xorgxrdp driver with

Code: Select all

# make install
One also needs to install the xserver for this driver to work. It seems like a lot of dependencies to emulate an 8-bit microcomputer; however, I found no easy way to easily install fewer packages. Also install xterm for good luck as it's the default application that will be launched when there is no window manager.

Code: Select all

# apt-get install xserver-xorg-core xterm
Perhaps the most non-intuitive part of the installation is editing sesman.ini so it can find where the xserver binary was installed. The location has not been standardized on Linux and the defaults don't work with Raspberry Pi OS or Debian.

Change to the xrdp configuration directory with

Code: Select all

# cd /etc/xrdp
and then edit the Xorg section in sesman.ini so it reads as

Code: Select all

param=/usr/lib/xorg/Xorg
At this point it is tempting to customize the login screen with a picture of a SuperPET and to fix the amazing color scheme. Instead, let's test whether it's possible to log in.

Enable and start the xrdp and sesman services with

Code: Select all

# systemctl enable xrdp.service
# systemctl enable xrdp-sesman.service
# systemctl start xrdp.service
# systemctl start xrdp-sesman.service
If everything works, you should be able to connect using remote desktop from Windows and get the login screen.
    xrdplogin.png
    xrdplogin.png (18.23 KiB) Viewed 1822 times
      Upon logging in, the xserver will start by default with an xterm in it. Close the xterm to log out.
        xrdpxterm.png
        xrdpxterm.png (3.37 KiB) Viewed 1822 times
          The next post will describe installing VICE and configuring the SuperPET emulator to launch upon login instead of the xterm.

          lurk101
          Posts: 1066
          Joined: Mon Jan 27, 2020 2:35 pm
          Location: Cumming, GA (US)

          Re: A Birthday Present for Fido

          Sun Nov 01, 2020 5:49 pm

          ejolson wrote:
          Sun Nov 01, 2020 3:48 am
          - The Dodecahedron Detector
          Are we moving on from the Dodecahedron Detector? That one seemed like just a little too much to do just for fun.

          ejolson
          Posts: 8628
          Joined: Tue Mar 18, 2014 11:47 am

          Re: A Birthday Present for Fido

          Sun Nov 01, 2020 8:31 pm

          lurk101 wrote:
          Sun Nov 01, 2020 5:49 pm
          ejolson wrote:
          Sun Nov 01, 2020 3:48 am
          - The Dodecahedron Detector
          Are we moving on from the Dodecahedron Detector? That one seemed like just a little too much to do just for fun.
          As mentioned in

          viewtopic.php?p=1713521#p1713521

          it is lovely to play Hunt the Wumpus on the original dodecahedron envisioned by Gregory Yob. To this end, we now have a list of seeds that cause the graph generator written by Ken Thompson to randomly create dodecahedrons and another list for the new graph generator written in Pascal that appears in this thread. While a list of seeds for the graph generators written in Rust and 8th are still missing, Fido's birthday is pending!

          In fact, I just got a message on FidoNet from the dog developer about wanting the licensed rerelease of the C64 and VIC-20 which includes a functional full-sized keyboard.

          Image
          https://www.amazon.co.uk/Koch-Distribut ... 08BSMKXKV/

          I think the same hardware, except marked as a C64, will be available in the states later this month. It appears each can emulate either the C64 or the VIC20, but not the SuperPET. It is is not clear that any of the Commodore disk drives are emulated, but the presence of USB ports in place of the cartridge slot makes me think it might be compatible with a thumb drive.

          Does anyone know if there is a Raspberry Pi inside?

          More information is at

          https://popularretro.com/

          As the stakes on the birthday present have been upped by physical hardware, I decided I better fix the color scheme on the login screen to avoid birthday disappointment or spending any additional money. After finding a reasonable picture of a SuperPET, I used Gimp to crop the image to 468x210, converted it to indexed mode and then saved it as superpet.bmp in /usr/local/share/xrdp.

          Next I edited the xrdp.ini in the /etc/xrdp directory to change the layout as well as the color scheme. The entire file now reads as

          Code: Select all

          [Globals]
          ; xrdp.ini file version number
          ini_version=1
          
          ; fork a new process for each incoming connection
          fork=true
          
          ; ports to listen on, number alone means listen on all interfaces
          ; 0.0.0.0 or :: if ipv6 is configured
          ; space between multiple occurrences
          ;
          ; Examples:
          ;   port=3389
          ;   port=unix://./tmp/xrdp.socket
          ;   port=tcp://.:3389                           127.0.0.1:3389
          ;   port=tcp://:3389                            *:3389
          ;   port=tcp://<any ipv4 format addr>:3389      192.168.1.1:3389
          ;   port=tcp6://.:3389                          ::1:3389
          ;   port=tcp6://:3389                           *:3389
          ;   port=tcp6://{<any ipv6 format addr>}:3389   {FC00:0:0:0:0:0:0:1}:3389
          ;   port=vsock://<cid>:<port>
          port=3389
          
          ; 'port' above should be connected to with vsock instead of tcp
          ; use this only with number alone in port above
          ; prefer use vsock://<cid>:<port> above
          use_vsock=false
          
          ; regulate if the listening socket use socket option tcp_nodelay
          ; no buffering will be performed in the TCP stack
          tcp_nodelay=true
          
          ; regulate if the listening socket use socket option keepalive
          ; if the network connection disappear without close messages the connection will be closed
          tcp_keepalive=true
          
          ; set tcp send/recv buffer (for experts)
          #tcp_send_buffer_bytes=32768
          #tcp_recv_buffer_bytes=32768
          
          ; security layer can be 'tls', 'rdp' or 'negotiate'
          ; for client compatible layer
          security_layer=negotiate
          
          ; minimum security level allowed for client for classic RDP encryption
          ; use tls_ciphers to configure TLS encryption
          ; can be 'none', 'low', 'medium', 'high', 'fips'
          crypt_level=high
          
          ; X.509 certificate and private key
          ; openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365
          certificate=
          key_file=
          
          ; set SSL protocols
          ; can be comma separated list of 'SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'
          ssl_protocols=TLSv1.2, TLSv1.3
          ; set TLS cipher suites
          #tls_ciphers=HIGH
          
          ; Section name to use for automatic login if the client sends username
          ; and password. If empty, the domain name sent by the client is used.
          ; If empty and no domain name is given, the first suitable section in
          ; this file will be used.
          autorun=
          
          allow_channels=true
          allow_multimon=true
          bitmap_cache=true
          bitmap_compression=true
          bulk_compression=true
          #hidelogwindow=true
          max_bpp=32
          new_cursors=true
          ; fastpath - can be 'input', 'output', 'both', 'none'
          use_fastpath=both
          ; when true, userid/password *must* be passed on cmd line
          #require_credentials=true
          ; You can set the PAM error text in a gateway setup (MAX 256 chars)
          #pamerrortxt=change your password according to policy at http://url
          
          ;
          ; colors used by windows in RGB format
          ;
          blue=009cb5
          grey=dedede
          #black=000000
          #dark_grey=808080
          #blue=08246b
          #dark_blue=08246b
          #white=ffffff
          #red=ff0000
          #green=00ff00
          #background=626c72
          
          ;
          ; configure login screen
          ;
          
          ; Login Screen Window Title
          #ls_title=My Login Title
          
          ; top level window background color in RGB format
          ls_top_window_bg_color=3e3e3e
          
          ; width and height of login screen
          ls_width=480
          ls_height=360
          
          ; login screen background color in RGB format
          ;ls_bg_color=dedede
          
          ; optional background image filename (bmp format).
          #ls_background_image=
          
          ; logo
          ; full path to bmp-file or file in shared folder
          ls_logo_filename=/usr/local/share/xrdp/superpet.bmp
          ls_logo_x_pos=6
          ls_logo_y_pos=26
          
          ; for positioning labels such as username, password etc
          ;ls_label_x_pos=310
          ls_label_x_pos=26
          ls_label_width=65
          
          ; for positioning text and combo boxes next to above labels
          ls_input_x_pos=108
          ls_input_width=210
          
          ; y pos for first label and combo box
          ls_input_y_pos=260
          
          ; OK button
          ls_btn_ok_x_pos=350
          ls_btn_ok_y_pos=305
          ls_btn_ok_width=100
          ls_btn_ok_height=30
          
          ; Cancel button
          ls_btn_cancel_x_pos=350
          ls_btn_cancel_y_pos=260
          ls_btn_cancel_width=100
          ls_btn_cancel_height=30
          
          [Logging]
          LogFile=xrdp.log
          LogLevel=DEBUG
          EnableSyslog=true
          SyslogLevel=DEBUG
          ; LogLevel and SysLogLevel could by any of: core, error, warning, info or debug
          
          [Channels]
          ; Channel names not listed here will be blocked by XRDP.
          ; You can block any channel by setting its value to false.
          ; IMPORTANT! All channels are not supported in all use
          ; cases even if you set all values to true.
          ; You can override these settings on each session type
          ; These settings are only used if allow_channels=true
          rdpdr=true
          rdpsnd=true
          drdynvc=true
          cliprdr=true
          rail=true
          xrdpvr=true
          tcutils=true
          
          ; for debugging xrdp, in section xrdp1, change port=-1 to this:
          #port=/tmp/.xrdp/xrdp_display_10
          
          ; for debugging xrdp, add following line to section xrdp1
          #chansrvport=/tmp/.xrdp/xrdp_chansrv_socket_7210
          
          ;
          ; Session types
          ;
          
          ; Some session types such as Xorg, X11rdp and Xvnc start a display server.
          ; Startup command-line parameters for the display server are configured
          ; in sesman.ini. See and configure also sesman.ini.
          [Xorg]
          name=Xorg
          lib=libxup.so
          username=ask
          password=ask
          ip=127.0.0.1
          port=-1
          code=20
          
          This results in the login screen
            xrdplogin2.png
            xrdplogin2.png (65.94 KiB) Viewed 1693 times
              Hopefully that will make the real pet super happy.

              Heater
              Posts: 18758
              Joined: Tue Jul 17, 2012 3:02 pm

              Re: A Birthday Present for Fido

              Sun Nov 01, 2020 9:46 pm

              Oh man. I can get a C64. Four decades too late.

              Do you think it's to late for me now?
              Memory in C++ is a leaky abstraction .

              ejolson
              Posts: 8628
              Joined: Tue Mar 18, 2014 11:47 am

              Re: A Birthday Present for Fido

              Mon Nov 02, 2020 7:53 pm

              Heater wrote:
              Sun Nov 01, 2020 9:46 pm
              Oh man. I can get a C64. Four decades too late.

              Do you think it's to late for me now?
              It's a very tempting purchase The VIC 20, if only to play the built-in program called California Games. I've done some searching and it appears possible to load user-written programs from a thumb drive, so maybe a C64 version of Hunt the Wumpus could be cross compiled on the Raspberry Pi with cc65.

              https://cc65.github.io/

              Rather than all this retro computing, what I'd really like is a rotatable 3D graph visualizer for the Raspberry Pi, perhaps written in Python or BBC Basic. Does anyone know of such a tool? Would Fido agree?

              Back to the birthday project, I've been compiling the latest release and development versions of VICE on the Pi with the gtk3, sdl and sdl2 user interfaces to see which one is better. So far, my observations are
              • The development version has changes in vsync.c which
                • were likely responsible for the uncontrolled frame rates I experienced on the 32-bit Raspberry Pi OS.
                  • removed a feature that allowed subsampling the emulated frame buffer without affecting the virtual framerate. Such subsampling seems important to avoid excess CPU when running VICE over remote desktop.
                • The SDL2 version
                  • launches the initial window in arbitrary position on the screen rather than the top left corner.
                    • locks up when switching to full screen mode when no window manager is present. Since I don't want a window manager in the xrdp session, this could be a problem.
                      • the symbolic keyboard mapping is weirdly positional and the run-stop key is mapped to insert.
                    • The Gtk3 version
                      • has huge pull-down menus that require the screen resolution to be at least 900x720.
                        • the decimal point "." on the keypad is not mapped correctly.
                          • seems less efficient than the SDL programs due to the higher resolution requirements.
                            • doesn't lock up when switching to full screen mode.
                              • there is a nice symbolic mapping for the keyboard. Run-stop is mapped to the left control key.
                            • The SDL1 version
                              • seems the most efficient when it comes to resources.
                                • doesn't lock up when switching to full screen mode.
                                  • has only a positional keyboard map.
                                    • has run-stop mapped to insert.
                                  Since the positional keyboard mapping is irritating, I've been using the Gtk3 interface for all my examples when running VICE on the machine locally. In that case, the pull-down menus are also not a problem. I'm currently trying to create an equivalent symbolic keyboard map for the SDL1 release version, as that would avoid those menus and be optimal for remote desktop.

                                  Fixing the keyboard mapping would be much easier if there was better documentation on the SDL key symbols or at least a program like xev to figure out what's going on experimentally.

                                  I almost ordered The VIC 20 last night out of frustration, but then I remembered the original keyboard uses same irritating layout as the SDL positional mapping. However, during these times of quarantine there is nothing like a joy stick to lift one's mood. As long as one is still alive it's never too late. Maybe I should get two joy sticks.
                                  Last edited by ejolson on Mon Nov 02, 2020 10:45 pm, edited 2 times in total.

                                  Heater
                                  Posts: 18758
                                  Joined: Tue Jul 17, 2012 3:02 pm

                                  Re: A Birthday Present for Fido

                                  Mon Nov 02, 2020 10:11 pm

                                  OK. Scratch the retro C64 clone idea. The Pi 4000 has just landed. A C64 done 2020 style!
                                  Memory in C++ is a leaky abstraction .

                                  ejolson
                                  Posts: 8628
                                  Joined: Tue Mar 18, 2014 11:47 am

                                  Re: A Birthday Present for Fido

                                  Mon Nov 02, 2020 10:34 pm

                                  Heater wrote:
                                  Mon Nov 02, 2020 10:11 pm
                                  OK. Scratch the retro C64 clone idea. The Pi 4000 has just landed. A C64 done 2020 style!
                                  I searched on Pi 4000 and found
                                    16504256-723-IMG_9405.JPG
                                    16504256-723-IMG_9405.JPG (60.54 KiB) Viewed 1559 times
                                    https://www.autobag.com/Media/Autobag/A ... 9-1997.pdf
                                      While it looks like fun, it doesn't appear to come with a joystick.

                                      Another search found a Pi 4000 that looked like
                                        image158.png
                                        image158.png (150.93 KiB) Viewed 1559 times
                                        https://www.protecequip.com/products/et ... t-test-set
                                          Howeover, again no joy.

                                          Did you mean the Pi 400?

                                          https://www.raspberrypi.org/products/raspberry-pi-400/

                                          I'll bet a USB joystick would work just as well in the Pi 400 as in The VIC 20, but where can I get a joystick in the correct shade of pink?
                                          Last edited by ejolson on Tue Nov 03, 2020 12:50 am, edited 1 time in total.

                                          ejolson
                                          Posts: 8628
                                          Joined: Tue Mar 18, 2014 11:47 am

                                          Re: A Birthday Present for Fido

                                          Tue Nov 03, 2020 12:38 am

                                          ejolson wrote:
                                          Sun Nov 01, 2020 3:48 am
                                          The next post will describe installing VICE and configuring the SuperPET emulator to launch upon login instead of the xterm.
                                          After making a snapshot of the current state of the file system, I proceeded to download and install VICE. Interestingly VICE is hosted on SourceForge and still uses subversion to track changes to the repository. Although the code in development is lacking a critical feature, the ability to subsample the frame buffer, which is useful when emulating the SuperPET in a remote desktop session, the official 3.4 release works well enough.

                                          Download and unpack the source using

                                          Code: Select all

                                          $ wget https://sourceforge.net/projects/vice-emu/files/releases/vice-3.4.tar.gz/download
                                          $ mv download vice-3.4.tar.gz
                                          $ tar zxf vice-3.4.tar.gz
                                          
                                          Assuming the packages mentioned at

                                          viewtopic.php?p=1751914#p1751914

                                          that were loaded for xrdp and xorgxrdp are still present, install these additional packages

                                          Code: Select all

                                          # apt-get install bison flex xa65 libasound2-dev
                                          # apt-get install texinfo libglew-dev libnet1-dev libpcap0.8-dev
                                          # apt-get install dos2unix texlive-binaries
                                          # apt-get install libsdl1.2-dev
                                          
                                          Note, if you plan to run VICE locally rather than through remote desktop it might be easier to add the package libgtk-3-dev and build the Gtk3 user interface instead. As there are plenty of other tutorials how to do that, I'll focus only on the details of a remote desktop configuration here.

                                          Build and install VICE using

                                          Code: Select all

                                          $ ./configure --prefix=/usr/local/vice-sdl --with-alsa \
                                              --enable-native-tools --enable-ethernet --disable-native-gtk3ui \
                                              --without-pulse --enable-sdlui --disable-sdlui2
                                          $ make -j4
                                          
                                          and then as root type

                                          Code: Select all

                                          # make install
                                          
                                          Now it is necessary to download the additional software. The Waterloo Languages for the SuperPET are contained in two files which may be downloaded from either

                                          http://mikenaberezny.com/hardware/super ... languages/

                                          or

                                          http://www.zimmers.net/anonftp/pub/cbm/ ... index.html

                                          I selected the files
                                          • Waterloo2-Language-No6702-1.d64
                                          • Waterloo2-Language-No6702-2.d64
                                          Here is an interesting picture of a room full of SuperPETs being used by students leaning how to program at the University of Waterloo.

                                          Image
                                          https://cs.uwaterloo.ca/40th/Chronology/printable.shtml

                                          You can tell it's an old picture because the students are not wearing face masks. My understanding is the machines depicted are early SuperPETs that employed three additional boards and did not enjoy the usual shape the PET is known for. The production versions of the SuperPET regained the distinctive trapezoidal enclosure for the monitor.

                                          The plan is for user files to eventually be saved over an emulated serial link directly to the Raspberry Pi using the hostcm protocol. For now, create a subdirectory called images to hold the disk images and format an empty disk image to hold some user files.

                                          Code: Select all

                                          $ mkdir images
                                          $ mv Waterloo2-Language-No6702-1.d64 images
                                          $ mv Waterloo2-Language-No6702-2.d64 images
                                          $ cd images
                                          $ /usr/local/vice-sdl/bin/c1541 -format "home,fi" d64 home.d64
                                          SDL error: Unable to open a console terminal
                                          formatting in unit 8 ...
                                          
                                          For reasons unknown the c1541 program tries to start SDL even when it's only formatting a new disk. This fails because I was connected through an ssh login. Fortunately, the formatting still works. In this example the name of the volume is "home" and the id is "fi" for Fido.

                                          Finally, in order to make VICE start upon graphical login, edit the .xsession file in the home directory to read

                                          Code: Select all

                                          #!/bin/bash
                                          sleep 1
                                          xsetroot -solid black
                                          echo "keysym Control_R = Control_L" | xmodmap -
                                          screen=`xrandr | grep '*' | awk '{ print $1 }'`
                                          width=${screen%%x*}
                                          height=${screen##*x}
                                          let "nh=width*532/704"
                                          let "nw=height*704/532"
                                          let "height=nh<height?nh:height"
                                          let "width=nw<width?nw:width"
                                          cat >$HOME/.config/vice/sdl-vicerc <<EOF
                                          [PET]
                                          MenuKey=282
                                          SDLWindowWidth=$width
                                          SDLWindowHeight=$height
                                          SaveResourcesOnExit=1
                                          ConfirmOnExit=0
                                          FullscreenEnable=0
                                          CrtcFilter=0
                                          RefreshRate=5
                                          EOF
                                          /usr/local/vice-sdl/bin/xpet +sound -keymap 2 \
                                              -symkeymap /home/ejolson/.config/vice/sdl-sym-PET.vkm \
                                              -truedrive -superpet -cpu6809 -model SuperPET \
                                              -drive8type 4040 \
                                              -8 ~/images/home.d64 \
                                              -drive9type 4040 \
                                              -9 ~/images/Waterloo2-Language-No6702-1.d64 \
                                              -drive10type 4040 \
                                              -10 ~/images/Waterloo2-Language-No6702-2.d64
                                          
                                          Do not create such an .xsession file for an account that will be used for a normal login, otherwise, you will get only the SuperPET when logging in either locally or through remote desktop. Note that I have specified CrtcFilter=0 to leave out the special effects that blur the dots as a real CRT screen and RefreshRate=5 to subsample every 5th frame in order to reduce the load on the CPU while the session is running. The file sdl-sym-PET.vkm is described in the post

                                          viewtopic.php?p=1755242#p1755242

                                          and may be omitted along with the -keymap 2 flag if you want to follow the development of the remote SuperPET desktop described in this thread in chronological order.

                                          Now, upon logging in, you should obtain a screen which looks like
                                            xrdpsuperpet.png
                                            xrdpsuperpet.png (13.63 KiB) Viewed 1530 times
                                            http://fractal.math.unr.edu/~ejolson/pi ... perpet.png

                                            Use <L_Alt>+Q to log out. It's a SuperPET emulator desktop running on a remote Raspberry Pi!
                                            Last edited by ejolson on Sat Nov 07, 2020 3:41 pm, edited 7 times in total.

                                            ejolson
                                            Posts: 8628
                                            Joined: Tue Mar 18, 2014 11:47 am

                                            Re: A Birthday Present for Fido

                                            Tue Nov 03, 2020 7:27 am

                                            ejolson wrote:
                                            Tue Nov 03, 2020 12:38 am
                                            It's a SuperPET emulator desktop running on a remote Raspberry Pi!
                                            The photo of the SuperPET computing lab and the image of the login screen got me thinking about how the Raspberry Pi compares as a computer for teaching computer science. In a typical SuperPET lab, a student would first use the built-in terminal emulator to log into their account on the department mini-computer and then start the hostcm program. Thus, a student could access their personal files from any of the SuperPETs in the lab and start programming without having to bring or insert any removable media to save their work.

                                            Although we have not yet reached that level of technology in the Windows labs where I work, the discontinued PiNet system allowed for a similar way to store students' files on a central server. I think PiServer might also do the same. My understanding is this fat client model of network computing lost popularity during the health food craze which prioritized thin clients and further allowed greater control over the code people wrote while they ate.

                                            Fortunately, the pendulum of fashion has continued to swing back and forth.

                                            After a quick search for Pi computing labs I found this photograph

                                            Image

                                            and this one

                                            Image

                                            and many others. Although similar in that nobody is wearing any mandatory face coverings, one notable difference is that the SuperPET was clearly designed to teach college students while the students using the Pi are younger.

                                            I then checked the programming menu on the Pi and found
                                              pidesktop.jpg
                                              pidesktop.jpg (80.55 KiB) Viewed 1446 times
                                                Though I remember Scratch used to be an option, currently two programming languages--Python and Mathematica--appear on the menu by default. I'm pretty sure Scratch is hiding in there somewhere and that C and C++ are also installed. That makes a total of 5 programming languages on the Pi, all different than the 5 on the menu of the SuperPET.

                                                If I were to match them up in purpose and functionality, I would pair them as
                                                • Basic -- Python
                                                • Pascal -- C++
                                                • APL -- Mathematica
                                                • Cobol -- Scratch
                                                • Fortran -- C
                                                I've also been studying the SuperPET brochure linked in the post

                                                viewtopic.php?p=1751037#p1751037

                                                and thinking to what extent it might apply to the Raspberry Pi.

                                                At the same time, I've been looking at information on the Raspberry Pi, for example, the Theory of Change

                                                https://static.raspberrypi.org/files/Ra ... Change.pdf

                                                and trying to understand how the SuperPET might have served the same purpose during a different age for a different generation.

                                                Heater
                                                Posts: 18758
                                                Joined: Tue Jul 17, 2012 3:02 pm

                                                Re: A Birthday Present for Fido

                                                Tue Nov 03, 2020 11:51 am

                                                ejolson wrote:
                                                Mon Nov 02, 2020 10:34 pm
                                                Did you mean the Pi 400?
                                                Dang. Those zeros are more meaningful than they look sometimes!

                                                But hey, who would not want to play with a 4000 amp circuit breaker tester? Look at the terminals on that thing! If the Pi had power terminals like that there would be less problems with inadequate supplies being used.
                                                ejolson wrote:
                                                Mon Nov 02, 2020 10:34 pm
                                                Here is an interesting picture of a room full of SuperPETs being used by students...
                                                That is possibly the only photograph ever of the entire user population of a computer model in the same room at the same time :)
                                                Memory in C++ is a leaky abstraction .

                                                lurk101
                                                Posts: 1066
                                                Joined: Mon Jan 27, 2020 2:35 pm
                                                Location: Cumming, GA (US)

                                                Re: A Birthday Present for Fido

                                                Wed Nov 04, 2020 6:30 pm

                                                ejolson wrote:
                                                Tue Nov 03, 2020 7:27 am
                                                After a quick search for Pi computing labs I found this photograph

                                                Image
                                                My daughter's response to this picture: Pish... Why don't they just use their phones! :(

                                                ejolson
                                                Posts: 8628
                                                Joined: Tue Mar 18, 2014 11:47 am

                                                Re: A Birthday Present for Fido

                                                Wed Nov 04, 2020 9:37 pm

                                                lurk101 wrote:
                                                Wed Nov 04, 2020 6:30 pm
                                                My daughter's response to this picture: Pish... Why don't they just use their phones! :(
                                                It is noticeable the Pi computers in both lab pictures were not actually being used for programming when the pictures were taken. In contrast the SuperPETs were actively being used, though the resolution of the photograph makes it difficult to determine whether they were programing in Pascal or some other language. Maybe you need to point out that under non-photographic circumstances the students would be using a keyboard to program the Pi computers rather than staring at the raspberry logo.

                                                With the announcement of the Pi 400 it is interesting to speculate why there's been such a chronological gap since the Sol-20, Apple II, TRS-80, ZX81, H89, VIC 20, Ti-99, Beeb, C64, SuperPET and other computers with built-in keyboards.

                                                From my point of view, the machine that replaced all this variety was the IBM PC which notably had a separate keyboard. While a few home computers with built-in keyboards, such as the Amiga 500 and Atari ST were subsequently released, it seems the 16 and 32-bit processors that followed the golden age of 8-bit personal computing generated too much heat to comfortably place the keyboard and CPU in the same enclosure. Moreover, the bulky addition of floppy and hard disks anyway required an additional box to be placed nearby.

                                                After more than 30 years of technological progress, we are back to power-efficient processors that can easily be contained in a keyboard. Moreover, sufficient advances in storage have been made so we can do away with floppy and hard disks entirely. A microSD card easily fits in a keyboard and larger amounts of data can be accessed from a NAS where files are backed up and safe from the weird power failures that happen when personal computers are used in a home setting.

                                                In addition to this, laptop computers, smart phones and tablets have obsoleted the one remaining advantage of a detachable keyboard: that you can hold it in your lap. Since the personal computer is again a tool of empowerment and productivity, the keyboard belongs on the desk. Moreover, optical mice don't work very well on the upholstery while lounging in an armchair.

                                                Even with all the excitement of Nevada being the state that ultimately breaks the tie and decides who will be president of the United States, I have made progress on Fido's birthday present. After finding no solutions but many complaints about the positional mapping used in the SDL version of VICE on the Internet, I looked at the source. As seldom is the case, the solution has already been implemented and works.

                                                The problem is the extra features needed seem not to be documented and are not used in any of the example configuration files. Anyway, here are some comments from keyboard.c which give a hint what's going on.

                                                Code: Select all

                                                enum shift_type {
                                                    NO_SHIFT = 0,             /* Key is not shifted. Keys will be deshifted,
                                                                                 no other flags will be checked */
                                                
                                                    VIRTUAL_SHIFT     = (1 << 0), /* The key needs a shift on the real machine. */
                                                    LEFT_SHIFT        = (1 << 1), /* Key is left shift. */
                                                    RIGHT_SHIFT       = (1 << 2), /* Key is right shift. */
                                                    ALLOW_SHIFT       = (1 << 3), /* Allow key to be shifted. */
                                                    DESHIFT_SHIFT     = (1 << 4), /* Although SHIFT might be pressed, do not
                                                                                 press shift on the real machine. */
                                                    ALLOW_OTHER       = (1 << 5), /* Allow another key code to be assigned if
                                                                                 SHIFT is pressed. */
                                                    SHIFT_LOCK        = (1 << 6), /* Key is shift lock on the real machine */
                                                    MAP_MOD_SHIFT     = (1 << 7), /* Key requires SHIFT to be pressed on host */
                                                
                                                    ALT_MAP           = (1 << 8), /* Key is used for an alternative keyboard mapping (x128) */
                                                
                                                    MAP_MOD_RIGHT_ALT = (1 << 9), /* Key requires right ALT (Alt-gr) to be pressed on host */
                                                    MAP_MOD_CTRL     = (1 << 10), /* Key requires control to be pressed on host */
                                                
                                                    VIRTUAL_CBM      = (1 << 11), /* The key is combined with CBM on the emulated machine */
                                                    VIRTUAL_CTRL     = (1 << 12), /* The key is combined with CTRL on the emulated machine */
                                                
                                                    LEFT_CBM         = (1 << 13), /* Key is CBM on the real machine */
                                                    LEFT_CTRL        = (1 << 14)  /* Key is CTRL on the real machine */
                                                };
                                                
                                                I haven't digested every bit, but the important flags appear to be ALLOW_OTHER and MAP_MOD_SHIFT. Used in combination, these allow a single key on the host machine to act as different keys on the emulator.

                                                For example, the parenthesis can be moved from the 8 and 9 keys to the 9 and 0 keys with

                                                Code: Select all

                                                57 9 3 32        /*            9 -> 9            */
                                                57 0 2 128       /*      shift+9 -> (            */
                                                48 1 3 32        /*            0 -> 0            */
                                                48 9 3 128       /*      shift+0 -> )            */
                                                
                                                Note that the layout on the SuperPET is incidentally quite similar to the ASR33 Teletype. The point, however, is that my muscle memory for the Teletype has long been adapted to present standards and switching back and forth was making a typing mess of all my typing.

                                                After I decide what to do about the insert key and whether to map run-stop to ctrl-C instead, I'll post a complete symbolic layout for the SuperPET emulator.

                                                While the ability to remap the keyboard is an advantage the Pi 400 has over The VIC 20, a licensed version of California Games and a joystick is pretty good competition for Minecraft and a pink mouse. I wonder what Fido would do.
                                                Last edited by ejolson on Thu Nov 05, 2020 4:25 pm, edited 3 times in total.

                                                lurk101
                                                Posts: 1066
                                                Joined: Mon Jan 27, 2020 2:35 pm
                                                Location: Cumming, GA (US)

                                                Re: A Birthday Present for Fido

                                                Thu Nov 05, 2020 3:01 am

                                                ejolson wrote:
                                                Sun Oct 18, 2020 2:31 pm
                                                lurk101 wrote:
                                                Sun Oct 18, 2020 5:22 am

                                                Sample of the output where the Magnadoodle patch was activated.

                                                Code: Select all

                                                pi@raspberrypi:~/wumpus $ fpc wumpus_cave.pas 
                                                Free Pascal Compiler version 3.0.4+dfsg-22 [2019/01/24] for aarch64
                                                Copyright (c) 1993-2017 by Florian Klaempfl and others
                                                Target OS: Linux for AArch64
                                                Compiling wumpus_cave.pas
                                                Assembling wumpus_cave
                                                Linking wumpus_cave
                                                196 lines compiled, 0.2 sec
                                                pi@raspberrypi:~/wumpus $ ./wumpus_cave 
                                                Directed graph
                                                    1->18
                                                    18->3
                                                    3->10
                                                    10->16
                                                    16->2
                                                    2->14
                                                    14->4
                                                    4->11
                                                    11->7
                                                    7->6
                                                    6->19
                                                    19->5
                                                    5->17
                                                    17->9
                                                    9->13
                                                    13->15
                                                    15->8
                                                    8->20
                                                    20->12
                                                    12->1
                                                    20->6
                                                    17->3
                                                    11->5
                                                    16->7
                                                    8->19
                                                    14->1
                                                    12->18
                                                    10->9
                                                    2->4
                                                    delete 2->14
                                                    13->2
                                                    15->14
                                                    14->7
                                                    2->4
                                                    3->17
                                                    1->8
                                                    9->10
                                                    16->5
                                                    11->6
                                                    18->20
                                                    19->12
                                                
                                                Wumpus cave
                                                    8 12 18
                                                    4 4 16    <--- Invalid wumpus room
                                                    10 17 18
                                                    2 11 14
                                                    16 17 19
                                                    7 11 19
                                                    6 11 14
                                                    1 15 20
                                                    10 13 17
                                                    3 9 16
                                                    4 6 7
                                                    1 19 20
                                                    2 9 15
                                                    1 4 7
                                                    8 13 14
                                                    2 5 10
                                                    3 5 9
                                                    1 3 20
                                                    5 6 12
                                                    8 12 18
                                                pi@raspberrypi:~/wumpus $
                                                Surprised no one caught it, but room 2 is connected to room 4 twice.

                                                Here's the bug fix. Add missing break statement.

                                                Code: Select all

                                                program wumpus_cave;
                                                
                                                const first_room=1;
                                                const last_room=20;
                                                const first_tunnel=1;
                                                const second_tunnel=2;
                                                const last_tunnel=3;
                                                
                                                type t_room_num=first_room..last_room;
                                                type t_tunnel_num=first_tunnel..last_tunnel;
                                                type t_cave=set of t_room_num;
                                                type t_cycle=array[t_room_num] of t_room_num;
                                                type t_room=array[t_tunnel_num] of integer;
                                                
                                                var rooms:array[t_room_num] of t_room;
                                                
                                                var cycle:t_cycle;
                                                var cave:t_cave;
                                                
                                                var r:t_room_num;
                                                var t:t_tunnel_num;
                                                
                                                { Swap the referenced parameters if the 1st is greater than the 2nd }
                                                procedure exchange(var i,j:integer);
                                                begin
                                                    if (i > j) then begin
                                                        i:=i xor j;
                                                        j:=i xor j;
                                                        i:=i xor j
                                                    end
                                                end;
                                                
                                                { Return number elements in cave set }
                                                function room_count:integer;
                                                var r:t_room_num;
                                                var n:integer;
                                                begin
                                                    n:=0;
                                                    for r:=first_room to last_room do
                                                        if r in cave then
                                                            n:=n+1;
                                                    room_count:=n
                                                end;
                                                
                                                { Randomly pick and return an element from the cave set }
                                                function random_pick:t_room_num;
                                                var r:t_room_num;
                                                var n:integer;
                                                begin
                                                    n:=Random(room_count);
                                                    for r:=first_room to last_room do
                                                        if r in cave then begin
                                                            if n=0 then
                                                                break;
                                                            n:=n-1
                                                        end;
                                                    random_pick:=r
                                                end;
                                                
                                                { Add a tunnel to room f connecting to room t }
                                                procedure add_directed_tunnel(f,t:t_room_num);
                                                begin
                                                    if rooms[f,first_tunnel]=-1 then
                                                        rooms[f,first_tunnel]:=t
                                                    else if rooms[f,second_tunnel]=-1 then
                                                        rooms[f,second_tunnel]:=t
                                                    else
                                                        rooms[f,last_tunnel]:=t
                                                end;
                                                
                                                { Add tunnel connecting two rooms }
                                                procedure add_tunnel(f,t:t_room_num);
                                                begin
                                                    writeln('    ',f,'->',t);
                                                    add_directed_tunnel(f,t);
                                                    add_directed_tunnel(t,f)
                                                end;
                                                
                                                { Delete a tunnel from room f connecting to room t }
                                                procedure del_directed_tunnel(f,t:t_room_num);
                                                var i,j:t_tunnel_num;
                                                begin
                                                    for i:=first_tunnel to last_tunnel do
                                                        if (rooms[f,i]=t) then begin
                                                            for j:=i to last_tunnel-1 do
                                                                rooms[f,j]:=rooms[f,j+1];
                                                            rooms[f,last_tunnel]:=-1;
                                                            break
                                                        end
                                                end;
                                                
                                                { Delete tunnel connecting two rooms }
                                                procedure del_tunnel(f,t:t_room_num);
                                                begin
                                                    writeln('    delete ',f,'->',t);
                                                    del_directed_tunnel(f,t);
                                                    del_directed_tunnel(t,f)
                                                end;
                                                
                                                { Return whether two rooms are neighbors }
                                                function neighbors(i,j:t_room_num):boolean;
                                                begin
                                                    neighbors:=(cycle[i]=j) or (cycle[j]=i)
                                                end;
                                                
                                                { Build a directed wumpus graph and room map }
                                                procedure directed_cave;
                                                var r,s,e,c,d:t_room_num;
                                                begin
                                                    writeln('Directed graph');
                                                
                                                    { Clear the tunnel map }
                                                    for r:=first_room to last_room do
                                                        for t:=first_tunnel to last_tunnel do
                                                            rooms[r,t]:=-1;
                                                
                                                    { Step 1 - Put the set of numbers 0 to 19 into an array and shuffle them.
                                                      Produce a bunch of connections, edges, that link all the nodes together
                                                      in a loop. To do this just assume that every element in the array
                                                      connects to the next one. And wrap around at the end. This ensures that
                                                      we will never get disjoint graphs, we have already connected everything
                                                      in a loop. }
                                                
                                                    { Just produce a random cycle directly }
                                                    r:=first_room;
                                                    cave:=[first_room..last_room]-[r];
                                                    repeat
                                                        e:=random_pick;
                                                        cave:=cave-[e];
                                                        add_tunnel(r,e);
                                                        cycle[r]:=e;
                                                        r:=e;
                                                    until cave=[];
                                                    cycle[r]:=first_room;
                                                    add_tunnel(r,first_room);
                                                
                                                    { Connect the remaining 10 edges }
                                                    cave:=[first_room..last_room];
                                                    repeat
                                                        { Step 2 - Looking at that nice loop it seems that if we pick any two,
                                                          different, nodes at random and connect them together we create two
                                                          nodes that both have the required number of exits, 3. Doing that
                                                          produces two connected loops. }
                                                        { Step 3 - Given that the two nodes connected above now have the
                                                          required 3 exits we can remove them from further consideration. So
                                                          remove them from the set of nodes. }
                                                        s:=random_pick;
                                                        cave:=cave-[s];
                                                        { Handle the special case where the last 2 nodes are neighbors }
                                                        if room_count>1 then
                                                            repeat e:=random_pick;
                                                                until not neighbors(s,e)
                                                        else
                                                            e:=random_pick;
                                                        cave:=cave-[e];
                                                        { if still neighbors then there were only 2 choices,
                                                          then handle the special case }
                                                        if neighbors(s,e) then begin
                                                            cave:=[first_room..last_room]-[s,e];
                                                            repeat c:=random_pick;
                                                                until (c<>s) and (c<>e) and (cycle[c]<>s) and (cycle[c]<>e);
                                                            d:=cycle[c];
                                                            del_tunnel(c,d);
                                                            add_tunnel(s,c);
                                                            add_tunnel(e,d);
                                                            break;
                                                        end
                                                        else
                                                            add_tunnel(s,e)
                                                    { Repeat till graph is empty }
                                                    until cave=[];
                                                
                                                    { Finally, sort the tunnels }
                                                    for r:=first_room to last_room do begin
                                                        exchange(rooms[r,first_tunnel],rooms[r,second_tunnel]);
                                                        exchange(rooms[r,second_tunnel],rooms[r,last_tunnel]);
                                                        exchange(rooms[r,first_tunnel],rooms[r,second_tunnel])
                                                    end
                                                end;
                                                
                                                begin
                                                    { Seed the RNG }
                                                    Randomize;
                                                
                                                    { Generate the cave }
                                                    directed_cave;
                                                
                                                    { Dump the cave map }
                                                    writeln;
                                                    writeln('Wumpus cave');
                                                    for r:=first_room to last_room do
                                                        writeln('    ',rooms[r,first_tunnel],' ',rooms[r,second_tunnel],
                                                            ' ',rooms[r,last_tunnel])
                                                end.

                                                Return to “Other projects”