|
|
@@ -4,9 +4,11 @@ const BITM = require('./utils/bitman.js'); |
|
|
|
|
|
|
|
function EnableICBit(cia, pos){ |
|
|
|
v = 1 << pos; |
|
|
|
cia.__IC = cia.__IC | v; |
|
|
|
// Enabling any bit enables bit 7 as well! |
|
|
|
cia.__IC = cia.__IC | 0x80; |
|
|
|
if ((cia.__ICMask & v) === 0){ |
|
|
|
cia.__IC = cia.__IC | v; |
|
|
|
// Enabling any bit enables bit 7 as well! |
|
|
|
cia.__IC = cia.__IC | 0x80; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -54,7 +56,7 @@ function TimerATick(cia){ |
|
|
|
cia.__timerA -= 1; |
|
|
|
} else { |
|
|
|
// Check if Timer A is continuous |
|
|
|
if (BITM.isOn(cia.__CTA, 3) === 0){ |
|
|
|
if (BITM.val(cia.__CTA, 3) === 0){ |
|
|
|
cia.__timerA = cia.__timerALatch; |
|
|
|
} else { |
|
|
|
// Not continuous, so clear bit 0 (stop timer). |
|
|
@@ -84,7 +86,7 @@ function TimerBTick(cia){ |
|
|
|
if (cia.__timerB > 0){ |
|
|
|
cia.__timerB -= 1; |
|
|
|
} else { |
|
|
|
if (BITM.isOn(cia.__CTB, 3) === 0){ |
|
|
|
if (BITM.val(cia.__CTB, 3) === 0){ |
|
|
|
cia.__timerB = cia.__timerBLatch; |
|
|
|
} else { |
|
|
|
cia.__CTB = BITM.clear(cia.__CTB, 0); |
|
|
@@ -104,8 +106,9 @@ function Tick(cia){ |
|
|
|
if (BITM.isOn(cia.__CTA, 1) && !BITM.isOn(cia.__CTA, 2)) |
|
|
|
cia.__PDB = BITM.clear(cia.__PDB, 6); |
|
|
|
|
|
|
|
if (!BITM.isOn(cia.__CTA, 5)) |
|
|
|
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)) |
|
|
@@ -206,11 +209,11 @@ class MOSCIA{ |
|
|
|
case 0x04: // Timer A Low |
|
|
|
val = (this.__timerA & 0x00FF); break; |
|
|
|
case 0x05: // Timer A High |
|
|
|
val = ((this.__timerA & 0xFF00) >> 4); break; |
|
|
|
val = ((this.__timerA & 0xFF00) >> 8); break; |
|
|
|
case 0x06: // Timer B Low |
|
|
|
val = (this.__timerB & 0x00FF); break; |
|
|
|
case 0x07: // Timer B High |
|
|
|
val = ((this.__timerB & 0xFF00) >> 4); break; |
|
|
|
val = ((this.__timerB & 0xFF00) >> 8); break; |
|
|
|
case 0x08: // 10th of Sec Reg |
|
|
|
val = (this.__TODLatch !== null) ? this.__TODLatch[0] : this.__TOD[0]; |
|
|
|
this.__TODLatch = null; |
|
|
@@ -258,13 +261,13 @@ class MOSCIA{ |
|
|
|
this.__timerALatch = (this.__timerALatch & 0xFF00) | (d & 0xFF); |
|
|
|
break; |
|
|
|
case 0x05: // Timer A High |
|
|
|
this.__timerALatch = (this.__timerALatch & 0x00FF) | ((d & 0xFF) << 4); |
|
|
|
this.__timerALatch = (this.__timerALatch & 0x00FF) | ((d & 0xFF) << 8); |
|
|
|
break |
|
|
|
case 0x06: // Timer B Low |
|
|
|
this.__timerBLatch = (this.__timerBLatch & 0xFF00) | (d & 0xFF); |
|
|
|
break; |
|
|
|
case 0x07: // Timer B High |
|
|
|
this.__timerBLatch = (this.__timerBLatch & 0x00FF) | ((d & 0xFF) << 4); |
|
|
|
this.__timerBLatch = (this.__timerBLatch & 0x00FF) | ((d & 0xFF) << 8); |
|
|
|
break; |
|
|
|
case 0x08: // 10th of Sec Reg |
|
|
|
if (this.__TODTick < 0){ |