Thursday, 30 December 2021

XTREE for Vintage Computing Christmas Challenge 2021


This is my response to Logiker's Christmas Challenge for 2021. Interesting exercise.


Author: Jim Gerrie (Sydney, Nova Scotia, Canada) http://faculty.cbu.ca/jgerrie/Home/Type-in-Mania.html

System: TRS-80 Micro Color Computer (MC-10)

Language used: Micro Color BASIC 1.0

Length of source code: 74 bytes (or 70 bytes if I use ? instead of PRINT)

Length of "executable" file: XTREE.C10 (365) 4TREE.C10 (679)-- these are files loadable by emulator.


Instructions on how to run the code: 

VMC10.exe is the Virtual MC-10 emulator. Unzip the emulator zip file into a directory of your choosing.  Execute VMC10.exe. Ignore any warnings. You should be fine.

The Challenge (XTREE.C10)

Type CLOAD & hit ENTER in the main emulator window. Select XTREE.C10 in the "Cassette" directory. Type RUN...


The Challenge - Variation 2 (4TREE.C10)

Type CLOAD & hit ENTER. Select 4TREE.C10 in the Cassette directory. Type RUN...

The source code for both programs are in the "quicktype" directory as text files.  These files can also be

loaded into the emulator via the "quicktype" feature in the Files menu.  Screenshots of the games are in the "screenshots" directory.


Description:

XTREE

0 FORY=1TO14:L=ASC(MID$("!#%'#'+/%+17##",Y))-32:PRINT,TAB((33-L)/2);:FORX=1TOL:PRINT"*";:NEXTX,Y

The XTREE program basically encodes the tree line lengths as a series of ASCII characters. The ASCII value

encodes the length of each line, which the program then decodes and prints the number of asterisks centred.

4TREE

0 FORC=1TO4:CLS0:FORR=1TO10:ONCGOSUB1,2,3,4:GOSUB6:ONCGOSUB5:NEXT:NEXT:GOTO

1 POKE49151,68:A$="":FORT=1TO23:A$=A$+CHR$(127+RND(128)):NEXT:RETURN

2 POKE49151,28:A$="":FORT=1TO23:A$=A$+CHR$(32+RND(64)):NEXT:RETURN

3 POKE49151,.:A$="":FORT=1TO23:A$=A$+CHR$((RND(8)-1)*16+143):NEXT:RETURN

4 POKE49151,28:A$="":FORT=1TO23:A$=A$+CHR$(32+RND(112)-(RND(2)=1)*64):NEXT:RETURN

5 FORT=1TO50:POKE49151,4-(RND(2)=1)*64:NEXT:RETURN

6 FORT=1TO14:L=ASC(MID$("!#%'#'+/%+17##",T))-32:PRINT@(T-1)*32+((32-L)/2),LEFT$(A$,L);:NEXT:RETURN

4TREE just uses a faster version of XTREE multiple times through GOSUBs but creates different type of characters strings in A$ such as the solid color graphic strings stored above ASCII 128.

It also puts the MC-10 into some of its stranger graphics modes to create some interesting special effects.  The POKES put the machine into these different modes.



Sunday, 26 December 2021

"Dropship" by Darren Ottery Ported to Micro Color BASIC

I've been working on Jaz's (Darren Ottery) "Dropship." Trying to make it all fit in one program that only needs regular Micro Color BASIC.

Dropship by Darren Ottery

My hope was not to mangle it too much by down shifting it from the more capable and feature rich MCX BASIC provided with the MCX Micro SD pack. Many compromises had to be made, since I was worried I wouldn't have enough memory with over 20 unique screens of data for its complex map and the merging of the two minigame sub-programs into one large program, but it actually turns our that there's quite a bit of memory left (3000 bytes).  So, I was able to add back in a few features I'd taken out, such as the exit indicators that flash in the initial room at program startup.

