瀏覽代碼

Tweaks to MOSCIA

master
Bryan Miller 5 年之前
父節點
當前提交
4772ddfaf5
共有 1 個文件被更改,包括 34 次插入4 次删除
  1. +34
    -4
      src/MOSCIA.js

+ 34
- 4
src/MOSCIA.js 查看文件

@@ -1,3 +1,4 @@
const IO = require('./common/io.js');
const BCD = require('./utils/bcd.js');
const BITM = require('./utils/bitman.js');

@@ -143,6 +144,7 @@ function Tick(cia){

class MOSCIA{
constructor(){
this.__io = new IO(["PDA", "PDB"], ["PDA", "PDB"]);
this.__regsel = 0;
this.__RW = 0;

@@ -186,13 +188,15 @@ class MOSCIA{
let val = 0;
switch(this.__regsel){
case 0x00: // Peripheral Data A
break;
this.__io.triggerRead("PDA", this.__DDA);
val = this.__PDA; break;
case 0x01: // Peripheral Data B
break;
this.__io.triggerRead("PDB", this.__DDB);
val = this.__PDB; break;
case 0x02: // Data Direction Reg A
break;
val = this.__DDA; break;
case 0x03: // Data Direction Reg B
break;
val = this.__DDB; break;
case 0x04: // Timer A Low
val = (this.__timerA & 0x00FF); break;
case 0x05: // Timer A High
@@ -230,12 +234,18 @@ class MOSCIA{
let tod = 0;
switch(this.__regsel){
case 0x00: // Peripheral Data A
this.__io.triggerWrite("PDA", this.__PDA, d & 0xFF);
this.__PDA = (this.__PDA & (~this.__DDA)) | ((d & 0xFF) & this.__DDA);
break;
case 0x01: // Peripheral Data B
this.__io.triggerWrite("PDB", this.__PDB, d & 0xFF);
this.__PDB = (this.__PDB & (~this.__DDB)) | ((d & 0xFF) & this.__DDB);
break;
case 0x02: // Data Direction Reg A
this.__DDA = d & 0xFF;
break;
case 0x03: // Data Direction Reg B
this.__DDB = d & 0xFF;
break;
case 0x04: // Timer A Low
this.__timerALatch = (this.__timerALatch & 0xFF00) | (d & 0xFF);
@@ -324,6 +334,25 @@ class MOSCIA{
}
}

onRead(name, fn){
this.__io.onRead(name, fn);
return this;
}

onWrite(name, fn){
this.__io.onWrite(name, fn);
return this;
}

setPDA(v){
this.__PDA = (this.__PDA & this.__DDA) | ((v & 0xFF) & (~this.__DDA));
return this;
}

setPDB(v){
this.__PDB = (this.__PDB & this.__DDB) | ((v & 0xFF) & (~this.__DDB));
return this;
}

reset(){
this.__CNT = 0;
@@ -350,6 +379,7 @@ class MOSCIA{
this.__TOD = [0,0,0,0];
this.__LTOD = [0,0,0,0];
this.__ALTOD = [0,0,0,0];
return this;
}
}


Loading…
取消
儲存