UNPKG

eighty-eighty-js

Version:

A nice little Intel 8080 emulator for Node.js and Browser!

115 lines (114 loc) 3.49 kB
import { u16, u8 } from 'typed-numbers'; import { Device } from '../types'; import { Memory } from './Memory'; import { Register } from './Register'; /** * Represents the Intel 8080 CPU. */ export declare class Cpu { /** Clock Frequency. */ static readonly CLOCK_FREQUENCY = 2000000; /** Time a single step takes in milliseconds. */ static readonly STEP_TIME = 16; /** Amount of CPU cycles a single step takes. */ static readonly STEP_CYCLES: number; /** CPU Register. */ reg: Register; /** CPU Memory. */ mem: Memory; /** Whether the CPU is halted. */ halted: boolean; /** Whether Flip-Flop instructions are interrupted. */ interruptEnabled: boolean; /** Whether debugging is enabled. */ debugEnabled: boolean; /** Device that handles input/output operations. */ device: Device; /** Keeps track of the amount CPU cycles of the current step. */ protected stepCycles: number; /** Keeps track of the start time of a step. */ protected stepZero: number; /** * Constructor. * @param mem - An instance of the Memory class, with the program already loaded in. * @param device - A class that implements Device. * @param [debugEnabled = false] - Enable debugging. */ constructor(mem: Memory, device: Device, debugEnabled?: boolean); next(): number; /** * Simulates a real CPU step with the Intel 8080's speed. */ step(): Promise<number>; handleInterrupt(address: u16): void; /************************ * IMMEDIATE ADDRESSING * ************************/ /** * Returns the byte at the program counter and moves the program counter forwards by 1. */ getNextByte(): u8; /** * Returns the word at the program counter and moves the program counter forwards by 2. */ getNextWord(): u16; /******************* * MEMORY REGISTER * *******************/ /** * Get value of register M, which is just the memory. */ getM(): u8; /** * Set value of register M, which is just the memory. * @param value - The new value. */ setM(value: u8): void; /******************** * STACK OPERATIONS * ********************/ /** * Add a value to the top of the stack. * @param value - The value to add. */ stackAdd(value: u16): void; /** * Pop a value from the top of the stack. * @return - The value from the stack. */ stackPop(): u16; /***************************** * BRANCH CONDITION CHECKING * *****************************/ /** * Checks branching condition for Jump/Call/Return operations * @param opcode - The opcode of the operation. */ checkBranchCondition(opcode: u8): boolean; /****************** * ALU OPERATIONS * ******************/ /** */ inr(num: u8): u8; dcr(num: u8): u8; daa(): void; add(num: u8): void; adc(num: u8): void; sub(num: u8): void; sbb(num: u8): void; ana(num: u8): void; xra(num: u8): void; ora(num: u8): void; cmp(num: u8): void; rlc(): void; rrc(): void; ral(): void; rar(): void; dad(num: u16): void; } export declare namespace Cpu { class UnimplementedInstructionError extends Error { opcode: u8; constructor(opcode: u8); } }