Esempio n. 1
0
                    $char = chr($this->_read($this->_memory[$i + 1]));
                    echo $char;
                    $i += 2;
                    break;
                case 20:
                    // in
                    $a = $this->_memory[$i + 1];
                    $c = ord(fgetc($in));
                    // windows sends \r\n upon enter, ignore the 13
                    if ($c == 13) {
                        // get the ascii 10
                        $c = ord(fgetc($in));
                    }
                    $this->_write($a, $c);
                    $i += 2;
                    break;
                case 21:
                    // noop
                    $i++;
                    break;
                default:
                    die("unknown op: {$op}");
                    break;
            }
        }
    }
}
$m = new Machine();
$m->load('challenge.bin');
$m->run();