I asked Darren if he'd mind me adding my initials to the splash screen-- a lot of work went in to converting all the screens to strings, as opposed to using the MCX LOADM command, which allows whole screens to be loaded directly. The effort made me appreciate all the work Darren put into the game. It's an incredible program. I'm still amazed it's all done just in BASIC, so many cool effects, such as the swooping fighters in the minigame and the flapping animation. I have wanted for some time to make sure others without an MCX expansion pack could play it too. Darren graciously agreed to let me put my initials on the splash screen.  He wrote:

"you go Jim! This was an exercise in learning what the MCX could do in some respects. Perfect that you are bringing it back. I've pushed pause on my current MCX project which I'll finish one day. I want to focus writing in Color basic and compiling with Greg Dionne's tool. I need to figure if I can do it all on real hardware."

And go I did . I added lot's of speedups, changes to the maps to get them to render appropriately in Micro Color BASIC. The big changes was that you can't have any special reverse characters, like space and punctuations embedded in strings in regular BASIC, unlike what the fancy MLOAD command allows for. Also, the inability to use reverse space (32) in strings meant areas that were open to having aliens or POWER put into them had to have another colour or character placed there.  For regular passages I chose 96, so that the strobe effect from alternating the screen colour (POKE419151,64) could still occur.  For the more complex rooms, I replaced 32 with black.  This toned down the strobe effect a little, but they looked odd with strips of regular space characters around them.

Reconciling the merging of the three main programs (Maze explore, Alien shoot'em up, Descent). required loading and renumbering the sub programs so they could be merged into the main program.  There's no equivalent to the CHAIN command and special variations of the RUN command that MCX BASIC provides, which allow programs to call and recall other programs. 

I also added to the dropship animation when it leaves the bay.  Now it actually looks like it is descending from the bay.  Instead of the whole screen simply scrolling upwards, the lander stays in place, which simulates its descent from the bay:

The exits to rooms are now alt black characters, so they aren't visible as in the original. Full scores appear on alien shoot'em-up, instead of being limited to 2 characters (100 would appear as 10). I changed the key input to WASD in the hopes of enticing my son Charlie to try the game, since he's home over Christmas. I made some changes to the final landing-- now crashes into the walls on the final screen don't end the entire game, they just take a life (if you have any left) just like what happens during the descent. I also made some edits to the instructions to condense them to fit the 128 character line limit of Micro Color BASIC. MCX BASIC allows for 255 character lines.

I hadn't implemented the shift between the shoot'em up subprogram and the main program properly initially. Darren had it so that after you do each shoot'em up minigame that room turns into a regular passage.  This meant you could only earn 2 stripes.  I had made it so that you returned to the start room after each shoot'em up and could return as much as you liked. I only noticed my mistake when I went back to play the original to do some checks on my sound translations.

Final speed enhancements involved basically chasing down unnecessary variables and replacing them with scratch variables. I needed as much speed as possible (a smaller number of variables means a smaller lookup table, which speeds things up) because the lack of a PLAY command and the necessity to use SOUND instead (which is a slower less subtle sound producer in general) for the footsteps of the player.  This meant I needed to scrape speed anywhere I could to keep the main loop as "tight" as possible. It took some trial and error to find reasonable replacements for PLAY sound effects using only SOUND.  I did my best, but it's only a rough approximation of Darren's cooler music and sound effects from the original, but I hope it will do.

DROPSHIP can, as for my other games, be played on my web page:

http://faculty.cbu.ca/jgerrie/MC10/JG_MC10_Recodings.html

Finally, I created a map, and I was thinking of attempting a recording of a complete playthrough (either me or my son), but I'm unsure if this would spoil the "mystery."  But the point is moot.  The game is too tough for me to complete it (I'm a crap gamer).

But as I said, maybe I can get me son Charlie to try. He's got nimble young fingers.  But if you're looking for some help, here's a map of the main game maze layout provided below:




WARNING!!!!!!!!!

********************

SPOILER ALERT!

********************

GAME MAP BELOW






       1  2  3  4  5  6  7

                          
1      +--+--A--+  N  +--D
       |  |     |  |  |   
       |  |     |  |  |   
