Commentary: Simple Item swap actuator

Under construction. Contain SPOILER. Last Update: 2010/11/01 22:35 +0900

Overview

Here is a top-view of his map.

3 steps.

1. Look at the alcove.
A green gem is at alcove.
2. Push a button next to the alcove.
3. Check the alcove now.
It is transformed to a worm round!

 

Map structure

At first, check the map structure and misc. parameters.

Yellow block means Floor.
Blue block means Wall.

DSA … location of DSA actuator.
A … location of Parameter A.
B … location of Parameter B.

Look at his DSA program. It is the program which you are interested in.

 

S0: "L0 LA L1 &NEG L1984 F &DUP L0 &SWAP &< ?JC0"
C0: "&TYPE L0 LB L8 L1984 F &TYPE &= ?JT0"
T0: "L1 LA L0 LB L2 L1984 F &ADD L0 LA L1 &NEG L1984 F LA &DEL"

Meaning of state "S0"

Scan at the alcove to find an Misc Item. If there is an Misc Item, go to the state "C0". Otherwise, DSA program finishes.

The following sections are to explain meaning of every code bit.

Basic stack operation

DSA uses "stack" algorithm to store temporary variables. CSBwin built-in features also use stack to interact with DSA program.

DSA's stack only stores "integer value" such as 1, 2, 0, -1. It won't store any of decimal/text/pictures/etc.

Finally the code "L0 LA L1 &NEG L1984" pushes 4 values at stack.

Code explanation.

  1. "L0" pushes a value 0 at top of stack.
  2. "LA" pushes a value of "Parameter A" of DSA actuator.
    If you have question for 498, see appendix.
  3. "L1" pushes a value 1 at top of stack.
  4. "&NEG" changes the sign of a value. Target value is always at top of stack.
    A value 1 is changed to -1.
  5. "L1984" pushes a value 1984 at top of stack.

Operator

Frankly speaking, next code "F" pops 4 values from stack, then pushes a value to stack.

More about "F", look at the reference of "F".

In this case, we assume that a greem gem is at alcove:

  1. DSA scanned any Misc Item at alcove. "F" popped 4 values because they were scan options.
  2. The scan was gone. An item "green gem" was matched. The item ID was 4.

&DUP

"&DUP" duplicates a value at top of stack.

Look at the reference of "&DUP".

L0 &SWAP

  1. "L0" pushes a value 0.
  2. "&SWAP" swapped 2 values at top of stack.

&<

4 is greater than 0. The criterion is satisfied, thus 1 is pushed, otherwise 0 is pushed.

In this case, there was a Misc Item (green gem) at alcove.

Remember, we assumed an green gem is at alcove. And "F" found a Misc Item. The item was marked as indirect index number "4". So "4" is pushed as item ID.

 

In this case, there was no Misc Item at alcove.

If there is no item at alcove then, "F" should have pushed "-1" instead of "4".

"-1" is less than "0", thus "0" will be pushed.

 

?JC0

 "?" is the operation to branch the running program. See reference of "IfElse".

Separate to 3 parts.

Part Meaning
? IfElse operation
J If xxx is satisfied, jump to ...
C0 column C0

IfElse is very easy to understand.

Generic IfElse consideration

?JC0 case

After "?" operation code, you specify "J" or "G", or ommit it.

Type of branch Working
JUMP Next run is at other column. (Such as S0/T0/C0)
GOSUB Next run is at other column.
However if you finish at branched office, you'll return here to continue rest DSA program.
CONTINUE No-branch occurs. Continue rest DSA program.

To understand what is "Yes" and "No", look at following figures.

In this case, the Misc Item (green gem) is at alcove.

In this case, there is no Misc Item at alcove.

 

Meaning of state "C0"

Verify the item at the alcove is a green gem. If surved item is a green gem, then go to state "T0". Otherwise, program finishes.

For example, if you surved a worm round, then program finishes.

Meaning of state "T0"

...

Appendix: Location and Integer

Location is always represented as Integer.

The absolute location is "level=6, x=15, y=18".

This would be an integer "498"?

You can convert the values between Binary and Integer. Use windows CALC.