MODULE SunPwrAd
TITLE 'Sun power controller address pal, Jim Gasbarro, December 5, 1988'

U02 DEVICE 'P16R4';

nS0, nS1, nS2, nS3, nS4, nS5, nS6 PIN 2, 3, 4, 5, 6, 7, 8;
SerIn, nForceOn, OnB PIN 9, 12, 13;
nJump PIN 19;
nCmd, OnA PIN 18, 17;
nHdrEven, nBad0To7, nBadAdr PIN 16, 15, 14;

IdleEven = ^h01;
StartEven = ^h10;
HdrEven = ^h32;
A0State = ^h72;
A1State = ^h33;
A2State = ^h60;
A3State = ^h25;
A4State = ^h3E;
A5State = ^h23;
A6State = ^h52;
IdleOdd = ^h57;
StartOdd = ^h2A;
HdrOdd = ^h59;
A7State = ^h78;
A8State = ^h0E;
CmdState = ^h75;
ResetState = ^h00;

A0 = 0;
A1 = 0;
A2 = 0;

A3 = 1;
A4 = 1;
A5 = 0;

A6 = 0;
A7 = 0;
A8 = 0;

St = [!nS0, !nS1, !nS2, !nS3, !nS4, !nS5, !nS6];

EQUATIONS

nJump = !(
(St == ResetState) #
(St == IdleEven) & SerIn #
(St == StartEven) & SerIn #
(St == IdleOdd) & SerIn #
(St == StartOdd) & SerIn #
(St == HdrOdd) & !SerIn
);

nCmd = !(St == CmdState);


OnA := !(
nCmd & !OnA & nForceOn #
(St == CmdState) & nBadAdr & (!OnA # OnB) & !SerIn & nForceOn #
(St == CmdState) & (!nBadAdr # (OnA & !OnB)) & !OnA & nForceOn #
(St == ResetState)
);

nHdrEven := !(St == HdrEven);

nBad0To7 := !(
(St == A0State) & (SerIn != A0) #
(St == A1State) & (SerIn != A1) #
(St == A2State) & (SerIn != A2) #
(St == A3State) & (SerIn != A3) #
(St == A4State) & (SerIn != A4) #
(St == A5State) & (SerIn != A5) #
(St == A6State) & (SerIn != A6) #
(St == A7State) & (SerIn != A7)
);

nBadAdr := !(
nHdrEven & !nBadAdr #
(St == HdrEven) & SerIn #
!nBad0To7 #
(St == A8State) & (SerIn != A8)
);

END SunPwrAd