Saga20101126 - simondotm/stardot-wiki GitHub Wiki

26/11/2010: Conditions

Just a quick update as I haven't had much time to work on it at the moment. I've set up the conditions routine (all except for the flags, as I'm lazy). Initially this was set up so each conditions jmp'd to either condfailed or condsuccess. To minimise the size of code I'd set up a couple of branches in the middle of the condition code, so each return would only be 2 bytes as opposed to 3. The reason why the branches were in the middle was due to the branch limit of 127 bytes either way.

The resultant code came out to &F6 bytes - so close to the page limit that a branch can cover! Some code reduction tuning was required. First off, the values to the registers were altered to match most conditions better (i.e. parameter in X and condition code in A; leaving Y reserved). This reduced the size of the code to &E3 bytes.

I can reduce it even more, by using RTS instead of a branch - but I need to think how this can be handled properly. There's also a possibility that I can munge several condtions together (most are very similar in code, e.g. "item present" and "item not present"). Again these need more thought.

The code to handle message responses was also added. The screenshot above is a mocked up one where I added only the code to move an object to the responses code.

So in theory I only have to write the responses handling code now and we should be able to play through the adventure from start to finish. For convenience I need to fix a few bugs in the parsing code (single verbs don't work properly and we sometimes loose the noun if it's unknown) and add the known shortcuts (N, S, E, W, U, D, I). Then there's the graphics code.

Update I've cleaned up the code now; the code for the conditions stands at &B5 bytes - thats a saving of 65 bytes! How did I do this, following on from the above tunings I also:

  • Changed A to contain the location of the object parameter (this is the most common use of parameter), so I could set it before I made the jump.

  • Changed to use an RTS in 60% of cases with a single return point.

The code to do the calling is:

                   lda objectlocs,x         ; as a shortcut

                   jmp setcondret          ; set up stack properly

.jumptable    jmp (bufptr)

.setcondret    jsr jumptable

.condret        beq condloop            ; condition succeeded

                   lda #0

                   sta exitnum              ; otherwise leave

So we use the zero flag to hold the status of the test - if it is set, then the test was successful. The problem here is I had to use a couple of branches for testing the "not" conditions (there maybe a better way, but it's late and I can't think). The branches just set A to 0 or 1, which'll set the zero flag for me:

.failit           lda #1

                  rts

.succeed      lda #0

                  rts

I still need to write the flag code, this may take it back up to a full page :-(

Comments

⚠️ **GitHub.com Fallback** ⚠️