#include "basic.h"
#include "clock.h"
#include "datapath.h"
#include "mic.h"
#include "comm.h"
#include "mem.h"
#include "computer.h"

Define Space | O;
 And aa ZERO ZERO O;
Endef;

/* ------
   The only input into the computer is the Reset and the manual clock !
   ------ */
Switch "0: Clk" hw-hx Tick ZERO;
Switch "1: Rst" hy-hz Reset ZERO;

/* ------
   Here is the computer
   ------ */
Computer "Computer" eo-hr Tick Reset | 
  Phase[1-4] 
  R0[15..0] R1[15..0] R2[15..0] R3[15..0] R4[15..0] R5[15..0]
  R6[15..0] R7[15..0] R8[15..0] R9[15..0] R10[15..0] R11[15..0]
  R12[15..0] R13[15..0] R14[15..0] R15[15..0]
  ABus[15-0] BBus[15-0] ALat[15-0] BLat[16-0]
  AMUX[15-0] ALUOut[15-0] C[15-0] N Z
  branch mir[31-0] MPC[7-0]
  MReq READ AddrBus[15..0] CommOut[15..0] mbr[15..0]
  DataBus[15..0];


/* ------
   The rest are probes...
   ------ */

/* -----------------
   4-phase clock
   ----------------- */
Probe "Ph1" gw Phase[1];
Probe "Ph2" gx Phase[2];
Probe "Ph3" gy Phase[3];
Probe "Ph4" gz Phase[4];

/* ---------------------------------------------------
   Registers R0 to R15
   --------------------------------------------------- */
Byte-probe-h "R0" aa-ac R0[15..8]; Byte-probe-h "PC" ad-af R0[7..0];
Byte-probe-h "R1" ba-bc R1[15..8]; Byte-probe-h "AC" bd-bf R1[7..0];
Byte-probe-h "R2" ca-cc R2[15..8]; Byte-probe-h "SP" cd-cf R2[7..0];
Byte-probe-h "R3" da-dc R3[15..8]; Byte-probe-h "IR" dd-df R3[7..0];
Byte-probe-h "R4" ea-ec R4[15..8]; Byte-probe-h "TIR" ed-ef R4[7..0];
Byte-probe-h "R5" fa-fc R5[15..8]; Byte-probe-h "0" fd-ff R5[7..0];
Byte-probe-h "R6" ga-gc R6[15..8]; Byte-probe-h "+1" gd-gf R6[7..0];
Byte-probe-h "R7" ha-hc R7[15..8]; Byte-probe-h "-1" hd-hf R7[7..0];

Byte-probe-h "R8"  ah-aj R8[15..8];  Byte-probe-h "AMASK"  ak-am R8[7..0];
Byte-probe-h "R9"  bh-bj R9[15..8];  Byte-probe-h "DMASK"  bk-bm R9[7..0];
Byte-probe-h "R10" ch-cj R10[15..8]; Byte-probe-h "A-Reg" ck-cm R10[7..0];
Byte-probe-h "R11" dh-dj R11[15..8]; Byte-probe-h "B-Reg" dk-dm R11[7..0];
Byte-probe-h "R12" eh-ej R12[15..8]; Byte-probe-h "C-Reg" ek-em R12[7..0];
Byte-probe-h "R13" fh-fj R13[15..8]; Byte-probe-h "R13" fk-fm R13[7..0];
Byte-probe-h "R14" gh-gj R14[15..8]; Byte-probe-h "R14" gk-gm R14[7..0];
Byte-probe-h "R15" hh-hj R15[15..8]; Byte-probe-h "R15" hk-hm R15[7..0];


/* ----------------------------
   A-Bus, B-Bus and C-bus data
   ---------------------------- */
Probe "A" jj.aa ABus[15]; Probe "-" jj.ab ABus[14];
Probe "B" jk.aa ABus[13]; Probe "u" jk.ab ABus[12];
Probe "s" jl.aa ABus[11]; Probe " " jl.ab ABus[10];
Probe "D" jm.aa ABus[9];  Probe "a" jm.ab ABus[8];
Probe "t" jn.aa ABus[7];  Probe "a" jn.ab ABus[6];
Probe " " jo.aa ABus[5];  Probe " " jo.ab ABus[4];
Probe " " jp.aa ABus[3];  Probe " " jp.ab ABus[2];
Probe " " jq.aa ABus[1];  Probe " " jq.ab ABus[0];

