Monday, April 10, 2023

Rescuing my old Commodore Amiga solitaire game...

Note:  This game was and is dedicated to Asha DeVelder, who has since passed away.. 

I once wrote a Klondike solitaire game for my Amiga computer.


Set the way back machine for 1991 or so...

I had my Amiga and my copy of the DICE (Dillon's Integrated C Environment... Matt Dillon - Not that one... The one from Dragonfly BSD!!) C programming software.

To date, I had written a few basically silly utilities (I remember I had written a command line tool that you could point at a GIF file and it would read the header and tell you things about that GIF file.  I know, wow..) but nothing substantial.  

I was also active on FIDONET back then.   That's another story, but basically you can think of FIDONET as an online forum, just over BBSes.  

It was on FIDONET that I "met" Asha DeVelder.  An artist and Amiga fan.  And at some time, she mentioned wanting a simple no-frills Klondike solitaire game.  I was looking for something to do and that seemed feasible, so I said I'd do that...  Even tho I didn't actually know how to play Klondike solitaire. 

So, with my trusty Amiga 500 (it did have 1M RAM and a 20M hard drive), my copy of  DICE (registered!!!), and a set of documents I downloaded on some BBS which were called the Amiga C Manual, I started working on it...

The Amiga C Manual was great because it was full of perfect examples.  Want to open a screen and attach a window to it?  There's an example for that.  Want to add menus?  Yep, there's an example.

So, armed with all that, I started working on this.  And at some point in time, I had a playable product.

Now it is 1992 and I have a program that opens a screen/window.  You have the menu options and you can select NEW and it shuffles and deals out the cards.  You can select (via the menu) whether or not the game stops when you run out of cards or whether you can re-use the deck.  And you can select whether it deals 1 card or 3 at a time, which is apparently a thing in Klondike solitaire (again, I didn't really know the rules).

Now, it was graphical, but not fully...  In that, when you wanted to pick up a card or some cards, you clicked on them and they would be outlined in red (selected).  Then you clicked where you wanted it/them to go and it would move the card(s).  You couldn't actually "pick up" the cards, as in some other graphical card games.  I was planning on probably adding that, but the point of this game for Asha was to be fast and simple, and this worked pretty well.

So I sent Asha the game to see what she thought, and she really liked it.  The only thing she noticed was that there were times when you might not want a card that CAN go to one of the four piles to go there when you clicked on it...   And I had assumed (remember I didn't know the rules) you would ALWAYS want to do that...  I remember I was devastated at hearing this.  I was convinced that would take an entire rewrite!  Oh the humanity!!! (Yeah, it was silly, but I kind of remember that it really threw me off at the time..)
Of course, that didn't last too long and I figured out that I could just have it where if you click ON the card, it does as my game always did and move it to one of the four piles.  But if you click on the column (above or below the card), it would highlight it and let you move it to another column.

I also found a library called Easysound on a BBS that let me add sounds to the game, which I did.

And I found another library called iff.library that let me add a title screen.

So, all in all, it was wrapping up to be ready for a shareware release.  According to my doc file (I am getting ahead of myself here), I was planning on disabling the sound unless you were nice enough to send me $5...  Oh, the early 90s... ;-)

I had sent it to Asha; I had tested it myself and my so did my brother; and at least one other person, Dave G.

And that is where the story stopped...  For a long time...  I apparently never got beyond that.

I never released it as Shareware...  To be honest, I have no idea what happened.  No memory of why I stopped then.  Possibly a hard drive failure and no backups or something???  Life just got crazy?  No idea...  But it stopped...

I had totally forgotten about it until the really late 90s or really early 2000's.  Somehow (I don't recall how), I got back in touch via e-mail with Asha, and she said she still had her Amiga and even still played my game.  That was awesome.  I had long since lost it.  Had no Amiga anymore.  But by then there was emulation.  So I asked and she sent me a copy.  After all those years, I had a copy again.

And then life happened.  My wife passed away and things changed.  Lost interest in it and forgot about it again, for another 20 years.

Then, a year ago or so, my old friend Dave (we had lost contact) saw a post I had made on a Facebook retro computing forum and reached out.  It was great to hear from him, and he mentioned he even thought he had a copy of that old solitaire game I wrote...  I asked him, if he came across it, if he could send me a copy.  He wasn't sure where, but said he would if he could find it...  But that got me interested...  

So I started going thru some of my old floppy disks.  Well, I went thru over 100 of my old floppy disks.  These were all PC floppies.  I didn't have any of my old Amiga floppies.  And on floppy 75 or so, I found a file called klon.zip...  Hmm....  Opened it up.  Yep, it was the binary for my old game.  I am guessing this was the version Asha had sent me...

So I fired it up in an emulator.  Worked great.  Fired it up in my Amiga 1200 (Yeah, I have one of those again) and it still ran great (which was impressive to me, as my 1200 is running the new OS 3.2.2).

Wow, this is some serious nostalgia...  Went thru the rest of the floppies, but nothing else...

Then, when going thru other stuff (triggered by my going thru all my old floppies) I found a folder, and when I looked inside, there was my C code for the game!  No, not on disk. On paper.  Apparently I had printed it out!!!

And in that moment, I decided to recreate my game.

I scanned and OCRd the source code.  It seems like it was maybe 95% accurate, which was great!  

The only things it had issues with were characters like (), {}, [] and 1, l, and I...  And apparently it sometimes didn't notice semicolons...  Or added spaces between /'s and *'s.  So, other than that...
And if you know anything about C, you are dying right now...  ;-)

