Browse Source

MOS CIA can now be reset. Serial communication implemented.

master
Bryan Miller 5 years ago
parent
commit
d3b1742795
1 changed files with 71 additions and 8 deletions
  1. +71
    -8
      src/MOSCIA.js

+ 71
- 8
src/MOSCIA.js View File

class MOSCIA{ class MOSCIA{
constructor(){ constructor(){
this.__regsel = 0; this.__regsel = 0;
this.__RW = 0;


this.__CNT = 0; this.__CNT = 0;
this.__SP = 0;
this.__SPi = 0;
this.__SData = 0;


this.__PDA = 0; this.__PDA = 0;
this.__PDB = 0; this.__PDB = 0;
this.__ICMask = 0; this.__ICMask = 0;


this.__timerA = 0; this.__timerA = 0;
this.__timerALatch = 0;
this.__timerALatch = 1;
this.__timerB = 0; this.__timerB = 0;
this.__timerBLatch = 0;
this.__timerBLatch = 1;


// Time Of Day // Time Of Day
this.__TODLatch = 0; this.__TODLatch = 0;
get RS(){return this.__regsel;} get RS(){return this.__regsel;}
set RS(rs){this.__regsel = rs & 0x0F;} set RS(rs){this.__regsel = rs & 0x0F;}


get RW(){return this.__RW;}
set RW(rw){this.__RW = (rw === true || rw === 1) ? 1 : 0;}

get DATA(){ get DATA(){
let val = 0; let val = 0;
switch(this.__regsel){ switch(this.__regsel){
TODLatch(this); TODLatch(this);
val = this.__LTOD[3]; break; val = this.__LTOD[3]; break;
case 0x0C: // Serial Data case 0x0C: // Serial Data
break;
val = this.__SData; break;
case 0x0D: // Interrupt Control case 0x0D: // Interrupt Control
let v = this.__IC; let v = this.__IC;
this.__IC = 0; this.__IC = 0;
} }


set DATA(d){ set DATA(d){
if (this.__RW === 1){return;}
switch(this.__regsel){ switch(this.__regsel){
case 0x00: // Peripheral Data A case 0x00: // Peripheral Data A
break; break;
if (BITM.isOn(this.__CTA, 0) && BITM.isOn(this.__CTA, 5)) if (BITM.isOn(this.__CTA, 0) && BITM.isOn(this.__CTA, 5))
TimerATick(this); TimerATick(this);


if (BITM.isOn(this.__CTB, 0){
if (BITM.isOn(this.__CTB, 0)){
let cs = (this.__CTB & 0x60) >> 5; let cs = (this.__CTB & 0x60) >> 5;
if (cs === 1) if (cs === 1)
TimerBTick(this); TimerBTick(this);
} }

if (BITM.isOn(this.__CTA, 6)){
if (this.__SPi > 0){
this.__SP = BITM.val(this.__SData, 7);
this.__SData = this.__SData << 1;
this.__SPi -= 1;
if (this.__SPi === 0)
BITM.set(this.__IC, 3);
}
} else {
if (this.__SPi < 7){
this.__SData = (this.__SData << 1) | this.__SP;
this.__SPi += 1;
if (this.__SPi === 7)
BITM.set(this.__IC, 3);
}
}
} }
} }


get SP(){return 0;}
set SP(b){}
get SP(){return this.__SP;}
set SP(sp){
this.__SP = (sp === true || sp === 1) ? 1 : 0;
}


get TOD(){return 0;} get TOD(){return 0;}
set TOD(b){ set TOD(b){
get phi2(){return 0;} get phi2(){return 0;}
set phi2(p){ set phi2(p){
if (p >= 1){ if (p >= 1){
if (BITM.isOn(this.__CTA, 0) && !BITM.isOn(this.__CTA, 5)){
TimerATick(this);
if (BITM.isOn(this.__CTA, 0)){
if (BITM.isOn(cia.__CTA, 1) && !BITM.isOn(cia.__CTA, 2))
cia.__PDB = BITM.clear(cia.__PDB, 6);

if (!BITM.isOn(this.__CTA, 5))
TimerATick(this);
} }
if (BITM.isOn(this.__CTB, 0)){ if (BITM.isOn(this.__CTB, 0)){
if (BITM.isOn(cia.__CTB, 1) && !BITM.isOn(cia.__CTB, 2))
cia.__PDB = BITM.clear(cia.__PDB, 7);

let cs = (this.__CTB & 0x60) >> 5; let cs = (this.__CTB & 0x60) >> 5;
if (cs === 0) if (cs === 0)
TimerBTick(this); TimerBTick(this);
} }
} }
} }


reset(){
this.__CNT = 0;

this.__PDA = 0;
this.__PDB = 0;
this.__DDA = 0;
this.__DDB = 0;

this.__CTA = 0;
this.__CTB = 0;

this.__IC = 0;
this.__ICMask = 0;

this.__timerA = 0;
this.__timerALatch = 1;
this.__timerB = 0;
this.__timerBLatch = 1;

// Time Of Day
this.__TODLatch = 0;
this.__TODTick = 0;
this.__TOD = [0,0,0,0];
this.__LTOD = [0,0,0,0];
this.__ALTOD = [0,0,0,0];
}
} }





Loading…
Cancel
Save