Probe "B" js.aa BBus[15]; Probe "-" js.ab BBus[14];
Probe "B" jt.aa BBus[13]; Probe "u" jt.ab BBus[12];
Probe "s" ju.aa BBus[11]; Probe " " ju.ab BBus[10];
Probe "D" jv.aa BBus[9];  Probe "a" jv.ab BBus[8];
Probe "t" jw.aa BBus[7];  Probe "a" jw.ab BBus[6];
Probe " " jx.aa BBus[5];  Probe " " jx.ab BBus[4];
Probe " " jy.aa BBus[3];  Probe " " jy.ab BBus[2];
Probe " " jz.aa BBus[1];  Probe " " jz.ab BBus[0];

Probe "A" kj.aa ALat[15]; Probe "-" kj.ab ALat[14];
Probe "L" kk.aa ALat[13]; Probe "a" kk.ab ALat[12];
Probe "t" kl.aa ALat[11]; Probe "c" kl.ab ALat[10];
Probe "h" km.aa ALat[9];  Probe " " km.ab ALat[8];
Probe "O" kn.aa ALat[7];  Probe "u" kn.ab ALat[6];
Probe "t" ko.aa ALat[5];  Probe "p" ko.ab ALat[4];
Probe "u" kp.aa ALat[3];  Probe "t" kp.ab ALat[2];
Probe " " kq.aa ALat[1];  Probe " " kq.ab ALat[0];

Probe "B" ks.aa BLat[15]; Probe "-" ks.ab BLat[14];
Probe "L" kt.aa BLat[13]; Probe "a" kt.ab BLat[12];
Probe "t" ku.aa BLat[11]; Probe "c" ku.ab BLat[10];
Probe "h" kv.aa BLat[9];  Probe " " kv.ab BLat[8];
Probe "O" kw.aa BLat[7];  Probe "u" kw.ab BLat[6];
Probe "t" kx.aa BLat[5];  Probe "p" kx.ab BLat[4];
Probe "u" ky.aa BLat[3];  Probe "t" ky.ab BLat[2];
Probe " " kz.aa BLat[1];  Probe " " kz.ab BLat[0];

Probe "A" lj.aa AMUX[15]; Probe "-" lj.ab AMUX[14];
Probe "M" lk.aa AMUX[13]; Probe "U" lk.ab AMUX[12];
Probe "X" ll.aa AMUX[11]; Probe " " ll.ab AMUX[10];
Probe "O" lm.aa AMUX[9];  Probe "u" lm.ab AMUX[8];
Probe "t" ln.aa AMUX[7];  Probe "p" ln.ab AMUX[6];
Probe "u" lo.aa AMUX[5];  Probe "t" lo.ab AMUX[4];
Probe " " lp.aa AMUX[3];  Probe " " lp.ab AMUX[2];
Probe " " lq.aa AMUX[1];  Probe " " lq.ab AMUX[0];


Probe "N" nm N;
Probe "Z" nm Z;

Probe "A" no.aa ALUOut[15]; Probe "L" no.ab ALUOut[14];
Probe "U" np.aa ALUOut[13]; Probe " " np.ab ALUOut[12];
Probe "o" nq.aa ALUOut[11]; Probe "u" nq.ab ALUOut[10];
Probe "t" nr.aa ALUOut[9];  Probe "p" nr.ab ALUOut[8];
Probe "u" ns.aa ALUOut[7];  Probe "t" ns.ab ALUOut[6];
Probe " " nt.aa ALUOut[5];  Probe " " nt.ab ALUOut[4];
Probe " " nu.aa ALUOut[3];  Probe " " nu.ab ALUOut[2];
Probe " " nv.aa ALUOut[1];  Probe " " nv.ab ALUOut[0];

Probe "S" oo.aa C[15]; Probe "H" oo.ab C[14];
Probe "F" op.aa C[13]; Probe " " op.ab C[12];
Probe "o" oq.aa C[11]; Probe "u" oq.ab C[10];
Probe "t" or.aa C[9];  Probe "p" or.ab C[8];
Probe "u" os.aa C[7];  Probe "t" os.ab C[6];
Probe " " ot.aa C[5];  Probe " " ot.ab C[4];
Probe " " ou.aa C[3];  Probe " " ou.ab C[2];
Probe " " ov.aa C[1];  Probe " " ov.ab C[0];


/* ---------------------------------
   Data after AMUX (A-latch or MBR)
   --------------------------------- */




/* ---------------------------------
   MIR
   --------------------------------- */
