Clean up CF handling (no more direct manipulation of result variables)
This commit is contained in:
parent
a02454467b
commit
9a0e5cddc6
4 changed files with 25 additions and 44 deletions
|
|
@ -13,7 +13,7 @@ machines:
|
||||||
8080 Exerciser Test Machine
|
8080 Exerciser Test Machine
|
||||||
---
|
---
|
||||||
|
|
||||||
This is a test of [PC8080](/modules/pc8080/), a new 8080-based machine emulator being added to the
|
This is a test of [PC8080](/modules/pc8080/), a new 8080-based machine emulator recently added to the
|
||||||
PCjs Project.
|
PCjs Project.
|
||||||
|
|
||||||
The test machine below loads a copy of the
|
The test machine below loads a copy of the
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ var CPUDef = {
|
||||||
SF: 0x0080, // bit 7: Sign flag
|
SF: 0x0080, // bit 7: Sign flag
|
||||||
ALL: 0x00D5, // all "arithmetic" flags (CF, PF, AF, ZF, SF)
|
ALL: 0x00D5, // all "arithmetic" flags (CF, PF, AF, ZF, SF)
|
||||||
MASK: 0x00FF, //
|
MASK: 0x00FF, //
|
||||||
IF: 0x0200 // bit 9: Interrupt flag (for internal use only)
|
IF: 0x0200 // bit 9: Interrupt flag (set if interrupts enabled; for internal use only)
|
||||||
},
|
},
|
||||||
PARITY: [ // 256-byte array with a 1 wherever the number of set bits of the array index is EVEN
|
PARITY: [ // 256-byte array with a 1 wherever the number of set bits of the array index is EVEN
|
||||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
||||||
|
|
@ -92,21 +92,21 @@ var CPUDef = {
|
||||||
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
* Bit values for intFlags
|
* Interrupt-related flags (stored in intFlags)
|
||||||
*/
|
*/
|
||||||
INTFLAG: {
|
INTFLAG: {
|
||||||
NONE: 0x00,
|
NONE: 0x00,
|
||||||
INTL: 0x07, // last interrupt level requested
|
INTL: 0x07, // last interrupt level requested
|
||||||
INTR: 0x08, // set if interrupt has been requested
|
INTR: 0x08, // set if interrupt has been requested
|
||||||
HALT: 0x10 // halt requested; see the HLT opcode
|
HALT: 0x10 // halt requested; see opHLT()
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
* Opcode definitions
|
* Opcode definitions
|
||||||
*/
|
*/
|
||||||
OPCODE: {
|
OPCODE: {
|
||||||
HLT: 0x76,
|
HLT: 0x76, // Halt
|
||||||
ACI: 0xCE, // PS.ALL
|
ACI: 0xCE, // Add with Carry Immediate (affects PS.ALL)
|
||||||
CALL: 0xCD,
|
CALL: 0xCD, // Call
|
||||||
RST0: 0xC7
|
RST0: 0xC7
|
||||||
// to be continued....
|
// to be continued....
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ CPUDef.opRLC = function()
|
||||||
{
|
{
|
||||||
var carry = this.regA << 1;
|
var carry = this.regA << 1;
|
||||||
this.regA = (carry & 0xff) | (carry >> 8);
|
this.regA = (carry & 0xff) | (carry >> 8);
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | (carry & 0x100);
|
this.updateCF(carry & 0x100);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ CPUDef.opDADB = function()
|
||||||
{
|
{
|
||||||
var w;
|
var w;
|
||||||
this.setHL(w = this.getHL() + this.getBC());
|
this.setHL(w = this.getHL() + this.getBC());
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100);
|
this.updateCF((w >> 8) & 0x100);
|
||||||
this.nStepCycles -= 10;
|
this.nStepCycles -= 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -204,7 +204,7 @@ CPUDef.opRRC = function()
|
||||||
{
|
{
|
||||||
var carry = (this.regA << 8) & 0x100;
|
var carry = (this.regA << 8) & 0x100;
|
||||||
this.regA = (carry | this.regA) >> 1;
|
this.regA = (carry | this.regA) >> 1;
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | carry;
|
this.updateCF(carry);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -282,8 +282,8 @@ CPUDef.opMVID = function()
|
||||||
CPUDef.opRAL = function()
|
CPUDef.opRAL = function()
|
||||||
{
|
{
|
||||||
var carry = this.regA << 1;
|
var carry = this.regA << 1;
|
||||||
this.regA = (carry & 0xff) | (this.resultZeroCarry >> 8);
|
this.regA = (carry & 0xff) | this.getCF();
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | (carry & 0x100);
|
this.updateCF(carry & 0x100);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -296,7 +296,7 @@ CPUDef.opDADD = function()
|
||||||
{
|
{
|
||||||
var w;
|
var w;
|
||||||
this.setHL(w = this.getHL() + this.getDE());
|
this.setHL(w = this.getHL() + this.getDE());
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100);
|
this.updateCF((w >> 8) & 0x100);
|
||||||
this.nStepCycles -= 10;
|
this.nStepCycles -= 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -362,9 +362,9 @@ CPUDef.opMVIE = function()
|
||||||
*/
|
*/
|
||||||
CPUDef.opRAR = function()
|
CPUDef.opRAR = function()
|
||||||
{
|
{
|
||||||
var carry = (this.regA << 8) & 0x100;
|
var carry = (this.regA << 8);
|
||||||
this.regA = ((this.resultZeroCarry & 0x100) | this.regA) >> 1;
|
this.regA = ((this.getCF() << 8) | this.regA) >> 1;
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | carry;
|
this.updateCF(carry & 0x100);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -452,7 +452,7 @@ CPUDef.opDAA = function()
|
||||||
CF = CPUDef.PS.CF;
|
CF = CPUDef.PS.CF;
|
||||||
}
|
}
|
||||||
this.regA = this.addByte(src);
|
this.regA = this.addByte(src);
|
||||||
this.updateCF(!!CF);
|
this.updateCF(CF? 0x100 : 0);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -465,7 +465,7 @@ CPUDef.opDADH = function()
|
||||||
{
|
{
|
||||||
var w;
|
var w;
|
||||||
this.setHL(w = this.getHL() + this.getHL());
|
this.setHL(w = this.getHL() + this.getHL());
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100);
|
this.updateCF((w >> 8) & 0x100);
|
||||||
this.nStepCycles -= 10;
|
this.nStepCycles -= 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -623,7 +623,7 @@ CPUDef.opDADSP = function()
|
||||||
{
|
{
|
||||||
var w;
|
var w;
|
||||||
this.setHL(w = this.getHL() + this.getSP());
|
this.setHL(w = this.getHL() + this.getSP());
|
||||||
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | ((w >> 8) & 0x100);
|
this.updateCF((w >> 8) & 0x100);
|
||||||
this.nStepCycles -= 10;
|
this.nStepCycles -= 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -689,7 +689,7 @@ CPUDef.opMVIA = function()
|
||||||
*/
|
*/
|
||||||
CPUDef.opCMC = function()
|
CPUDef.opCMC = function()
|
||||||
{
|
{
|
||||||
this.updateCF(!this.getCF());
|
this.updateCF(this.getCF()? 0 : 0x100);
|
||||||
this.nStepCycles -= 4;
|
this.nStepCycles -= 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ CPUSim.prototype.clearCF = function()
|
||||||
* getCF()
|
* getCF()
|
||||||
*
|
*
|
||||||
* @this {CPUSim}
|
* @this {CPUSim}
|
||||||
* @return {number} 0 or CPUDef.PS.CF
|
* @return {number} 0 or 1 (CPUDef.PS.CF)
|
||||||
*/
|
*/
|
||||||
CPUSim.prototype.getCF = function()
|
CPUSim.prototype.getCF = function()
|
||||||
{
|
{
|
||||||
|
|
@ -452,18 +452,14 @@ CPUSim.prototype.setCF = function()
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateCF(fCarry)
|
* updateCF(CF)
|
||||||
*
|
*
|
||||||
* @this {CPUSim}
|
* @this {CPUSim}
|
||||||
* @param {boolean} fCarry
|
* @param {number} CF (0x000 or 0x100)
|
||||||
*/
|
*/
|
||||||
CPUSim.prototype.updateCF = function(fCarry)
|
CPUSim.prototype.updateCF = function(CF)
|
||||||
{
|
{
|
||||||
if (fCarry) {
|
this.resultZeroCarry = (this.resultZeroCarry & 0xff) | CF;
|
||||||
this.resultZeroCarry |= 0x100;
|
|
||||||
} else {
|
|
||||||
this.resultZeroCarry &= ~0x100;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -528,21 +524,6 @@ CPUSim.prototype.setAF = function()
|
||||||
this.resultAuxOverflow = (~this.resultParitySign & 0x10) | (this.resultAuxOverflow & ~0x10);
|
this.resultAuxOverflow = (~this.resultParitySign & 0x10) | (this.resultAuxOverflow & ~0x10);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* updateAF(fAuxCarry)
|
|
||||||
*
|
|
||||||
* @this {CPUSim}
|
|
||||||
* @param {boolean} fAuxCarry
|
|
||||||
*/
|
|
||||||
CPUSim.prototype.updateAF = function(fAuxCarry)
|
|
||||||
{
|
|
||||||
if (fAuxCarry) {
|
|
||||||
this.setAF();
|
|
||||||
} else {
|
|
||||||
this.clearAF();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clearZF()
|
* clearZF()
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue