Alien Experiment Laboratories

November 27, 2006

Z88dk and C gotchas - episode 1

Still working on experimental stuff (partly to get the hang of Z88dk, and partly to scrape the rust off my underutilized C-coding “skillz” before doing anything important), I got stung by a nasty little gotcha.

I created a source file, 2player.c, which is expanding on the first bit of z88dk/Spritepack 3 code I wrote, to have two graphics on screen, both player controllable.

Every build attempt met with this error:

zcc +zx -vn 2player.c -o 2player.bin -create-app -lsp1 -lballoc
1 errors occurred during assembly
Errors in source file 2player.c:
File '/tmp/tmpXXTIgPHd.opt', at line 10, Illegal identifier
make: *** [2player] Error 1

Ouch. Where’s the error? Line 10 is in the middle of my descriptive comment section! This is meaningless!! Eventually I stripped out just about everything to the point where it couldn’t possibly NOT compile and…still the same error! WTF?

Then it occurred to me: somewhere in the build process, perhaps the filename is being used as an identifier. And perhaps identifiers starting with a number are illegal. A quick rollback to the proper code I’d written first time around (Vim 7 undo rocks!), rename to twoplayer.c and the bugger builds first time.

Attempting to run the thing resulted in a spectacular crash, but at least it built! Now for some trial and error debugging (my kingdom for a z88dk equivalent to gdb). I look at the pointer stuff first and find that it doesn’t like the following code:

for (p = 0; p != 2; p++) {
    player[p]->sprite = sp1_CreateSpr(sp1_SprId2Type(SP1_ID_MASK2_LB) | SP1_TYPE_2BYTE, 3, 0, 0);
    sp1_AddColSpr(player[p]->sprite, sp1_SprId2Type(SP1_ID_MASK2), 48, 0);
    sp1_AddColSpr(player[p]->sprite, sp1_SprId2Type(SP1_ID_MASK2_RB), 0, 0);
    sp1_MoveSprAbs(player[p]->sprite, &drawarea, man + 16, 10, 14, 0, 4);
    player[p]->frameoffset = (uchar *) 0;   /* no frame offset */
    /* make sure player[p] isn't in motion */
    player[p]->dx = player[p]->dy = 0;
}

Changing it to this code (with the appropriate pointer-to-player-struct declared at the top of main()) gets over that speed bump, by pointing a pointer at the array element and then using the pointer instead of the subscripted reference. It’s not clear why the first fails and the second appears to work. I probably need to go read K&R again…

for (p = 0; p != 2; p++) {
    pl = &player[p];
    pl->sprite = sp1_CreateSpr(sp1_SprId2Type(SP1_ID_MASK2_LB) | SP1_TYPE_2BYTE, 3, 0, p);
    sp1_AddColSpr(pl->sprite, sp1_SprId2Type(SP1_ID_MASK2), 48, p);
    sp1_AddColSpr(pl->sprite, sp1_SprId2Type(SP1_ID_MASK2_RB), 0, p);
    sp1_MoveSprAbs(pl->sprite, &drawarea, man + 16, 10, 14, 0, 4);
    pl->frameoffset = (uchar *) 0;  /* no frame offset */
    /* make sure pl isn't in motion */
    pl->dx = pl->dy = 0;
}

Referencing the players array via a temporary pointer like this, the program builds and runs exactly as designed.

November 26, 2006

Oh no, not another Learning Experience!

This week, I have mostly been eating…Z88dk include files.

Learning Z88dk and Sprite Pack v3 is definitely not for the faint of heart. Never has the phrase “the source code is the documentation” been so entirely apt.

It becomes even more fun when you realize that the comments in aforementioned source code, as well as the accompanying examples, are not always the best in the world. Fortunately there aren’t too many major areas which need to be understood.

I’m focusing on sp1.h (Sprite Pack), input.h (keyboard/joystick), spectrum.h (general Speccy stuff) and sound.h (beeps and FX) and putting together a simple example program which will allow you to move a sprite around with the keyboard, complete with actual useful comments that I can refer back to at a later time.

On that note, watch this space for something resembling a how-to/tutorial series. Same bat-time, same bat-channel, and so on.

November 19, 2006

Getting SevenuP to work in Ubuntu.

This isn’t the gosh-wow-amazing-awesome post I’ve been working on. That, like a 2-month-old iPod, became obsolete when I figured out a way around my graphic editing problems that didn’t involve writing a script. Well, not a big script, anyway. This is another one, though hopefully it too will prove useful to someone.

Getting SevenuP to work in Ubuntu was being a real PITA. The binary version would crap out with “library not found” type errors for the WxWidgets stuff, and building it from source got nowhere either.
Read the rest of this entry »

November 12, 2006

Pimp my site!

This week’s progress has been entirely related to the appearance of the site.

Gone is the old, off-the-shelf look, replaced by what you now see. Certified Firefox, Opera, Konqueror and Safari friendly, looks pretty decent on IE5:Mac with only a few minor breakages, looks OK on IE6 and IE7 too, though there are a couple of bugs to be squashed in both (nothing new there, though IE7’s misdisplaying of some elements is very disappointing).

If you’re using a text browser it should be all nice and semantic. I had visions of removing a lot of the classes and using child/adjacent selectors instead, but it made my head hurt. ;-)

November 5, 2006

All quiet

Nothing much of postworthiness this week. (Apart from spontaneously inventing a new word, “postworthiness”. Go me.)

I am working on something interesting to be posted, but it’s not ready yet. I’m also thinking on re-theming the site. I consulted the project manager for their take on events and they had this to say:

What does the future hold?