But I wasn't deterred.  I also saw that I used three .h files, which I didn't have.  One was for the menu structure, one for my "About" requester/window, and one was for the playing card graphic data.  BUT, remember, I have a working executable.  So I can use that for reference for rebuilding the menus and requester, and I should be able to rip the playing card graphics...

And I am going to do this all on the Amiga...

I load up DICE (that took a while, as I was REALLY rusty with C).  I load up my code.  I try to compile it, and it fails miserably, but it is what I expected based on the OCR.  So I start compiling, failing, and fixing...  I also disabled the sound, title screen, About requester, and card graphics.  I quickly created a basic stub menu file.  And kept working on it...  Lots and lots of work...  Comparing to the printout...  

I was starting to think that I should have just retyped the whole thing...  But finally, after a LOT of correcting, I ran a compile that had lots of warnings, but no errors...  What?  Really...  So I run it, and..

The game screen comes up!  Woo Hoo!

Now I have to rebuild the menu.h file.  I know I used the Amiga C Manual ( a collection of docs and example files that was going around the BBS scene back then) to build this game, so I check online and find a copy.  I get to the section about menus and yeah, it's call to load the menus matches the call I have in my code.  Using my working executable as a guide, I add the menus in, one item at a time.  I was really rusty, and the checkmark menus gave me some trouble (I needed to add a flag MENUTOGGLE that I used and it wasn't in the Amiga C Manual.  Luckily, there are lots of other good PDF books online!!), but I eventually got my menus working.

So, fire up the game, go the the NEW menu option and bang!  Cards start drawing!  

Well, OK, they don't "draw" as I have graphic drawing disabled, but I see red or black letters drawing!  In my game, I would draw a blank card of whichever suit, and then I'd add the value as a letter/number in the corners.  I didn't have the cards, but I would still see a red Q in the top-right/bottom-left of where the card graphic WOULD be!!  Now, what I hadn't noticed was that it wasn't doing all that properly.  It was dealing out the cards as one row across, not as one card on the first column, two on the second, etc..  But still...

So now I moved on to working on my card graphics.  On my Amiga, I launched the binary of my game that Asha had sent me and chose NEW so there were cards on the screen.  Then I loaded Personal Paint and went to GRAB the screen from my game (that is a nice feature in Personal Paint).  Then I grabbed a card as a brush.  When I go to save the brush, one of the options is C code.  Great!

Then I remembered that my cards needed to be blank!  I print the value after the card is drawn.  So I took each suit and removed the value (Q or K or 10 or whatever), so I had JUST empty suit cards.  Then I grabbed a copy of the back of the cards (card face down).  And I grabbed some empty space that was card sized.  Saved those all as C code.  Merged them and did some editing and cleanup, and had my cards.h file.  

And..... It didn't work...  ;-(

I re-enabled the card drawing functions, and was getting an error.  Hmmm...

OK, DICE doesn't like the card data that was exported from PPaint...  Did some checking and reading of doc files...  Noticed that the example of drawing a graphic from the Amiga C Manual was giving me the same error... Hmmm...  And, finally I tracked it down...

The examples in the Amiga C Manual and Personal Paint's export have a line that says "USHORT CHIP" to define the memory type, so it goes into CHIP (graphics) memory for the Amiga, and my compiler doesn't like that.  I can take the CHIP out, and I don't get that error, but that would mean my game would only run on an Amiga with ALL chip memory...  Hmm... I do some more checking and there is a compiler option to put the whole program in CHIP, but that's not a great solution...  Then I finally find it in the DICE manual.

DICE wants it in the format "__chip USHORT"  and not "USHORT chip" <sigh>.

