import { CPU } from "./cpu" ; import { MemoryDefinition } from "../assembly/assembler" ; import { MemoryBlock } from "./memory-block" ; export class Process { private started : boolean = false ; constructor ( private _cpu ) { this . cpu . onExit . subscribe ( ( cpu ) => this . started = false ) ; } get cpu ( ) : CPU { return this . _cpu ; } public start ( sync = false ) { this . started = true ; this . reset ( ) ; this . initMemory ( ) ; if ( sync ) { this . cpu . runSync ( ) ; } else this . cpu . run ( ) ; } public isStarted ( ) { return this . started ; } public isRunning ( ) { return this . isStarted ( ) && this . cpu . running ; } public isPaused ( ) { return this . isStarted ( ) && ! this . cpu . running ; } public reset ( ) { this . cpu . reset ( ) ; this . cpu . memory . clear ( ) ; } private initMemory ( ) { let memoryDefinitions = this . cpu . program . memoryDefinitions ; let memory = this . cpu . memory ; for ( const memoryDef of memoryDefinitions ) { memory . load ( memoryDef . address , memoryDef . size ) . setValue ( memoryDef . value ) ; } } }