Name     MemMap ;
PartNo   U2 ;
Date     31/08/2020 ;
Revision 01 ;
Designer Bert Hoogenboom ;
Company  BHB Electronics ;
Assembly V1 ;
Location  ;
Device   f1508ispqfp100 ;

PROPERTY ATMEL {Preassign = KEEP};

/* *************** INPUT PINS *********************/
PIN  89 = XCLK    ;
PIN  90 = nHALT   ;
PIN  91 = nRESET  ;
PIN  92 = CLKi    ;


PIN  11 = A0      ;
PIN  12 = A1      ; 
PIN  14 = A2      ; 
PIN  15 = A3      ; 
PIN  16 = A4      ; 
PIN  18 = A5      ; 
PIN  19 = A6      ; 
PIN  21 = A7      ;
PIN  22 = A8      ; 
PIN  23 = A9      ; 
PIN  24 = A10     ; 
PIN  25 = A11     ; 
PIN  26 = A12     ; 
PIN  27 = A13     ;
PIN  29 = A14     ; 
PIN  30 = A15     ; 

PIN  96 = nRD     ; 
PIN  98 = nWR     ; 
PIN  95 = nIORQ   ; 
PIN  94 = nMREQ   ; 

PIN   9 = nM1     ;


PIN  99 = nWE     ; 
PIN  46 = CLK     ;
PIN  47 = nINT    ;

PIN  69 = nResume ;

/* spare no function*/
PIN  78 = nBUScon ;
PIN  52 = nBUSACK ;
PIN   7 = nBUSRQ  ;
PIN  67 = nBUSRD  ;
PIN  10 = nRFSH ;

/* *************** OUTPUT PINS *********************/

PIN  82 = RomA13  ;  
PIN  81 = RomA14  ; 
PIN   4 = RomA15  ;  
PIN   3 = RomA16  ;  
PIN   2 = RomA17  ;  
PIN  85 = RomA18  ;  
PIN  83 = RomA19  ;  

PIN   1 = nRomCS  ;  
PIN  87 = nRomWE  ; 
PIN  86 = nRomRD  ;

PIN  49 = Debug1  ; 
PIN  50 = Debug2  ;
PIN  70 = SECADR_PIN  ;
PIN  62 = nSLT2   ;
PIN  63 = nSLT1   ;
PIN  57 = test1   ;
PIN  66 = test2   ;
PIN  44 = PRIMADR_PIN   ;
 
PIN  72 = nCS_Serial;
PIN  73 = nCS_HD  ;
PIN  77 = nCS_RTC ;
PIN  74 = SpareCS ;

PIN 100 = nWAIT   ;

PIN  54 = ATCLK   ;
PIN  56 = nCLK    ;

PIN   8 = Z80RESET;

PIN  55 = INT     ;
PIN  48 = nNMI    ;

/* ************ BIdirectional PINS **************** */

PIN  31 = D0      ; 
PIN  32 = D1      ; 
PIN  33 = D2      ; 
PIN  34 = D3      ;
PIN  35 = D4      ; 
PIN  37 = D5      ; 
PIN  38 = D6      ; 
PIN  39 = D7      ;

/* ************ Unconnected PINS ********************

PIN  43 = ; 
PIN  44 = ; 
PIN  58 = ;
PIN  59 = ;
PIN  60 = ;
PIN  70 = ;
PIN  71 = ;
PIN  79 = ;
PIN  80 = ; 
*/
/* *******************  Nodes    *********************/

NODE     NOWAIT;
NODE     DOWAIT;
NODE	  Clka;

NODE    [PRIM7..PRIM0]    ;  
NODE    [SEC7..SEC0]      ;
NODE 	 [R17..R10];
NODE	 [R27..R20];
NODE	 [R37..R30];
NODE 	 [R47..R40];

/*****************IMPLENTATION**********************/
/*nMemMapADR = A2 & A3 & A4 & A5 & A6 & A7 & !nIORQ;*/
nCS_Serial  = !( !A3 & !A4 & !A5 & !A6 & A7 & !nIORQ );  /* 80h - 87h for serial IO */
nCS_RTC     = !( !A1 & A2 & !A3 & A4 & A5 & !A6 & A7 & !nIORQ ); /* B4h - B5h of RTC */
nCS_HD      = !(!A3 & A4 & !A5 & A6 & A7 & !nIORQ); /* D0h - D7h for HD drive */
SpareCS     = !(A8 & A9 & A10 & A11 & A12 & A13);