So I do that and get past that error, and... I get another error about the DrawImage function.  Hmmm.. That is built into the Amiga...  How can that be erroring out?  I can get the Amiga C Manual example to compile and that uses DrawImage...  So it should be working....
LOTS of trying to figure this out... And then I finally see it.  

It isn't complaining about DrawImage being undefined.  It is complaining about Drawlmage being undefined!!!  An l (lower case L) instead of an I (upper case i).   Another OCR glitch!!!!  I find that the majority of my DrawImage calls were wrong in that way...  OK, so I fix that...  Get a clean compile...  Run it, and as it draws, there are my HEARTS cards!  (I started with just hearts)  I still haven't noticed my other issue.  But I then go in and re-enable all the other cards...  Compile it, run it, and Woo Hoo!  All my cards are drawing as cards!!!  

And... (then I see it)

They are drawing straight across...

OK, is this a code glitch?  I mean, I am working on a printout that I don't know if it is the final version.  I don't remember what the final version was, because I never got to final really.  So now, I start going thru the code.  What routines are being called when it is happening?  It's been 30 years, and even tho I had comments in my code, it's not that easy to just figure it out...  But, after multiple hours looking at code and comparing it to my printout, I think I see something...  Is that an == where there should be a != ?  There are some == above and below, so I need to make sure, and .... Yep!  That is wrong!!
That was apparently a combination OCR and human error.  The OCR messed up a few "==" or "!=" as just "=" or "1=" or "]=" or something similar, and apparently when I "corrected" that one, I got off the line I was looking at in the printout and fixed it with "==" instead of "!="...  <sigh>  

So I fix that, compile it, and run it...

 And there are my cards, being dealt out the way Klondike solitaire should deal them out!

Next I go to tackle the sounds.  I know I used Easysound before, so I go to Aminet and download it and.. er..  that doesn't look right..  Yeah, this is a much newer version...  Doesn't work the same way...  So I start looking, and hey!!  I didn't see that before...  My copy of the Amiga C Manual has an older version of Easysound in it, and that version looks the same.  So I use that and enable the sounds, compile it with the -leasysound.o option, and it compiles!!!  Run it and...

Now I can hear it as the cards get dealt!!
(Memory flashback trivia... I remember the sound I used was originally a gun firing sound that I slowed down and chopped a bit to make it sound (ish) like a card being dealt...  Not sure why THAT I remember...)

OK, on to the requester for my About window.  Again, the Amiga C Manual has examples that are similar, so I get to working on that, with my original (Asha sent) version up on my emulated PC for comparison...  And eventually I get it mostly the same.  I notice my window has a 3D-ish effect with the border being lighter on the left/top and darker on the right/bottom and my new requester just has one border set all the same color...  Did I really do all that work to setup multiple linked borders of just two lines each in different colors, or is there a FLAG for that?  Checking, and nope... I apparently did it the hard way...  So I go about doing that for my requester too.  

Done, and it does look much nicer, so ... worth it..

And now, I just need to get my title screen picture working.  My intro comments on my code said I used a library called iff.library for that, so head over to Aminet and... yep, it's still there...  Grab it and...  er.. this also looks different..  Yeah, much newer version and it doesn't compile.  (Note: the library does "work" in that if I install the new iff.library in my Amiga LIBS: directory, my old binary shows the pic.  It's just the new version of the C support files don't work with my code to compile.)  I do some checking and can't find the older version that I used... <sigh>  I know my game works with the newer version, because when I copy the iff.library file to my LIBS: on my Amiga, my old game shows the title screen pic.  OK, so, what is the difference...  A bit more reading on the new iff.library and ... apparently it was changed to avoid conflicts with the newer Commodore IFF libraries...  But function wise, it is backwards compatible...  Just I have to change some function calls...  Luckily, not too many...  Compile..  Ooopps, missed one..  Changed and compile and oh... it compiled...  Run it and...

There's the title screen!  Try playing the game.  Works...  Sound on, works.  Sound off, works.  About requester works...

Game is fully working!  Tested on my Amiga 1200 with new OS 3.2.2 and works.  Tested on virtual Amiga 500 with 1.3 and works!!

So, I again have my executable version of my game AND I have the C source code with additional files so I can work on it.

Which is good because I did remember it had a bug.  It's in the way I was interacting with those checkbox menu items.  It works, as long as you don't select more than one at a time, which the OS lets you do. (I remember my brother found that one...)

**So, fixing that will be for a later time... ;-)

Also, in the mean time I did some googling and found another Amiga Klondike solitaire game that was released about the same time...  And it's nicer than mine.  Wouldn't surprise me if that played a part in my never releasing my version...  Gotta be quick in that biz apparently.  ;-)

