Monday, July 7, 2014

Well, that's random

Why random numbers?

In order to make a fun game of chance, you need random numbers. Dice rolls, card shuffles, or a roulette wheel are no fun if they're predictable.

Mommy, where do randoms come from?

There are mathematical formulas that can provide a stream of seemingly random numbers. These are called pseudo-random number generators, or PRNGs. You start off a PRNG with a truly random "seed" number, from which the PRNG derives a sequence of numbers. Although this sequence gives the appearance of being random, it is completely predictable - each time the PRNG is started with the same seed, it will produce the same resulting sequence of numbers.

It all starts with a seed...

Thus, the initial seed for a PRNG must be truly as random as possible. Computers are great at many things, but being unpredictable isn't one of them - so to get some randomness (or "entropy" as it's called in Information Theory), we need the human touch. In this case, quite literally.

For each of the platforms I'm using for my Retrochallenge entry (Atari 800, Epson PX-8, PDP-11/23+), I wanted to find a suitably fast-changing clock or register that could be used as a seed. To get this value at a random time, you ask the user to press a key to perform some action (e.g., get their initial bankroll - thanks Ian!). After their key press, a value is sampled from the high-speed clock and used as the seed value. As long as that clock is fast enough, then voila, there's your random number seed.

Harvesting the seed

The PX-8 was the most ideal. There is a 614.4 KHz clock that updates a rolling 16-bit register, the value of which can be read with from the BASIC "INP" function. This function reads values from Z80 I/O registers. Since 614.4 KHz will update the value more than 600,000 times per second, it is unlikely in the extreme that a user could predict when to press a key even if they wanted to.

The Atari 800 and PDP-11 were not as good, but still passable. Each have memory-mapped registers that update at 60 Hz. Typically called "ticks", these are internal clocks for the computer's functions. In the Atari, it's part of the ANTIC video chip, and for the PDP-11, it's a component of the line clock. Reading the value of minutes, seconds and ticks after a user key press should provide an ample source of randomness. On the PDP-11, there is a system library function, callable from Fortran, called "GTIM", that provides the current count of ticks. On the Atari, in Forth, the value can be read with "C@", the Forth equivalent of a one-byte PEEK function.

Now we have a seed, how 'bout some numbers?

PX-8 BASIC also has a PRNG built-in. You seed it with the "RANDOMIZE" statement, then use the RND function to get random numbers (fractions 0<=x<1). For Forth and Fortran, I need to provide the PRNGs; however, there are happily some good ones online.

So hey, pal, no counting cards in my RC casino!

Monday, June 30, 2014

Retrochallenge 2014 - Get Set

Now it's 11:37 PM Pacific Time, and the excitement is building on the West Coast of the US, where Retrochallenge 2014 is about to commence!

The computers are ready. But, alone, are they enough to stand up to the tests of character and strength that await them? Take heart, there is help from the sidelines.

The Raspberry Pi

Serving once again as a trusty virtual disk drive for the PX-8, the Raspberry Pi is ready to retrieve and store BASIC programs:

The Raspberry Pi wishes it was a PX-8

 SIO2PC

Hey, the PX-8 isn't the only kid that gets to play with a virtual disk drive. The SIO2PC, a device which conveniently hooks an Atari 8-bit system to a modern PC, festooned with blinky lights, is standing by:

Tomorrow, these LEDs shall blink


The Manuals

Books are the stuff of life, and the reference materials are also waiting in their corner. Here are, in no particular order, the Atari 800 "Purple Book", the KED editor (PDP-11) quick reference, and the Epson PX-8 BASIC Reference Guide:





Notice that nothing is powered on... No, my friends, that celebration comes in just a few minutes, as these digital animals are let out of their time-boxed cage! BWA HA HA HA HA HA.

Ha.

See you in the morning!

Retrochallenge 2014 - On Your Marks

It's 10:49 PM Pacific Time in Portland, Oregon. The temp is 74 degrees outside, and it's going to be a whopping 98 tomorrow. That's 36.6 Celsius, quite warm by any measure. In just over an hour, this year's Retrochallenge will begin for those of us on the West Coast of the US. Much of the world has already started. Eclipsing the Olympics and even the current World Cup frenzy, the Retrochallenge is the ultimate test of strength, agility, and stamina.

OK, so, maybe that's over the top. However, I'm quite excited. In preparation, I've readied my systems. Here they are, in descending order of gross metric tonnage:

The PDP-11/23+

Weighing in at over 300 pounds (>136 kilos) is the PDP-11/23+. It's loaded with the venerable Fortran 77 compiler. I love to say venerable. I'm not even sure what it means. But it's impressive.

The venerable PDP-11/23+ with venerable Fortran 77

The Atari 800

Yes, this is the original Atari 800, packed with 1.79 MHz of raw 6502 power, and running the venerable Extended Fig-Forth.

Atari 800 with Commodore monitor


The Epson PX-8

Last but not least (except in weight), the Epson PX-8 and BASIC in ROM stand ready to meet any challenge. It's sitting next to my Dell E6430, but they don't talk much. Generation gap.

I guess it's not venerable, but it is cute:

The Epson PX-8 and Dell E6430, brothers from another mother


All this takes massive, Earth-shaking power to run:


60 Hz and loving it

