コード例 #1
0
def main():
    rom_fn, = sys.argv[1:]
    rom = open(rom_fn).read()
    assert len(rom) == 32768
    with standalone_programmer.Port() as ser:
        ser.write("I")  # identify chip
        resp = read_until(ser, "ID DONE")
        print("DONE")
        print()
        print(resp.strip())

        pos = 0
        if resp.find("SST39SF010") != -1:
            print("it's a SST39SF010; we can program that")
            ser.write("W")  # write 32k
            print(read_until(ser, "Programming"))
            while pos < len(rom):
                n = ser.write(rom[pos:pos + 63])
                if n:
                    pos += n
                    print("wrote %d bytes" % n)
                else:
                    time.sleep(0.01)

                r = ser.read(1024)
                if r:
                    print(repr(r))
            print(read_until(ser, "WRITE DONE"))
コード例 #2
0
def main():
	with standalone_programmer.Port() as ser:

		cart_read_start = time.time()
		print("setting flags: RPM=0 RBS=0 RWE=0")
		ser.write("w" + BANK_SEL + "\x00")

		for bank in range(128):
			print("READ BANK %d" % bank)
			bank_read_start = time.time()
			write_cmd = "w" + BANK_SEL + chr(bank)
			print(repr(write_cmd))
			ser.write(write_cmd)
			ser.write("S")  # fast read
			resp = ''
			while True:
				r = ser.read(1024)
				if r:
					#print `r`
					resp += r
					if resp.rstrip().endswith("ROM DONE"):
						break
				else:
					time.sleep(0.1)
			print("Bank read in %.2f s" % (time.time() - bank_read_start))

			rom_data = re.search("ROM\[(.{32768})\]", resp, re.DOTALL).group(1)
			print(len(rom_data))
			open("mgc_rom_%d.bin" % (bank * 2), "w").write(rom_data[:16384])
			open("mgc_rom_%d.bin" % (bank * 2 + 1), "w").write(rom_data[16384:])

		print("Whole cartridge read in %.2f s" % (time.time() - cart_read_start))
コード例 #3
0
def main():
    data_to_write = "*" * 131072
    with standalone_programmer.Port() as ser:
        ser.write("Z")  # USB test mode
        written = read = 0
        to_write = len(data_to_write)
        while written < to_write:
            n = ser.write(data_to_write[written:written + 63])
            if n:
                print "written %d: %d/%d (read %d)" % (n, written, to_write,
                                                       read)
                written += n
            else:
                time.sleep(0.01)
            r = ser.read(1024)
            if r:
                read += len(r)
                print "READ %d: %d total" % (len(r), read)
                print ` r `
コード例 #4
0
def main():
    with standalone_programmer.Port() as ser:
        ser.write("S")  # fast read
        resp = ''
        while 1:
            r = ser.read(1024)
            if r:
                print ` r `
                resp += r
                if resp.rstrip().endswith("ROM DONE"):
                    break
            else:
                time.sleep(0.1)
        print "DONE"

    rom_data = re.search("ROM\[(.{32768})\]", resp, re.DOTALL).group(1)
    print len(rom_data)
    open("rom1.bin", "w").write(rom_data[:16384])
    open("rom2.bin", "w").write(rom_data[16384:])
コード例 #5
0
def main():
    svf_fn, = sys.argv[1:]
    svf = open(svf_fn).read() + "\n\x04"

    with standalone_programmer.Port() as ser:
        # print "Serial port opened:", ser

        while True:
            r = ser.read(1024)
            if not r: break
            print(repr(r))
            time.sleep(0.1)

        ser.write("C\n")

        resp = ''
        print("Waiting for SEND SVF")
        while True:
            r = ser.read(1024)
            if r:
                resp += r
                print(repr(r))
                if resp.find("SEND SVF") != -1:
                    print("got SEND SVF - continuing")
                    break
            time.sleep(0.1)

        svf_start_time = time.time()
        resp = ''
        SLEEP_TIME = 0.01
        sleep_count = 0
        svf_pos = 0
        all_done = False
        line_no = 1
        stars = 0  # count of how many times we've seen *#, which means send another packet
        while not all_done:
            if stars < -3:
                time.sleep(0.001)
            else:
                print("\r  (write @ line %d, %d/%d)" %
                      (line_no, svf_pos, len(svf)),
                      end=' ')
                sys.stdout.flush()

                # always send 63 chars if we can
                p = min(len(svf), svf_pos + 63)

                n = ser.write(svf[svf_pos:p])
                if n:
                    stars -= 1
                    #print "  (%d bytes written)" % n
                    #print "  (sent: %s)" % `svf[svf_pos:p]`
                    line_no += svf[svf_pos:p].count("\n")
                    svf_pos += n

            while True:
                r = ser.read(1024)
                if not r:
                    break
                #print r
                resp += r
                while True:
                    p = resp.find("\n")
                    if p == -1: break
                    line = resp[:p].strip()
                    if line == "*#":
                        stars += 1
                    else:
                        print("\r%s" % line)
                    resp = resp[p + 1:]
                    if line.find("SVF DONE") != -1:
                        all_done = True
                        print("all done")
            if not n:
                time.sleep(SLEEP_TIME)
                sleep_count += 1
        svf_delivery_time = time.time() - svf_start_time

        print("SVF entirely sent, in %.2f s" % svf_delivery_time)
        total_sleep_time = SLEEP_TIME * sleep_count
        if total_sleep_time > 0.3:
            print("Slept for %.2f s total" % total_sleep_time)