summaryrefslogtreecommitdiff
path: root/nandgame/assembler/createbin_main.py
blob: e2497cd1399193eb571f935af2c5d2818a413a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()