2      S  +--+--T--+  L  P
       |        |  |  |  |
       |        |  |  |  |
3      +--+--+--+  I  +--+
             |     |  |  |
             |     |  |  |
4      C--+--+  +--+  +  +
          |     |     |  |
          |     |     |  |
5      +--+--+--+  +--O--+
       |        |  |  |  |
       |        |  |  |  |
6      +--A--+--+--+  +--+


S=START
A=ALIENS  C=CARD   I=ION DRIVE  L=AIR LOCK  
O=CORE    N=NUKE   P=POWER      T-TRS-80 ROOM

P.S.  I did finally complete the main level:




Sunday, 5 December 2021

Lots of Simple Type-ins


I  ported a bunch of simple small programs to Micro Color BASIC.  The first one, "Peeper" by David Wilkins, is from the Sinclair ZX81. I've sped it up a little and added colour in a way that I hope creates something of a nighttime ambience.  I'm not sure who "the peeper" is, but in my version he or she is someone in a well lit building with lots of windows.  I hope that's not a gun at the bottom, but just an annoying flashlight or possibly a non-dangerous laser pointer.

"Speedboat" by Steven Holiday. It's from TRS-80 Colour Computer: Fantastic Computer Games, published in Burlington Ontario by Hayes Publishing in 1984. I've added a few minor esthetic tweaks and programming speedups.  I added the white "wake" to add to the sense that you are slicing through the waves at great speed.  I changed the boat from a solid colour to a pointy "V."


And another program from that book called "Logger" by Brian Jaikens. It indicates the strong desire of early type-in programmers to make games based on popular arcade themes-- in this case: Donkey Kong.  This particular program demonstrates some nice character graphic animation.


Another was recommended by Erico Patricio Monteiro over on the Coco group. He called it "1K Space Invader."  Or at least that was what he called it initially, because he just had a partial page clipping provided by someone on Twitter of the source code:


I was able to locate the original, which was actually called "War of the Worlds" by David Healey.  I did this by typing in a few of the more unique program lines into a search engine.  I put quotes around them to search for the exact line.  This doesn't always work, since scans of magazines can often fail to capture the actual program listing accurately.  But I tried a few different lines and eventually found it on the Internet Archive.

WARWORLD

You can try "Haiku," a BASIC poetry generating program by John Krutch, by going to my GameJolt page, selecting PLAY and then choosing the "Educational Programs" menu item. Then select HAIKU from the Cassette menu and type RUN and hit Enter.  It was intended as an example of computer generated artwork as a demonstration of AI in Krutch's book AI for Small Computers.  Whether it truly constitutes "AI" is an issue I will leave to you, the reader, but it is is certainly an interesting bit of early 1980s artificial intelligence research.


And finally a program of my own making called FLAGS.  I just wanted to add the flag graphics for every country on my Type-in Mania main page.


The reorganization of the page involved changing it to just include a rotation of flags of the countries mentioned and screen shots of the programs actually listed on the page.

I've moved into a programming phase where I plan to focus on getting copies of simple classic type-in programs working, especially those that demonstrate simple examples of so-called AI programing techniques like the program "Guess the Animal" that I discussed in my last post.  This is in part a result of expediency.  I think I've simply gleaned all the more significant programs that weren't already well represented out there on the Net.  But of course, I could be being too hasty.  In the past when I've thought I had exhausted the possibilities for finding important but "missing" BASIC programs, I've turned out to be wrong.  So anyone out there who might be reading this, please feel free to post suggestions for significant, but perhaps neglected, type-in BASIC programs to look for.

Wednesday, 1 December 2021

Early Machine Learning: "Animal" from David Ahl's BASIC Games


I teach a philosophy course on AI.  One of the things we look at are historical programs from the beginning of AI research. One of these is the "Guess the Animal" game included in David Ah's classic BASIC Games compendium from 1978.  However, when I went to look for easily accessible and playable versions of the original program I was surprised to discover that they were kind of hard to access.  Like so many of the programs on the list of Ahl classics, you can easily find copies of the source, and scans of the original book, such as:


