summaryrefslogtreecommitdiff
path: root/nandgame
diff options
context:
space:
mode:
authoruvok2026-01-07 19:38:04 +0100
committeruvok2026-01-07 19:38:04 +0100
commit7eeaa1a04733910d408b2400b3f67cda525bc5ca (patch)
tree7792462f6ba8ed60165eaa965c4ed67709b4b1b9 /nandgame
parent3ba356cf0727817a431b28e01dd6d5d7b68d30ef (diff)
cb: specify endianness via arg
Diffstat (limited to 'nandgame')
-rwxr-xr-xnandgame/assembler/createbin.py37
1 files changed, 25 insertions, 12 deletions
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))