aiko-php/aiko
2025-04-06 01:20:37 +00:00

62 lines
1.4 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
namespace Aiko;
require_once __DIR__ . '/vendor/autoload.php';
error_reporting(-1);
//define('AIKO_ROM', '/home/flash/6502_65C02_functional_tests/bin_files/6502_functional_test.bin');
define('AIKO_ROM', __DIR__ . '/test.bin');
$cpu = new Cpu(
FileMemory::open(AIKO_ROM)
// new ClosureMemory(
// function(int $addr): int {
// printf('GET $%04X%s', $addr, PHP_EOL);
// return $addr & 0xFF;
// },
// function(int $addr, int $value): void {
// printf('SET $%04X -> $%02X %s', $addr, $value, PHP_EOL);
// }
// )
);
$lastAddr = null;
$lastAddrCount = 0;
$lastStackPtr = $cpu->state->s;
$cpu->state->pc = 0x400;
printf('[ %s ]%s', $cpu->state, PHP_EOL);
for(;;) {
$cpu->tick();
if($lastStackPtr !== $cpu->state->s) {
$lastStackPtr = $cpu->state->s;
printf('Stack page:%s', PHP_EOL);
for($i = 0; $i < 0x100; ++$i) {
printf(' %02X', $cpu->mem->read($cpu->state->sPage | $i, true));
if(($i & 0x1F) === 0x1F)
echo PHP_EOL;
}
}
echo PHP_EOL;
if($lastAddr === $cpu->state->pc) {
if(++$lastAddrCount > 9) {
printf('Trapped!%s', PHP_EOL);
break;
}
} else {
$lastAddr = $cpu->state->pc;
$lastAddrCount = 0;
}
printf('[ %s ]%s', $cpu->state, PHP_EOL);
//usleep(200);
readline();
}