|
|
|
|
|
|
|
|
const Clock = require('common/clock.js'); |
|
|
|
|
|
const BCD = require('utils/bcd.js'); |
|
|
|
|
|
const BITM = require('utils/bitman.js'); |
|
|
|
|
|
|
|
|
const BCD = require('./utils/bcd.js'); |
|
|
|
|
|
const BITM = require('./utils/bitman.js'); |
|
|
|
|
|
|
|
|
function ChangeICBit(cia, v, pos){ |
|
|
function ChangeICBit(cia, v, pos){ |
|
|
let mask = ~(1 << pos); |
|
|
let mask = ~(1 << pos); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Tick(cia){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTA, 0)){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTA, 1) && !BITM.isOn(cia.__CTA, 2)) |
|
|
|
|
|
cia.__PDB = BITM.clear(cia.__PDB, 6); |
|
|
|
|
|
|
|
|
|
|
|
if (!BITM.isOn(cia.__CTA, 5)) |
|
|
|
|
|
TimerATick(cia); |
|
|
|
|
|
} |
|
|
|
|
|
if (BITM.isOn(cia.__CTB, 0)){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTB, 1) && !BITM.isOn(cia.__CTB, 2)) |
|
|
|
|
|
cia.__PDB = BITM.clear(cia.__PDB, 7); |
|
|
|
|
|
|
|
|
|
|
|
let cs = (cia.__CTB & 0x60) >> 5; |
|
|
|
|
|
if (cs === 0) |
|
|
|
|
|
TimerBTick(cia); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cia.__CNT === 1){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTA, 0) && BITM.isOn(cia.__CTA, 5)) |
|
|
|
|
|
TimerATick(cia); |
|
|
|
|
|
|
|
|
|
|
|
if (BITM.isOn(cia.__CTB, 0)){ |
|
|
|
|
|
let cs = (cia.__CTB & 0x60) >> 5; |
|
|
|
|
|
if (cs === 1) |
|
|
|
|
|
TimerBTick(cia); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (BITM.isOn(cia.__CTA, 6)){ |
|
|
|
|
|
if (cia.__SPi > 0){ |
|
|
|
|
|
cia.__SP = BITM.val(cia.__SData, 7); |
|
|
|
|
|
cia.__SData = (cia.__SData << 1) & 0xFF; |
|
|
|
|
|
cia.__SPi -= 1; |
|
|
|
|
|
if (cia.__SPi === 0) |
|
|
|
|
|
cia.__IC = BITM.set(cia.__IC, 3); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if (cia.__SPi < 8){ |
|
|
|
|
|
cia.__SData = (cia.__SData << 1) | cia.__SP; |
|
|
|
|
|
cia.__SPi += 1; |
|
|
|
|
|
if (cia.__SPi === 8) |
|
|
|
|
|
cia.__IC = BITM.set(cia.__IC, 3); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
cia.__CNT = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MOSCIA{ |
|
|
class MOSCIA{ |
|
|
constructor(){ |
|
|
constructor(){ |
|
|
this.__regsel = 0; |
|
|
this.__regsel = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set DATA(d){ |
|
|
set DATA(d){ |
|
|
if (this.__RW === 1){return;} |
|
|
if (this.__RW === 1){return;} |
|
|
|
|
|
let tod = 0; |
|
|
switch(this.__regsel){ |
|
|
switch(this.__regsel){ |
|
|
case 0x00: // Peripheral Data A |
|
|
case 0x00: // Peripheral Data A |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 0x08: // 10th of Sec Reg |
|
|
case 0x08: // 10th of Sec Reg |
|
|
TODLatch(this); |
|
|
TODLatch(this); |
|
|
this.__TODLatch = 2; |
|
|
this.__TODLatch = 2; |
|
|
let tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
|
|
|
|
|
|
tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
tod[0] = d & 0xFF; |
|
|
tod[0] = d & 0xFF; |
|
|
break; |
|
|
break; |
|
|
case 0x09: // Seconds Reg |
|
|
case 0x09: // Seconds Reg |
|
|
TODLatch(this); |
|
|
TODLatch(this); |
|
|
this.__TODLatch = 2; |
|
|
this.__TODLatch = 2; |
|
|
let tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
|
|
|
|
|
|
tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
tod[1] = d & 0xFF; |
|
|
tod[1] = d & 0xFF; |
|
|
break; |
|
|
break; |
|
|
case 0x0A: // Minutes Reg |
|
|
case 0x0A: // Minutes Reg |
|
|
TODLatch(this); |
|
|
TODLatch(this); |
|
|
this.__TODLatch = 2; |
|
|
this.__TODLatch = 2; |
|
|
let tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
|
|
|
|
|
|
tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
tod[2] = d & 0xFF; |
|
|
tod[2] = d & 0xFF; |
|
|
break; |
|
|
break; |
|
|
case 0x0B: // Hours AM/PM Reg |
|
|
case 0x0B: // Hours AM/PM Reg |
|
|
TODLatch(this); |
|
|
TODLatch(this); |
|
|
this.__TODLatch = 2; |
|
|
this.__TODLatch = 2; |
|
|
let tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
|
|
|
|
|
|
tod = (BITM.isOn(this.__CTB, 7)) ? this.__ALTOD : this.__TOD; |
|
|
tod[3] = d & 0xFF; |
|
|
tod[3] = d & 0xFF; |
|
|
break; |
|
|
break; |
|
|
case 0x0C: // Serial Data |
|
|
case 0x0C: // Serial Data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get CNT(){return this.__CNT;} |
|
|
get CNT(){return this.__CNT;} |
|
|
set CNT(c){ |
|
|
set CNT(c){ |
|
|
this.__CNT = (c >= 1) ? 1 : 0; |
|
|
|
|
|
if (this.__CNT === 1){ |
|
|
|
|
|
if (BITM.isOn(this.__CTA, 0) && BITM.isOn(this.__CTA, 5)) |
|
|
|
|
|
TimerATick(this); |
|
|
|
|
|
|
|
|
|
|
|
if (BITM.isOn(this.__CTB, 0)){ |
|
|
|
|
|
let cs = (this.__CTB & 0x60) >> 5; |
|
|
|
|
|
if (cs === 1) |
|
|
|
|
|
TimerBTick(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (BITM.isOn(this.__CTA, 6)){ |
|
|
|
|
|
if (this.__SPi > 0){ |
|
|
|
|
|
this.__SP = BITM.val(this.__SData, 7); |
|
|
|
|
|
this.__SData = this.__SData << 1; |
|
|
|
|
|
this.__SPi -= 1; |
|
|
|
|
|
if (this.__SPi === 0) |
|
|
|
|
|
BITM.set(this.__IC, 3); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if (this.__SPi < 7){ |
|
|
|
|
|
this.__SData = (this.__SData << 1) | this.__SP; |
|
|
|
|
|
this.__SPi += 1; |
|
|
|
|
|
if (this.__SPi === 7) |
|
|
|
|
|
BITM.set(this.__IC, 3); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.__CNT = (c >= 1) ? 1 : 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get SP(){return this.__SP;} |
|
|
get SP(){return this.__SP;} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get phi2(){return 0;} |
|
|
get phi2(){return 0;} |
|
|
set phi2(p){ |
|
|
set phi2(p){ |
|
|
if (p >= 1){ |
|
|
|
|
|
if (BITM.isOn(this.__CTA, 0)){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTA, 1) && !BITM.isOn(cia.__CTA, 2)) |
|
|
|
|
|
cia.__PDB = BITM.clear(cia.__PDB, 6); |
|
|
|
|
|
|
|
|
|
|
|
if (!BITM.isOn(this.__CTA, 5)) |
|
|
|
|
|
TimerATick(this); |
|
|
|
|
|
} |
|
|
|
|
|
if (BITM.isOn(this.__CTB, 0)){ |
|
|
|
|
|
if (BITM.isOn(cia.__CTB, 1) && !BITM.isOn(cia.__CTB, 2)) |
|
|
|
|
|
cia.__PDB = BITM.clear(cia.__PDB, 7); |
|
|
|
|
|
|
|
|
|
|
|
let cs = (this.__CTB & 0x60) >> 5; |
|
|
|
|
|
if (cs === 0) |
|
|
|
|
|
TimerBTick(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (p === true || p === 1){ |
|
|
|
|
|
Tick(this); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|