SECADR = A0 & A1 & A2 & A3 & A4 & A5 & A6 & A7 & A8 & A9 & A10 & A11 & A12 & A13 & A14 & A15 & !nMREQ;
PRIMADR = !A0 & !A1 & !A2 & A3 & !A4 & A5 & !A6 & A7 & !nIORQ;
MEMMAPMADR = A2 & A3 & A4 & A5 & A6 & A7; 

NOWAIT = !(nCS_Serial & nCS_HD & nCS_RTC & DOWAIT);
DOWAIT = !(nResume & nRESET & NOWAIT);
nWAIT.L = DOWAIT;
nWAIT.LE = !(nCS_Serial & nCS_HD & nCS_RTC);
nWAIT.OE = !(nCS_Serial & nCS_HD & nCS_RTC);

[R17..R10].D = [D7..D0].IO;
[R27..R20].D = [D7..D0].IO;
[R37..R30].D = [D7..D0].IO;
[R47..R40].D = [D7..D0].IO;

[D7..D0].L = ([R17..R10] & !A0 & !A1 & MEMMAPMADR & !nIORQ & !nRD)
           # ([R27..R20] & A0 & !A1 & MEMMAPMADR & !nIORQ & !nRD) 
           # ([R37..R30] & !A0 & A1 & MEMMAPMADR & !nIORQ & !nRD) 
           # ([R47..R40] & A0 & A1 & MEMMAPMADR & !nIORQ & !nRD); 

[D7..D0].LE = (MEMMAPMADR & !nIORQ & !nRD);

[D7..D0].OE = (MEMMAPMADR & !nIORQ & !nRD);

[R17..R10].CK = !A0 & !A1 & MEMMAPMADR & !nIORQ & !nWR ;
[R27..R20].CK = A0 & !A1 & MEMMAPMADR & !nIORQ & !nWR ;
[R37..R30].CK = !A0 & A1 & MEMMAPMADR & !nIORQ & !nWR ;
[R47..R40].CK = A0 & A1 & MEMMAPMADR & !nIORQ & !nWR ;

[R17..R10].AR = !nRESET;
[R27..R21].AR = !nRESET;
R20.AP = !nRESET;
[R37..R32, R30].AR = !nRESET;
R31.AP = !nRESET;
[R47..R42].AR = !nRESET;
[R41, R40].AP = !nRESET;

RomA14_21_1x = !A14 & !A15; 
RomA14_21_2x =  A14 & !A15;
RomA14_21_3x = !A14 &  A15;
RomA14_21_4x =  A14 &  A15;

RomA13 = A13;
RomA14 = (RomA14_21_1x & R10 & !nMREQ)
	# (RomA14_21_2x & R20 & !nMREQ)
       # (RomA14_21_3x & R30 & !nMREQ)
       # (RomA14_21_4x & R40 & !nMREQ);

RomA15 = (RomA14_21_1x & R11 & !nMREQ)
	# (RomA14_21_2x & R21 & !nMREQ)
       # (RomA14_21_3x & R31 & !nMREQ)
       # (RomA14_21_4x & R41 & !nMREQ);

RomA16 = (RomA14_21_1x & R12 & !nMREQ)
	# (RomA14_21_2x & R22 & !nMREQ)
       # (RomA14_21_3x & R32 & !nMREQ)
       # (RomA14_21_4x & R42 & !nMREQ);

RomA17 = (RomA14_21_1x & R13 & !nMREQ)
	# (RomA14_21_2x & R23 & !nMREQ)
       # (RomA14_21_3x & R33 & !nMREQ)
       # (RomA14_21_4x & R43 & !nMREQ);

RomA18 = (RomA14_21_1x & R14 & !nMREQ)
	# (RomA14_21_2x & R24 & !nMREQ)
       # (RomA14_21_3x & R34 & !nMREQ)
       # (RomA14_21_4x & R44 & !nMREQ);

RomA19 = (RomA14_21_1x & R15 & !nMREQ)
	# (RomA14_21_2x & R25 & !nMREQ)
       # (RomA14_21_3x & R35 & !nMREQ)
       # (RomA14_21_4x & R45 & !nMREQ);

nRomCS = nMREQ;  
nRomWE = nWR # nMREQ;
nRomRD = nRD # nMREQ;

Clka.D = !Clka;
Clka.CK = XCLK;

Z80RESET = nRESET;
ATCLK =  Clka;
	
nCLK =  XCLK; /*CLKi;*/

/* to make sure that all used pins are defined as input*/
Debug1 = CLK # nINT # nNMI;
Debug2 = nBUScon;
test = nBUSRQ # nBUSACK # INT # nBUSRD # nHALT # CLKi;
nSLT4 = nM1 # nRFSH;


