
Blackjack Machine - TOP LEVEL module
This
is the top level module for implementing the Blackjack Machine on a CPLD
device. This module integrates the lower three modules as sub-module instantiations.
 
 module
bjtopx;
title
'Blackjack Machine with a hierarchical implementation.'
//    
Original Design consists of 3 blocks:
//       
Block          Device
//       
-----          ------
//       
bjack          P16R6
//       
muxadd         P22V10
//       
binbcdx        P16L8
//    
Post-linked design fits a single Xilinx CPLD device.
//    
Based on BJACKTOP.
//
//    
This design is identical to the original BJACKTOP except for the
//    
removal of unnecessary inversions in the Hit and Bust equations.
//
//    
Ena is removed since OE pin in bjack module is removed
// Sub-module prototypes...
   
bjack interface (Clk,ClkIN,GT16,LT22,is_Ace,Restart,CardIn,CardOut
                     
:> AddClk, Add10,Sub10,Q2..Q0, Ace);
muxadd interface (V0..V4,AddClk,Clr,Add10,Sub10 :> S0..S4, is_Ace);
binbcd interface (S0..S4 -> LT22, GT16, D0..D5);
// Sub-module instantiations...
   
BJ functional_block bjack;
   
MA functional_block muxadd;
   
BB functional_block binbcd;
// Top level inputs...
   
Clk            
pin;      "System clock         
-- bjack
   
CardIn,CardOut  pin;      "Card present switches
-- bjack
   
Restart         pin;     
"Restart game          --
bjack
   
V4..V0          pin;     
"                     
-- muxadd
   
Ace            
pin;
   
Card           
= [V4..V0];
   
Sensor          = [CardIn,CardOut];
   
_In            
= [  0   ,   1   ];
   
InOut           = [ 
1   ,   1   ];
   
Out            
= [  1   ,   0   ];
//
Top level outputs...
 
   
D5..D0          pin istype
'com';           
"            --
binbcd
   
BCD1           
= [D3..D0];
   
BCD2           
= [D5,D4];
// Top level pins (for observing state machine)...
   
Q2..Q0          pin istype
'com';
   
Add10,Sub10     pin istype 'com';
   
AddClk          pin istype
'com';
   
Hit, Bust       pin istype 'com';
   
MuxClk          pin;
   
Qstate          =  [Add10,Sub10,Q2,Q1,Q0];
   
Clear           = 
[  1  ,  1  , 1, 1, 1]; "31
   
ShowHit         =  [ 
1  ,  1  , 1, 1, 0]; "30
   
AddCard         =  [ 
1  ,  1  , 0, 0, 0]; "24
   
Add_10          =  [ 
0  ,  1  , 0, 0, 0]; "16
   
Wait           
=  [  1  ,  1  , 0, 0, 1]; "25
   
Test_17         =  [ 
1  ,  1  , 0, 1, 0]; "26
   
Test_22         =  [ 
1  ,  1  , 0, 1, 1]; "27
   
ShowStand       =  [  1  , 
1  , 1, 0, 0]; "28
   
ShowBust        =  [  1 
,  1  , 1, 0, 1]; "29
   
Sub_10          =  [ 
1  ,  0  , 0, 0, 1]; "17
   
Zero           
=  [  0  ,  0  , 0, 0, 0]; "0
 
C,X,L,H = .c.,.x.,0,1;
equations
// Describe the input connections...
   
MA.[V4,V3,V2,V1,V0] = Card;
   
MA.Clr      = Restart;
   
BJ.Clk      = Clk;
   
BJ.ClkIN    = Clk;
   
BJ.Restart  = Restart;
   
BJ.CardIn   = CardIn;
   
BJ.CardOut  = CardOut;
   
MA.AddClk  = MuxClk;
"
MuxClk will be connected to AddClk externally.  This trick is
"
not necessary for Xilinx CPLD devices since the CPLD fitter can
"
emulate product term
clocks using the FastCLK I/O buffer. However,
"
the design was not changed
in order to allow the existing test vectors " from BJACKTOP
to
be used.
// Describe the output connections...
   
[D5,D4,D3,D2,D1,D0]    = BB.[D5,D4,D3,D2,D1,D0];
   
Add10       = BJ.Add10;
   
Sub10       = BJ.Sub10;
   
Q0          = BJ.Q0;
   
Q1          = BJ.Q1;
   
Q2          = BJ.Q2;
   
Ace        = BJ.Ace;
   
AddClk     = BJ.AddClk;
   
Hit  = BB.GT16; " Removed unnecassary inversions placed in original
   
Bust        = BB.LT22; " Data I/O BJACKTOP
design.
 
// Describe inter-module connections...
   
MA.Sub10    = BJ.Sub10;
   
MA.Add10    = BJ.Add10;
   
BB.[S0,S1,S2,S3,S4] = MA.[S0,S1,S2,S3,S4];
   
BJ.is_Ace   = MA.is_Ace;
   
BJ.GT16     = BB.GT16;
   