Probe "AMUX" ao mir[31]; Probe "CD" ap.aa mir[30];
Probe "CD" ap.ab mir[29]; Probe "AL" aq.aa mir[28];
Probe "AL" aq.ab mir[27]; Probe "SH" ar.aa mir[26];
Probe "SH" ar.ab mir[25]; Probe "MB" as.aa mir[24];
Probe "MA" as.ab mir[23]; Probe "WR" at.aa mir[22];
Probe "RD" at.ab mir[21]; Probe "ENC" au.aa mir[20];
Probe "C" av.aa mir[19]; Probe "C" av.ab mir[18];
Probe "C" aw.aa mir[17]; Probe "C" aw.ab mir[16];

Probe "B"  bs.aa mir[15]; Probe "B"  bs.ab mir[14];
Probe "B"  bt.aa mir[13]; Probe "B"  bt.ab mir[12];
Probe "A"  bu.aa mir[11]; Probe "A"  bu.ab mir[10];
Probe "A"  bv.aa mir[9];  Probe "A"  bv.ab mir[8];
Probe "NA" bw.aa mir[7];  Probe "NA" bw.ab mir[6];
Probe "NA" bx.aa mir[5];  Probe "NA" bx.ab mir[4];
Probe "NA" by.aa mir[3];  Probe "NA" by.ab mir[2];
Probe "NA" bz.aa mir[1];  Probe "NA" bz.ab mir[0];

/*
Byte-probe-h "MPC" dt-dz MPC[7-0];
*/
Probe "BRA?" dt-du branch;
Probe "M" dw.aa MPC[7];
Probe "P" dw.ab MPC[6];
Probe "C" dx.aa MPC[5];
Probe " " dx.ab MPC[4];
Probe " " dy.aa MPC[3];
Probe " " dy.ab MPC[2];
Probe " " dz.aa MPC[1];
Probe " " dz.ab MPC[0];

Probe "M" ka.aa AddrBus[15]; Probe "A" ka.ab AddrBus[14];
Probe "R" kb.aa AddrBus[13]; Probe " " kb.ab AddrBus[12];
Probe " " kc.aa AddrBus[11]; Probe " " kc.ab AddrBus[10];
Probe " " kd.aa AddrBus[9];  Probe " " kd.ab AddrBus[8];
Probe " " ke.aa AddrBus[7];  Probe " " ke.ab AddrBus[6];
Probe " " kf.aa AddrBus[5];  Probe " " kf.ab AddrBus[4];
Probe " " kg.aa AddrBus[3];  Probe " " kg.ab AddrBus[2];
Probe " " kh.aa AddrBus[1];  Probe " " kh.ab AddrBus[0];

Probe "M" la.aa mbr[15]; Probe "B" la.ab mbr[14];
Probe "R" lb.aa mbr[13]; Probe " " lb.ab mbr[12];
Probe " " lc.aa mbr[11]; Probe " " lc.ab mbr[10];
Probe " " ld.aa mbr[9];  Probe " " ld.ab mbr[8];
Probe " " le.aa mbr[7];  Probe " " le.ab mbr[6];
Probe " " lf.aa mbr[5];  Probe " " lf.ab mbr[4];
Probe " " lg.aa mbr[3];  Probe " " lg.ab mbr[2];
Probe " " lh.aa mbr[1];  Probe " " lh.ab mbr[0];


Probe "MReq" ma-mb MReq;
Probe "RD"   mc-md READ;


Probe "C" na.aa CommOut[15]; Probe "P" na.ab CommOut[14];
Probe "U" nb.aa CommOut[13]; Probe " " nb.ab CommOut[12];
Probe "D" nc.aa CommOut[11]; Probe "a" nc.ab CommOut[10];
Probe "t" nd.aa CommOut[9];  Probe "a" nd.ab CommOut[8];
Probe " " ne.aa CommOut[7];  Probe " " ne.ab CommOut[6];
Probe " " nf.aa CommOut[5];  Probe " " nf.ab CommOut[4];
Probe " " ng.aa CommOut[3];  Probe " " ng.ab CommOut[2];
Probe " " nh.aa CommOut[1];  Probe " " nh.ab CommOut[0];

Probe "M" pa.aa DataBus[15]; Probe "e" pa.ab DataBus[14];
Probe "m" pb.aa DataBus[13]; Probe " " pb.ab DataBus[12];
Probe "D" pc.aa DataBus[11]; Probe "a" pc.ab DataBus[10];
Probe "t" pd.aa DataBus[9];  Probe "a" pd.ab DataBus[8];
Probe " " pe.aa DataBus[7];  Probe " " pe.ab DataBus[6];
Probe " " pf.aa DataBus[5];  Probe " " pf.ab DataBus[4];
Probe " " pg.aa DataBus[3];  Probe " " pg.ab DataBus[2];
Probe " " ph.aa DataBus[1];  Probe " " ph.ab DataBus[0];


