INCLUDE "74157";
INCLUDE "74280";
INCLUDE "BTRI";
SUBDESIGN datapath
(
	% segnali verso 68030 %
	a68k[31..0]		: INPUT;
	d68k[31..0]		: BIDIR;
	/as			: INPUT = VCC;
	/ds			: INPUT = VCC;
	% segnali verso il bus PCI %
	ad[31..0]		: BIDIR;
	c_be[3..0]		: INPUT;
	% segnali tra i blocchi del bridge %
	(l_a68k0, l_a68k1, l_a68k16, l_a68k17, l_a68k18,
	l_a68k19, l_a68k28, l_a68k29, l_a68k30, 
	l_a68k31)		: OUTPUT;
	/io_space		: INPUT = VCC;
	/a_enable		: INPUT = VCC;
	/di_enable		: INPUT = VCC;
	/di_latch		: INPUT = VCC;
	/do_enable		: INPUT = VCC;
	current_par		: OUTPUT;
)
VARIABLE
	latch_indirizzi[31..0]	: LATCH;
	latch_dati_read[31..0]	: LATCH;
	latch_dati_write[31..0]	: LATCH;
	latch_cbe[3..0]		: LATCH;
	selettore[8..1]		: 74157;
	checker[5..1]		: 74280;
	buffer_PCI[31..0]	: BTRI;
	buffer_dati_read[31..0]	: BTRI;
	rom_space		: NODE;
BEGIN
% rimappo la ROM sulla scheda da C0000 a 00000 %
% C in binario fa 1100 %
	rom_space = (a68k[19..16] == H"C");
% il datapath vero e proprio... %
% in uscita da 68030: indirizzi %
	latch_indirizzi[31..0].ena = /as;
	selettore[8..1].gn = GND;
	selettore[8..1].sel = /a_enable;
	selettore1.a[4..1] = latch_indirizzi[3..0].q;
	selettore2.a[4..1] = latch_indirizzi[7..4].q;
	selettore3.a[4..1] = latch_indirizzi[11..8].q;
	selettore4.a[4..1] = latch_indirizzi[15..12].q;
	selettore5.a[4..1] = latch_indirizzi[19..16].q;
	selettore6.a[4..1] = latch_indirizzi[23..20].q;
	selettore7.a[4..1] = latch_indirizzi[27..24].q;
	selettore8.a[4..1] = latch_indirizzi[31..28].q;
	l_a68k31 = latch_indirizzi31.q;
	l_a68k[1..0] = latch_indirizzi[1..0].q;
	l_a68k[19..16] = latch_indirizzi[19..16].q;
	l_a68k[30..28] = latch_indirizzi[30..28].q;
	latch_indirizzi1.d = a68k[1] !# /io_space;
	latch_indirizzi0.d = a68k[0] !# /io_space;
	latch_indirizzi[17..2].d = a68k[17..2];
	latch_indirizzi18.d = a68k18 & !rom_space;
	latch_indirizzi19.d = a68k19 & !rom_space;
	latch_indirizzi[23..20].d = a68k[23..20];
	latch_indirizzi[31..24].d = a68k[31..24];
% in uscita da 68030: dati %
	latch_dati_write[31..0].ena = /ds;
	selettore1.b[4..1] = latch_dati_write[3..0].q;
	selettore2.b[4..1] = latch_dati_write[7..4].q;
	selettore3.b[4..1] = latch_dati_write[11..8].q;
	selettore4.b[4..1] = latch_dati_write[15..12].q;
	selettore5.b[4..1] = latch_dati_write[19..16].q;
	selettore6.b[4..1] = latch_dati_write[23..20].q;
	selettore7.b[4..1] = latch_dati_write[27..24].q;
	selettore8.b[4..1] = latch_dati_write[31..28].q;
	latch_dati_write[31..0].d = d68k[31..0];
% pilotaggio linee AD PCI %
	buffer_PCI[31..0].oen = /do_enable;
	buffer_PCI[3..0].in = selettore1.y[4..1];
	buffer_PCI[7..4].in = selettore2.y[4..1];
	buffer_PCI[11..8].in = selettore3.y[4..1];
	buffer_PCI[15..12].in = selettore4.y[4..1];
	buffer_PCI[19..16].in = selettore5.y[4..1];
	buffer_PCI[23..20].in = selettore6.y[4..1];
	buffer_PCI[27..24].in = selettore7.y[4..1];
	buffer_PCI[31..28].in = selettore8.y[4..1];
	ad[31..0] = buffer_PCI[31..0].out;
% dati in ingresso al 68030 %
	latch_dati_read[31..0].ena = /di_latch;
	buffer_dati_read[31..0].oen = /di_enable;
	d68k[31..0] = buffer_dati_read[31..0].out;
	buffer_dati_read[31..0].in = latch_dati_read[31..0].q;
	latch_dati_read[31..0].d = ad[31..0];
% generatore di parita %
	latch_cbe[3..0].d = c_be[3..0];
	latch_cbe[3..0].ena = /do_enable;
	checker1.(a,b,c,d) = selettore1.y[4..1];
	checker1.(e,f,g,h) = selettore2.y[4..1];
	checker1.i = latch_cbe0.q;
	checker2.(a,b,c,d) = selettore3.y[4..1];
	checker2.(e,f,g,h) = selettore4.y[4..1];
	checker2.i = latch_cbe1.q;
	checker3.(a,b,c,d) = selettore5.y[4..1];
	checker3.(e,f,g,h) = selettore6.y[4..1];
	checker3.i = latch_cbe2.q;
	checker4.(a,b,c,d) = selettore7.y[4..1];
	checker4.(e,f,g,h) = selettore8.y[4..1];
	checker4.i = latch_cbe3.q;
	checker5.a = checker1.even;
	checker5.b = checker2.even;
	checker5.c = checker3.even;
	checker5.d = checker4.even;
	checker5.(e,f,g,h,i) = GND; % cinque ingressi non sono usati %
	current_par = checker5.even;
END;
