Closed thecodewarrior closed 6 years ago
LAST
conforms to TIS-100 specifications.
Are you against possibly adding a ROT
command (don't like the name, but all I could come up with on the spot), or some other similar command, that can rotate the LAST
value so you can do this kind of stuff? That's all that's really needed. To cross over signals you just do this:
MOV ANY ACC
ROT 2
MOV ACC LAST
That's an interesting approach to making programs more reusable! I've actually been pondering adding a simple #define
preprocessor macro with that goal (so you could #define PORT_IN LEFT
and then do MOV PORT_IN ACC
e.g.), but couldn't come up with a nice way of keeping that reversible (for copying back to the code bible) without keeping the "raw" input around, which is... meh, as I'd like to have the macro processor bound to the code bible.
I would like to avoid modifying opcodes from the original specification, but I'm pretty open to adding new opcodes. One to modify LAST... hmm, if it's write-only, why not. Though some other name would be required, yeah, since ROT sounds way too shift with wrap. Though I can't think of something nice right away, either.
I know I am very, very late to this discussion (I somehow managed to miss this PR for over a year), but maybe for the opcode name consider TURN? If you're thinking of the LAST register in terms of the physical directions, and visualize it as an imaginary knob pointed in a specific direction, it is the kind of thing someone might have come up with in the hypothetical alternate universe TIS-100 comes from, and in my opinion it doesn't really collide significantly with related concepts.
All right, added both support for defines (e5bb9ebe6eea13e3e0ff989301faa46dddc2b098) as well as two new instructions to manipulate LAST
, RRLAST
and RLLAST
, rotating the value one to the right or the left, respectively, unless it is NIL
in which case it does nothing (6e3b48312d21243f97b547d0a3dbec7e7130b5a9). Yes, it needs two ops to flip LAST
by 180 degrees, but I'm fine with that given how much simpler this is on all ends.
I was thinking about the
LAST
port, and was wondering if it could be made even more useful, so I decided to take a stab at it to see how I do.I changed the
LAST
port to instead be calledDYN
because it's more general thanLAST
was, and added aDYNP
register.DYN
dynamically points to one of[NIL, UP, RIGHT, DOWN, LEFT]
. It is automatically set with the port the last successfulANY
operation happened on, just likeLAST
, but in addition to that the program can read and manipulate it using theDYNP
register. TheDYNP
mapping table thingy is as follows:{-1=NIL, 0=UP, 1=RIGHT, 2=DOWN, 3=LEFT}
If you set
DYNP
to a value less than -1 it will be set to -1.If you set
DYNP
to a value greater than 3 it will be wrapped (using modulus) to within 0-3, allowing you to rotate by simply adding a number toDYNP
.Here's the test program I used:
That program writes 65 to wherever it can (I placed a stack next to it) and then reads what side was written to using
DYNP
, rotates it 180º, writes that value back toDYNP
, and then writes 66 to that side. Basically it writes to any side, then writes exclusively to the opposite side.It would be incredibly useful for "asynchronous" code because you could wait for any input, and execute different code depending on the side input.
One downside to this, or possibly upside, is that it grants you an extra 2.5 bits of memory if you aren't using
ANY
orDYN
, but I don't think that would cause much of a balance problem. I don't know the design of the mod all that well though. Having one more place to store values could be a deal breaker.