summaryrefslogtreecommitdiff
path: root/nandgame/assembler/createbin_main.py
diff options
context:
space:
mode:
Diffstat (limited to 'nandgame/assembler/createbin_main.py')
-rwxr-xr-xnandgame/assembler/createbin_main.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/nandgame/assembler/createbin_main.py b/nandgame/assembler/createbin_main.py
new file mode 100755
index 0000000..e2497cd
--- /dev/null
+++ b/nandgame/assembler/createbin_main.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+"""
+Basically, iterate all 16-bit numbers,
+or rather, 15-bit, to have valid
+nandgame instructions, skip reserved bits.
+"""
+
+# ENDIANNESS = 'big'
+endianness = "little"
+
+
+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))
+
+ 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()