Anyway, it's working and I can continue to work on it, so I decided to do what I didn't do in the past:

http://68k.aminet.net/package/game/think/Klondike92

I have released it to the public!  

Yes, I of course removed my asking for a shareware donation, although I left the text of that in the DOC file (commented for context), because I am really releasing it as a kind of historical document of what I had done and was thinking at the time.  ;-) 

So, if you have an Amiga or an emulator, you can give it a try.  It's not the best Amiga solitaire game...  It's not the second best, and I'm pretty sure not the 3rd or so....  But it works and I think it's decent and a good start.  It had promise. ;-)

And that's now one thing I hadn't done in the past, that I finally have... 32 years later.

---

** Later time has arrived. ;-)

The menu bug(s) has been fixed.  There were actually two issues.

One, there is a way to step thru multiple menu selections, that I didn't know about. 
But when I fixed that, there was still an error if you selected something in the Options menu and then (while still holding down the menu button) tried to select something in the Project menu...
Turns out my nested menu check concept doesn't work with multiple menus.  So I had to rewrite it to have just one while loop to check all menu hits, and then evaluate which menu/menuitem was selected and do the appropriate action.

That is now done and updated on Aminet, with source code included!


Tuesday, May 8, 2012

Introduction/Retro History

Where to start?
My first home game system was a pong clone.

My first home game console was an Odyssey II by Magnavox.


And my first real introduction to computer theory that I can directly tie-in was:
The Cave of Time, by Edward Packard


Yes, it was a book.
Specifically a "Choose Your Own Adventure" book.

I might not have read the whole series, but I read every one I could find...
The interactive, yet thoughtful, process was more appealing to me at the time than K.C. Munchkin on the Odyssey II.
(And I loved K.C. Munchkin....)

My first home computer was a Commodore VIC-20.

Yes, it had games, but it also had BASIC.  A language I could use to control the computer.  Not just having fun with software that other people wrote, but writing my own.  Creating my own games.
And my first game?

The beginning of "The Cave of  Time."
It was perfect.  "Print" statements and GOTOs..
I told the computer what to do, and it did it.  I understood what it was doing.  And, I figured it out by myself, with just the manual that came with the computer.  This was something that I understood; it made sense to me.

Why just "the beginning" of the story?  No, it wasn't the lack of computer memory; although the VIC-20 only had about 3.5K usable RAM.  It was storage..
I had none..  ;-)

At the time, I didn't have a tape drive and definitely not a disk drive.  When I turned off the computer, I lost what I was working on....  That has a way of limiting what you want to do..

Nevertheless, I was hooked...

I had a physical representation of what the computer program was going to be in that book.  Basically, it was the most detailed design document ever.  ;-)

That was really the start, and I never looked back...

I eventually did get a tape drive, but by then I was working on my own really bad games (I'm pretty sure the first one was a choose-your-own-adventure type that involved a dragon..) or typing in games from books/magazines.

I loved the type-in BASIC games..

Now, it would be awesome to say that I got more and more into programming; learned assembler, and I'm now working in the games industry.
That's not what happened.

I continued my programming and computer interest.  Moved to a Commodore 64.  Then an SX-64.  Then an Amiga 500 and 1200....  (More on those at a later date)

And while I did a fair amount of programming, I found that as a programmer, I was a great system/network administrator.

So I spent time working on payphones, phone systems, computer networks, midrange computers.  I did some database and C programming here and there, but it was pretty obvious to me that I didn't want to program for a living by then.

But I understood (to a point) how the computers worked.
And when networking came around, I understood that...

So, I'm still working in the industry.  Playing with Linux and Windows 2008 servers, switches and routers, ITIL and other acronyms.

And when I go home, I sometimes still fire up the Vic-20 or the O2.
I have a batch of Amiga computers...

I enjoy my work, but never lost the fun I feel working with the older systems.

There's something about those older systems..
They don't do everything for you.  But you can generally get them do what you need with a little work.  I think it's that balance that I really enjoy.

It's not point and click easy.  I have to think about it and work on it.
But it's not assembly language hard...

It's that middle ground that seems to be exactly what I enjoy the most with my technology.  I appreciate technology that is smart and smooth enough to appear transparent.  But, I would rather interact with my technology in a way that there's a bit of work involved.  So that when I do something, I feel pretty good that I got that to work.

There's also the nagging feeling that, for some reason, we haven't advanced as much as I think we should have....  I suppose there will be more on that later also..

Anyway, that's me, as a technical history overview...

I can fill in the blanks over time...