Last active
October 26, 2017 21:41
-
-
Save SiD3W4y/043f85e61f0c190a2f24e1eaafdfdd3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
# LSE LadyBot assembler lib | |
class Ops: | |
MOVE = 0x00 | |
ADD = 0x10 | |
EQ = 0x20 | |
LT = 0x30 | |
LE = 0x40 | |
XOR = 0x50 | |
TURN = 0x60 | |
TURNX = 0x64 | |
SWAP = 0x68 | |
NOP = 0x6c | |
WALK = 0x6e | |
JUMP = 0x70 | |
PUSH = 0x74 | |
POP = 0x78 | |
NOT = 0x7c | |
JUMP_IM = 0x80 | |
LOAD_CONST = 0xc0 | |
def assemble(op,regA=0,regB=0,val=0): | |
# A and B reg ops | |
res = 0xff | |
if op in [Ops.MOVE,Ops.ADD,Ops.EQ,Ops.LT,Ops.LE,Ops.XOR]: | |
res = op | ((regA & 0x3) << 2) | (regB & 0x3) | |
# Only A ops | |
if op in [Ops.TURN,Ops.SWAP,Ops.JUMP,Ops.PUSH,Ops.POP,Ops.NOT]: | |
res = op | (regA & 0x3) | |
# Immediate value (LARGE) | |
if op in [Ops.JUMP_IM,Ops.LOAD_CONST]: | |
res = op | (val & 0x3f) | |
# Immediate value (SINGLE) | |
if op in [Ops.WALK,Ops.NOP]: | |
res = op | (val & 0x1) | |
if op == Ops.TURNX: | |
res = op | val & 0x3 | |
return struct.pack("B",res) | |
def convert_map(input_str): | |
text = input_str.decode("UTF-8") | |
convert = lambda a: ord(a) % 2 # Convert "#" to 1 and "." to 0 | |
lines = list(filter(lambda a: "#" in a,text.split("\n"))) | |
return list(map(lambda a: list(map(convert,a)),lines)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment