| @@ -2,24 +2,66 @@ const Clock = require('common/clock.js'); | |||
| const BCD = require('utils/bcd.js'); | |||
| function ChangeICBit(cia, v, pos){ | |||
| let mask = ~(1 << pos); | |||
| v = ((v === true || v === 1) ? 1 : 0) << pos; | |||
| cia.__IC = (cia.__IC & mask) | v; | |||
| } | |||
| function TODTick(cia){ | |||
| cia.__TODTick += 1; | |||
| if (cia.__TODTick === 6){ | |||
| cia.__TODTick = cia.__CTA & 0x01; | |||
| if (cia.__10ths == 0x09){ | |||
| cia.__10ths = 0; | |||
| if (cia.__sec == 0x59){ | |||
| cia.__sec = 0; | |||
| if (cia.__min == 0x59){ | |||
| cia.__min = 0; | |||
| if (cia.__hour == 0x11 || cia.__hour == 0x91){ | |||
| cia.__hour = (cia.__hour == 0x91) ? 0x00 : 0x10; | |||
| } else { | |||
| let pm = cia.__hour & 0x80; | |||
| cia.__hour = BCD.add(cia.__hour & 0x7F, 0x01, 2) | pm; | |||
| } | |||
| } else {cia.__min = BCD.add(cia.__min, 0x01, 2);} | |||
| } else {cia.__sec = BCD.add(cia.__sec, 0x01, 2);} | |||
| } else {cia.__10ths = BCD.add(cia.__10ths, 0x01, 2);} | |||
| } | |||
| if (cia.__10ths == cia.__AL10ths && cia.__sec == cia.__ALsec && cia.__min == cia.__ALmin && cia.__hour == cia.__ALhour){ | |||
| ChangeICBit(cia, 1, 2); | |||
| } | |||
| } | |||
| class MOSCIA{ | |||
| constructor(){ | |||
| this.__regsel = 0; | |||
| this.__CTA = 0; | |||
| this.__CTB = 0; | |||
| this.__IC = 0; | |||
| this.__timerA = 0; | |||
| this.__timerALatch = 0; | |||
| this.__timerB = 0; | |||
| this.__timerBLatch = 0; | |||
| // Time Of Day | |||
| this.__TODLatch = 0; | |||
| this.__TODTick = 0; | |||
| this.__10ths = 0; | |||
| this.__sec = 0; | |||
| this.__min = 0; | |||
| this.__hours = 0; | |||
| this.__hour = 0; | |||
| // TOD Alarm | |||
| this.__AL10ths = 0; | |||
| this.__ALsec = 0; | |||
| this.__ALmin = 0; | |||
| this.__ALhour = 0; | |||
| } | |||
| get RS(){return this.__regsel;} | |||
| @@ -112,25 +154,7 @@ class MOSCIA{ | |||
| 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; | |||
| if (this.__10ths == 0x09){ | |||
| this.__10ths = 0; | |||
| if (this.__sec == 0x59){ | |||
| this.__sec = 0; | |||
| if (this.__min == 0x59){ | |||
| this.__min = 0; | |||
| if (this.__hour == 0x11 || this.__hour == 0x91){ | |||
| this.__hour = (this.__hour == 0x91) ? 0x00 : 0x10; | |||
| } else { | |||
| let pm = this.__hour & 0x80; | |||
| this.__hour = BCD.add(this.__hour & 0x7F, 0x01, 2) | pm; | |||
| } | |||
| } else {this.__min = BCD.add(this.__min, 0x01, 2);} | |||
| } else {this.__sec = BCD.add(this.__sec, 0x01, 2);} | |||
| } else {this.__10ths = BCD.add(this.__10ths, 0x01, 2);} | |||
| } | |||
| TODTick(this); | |||
| } | |||
| } | |||