But finding an easily playable version of the original was tough.  I did find some modern remakes, including one that is trying to compile an ever increasing list of inputs from people on the Net:

https://www.animalgame.com/play/faq.php

The reason this site is so interesting is that Animal is one of the early simple and accessible examples of a program involving "machine learning", which is a big buzz word these day in the field of AI. The intelligence of the program really relies on the input of the users and the intelligence of the program grows with additions to the input from users, who slowly train and expand the ability of the program.  The program tries to accurately guess the animal your are currently thinking of simply by asking questions and answers input by prior users.  It only has a limited number of questions that it starts with, but the users must supply all the rest.

Obviously, on the early 8-bit home computers this kind of program was limited by a number of factors.  The first was the reliance on slow and awkward forms of long term storage such as cassette tapes.  The second was limits on machine RAM memory for dealing with any growing body of input data.  The program was originally developed for networked minicomputer systems, which allowed for data to be more easily compiled, and for more users to be interacted with:

https://www.animalgame.com/play/misc/source.php

However, the Microsoft BASIC version for Ahl's book dispenses with the the "save" and "loading" features.  As a result, in its accessible type-in form it is easy to understand why people might not have been particularly interested in the program, with its data limited to single sessions on an un-networked 8-bit home computer.

Another possible reason for the relative lack of prominence on the Net among retrocomputing enthusiasts is that the Ahl version seems to have some bugs.  In the version I worked from the question printing routine didn't properly parse the questions, which are saved as text strings with numeric values tacked onto the end of them for directing the Y and N responses. The result is that the computer posses question with some of this Y/N numeric info tacked on at the end.  It was more an esthetic nuisance, than a fatal error.

The Original Question Print Routine:

400 Q$=A$(K)

410 FOR Z=3 TO LEN(Q$)

415 IF MID$(Q$,Z,1)<>"\" THEN PRINT MID$(Q$,Z,1);

417 NEXT Z

420 INPUT C$

My Question Print Routine:

400 Q$=A$(K)

410 FOR Z=3 TO LEN(Q$)

415 IF MID$(Q$,Z,1)<>"^" THEN 417

416 M$=MID$(Q$,3,Z-3)+"?":GOSUB1:Z=255:REM JUMP TO WORD WRAP PRINT ROUTINE

417 NEXT Z

However, there were possibly other more fatal problems involving the creation of new data items due to improper conversion of the numeric values into strings for concatenation onto new question strings.

370 A$(K)="\Q"+X$+"\"+A$+STR$(Z1+1)+"\"+B$+STR$(Z1)+"\"

In Microsoft BASIC, the lingua Franca of Ahl's publications, the proceeding space of unsigned positive number values is preserved when the STR$ function is used to convert those values to a string.  I think the original program, based on some version of minicomputer BASIC, probably automatically stripped all spaces from numbers, and just returned the number alone. But the program was re-written for Microsoft BASIC for Ahl's publication, and seems to possibly to have been a little rushed. I decided to add some MID$ treatments to the STR$ function used, in order to make sure the spaces were stripped.

370 A$(K)="^Q"+X$+"^"+A$+MID$(STR$(Z1+1),2)+"^"+B$+MID$(STR$(Z1),2)+"^"

I think the program might have possibly messed up otherwise in its interpretation of the numeric data of those generated strings, although perhaps not, since the final result is processed by a VAL function, which will simply ignore spaces.  But I wanted to make sure that the data was in the same non-spaced format as the original DATA statements for questions: DATA "\QDOES IT SWIM\Y2\N3\"

I also added word wrap so the output of the program, regardless of the length of questions and animal names would be nicely formatted for a 32 character screen.  I suspect that it would be possible for some questions to easily go over the 32 character or even the more standard 40 character limit of most home computers of the day.

So maybe because of its obvious limitations and bugs relatively few people using home computers ever actually typed in this program and played around with it.  Hence, it is not widely recalled or discussed by people on the Net today.  Which is sad because it is an important historical forerunner of modern AI developments and particularly machine learning techniques.