|
|
@@ -0,0 +1,129 @@ |
|
|
|
const Clock = require('common/clock.js'); |
|
|
|
|
|
|
|
function Num2BCD(n){ |
|
|
|
let v = (n < 9) ? Math.floor(n / 10) : 0; |
|
|
|
v = (v << 4) | (n - (v * 10)); |
|
|
|
return v; |
|
|
|
} |
|
|
|
|
|
|
|
class MOSCIA{ |
|
|
|
constructor(){ |
|
|
|
this.__regsel = 0; |
|
|
|
|
|
|
|
this.__CTA = 0; |
|
|
|
this.__CTB = 0; |
|
|
|
|
|
|
|
this.__timerA = 0; |
|
|
|
this.__timerALatch = 0; |
|
|
|
this.__timerB = 0; |
|
|
|
this.__timerBLatch = 0; |
|
|
|
|
|
|
|
this.__TODLatch = 0; |
|
|
|
this.__TODTick = 0; |
|
|
|
this.__10ths = 0; |
|
|
|
this.__sec = 0; |
|
|
|
this.__min = 0; |
|
|
|
this.__hours = 0; |
|
|
|
} |
|
|
|
|
|
|
|
get RS(){return this.__regsel;} |
|
|
|
set RS(rs){this.__regsel = rs & 0x0F;} |
|
|
|
|
|
|
|
get DATA(){ |
|
|
|
let val = 0; |
|
|
|
switch(this.__regsel){ |
|
|
|
case 0x00: // Peripheral Data A |
|
|
|
break; |
|
|
|
case 0x01: // Peripheral Data B |
|
|
|
break; |
|
|
|
case 0x02: // Data Direction Reg A |
|
|
|
break; |
|
|
|
case 0x03: // Data Direction Reg B |
|
|
|
break; |
|
|
|
case 0x04: // Timer A Low |
|
|
|
break; |
|
|
|
case 0x05: // Timer A High |
|
|
|
break |
|
|
|
case 0x06: // Timer B Low |
|
|
|
break; |
|
|
|
case 0x07: // Timer B High |
|
|
|
break; |
|
|
|
case 0x08: // 10th of Sec Reg |
|
|
|
this.__TODLatch = 0; |
|
|
|
return Num2BCD(this.__10ths); break; |
|
|
|
case 0x09: // Seconds Reg |
|
|
|
return Num2BCD(this.__sec); break; |
|
|
|
case 0x0A: // Minutes Reg |
|
|
|
return Num2BCD(this.__min); break; |
|
|
|
case 0x0B: // Hours AM/PM Reg |
|
|
|
this.__TODLatch = 1; |
|
|
|
return Num2BCD(this.__hours); break; |
|
|
|
case 0x0C: // Serial Data |
|
|
|
break; |
|
|
|
case 0x0D: // Interrupt Control |
|
|
|
break; |
|
|
|
case 0x0E: // Control Timer Reg A |
|
|
|
break; |
|
|
|
case 0x0F: // Control Timer Reg B |
|
|
|
break; |
|
|
|
} |
|
|
|
return val; |
|
|
|
} |
|
|
|
|
|
|
|
set DATA(d){ |
|
|
|
switch(this.__regsel){ |
|
|
|
case 0x00: // Peripheral Data A |
|
|
|
break; |
|
|
|
case 0x01: // Peripheral Data B |
|
|
|
break; |
|
|
|
case 0x02: // Data Direction Reg A |
|
|
|
break; |
|
|
|
case 0x03: // Data Direction Reg B |
|
|
|
break; |
|
|
|
case 0x04: // Timer A Low |
|
|
|
break; |
|
|
|
case 0x05: // Timer A High |
|
|
|
break |
|
|
|
case 0x06: // Timer B Low |
|
|
|
break; |
|
|
|
case 0x07: // Timer B High |
|
|
|
break; |
|
|
|
case 0x08: // 10th of Sec Reg |
|
|
|
break; |
|
|
|
case 0x09: // Seconds Reg |
|
|
|
break; |
|
|
|
case 0x0A: // Minutes Reg |
|
|
|
break; |
|
|
|
case 0x0B: // Hours AM/PM Reg |
|
|
|
break; |
|
|
|
case 0x0C: // Serial Data |
|
|
|
break; |
|
|
|
case 0x0D: // Interrupt Control |
|
|
|
break; |
|
|
|
case 0x0E: // Control Timer Reg A |
|
|
|
break; |
|
|
|
case 0x0F: // Control Timer Reg B |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
get CNT(){return 0;} |
|
|
|
set CNT(c){} |
|
|
|
|
|
|
|
get SP(){return 0;} |
|
|
|
set SP(b){} |
|
|
|
|
|
|
|
get TOD(){return 0;} |
|
|
|
set TOD(b){ |
|
|
|
if (b <= 0 || this.__TODLatch > 0){return;} |
|
|
|
this.__TODTick += 1; |
|
|
|
if (this.__TODTick === 6){ |
|
|
|
this.__TODTick = this.__CTA & 0x01; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = MOSCIA; |
|
|
|
|
|
|
|
|