(Do you think this is a fire hazard?)

These computers have accoutrements, which I will describe in the next blog post ("Get Set")!

I am shaking out the muscles, and getting ready for the sprint!

Friday, June 13, 2014

Retrochallenge Summer 2014

For my Retrochallenge Summer 2014 entry, I want to do a 3 x 3 game marathon.

3 games:
  • 21
  • Craps
  • Roulette

3 platforms - choice of:
  • Commodore VIC-20
  • Commodore 64
  • Commodore 128
  • Apple II
  • Atari 800
  • TRS-80 Model 100
  • Epson PX-8
  • PDP-11 with VT-100 terminal

Language choices:
  • C
  • Forth
  • BASIC

Challenges:
  • Will need a good pseudo random number generator (PRNG) and a good seed
  • Will have to understand the I/O approaches for each of the three chosen platforms and languages
  • Will have to decide which subset of rules for each of the games will be implemented

So, super-duper success is all nine games (3 x 3) implemented, including graphics and sound applicable to the platform(s). Just barely crossing the finish line is one game on one platform. No games equals total loss and utter humiliation.

If you have suggestions on platforms or languages, let me know!



Friday, January 31, 2014

Retrochallenge Winter Warmup 2014 Success!

A few years ago, inspired by software disk drive emulators for the Epson PX-8 laptop computer, I set out to find a self-contained hardware/software combination that could serve as a portable drive. This would be a functional replacement for the PF-10 portable drive, which is unobtainium these days.

With the conclusion of this year's Retrochallenge Winter Warmup 2014, I'm quite a bit closer to the goal. The only thing missing is battery power, which I might be able to solve at some point.

Before going into gory details, here is a video of the drive emulator in action:




Now, the rest of the story...

HARDWARE

The Epson PX-8 is one of the first notebook computers. It's a gem. For a long time, they were still available (recently) brand-new in box. Alas, the distributor is now out of stock. I used the PX-8 back in the day, and worked on the support team for them at Epson. I did an entire podcast episode on this computer, so have a listen if you'd like to learn more.

The centerpiece of the drive emulator project is the Raspberry Pi - a $35 single board Linux computer. You can do a LOT of stuff with it. If this fine device has not made it onto your radar as yet, have a look at these links:

Raspberry Pi on Wikipedia

Raspberry Pi Official Site

Slapped on top of the Raspberry Pi is another key ingredient - the PiFace Control and Display (PiFaceCAD). It is a combination of things designed to help you control your Raspberry Pi without requiring the standard KVM (keyboard/video/mouse) setup. Here's a picture, with credit to the distributor, Element14:



It has a backlit 16x2 LCD display, 5 pushbuttons plus a rocker/button combo on the back, an infrared remote control reader (which I did not use), and a socket which attaches to the I/O pins on top of the Raspberry Pi. You can program all the functionality with Python, as well as do some things from C. I used Python, given it has good support for calls to the operating system.

To round out the hardware, I used a FTDI USB to RS232 converter as the serial port to connect the Raspberry Pi with the Epson PX-8. The final connection to the PX-8 required a custom cable, a mini DIN 8 to DB9. I will provide more info on this in a future post, and you can also find info on building such cables at Fred J. Kraan's site for the PX-8.

SOFTWARE

There are two key pieces of software, plus some configuration, involved in making this all work.

First, credit again to Fred J. Kraan for the vfloppy software, a disk drive emulator and set of associated disk image management utilities for the Epson PX-8. The software is updated from time to time, and not too long ago, switched to a new disk image format to make it compatible with a PX-8 emulator.

The vfloppy program is a command-line tool, so I needed to instrument it somehow to work with the PiFace CAD. Python was the natural choice for the "glue" logic to create a UI on the LCD screen, and launch the software with the disk image selected by the user. The "subprocess" module in Python permits the invocation of processes, and then control of those processes throughout their life cycle.

So, in short, I wrote a Python program to:

  • Present a UI for the user to select a disk image
  • Monitor the PiFaceCAD buttons for interaction
  • Once an image was selected, run the vfloppy program and save the process ID
  • When user pressed "SELECT", stop the vfloppy program, and permit a new image selection, running vfloppy again once selected
  • Exit the program if "EXIT" is selected, and stop the vfloppy process
CONFIGURATION

Writing the program wasn't the complete picture, however. The Raspberry Pi needed to run the program on boot-up. To accomplish this, I performed these steps:
  •  Created a new user on the Raspberry Pi
  • Added that user to groups as necessary to permit access to the Pi's I/O (gpio, spi)
  • Edited the user's startup shell script (~/.bashrc) to run the PF-2014 software on login
  • Set the Pi to auto-login the new user
With these settings in place, the Pi runs the software (which I call "PF-2014" in homage to the PF-10 disk drive for the PX-8) on startup. No hands or feet required.

I learned so much during this Retrochallenge, most notably about Python. I'll blog in a later post about some of the things I picked up (they're handy!).

Looking forward to the summer classic!


Friday, January 17, 2014

Chess Match Info!

The Commodore 64 versus Apple II chess match will air live tomorrow (Sat 1/17) at 1:00 PM Pacific, 4:00 PM Eastern.

Watch live at: http://www.youtube.com/watch?v=wD35BimEOvo

See you then!