66 lines
1.2 KiB
PHP
66 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Machine;
|
|
|
|
use Machine\Memory\DataRegisters;
|
|
use Machine\Memory\MemoryController;
|
|
use Machine\Memory\ProgramMemory;
|
|
use Machine\Memory\ToolMemory;
|
|
|
|
class CNC6600
|
|
{
|
|
public DataRegisters $DR;
|
|
public InstructionSet $IS;
|
|
public ToolMemory $TM;
|
|
public ProgramMemory $SPM;
|
|
public ProgramMemory $PPM;
|
|
public MemoryController $SPMC;
|
|
public MemoryController $PPMC;
|
|
public MemoryController $_AMC;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->DR = new DataRegisters();
|
|
$this->IS = new InstructionSet($this);
|
|
$this->TM = new ToolMemory();
|
|
$this->SPM = new ProgramMemory();
|
|
$this->PPM = new ProgramMemory();
|
|
$this->SPMC = new MemoryController($this->SPM);
|
|
$this->PPMC = new MemoryController($this->PPM);
|
|
$this->_AMC = $this->PPMC;
|
|
}
|
|
|
|
|
|
public function loadProgram(int $N): void
|
|
{
|
|
$this->PPMC->loadProgram($N);
|
|
$this->_AMC = $this->PPMC;
|
|
}
|
|
|
|
|
|
public function step(): void
|
|
{
|
|
if ($this->_AMC === $this->SPMC && count($this->_AMC) === 0) {
|
|
$this->_AMC = $this->PPMC;
|
|
}
|
|
$block = $this->_AMC->next();
|
|
$this->IS->apply($block);
|
|
}
|
|
|
|
|
|
public function execute(): void
|
|
{
|
|
while ($this->PPMC->ready()) {
|
|
$this->step();
|
|
}
|
|
}
|
|
|
|
|
|
public function reset(): void
|
|
{
|
|
$this->PPMC->reset();
|
|
$this->SPMC->reset();
|
|
}
|
|
}
|