Hello IIGS Key Events

On my second attempt at writing a game for the IIGS, I am trying to avoid unnecessary challenges. This translates into getting more comfortable buying books and tools to help me instead of trying to “just make do”. It also doesn’t hurt that I like the look of the USB drive that Juiced.GS sells containing The Byte Works’ collection of compilers and books – Opus ][: The Software.

Honestly, buying this turned out to be an even bigger success than I had hoped. After getting ORCA/C up and running on my IIGS, I found the book Toolbox Programming in C by Mike Westerfield in the included collection. This seems like exactly the kind of book I wish I had when making earlier attempts. The first example program went well and I enthusiastically dove into the second one – a program to display the key I pressed as well as any modifiers (Control, Shift, etc.). And my first stumbling block was hit. The code was running (the step and arrow icons in the top right indicate that); but, no display of the key and modifiers was visible.

I spent a while longer than I want to admit (a long while longer than I want to admit) trying to puzzle out what I was doing wrong. Despite my promise to myself of not taking on unneeded challenges, I did not read the manual for ORCA/C (which I’m guessing covers this). Eventually, I sorted out that there are specific windows for specific things.

The graphics I was trying to display were, ahem, located in the Graphics Window. Once I had the Graphics, Shell, and source windows displayed, things were a bit cozy; but, better positioned for success.

I’m honestly not great at translating from decimal to binary on the fly. I could see the flag value changing as I pressed various modifier keys; but, it wasn’t obvious to me which keys were causing which changes. Both Toolbox Programming in C and Apple IIGS Toolbox Reference Volume 1 provide a breakout of all the modifier flags; but, I pulled out just the ones related to keyboard modifiers and assigned each a letter.

I put together a small routine to take in the modifier and print out the above letters when a given flag bit is set.

#define MODIFIERS "^^^^^^^^ASLOCP^^"

void PrintKeyMask(int modifiers) {
  int bit;

  for (bit=0; bit<16; bit++) {
    if (modifiers & (0x01 << bit)) {
    } else {

Works for the Shift key.

And button mashing does not throw it off either.

Overall, this felt like a great first step on the road to writing a game. There’s still plenty more to learn; but, it’s nice to have a paced approach to working through the IIGS toolbox and general program structure.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s