• Pinacolada's Projects

  • by Pinacolada

Wherein I enlighten you, dear reader, on the status of my many eclectic hopes and dreams for Commodore projects.


ML musings

Thoughts on and explanation of some assembly routines.

Recently, I managed to add a flag to my disk input routine: it puts a specified number of bytes into the 1st defined variable, but can do one of two things:

  • skip carriage returns (incorporating them into data read - this flag was developed because of problems loading a binary blob of player stats: 13 could be a valid stat, truncating the player data!)
  • or stop reading data when a carriage return is encountered (useful for SEQ files, or room description data, stored in indexed REL files).

I'm working with Agent Friday to realize a routine which I think will make interacting with/creating NPCs later in the game easier: %-substitutions (a concept borrowed from M$-DOS batch files). Ultimately it may make text output easier as well (not so much string splicing from BASIC). It works something like this:

"Hi, %n. How are you?"

The %n above would be replaced by the main character's name, displaying

"Hi, Pinacolada. How are you?"

(It occurs to me that maybe using $ instead of % would be better, since it's really an array of string variables to be printed - internally, character names are stored in the A$(0-4) array.) I'll stick with %-substitution for now, though. More command characters could be added later. One I'm thinking of is a forward slash for things like "/t" to output a tab character, "/r" for a new line... sort of like the "bash" shell in Linux works (modified for our C64, notcherwelly... pardon me, I've dropped my monocle in a snifter of warmed brandy, tsk.)

So far my collection of ML routines encompasses:

Syntax                                                     BASIC variable
SYS 49152,"search_thru","search_for"                 instring    (is)
SYS 49155,
<channel_number>,<byte_count>,<crskip>    input any    (ia)
SYS 49158,"filename"                                module 64    (ml)

The instring function works much like the Commodore 128's namesake, returning in I% the position of the matched string, or 0 if not found.

Input Any is by Jim Butterfield, returning number of bytes from in the 1st-defined variable as discussed above.

The flag is already making things easier on me, although I do have to re-factor my code when getting level information data (# of rooms on each level and the level name - have to switch between clearing the flag, get a certain # of bytes, then set the flag to retrieve the room name, stopping at a carriage return. Shouldn't be too hard.

Module 64 is an interesting solution to a perennial problem of exhausting memory on a large program: break it into modules. Lines 1000- are kept in memory at all times, and you can load lines 1-999 from disk (I use the current device, PEEK(186) or $BA) and it is re-linked to the "kernel" (commonly used subroutines, the "parser", various checks and messages being output, plus much more as the game continues to evolve). Plus, variables are preserved between loads.

I have also linked a POP routine to clear the most recent GOSUB off the stack, since the original Apple code used it about, oh, 200 times. Poor programming really, but I might as well include it in case I ever get written into a corner, so to speak.

Leave a Comment

You must be signed-in to post comments.