コード例 #1
0
ファイル: rawbin2txt.py プロジェクト: usbalex/zorrom
def run(fn_in,
        fn_out,
        width,
        height=None,
        bits=None,
        grows=None,
        gcols=None,
        lsb=False,
        verbose=False):
    if lsb:
        txt_raw = mrom.load_bin_lsb(open(fn_in, "rb"))
    else:
        txt_raw = mrom.load_bin_msb(open(fn_in, "rb"))
    if height is None:
        assert len(txt_raw) % width == 0
        height = len(txt_raw) // width
    if not bits:
        bits = width * height
    bits = width * height
    txt = txt_raw[0:bits]
    print("%uw x %uh => %u bits" % (width, height, bits))
    txtdict = mrom.txt2dict(txt, width, height)

    if grows is None:
        grows = list(range(8, height, 8))

    if gcols is None:
        gcols = list(range(8, width, 8))

    mrom.save_txt(open(fn_out, "w"),
                  txtdict,
                  width,
                  height,
                  grows=grows,
                  gcols=gcols)
コード例 #2
0
def run(verbose, rom1_fn, rom2_fn, fn_out):
    txt1, w1, h1 = mrom.load_txt(open(rom1_fn, "r"), None, None)
    txt2, w2, h2 = mrom.load_txt(open(rom2_fn, "r"), None, None)

    # strictly speaking don't need w assert, but keep for now
    assert w1 == w2 and h1 == h2, "size mismatch: left bits %u (%uw x %uh), right bits %u (%uw x %uh)" % (
        len(txt1), w1, h1, len(txt2), w2, h2)
    w = w1
    h = h1
    wout = w * 2
    hout = h
    print("%uw x %uh + %uw x %uh => %uw x %uh" % (w1, h1, w1, h2, wout, hout))

    # txtdict1 = mrom.txt2dict(txt1, w1, h1)
    txtdict2 = mrom.txt2dict(txt2, w2, h2)

    txtdict = mrom.txt2dict(txt1, w1, h1)
    for x in range(w2):
        for y in range(h2):
            txtdict[(w1 + x, y)] = txtdict2[(x, y)]

    mrom.save_txt(open(fn_out, "w"), txtdict, wout, hout)
コード例 #3
0
ファイル: txtand.py プロジェクト: usbalex/zorrom
def run(verbose, fn_ins, fn_out):
    w = None
    h = None
    txtdict = None

    for fn_in in fn_ins:
        txt1, w1, h1 = mrom.load_txt(open(fn_in, "r"), None, None)
        print("Check %s, %uw x %uh" % (fn_in, w1, h1))
        if txtdict is None:
            w = w1
            h = h1
        else:
            # strictly speaking don't need w assert, but keep for now
            assert w1 == w and h1 == h, "size mismatch: left bits %u (%uw x %uh), right bits %u (%uw x %uh)" % (
                len(txt1), w1, h1, len(w * h), w, h)

        txtdict1 = mrom.txt2dict(txt1, w1, h1)
        if txtdict is None:
            txtdict = txtdict1
        else:
            for x in range(w):
                for y in range(h):
                    l = txtdict1[(x, y)]
                    r = txtdict[(x, y)]
                    txtdict[(x, y)] = l if l == r else 'X'

    syms = dict()
    for x in range(w):
        for y in range(h):
            r = txtdict[(x, y)]
            syms[r] = syms.get(r, 0) + 1
    print("Statistics")
    for sym in "01X":
        print("  %s: %u" % (sym, syms[sym]))

    mrom.save_txt(open(fn_out, "w"), txtdict, w, h)
コード例 #4
0
def run(verbose, rom1_fn, rom2_fn, fn_out=None, grows=None, gcols=None):
    txt1, w1, h1 = mrom.load_txt(open(rom1_fn, "r"), None, None)
    txt2, w2, h2 = mrom.load_txt(open(rom2_fn, "r"), None, None)

    assert w1 == w2 and h1 == h2, "size mismatch: left bits %u (%uw x %uh), right bits %u (%uw x %uh)" % (
        len(txt1), w1, h1, len(txt2), w2, h2)
    l = len(txt1)
    w = w1
    h = h1
    print("0x%04X (%u) bytes, %uw x %uh" % (l, l, w, h))

    txtdict1 = mrom.txt2dict(txt1, w1, h1)
    txtdict2 = mrom.txt2dict(txt2, w2, h2)
    txtdict = mrom.txt2dict(txt1, w2, h2)

    bitd = {}
    for x in range(w2):
        for y in range(h2):
            l = txtdict1[(x, y)]
            r = txtdict2[(x, y)]
            if l == r:
                continue
            bitd[(x, y)] = (l, r)
            txtdict[(x, y)] = "?"
    print("%u bits different" % len(bitd))
    if verbose:
        for (x, y), (l, r) in sorted(bitd.items()):
            print("  %ux, %uy: %s vs %s" % (x, y, l, r))
    if fn_out:
        print("Saving %s" % fn_out)
        mrom.save_txt(open(fn_out, "w"),
                      txtdict,
                      w,
                      h,
                      gcols=gcols,
                      grows=grows)
コード例 #5
0
ファイル: txtmunge.py プロジェクト: yusufm/zorrom
def run(fn_in,
        fn_out,
        invert=None,
        rotate=None,
        flipx=False,
        flipy=False,
        grows=[],
        gcols=[],
        verbose=False):
    txtin, win, hin = mrom.load_txt(open(fn_in, "r"), None, None)
    txtdict, wout, hout = munge_txt(txtin,
                                    win,
                                    hin,
                                    rotate=rotate,
                                    flipx=flipx,
                                    flipy=flipy,
                                    invert=invert)
    # return mrom.dict2txt(txtdict, wout, hout)
    mrom.save_txt(open(fn_out, "w"),
                  txtdict,
                  wout,
                  hout,
                  grows=grows,
                  gcols=gcols)