Ejemplo n.º 1
0
def main():
    global DEBUG
    global buffer
    global run_id
    global fn

    if(os.name == 'nt'):
        psutil.Process().nice(psutil.REALTIME_PRIORITY_CLASS)
    else:
        psutil.Process().nice(20)

    gc.disable()

    parser = argparse_helper.setup_parser_full()

    args = parser.parse_args()

    if args.transition != None:
        for transition in args.transition:
            transition[0] = int(transition[0])
            if transition[1] == 'A':
                transition[1] = b'A'
            elif transition[1] == 'N':
                transition[1] = b'N'
            elif transition[1] == 'S':
                transition[1] = b'S'
            elif transition[1] == 'H':
                transition[1] = b'H'

    if args.latchtrain != '':
        args.latchtrain = [int(x) for x in args.latchtrain.split(',')]

    DEBUG = args.debug

    args.players = args.players.split(',')
    for x in range(len(args.players)):
        args.players[x] = int(args.players[x])

    if args.serial == None:
        dev = TAStm32(serial_helper.select_serial_port())
    else:
        dev = TAStm32(args.serial)

    if args.hardreset or args.softreset:
        dev.power_off()
        if args.hardreset:
            time.sleep(2.0)

    if args.clock != None:
        args.clock = int(args.clock)
        if args.clock < 0 or args.clock > 63:
            print('ERROR: The clock value must be in the range [0,63]! Exiting.')
            sys.exit(0)

    try:
        with open(args.movie, 'rb') as f:
            data = f.read()
    except:
        print('ERROR: the specified file (' + args.movie + ') failed to open')
        sys.exit(0)

    dev.reset()
    if args.console == 'genesis':
        header = gmv.read_header(data)
        args.players = (header.get("p1"), header.get("p2"), header.get("3players"))
    run_id = dev.setup_run(args.console, args.players, args.dpcm, args.overread, args.clock)
    if run_id == None:
        raise RuntimeError('ERROR')
        sys.exit()
    if args.console == 'n64':
        buffer = m64.read_input(data)
        blankframe = b'\x00\x00\x00\x00' * len(args.players)
    elif args.console == 'snes':
        buffer = r16m.read_input(data, args.players)
        blankframe = b'\x00\x00' * len(args.players)
    elif args.console == 'nes':
        buffer = r08.read_input(data, args.players)
        blankframe = b'\x00' * len(args.players)
    elif args.console == 'gc':
        buffer = dtm.read_input(data)
        blankframe = b'\x00\x00\x00\x00\x00\x00\x00\x00' * len(args.players)
    elif args.console == 'genesis':
        buffer = gmv.read_input(data)
        blankframe = b'\x00\x00\x00'

    # Transitions
    if args.transition != None:
        for transition in args.transition:
            dev.send_transition(run_id, *transition)
    # Send Blank Frames
    for blank in range(args.blank):
        data = run_id + blankframe
        dev.write(data)
    print(f'Sending Blank Latches: {args.blank}')
    fn = 0
    for latch in range(int_buffer-args.blank):
        try:
            data = run_id + buffer[fn]
            dev.write(data)
            if fn % 100 == 0:
                print(f'Sending Latch: {fn}')
            fn += 1
        except IndexError:
            pass
    err = dev.read(int_buffer)
    fn -= err.count(b'\xB0')
    if err.count(b'\xB0') != 0:
        print('Buffer Overflow x{}'.format(err.count(b'\xB0')))
    # Latch trains
    if args.latchtrain != '':
        dev.send_latchtrain(run_id, args.latchtrain)
    
    run = RunObject(run_id, buffer, fn, blankframe)
    print('Main Loop Start')
    if not args.nobulk:
        dev.set_bulk_data_mode(run_id, b"1")
    dev.power_on()
    dev.main_loop(run)
    print('Exiting')
    dev.ser.close()
    sys.exit(0)
Ejemplo n.º 2
0
def bitswap(b):
    b = (b&0xF0) >> 4 | (b&0x0F) << 4
    b = (b&0xCC) >> 2 | (b&0x33) << 2
    b = (b&0xAA) >> 1 | (b&0x55) << 1
    return b
    
data = None

parser = argparse_helper.audio_parser()
args = parser.parse_args()

DEBUG = args.debug

if args.serial == None:
    dev = tastm32.TAStm32(serial_helper.select_serial_port())
else:
    dev = tastm32.TAStm32(args.serial)

# connect to device
ser = dev

# open file
f = sys.stdin.buffer #open(sys.argv[1], "rb")

latches = 0

cmd = None
inputs = None   

print("--- Starting read loop")
Ejemplo n.º 3
0
def main():
    parser = argparse_helper.setup_parser()
    args = parser.parse_args()
    
    if args.serial == None:
        ser = serial_helper.select_serial_port()
    else:
        ser = args.serial
    try:
        ser = serial.Serial(ser, 115200, timeout=0)
    except serial.SerialException:
        print ('ERROR: the specified interface (' + ser + ') is in use')
        sys.exit(0)

    try:
        with open(args.movie, 'rb') as f:
            data = f.read()
    except:
        print('ERROR: the specified file (' + args.movie + ') failed to open')
        sys.exit(0)

    buffer = m64.read_input(data)
    serial_write(ser, b'R') # send RESET command
    err = serial_read(ser, 2)
    if err == b'\x01R':
        pass
    elif err == b'\xFF':
        raise RuntimeError('Prefix not recognised')
    else:
        raise RuntimeError('Unknown error during reset')
    serial_write(ser, b'S' + run_id + b'M\x01')
    err = serial_read(ser, 2)
    if err == b'\x01S':
        pass
    elif err == b'\xFF':
        raise RuntimeError('Prefix not recognised')
    elif err == b'\xFE':
        raise RuntimeError('Run number not recognised')
    elif err == b'\xFD':
        raise RuntimeError('Number of controllers not recognised')
    elif err == b'\xFC':
        raise RuntimeError('Console Type not recognised')
    else:
        raise RuntimeError('Unknown error during run setup')
    for blank in range(args.blank):
        data = run_id + b'\x00\x00\x00\x00'
        serial_write(ser, data)
        print('Sending Blank Latch: {}'.format(blank))
    fn = 0
    for latch in range(int_buffer-args.blank):
        data = run_id + buffer[fn]
        serial_write(ser, data)
        print('Sending Latch: {}'.format(fn))
        fn += 1
    err = serial_read(ser, int_buffer)
    fn -= err.count(b'\xB0')
    done = False
    print('Main Loop Start')
    while not done:
        try:
            c = serial_read(ser, 1)
            if c == '':
                continue
            numBytes = ser.inWaiting()
            if numBytes > 0:
                c += serial_read(ser, numBytes)
                if numBytes > int_buffer:
                    print ("WARNING: High latch rate detected: " + str(numBytes))
            if DEBUG:
                print('R: {}'.format(c))
            latches = c.count(run_id)
            for latch in range(latches):
                data = run_id + buffer[fn]
                serial_write(ser, data)
                print('Sending Latch: {}'.format(fn))
                fn += 1
            err = serial_read(ser, int_buffer)
            fn -= err.count(b'\xB0')
        except serial.SerialException:
            print('ERROR: Serial Exception caught!')
            done = True
        except KeyboardInterrupt:
            print('^C Exiting')
            done = True
        except IndexError:
            print('End of Input Exiting')
            done = True
    print('trying to exit')
    try:
        ser.close()
    except serial.SerialException:
        sys.exit(0)
    ser.close()
    sys.exit(0)