BJ.LT22     = BB.LT22;
"The
polarities of the existing Hit and Bust test vectors were
"corrected
to reflect the inversions removed from the original design.
test_vectors
'Assume two cards that total between 16 and 21'
([Restart,MuxClk,Clk,Sensor,Card]
-> [Qstate   ,Hit,Bust,BCD2,BCD1])
 [  
0   ,   0  , C ,  Out ,  0 ] -> [ 
X      , 0 ,  1 ,  0 ,  0 ];
 [  
0   ,   C  , C ,  Out ,  0 ] -> [Clear   
, 0 ,  1 ,  0 ,  0 ];
 [  
1   ,   0  , C ,  Out ,  9 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  0 ];
 [  
1   ,   0  , C ,InOut ,  9 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  0 ];
 [  
1   ,   C  , C ,  _In ,  9 ] -> [AddCard 
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   0  , C ,  _In ,  9 ] -> [Wait    
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   0  , C ,InOut ,  9 ] -> [Wait    
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   0  , C ,  Out ,  9 ] -> [Test_17 
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   0  , C ,  Out ,  8 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  9 ];
 [  
1   ,   C  , C ,  _In ,  8 ] -> [AddCard 
, 1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,  _In ,  8 ] -> [Wait    
, 1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,InOut ,  8 ] -> [Wait    
, 1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,  Out ,  8 ] -> [Test_17 
, 1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [Test_22 
, 1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowStand,
1 ,  1 ,  1 ,  7 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowStand,
1 ,  1 ,  1 ,  7 ];
 [  
0   ,   C  , C ,  Out ,  0 ] -> [Clear   
, 0 ,  1 ,  0 ,  0 ];
 
 
test_vectors
'Assume 2 Aces and 3 cards that total over 21'
([Restart,MuxClk,Clk,Sensor,Card]
-> [Qstate   ,Hit,Bust,BCD2,BCD1])
 [  
0   ,   C  , C ,  Out ,  0 ] -> [Clear   
, 0 ,  1 ,  0 ,  0 ];
 [  
0   ,   C  , C ,  Out ,  0 ] -> [Clear   
, 0 ,  1 ,  0 ,  0 ];"20
 [  
1   ,   0  , C ,  Out ,  4 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  0 ];
 [  
1   ,   0  , C ,InOut ,  4 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  0 ];
 [  
1   ,   C  , C ,  _In ,  4 ] -> [AddCard 
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   0  , C ,  _In ,  4 ] -> [Wait    
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   0  , C ,InOut ,  4 ] -> [Wait    
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   0  , C ,  Out ,  4 ] -> [Test_17 
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   0  , C ,  Out ,  1 ] -> [ShowHit 
, 0 ,  1 ,  0 ,  4 ];
 [  
1   ,   C  , C ,  _In ,  1 ] -> [AddCard 
, 0 ,  1 ,  0 ,  5 ];
 [  
1   ,   0  , C ,  _In ,  1 ] -> [Add_10  
, 0 ,  1 ,  0 ,  5 ];"30
 [  
1   ,   C  , C ,  _In ,  1 ] -> [Wait    
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,InOut ,  1 ] -> [Wait    
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  1 ] -> [Test_17 
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,InOut ,  1 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   C  , C ,  _In ,  1 ] -> [AddCard 
, 0 ,  1 ,  1 ,  6 ];
 [  
1   ,   0  , C ,  _In ,  1 ] -> [Wait    
, 0 ,  1 ,  1 ,  6 ];
 [  
1   ,   0  , C ,InOut ,  1 ] -> [Wait    
, 0 ,  1 ,  1 ,  6 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [Test_17 
, 0 ,  1 ,  1 ,  6 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  6 ];"40
 [  
1   ,   0  , C ,InOut ,  9 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  6 ];
 [  
1   ,   C  , C ,  _In ,  9 ] -> [AddCard 
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   0  , C ,  _In ,  9 ] -> [Wait    
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   0  , C ,InOut ,  9 ] -> [Wait    
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  9 ] -> [Test_17 
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [Test_22 
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [Sub_10  
, 1 ,  0 ,  2 ,  5 ];
 [  
1   ,   C  , C ,  Out ,  0 ] -> [Test_17 
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  5 ];
 [  
1   ,   0  , C ,InOut ,  8 ] -> [ShowHit 
, 0 ,  1 ,  1 ,  5 ];"50
 [  
1   ,   C  , C ,  _In ,  8 ] -> [AddCard 
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,  _In ,  8 ] -> [Wait    
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,InOut ,  8 ] -> [Wait    
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,  Out ,  8 ] -> [Test_17 
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [Test_22 
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowBust
, 1 ,  0 ,  2 ,  3 ];
 [  
1   ,   0  , C ,  Out ,  0 ] -> [ShowBust
, 1 ,  0 ,  2 ,  3 ];
 [  
0   ,   C  , C ,  Out ,  0 ] -> [Clear   
, 0 ,  1 ,  0 ,  0 ];
end;