/** * @fileoverview Implements PC8080 opcode handlers. * @author Jeff Parsons * @version 1.0 * Created 2016-Apr-20 * * Copyright © 2012-2016 Jeff Parsons * * This file is part of PCjs, which is part of the JavaScript Machines Project (aka JSMachines) * at and . * * PCjs is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * PCjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with PCjs. If not, * see . * * You are required to include the above copyright notice in every source code file of every * copy or modified version of this work, and to display that copyright notice on every screen * that loads or runs any version of this software (see Computer.COPYRIGHT). * * Some PCjs files also attempt to load external resource files, such as character-image files, * ROM files, and disk image files. Those external resource files are not considered part of the * PCjs program for purposes of the GNU General Public License, and the author does not claim * any copyright as to their contents. */ "use strict"; if (NODE) { var str = require("../../shared/lib/strlib"); var Messages = require("./messages"); var CPUDef = require("./CPUDef"); } /** * op=0x00 (NOP) * * @this {CPUSim} */ CPUDef.opNOP = function() { this.nStepCycles -= 4; }; /** * op=0x01 (LXI B,d16) * * @this {CPUSim} */ CPUDef.opLXIB = function() { this.setBC(this.getPCWord()); this.nStepCycles -= 10; }; /** * op=0x02 (STAX B) * * @this {CPUSim} */ CPUDef.opSTAXB = function() { this.setByte(this.getBC(), this.regA); this.nStepCycles -= 7; }; /** * op=0x03 (INX B) * * @this {CPUSim} */ CPUDef.opINXB = function() { this.setBC(this.getBC() + 1); this.nStepCycles -= 5; }; /** * op=0x04 (INR B) * * @this {CPUSim} */ CPUDef.opINRB = function() { this.regB = this.incByte(this.regB); this.nStepCycles -= 5; }; /** * op=0x05 (DCR B) * * @this {CPUSim} */ CPUDef.opDCRB = function() { this.regB = this.decByte(this.regB); this.nStepCycles -= 5; }; /** * op=0x06 (MVI B,d8) * * @this {CPUSim} */ CPUDef.opMVIB = function() { this.regB = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x07 (RLC) * * @this {CPUSim} */ CPUDef.opRLC = function() { var carry = this.regA << 1; this.regA = (carry & 0xff) | (carry >> 8); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | (carry & 0x100); this.nStepCycles -= 4; }; /** * op=0x09 (DAD B) * * @this {CPUSim} */ CPUDef.opDADB = function() { var w; this.setHL(w = this.getHL() + this.getBC()); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100); this.nStepCycles -= 10; }; /** * op=0x0A (LDAX B) * * @this {CPUSim} */ CPUDef.opLDAXB = function() { this.regA = this.getByte(this.getBC()); this.nStepCycles -= 7; }; /** * op=0x0B (DCX B) * * @this {CPUSim} */ CPUDef.opDCXB = function() { this.setBC(this.getBC() - 1); this.nStepCycles -= 5; }; /** * op=0x0C (INR C) * * @this {CPUSim} */ CPUDef.opINRC = function() { this.regC = this.incByte(this.regC); this.nStepCycles -= 5; }; /** * op=0x0D (DCR C) * * @this {CPUSim} */ CPUDef.opDCRC = function() { this.regC = this.decByte(this.regC); this.nStepCycles -= 5; }; /** * op=0x0E (MVI C,d8) * * @this {CPUSim} */ CPUDef.opMVIC = function() { this.regC = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x0F (RRC) * * @this {CPUSim} */ CPUDef.opRRC = function() { var carry = (this.regA << 8) & 0x100; this.regA = (carry | this.regA) >> 1; this.resultZeroCarry = (this.resultZeroCarry & 0xff) | carry; this.nStepCycles -= 4; }; /** * op=0x11 (LXI D,d16) * * @this {CPUSim} */ CPUDef.opLXID = function() { this.setDE(this.getPCWord()); this.nStepCycles -= 10; }; /** * op=0x12 (STAX D) * * @this {CPUSim} */ CPUDef.opSTAXD = function() { this.setByte(this.getDE(), this.regA); this.nStepCycles -= 7; }; /** * op=0x13 (INX D) * * @this {CPUSim} */ CPUDef.opINXD = function() { this.setDE(this.getDE() + 1); this.nStepCycles -= 5; }; /** * op=0x14 (INR D) * * @this {CPUSim} */ CPUDef.opINRD = function() { this.regD = this.incByte(this.regD); this.nStepCycles -= 5; }; /** * op=0x15 (DCR D) * * @this {CPUSim} */ CPUDef.opDCRD = function() { this.regD = this.decByte(this.regD); this.nStepCycles -= 5; }; /** * op=0x16 (MVI D,d8) * * @this {CPUSim} */ CPUDef.opMVID = function() { this.regD = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x17 (RAL) * * @this {CPUSim} */ CPUDef.opRAL = function() { var carry = this.regA << 1; this.regA = (carry & 0xff) | (this.resultZeroCarry >> 8); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | (carry & 0x100); this.nStepCycles -= 4; }; /** * op=0x19 (DAD D) * * @this {CPUSim} */ CPUDef.opDADD = function() { var w; this.setHL(w = this.getHL() + this.getDE()); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100); this.nStepCycles -= 10; }; /** * op=0x1A (LDAX D) * * @this {CPUSim} */ CPUDef.opLDAXD = function() { this.regA = this.getByte(this.getDE()); this.nStepCycles -= 7; }; /** * op=0x1B (DCX D) * * @this {CPUSim} */ CPUDef.opDCXD = function() { this.setDE(this.getDE() - 1); this.nStepCycles -= 5; }; /** * op=0x1C (INR E) * * @this {CPUSim} */ CPUDef.opINRE = function() { this.regE = this.incByte(this.regE); this.nStepCycles -= 5; }; /** * op=0x1D (DCR E) * * @this {CPUSim} */ CPUDef.opDCRE = function() { this.regE = this.decByte(this.regE); this.nStepCycles -= 5; }; /** * op=0x1E (MVI E,d8) * * @this {CPUSim} */ CPUDef.opMVIE = function() { this.regE = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x1F (RAR) * * @this {CPUSim} */ CPUDef.opRAR = function() { var carry = (this.regA << 8) & 0x100; this.regA = ((this.resultZeroCarry & 0x100) | this.regA) >> 1; this.resultZeroCarry = (this.resultZeroCarry & 0xff) | carry; this.nStepCycles -= 4; }; /** * op=0x21 (LXI H,d16) * * @this {CPUSim} */ CPUDef.opLXIH = function() { this.setHL(this.getPCWord()); this.nStepCycles -= 10; }; /** * op=0x22 (SHLD a16) * * @this {CPUSim} */ CPUDef.opSHLD = function() { this.setWord(this.getPCWord(), this.getHL()); this.nStepCycles -= 16; }; /** * op=0x23 (INX H) * * @this {CPUSim} */ CPUDef.opINXH = function() { this.setHL(this.getHL() + 1); this.nStepCycles -= 5; }; /** * op=0x24 (INR H) * * @this {CPUSim} */ CPUDef.opINRH = function() { this.regH = this.incByte(this.regH); this.nStepCycles -= 5; }; /** * op=0x25 (DCR H) * * @this {CPUSim} */ CPUDef.opDCRH = function() { this.regH = this.decByte(this.regH); this.nStepCycles -= 5; }; /** * op=0x26 (MVI H,d8) * * @this {CPUSim} */ CPUDef.opMVIH = function() { this.regH = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x27 (DAA) * * @this {CPUSim} */ CPUDef.opDAA = function() { var acc = this.regA; var fCarry = !!this.getCF(); var fAuxCarry = !!this.getAF(); if ((acc & 0xf) > 9 || fAuxCarry) { acc += 0x6; fAuxCarry = true; } else { fAuxCarry = false; } if (acc >= 0xa0 || fCarry) { acc += 0x60; fCarry = true; } else { fCarry = false; } this.resultZeroCarry = this.resultParitySign = this.regA = (acc & 0xff); this.updateCF(fCarry); this.updateAF(fAuxCarry); this.nStepCycles -= 4; }; /** * op=0x29 (DAD H) * * @this {CPUSim} */ CPUDef.opDADH = function() { var w; this.setHL(w = this.getHL() + this.getHL()); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100); this.nStepCycles -= 10; }; /** * op=0x2A (LHLD a16) * * @this {CPUSim} */ CPUDef.opLHLD = function() { this.setHL(this.getWord(this.getPCWord())); this.nStepCycles -= 16; }; /** * op=0x2B (DCX H) * * @this {CPUSim} */ CPUDef.opDCXH = function() { this.setHL(this.getHL() - 1); this.nStepCycles -= 5; }; /** * op=0x2C (INR L) * * @this {CPUSim} */ CPUDef.opINRL = function() { this.regL = this.incByte(this.regL); this.nStepCycles -= 5; }; /** * op=0x2D (DCR L) * * @this {CPUSim} */ CPUDef.opDCRL = function() { this.regL = this.decByte(this.regL); this.nStepCycles -= 5; }; /** * op=0x2E (MVI L,d8) * * @this {CPUSim} */ CPUDef.opMVIL = function() { this.regL = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x2F (CMA) * * @this {CPUSim} */ CPUDef.opCMA = function() { this.regA = ~this.regA & 0xff; this.nStepCycles -= 4; }; /** * op=0x31 (LXI SP,d16) * * @this {CPUSim} */ CPUDef.opLXISP = function() { this.setSP(this.getPCWord()); this.nStepCycles -= 10; }; /** * op=0x32 (STA a16) * * @this {CPUSim} */ CPUDef.opSTA = function() { this.setByte(this.getPCWord(), this.regA); this.nStepCycles -= 13; }; /** * op=0x33 (INX SP) * * @this {CPUSim} */ CPUDef.opINXSP = function() { this.setSP(this.getSP() + 1); this.nStepCycles -= 5; }; /** * op=0x34 (INR M) * * @this {CPUSim} */ CPUDef.opINRM = function() { var addr = this.getHL(); this.setByte(addr, this.incByte(this.getByte(addr))); this.nStepCycles -= 10; }; /** * op=0x35 (DCR M) * * @this {CPUSim} */ CPUDef.opDCRM = function() { var addr = this.getHL(); this.setByte(addr, this.decByte(this.getByte(addr))); this.nStepCycles -= 10; }; /** * op=0x36 (MVI M,d8) * * @this {CPUSim} */ CPUDef.opMVIM = function() { this.setByte(this.getHL(), this.getPCByte()); this.nStepCycles -= 10; }; /** * op=0x37 (STC) * * @this {CPUSim} */ CPUDef.opSTC = function() { this.setCF(); this.nStepCycles -= 4; }; /** * op=0x39 (DAD SP) * * @this {CPUSim} */ CPUDef.opDADSP = function() { var w; this.setSP(w = this.getHL() + this.getSP()); this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100); this.nStepCycles -= 10; }; /** * op=0x3A (LDA a16) * * @this {CPUSim} */ CPUDef.opLDA = function() { this.regA = this.getByte(this.getPCWord()); this.nStepCycles -= 13; }; /** * op=0x3B (DCX SP) * * @this {CPUSim} */ CPUDef.opDCXSP = function() { this.setSP(this.getSP() - 1); this.nStepCycles -= 5; }; /** * op=0x3C (INR A) * * @this {CPUSim} */ CPUDef.opINRA = function() { this.regA = this.incByte(this.regA); this.nStepCycles -= 5; }; /** * op=0x3D (DCR A) * * @this {CPUSim} */ CPUDef.opDCRA = function() { this.regA = this.decByte(this.regA); this.nStepCycles -= 5; }; /** * op=0x3E (MVI A,d8) * * @this {CPUSim} */ CPUDef.opMVIA = function() { this.regA = this.getPCByte(); this.nStepCycles -= 7; }; /** * op=0x3F (CMC) * * @this {CPUSim} */ CPUDef.opCMC = function() { this.updateCF(!this.getCF()); this.nStepCycles -= 4; }; /** * op=0x40 (MOV B,B) * * @this {CPUSim} */ CPUDef.opMOVBB = function() { this.nStepCycles -= 5; }; /** * op=0x41 (MOV B,C) * * @this {CPUSim} */ CPUDef.opMOVBC = function() { this.regB = this.regC; this.nStepCycles -= 5; }; /** * op=0x42 (MOV B,D) * * @this {CPUSim} */ CPUDef.opMOVBD = function() { this.regB = this.regD; this.nStepCycles -= 5; }; /** * op=0x43 (MOV B,E) * * @this {CPUSim} */ CPUDef.opMOVBE = function() { this.regB = this.regE; this.nStepCycles -= 5; }; /** * op=0x44 (MOV B,H) * * @this {CPUSim} */ CPUDef.opMOVBH = function() { this.regB = this.regH; this.nStepCycles -= 5; }; /** * op=0x45 (MOV B,L) * * @this {CPUSim} */ CPUDef.opMOVBL = function() { this.regB = this.regL; this.nStepCycles -= 5; }; /** * op=0x46 (MOV B,M) * * @this {CPUSim} */ CPUDef.opMOVBM = function() { this.regB = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x47 (MOV B,A) * * @this {CPUSim} */ CPUDef.opMOVBA = function() { this.regB = this.regA; this.nStepCycles -= 5; }; /** * op=0x48 (MOV C,B) * * @this {CPUSim} */ CPUDef.opMOVCB = function() { this.regC = this.regB; this.nStepCycles -= 5; }; /** * op=0x49 (MOV C,C) * * @this {CPUSim} */ CPUDef.opMOVCC = function() { this.nStepCycles -= 5; }; /** * op=0x4A (MOV C,D) * * @this {CPUSim} */ CPUDef.opMOVCD = function() { this.regC = this.regD; this.nStepCycles -= 5; }; /** * op=0x4B (MOV C,E) * * @this {CPUSim} */ CPUDef.opMOVCE = function() { this.regC = this.regE; this.nStepCycles -= 5; }; /** * op=0x4C (MOV C,H) * * @this {CPUSim} */ CPUDef.opMOVCH = function() { this.regC = this.regH; this.nStepCycles -= 5; }; /** * op=0x4D (MOV C,L) * * @this {CPUSim} */ CPUDef.opMOVCL = function() { this.regC = this.regL; this.nStepCycles -= 5; }; /** * op=0x4E (MOV C,M) * * @this {CPUSim} */ CPUDef.opMOVCM = function() { this.regC = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x4F (MOV C,A) * * @this {CPUSim} */ CPUDef.opMOVCA = function() { this.regC = this.regA; this.nStepCycles -= 5; }; /** * op=0x50 (MOV D,B) * * @this {CPUSim} */ CPUDef.opMOVDB = function() { this.regD = this.regB; this.nStepCycles -= 5; }; /** * op=0x51 (MOV D,C) * * @this {CPUSim} */ CPUDef.opMOVDC = function() { this.regD = this.regC; this.nStepCycles -= 5; }; /** * op=0x52 (MOV D,D) * * @this {CPUSim} */ CPUDef.opMOVDD = function() { this.nStepCycles -= 5; }; /** * op=0x53 (MOV D,E) * * @this {CPUSim} */ CPUDef.opMOVDE = function() { this.regD = this.regE; this.nStepCycles -= 5; }; /** * op=0x54 (MOV D,H) * * @this {CPUSim} */ CPUDef.opMOVDH = function() { this.regD = this.regH; this.nStepCycles -= 5; }; /** * op=0x55 (MOV D,L) * * @this {CPUSim} */ CPUDef.opMOVDL = function() { this.regD = this.regL; this.nStepCycles -= 5; }; /** * op=0x56 (MOV D,M) * * @this {CPUSim} */ CPUDef.opMOVDM = function() { this.regD = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x57 (MOV D,A) * * @this {CPUSim} */ CPUDef.opMOVDA = function() { this.regD = this.regA; this.nStepCycles -= 5; }; /** * op=0x58 (MOV E,B) * * @this {CPUSim} */ CPUDef.opMOVEB = function() { this.regE = this.regB; this.nStepCycles -= 5; }; /** * op=0x59 (MOV E,C) * * @this {CPUSim} */ CPUDef.opMOVEC = function() { this.regE = this.regC; this.nStepCycles -= 5; }; /** * op=0x5A (MOV E,D) * * @this {CPUSim} */ CPUDef.opMOVED = function() { this.regE = this.regD; this.nStepCycles -= 5; }; /** * op=0x5B (MOV E,E) * * @this {CPUSim} */ CPUDef.opMOVEE = function() { this.nStepCycles -= 5; }; /** * op=0x5C (MOV E,H) * * @this {CPUSim} */ CPUDef.opMOVEH = function() { this.regE = this.regH; this.nStepCycles -= 5; }; /** * op=0x5D (MOV E,L) * * @this {CPUSim} */ CPUDef.opMOVEL = function() { this.regE = this.regL; this.nStepCycles -= 5; }; /** * op=0x5E (MOV E,M) * * @this {CPUSim} */ CPUDef.opMOVEM = function() { this.regE = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x5F (MOV E,A) * * @this {CPUSim} */ CPUDef.opMOVEA = function() { this.regE = this.regA; this.nStepCycles -= 5; }; /** * op=0x60 (MOV H,B) * * @this {CPUSim} */ CPUDef.opMOVHB = function() { this.regH = this.regB; this.nStepCycles -= 5; }; /** * op=0x61 (MOV H,C) * * @this {CPUSim} */ CPUDef.opMOVHC = function() { this.regH = this.regC; this.nStepCycles -= 5; }; /** * op=0x62 (MOV H,D) * * @this {CPUSim} */ CPUDef.opMOVHD = function() { this.regH = this.regD; this.nStepCycles -= 5; }; /** * op=0x63 (MOV H,E) * * @this {CPUSim} */ CPUDef.opMOVHE = function() { this.regH = this.regE; this.nStepCycles -= 5; }; /** * op=0x64 (MOV H,H) * * @this {CPUSim} */ CPUDef.opMOVHH = function() { this.nStepCycles -= 5; }; /** * op=0x65 (MOV H,L) * * @this {CPUSim} */ CPUDef.opMOVHL = function() { this.regH = this.regL; this.nStepCycles -= 5; }; /** * op=0x66 (MOV H,M) * * @this {CPUSim} */ CPUDef.opMOVHM = function() { this.regH = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x67 (MOV H,A) * * @this {CPUSim} */ CPUDef.opMOVHA = function() { this.regH = this.regA; this.nStepCycles -= 5; }; /** * op=0x68 (MOV L,B) * * @this {CPUSim} */ CPUDef.opMOVLB = function() { this.regL = this.regB; this.nStepCycles -= 5; }; /** * op=0x69 (MOV L,C) * * @this {CPUSim} */ CPUDef.opMOVLC = function() { this.regL = this.regC; this.nStepCycles -= 5; }; /** * op=0x6A (MOV L,D) * * @this {CPUSim} */ CPUDef.opMOVLD = function() { this.regL = this.regD; this.nStepCycles -= 5; }; /** * op=0x6B (MOV L,E) * * @this {CPUSim} */ CPUDef.opMOVLE = function() { this.regL = this.regE; this.nStepCycles -= 5; }; /** * op=0x6C (MOV L,H) * * @this {CPUSim} */ CPUDef.opMOVLH = function() { this.regL = this.regH; this.nStepCycles -= 5; }; /** * op=0x6D (MOV L,L) * * @this {CPUSim} */ CPUDef.opMOVLL = function() { this.nStepCycles -= 5; }; /** * op=0x6E (MOV L,M) * * @this {CPUSim} */ CPUDef.opMOVLM = function() { this.regL = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x6F (MOV L,A) * * @this {CPUSim} */ CPUDef.opMOVLA = function() { this.regL = this.regA; this.nStepCycles -= 5; }; /** * op=0x70 (MOV M,B) * * @this {CPUSim} */ CPUDef.opMOVMB = function() { this.setByte(this.getHL(), this.regB); this.nStepCycles -= 7; }; /** * op=0x71 (MOV M,C) * * @this {CPUSim} */ CPUDef.opMOVMC = function() { this.setByte(this.getHL(), this.regC); this.nStepCycles -= 7; }; /** * op=0x72 (MOV M,D) * * @this {CPUSim} */ CPUDef.opMOVMD = function() { this.setByte(this.getHL(), this.regD); this.nStepCycles -= 7; }; /** * op=0x73 (MOV M,E) * * @this {CPUSim} */ CPUDef.opMOVME = function() { this.setByte(this.getHL(), this.regE); this.nStepCycles -= 7; }; /** * op=0x74 (MOV M,H) * * @this {CPUSim} */ CPUDef.opMOVMH = function() { this.setByte(this.getHL(), this.regH); this.nStepCycles -= 7; }; /** * op=0x75 (MOV M,L) * * @this {CPUSim} */ CPUDef.opMOVML = function() { this.setByte(this.getHL(), this.regL); this.nStepCycles -= 7; }; /** * op=0x76 (HLT) * * @this {CPUSim} */ CPUDef.opHLT = function() { /* * The CPU is never REALLY halted by a HLT instruction; instead, by setting X86.INTFLAG.HALT, * we are signalling to stepCPU() that it's free to end the current burst AND that it should not * execute any more instructions until checkINTR() indicates a hardware interrupt is requested. */ this.intFlags |= CPUDef.INTFLAG.HALT; this.nStepCycles -= 7; /* * If a Debugger is present and the HALT message category is enabled, then we REALLY halt the CPU, * on the theory that whoever's using the Debugger would like to see HLTs. */ if (DEBUGGER && this.dbg && this.messageEnabled(Messages.HALT)) { this.setPC(this.getPC() - 1); // this is purely for the Debugger's benefit, to show the HLT this.dbg.stopCPU(); return; } /* * We also REALLY halt the machine if interrupts have been disabled, since that means it's dead * in the water (we have no NMI generation mechanism at the moment). */ if (!this.getIF()) { if (DEBUGGER && this.dbg) this.setPC(this.getPC() - 1); this.stopCPU(); } }; /** * op=0x77 (MOV M,A) * * @this {CPUSim} */ CPUDef.opMOVMA = function() { this.setByte(this.getHL(), this.regA); this.nStepCycles -= 7; }; /** * op=0x78 (MOV A,B) * * @this {CPUSim} */ CPUDef.opMOVAB = function() { this.regA = this.regB; this.nStepCycles -= 5; }; /** * op=0x79 (MOV A,C) * * @this {CPUSim} */ CPUDef.opMOVAC = function() { this.regA = this.regC; this.nStepCycles -= 5; }; /** * op=0x7A (MOV A,D) * * @this {CPUSim} */ CPUDef.opMOVAD = function() { this.regA = this.regD; this.nStepCycles -= 5; }; /** * op=0x7B (MOV A,E) * * @this {CPUSim} */ CPUDef.opMOVAE = function() { this.regA = this.regE; this.nStepCycles -= 5; }; /** * op=0x7C (MOV A,H) * * @this {CPUSim} */ CPUDef.opMOVAH = function() { this.regA = this.regH; this.nStepCycles -= 5; }; /** * op=0x7D (MOV A,L) * * @this {CPUSim} */ CPUDef.opMOVAL = function() { this.regA = this.regL; this.nStepCycles -= 5; }; /** * op=0x7E (MOV A,M) * * @this {CPUSim} */ CPUDef.opMOVAM = function() { this.regA = this.getByte(this.getHL()); this.nStepCycles -= 7; }; /** * op=0x7F (MOV A,A) * * @this {CPUSim} */ CPUDef.opMOVAA = function() { this.nStepCycles -= 5; }; /** * op=0x80 (ADD B) * * @this {CPUSim} */ CPUDef.opADDB = function() { this.regA = this.addByte(this.regA, this.regB); this.nStepCycles -= 4; }; /** * op=0x81 (ADD C) * * @this {CPUSim} */ CPUDef.opADDC = function() { this.regA = this.addByte(this.regA, this.regC); this.nStepCycles -= 4; }; /** * op=0x82 (ADD D) * * @this {CPUSim} */ CPUDef.opADDD = function() { this.regA = this.addByte(this.regA, this.regD); this.nStepCycles -= 4; }; /** * op=0x83 (ADD E) * * @this {CPUSim} */ CPUDef.opADDE = function() { this.regA = this.addByte(this.regA, this.regE); this.nStepCycles -= 4; }; /** * op=0x84 (ADD H) * * @this {CPUSim} */ CPUDef.opADDH = function() { this.regA = this.addByte(this.regA, this.regH); this.nStepCycles -= 4; }; /** * op=0x85 (ADD L) * * @this {CPUSim} */ CPUDef.opADDL = function() { this.regA = this.addByte(this.regA, this.regL); this.nStepCycles -= 4; }; /** * op=0x86 (ADD M) * * @this {CPUSim} */ CPUDef.opADDM = function() { this.regA = this.addByte(this.regA, this.getByte(this.getHL())); this.nStepCycles -= 7; }; /** * op=0x87 (ADD A) * * @this {CPUSim} */ CPUDef.opADDA = function() { this.regA = this.addByte(this.regA, this.regA); this.nStepCycles -= 4; }; /** * op=0x88 (ADC B) * * @this {CPUSim} */ CPUDef.opADCB = function() { this.regA = this.addByteCarry(this.regA, this.regB); this.nStepCycles -= 4; }; /** * op=0x89 (ADC C) * * @this {CPUSim} */ CPUDef.opADCC = function() { this.regA = this.addByteCarry(this.regA, this.regC); this.nStepCycles -= 4; }; /** * op=0x8A (ADC D) * * @this {CPUSim} */ CPUDef.opADCD = function() { this.regA = this.addByteCarry(this.regA, this.regD); this.nStepCycles -= 4; }; /** * op=0x8B (ADC E) * * @this {CPUSim} */ CPUDef.opADCE = function() { this.regA = this.addByteCarry(this.regA, this.regE); this.nStepCycles -= 4; }; /** * op=0x8C (ADC H) * * @this {CPUSim} */ CPUDef.opADCH = function() { this.regA = this.addByteCarry(this.regA, this.regH); this.nStepCycles -= 4; }; /** * op=0x8D (ADC L) * * @this {CPUSim} */ CPUDef.opADCL = function() { this.regA = this.addByteCarry(this.regA, this.regL); this.nStepCycles -= 4; }; /** * op=0x8E (ADC M) * * @this {CPUSim} */ CPUDef.opADCM = function() { this.regA = this.addByteCarry(this.regA, this.getByte(this.getHL())); this.nStepCycles -= 7; }; /** * op=0x8F (ADC A) * * @this {CPUSim} */ CPUDef.opADCA = function() { this.regA = this.addByteCarry(this.regA, this.regA); this.nStepCycles -= 4; }; /** * op=0x90 (SUB B) * * @this {CPUSim} */ CPUDef.opSUBB = function() { this.regA = this.subByte(this.regA, this.regB); this.nStepCycles -= 4; }; /** * op=0x91 (SUB C) * * @this {CPUSim} */ CPUDef.opSUBC = function() { this.regA = this.subByte(this.regA, this.regC); this.nStepCycles -= 4; }; /** * op=0x92 (SUB D) * * @this {CPUSim} */ CPUDef.opSUBD = function() { this.regA = this.subByte(this.regA, this.regD); this.nStepCycles -= 4; }; /** * op=0x93 (SUB E) * * @this {CPUSim} */ CPUDef.opSUBE = function() { this.regA = this.subByte(this.regA, this.regE); this.nStepCycles -= 4; }; /** * op=0x94 (SUB H) * * @this {CPUSim} */ CPUDef.opSUBH = function() { this.regA = this.subByte(this.regA, this.regH); this.nStepCycles -= 4; }; /** * op=0x95 (SUB L) * * @this {CPUSim} */ CPUDef.opSUBL = function() { this.regA = this.subByte(this.regA, this.regL); this.nStepCycles -= 4; }; /** * op=0x96 (SUB M) * * @this {CPUSim} */ CPUDef.opSUBM = function() { this.regA = this.subByte(this.regA, this.getByte(this.getHL())); this.nStepCycles -= 7; }; /** * op=0x97 (SUB A) * * @this {CPUSim} */ CPUDef.opSUBA = function() { this.regA = this.subByte(this.regA, this.regA); this.nStepCycles -= 4; }; /** * op=0x98 (SBB B) * * @this {CPUSim} */ CPUDef.opSBBB = function() { this.regA = this.subByteBorrow(this.regA, this.regB); this.nStepCycles -= 4; }; /** * op=0x99 (SBB C) * * @this {CPUSim} */ CPUDef.opSBBC = function() { this.regA = this.subByteBorrow(this.regA, this.regC); this.nStepCycles -= 4; }; /** * op=0x9A (SBB D) * * @this {CPUSim} */ CPUDef.opSBBD = function() { this.regA = this.subByteBorrow(this.regA, this.regD); this.nStepCycles -= 4; }; /** * op=0x9B (SBB E) * * @this {CPUSim} */ CPUDef.opSBBE = function() { this.regA = this.subByteBorrow(this.regA, this.regE); this.nStepCycles -= 4; }; /** * op=0x9C (SBB H) * * @this {CPUSim} */ CPUDef.opSBBH = function() { this.regA = this.subByteBorrow(this.regA, this.regH); this.nStepCycles -= 4; }; /** * op=0x9D (SBB L) * * @this {CPUSim} */ CPUDef.opSBBL = function() { this.regA = this.subByteBorrow(this.regA, this.regL); this.nStepCycles -= 4; }; /** * op=0x9E (SBB M) * * @this {CPUSim} */ CPUDef.opSBBM = function() { this.regA = this.subByteBorrow(this.regA, this.getByte(this.getHL())); this.nStepCycles -= 7; }; /** * op=0x9F (SBB A) * * @this {CPUSim} */ CPUDef.opSBBA = function() { this.regA = this.subByteBorrow(this.regA, this.regA); this.nStepCycles -= 4; }; /** * op=0xA0 (ANA B) * * @this {CPUSim} */ CPUDef.opANAB = function() { this.regA = this.andByte(this.regA, this.regB); this.nStepCycles -= 4; }; /** * opTBD() * * @this {CPUSim} */ CPUDef.opTBD = function() { this.setPC(this.getPC() - 1); this.printMessage("unimplemented opcode", true); this.stopCPU(); }; /* * This 256-entry array of opcode functions is at the heart of the CPU engine: stepCPU(n). * * It might be worth trying a switch() statement instead, to see how the performance compares, * but I suspect that would vary quite a bit across JavaScript engines; for now, I'm putting my * money on array lookup. */ CPUDef.aOps = [ /* 0x00-0x03 */ CPUDef.opNOP, CPUDef.opLXIB, CPUDef.opSTAXB, CPUDef.opINXB, /* 0x04-0x07 */ CPUDef.opINRB, CPUDef.opDCRB, CPUDef.opMVIB, CPUDef.opRLC, /* 0x08-0x0B */ CPUDef.opNOP, CPUDef.opDADB, CPUDef.opLDAXB, CPUDef.opDCXB, /* 0x0C-0x0F */ CPUDef.opINRC, CPUDef.opDCRC, CPUDef.opMVIC, CPUDef.opRRC, /* 0x10-0x13 */ CPUDef.opNOP, CPUDef.opLXID, CPUDef.opSTAXD, CPUDef.opINXD, /* 0x14-0x17 */ CPUDef.opINRD, CPUDef.opDCRD, CPUDef.opMVID, CPUDef.opRAL, /* 0x18-0x1B */ CPUDef.opNOP, CPUDef.opDADD, CPUDef.opLDAXD, CPUDef.opDCXD, /* 0x1C-0x1F */ CPUDef.opINRE, CPUDef.opDCRE, CPUDef.opMVIE, CPUDef.opRAR, /* 0x20-0x23 */ CPUDef.opNOP, CPUDef.opLXIH, CPUDef.opSHLD, CPUDef.opINXH, /* 0x24-0x27 */ CPUDef.opINRH, CPUDef.opDCRH, CPUDef.opMVIH, CPUDef.opDAA, /* 0x28-0x2B */ CPUDef.opNOP, CPUDef.opDADH, CPUDef.opLHLD, CPUDef.opDCXH, /* 0x2C-0x2F */ CPUDef.opINRL, CPUDef.opDCRL, CPUDef.opMVIL, CPUDef.opCMA, /* 0x30-0x33 */ CPUDef.opNOP, CPUDef.opLXISP, CPUDef.opSTA, CPUDef.opINXSP, /* 0x34-0x37 */ CPUDef.opINRM, CPUDef.opDCRM, CPUDef.opMVIM, CPUDef.opSTC, /* 0x38-0x3B */ CPUDef.opNOP, CPUDef.opDADSP, CPUDef.opLDA, CPUDef.opDCXSP, /* 0x3C-0x3F */ CPUDef.opINRA, CPUDef.opDCRA, CPUDef.opMVIA, CPUDef.opCMC, /* 0x40-0x43 */ CPUDef.opMOVBB, CPUDef.opMOVBC, CPUDef.opMOVBD, CPUDef.opMOVBE, /* 0x44-0x47 */ CPUDef.opMOVBH, CPUDef.opMOVBL, CPUDef.opMOVBM, CPUDef.opMOVBA, /* 0x48-0x4B */ CPUDef.opMOVCB, CPUDef.opMOVCC, CPUDef.opMOVCD, CPUDef.opMOVCE, /* 0x4C-0x4F */ CPUDef.opMOVCH, CPUDef.opMOVCL, CPUDef.opMOVCM, CPUDef.opMOVCA, /* 0x50-0x53 */ CPUDef.opMOVDB, CPUDef.opMOVDC, CPUDef.opMOVDD, CPUDef.opMOVDE, /* 0x54-0x57 */ CPUDef.opMOVDH, CPUDef.opMOVDL, CPUDef.opMOVDM, CPUDef.opMOVDA, /* 0x58-0x5B */ CPUDef.opMOVEB, CPUDef.opMOVEC, CPUDef.opMOVED, CPUDef.opMOVEE, /* 0x5C-0x5F */ CPUDef.opMOVEH, CPUDef.opMOVEL, CPUDef.opMOVEM, CPUDef.opMOVEA, /* 0x60-0x63 */ CPUDef.opMOVHB, CPUDef.opMOVHC, CPUDef.opMOVHD, CPUDef.opMOVHE, /* 0x64-0x67 */ CPUDef.opMOVHH, CPUDef.opMOVHL, CPUDef.opMOVHM, CPUDef.opMOVHA, /* 0x68-0x6B */ CPUDef.opMOVLB, CPUDef.opMOVLC, CPUDef.opMOVLD, CPUDef.opMOVLE, /* 0x6C-0x6F */ CPUDef.opMOVLH, CPUDef.opMOVLL, CPUDef.opMOVLM, CPUDef.opMOVLA, /* 0x70-0x73 */ CPUDef.opMOVMB, CPUDef.opMOVMC, CPUDef.opMOVMD, CPUDef.opMOVME, /* 0x74-0x77 */ CPUDef.opMOVMH, CPUDef.opMOVML, CPUDef.opHLT, CPUDef.opMOVMA, /* 0x78-0x7B */ CPUDef.opMOVAB, CPUDef.opMOVAC, CPUDef.opMOVAD, CPUDef.opMOVAE, /* 0x7C-0x7F */ CPUDef.opMOVAH, CPUDef.opMOVAL, CPUDef.opMOVAM, CPUDef.opMOVAA, /* 0x80-0x83 */ CPUDef.opADDB, CPUDef.opADDC, CPUDef.opADDD, CPUDef.opADDE, /* 0x84-0x87 */ CPUDef.opADDH, CPUDef.opADDL, CPUDef.opADDM, CPUDef.opADDA, /* 0x88-0x8B */ CPUDef.opADCB, CPUDef.opADCC, CPUDef.opADCD, CPUDef.opADCE, /* 0x8C-0x8F */ CPUDef.opADCH, CPUDef.opADCL, CPUDef.opADCM, CPUDef.opADCA, /* 0x90-0x93 */ CPUDef.opSUBB, CPUDef.opSUBC, CPUDef.opSUBD, CPUDef.opSUBE, /* 0x94-0x97 */ CPUDef.opSUBH, CPUDef.opSUBL, CPUDef.opSUBM, CPUDef.opSUBA, /* 0x98-0x9B */ CPUDef.opSBBB, CPUDef.opSBBC, CPUDef.opSBBD, CPUDef.opSBBE, /* 0x9C-0x9F */ CPUDef.opSBBH, CPUDef.opSBBL, CPUDef.opSBBM, CPUDef.opSBBA, /* 0xA0-0xA3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xA4-0xA7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xA8-0xAB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xAC-0xAF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xB0-0xB3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xB4-0xB7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xB8-0xBB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xBC-0xBF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xC0-0xC3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xC4-0xC7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xC8-0xCB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xCC-0xCF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xD0-0xD3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xD4-0xD7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xD8-0xDB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xDC-0xDF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xE0-0xE3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xE4-0xE7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xE8-0xEB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xEC-0xEF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xF0-0xF3 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xF4-0xF7 */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xF8-0xFB */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, /* 0xFC-0xFF */ CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD, CPUDef.opTBD ];