Not quite there

Posted: June 21, 2012 in Commodore 64, Programming
Tags: , , , , , ,

Last post, I told that I’d be showing new layout and stuff, but I have some ground to cover before I get to that point.

I thought that the first thing I should be doing is to create a routine that allows me to position the text using X and Y coordinates, (like the PRINT AT on the Spectrum, or Print @ on my beloved TRS family). Too bad the Commodore’s BASIC doesn’t have this kind of command, so after looking few different options in magazines and books, I’ve come up with this piece of code:

The memory positions 214 and 215 set the cursor position to the respective X and Y coordinates. I tried to create it as a reusable subroutine, using higher line numbers and specific variable names that are going to be used only by the subroutine. Since BASIC doesn’t have the context of scope, all variables are naturally globals so it is important to be sure I’m not using those variable names somewhere else in my code. To help on this objective, I’ve decided to pass the coordinates to print as part of the string, using the format “XX:YY:STRING”. This way the caller code will be shorter and will use less variables. For example:

10 PTR$=”10;20:PRINTING SOMETHING”:GOSUB 60000

The function above (we could call it that way, yes?) is not perfect, since it is always expecting two digits for X and Y, like 01;02. I can improve it later adding some additional checks to extract the coordinates using the separators; after all, this is why I put them there at first place.

Now, I’m ready to use it in my Star Text game! Wait a minute….how can I load this code in there without having to re-type it in?  (I know how! I’m just trying to keep you interested 😉 )


Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s