Skip to content

Commit

Permalink
[MC6809] Fix capture context
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed May 4, 2024
1 parent be2699d commit a2665f3
Show file tree
Hide file tree
Showing 15 changed files with 995 additions and 982 deletions.
47 changes: 21 additions & 26 deletions debugger/mc6809/pins_mc6809.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ constexpr uint8_t PINS_HIGH[] = {
PIN_BREQ,
};

constexpr uint8_t PINS_PULLUP[] = {
PIN_XTAL,
};

constexpr uint8_t PINS_INPUT[] = {
PIN_D0,
PIN_D1,
Expand Down Expand Up @@ -177,6 +173,7 @@ constexpr uint8_t PINS_INPUT[] = {
PIN_E,
PIN_BS,
PIN_BA,
PIN_XTAL,
};

inline void extal_cycle() {
Expand All @@ -191,7 +188,6 @@ inline void extal_cycle() {
void PinsMc6809::resetPins() {
pinsMode(PINS_LOW, sizeof(PINS_LOW), OUTPUT, LOW);
pinsMode(PINS_HIGH, sizeof(PINS_HIGH), OUTPUT, HIGH);
pinsMode(PINS_PULLUP, sizeof(PINS_PULLUP), INPUT_PULLUP);
pinsMode(PINS_INPUT, sizeof(PINS_INPUT), INPUT);

assert_reset();
Expand All @@ -208,8 +204,8 @@ void PinsMc6809::resetPins() {
// C1L
extal_lo();
// At least one #RESET cycle.
cycle();
cycle();
for (auto i = 0; i < 3; ++i)
cycle();
negate_reset();
}

Expand All @@ -233,29 +229,29 @@ Signals *PinsMc6809::rawCycle() const {
// C1H
extal_hi();
busMode(D, INPUT);
auto signals = Signals::put();
auto s = Signals::put();
delayNanoseconds(c1_hi_ns);
// C2L
extal_lo();
delayNanoseconds(c2_lo_ns);
signals->getHighAddr();
s->getHighAddr();
// C2H
extal_hi();
signals->getDirection();
s->getDirection();
delayNanoseconds(c2_hi_ns);
// C3L
extal_lo();
signals->getLowAddr();
if (signals->write()) {
s->getLowAddr();
if (s->write()) {
delayNanoseconds(c3_lo_write);
// C3H
extal_hi();
signals->getData();
s->getData();
delayNanoseconds(c3_hi_write);
// C4L
extal_lo();
if (signals->writeMemory()) {
_mems->write(signals->addr, signals->data);
if (s->writeMemory()) {
_mems->write(s->addr, s->data);
if (c4_lo_write)
delayNanoseconds(c4_lo_write);
} else {
Expand All @@ -269,27 +265,27 @@ Signals *PinsMc6809::rawCycle() const {
delayNanoseconds(c3_lo_read);
// C3H
extal_hi();
if (signals->readMemory()) {
signals->data = _mems->read(signals->addr);
if (s->readMemory()) {
s->data = _mems->read(s->addr);
delayNanoseconds(c3_hi_read);
} else {
delayNanoseconds(c3_hi_inject);
}
// C4L
extal_lo();
busMode(D, OUTPUT);
busWrite(D, signals->data);
busWrite(D, s->data);
delayNanoseconds(c4_lo_read);
// C4H
extal_hi();
Signals::nextCycle();
delayNanoseconds(c4_hi_read);
}
// C1L
signals->clearControl();
s->clearControl();
extal_lo();

return signals;
return s;
}

Signals *PinsMc6809::cycle() const {
Expand Down Expand Up @@ -329,18 +325,17 @@ uint8_t PinsMc6809::captureContext(uint8_t *context, uint16_t &sp) {
injectReads(&SWI, sizeof(SWI));
uint16_t pc = 0;
uint8_t cap = 0;
auto s = Signals::put();
while (!s->vector()) {
s->capture();
s->inject(hi(pc));
s = cycle();
const Signals *s;
do {
s = Signals::put()->inject(hi(pc))->capture();
cycle();
if (s->write()) {
if (cap == 0)
sp = s->addr;
context[cap++] = s->data;
pc = uint16(context[1], context[0]);
}
}
} while (!s->vector());
Signals::put()->inject(lo(pc));
cycle(); // SWI lo(vector)
cycle(); // non-VMA
Expand Down
39 changes: 21 additions & 18 deletions debugger/mc6809/pins_mc6809e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ inline void c4_clock() {
digitalWriteFast(PIN_Q, LOW);
}

inline auto signal_avma() {
return digitalReadFast(PIN_AVMA);
}

void negate_irq() {
digitalWriteFast(PIN_IRQ, HIGH);
}
Expand Down Expand Up @@ -158,63 +162,62 @@ void PinsMc6809E::resetPins() {

assert_reset();
// At least one #RESET cycle.
for (auto i = 0; i < 3; i++)
for (auto i = 0; i < 5; i++)
cycle();
cycle();
negate_reset();
}

mc6809::Signals *PinsMc6809E::rawCycle() const {
static uint8_t vma = LOW;
static uint8_t vma_next = LOW;
// c1
busMode(D, INPUT);
auto signals = Signals::put();
auto s = Signals::put();
// c2
c2_clock();
delayNanoseconds(c2_ns);
signals->getDirection();
signals->getHighAddr();
s->getDirection();
s->getHighAddr();
// c3
c3_clock();
signals->getLowAddr();
if (vma == LOW) {
s->getLowAddr();
if (vma_next == LOW) {
delayNanoseconds(c3_novma);
// c4
c4_clock();
Signals::nextCycle();
delayNanoseconds(c4_novma);
} else if (signals->write()) {
} else if (s->write()) {
delayNanoseconds(c3_write);
signals->getData();
s->getData();
// c4
c4_clock();
if (signals->writeMemory()) {
_mems->write(signals->addr, signals->data);
if (s->writeMemory()) {
_mems->write(s->addr, s->data);
delayNanoseconds(c4_write);
} else {
delayNanoseconds(c4_capture);
}
Signals::nextCycle();
} else {
if (signals->readMemory()) {
signals->data = _mems->read(signals->addr);
if (s->readMemory()) {
s->data = _mems->read(s->addr);
delayNanoseconds(c3_read);
} else {
delayNanoseconds(c3_inject);
}
// c4
c4_clock();
busMode(D, OUTPUT);
busWrite(D, signals->data);
busWrite(D, s->data);
Signals::nextCycle();
delayNanoseconds(c4_read);
}
s->getControl();
vma_next = signal_avma();
// c1
signals->getControl();
c1_clock();
vma = signals->avma();

return signals;
return s;
}

mc6809::Signals *PinsMc6809E::cycle() const {
Expand Down
2 changes: 1 addition & 1 deletion debugger/mc6809/regs_mc6809.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace mc6809 {

SoftwareType RegsMc6809::checkSoftwareType() {
static const uint8_t DETECT_6309[] = {
0x5F, 0x10, // CLRB
0x5F, 0x10, // CLRB ; 1:N
0x10, 0x43, 0xF7, // COMD on HD6309 ; 1:2:N
// NOP on MC6809 ; 1:x:x
0xF7, 0x80, 0x00, // STB $8000 ; 1:2:3:B
Expand Down
1 change: 0 additions & 1 deletion debugger/mc6809/signals_mc6809.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void Signals::getDirection() {

void Signals::clearControl() {
lic() = 0;
avma() = 0;
vma() = 1;
}

Expand Down
2 changes: 0 additions & 2 deletions debugger/mc6809/signals_mc6809.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ struct Signals : SignalsBase<Signals, mc6800::Signals> {

bool vector() const { return status() == S_VEC; }
uint8_t lic() const { return _signals[4]; }
uint8_t avma() const { return _signals[5]; }
uint8_t &lic() { return _signals[4]; }
uint8_t &avma() { return _signals[5]; }

protected:
enum Status : uint8_t {
Expand Down
1 change: 0 additions & 1 deletion debugger/mc6809/signals_mc6809e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace mc6809e {

void Signals::getControl() {
lic() = digitalReadFast(PIN_LIC);
avma() = digitalReadFast(PIN_AVMA);
vma() = 1;
}

Expand Down
2 changes: 2 additions & 0 deletions debugger/mems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ uint32_t Mems::disassemble(uint32_t addr, uint8_t numInsn) const {
cli.print('\'');
}
cli.println();
if (insn.getError() == libasm::NO_MEMORY)
break;
}
addr += insn.length();
++num;
Expand Down
5 changes: 2 additions & 3 deletions samples/hd6309/mandelbrot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ main:
sta ACIA+2 ; set #FIRQ name for MC6805 emulator
andcc #~CC_FIRQ ; Clear FIRQ mask

loop:
jsr mandelbrot
jsr newline
wait: tst tx_queue ; tx queue len
bne wait
swi
bra loop

;;; Get character
;;; @return A
Expand Down
4 changes: 2 additions & 2 deletions samples/hd6309/mandelbrot.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ print_char:
jsr getchar
bcc next_x
tsta
beq mandelbrot_end ; break
bne next_x
swi ; halt to system
next_x:
inc vX ; X+=1
lda vX
Expand All @@ -165,5 +166,4 @@ next_x:
lda vY
cmpa #13
lblt loop_y ; if Y<13
mandelbrot_end:
rts
Loading

0 comments on commit a2665f3

Please sign in to comment.