From 7eeaa1a04733910d408b2400b3f67cda525bc5ca Mon Sep 17 00:00:00 2001 From: uvok Date: Wed, 7 Jan 2026 19:38:04 +0100 Subject: cb: specify endianness via arg --- nandgame/assembler/createbin.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'nandgame') diff --git a/nandgame/assembler/createbin.py b/nandgame/assembler/createbin.py index 23f9979..c8559a5 100755 --- a/nandgame/assembler/createbin.py +++ b/nandgame/assembler/createbin.py @@ -9,18 +9,31 @@ nandgame instructions, skip reserved bits. #ENDIANNESS = 'big' ENDIANNESS = 'little' -with open("allins.bin", "wb") as f: - ins=0x0000 - # ldi A, 0 - f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) +def main(): + with open("allins.bin", "wb") as f: + ins=0x0000 + # ldi A, 0 + f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) - ins=0x00ff - # ldi A, 255 - f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) + ins=0x00ff + # ldi A, 255 + f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) - for ins in range(0x8000, 0xffff + 1): - # unused bytes, force 1 - if (ins & 0x6800) != 0x6800: - continue + for ins in range(0x8000, 0xffff + 1): + # unused bytes, force 1 + if (ins & 0x6800) != 0x6800: + continue + + f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) + +import sys + +if __name__ == "__main__": + if len(sys.argv) == 2: + if sys.argv[1] in ["little", "le"]: + ENDIANNESS = "little" + elif sys.argv[1] in ["big", "be"]: + ENDIANNESS = "big" + print(f"Use Endianness: {ENDIANNESS}") + main() - f.write(ins.to_bytes(2, byteorder = ENDIANNESS)) -- cgit v1.2.3