This custom interpreter can move the box from this challenge!
W=$8010
DO
A=PEEKW(W)+2^16
G=PEEKW(W+3)+2^16
POKE A,PEEK(A)+PEEK(W+2)*(PEEK(G) AND 1)
ROR G,1
W=PEEK(W+5)+$8010
IF W=$8028 THEN WAIT 1
LOOP
#2:C
FFFFFFFFFFFFFFFF7F7F7FFFFEB686FE
20FFFA008006
76FF0100800C
00FE50008012
01FE50008018
01FEFF70FF1E
01FE0170FF24
00FEFF70FF2A
00FE0170FF18
These 8 instructions occupy 6 bytes each.
W holds the address in memory of the current instruction
Each instruction has 4 parameters:
- A (found at W+0) is the address of the memory location to modify
- (found at W+2) is the value to add to the value at memory location A. You can get the effect of negative numbers (subtracting) within this byte using $100 minus this value as a value.
- G (found at W+3) is the address of either the user input register or it points to a sequence of eight 1's to neutralize any effects. And have parameter 2's value be THE value.
- (found at W+5) contains the next instruction's address with $8010 subtracted from it so that this address information fits in a single byte. This allows it to run a bit of setup code, and then run a loop
What do the instructions do?
- Turn both backgrounds off, and go to 2.
- Turn the gamepad on, and go to 3.
- Center the sprite's X coordinate, go to 4.
- Center the sprite's Y coordinate, go to 5.
- Step in negative Y if the up button is pressed, go to 6.
- Step in positive Y if the down button is pressed, go to 7.
- Step in negative X if the left button is pressed, go to 8.
- Step in positive X if the right button is pressed, go to 5.
Detailed description
- Turn both backgrounds off. This could be done with NX commands or with "POKE $FF20, 1", but instead, it looks like this: "20FF FA 0080 06". This translates to modifying the value at $FF20, adding $FA (which equates to -6) to it, $8000 can be ignored, and at $8010+6 = $8016 is the next instruction
- Turn the gamepad on. This could be done with "POKE $FF76, 1", but it looks like this:
76FF 01 0080 0C
This means: add 1 to the value at $FF76, and at $801C is the next instruction
- Center the sprite's X coordinate. Instead of "POKE $FE00, 80", it's:
00FE 50 0080 12. This means: add 5 to the value at $FE00, then go to $8022.
- Center the sprite's Y coordinate. "POKE $FE01, 80" looks like this "01FE 50 0080 18". Which is very similar to the previous instruction.
- Step in negative Y if the up button is pressed looks like "01FE FF 70FF 1E". If the least significant bit of the gamepad register byte at $FF70 is on then $FF (equivalent to -1) is added to the sprite's Y position at $FE01.
- Step in positive Y if the down button is pressed. "01FE 01 70FF 24" is similar to the previous but it adds 1 instead of subtracting 1.
- Step in negative X if the left button is pressed. "00FE FF 70FF 2A" is similar to 6 but it modifies the sprite's X register instead.
- Step in positive X if the right button is pressed. "00FE 01 70FF 18" is similar to the previous one but adds 1 instead of subtracting one. The next instruction is at $8028 which is the fifth operation.
Side note
Location $8000 (the character image data) contains a byte with the data $FF, the code uses this as a dummy byte, to keep the bit shifter and the logical AND busy when they aren't needed without those operations modifying anything.