log_user 1
	    exp_internal 0

	    set timeout -1
	    set log_path "/home/pi/CAFCA/log/expect.log"
	    set busy_flag "/home/pi/CAFCA/data/scan_flag"
	    set coin_file "/home/pi/CAFCA/data/tmp/cafca_coins_cnt"
	    set pid [exec pidof retroarch]
	    set ready 0
	    set scanned 0
	    set matched 0
	    set matches 999
	    set match_limit 5
	    set credits 0
	    set last_credits 0

	    exec echo -e "\n" > "$log_path"
	    log_file "$log_path"
	    spawn scanmem -p $pid
	    proc startup {} {
	      exec echo 0 > "$::busy_flag"
	      expect {
	        "Please" {
	          exec sleep 1
	          send "option region_scan_level 3\r"
	          exec sleep 1
	          send "reset\r"
	          exec sleep 1
	          exp_continue
	        }
	        "*suitable*" {
	          set ::ready 1
	          exec sleep 1
	        }
	      }
	      while {$::credits == $::last_credits} {
	        set ::credits [exec cat "$::coin_file"]
	      }
	    }
	    proc put_coin {} {
	      set ::credits [exec cat "$::coin_file"]
	      if {$::credits != $::last_credits} {
	        set ::last_credits $::credits
	        exec echo 1 > "$::busy_flag"
	        exec sleep 1
	        send "$::credits\r"
	        exec sleep 1
	        expect {
	          "*currently*" {
	            exec echo 0 > "$::busy_flag"
	            #set ::matches [lindex [split [lindex [split $expect_out(0,string) "\n"] end ] ">" ] 0]
	            set ::matches [lindex [split [lindex [split $expect_out(buffer) "\n"] end-1 ] " " ] end-1 ]
	            send_user "\n\nmatches: $::matches\n"
	            if {$::matches == "other"} {
	              send_user "MATCH IS 1!\n"
	              set ::matches 1
	            }
	            #if {$::matches <= $::match_limit} {
	            # send "list\r"
	            #}
	            #exp_continue
	          }
	          #"*identified*" {
	          #  exec sleep 1
		  #  send "list\r"
	          #  #    exp_continue
	          #}

	          #"*matches*" {
	          #  exec echo 0 > "$::busy_flag"
	          #  exec sleep 1
	            #send "\r"
	            #exec sleep 1
	            #set ::matches [lindex [split [lindex [split $expect_out(0,string) "\n"] end ] ">" ] 0]
	            #set ::matches [lindex [split $expect_out(0,string) "\n"] end ]
	            #send_user "\n\nmatches: $::matches\n\n"
	            #if {$::matches < $::match_limit} {
	            #  extract_match
	            #}
	          #}
	        }
	      }
	    }
	    proc extract_match {} {
	      send_user "\n\nMATCH LIMIT REACHED\n\n"
	      send "list\r"
	    }
	    startup
	    while {$matches > $match_limit} {
	      put_coin
	    }
	    exec sleep 1
	    send_user "\nBREAK!\n"
	    send "list\r"
	    expect {
	      "*0x*" {
	        send_user "LISTING!\n"
	        exp_continue
	      }
	    }
	    #send "exit\r"
	    #close
	    #expect eof


    
	    
			#!/bin/bash
			
declare -A data=()
declare -a regions=()
			/usr/bin/expect -c '