Skip to content

Commit

Permalink
template TST TSTB
Browse files Browse the repository at this point in the history
  • Loading branch information
davecheney committed Sep 22, 2020
1 parent 3edcb5d commit e7fc08a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
24 changes: 2 additions & 22 deletions kb11.cc
Expand Up @@ -440,26 +440,6 @@ void KB11::MOVB(const uint16_t instr) {
setNZ<1>(src);
}

// TST 0057DD
void KB11::TST(const uint16_t instr) {
auto dst = memread<2>(DA(instr));
PSW &= 0xFFF0;
setZ(dst == 0);
if (dst & 0x8000) {
PSW |= FLAGN;
}
}

// TSTB 1057DD
void KB11::TSTB(const uint16_t instr) {
auto dst = memread<1>(DA(instr));
PSW &= 0xFFF0;
setZ(dst == 0);
if (dst & 0x80) {
PSW |= FLAGN;
}
}

// SWAB 0003DD
void KB11::SWAB(const uint16_t instr) {
auto da = DA(instr);
Expand Down Expand Up @@ -611,7 +591,7 @@ void KB11::step() {
SBC<2>(instr);
return;
case 057: // TST 0057DD
TST(instr);
TST<2>(instr);
return;
case 060: // ROR 0060DD
ROR<2>(instr);
Expand Down Expand Up @@ -759,7 +739,7 @@ void KB11::step() {
SBC<1>(instr);
return;
case 057: // TSTB 1057DD
TSTB(instr);
TST<1>(instr);
return;
case 060: // RORB 1060DD
ROR<1>(instr);
Expand Down
18 changes: 18 additions & 0 deletions kb11.h
Expand Up @@ -185,6 +185,18 @@ class KB11 {
}
}

// Set N, Z, clearing C & V
template <uint16_t len> void setNZC(uint16_t v) {
static_assert(len == 1 || len == 2);
PSW &= 0xFFF0;
if (v == 0) {
PSW |= FLAGZ;
}
if (v & (len == 2 ? 0x8000 : 0x80)) {
PSW |= FLAGN;
}
}

template <uint8_t l> void BIC(const uint16_t instr) {
const uint16_t msb = l == 2 ? 0x8000 : 0x80;
const uint16_t max = l == 2 ? 0xFFFF : 0xff;
Expand Down Expand Up @@ -433,6 +445,12 @@ class KB11 {
setNZ<l>(result);
}

// TST 0057DD, TSTB 1057DD
template <uint16_t l> void TST(const uint16_t instr) {
auto dst = memread<l>(DA(instr));
setNZC<l>(dst);
}

void ADD(const uint16_t instr);
void SUB(const uint16_t instr);
void JSR(const uint16_t instr);
Expand Down

0 comments on commit e7fc08a

Please sign in to comment.