Sunday, 3 November 2013

Sandy White's Ant Attack ported to the Sinclair ZX81

Conventional wisdom is a funny thing; "Money doesn't grow on trees"(1), "Never look a gift horse in the mouth" and "You'll NEVER get a anything near a decent version of Ant Attack on the ZX81" are three well-known sayings that some people will heed, especially the last. So, what happens when someone attempts to fit Sandy White's sublime classic game into the meagre amount of memory and limited resources available on a ZX81 with a wobbly RAM pack? Could it really be possible?

This is exactly what Bob Smith has done. Screw this conventional wisdom nonsense - let's make something happen must have been Bob's thought process here. After many months in the making, and just in time for Halloween 2013, he released Ant Attack 81 with the blessing and help of Sandy. So, what do we have here? Has this highly improbable game converted to the blocky and monochrome 8-bit personal computer done well enough to say that all of the work has been worth it?

Ant Attack 81 splash screen

I have to say that it's a resounding YES! To use a term that is used by younger folk than me, Bob has SMASHED IT!(2) From the stylish and blocky visuals, to the isometric scrolling, ravenous and scary giant Ants and most importantly of all the game play, this is everything that the original was without the high-resolution graphics. ZX81 fans will be chuffed to bits, as will many of those who consider the original game such an enduring classic. Best of all, it's available for non-commercial uses to download right now. If you don't have a ZX81 then fear not as a quick Internet search will find you a decent emulator (I use EightyOne here).

Ant Attack 81 in-game screen

(1) Scientists have found traces of Gold in Eucalyptus Trees - source.

(2) This apparently means "rather resplendent" or something like that.

Wednesday, 2 October 2013

String [ ] args

I'm about to delve into the world of C#, an Object Orientated language heavily influenced by Java, on my current studies at Birmingham City University. And as happened when I attended the Foundation Degree in Enterprise Computing (or Computer Enterprise - I don't recall which way about), we're starting from the ground and working up. This is good even at MSc level because, for whatever reason, programming and software development are subjects that seems to have many people confused. As far as I'm concerned, it's Databases that's the difficult bit; in comparison to this particular field, programming is relatively easy. (I said relatively...)

One that that I wondered with Java is why String [] args in the main declaration? It wasn't until the second year of the Foundation Degree that this was explained. You see, before Windows, Workbench, STOS, GEOS and othe GUIs, there was DOS (and before that, CP/M I think), and as this still exists to a fashion even in Windows.

Anyway, String [] args is in there in C# and allows you to pass arguments or parameters to your Command Line application. Sometimes you don't need to make a Windows-based application. So, how does it work?

Firstly, let's open up Visual Studio and make a C# Command Line application. It should give you some source code to get started, which will look something like this (notice that I've called my application TestConsoleApplication):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApplication
    class Program
        static void Main(string[] args)

At the moment, the Main is the entry point of the application, and it doesn't do anything yet, so let's add some code there, like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApplication
    class Program
        static void Main(string[] args)
            /// Sets the title bar on our console
            Console.Title = "Using Command Line... Like a DOS!";
            /// Set up a integer in local scope,
            /// initialising it to zero
            int counter = 0;
            /// Clears the console, like cls
            /// (CLear Screen)
            /// Checks if there's any arguments first
            if (args.Length > 0)
                /// If args has been added, then we'll loop
                /// through each one
                foreach (var arg in args)
                    Console.Write(" ");
                /// Escape string for newline
                Console.Write("\nNumber of arguments sent: " 
                              + counter);
            /// Here's a generic message, like "Hello World"
            /// or whatever. Note: WriteLine adds a carriage
            /// return after writing the text
            Console.WriteLine("I can do Computers me!");
            Console.Write("Press the Any key to exit...");
            /// Wait for key-press
            /* FIN - Exit application */

So, in Visual Studio, you have to build your solution before it will run: if you make changes without building, the compiled .exe will be the last build (and if you haven't built anything, nothing at all). Once built (and by default, it'll be a Debug version unless you state Release), you can run it from Command Line.

In my case, I put all my development stuff in C:\development\ - if it's PHP, there'll be a sub-folder in there called www, but this is windows, so that's the name of my sub-folder.

The path to the build in my case is c:\development\windows\TestConsoleApplication\TestConsoleApplication\bin\Release. From your start menu, type cmd.exe and navigate to your solution (if you've built a debug version, it will be in \bin\Debug not \bin\Release as here). If you type:
c:\development\windows\TestConsoleApplication\TestConsoleApplication\bin\Release> dir *.exe

and press enter, you should see your built solution. In my case, it's called TestConsoleApplication.exe - so type your solution name in (I think the .exe is optional) and press enter.

As you've not sent any arguments to your solution (or program, or console application), it will not display anything. Try again, but this time, after the solution type Hello World and see what happens. Try any number of words or numbers, like The Quick Brown Fox Jumps Over The Lazy Dog and see what happens.

Okay, this is a trivial example, but it means that you can set any number of parameters in your program with a bit of thought. For instance, you could use a shell sort to display each argument alphabetically, but I'll leave you to think how one might do that.

Monday, 30 September 2013

Teething problems.

Well, after the confusion over my time table for the MSc Computing at Birmingham City University, I find myself in a nightmare situation of having to study Databases again; a subject that I don't get on with, that is confusing and much too high brow for me.

On Friday afternoon, just before leaving work, I discovered that the Database for Enterprise was scheduled for Monday morning at 9am. This was obviously short notice (especially for my employer), and to add insult to injury, the lecturer has not yet turned up nearly 30 minutes after the lecture was due to begin. I hope that this is teething problems, but with the lost time already (as there wasn't a lecture last week apparently), it's looking increasing unlikely that this will be a module that I'll pass because there simply won't be enough time left to cover everything that I need to know if we're running two weeks behind the proposed schedule, especially as I don't have access to the teaching material associated with this module.

Thursday, 26 September 2013

Now linked.

If you're reading this through BCU Moodle/iCity or whatever it is and wondering how I got so many posts, well I linked my Moodle blog to my Gaming and Technology blog. Most impressively, considering how useless the SharePoint interface usually is, it actually works! Oh, and you may have just got a lot of SPAM to your bcu mail account - sorry about that.
Anyways, today was my first lecture on the MSc Computing, and it's my favourite subject too - computer programming and software development. I'm really going to enjoy this C# stuff I think.
I emailed the lecturer Steve about a site which goes some way to explaining how computers do mathematics, and why you may end up with rounding errors - the link is, and I recommend it for all budding developers. Although this sort of thing may go beyond the scope of the module, if there's any interested programmers and developers who want to chat about more advanced programming topics then just nudge me. Whatever my Uni ID says, I use my middle name (just to confuse everyone) - don't be shy as I don't usually bite.

Hello World... again.

Yet again, I find myself a student. This time, it's at the Birmingham City University, and - oddly enough - I'm studying MSc Computing.
Today was my first lecture: Systems Development, or more precisely, C# Programming, and even though it's a Masters, there's still the need to go through the print "Hello Mum"; or whatever to get the basics of the language. Thankfully, I had some writing to do though, so I sort of did that during the lecture. So, look out for news of a Pitfall clone for the Commodore VIC 20 and some ZX Spectrum and Commodore 64 news in a Micro Mart issue soon.

Friday, 14 June 2013

Working with percentages

I wouldn't say that I'm the best mathematician; if I'm being generous, my skills in the maths department is somewhere about average which isn't always a good place to be for a programmer. But what I lack here I make up for in understanding of how computers work and how to program them, and this is what acts as a stabiliser against the wrath of BODMAS and such like.

So, I've been working on a project for a client which in part has to work out percentages of a price, like adding VAT levied by the Government on saleable goods. Now, this is actually the easy bit. VAT, at the time of writing, is 20%, so if an item costs £100 without it, that item will be £120 including VAT. So, writing the code for this is simple: take the current price, work out 20% and add that to it. Or, multiply the current price by 1.20, which does the same thing.

Writing the code for this is easy, in a C-like language, it would be something like:

float price = 80.00f; // assuming £80.00p
float priceWithVAT = price * 1.20f; // This is a quick way to add VAT @ 20%
// So...
printf( "Price ex-VAT: %.2f", price );
printf( "Price with VAT: %.2f", priceWithVAT );

Great! Assuming the VAT rate will always be 20%, this will always work. But not long ago, VAT was at 17.5%, and before that, which dropped temporarily to 15%. Now, let's say that you want to work with different percentage rates, or the rate unexpectedly changes. Something like the following will work:

 * A quick demonstration of working out percentages using C
 * will probably work on all other problem-orientated languages.
 * Written with Code::Blocks, tested on Windows 7 and cmd.exe
 * @Author:     Shaun B
 * @Version: 1.0.1 - 2013-06-14
 * @Todo:       Look into floating point guides and why
 *              there are rounding errors

/// Remove the white spaces as the Blogger engine thinks that
/// I'm trying to do HTML tags called stdio and stdlib :-/
#include < stdio.h >
#include < stdlib.h >

/// Function prototypes:
int main();
float percent (float pc);
float taxToAdd (float number, float percent);

/// Variables:
float taxRate   = 20.00f;     // ie VAT, PAYE etc...
float percentage = 0.00f;
float taxToPay  = 0.00f;
float priceWithTax = 0.00f;

int main()
    float originalPrice = 59.99f;
    unsigned char pound = 156;

    percentage   = percent (taxRate);
    taxToPay    = taxToAdd (originalPrice, percentage);
    priceWithTax = originalPrice + taxToPay;

    printf("Tax rate set to: %.2f\%%\n", taxRate);
    printf("Original price of goods less tax: %c%.2f\n", pound, originalPrice);
    printf("Tax on goods: %c%.2f\n", pound, taxToPay);
    printf("Total payable: %c%.2f\n", pound, priceWithTax);

    printf("Fin. Press any key.");

    return 0;

float percent (float pc)
    return (float)pc/100.00f;

float taxToAdd (float price, float percent)
    return (float)price*percent;

Things should be fairly self-explanatory here. This example means that if your tax rate changes, you only have to change one variable rather than tracing all of the instances of *1.20f in your source code. This makes it easy to set percentage rates for other taxes, levies or fees that a client may encounter. The only problem now is what to do with the third decimal place, say if something works out to be £17.8555 with fees or taxes added? I think things are usually rounded up though. Note that the £ sign doesn't appear on my computer here - all of the documentation online says that it should be 0xa3 (or 163 in human), but I found it to be 156 (or 0x9c in hexadecimal) on this Windows 7 machine.