| const Clock = require('common/clock.js'); | const Clock = require('common/clock.js'); | ||||
| const BCD = require('utils/bcd.js'); | |||||
| function Num2BCD(n){ | |||||
| let v = (n < 9) ? Math.floor(n / 10) : 0; | |||||
| v = (v << 4) | (n - (v * 10)); | |||||
| return v; | |||||
| } | |||||
| class MOSCIA{ | class MOSCIA{ | ||||
| constructor(){ | constructor(){ | ||||
| break; | break; | ||||
| case 0x08: // 10th of Sec Reg | case 0x08: // 10th of Sec Reg | ||||
| this.__TODLatch = 0; | this.__TODLatch = 0; | ||||
| return Num2BCD(this.__10ths); break; | |||||
| return this.__10ths; break; | |||||
| case 0x09: // Seconds Reg | case 0x09: // Seconds Reg | ||||
| return Num2BCD(this.__sec); break; | |||||
| return this.__sec; break; | |||||
| case 0x0A: // Minutes Reg | case 0x0A: // Minutes Reg | ||||
| return Num2BCD(this.__min); break; | |||||
| return this.__min; break; | |||||
| case 0x0B: // Hours AM/PM Reg | case 0x0B: // Hours AM/PM Reg | ||||
| this.__TODLatch = 1; | this.__TODLatch = 1; | ||||
| return Num2BCD(this.__hours); break; | |||||
| return this.__hours; break; | |||||
| case 0x0C: // Serial Data | case 0x0C: // Serial Data | ||||
| break; | break; | ||||
| case 0x0D: // Interrupt Control | case 0x0D: // Interrupt Control | ||||
| this.__TODTick += 1; | this.__TODTick += 1; | ||||
| if (this.__TODTick === 6){ | if (this.__TODTick === 6){ | ||||
| this.__TODTick = this.__CTA & 0x01; | 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);} | |||||
| } | } | ||||
| } | } | ||||
| } | } |