Skip to content

Instantly share code, notes, and snippets.

@ISSOtm
Created September 5, 2021 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ISSOtm/9a86458bb39d7e02f62d6ff39442fcad to your computer and use it in GitHub Desktop.
Save ISSOtm/9a86458bb39d7e02f62d6ff39442fcad to your computer and use it in GitHub Desktop.
"Clever" assembly for NANDGame maze escape mission (not really Python, just for approximate syntax highlighting)
# Start of main loop
loop:
# Wait until everything is settled before doing anything
A = 0x600
D = A
wait_init:
A = 0x7FFF
# D has its bits get progressively cleared as exit conditions become true
# (since we're not instructing the robot to move, it won't suddenly start doing so)
D = D & *A
A = wait_init
D ; JNE
# To get out, follow the wall to our right
# First, turn right to check if there is one
A = 0x0F
# The reason why we're loading one less and then adding one is explained next to the jump to this label
turn_left:
D = A + 1
# Now, turn left until we're facing nothing.
# This will loop infinitely if we are in a a box, but we're trapped anyway
turn_loop:
# Turn according to pre-computed vector
A = 0x7FFF
*A = D
# Wait until that movement is over
A = 0x200
D = A
wait_turn:
A = 0x7FFF
# Same logic as `wait_init` loop
D = D & *A
A = wait_turn
D ; JNE
# Okay, we finished turning. Is there a wall in front of us?
A = 0x100
D = A
A = 0x7FFF
D = D & *A
# Okay, this needs a bit of an explanation.
# We need to jump back to the loop to write 8 there.
# By a huge stroke of luck, this happens to be at address 0x7, which is exactly one less than the value we need!
# So we use that jump address, and load it PLUS ONE into D!!
A = turn_left
# There is a wall, keep turning left
D ; JNE
# There is no wall in front of us!
# Step forward, and jump back to the start of the main loop, which will wait the movement out.
A = 0x4
D = A
A = 0x7FFF
*A = D
A = loop
JMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment