Document 13736395

advertisement
A
User Interface Source Codes
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
//
/ / 6 . 1 1 1 FPGA L a b k i t −− ADV7185 Video Decoder C o n f i g u r a t i o n I n i t
//
/ / Cr ea ted :
/ / Author : Nathan I c k e s
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
/ / R e g i s t e r 0
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INPUT SELECT
4 ’ h0
/ / 0 : CVBS on AIN1 ( c o m p o s i t e v i d e o i n )
/ / 7 : Y on AIN2 , C on AIN5 ( s−v i d e o i n )
/ / ( These a r e t h e o n l y c o n f i g u r a t i o n s s u p p o r t e d by t h e 6 . 1 1 1 l a b k i t hardware )
4 ’ h0
‘ d e f i n e INPUT MODE
/ / 0 : A u t o d e t e c t : NTSC o r PAL ( BGHID) , w/ o p e d e s t a l
/ / 1 : A u t o d e t e c t : NTSC o r PAL ( BGHID) , w/ p e d e s t a l
/ / 2 : A u t o d e t e c t : NTSC o r PAL (N) , w/ o p e d e s t a l
/ / 3 : A u t o d e t e c t : NTSC o r PAL (N) , w/ p e d e s t a l
/ / 4 : NTSC w/o p e d e s t a l
/ / 5 : NTSC w/ p e d e s t a l
/ / 6 : NTSC 4 . 4 3 w/o p e d e s t a l
/ / 7 : NTSC 4 . 4 3 w/ p e d e s t a l
/ / 8 : PAL BGHID w/o p e d e s t a l
/ / 9 : PAL N w/ p e d e s t a l
/ / A : PAL M w/ o p e d e s t a l
/ / B : PAL M w/ p e d e s t a l
/ / C : PAL co mbina tio n N
/ / D : PAL co mbina tio n N w/ p e d e s t a l
/ / E−F : [ Not v a l i d ]
‘ d e f i n e ADV7185 REGISTER 0 { ‘INPUT MODE, ‘ INPUT SELECT}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 1
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ define
// 0:
// 1:
// 2:
// 3:
‘ define
// 0:
// 1:
‘ define
VIDEO QUALITY
Br o a dca st q u a l i t y
TV q u a l i t y
VCR q u a l i t y
Surveillance quality
SQUARE PIXEL IN MODE
Normal mode
Square p i x e l mode
DIFFERENTIAL INPUT
2 ’ h0
1 ’ b0
1 ’ b0
1
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
S i n g l e −ended i n p u t s
D i f f e r e n t i a l i n p u t s
1 ’ b0
FOUR TIMES SAMPLING
Standard sa mpling r a t e
4 x sa mpling r a t e (NTSC o n l y )
1 ’ b0
BETACAM
Standard v i d e o i n p u t
Betacam v i d e o i n p u t
1 ’ b1
AUTOMATIC STARTUP ENABLE
Change o f i n p u t t r i g g e r s r e a c q u i r e
Change o f i n p u t do es not t r i g g e r r e a c q u i r e
‘ d e f i n e ADV7185 REGISTER 1 { ‘AUTOMATIC STARTUP ENABLE, 1 ’ b0 , ‘BETACAM,
‘FOUR TIMES SAMPLING , ‘ DIFFERENTIAL INPUT,
‘SQUARE PIXEL IN MODE , ‘ VIDEO QUALITY}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 2
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ define
// 0:
// 1:
// 2:
// 3:
// 4:
// 5:
// 6:
// 7:
‘ define
// 0:
// 1:
// 2:
// 3:
Y PEAKING FILTER
Composite = 4 . 5 dB , s−v i d e o
Composite = 4 . 5 dB , s−v i d e o
Composite = 4 . 5 dB , s−v i d e o
Composite = 1 . 2 5 dB , s−v i d e o
Composite = 0 . 0 dB , s−v i d e o
Composite = −1.25dB , s−v i d e o
Composite = −1.75dB , s−v i d e o
Composite = −3.0dB , s−v i d e o
CORING
No c o r i n g
Truncate i f Y < b l a c k+8
Truncate i f Y < b l a c k+16
Truncate i f Y < b l a c k+32
3 ’ h4
= 9 . 2 5 dB
= 9 . 2 5 dB
= 5 . 7 5 dB
= 3 . 3 dB
= 0 . 0 dB
= −3.0dB
= −8.0dB
= −8.0dB
2 ’ h0
‘ d e f i n e ADV7185 REGISTER 2 { 3 ’ b000 , ‘ CORING, ‘ Y PEAKING FILTER}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 3
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INTERFACE SELECT
/ / 0 : P h i l i p s −c o m p a t i b l e
/ / 1 : B r o k t r e e API A−c o m p a t i b l e
/ / 2 : B r o k t r e e API B−c o m p a t i b l e
/ / 3 : [ Not v a l i d ]
‘ d e f i n e OUTPUT FORMAT
/ / 0 : 1 0 − b i t @ LLC , 4 : 2 : 2 CCIR656
/ / 1 : 2 0 − b i t @ LLC , 4 : 2 : 2 CCIR656
/ / 2 : 1 6 − b i t @ LLC , 4 : 2 : 2 CCIR656
/ / 3 : 8 − b i t @ LLC , 4 : 2 : 2 CCIR656
2 ’ h0
4 ’ h0
2
/ / 4 : 1 2 − b i t @ LLC , 4 : 1 : 1
// 5 −F : [ Not v a l i d ]
/ / ( Note t h a t t h e 6 . 1 1 1 l a b k i t hardware p r o v i d e s o n l y a 10− b i t i n t e r f a c e t o
/ / t h e ADV7185 . )
1 ’ b0
‘ d e f i n e TRISTATE OUTPUT DRIVERS
/ / 0 : D r i v e r s t r i s t a t e d when ˜OE i s hig h
/ / 1 : D r i v e r s a lwa ys t r i s t a t e d
‘ d e f i n e VBI ENABLE
1 ’ b0
/ / 0 : Decode l i n e s d u r i n g v e r t i c a l b l a n k i n g i n t e r v a l
/ / 1 : Decode o n l y a c t i v e v i d e o r e g i o n s
‘ d e f i n e ADV7185 REGISTER 3 { ‘ VBI ENABLE , ‘ TRISTATE OUTPUT DRIVERS , ‘OUTPUT FORMAT,
‘INTERFACE SELECT}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 4
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
1 ’ b0
OUTPUT DATA RANGE
Output v a l u e s r e s t r i c t e d t o CCIR−c o m p l i a n t r a ng e
Use f u l l o utput r a ng e
BT656 TYPE
1 ’ b0
BT656−3−c o m p a t i b l e
BT656−4−c o m p a t i b l e
‘ d e f i n e ADV7185 REGISTER 4 { ‘ BT656 TYPE , 3 ’ b000 , 3 ’ b110 , ‘OUTPUT DATA RANGE}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 5
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ define
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
4 ’ b0000
GENERAL PURPOSE OUTPUTS
GPO 0 1 ENABLE
1 ’ b0
Gener a l pur po se o u t p u t s 0 and 1 t r i s t a t e d
Gener a l pur po se o u t p u t s 0 and 1 e n a b l e d
GPO 2 3 ENABLE
1 ’ b0
Gener a l pur po se o u t p u t s 2 and 3 t r i s t a t e d
Gener a l pur po se o u t p u t s 2 and 3 e n a b l e d
1 ’ b1
BLANK CHROMA IN VBI
Chroma decoded and o utput d u r i n g v e r t i c a l b l a n k i n g
Chroma bla nked d u r i n g v e r t i c a l b l a n k i n g
1 ’ b0
HLOCK ENABLE
GPO 0 i s a g e n e r a l pur po se o utput
GPO 0 shows HLOCK s t a t u s
‘ d e f i n e ADV7185 REGISTER 5 { ‘HLOCK ENABLE, ‘ BLANK CHROMA IN VBI, ‘ GPO 2 3 ENABLE ,
‘GPO 0 1 ENABLE , ‘ GENERAL PURPOSE OUTPUTS}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 7
3
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
5 ’ h10
‘ d e f i n e FIFO FLAG MARGIN
/ / S e t s t h e l o c a t i o n s where FIFO almost− f u l l and almost−empty f l a g s a r e s e t
‘ d e f i n e FIFO RESET
1 ’ b0
/ / 0 : Normal o p e r a t i o n
/ / 1 : Reset FIFO . This b i t i s a u t o m a t i c a l l y c l e a r e d
‘ d e f i n e AUTOMATIC FIFO RESET
1 ’ b0
/ / 0 : No a uto ma tic r e s e t
/ / 1 : FIFO i s a u t m a t i c a l l y r e s e t a t t h e end o f ea ch v i d e o f i e l d
1 ’ b1
‘ d e f i n e FIFO FLAG SELF TIME
/ / 0 : FIFO f l a g s a r e s y n c h r o n i z e d t o CLKIN
/ / 1 : FIFO f l a g s a r e s y n c h r o n i z e d t o i n t e r n a l 2 7MHz c l o c k
‘ d e f i n e ADV7185 REGISTER 7 { ‘ FIFO FLAG SELF TIME , ‘ AUTOMATIC FIFO RESET,
‘FIFO RESET , ‘ FIFO FLAG MARGIN}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 8
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INPUT CONTRAST ADJUST
8 ’ h80
‘ d e f i n e ADV7185 REGISTER 8 { ‘INPUT CONTRAST ADJUST}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 9
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INPUT SATURATION ADJUST
8 ’ h8C
‘ d e f i n e ADV7185 REGISTER 9 { ‘INPUT SATURATION ADJUST}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register A
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INPUT BRIGHTNESS ADJUST
8 ’ h00
‘ d e f i n e ADV7185 REGISTER A { ‘ INPUT BRIGHTNESS ADJUST}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register B
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e INPUT HUE ADJUST
8 ’ h00
‘ d e f i n e ADV7185 REGISTER B { ‘ INPUT HUE ADJUST}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register C
4
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e DEFAULT VALUE ENABLE
/ / 0 : Use programmed Y, Cr , and Cb v a l u e s
/ / 1 : Use d e f a u l t v a l u e s
‘ d e f i n e DEFAULT VALUE AUTOMATIC ENABLE
/ / 0 : Use programmed Y, Cr , and Cb v a l u e s
/ / 1 : Use d e f a u l t v a l u e s i f l o c k i s l o s t
‘ d e f i n e DEFAULT Y VALUE
// Default Y value
1 ’ b0
1 ’ b0
6 ’ h0C
‘ d e f i n e ADV7185 REGISTER C { ‘DEFAULT Y VALUE, ‘ DEFAULT VALUE AUTOMATIC ENABLE,
‘DEFAULT VALUE ENABLE}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register D
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
4 ’ h8
‘ d e f i n e DEFAULT CR VALUE
/ / Most−s i g n i f i c a n t f o u r b i t s o f d e f a u l t Cr v a l u e
‘ d e f i n e DEFAULT CB VALUE
4 ’ h8
/ / Most−s i g n i f i c a n t f o u r b i t s o f d e f a u l t Cb v a l u e
‘ d e f i n e ADV7185 REGISTER D { ‘DEFAULT CB VALUE, ‘ DEFAULT CR VALUE}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register E
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e TEMPORAL DECIMATION ENABLE
/ / 0 : Disable
/ / 1 : Enable
‘ d e f i n e TEMPORAL DECIMATION CONTROL
/ / 0 : S u p r e s s fr a mes , s t a r t with even f i e l d
/ / 1 : S u p r e s s fr a mes , s t a r t with odd f i e l d
/ / 2 : S u p r e s s even f i e l d s o n l y
/ / 3 : S u p r e s s odd f i e l d s o n l y
‘ d e f i n e TEMPORAL DECIMATION RATE
// 0 −F : Number o f f i e l d s / f r a m e s t o s k i p
1 ’ b0
2 ’ h0
4 ’ h0
‘ d e f i n e ADV7185 REGISTER E { 1 ’ b0 , ‘ TEMPORAL DECIMATION RATE,
‘TEMPORAL DECIMATION CONTROL,
‘TEMPORAL DECIMATION ENABLE}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register F
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e POWER SAVE CONTROL
/ / 0 : Full operation
/ / 1 : CVBS o n l y
2 ’ h0
5
// 2:
// 3:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
‘ define
// 0:
// 1:
D i g i t a l o n l y
Power s a v e mode
1 ’ b0
POWER DOWN SOURCE PRIORITY
Power−down p i n has p r i o r i t y
Power−down c o n t r o l b i t has p r i o r i t y
1 ’ b0
POWER DOWN REFERENCE
Reference i s functional
R e f e r e n c e i s powered down
1 ’ b0
POWER DOWN LLC GENERATOR
LLC g e n e r a t o r i s f u n c t i o n a l
LLC g e n e r a t o r i s powered down
1 ’ b0
POWER DOWN CHIP
Chip i s f u n c t i o n a l
Input pads d i s a b l e d and c l o c k s sto pped
1 ’ b0
TIMING REACQUIRE
Normal o p e r a t i o n
Reacquire video s i g n a l ( b i t w i l l automatically r e s e t )
1 ’ b0
RESET CHIP
Normal o p e r a t i o n
Reset d i g i t a l c o r e and I2C i n t e r f a c e ( b i t w i l l a u t o m a t i c a l l y r e s e t )
‘ d e f i n e ADV7185 REGISTER F { ‘ RESET CHIP , ‘ TIMING REACQUIRE, ‘ POWER DOWN CHIP,
‘POWER DOWN LLC GENERATOR, ‘POWER DOWN REFERENCE,
‘POWER DOWN SOURCE PRIORITY, ‘POWER SAVE CONTROL}
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
// Register 33
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
‘ d e f i n e PEAK WHITE UPDATE
/ / 0 : Update g a i n o nce per l i n e
/ / 1 : Update g a i n o nce per f i e l d
‘ d e f i n e AVERAGE BIRIGHTNESS LINES
/ / 0 : Use l i n e s 3 3 t o 3 1 0
/ / 1 : Use l i n e s 3 3 t o 2 7 0
‘ d e f i n e MAXIMUM IRE
/ / 0 : PAL: 1 3 3 , NTSC: 1 2 2
/ / 1 : PAL: 1 2 5 , NTSC: 1 1 5
/ / 2 : PAL: 1 2 0 , NTSC: 1 1 0
/ / 3 : PAL: 1 1 5 , NTSC: 1 0 5
/ / 4 : PAL: 1 1 0 , NTSC: 1 0 0
/ / 5 : PAL: 1 0 5 , NTSC: 1 0 0
/ / 6 − 7 : PAL: 1 0 0 , NTSC: 1 0 0
‘ d e f i n e COLOR KILL
/ / 0 : Disable co lo r k i l l
/ / 1 : Enable c o l o r k i l l
1 ’ b1
1 ’ b1
3 ’ h0
1 ’ b1
‘ d e f i n e ADV7185 REGISTER 33 { 1 ’ b1 , ‘ COLOR KILL, 1 ’ b1 , ‘ MAXIMUM IRE,
‘AVERAGE BIRIGHTNESS LINES,
‘PEAK WHITE UPDATE}
6
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
‘ define
ADV7185 REGISTER 10
ADV7185 REGISTER 11
ADV7185 REGISTER 12
ADV7185 REGISTER 13
ADV7185 REGISTER 14
ADV7185 REGISTER 15
ADV7185 REGISTER 16
ADV7185 REGISTER 17
ADV7185 REGISTER 18
ADV7185 REGISTER 19
ADV7185 REGISTER 1A
ADV7185 REGISTER 1B
ADV7185 REGISTER 1C
ADV7185 REGISTER 1D
ADV7185 REGISTER 1E
ADV7185 REGISTER 1F
ADV7185 REGISTER 20
ADV7185 REGISTER 21
ADV7185 REGISTER 22
ADV7185 REGISTER 23
ADV7185 REGISTER 24
ADV7185 REGISTER 25
ADV7185 REGISTER 26
ADV7185 REGISTER 27
ADV7185 REGISTER 28
ADV7185 REGISTER 29
ADV7185 REGISTER 2A
ADV7185 REGISTER 2B
ADV7185 REGISTER 2C
ADV7185 REGISTER 2D
ADV7185 REGISTER 2E
ADV7185 REGISTER 2F
ADV7185 REGISTER 30
ADV7185 REGISTER 31
ADV7185 REGISTER 32
ADV7185 REGISTER 34
ADV7185 REGISTER 35
ADV7185 REGISTER 36
ADV7185 REGISTER 37
ADV7185 REGISTER 38
ADV7185 REGISTER 39
ADV7185 REGISTER 3A
ADV7185 REGISTER 3B
8 ’ h00
8 ’ h00
8 ’ h00
8 ’ h45
8 ’ h18
8 ’ h60
8 ’ h00
8 ’ h01
8 ’ h00
8 ’ h10
8 ’ h10
8 ’ hF0
8 ’ h16
8 ’ h01
8 ’ h00
8 ’ h3D
8 ’ hD0
8 ’ h09
8 ’ h8C
8 ’ hE2
8 ’ h1F
8 ’ h07
8 ’ hC2
8 ’ h58
8 ’ h3C
8 ’ h00
8 ’ h00
8 ’ hA0
8 ’hCE
8 ’ hF0
8 ’ h00
8 ’ hF0
8 ’ h00
8 ’ h70
8 ’ h00
8 ’ h0F
8 ’ h01
8 ’ h00
8 ’ h00
8 ’ h00
8 ’ h00
8 ’ h00
8 ’ h00
‘ d e f i n e ADV7185 REGISTER 44 8 ’ h41
‘ d e f i n e ADV7185 REGISTER 45 8 ’hBB
‘ d e f i n e ADV7185 REGISTER F1 8 ’ hEF
‘ d e f i n e ADV7185 REGISTER F2 8 ’ h80
7
module a d v 7 1 8 5 i n i t ( r e s e t , clo ck 2 7 mhz , s o u r c e , t v i n r e s e t b ,
tv in i2c clock , tv in i2c data );
input r e s e t ;
i n p u t clo ck 2 7 mhz ;
o utput t v
i n r e s e t b ; / / Reset s i g n a l t o ADV7185
o utput t v
i n i 2 c c l o c k ; / / I2C c l o c k o utput t o ADV7185
o utput t v
i n i 2 c d a t a ; / / I2C da ta l i n e t o ADV7185
i n p u t s o u r c e ; / / 0 : co mpo site , 1 : s−v i d e o
i n i t i a l begin
$ d i s p l a y ( ”ADV7185 I n i t i a l i z a t i o n
$ d i s p l a y ( ” R e g i s t e r 0 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 1 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 2 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 3 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 4 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 5 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 7 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 8 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 9 : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r A : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r B : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r C : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r D : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r E : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r F : 0x%X” ,
$ d i s p l a y ( ” R e g i s t e r 3 3 : 0 x%X” ,
end
values : ” ) ;
‘ ADV7185 REGISTER 0 ) ;
‘ ADV7185 REGISTER 1 ) ;
‘ ADV7185 REGISTER 2 ) ;
‘ ADV7185 REGISTER 3 ) ;
‘ ADV7185 REGISTER 4 ) ;
‘ ADV7185 REGISTER 5 ) ;
‘ ADV7185 REGISTER 7 ) ;
‘ ADV7185 REGISTER 8 ) ;
‘ ADV7185 REGISTER 9 ) ;
‘ ADV7185 REGISTER A ) ;
‘ ADV7185 REGISTER B ) ;
‘ ADV7185 REGISTER C ) ;
‘ ADV7185 REGISTER D ) ;
‘ ADV7185 REGISTER E ) ;
‘ ADV7185 REGISTER F ) ;
‘ ADV7185 REGISTER 33 ) ;
//
/ / Gener a te a 1MHz f o r t h e I2C d r i v e r ( r e s u l t i n g I2C c l o c k r a t e i s 2 5 0 kHz )
//
r e g [ 7 : 0 ] c l k
d i v c o u n t , r e s e t c o u n t ;
r e g c l o c k
s l o w ;
w i r e r e s e t
s l o w ;
initial
begin
c l k d i v c o u n t <= 8 ’ h00 ;
// synthesis attribute i n i t of clk div count i s ”00”;
c l o c k s l o w <= 1 ’ b0 ;
/ / s y n t h e s i s a t t r i b u t e i n i t o f c l o c k s l o w i s ” 0 ” ;
end
a lwa ys @( po sedg e clo ck 2 7 mhz )
i f ( c l k d i v c o u n t == 26)
b e g i n
c l o c k
s l o w <= ˜ c l o c k s l o w ;
c l k d i v c o u n t <= 0;
8
end
e l s e
c l k
d i v c o u n t <= c l k d i v c o u n t +1;
a lwa ys @( po sedg e clo ck 2 7 mhz )
i f ( r e s e t )
r e s e t
c o u n t <= 100;
e l s e
r e s e t c o u n t <= ( r e s e t c o u n t = = 0 ) ? 0 : r e s e t c o u n t −1;
assign reset slow = reset count != 0;
//
/ / I2C d r i v e r
//
reg load ;
r e g [ 7 : 0 ] da ta ;
w i r e ack , i d l e ;
i 2 c i 2 c ( . r e s e t ( r e s e t s l o w ) , . c l o c k 4 x ( c l o c k s l o w ) , . da ta ( da ta ) , . l o a d ( l o a d ) ,
. ack ( ack ) , . i d l e ( i d l e ) , . s c l ( t v i n i 2 c c l o c k ) ,
. sda ( t v
i n i 2 c d a t a ) ) ;
//
/ / S t a t e machine
//
r e g [ 7 : 0 ] s t a t e ;
r e g t v
i n r e s e t b ;
reg old source ;
a lwa ys @( po sedg e c l o c k s l o w )
i f ( r e s e t s l o w )
b e g i n
s t a t e <= 0;
l o a d <= 0;
t v i n r e s e t b <= 0;
o l d s o u r c e <= 0;
end
e l s e
c a s e ( s t a t e )
8 ’ h00 :
b e g i n
/ / A s s e r t r e s e t
l o a d <= 1 ’ b0 ;
t v i n r e s e t b <= 1 ’ b0 ;
i f ( ! ack )
s t a t e <= s t a t e +1;
end
8 ’ h01 :
9
s t a t e <= s t a t e +1;
8 ’ h02 :
b e g i n
/ / R e l e a s e r e s e t
t v i n r e s e t b <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h03 :
b e g i n
/ / Send ADV7185 a d d r e s s
da ta <= 8 ’h8A ;
l o a d <= 1 ’ b1 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h04 :
b e g i n
/ / Send s u b a d d r e s s o f f i r s t r e g i s t e r
da ta <= 8 ’ h00 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h05 :
begin
/ / Write t o r e g i s t e r 0
da ta <= ‘ADV7185 REGISTER 0 | { 5 ’ h00 , { 3 { s o u r c e } } } ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h06 :
b e g i n
/ / Write t o r e g i s t e r 1
da ta <= ‘ADV7185 REGISTER 1 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h07 :
b e g i n
/ / Write t o r e g i s t e r 2
da ta <= ‘ADV7185 REGISTER 2 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h08 :
b e g i n
/ / Write t o r e g i s t e r 3
da ta <= ‘ADV7185 REGISTER 3 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h09 :
10
b e g i n
/ / Write t o r e g i s t e r 4
da ta <= ‘ADV7185 REGISTER 4 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h0A :
b e g i n
/ / Write t o r e g i s t e r 5
da ta <= ‘ADV7185 REGISTER 5 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h0B :
begin
/ / Write t o r e g i s t e r 6
da ta <= 8 ’ h00 ; / / Reser ved r e g i s t e r , w r i t e a l l z e r o s
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h0C :
b e g i n
/ / Write t o r e g i s t e r 7
da ta <= ‘ADV7185 REGISTER 7 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’h0D :
b e g i n
/ / Write t o r e g i s t e r 8
da ta <= ‘ADV7185 REGISTER 8 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h0E :
b e g i n
/ / Write t o r e g i s t e r 9
da ta <= ‘ADV7185 REGISTER 9 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h0F : b e g i n
/ / Write t o r e g i s t e r A
da ta <= ‘ADV7185 REGISTER A ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h10 :
b e g i n
/ / Write t o r e g i s t e r B
da ta <= ‘ADV7185 REGISTER B ;
11
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h11 :
b e g i n
/ / Write t o r e g i s t e r C
da ta <= ‘ADV7185 REGISTER C ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h12 :
b e g i n
/ / Write t o r e g i s t e r D
da ta <= ‘ADV7185 REGISTER D ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h13 :
b e g i n
/ / Write t o r e g i s t e r E
da ta <= ‘ADV7185 REGISTER E ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h14 :
b e g i n
/ / Write t o r e g i s t e r F
da ta <= ‘ADV7185 REGISTER F ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h15 :
begin
/ / Wait f o r I2C t r a n s m i t t e r t o f i n i s h
l o a d <= 1 ’ b0 ;
if ( idle )
s t a t e <= s t a t e +1;
end
8 ’ h16 :
b e g i n
/ / Write a d d r e s s
da ta <= 8 ’h8A ;
l o a d <= 1 ’ b1 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h17 :
b e g i n
da ta <= 8 ’ h33 ;
i f ( ack )
s t a t e <= s t a t e +1;
12
end
8 ’ h18 :
begin
da ta <= ‘ADV7185 REGISTER 33 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h19 :
b e g i n
l o a d <= 1 ’ b0 ;
i f ( i d l e )
s t a t e <= s t a t e +1;
end
8 ’ h1A : b e g i n
da ta <= 8 ’h8A ;
l o a d <= 1 ’ b1 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h1B :
b e g i n
da ta <= 8 ’ h33 ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h1C :
b e g i n
l o a d <= 1 ’ b0 ;
i f ( i d l e )
s t a t e <= s t a t e +1;
end
8 ’h1D :
b e g i n
l o a d <= 1 ’ b1 ;
da ta <= 8 ’h8B ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h1E :
b e g i n
da ta <= 8 ’hFF ;
i f ( ack )
s t a t e <= s t a t e +1;
end
8 ’ h1F :
b e g i n
l o a d <= 1 ’ b0 ;
i f ( i d l e )
s t a t e <= s t a t e +1;
end
13
8 ’ h20 :
b e g i n
/ / I d l e
i f ( o l d
s o u r c e ! = s o u r c e ) s t a t e <= s t a t e +1;
o l d s o u r c e <= s o u r c e ;
end
8 ’ h21 : b e g i n
/ / Send ADV7185 a d d r e s s
da ta <= 8 ’h8A ;
l o a d <= 1 ’ b1 ;
i f ( ack ) s t a t e <= s t a t e +1;
end
8 ’ h22 : b e g i n
/ / Send s u b a d d r e s s o f r e g i s t e r 0
da ta <= 8 ’ h00 ;
i f ( ack ) s t a t e <= s t a t e +1;
end
8 ’ h23 : b e g i n
/ / Write t o r e g i s t e r 0
da ta <= ‘ADV7185 REGISTER 0 | { 5 ’ h00 , { 3 { s o u r c e } } } ;
i f ( ack ) s t a t e <= s t a t e +1;
end
8 ’ h24 : b e g i n
/ / Wait f o r I2C t r a n s m i t t e r t o f i n i s h
l o a d <= 1 ’ b0 ;
i f ( i d l e ) s t a t e <= 8 ’ h20 ;
end
e n d c a s e
endmodule
/ / i 2 c module f o r use with t h e ADV7185
module i 2 c ( r e s e t , c l o c k 4 x , data , lo a d , i d l e , ack , s c l , sda ) ;
i n p u t r e s e t ;
i n p u t c l o c k 4 x ;
i n p u t [ 7 : 0 ] da ta ;
i n p u t l o a d ;
o utput ack ;
o utput i d l e ;
o utput s c l ;
o utput sda ;
reg
reg
reg
reg
[ 7 : 0 ] l d a t a ;
ack , i d l e ;
s c l ;
s d a i ;
reg [ 7 : 0 ] state ;
14
a s s i g n sda = s d a i ? 1 ’ bZ : 1 ’ b0 ;
a lwa ys @( po sedg e c l o c k 4 x )
if ( reset )
b e g i n
s t a t e <= 0;
ack <= 0;
end
e l s e
c a s e ( s t a t e )
8 ’ h00 : / / i d l e
begin
s c l <= 1 ’ b1 ;
s d a i <= 1 ’ b1 ;
ack <= 1 ’ b0 ;
i d l e <= 1 ’ b1 ;
i f ( load )
begin
l d a t a <= da ta ;
ack <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
end
8 ’ h01 : / / S t a r t
begin
ack <= 1 ’ b0 ;
i d l e <= 1 ’ b0 ;
s d a i <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h02 :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h03 : / / Send b i t 7
begin
ack <= 1 ’ b0 ;
s d a i <= l d a t a [ 7 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h04 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h05 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h06 :
15
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h07 :
begin
s d a i <= l d a t a [ 6 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h08 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h09 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h0A :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h0B :
begin
s d a i <= l d a t a [ 5 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h0C :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h0D :
begin
s t a t e <= s t a t e +1;
end
8 ’ h0E :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h0F :
begin
s d a i <= l d a t a [ 4 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h10 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
16
end
8 ’ h11 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h12 :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h13 :
begin
s d a i <= l d a t a [ 3 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h14 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h15 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h16 :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h17 :
begin
s d a i <= l d a t a [ 2 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h18 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h19 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h1A :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h1B :
begin
s d a i <= l d a t a [ 1 ] ;
17
s t a t e <= s t a t e +1;
end
8 ’ h1C :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h1D :
begin
s t a t e <= s t a t e +1;
end
8 ’ h1E :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h1F :
begin
s d a i <= l d a t a [ 0 ] ;
s t a t e <= s t a t e +1;
end
8 ’ h20 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h21 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h22 :
begin
s c l <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h23 : / / Acknowledge b i t
begin
s t a t e <= s t a t e +1;
end
8 ’ h24 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h25 :
begin
s t a t e <= s t a t e +1;
end
8 ’ h26 :
begin
s c l <= 1 ’ b0 ;
18
i f ( load )
begin
l d a t a <= da ta ;
ack <= 1 ’ b1 ;
s t a t e <= 3;
end
else
s t a t e <= s t a t e +1;
end
8 ’ h27 :
begin
s d a i <= 1 ’ b0 ;
s t a t e <= s t a t e +1;
end
8 ’ h28 :
begin
s c l <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h29 :
begin
s d a i <= 1 ’ b1 ;
s t a t e <= 0;
end
e n d c a s e
endmodule
19
//
//
//
//
//
//
//
//
//
//
File :
z b t
6 1 1 1 . v
Date :
27−Nov−05
Author : I . Chuang
Simple ZBT d r i v e r f o r t h e MIT 6 . 1 1 1 l a b k i t , which do es not h i d e t h e
p i p e l i n e d e l a y s o f t h e ZBT from t h e u s e r . The ZBT memories have
two c y c l e l a t e n c i e s on r ea d and w r i t e , and a l s o need e x t r a −l o n g da ta ho ld
t i m e s around t h e c l o c k p o s i t i v e edg e t o work r e l i a b l y .
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / /
/ / Ike ’ s s i m p l e ZBT RAM d r i v e r f o r t h e MIT 6 . 1 1 1 l a b k i t
//
/ / Data f o r w r i t e s can be p r e s e n t e d and c l o c k e d i n i m m e d i a t e l y ; t h e a c t u a l
/ / w r i t i n g t o RAM w i l l happen two c y c l e s l a t e r .
//
/ / Read r e q u e s t s a r e p r o c e s s e d immedia tely , but t h e r ea d da ta i s not a v a i l a b l e
/ / u n t i l two c y c l e s a f t e r t h e i n t i a l r e q u e s t .
//
/ / A c l o c k e n a b l e s i g n a l i s p r o v i d e d ; i t e n a b l e s t h e RAM c l o c k when hig h .
module z b t
6 1 1 1 ( c l k , cen , we , addr , w r i t e d a t a , r e a d d a t a ,
r a m clk , ram we b , r a m a ddr ess , ram data , r a m cen b ) ;
i n p u t c l k ;
i n p u t cen ;
i n p u t we ;
i n p u t [ 1 8 : 0 ] addr ;
i n p u t [ 3 5 : 0 ] w r i t e d a t a ;
o utput [ 3 5 : 0 ] r e a d d a t a ;
o utput
ram clk ;
o utput
ram we b ;
o utput [ 1 8 : 0 ] r a m a d d r e s s ;
i n o u t [ 3 5 : 0 ] ram data ;
o utput
r a m cen b ;
//
//
//
//
//
//
//
//
//
//
//
system c l o c k
c l o c k e n a b l e f o r g a t i n g ZBT c y c l e s
w r i t e e n a b l e ( a c t i v e HIGH)
memory a d d r e s s
da ta t o w r i t e
da ta r ea d from memory
p h y s i c a l l i n e t o ram c l o c k
p h y s i c a l l i n e t o ram we b
p h y s i c a l l i n e t o ram a d d r e s s
p h y s i c a l l i n e t o ram da ta
p h y s i c a l l i n e t o ram c l o c k e n a b l e
/ / c l o c k e n a b l e ( s h o u l d be synchr o no us and one c y c l e hig h a t a time )
wire
r a m cen b = ˜ cen ;
/ / c r e a t e d e l a y e d ram we s i g n a l : no te t h e d e l a y i s by two c y c l e s !
/ / i e we p r e s e n t t h e da ta t o be w r i t t e n two c y c l e s a f t e r we i s r a i s e d
/ / t h i s means t h e bus i s t r i −s t a t e d two c y c l e s a f t e r we i s r a i s e d .
reg [ 1 : 0 ]
we delay ;
a lwa ys @( po sedg e c l k )
w e d e l a y <= cen ? { w e d e l a y [ 0 ] , we } : w e d e l a y ;
/ / c r e a t e two−s t a g e p i p e l i n e f o r w r i t e da ta
20
reg [ 3 5 : 0 ]
w r i t e d a t a o l d 1 ;
reg [ 3 5 : 0 ]
w r i t e
d a t a o l d 2 ;
a lwa ys @( po sedg e c l k )
i f ( cen )
{ w r i t e
d a t a o l d 2 , w r i t e d a t a o l d 1 } <= { w r i t e d a t a o l d 1 , w r i t e d a t a } ;
/ / w i r e t o ZBT RAM s i g n a l s
assign
ram we b = ˜ we ;
assign
ram clk = ˜ clk ;
/ / RAM i s not happy with our da ta ho ld
/ / t i m e s i f i t s c l k e d g e s e q u a l FPGA’ s
/ / so we c l o c k i t on t h e f a l l i n g e d g e s
/ / and thus l e t da ta s t a b i l i z e l o n g e r
assign
r a m a d d r e s s = addr ;
assign
assign
ram data = w e d e l a y [ 1 ] ? w r i t e d a t a o l d 2 : { 3 6 { 1 ’ bZ } } ;
r e a d d a t a = ram data ;
endmodule / / z b t 6 1 1 1
21
//
// File :
ntsc2zbt . v
/ / Date :
27−Nov−05
/ / Author : I . Chuang
//
/ / Example f o r MIT 6 . 1 1 1 l a b k i t showing how t o p r e p a r e NTSC data
/ / ( from J a v i e r ’ s d e c o d e r ) t o be l o a d e d i n t o t h e ZBT RAM f o r v i d e o
// display .
//
// M o d i f i e d so t h a t 2 s e t s o f 1 8 b i t da ta c o r r e s p o n d i n g t o 2 p i x e l s
/ / a r e w r i t t e n d u r i n g ea ch w r i t e
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / /
/ / P r epa r e da ta and a d d r e s s v a l u e s t o f i l l ZBT memory with NTSC da ta
module n t s c t o z b t ( c l k , v c l k , fvh , dv , din , n t s c a d d r , n t s c d a t a , n t s c w e ) ;
input
input
input [ 2 : 0 ]
input
input [ 2 9 : 0 ]
clk ;
vclk ;
f v h ;
dv ;
d i n ;
/ / system c l o c k
/ / v i d e o c l o c k from camera
o utput [ 1 8 : 0 ] n t s c
a d d r ;
o utput [ 3 5 : 0 ] n t s c
d a t a ;
o utput
ntsc we ;
/ / w r i t e e n a b l e f o r NTSC da ta
COL START = 1 0 ’ d0 ;
ROW START = 1 0 ’ d0 ;
pa r a meter
pa r a meter
/ / h e r e put t h e lumina nce da ta from t h e n t s c d e c o d e r i n t o t h e ram
/ / t h i s i s f o r 1 0 2 4 x 7 6 8 XGA d i s p l a y
reg [ 9 : 0 ]
reg [ 9 : 0 ]
reg [ 1 7 : 0 ]
reg
reg
reg
reg
reg
col = 0;
row = 0 ;
vdata = 0 ;
vwe ;
old dv ;
old frame ;
old v ;
even o dd ;
wire
wire
wire
frame = f v h [ 2 ] ;
f r a m e e d g e = frame & ˜ o l d f r a m e ;
v edge = ! fvh [ 2 ] & ! fvh [ 1 ] & o ld v ;
a lwa ys @
begin
old
vwe
old
/ / f r a m e s a r e even / odd i n t e r l a c e d
/ / deco de i n t e r l a c e d frame t o t h i s w i r e
( po sedg e v c l k ) / / LLC1 i s r e f e r e n c e
d v <= dv ;
<= dv && ! f v h [ 2 ] & ˜ o l d d v ; / / i f da ta v a l i d , w r i t e i t
f r a m e <= frame ;
22
o l d v = f v h [ 1 ] ;
even o dd = f r a m e e d g e ? ˜ even o dd : even o dd ;
i f ( ! fvh [ 2 ] )
begin
c o l <= f v h [ 0 ] ? COL START :
( ! f v h [ 2 ] & & dv && ( c o l < 640+COL START ) ) ? c o l + 1 : c o l ;
row <= v e d g e ? ROW START :
( ! f v h [ 2 ] & & f v h [ 0 ] & & ( row < 480+ROW START) ) ? row + 1 : row ;
vdata <= (dv && ! f v h [ 2 ] ) ? { d i n [ 2 9 : 2 2 ] , d i n [ 1 9 : 1 5 ] , d i n [ 9 : 5 ] } : vdata ;
end
end
/ / s y n c h r o n i z e with system c l o c k
reg [ 9 : 0 ] x [ 1 : 0 ] ;
reg [ 9 : 0 ] y [ 1 : 0 ] ;
r e g [ 1 7 : 0 ] da ta [ 1 : 0 ] ;
reg
we [ 1 : 0 ] ;
reg
eo [ 1 : 0 ] ;
a lwa ys @( po sedg e c l k )
b e g i n
{x [ 1 ] , x [0 ]} < = { x [ 0 ] , c o l } ;
{y [ 1 ] , y [0 ]} < = { y [ 0 ] , row } ;
{ da ta [ 1 ] , da ta [0 ]} < = { da ta [ 0 ] , vdata } ;
{we [ 1 ] , we [0 ]} < = { we [ 0 ] , vwe } ;
{ eo [ 1 ] , eo [0 ]} < = { eo [ 0 ] , even o dd } ;
end
/ / edg e d e t e c t i o n on w r i t e e n a b l e s i g n a l
reg old we ;
w i r e we edg e = we [ 1 ] & ˜ o l d w e ;
a lwa ys @( po sedg e c l k ) o l d w e <= we [ 1 ] ;
/ / s h i f t ea ch s e t o f f o u r b y t e s i n t o a l a r g e r e g i s t e r f o r t h e ZBT
r e g [ 3 5 : 0 ] mydata ;
a lwa ys @( po sedg e c l k )
i f ( we edg e )
mydata <= { mydata [ 1 7 : 0 ] , da ta [ 1 ] } ;
/ / compute a d d r e s s t o s t o r e da ta i n
w i r e [ 1 8 : 0 ] myaddr = { y [ 1 ] [ 8 : 0 ] , 1 ’ b0 , x [ 1 ] [ 9 : 1 ] } ;
/ / update t h e o utput a d d r e s s and da ta o n l y when f o u r b y t e s r eady
reg [ 1 8 : 0 ]
ntsc addr ;
23
reg [ 3 5 : 0 ]
wire
ntsc data ;
n t s c w e = we edg e & ( x [ 1 ] [ 0 ] = = 1 ’ b0 ) ;
a lwa ys @( po sedg e c l k )
i f ( ntsc we )
begin
n t s c a d d r <= myaddr ;
n t s c d a t a <= mydata ;
end
/ / normal and expanded modes
endmodule / / n t s c t o z b t
24
//
// File :
n t s c
d e c o d e . v
/ / Date :
31−Oct−05
/ / Author : J . Ca str o ( MIT 6 . 1 1 1 , f a l l 2 0 0 5 )
//
/ / This f i l e c o n t a i n s t h e n t s c
d e c o d e modules
//
/ / This module (w/ ADV7185init ) i s used t o g r a b i n p u t NTSC v i d e o da ta from t h e RCA
/ / phono j a c k on t h e r i g h t hand s i d e o f t h e 6 . 1 1 1 l a b k i t ( c o n n e c t
/ / t h e camera t o t h e LOWER j a c k ) .
//
/ / M o d i f i e d so t h a t v i s low d u r i n g t h e e n t i r e odd f i e l d
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / /
//
/ / NTSC deco de − 16− b i t CCIR656 d e c o d e r
/ / By J a v i e r Ca str o
/ / This module t a k e s a str ea m o f LLC da ta from t h e adv7185
/ / NTSC/PAL v i d e o d e c o d e r and g e n e r a t e s t h e c o r r e s p o n d i n g p i x e l s ,
/ / t h a t a r e encoded w i t h i n t h e stream , i n YCrCb fo r ma t .
/ / Make s u r e t h a t t h e adv7185 i s s e t t o run i n 16− b i t LLC2 mode .
module n t s c d e c o d e ( c l k , r e s e t , t v i n y c r c b , ycr cb , f , v , h , d a t a v a l i d ) ;
//
//
//
//
//
//
//
c l k − l i n e −l o c k e d c l o c k ( i n t h i s c a s e , LLC1 which r uns a t 2 7Mhz)
r e s e t − system r e s e t
t v
i n y c r c b − 10− b i t i n p u t from c h i p . s h o u l d map t o p i n s [ 1 9 : 1 0 ]
y c r c b − 2 4 b i t lumina nce and chr o mina nce ( 8 b i t s ea ch )
f − f i e l d : 1 i n d i c a t e s an even f i e l d , 0 an odd f i e l d
v − v e r t i c a l sync : 1 means v e r t i c a l sync
h − h o r i z o n t a l sync : 1 means h o r i z o n t a l sync
i n p u t c l k ;
i n p u t r e s e t ;
i n p u t [ 9 : 0 ] t v
i n y c r c b ; / / m o d i f i e d f o r 1 0 b i t i n p u t − s h o u l d be P [ 1 9 : 1 0 ]
o utput [ 2 9 : 0 ] y c r c b ;
o utput
f ;
o utput
v ;
o utput
h ;
o utput
d a t a
v a l i d ;
/ / o utput [ 4 : 0 ] s t a t e ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
SYNC 1 = 0 ;
SYNC 2 = 1 ;
SYNC 3 = 2 ;
SAV f1 cb0 = 3 ;
SAV f1 y0 = 4 ;
SAV
f1 cr 1 = 5 ;
SAV f1 y1 = 6 ;
EAV f1 = 7 ;
SAV VBI f1 = 8 ;
25
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
EAV
SAV
SAV
SAV
SAV
EAV
SAV
EAV
VBI f1 = 9 ;
f2 cb0 = 1 0 ;
f2 y0 = 1 1 ;
f2 cr 1 = 1 2 ;
f2 y1 = 1 3 ;
f2 = 1 4 ;
VBI f2 = 1 5 ;
VBI f2 = 1 6 ;
/ / In t h e s t a r t s t a t e , t h e module doesn ’ t know where
// in the sequence o f p i x e l s , i t i s lo o king .
/ / Once we d e t e r m i n e where t o s t a r t , t h e FSM g o e s thr o ug h a normal
/ / s e q u e n c e o f SAV process YCrCb EAV . . . r e p e a t
/ / The da ta str ea m l o o k s a s f o l l o w s
/ / SAV FF | SAV 00 | SAV 00 | SAV XY | Cb0 | Y0 | Cr1 | Y1 | Cb2 |Y | . . . | EAV s e q u e n c e
/ / There a r e two t h i n g s we need t o do :
//
1 . Find t h e two SAV b l o c k s ( s t a n d s f o r S t a r t A c t i v e Video per ha ps ? )
//
2 . Decode t h e s u b s e q u e n t da ta
reg
reg
reg
reg
[4:0]
[9:0]
[9:0]
[9:0]
assign
current state
y = 1 0 ’ h000 ;
c r = 1 0 ’ h000 ;
cb = 1 0 ’ h000 ;
= 5 ’ h00 ;
/ / lumina nce
/ / chr o mina nce
/ / more chr o mina nce
state = current state ;
a lwa ys @ ( po sedg e c l k )
begin
if ( reset )
begin
end
else
begin
/ / t h e s e s t a t e s don ’ t do much e x c e p t a l l o w us t o know where we a r e i n t h e str ea m .
/ / whenever t h e s y n c h r o n i z a t i o n co de i s seen , go back t o t h e s y n c s t a t e b e f o r e
/ / t r a n s i t i o n i n g t o t h e new s t a t e
case ( cur r ent s ta te )
SYNC 1 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h000 ) ? SYNC 2 : SYNC 1 ;
SYNC 2 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h000 ) ? SYNC 3 : SYNC 1 ;
SYNC 3 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h200 ) ? SAV f1 cb0 :
( t v i n y c r c b == 10 ’ h274 ) ? EAV f1 :
( t v i n y c r c b == 10 ’ h2ac ) ? SAV VBI f1 :
( t v i n y c r c b == 10 ’ h2d8 ) ? EAV VBI f1 :
( t v i n y c r c b == 10 ’ h31c ) ? SAV f2 cb0 :
( t v i n y c r c b == 10 ’ h368 ) ? EAV f2 :
26
( t v i n y c r c b == 10 ’ h3b0 ) ? SAV VBI f2 :
( t v i n y c r c b == 10 ’ h3c4 ) ? EAV VBI f2 : SYNC 1 ;
SAV
SAV
SAV
SAV
f1
f1
f1
f1
cb0 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1
y0 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1 :
cr 1 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1
y1 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1 :
: SAV f1 y0 ;
SAV f1 cr 1 ;
: SAV f1 y1 ;
SAV f1 cb0 ;
SAV
SAV
SAV
SAV
f2
f2
f2
f2
cb0 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1
y0 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1 :
cr 1 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1
y1 : c u r r e n t s t a t e <= ( t v i n y c r c b == 10 ’ h 3 f f ) ? SYNC 1 :
: SAV f2 y0 ;
SAV f2 cr 1 ;
: SAV f2 y1 ;
SAV f2 cb0 ;
/ / These s t a t e s a r e h e r e i n t h e e v e n t t h a t we want t o c o v e r t h e s e s i g n a l s
/ / i n t h e f u t u r e . For now , they j u s t send t h e s t a t e machine back t o SYNC 1
EAV f1 : c u r r e n t s t a t e <= SYNC 1 ;
SAV VBI f1 : c u r r e n t
s t a t e <= SYNC 1 ;
EAV VBI f1 : c u r r e n t
s t a t e <= SYNC 1 ;
EAV f2 : c u r r e n t
s t a t e <= SYNC 1 ;
SAV VBI f2 : c u r r e n t
s t a t e <= SYNC 1 ;
EAV VBI f2 : c u r r e n t
s t a t e <= SYNC 1 ;
e n d c a s e
end
end / / a lwa ys @ ( po sedg e c l k )
/ / implement our d e c o d i n g mechanism
wire y enable ;
wire c r e n a b l e ;
wire cb enable ;
/ / i f y i s coming in , e n a b l e t h e r e g i s t e r
/ / l i k e w i s e f o r c r and cb
a s s i g n y e n a b l e = ( c u r r e n t s t a t e == SAV f1 y0 ) | |
( c u r r e n t s t a t e == SAV f1 y1 ) | |
( c u r r e n t
s t a t e == SAV f2 y0 ) | |
( c u r r e n t
s t a t e == SAV f2 y1 ) ;
a s s i g n c r e n a b l e = ( c u r r e n t s t a t e == SAV f1 cr 1 ) | |
( c u r r e n t s t a t e == SAV f2 cr 1 ) ;
a s s i g n c b e n a b l e = ( c u r r e n t s t a t e == SAV f1 cb0 ) | |
( c u r r e n t s t a t e == SAV f2 cb0 ) ;
/ / f , v , and h o n l y go hig h when a c t i v e
a s s i g n { v , h } = ( c u r r e n t s t a t e == SYNC 3 ) ? t v i n y c r c b [ 7 : 6 ] : 2 ’ b00 ;
/ / da ta i s v a l i d when we have a l l t h r e e v a l u e s : y , cr , cb
assign data valid = y enable ;
a s s i g n y c r c b = { y , cr , cb } ;
reg
f = 0;
27
a lwa ys @ ( po sedg e c l k )
b e g i n
y <= y
e n a b l e ? t v i n y c r c b : y ;
c r <= c r
e n a b l e ? t v i n y c r c b : c r ;
cb <= c b
e n a b l e ? t v i n y c r c b : cb ;
f <= ( c u r r e n t s t a t e == SYNC 3 ) ? t v i n y c r c b [ 8 ] : f ;
end
endmodule
28
/ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗
∗∗
∗ ∗ Module : y c r c b 2 r g b
∗∗
∗ Convert y c r c b t o rgb c o l o r s p a c e
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ ∗ ∗∗ ∗ ∗∗ ∗ /
module YCrCb2RGB ( R , G, B , c l k , r s t , Y, Cr , Cb ) ;
o utput [ 7 : 0 ]
R , G, B ;
input
input [ 9 : 0 ]
c l k , r s t ;
Y, Cr , Cb ;
wire [ 7 : 0 ]
reg [ 2 0 : 0 ]
reg [ 9 : 0 ]
reg [ 9 : 0 ]
R,G, B;
R
int , G int , B int , X int , A int , B1 int , B2 int , C i n t ;
co nst1 , co nst2 , co nst3 , co nst4 , c o n s t 5 ;
Y reg , Cr
r eg , Cb reg ;
// r e g i s t e r i n g c o n s t a n t s
a lwa ys @ ( po sedg e c l k )
b e g i n
const1 = 10 ’b 0100101010;
const2 = 10 ’b 0110011000;
const3 = 10 ’b 0011010000;
const4 = 10 ’b 0001100100;
const5 = 10 ’b 1000000100;
end
//1.164
//1.596
//0.813
//0.392
//2.017
=
=
=
=
=
0 1 . 0 0 1 0 1 0 1 0
0 1 . 1 0 0 1 1 0 0 0
0 0 . 1 1 0 1 0 0 0 0
0 0 . 0 1 1 0 0 1 0 0
1 0 . 0 0 0 0 0 1 0 0
a lwa ys @ ( po sedg e c l k o r po sedg e r s t )
i f ( r s t )
b e g i n
Y r eg < = 0 ; C r r e g < = 0 ; Cb reg <= 0;
end
e l s e
b e g i n
Y r eg <= Y ; C r
r e g <= Cr ; Cb reg <= Cb ;
end
a lwa ys @ ( po sedg e c l k o r po sedg e r s t )
if ( rst )
begin
A i n t < = 0 ; B 1 i n t < = 0 ; B 2 i n t < = 0 ; C i n t < = 0 ; X i n t <= 0;
end
else
b e g i n
X i n t <= ( c o n s t 1 ∗ ( Y r eg − ’ d64 ) ) ;
A
i n t <= ( c o n s t 2 ∗ ( C r r e g − ’ d512 ) ) ;
B 1 i n t <= ( c o n s t 3 ∗ ( C r
r e g − ’ d512 ) ) ;
B 2
i n t <= ( c o n s t 4 ∗ ( Cb reg − ’ d512 ) ) ;
C i n t <= ( c o n s t 5 ∗ ( Cb reg − ’ d512 ) ) ;
29
end
a lwa ys @ ( po sedg e c l k
i f ( r s t )
b e g i n
R int <= 0; G
end
e l s e
b e g i n
R
i n t <= X i n t
G
i n t <= X i n t
B
i n t <= X i n t
end
/∗ limit
assign R
assign G
assign B
o r po sedg e r s t )
i n t < = 0 ; B i n t <= 0;
+ A i n t ;
− B 1 i n t − B 2 i n t ;
+ C i n t ;
o utput t o 0 −
= ( R int [ 2 0 ] )
= ( G int [ 2 0 ] )
= ( B int [ 2 0 ] )
4095 ,
? 0 :
? 0 :
? 0 :
<0
(R
(G
(B
e q u a l s 0 and >4095 e q u a l s 4 0 9 5 ∗ /
i n t [ 1 9 : 1 8 ] = = 2 ’ b0 ) ? R i n t [ 1 7 : 1 0 ] : 8 ’ b11111111 ;
i n t [ 1 9 : 1 8 ] = = 2 ’ b0 ) ? G
i n t [ 1 7 : 1 0 ] : 8 ’ b11111111 ;
i n t [ 1 9 : 1 8 ] = = 2 ’ b0 ) ? B
i n t [ 1 7 : 1 0 ] : 8 ’ b11111111 ;
endmodule
30
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / /
// parameterized delay l i n e
module delayN ( c l k , in , out ) ;
input clk ;
input in ;
o utput out ;
pa r a meter NDELAY = 3 ;
r e g [ NDELAY− 1 : 0 ] s h i f t r e g ;
wire
out = s h i f t r e g [NDELAY− 1 ] ;
a lwa ys @( po sedg e c l k )
s h i f t r e g <= { s h i f t r e g [NDELAY− 2 : 0 ] , i n } ;
endmodule / / delayN
31
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / /
/ / g e n e r a t e d i s p l a y p i x e l s from r e a d i n g t h e ZBT ram
/ / Each da ta has 2 1 8 b i t pa cka g e c o r r e s p o n d i n g t o 2 p i x e l s .
module v r a m
d i s p l a y ( r e s e t , c l k , hcount , vcount , v r p i x e l ,
vram addr , v r a m r e a d d a t a ) ;
i n p u t r e s e t , c l k ;
i n p u t [ 9 : 0 ] hcount ;
i n p u t [ 9 : 0 ] vcount ;
o utput [ 1 7 : 0 ] v r
p i x e l ;
o utput [ 1 8 : 0 ] vram
addr ;
i n p u t [ 3 5 : 0 ] v r a m
r e a d d a t a ;
wire [ 9 : 0 ]
wire [ 9 : 0 ]
wire [ 1 8 : 0 ]
v s h i f t = vcount + 2 1 ;
h s h i f t = hcount + 1 4 ;
vram addr = { v s h i f t [ 9 : 1 ] , 1 ’ b0 , h s h i f t [ 9 : 1 ] } ;
wire
reg [ 1 7 : 0 ]
reg [ 3 5 : 0 ]
reg [ 3 5 : 0 ]
hc4 = hcount [ 0 ] ;
v r
p i x e l ;
v r
d a t a l a t c h e d ;
l a s t
v r d a t a ;
a lwa ys @( po sedg e c l k )
b e g i n
v r
d a t a l a t c h e d <= ( hc4 ) ? v r a m r e a d d a t a : v r d a t a l a t c h e d ;
l a s t v r d a t a <= ( hc4 ) ? v r d a t a l a t c h e d : l a s t v r d a t a ;
end
a lwa ys @( ∗ )
b e g i n
c a s e ( hc4 )
1 ’ d1 : v r
p i x e l <= l a s t v r d a t a [ 1 7 : 0 ] ;
1 ’ d0 : v r
p i x e l <= l a s t v r d a t a [ 3 5 : 1 8 ] ;
endcase
end
endmodule / / v r a m d i s p l a y
32
// module s e a r c h e s f o r two clumps o f b r i g h t l i g h t s
// t h e s e two clumps s h o u l d c o r r e s p o n d t o t h e l e f t and r i g h t hands o f t h e u s e r
module f i n d l i g h t s ( c l k , r e s e t , vcount , hcount , v a l i d c o l o r , v c e n l , h c e n l , vcenr , hcenr ) ;
input clk , r e s e t ;
i n p u t [ 9 : 0 ] vcount , hcount ;
input
validcolor ;
o utput [ 9 : 0 ] v c e n l , h c e n l ;
o utput [ 9 : 0 ] vcenr , hcenr ;
reg [ 9 : 0 ]
reg [ 9 : 0 ]
vcenl , hcenl ;
vcenr , hcenr ;
reg [ 9 : 0 ]
reg [ 9 : 0 ]
reg
vcen1 , hcen1 ;
vup1 , vdown1 , h l e f t 1 , h r i g h t 1 ;
onevalid ;
wire
wire
wire
wire
wire
wire
wire
wire
wire
wire
up1 = vcount < vup1 ;
down1 = vcount > vdown1 ;
l e f t 1 = hcount < h l e f t 1 ;
r i g h t 1 = hcount > h r i g h t 1 ;
v d i s t 1 = vdown1 − vup1 ;
hdist1 = hright1 − hleft1 ;
tempvcen1 = vup1 + { 0 , v d i s t 1 [ 9 : 1 ] } ;
temphcen1 = h l e f t 1 + { 0 , h d i s t 1 [ 9 : 1 ] } ;
t e m p d i s t 1 = ( hcount>=temphcen1 ) ?
( hcount − temphcen1 ) : ( temphcen1 − hcount ) ;
ca ntbeo ne = ( ( tempdist1 > = 1 0 ) | | ( ( vcount − tempvcen1 ) >=10));
reg [ 9 : 0 ]
reg [ 9 : 0 ]
reg
vcen2 , hcen2 ;
vup2 , vdown2 , h l e f t 2 , h r i g h t 2 ;
t w o v a l i d ;
wire
wire
wire
wire
wire [ 9 : 0 ]
up2 = vcount < vup2 ;
down2 = vcount > vdown2 ;
l e f t 2 = hcount < h l e f t 2 ;
r i g h t 2 = hcount > h r i g h t 2 ;
v d i s t 2 = vdown2 − vup2 ;
wire
wire
wire
wire
wire
hdist2 = hright2 − hleft2 ;
tempvcen2 = vup2 + { 0 , v d i s t 2 [ 9 : 1 ] } ;
temphcen2 = h l e f t 2 + { 0 , h d i s t 2 [ 9 : 1 ] } ;
t e m p d i s t 2 = ( hcount>=temphcen2 ) ?
( hcount − temphcen2 ) : ( temphcen2 − hcount ) ;
cantbetwo = ( ( tempdist2 > = 1 0 ) | | ( ( vcount − tempvcen2 ) >=10));
reg [ 5 : 0 ]
validhist ;
wire
v a l i d p i x e l = ( ( ( hcount >9) && ( hcount <628)) &&
( ( vcount >=200) && ( vcount <=479)));
[9:0]
[9:0]
[9:0]
[9:0]
[9:0]
[9:0]
[9:0]
[9:0]
[9:0]
33
wire
newframe = ( ( vcount ==524) && ( hcount ==799));
wire
o n e i s l e f t = ( temphcen1 < temphcen2 ) ;
a lwa ys @ ( po sedg e c l k )
begin
if ( reset )
b e g i n
vcen1 <= 0;
hcen1 <= 0;
vup1 <= 10 ’ d479 ;
vdown1 <= 10 ’d0 ;
h l e f t 1 <= 10 ’ d639 ;
h r i g h t 1 <= 10 ’d0 ;
o n e v a l i d <= 0;
vcen2 <= 0;
hcen2 <= 0;
vup2 <= 10 ’ d479 ;
vdown2 <= 10 ’d0 ;
h l e f t 2 <= 10 ’ d639 ;
h r i g h t 2 <= 10 ’d0 ;
t w o v a l i d <= 0;
v a l i d h i s t <= 4 ’ d0 ;
end
e l s e
begin
v a l i d h i s t <= { v a l i d h i s t [ 4 : 0 ] , v a l i d c o l o r } ;
i f (& ( v a l i d h i s t ) & v a l i d p i x e l ) b e g i n
i f ( ! o n e v a l i d ) b e g i n
o n e v a l i d <= 1;
vup1 <= up1 ? vcount : vup1 ;
vdown1 <= down1 ? vcount : vdown1 ;
h l e f t 1 <= l e f t 1 ? hcount − 4 : h l e f t 1 ;
h r i g h t 1 <= r i g h t 1 ? hcount − 4 : h r i g h t 1 ;
end
e l s e b e g i n
i f ( ca ntbeo ne ) b e g i n
i f ( ! t w o v a l i d | ( t w o v a l i d & ! cantbetwo ) ) b e g i n
t w o v a l i d <= 1;
vup2 <= up2 ? vcount : vup2 ;
vdown2 <= down2 ? vcount : vdown2 ;
h l e f t 2 <= l e f t 2 ? hcount − 4 : h l e f t 2 ;
h r i g h t 2 <= r i g h t 2 ? hcount − 4 : h r i g h t 2 ;
end
end
e l s e b e g i n
o n e v a l i d <= 1;
vup1 <= up1 ? vcount : vup1 ;
vdown1 <= down1 ? vcount : vdown1 ;
34
h l e f t 1 <= l e f t 1 ? hcount − 4 : h l e f t 1 ;
h r i g h t 1 <= r i g h t 1 ? hcount − 4 : h r i g h t 1 ;
end
end
end
i f ( newframe ) b e g i n
vcen1 <= 0;
hcen1 <= 0;
vup1 <= 10 ’ d479 ;
vdown1 <= 10 ’ d0 ;
h l e f t 1 <= 10 ’ d639 ;
h r i g h t 1 <= 10 ’d0 ;
o n e v a l i d <= 0;
vcen2 <= 0;
hcen2 <= 0;
vup2 <= 10 ’ d479 ;
vdown2 <= 10 ’ d0 ;
h l e f t 2 <= 10 ’ d639 ;
h r i g h t 2 <= 10 ’d0 ;
t w o v a l i d <=0;
v a l i d h i s t <= 4 ’ d0 ;
vcenl
hcenl
<=
<=
o n e i s l e f t ? tempvcen1 : tempvcen2 ;
o n e i s l e f t ? temphcen1 : temphcen2 ;
vcenr
hcenr
<=
<=
o n e i s l e f t ? tempvcen2 : tempvcen1 ;
o n e i s l e f t ? temphcen2 : temphcen1 ;
end
end
end
endmodule
35
// p a s s e s t h e x v a l u e o f t h e hand p o s i t i o n s
// and p a s s e s computes a b i n a r y up/down y p o s i t i o n
module s e n d g l o v e h e i g h t ( g l i
input
[ 9 : 0] gli x , gli
o utput [ 9 : 0 ] g l o
x , g r o
o utput
g l o
y , g r o
wire [ 9 : 0 ]
wire
x , g l i y , gri x , gri y , glo x , glo y , gro x , gro y ) ;
y , g r i x , g r i y ;
x ;
y ;
g l o
x , g r o x ;
g l o
y , g r o y ;
pa r a meter
UPDOWNBOUNDARY = 1 0 ’ d350 ;
assign
assign
g l o
x = g l i x ;
g r o
x = g r i x ;
assign
assign
g l o
y = ( g l i y <UPDOWNBOUNDARY) ;
g r o
y = ( g r i y <UPDOWNBOUNDARY) ;
endmodule
36
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / E n g i n e e r : Uzoma A . O r j i
/ / D e s c r i p t i o n : Counter t a k e s an i n p u t c l o c k and send a p u l s e on endcount
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module c o u n t e r ( c l k , r e s e t , e n a b l e ) ;
input clk , r e s e t ;
o utput e n a b l e ;
reg
e n a b l e ;
r e g [ 2 5 : 0 ] co unt ;
pa r a meter
endcount = 3 3 7 4 9 9 9 ;
a lwa ys @ ( po sedg e c l k )
b e g i n
i f ( r e s e t ) b e g i n
co unt <= 26 ’ d0 ;
e n a b l e <=1’b0 ;
end
e l s e i f ( co unt==endcount ) b e g i n
count <=26’d0 ;
e n a b l e <=1’b1 ;
end
e l s e b e g i n
count<=co unt +1;
e n a b l e <=1’b0 ;
end
end
endmodule
37
// c o n t r o l l e r t h a t i n p u t s t h e s e r i a l da ta from t h e ADC and computes t h e 8 b i t s i g n a l
module s e r i a l 2 p a r a l l e l ( c l k , pclk , r e s e t , d a t a i n , RFS , CONVST, dataout , v a l i d ) ;
input clk , pclk ;
input r e s e t ;
input datain ;
i n p u t RFS ;
i n p u t CONVST;
o utput [ 7 : 0 ] da ta o ut ;
o utput
valid ;
reg [ 1 : 0 ]
pa r a meter
pa r a meter
pa r a meter
pa r a meter
s t a t e ;
IDLE = 0 ;
WAITFORRFS = 1 ;
GETDATA = 2 ;
DATAVALID = 3 ;
reg
reg
reg [ 7 : 0 ]
v a l i d ;
o l d s t a t e ;
dataout , datatemp ;
a lwa ys @ ( neg edg e c l k )
b e g i n
i f ( r e s e t ) b e g i n
datatemp <= 8 ’ b0 ;
s t a t e <= IDLE ;
end
e l s e b e g i n
c a s e ( s t a t e )
IDLE :
i f ( !CONVST)
s t a t e <= WAITFORRFS;
e l s e
s t a t e <= IDLE ;
WAITFORRFS:
i f ( ! RFS ) b e g i n
datatemp <= { datatemp [ 6 : 0 ] , d a t a i n } ;
s t a t e <= GETDATA;
end
e l s e
s t a t e <= WAITFORRFS;
GETDATA:
i f ( RFS ) b e g i n
s t a t e <= DATAVALID ;
end
e l s e b e g i n
datatemp <= { datatemp [ 6 : 0 ] , d a t a i n } ;
s t a t e <= GETDATA;
end
DATAVALID:
38
s t a t e <= IDLE ;
e n d c a s e
end
end
a lwa ys @ ( po sedg e p c l k )
b e g i n
o l d s t a t e <= s t a t e ;
v a l i d <=0;
i f ( ( s t a t e == DATAVALID) && ( o l d s t a t e !=DATAVALID ) ) b e g i n
v a l i d <= 1;
dataout <= datatemp ;
end
end
endmodule
39
// sendpunch a v e r a g e s f o u r sa mples from t h e ADC and computes t h e maximum punch d u r i n g
// t h e i n t e r v a l . I t o u t p u t s t h e 2 b i t p u n c h l e v e l
module sendpunch ( c l k , r e f r e s h , d a t a i n , v a l i d i n , p u n c h l e v e l ) ;
input clk ;
input r e f r e s h ;
input [ 7 : 0 ] datain ;
input
validin ;
o utput [ 1 : 0 ] p u n c h l e v e l ;
wire [ 1 : 0 ]
punchlevel ;
reg [ 7 : 0 ]
reg [ 2 : 0 ]
datamax ;
num ;
reg [ 9 : 0 ]
tempsum ;
reg
oldvalidin ;
wire
validedge = ( validin & ! oldvalidin ) ;
wire
update = ( tempsum [ 9 : 2 ] > datamax ) ;
pa r a meter
pa r a meter
pa r a meter
HARDPUNCH = 8 ’ b11111000 ;
MEDPUNCH = 8 ’ b11101100 ;
SOFTPUNCH = 8 ’ b11010000 ;
wire
wire
wire
hard = ( datamax>=HARDPUNCH) ;
med = ( datamax>=MEDPUNCH) ;
s o f t = ( datamax>=SOFTPUNCH) ;
assign
p u n c h l e v e l = hard ? 2 ’ b11 :
med ? 2 ’ b10 :
s o f t ? 2 ’ b01 : 2 ’ b00 ;
a lwa ys @ ( neg edg e c l k )
b e g i n
i f ( r e f r e s h ) b e g i n
num <= 3 ’ b0 ;
datamax <= 8 ’ b0 ;
tempsum <= 10 ’b0 ;
end
e l s e b e g i n
i f ( num==3’b100 ) b e g i n
num <= 3 ’ b0 ;
datamax <= update ? tempsum [ 9 : 2 ] : datamax ;
tempsum <= 10 ’ b0 ;
end
e l s e i f ( v a l i d e d g e ) b e g i n
40
num <= num + 1 ;
tempsum <= tempsum + d a t a i n ;
end
e l s e begin
num <= num ;
tempsum <= tempsum ;
end
end
end
a lwa ys @ ( po sedg e c l k )
o l d v a l i d i n <= v a l i d i n ;
endmodule
41
// p u n c h d e t e c t o r i s t h e top l e v e l module f o r t h e u s e r i n t e r f a c e
// i t c o n t r o l s t h e CONVST t h a t s t a r t s a c o n v e r s i o n f o r t h e ADC
// i t a l s o c o n t r o l s t h e r e f r e s h b i t t h a t c l e a r s t h e sendpunch module
/ / i t o u t p u t s t h e p o s i t i o n s o f t h e hands and t h e p u n c h l e v e l s
module p u n c h d e t e c t o r ( clo ck 2 7 mhz , pclk , s c l k , r e s e t , CONVST, d a t a i n l , RFSl , d a t a i n r , RFSr ,
gli x , gli y , gri x , gri y ,
glo x , glo y , gro x , gro y , punchlevell , punchlevelr ) ;
input
input
input
input
clo ck 2 7 mhz , pclk , r e s e t ;
d a t a i n l , RFSl ;
d a t a i n r , RFSr ;
[ 9 : 0 ] g l i
x , g l i y , g r i x , g r i y ;
o utput
s c l k , CONVST;
o utput [ 9 : 0 ] g l o
x , g r o x ;
o utput
g l o
y , g r o y ;
o utput [ 1 : 0 ] p u n c h l e v e l l , p u n c h l e v e l r ;
reg [ 3 : 0 ]
c l k c o u n t ;
a lwa ys @ ( po sedg e clo ck
2 7 mhz )
c l k c o u n t <= c l k c o u n t + 1 ;
BUFG p i x e l c l o c k b u f ( . I ( c l k c o u n t [ 2 ] ) , . O( s c l k ) ) ;
// s c l k i s 3 . 3 7 5 MHz
wire
s t a r t p u l s e ;
c o u n t e r co unt ( s c l k , r e s e t , s t a r t p u l s e ) ;
defparam
co unt . endcount =
9 0 0 ;
wire
CONVST = ˜ s t a r t p u l s e ;
wire [ 7 : 0 ]
wire
wire [ 7 : 0 ]
wire
d a t a o u t l ;
v a l i d l ;
d a t a o u t r ;
v a l i d r ;
s e r i a l 2 p a r a l l e l s 2 p l ( s c l k , pclk , r e s e t , d a t a i n l , RFSl , CONVST, d a t a o u t l , v a l i d l ) ;
s e r i a l 2 p a r a l l e l s 2 p r ( s c l k , pclk , r e s e t , d a t a i n r , RFSr , CONVST, da ta o utr , v a l i d r ) ;
wire [ 9 : 0 ]
wire
g l o x , g r o x ;
g l o
y , g r o y ;
s e n d g l o v e h e i g h t sgh ( g l i x , g l i y , g r i x , g r i y , g l o x , g l o y , g r o x , g r o y ) ;
wire
r e f r e s h ;
c o u n t e r r e f r e s h e r ( pclk , r e s e t , r e f r e s h ) ;
defparam r e f r e s h e r . endcount =
4 2 0 0 0 0 0 ;
wire [ 1 : 0 ]
punchlevell , punchlevelr ;
sendpunch s p l ( pclk , r e f r e s h , d a t a o u t l , v a l i d l , p u n c h l e v e l l ) ;
42
sendpunch s p r ( pclk , r e f r e s h , da ta o utr , v a l i d r , p u n c h l e v e l r ) ;
endmodule
43
B
Control Unit Source Codes
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
13:45:29 03/19/06
/ / Desig n Name :
/ / Module Name :
controlunit
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n : Major FSM f o r Pong game t h a t a l s o s t o r e s t h e b a l l ’ s p o s i t i o n
//
and v e l o c i t y , t h e paddle ’ s p o s i t i o n , and g r a v i t y w e l l ’ s p o s i t i o n and
//
pulse information .
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module c o n t r o l u n i t ( c l k , r e s e t , s t a r t ,
plx , ply , plp ,
prx , pry , prp ,
p l a y e r l h a n d x , p l a y e r l h a n d y , p l a y e r l h a n d p u n c h ,
p l a y e r
r h a n d x , p l a y e r r h a n d y , p l a y e r r h a n d p u n c h ,
o ppo nent hea d x ,
opponent picture ,
p l a y e r l i f e , o p p o n e n t l i f e ,
p l a y e r
e n e r g y , o ppo nent ener g y ,
t i m e
l e f t , mode , round , game type , s t a t e ,
i n d e x i n , d a t a i n , e n a b l e i n ,
i n d e x
o u t , d a t a o u t , e n a b l e o u t
) ;
// i n p u t s and o u t p u t s
input clk , reset , s t a r t ;
i n p u t [ 9 : 0 ] plx , prx ;
input
ply , pry ;
i n p u t [ 1 : 0 ] plp , prp ;
o utput [ 9 : 0 ] p l a y e r l h a n d x , p l a y e r r h a n d x ;
o utput
player l hand y , player r hand y ;
o utput [ 1 : 0 ] p l a y e r l h a n d p u n c h , p l a y e r r h a n d p u n c h ;
44
o utput [ 9 : 0 ] o p p o n e n t h e a d x ;
o utput [ 4 : 0 ] o p p o n e n t p i c t u r e ,
p l a y e r l i f e , o p p o n e n t l i f e , player energy , opponent energy ;
o utput [ 7 : 0 ] t i m e l e f t ;
o utput [ 1 : 0 ] mode , round , game type ;
o utput [ 2 : 0 ] s t a t e ;
input [ 2 : 0 ] index in ;
input [ 9 : 0 ] data in ;
input e n a b l e i n ;
o utput [ 2 : 0 ] i n d e x o u t ;
o utput [ 9 : 0 ] d a t a o u t ;
o utput e n a b l e o u t ;
// Major FSM da ta
r e g [ 9 : 0 ] p l a y e r l h a n d x , p l a y e r r h a n d x , o p p o n e n t l h a n d x , o p p o n e n t r h a n d x ;
reg
p l a y e r l h a n d y , p l a y e r r h a n d y , o p p o n e n t l h a n d y , o p p o n e n t r h a n d y ;
r e g [ 1 : 0 ] p l a y e r l h a n d
p u n c h , p l a y e r r h a n d p u n c h
, o ppo nent l ha nd punch , o ppo nent r ha nd punch ;
reg [ 9 : 0 ] player head x , opponent head x ;
reg [ 4 : 0 ] player picture , opponent picture ,
p l a y e r l i f e , o p p o n e n t l i f e , player energy , opponent energy ;
reg [ 7 : 0 ] t i m e l e f t ;
r e g endround ;
r e g [ 9 : 0 ] o lx , o r x ;
reg
o ly , o r y ;
r e g [ 1 : 0 ] o lp , orp ;
reg [ 1 : 0 ]
reg [ 1 : 0 ]
reg [ 2 : 0 ]
reg [ 5 : 0 ]
mode , round ;
game type ;
s t a t e ;
e n e r g y p u l s e ;
// o u t p u t s from minor FSMS
w i r e [ 9 : 0 ] t i t l e
l h a n d x , t i t l e r h a n d x ;
wire
title l hand y , title r hand y ;
w i r e [ 1 : 0 ] next mode , n e x t g a m e t y p e ;
wire [ 9 : 0 ] olx in , o r x i n ;
wire
oly in , ory in ;
wire [ 1 : 0 ] olp in , orp in ;
wire [ 9 : 0 ] o l x a i , o r x a i ;
wire
oly ai , ory ai ;
wire [ 1 : 0 ] o l p a i , o r p a i ;
wire [ 9 : 0 ]
wire
wire [ 4 : 0 ]
wire [ 7 : 0 ]
plx in , prx in , ohx in ;
ply in , pry in ;
opic in , plb in , olb in , peb in , oeb in ;
time left in ;
45
wire [ 1 : 0 ] plp in , prp in ;
wire endround in ;
wire
wire
wire
wire
wire
wire
wire
wire
wire
[ 7 : 0] next
[ 9 : 0 ] next
next
[ 1 : 0 ] next
[ 4 : 0 ] next
[ 9 : 0 ] next
next
[ 1 : 0 ] next
[ 4 : 0 ] next
time left ;
player l hand x , next player r hand x , next player head x ;
player l hand y , next player r hand y ;
player l hand punch , next player r hand punch ;
player picture , next opponent life , next player energy ;
opponent l hand x , next opponent r hand x , next opponent head x ;
opponent l hand y , next opponent r hand y ;
opponent l hand punch , next opponent r hand punch ;
opponent picture , n e x t p l a y e r l i f e , next opponent energy ;
wire [ 1 : 0 ] pstate , o s t a t e ;
wire [ 2 : 0 ] index in , index in e , index out , index out su , index out sd , index out gu ,
index out gd ;
wire [ 9 : 0 ] data in , data out , data out u , data out d ;
wire enable in , enable out , enable out u , enable out d ;
wire valid u , v a l i d d ;
//game modes
pa r a meter TITLE = 2 ’ d0 ;
pa r a meter ROUND = 2 ’ d1 ;
pa r a meter REST
= 2 ’ d2 ;
pa r a meter GAMEOVER= 2 ’ d3 ;
//game t y p e s
pa r a meter ONEPLAYER
pa r a meter TWOPLAYERM
pa r a meter TWOPLAYERS
= 2 ’ d0 ;
= 2 ’ d1 ;
= 2 ’ d2 ;
//game s t a t e s
pa r a meter IDLE
pa r a meter STARTGETDATA
pa r a meter WAITGETDATA
pa r a meter STARTCOMPUTE
pa r a meter WAITCOMPUTE
pa r a meter STARTSENDDATA
pa r a meter WAITSENDDATA
=
=
=
=
=
=
= 3 ’ d0 ;
3 ’ d1 ;
3 ’ d2 ;
3 ’ d3 ;
3 ’ d4 ;
3 ’ d5 ;
3 ’ d6 ;
a s s i g n i n d e x
o u t [ 2 : 0 ] = ( game type == TWOPLAYERM) ?
( e n a b l e
o u t ? i n d e x o u t s d [ 2 : 0 ] : i n d e x o u t g u [ 2 : 0 ] ) :
( e n a b l e
o u t ? i n d e x o u t s u [ 2 : 0 ] : i n d e x o u t g d [ 2 : 0 ] ) ;
a s s i g n d a t a o u t [ 9 : 0 ] = ( game type == TWOPLAYERM) ? d a t a o u t d [ 9 : 0 ] : d a t a o u t u [ 9 : 0 ] ;
a s s i g n e n a b l e o u t = ( game type == TWOPLAYERM) ?
( s t a t e==WAITSENDDATA ? e n a b l e o u t d : 1 ’ b0 ) :
( e n a b l e
i n | | s t a t e !=WAITSENDDATA? 1 ’ b0 : e n a b l e o u t u ) ;
// a s s i g n i n d e x i n e = e n a b l e i n ? i n d e x i n : 3 ’ d0 ;
a s s i g n i n d e x i n e = e n a b l e o u t | | ˜ e n a b l e i n ? 3 ’ d0 : i n d e x i n ;
46
// Major / Minor FSM c o n t r o l s
reg t i t l e f s m s t a r t ;
wire t i t l e f s m b u s y ;
reg getuserdata start , senduserdata start ;
wire getuserdata busy , senduserdata busy ;
reg t l f s m s t a r t , pfsm start , ofsm start ;
w i r e t l f s m b u s y , pfsm busy , o fsm busy ;
reg getdispdata start , senddispdata start ;
wire getdispdata busy , senddispdata busy ;
reg p knockouts ;
reg o knockouts ;
reg a i s t a r t ;
wire ai busy ;
// i n t e r f i g h t e r c o n n e c t i o n s
wire [ 6 : 0 ] p l a y e r s t a l l i n c , o p p o n e n t s t a l l i n c ;
wire [ 1 : 0 ] p l a y e r h i t , opponent hit ;
// f i g h t e r t o a i
wire [ 6 : 0 ] p l a y e r s t a l l , o p p o n e n t s t a l l ;
// da ta bus communication
// communication comm( da ta bus , game type ,
// i n d e x i n , d a t a i n , a c k o u t , e n a b l e i n ,
// i n d e x
o u t , d a t a o u t , a c k i n , e n a b l e o u t ) ;
// Minor FSMs
t i t l e f s m t i t l e ( c l k , r e s e t , t i t l e f s m s t a r t , t i t l e f s m b u s y ,
plx , prx , ply , pry , plp , prp ,
t i t l e
l h a n d x , t i t l e r h a n d x , t i t l e l h a n d y , t i t l e r h a n d y ,
next mode , n e x t g a m e t y p e ) ;
t i m e l e ft fs m t l ( clk , reset , t l f s m s t a r t , tlfsm busy , t i m e l e f t , n e x t t i m e l e f t ) ;
fighterfsm
p l a y e r ( c l k , r e s e t , p f s m s t a r t , pfsm busy ,
plx , prx , ply , pry , plp , prp ,
p l a y e r
e n e r g y ,
p l a y e r s t a l l i n c , p l a y e r h i t ,
o p p o n e n t
r h a n d y , o s t a t e , o ppo nent hea d x , o p p o n e n t l i f e ,
n e x t p l a y e r l h a n d x , n e x t p l a y e r r h a n d x ,
n e x t
p l a y e r l h a n d y , n e x t p l a y e r r h a n d y ,
n e x t
p l a y e r l h a n d p u n c h , n e x t p l a y e r r h a n d p u n c h , n e x t p l a y e r h e a d x ,
next player picture , next opponent life , next player energy ,
o p p o n e n t s t a l l i n c , o p p o n e n t h i t ,
p s t a t e , p l a y e r
s t a l l ) ;
47
fighterfsm
opponent ( c l k , r e s e t , o f s m s t a r t , ofsm busy ,
o lx , orx , o ly , ory , o lp , orp ,
o ppo nent
ener g y , o p p o n e n t s t a l l i n c , o p p o n e n t h i t ,
player r hand y , pstate , player head x , p l a y e r l i f e ,
n e x t o p p o n e n t l h a n d x , n e x t o p p o n e n t r h a n d x ,
n e x t
o p p o n e n t l h a n d y , n e x t o p p o n e n t r h a n d y ,
n e x t
o p p o n e n t l h a n d p u n c h , n e x t o p p o n e n t r h a n d p u n c h ,
n e x t o p p o n e n t h e a d x ,
n e x t
o p p o n e n t p i c t u r e , n e x t p l a y e r l i f e , n e x t o p p o n e n t e n e r g y ,
p l a y e r s t a l l i n c ,
p l a y e r
h i t ,
ostate , opponent stall ) ;
a i a i f i g h t e r ( clk , reset , a i s t a r t , ai busy ,
opponent stall , player head x , player l hand x , player r hand x ,
olx ai , orx ai , oly ai , ory ai , olp ai , orp ai );
// w i r e s c l k ;
// r e g [ 3 : 0 ] c l k c o u n t ;
// a lwa ys @ ( po sedg e c l k )
//
c l k c o u n t <= c l k c o u n t + 1 ;
//BUFG p i x e l
c l o c k b u f ( . I ( c l k c o u n t [ 2 ] ) , . O( s c l k ) ) ;
//// c l k i s 3 . 3 7 5 MHz
g e t u s e r d a t a gud ( c l k , r e s e t , g e t u s e r d a t a s t a r t , g e t u s e r d a t a b u s y ,
index in e , data in , enable in , index out gu ,
olx in , orx in , oly in , ory in , olp in , orp in , valid u ) ;
s e n d u s e r d a t a sud ( c l k , r e s e t , s e n d u s e r d a t a s t a r t , s e n d u s e r d a t a b u s y ,
index out su , data out u , enable out u , index in ,
plx , prx , ply , pry , plp , prp ) ;
s e n d d i s p d a t a sdd ( c l k , r e s e t , s e n d d i s p d a t a s t a r t , s e n d d i s p d a t a b u s y ,
index out sd , data out d , enable out d , index in ,
opponent l hand x , opponent r hand x , opponent l hand y ,
o p p o n e n t r h a n d y ,
p l a y e r
h e a d x , p l a y e r p i c t u r e , t i m e l e f t ,
o p p o n e n t l i f e , p l a y e r l i f e , o ppo nent ener g y , p l a y e r e n e r g y ,
o ppo nent l ha nd punch , o ppo nent r ha nd punch , endround ) ;
g e t d i s p d a t a gdd ( c l k , r e s e t , g e t d i s p d a t a s t a r t , g e t d i s p d a t a b u s y ,
i n d e x i n e , d a t a i n , e n a b l e i n , i n d e x o u t g d ,
p l x
i n , p r x i n , p l y i n , p r y i n , o h x i n , o p i c i n ,
t i m e l e f t i n , plb in , olb in , peb in , oeb in , plp in , prp in ,
endr o und in , v a l i d d ) ;
a lwa ys @( po sedg e c l k ) b e g i n
t l f s m s t a r t <= 0;
p f s m
s t a r t
<= 0;
<= 0;
ofsm start
48
ai start
<= 0;
g e t u s e r d a t a s t a r t <= 0;
s e n d u s e r d a t a s t a r t <= 0;
g e t d i s p d a t a s t a r t <= 0;
s e n d d i s p d a t a s t a r t <= 0;
i f ( r e s e t ) begin
t i m e l e f t <= 180;
state
<= IDLE ;
mode
<= TITLE ;
round <=0;
player picture
opponent picture
player life
opponent life
player energy
opponent energy
e n e r g y p u l s e <= 0;
o lx <=300;
orx <=340;
o ly <=1;
ory <=1;
o lp <=0;
orp <=0;
o p p o n e n t l h a n d x <=300;
o p p o n e n t r h a n d x <=1;
o p p o n e n t l h a n d y <=340;
o p p o n e n t r h a n d y <=1;
o ppo nent l ha nd punch <=0;
o ppo nent r ha nd punch <=0;
p l a y e r h e a d x <=0;
o ppo nent hea d x <=0;
endround <=0;
p kno cko uts <=0;
o k n o c k o u t s <=0;
end e l s e b e g i n
c a s e ( mode )
TITLE : b e g i n
case ( state )
IDLE :
i f ( s t a r t ) begin
titlefsm start
<= 1;
s t a t e <= STARTGETDATA;
end e l s e b e g i n
s t a t e <= IDLE ;
end
STARTGETDATA: b e g i n
49
<= 0;
<= 0;
<= 31;
<= 31;
<= 31;
<= 31;
i f ( ˜ t i t l e f s m b u s y ) b e g i n
t i t l e f s m s t a r t <= 1;
s t a t e <= STARTGETDATA;
end e l s e b e g i n
s t a t e <= WAITGETDATA;
end
end
WAITGETDATA:
begin
i f ( t i t l e f s m b u s y ) b e g i n
s t a t e <= WAITGETDATA;
end e l s e b e g i n
p l a y e r
l h a n d x
player r hand x
<= t i t l e l h a n d x ;
<= t i t l e r h a n d x ;
player l hand y
player r hand y
<= t i t l e l h a n d y ;
<= t i t l e r h a n d y ;
mode
game type
<= next mode ;
<= n e x t
g a m e t y p e ;
round <=1;
player l hand punch
p l a y e r
r h a n d p u n c h
p l a y e r
h e a d x
player picture
player energy
player life
olx
orx
oly
ory
olp
orp
<=
<=
<=
<=
<=
<=
<= 0;
<= 0;
<= 320;
<= 0;
<= 31;
<= 31;
300;
340;
1;
1;
0;
0;
opponent l hand x
opponent r hand x
opponent l hand y
o p p o n e n t
r h a n d y
o p p o n e n t
l h a n d p u n c h
o ppo nent
r ha nd punch
o p p o n e n t h e a d
x
opponent picture
opponent energy
opponent life
<=
<=
<=
<=
<= 0;
<= 0;
<= 320;
<= 0;
<= 31;
t i m e l e f t <=180;
/∗ i f ( n e x t g a m e t y p e==TWOPLAYERM) b e g i n
g e t u s e r d a t a s t a r t <= 1;
s t a t e <=STARTGETDATA;
50
300;
340;
1;
1;
<= 31;
end e l s e i f ( n e x t g a m e t y p e==TWOPLAYERS) b e g i n
s e n d u s e r d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end e l s e ∗/
s t a t e <= IDLE ;
// i n i t <=1;
end
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
ROUND: b e g i n
i f ( round ==0) b e g i n
mode<=GAMEOVER;
end e l s e i f ( endround ) b e g i n
mode <=REST ;
round <= round + 1 ;
t i m e
l e f t <= 30;
endround <= 0;
end e l s e
c a s e ( game type )
TWOPLAYERS: b e g i n
// p a s s thr o ug h punch da ta
c a s e ( s t a t e )
IDLE :
i f ( s t a r t ) begin
s e n d u s e r d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end e l s e b e g i n
s t a t e <= IDLE ;
end
STARTSENDDATA: b e g i n
i f (˜ senduserdata busy ) begin
// i f ( ˜ e n a b l e i n )
s e n d u s e r d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end e l s e b e g i n
s t a t e <= WAITSENDDATA;
end
end
WAITSENDDATA : b e g i n
i f ( e n a b l e i n ) begin
g e t d i s p d a t a s t a r t <= 1;
s t a t e <= STARTGETDATA;
end e l s e i f ( s e n d u s e r d a t a b u s y ) b e g i n
s t a t e <= WAITSENDDATA;
end e l s e b e g i n
g e t d i s p d a t a s t a r t <= 1;
s t a t e <= STARTGETDATA;
end
end
51
STARTGETDATA: b e g i n
i f ( ˜ g e t d i s p d a t a b u s y ) b e g i n
g e t d i s p d a t a s t a r t <= 1;
s t a t e <= STARTGETDATA;
end e l s e b e g i n
s t a t e <= WAITGETDATA;
end
end
WAITGETDATA : b e g i n
i f ( g e t d i s p d a t a b u s y ) b e g i n
s t a t e <= WAITGETDATA;
end e l s e b e g i n
i f ( v a l i d d && p l x i n !=0 && p r x
i n !=0
&& p l x i n < p r x i n ) b e g i n
p l a y e r l h a n d x <= p l x i n ;
p l a y e r r h a n d x <= p r x i n ;
p l a y e r l h a n d y <= p l y i n ;
p l a y e r r h a n d y <= p r y i n ;
p l a y e r l h a n d p u n c h <= p l p i n ;
p l a y e r r h a n d p u n c h <= p r p i n ;
o p p o n e n t h e a d x <= o h x i n ;
o p p o n e n t p i c t u r e <= o p i c i n ;
<= t i m e l e f t i n ;
time left
player life
<= p l b i n ;
opponent life
<= o l b i n ;
<= p e b i n ;
p l a y e r
e n e r g y
o p p o n e n t e n e r g y <= o e b
i n ;
endround
<= e n d r o u n d
i n ;
end
s e n d u s e r d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
// s t a t e <= IDLE ;
// s l a v e n e v e r g o e s i d l e
end
end
d e f a u l t : b e g i n
i f ( e n a b l e i n && s t a t e !=WAITGETDATA &&
s t a t e !=STARTGETDATA) b e g i n
g e t d i s p d a t a s t a r t <= 1;
s t a t e <=STARTGETDATA;
end e l s e b e g i n
s e n d u s e r d a t a
s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end
// s t a t e <=IDLE ;
end
endcase
end
d e f a u l t : b e g i n // f o r two p l a y e r m o r s i n g l e p l a y e r
case ( state )
52
IDLE :
i f ( s t a r t ) begin
i f ( game type == ONEPLAYER)
a i s t a r t <= 1;
e l s e g e t u s e r d a t a s t a r t <= 1;
s t a t e <= STARTGETDATA;
end e l s e b e g i n
s t a t e <= IDLE ;
end
STARTGETDATA: b e g i n
i f ( ( game type == TWOPLAYERM && ˜ g e t u s e r d a t a b u s y )
| | ( game type == ONEPLAYER && ˜ a i b u s y ) ) b e g i n
i f ( game type == ONEPLAYER)
a i s t a r t <= 1;
e l s e g e t u s e r d a t a
s t a r t <= 1;
s t a t e <= STARTGETDATA;
end e l s e b e g i n
s t a t e <= WAITGETDATA;
end
end
WAITGETDATA : b e g i n
// f o r c e s c o n t i n u e i f a n o t h e r s t a r t p u l s e o c c u r s
i f ( ( ( game type == TWOPLAYERM && g e t u s e r d a t a b u s y )
| | ( game type == ONEPLAYER && a i b u s y ) )
/∗ && ˜ s t a r t ∗ / ) b e g i n
s t a t e <= WAITGETDATA;
end e l s e b e g i n
i f ( game type == ONEPLAYER && ˜ a i
b u s y ) b e g i n
o l x <= o l x a i ;
o r x <= o r x
a i ;
o l y <= o l y a i ;
o r y <= o r y
a i ;
o l p <= o l p a i ;
orp <= o r p
a i ;
end e l s e i f ( game type == TWOPLAYERM
&& ˜ g e t u s e r d a t a b u s y ) b e g i n
i f ( v a l i d u ) begin
// && o l x i n !=0 && o r x i n !=0 &&
// o l x i n < o r x i n ) begin
o l x <= o l x i n ;
o r x <= o r x
i n ;
o l y <= o l y i n ;
o r y <= o r y
i n ;
o l p <= o l p i n ;
orp <= o r p
i n ;
end
end e l s e b e g i n
/∗ o l x <= 300;
o r x <= 340;
53
o l y <= 1;
o r y <= 1;
o l p <= 0;
orp <= 0;∗/
end
t l f s m s t a r t <= 1;
p f s m
s t a r t <= 1;
o f s m s t a r t <= 1;
e n e r g y p u l s e <= e n e r g y p u l s e + 1 ;
s t a t e <= STARTCOMPUTE;
end
end
STARTCOMPUTE: b e g i n
// s t a r t minor FSM’ s and r e p e a t u n t i l a l l have s t a r t e d
// and have r e p o r t e d t h a t they a r e busy ( i n co mputa tio n )
i f ( ˜ t l f s m b u s y | | ˜ pfsm busy | | ˜ o fsm busy ) b e g i n
t l f s m s t a r t <= 1;
p f s m
s t a r t <= 1;
o f s m s t a r t <= 1;
s t a t e <= STARTCOMPUTE;
end e l s e b e g i n
s t a t e <= WAITCOMPUTE;
end
end
WAITCOMPUTE: b e g i n
// wa it u n t i l a l l minor FSM’ s have f i n i s h e d
/ / c a l c u l a t i n g t h e i r next v a l u e s
i f ( t l f s m b u s y | | pfsm busy | | o fsm busy ) b e g i n
s t a t e <= WAITCOMPUTE;
end e l s e b e g i n / / i f f i n i s h e d update next v a l u e s
/ / and wa it u n t i l next co mputa tio n
t i m e
l e f t <= n e x t t i m e l e f t ;
player l hand x
<= n e x t p l a y e r l h a n d x ;
player r hand x
<= n e x t p l a y e r r h a n d x ;
player l hand y
<= n e x t p l a y e r l h a n d y ;
<= n e x t p l a y e r r h a n d y ;
player r hand y
p l a y e r l h a n d p u n c h <= n e x t p l a y e r l h a n d p u n c h ;
<= n e x t p l a y e r r h a n d p u n c h ;
player r hand punch
player head x
<= 640 − n e x t p l a y e r h e a d x ;
p l a y e r p i c t u r e <= n e x t p l a y e r p i c t u r e ;
p l a y e r
e n e r g y <=
n e x t p l a y e r e n e r g y + &( e n e r g y p u l s e ) >= 31 ?
3 1 : n e x t
p l a y e r e n e r g y + &( e n e r g y p u l s e ) ;
p l a y e r l i f e <= n e x t p l a y e r l i f e ;
opponent
opponent
opponent
opponent
54
l
r
l
r
hand
hand
hand
hand
x
x
y
y
<=
<=
<=
<=
next
next
next
next
opponent
opponent
opponent
opponent
l
r
l
r
hand
hand
hand
hand
x;
x;
y;
y;
o ppo nent l ha nd punch <= n e x t o p p o n e n t l h a n d p u n c h ;
o ppo nent r ha nd punch <= n e x t o p p o n e n t r h a n d p u n c h ;
o ppo nent hea d x <= 640 − n e x t o p p o n e n t h e a d x ;
opponent picture
<= n e x t o p p o n e n t p i c t u r e ;
o p p o n e n t e n e r g y <=
( n e x t o p p o n e n t e n e r g y + &( e n e r g y p u l s e )) > = 3 1 ?
3 1 : n e x t o p p o n e n t e n e r g y + &( e n e r g y p u l s e ) ;
opponent life
<= n e x t o p p o n e n t l i f e ;
i f ( t i m e l e f t = = 0 ||
o p p o n e n t l i f e < n e x t o p p o n e n t l i f e | |
o p p o n e n t l i f e < n e x t o p p o n e n t l i f e ) b e g i n
if ( player life < next player life )
p kno cko uts<=p k n o c k o u t s +1;
i f ( opponent life < next opponent life )
o k n o c k o u t s<=o k n o c k o u t s +1;
endround <=1;
end
i f ( game type==ONEPLAYER)
s t a t e <=IDLE ;
e l s e begin
s e n d d i s p d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end
end
end
STARTSENDDATA: b e g i n
i f (˜ senddispdata busy ) begin
s e n d d i s p d a t a s t a r t <= 1;
s t a t e <= STARTSENDDATA;
end e l s e b e g i n
s t a t e <= WAITSENDDATA;
end
end
WAITSENDDATA : b e g i n
/∗ i f ( s t a r t ) b e g i n
s e n d d i s p d a t a s t a r t <= 1;
end e l s e ∗ / i f ( s e n d d i s p d a t a b u s y /∗ && ˜ s t a r t ∗ / )
begin
s t a t e <= WAITSENDDATA;
end e l s e b e g i n
s t a t e <= IDLE ;
end
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
endcase
end
REST : b e g i n
55
case ( state )
IDLE : b e g i n
i f ( s t a r t ) begin
t l f s m s t a r t <= 1;
s t a t e <= STARTCOMPUTE;
end e l s e b e g i n
s t a t e <= IDLE ;
end
end
STARTCOMPUTE: b e g i n
i f ( ˜ t l f s m b u s y ) b e g i n
t l f s m s t a r t <= 1;
s t a t e <= STARTCOMPUTE;
end e l s e b e g i n
s t a t e <= WAITCOMPUTE;
end
end
WAITCOMPUTE: b e g i n
t i m e
l e f t <= n e x t t i m e l e f t ;
p l a y e r
l h a n d p u n c h
p l a y e r
r h a n d p u n c h
p l a y e r
h e a d x
player picture
player energy
player life
olx
orx
oly
ory
olp
orp
<=
<=
<=
<=
<=
<=
<= 0;
<= 0;
<= 320;
<= 0;
<= 31;
<= 31;
300;
340;
1;
1;
0;
0;
opponent l hand x
opponent r hand x
opponent l hand y
opponent r hand y
o p p o n e n t l h a n d p u n c h <= 0;
o ppo nent
r ha nd punch <= 0;
o p p o n e n t h e a d
x
opponent picture
opponent energy
opponent life
<=
<=
<=
<=
<= 320;
<= 0;
<= 31;
i f ( t i m e l e f t ==0|| n e x t t i m e l e f t ==0) b e g i n
mode<=ROUND;
t i m e
l e f t <=180;
end
s t a t e <=IDLE ;
end
56
300;
340;
1;
1;
<= 31;
d e f a u l t : s t a t e <=IDLE ;
endcase
end
GAMEOVER: b e g i n
// done
end
endcase
end
end
endmodule
57
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
/ / E n g i n e e r :
//
/ / Cr ea te Date :
1 7 : 4 4 : 0 5 0 4 / 2 3 / 0 6
/ / Desig n Name :
/ / Module Name :
f i g h t e r f s m
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n :
//
/ / Dependencies :
//
/ / R e v i s i o n :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module f i g h t e r f s m ( c l k , r e s e t , s t a r t , busy ,
l h a n d x , r ha nd x , l h a n d y , r ha nd y , l ha nd punch , r hand punch ,
ener g y , s t a l l i n c , h i t ,
op hand y , o p
s t a t e , o p hea d x , o p l i f e ,
next l hand x , next r hand x , next l hand y , next r hand y ,
n e x t l h a n d p u n c h , n e x t r h a n d p u n c h , n e x t h e a d x ,
p i c t u r e , n e x t
o p l i f e , n e x t e n e r g y , o p s t a l l i n c , o p h i t ,
state , s t a l l ) ;
input
input
input
input
input
input
input
input
input
clk , reset , s t a r t ;
[ 9 : 0 ] l h a n d x , r ha nd x , o p h e a d x ;
l h a n d y , r ha nd y , o p ha nd y ;
[ 1 : 0 ] l ha nd punch , r ha nd punch ;
[ 4 : 0 ] energy ;
[ 1 : 0 ] op state ;
[4:0] op life ;
[6:0] stall inc ;
[ 1 : 0 ] hit ;
o utput busy ;
o utput [ 9 : 0 ]
next l hand x , next r hand x , next head x ;
o utput
next l hand y , next r hand y ;
o utput [ 1 : 0 ]
next l hand punch , next r hand punch ;
o utput [ 4 : 0 ] p i c t u r e , n e x t o p l i f e , n e x t e n e r g y ;
o utput [ 1 : 0 ] s t a t e ;
o utput [ 6 : 0 ] o p s t a l l i n c ;
o utput [ 1 : 0 ] o p h i t ;
o utput [ 6 : 0 ] s t a l l ;
reg fsmstate ;
58
reg [ 1 : 0 ] state ;
r e g busy ;
reg [ 9 : 0 ]
next l hand x , next r hand x , next head x ;
reg
next l hand y , next r hand y ;
reg [ 1 : 0 ]
next l hand punch , next r hand punch ;
reg [ 4 : 0 ] picture , n e x t o p l i fe , next energy ;
reg [ 1 : 0 ] lrpunch ;
r e g [ 9 : 0 ] punch x ;
reg
punch y ;
reg [ 1 : 0 ] punch str ;
reg [ 6 : 0 ] s t a l l ;
reg [ 6 : 0 ] combostall ;
reg [ 6 : 0 ] o p s t a l l i n c ;
reg [ 1 : 0 ] op hit ;
r e g impact ;
pa r a meter IDLE = 1 ’ b0 ;
pa r a meter ACTIVE= 1 ’ b1 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
STAND =2 ’d0 ;
BLOCK =2 ’d1 ;
PUNCH =2 ’d2 ;
RECOIL
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
STANDING00
STANDING01
STANDING10
STANDING11
BLOCKING0
BLOCKING1
LJAB
RJAB
LBODY
RBODY
LHOOK
RHOOK
LHOOKLOW
RHOOKLOW
LCROSS
RCROSS
LUPPER
RUPPER
BOTHLOW
BOTHHIGH
LRECOIL
RRECOIL
BOTHRECOIL
HITLEFT
HITRIGHT
HITLOW
=2 ’d3 ;
=
=
=
=
=
=
0;
1;
2;
3;
4;
5;
= 6;
= 7;
=
=
=
=
=
=
8;
9;
10;
11;
12;
13;
=
=
=
=
=
14;
15;
16;
17;
18;
= 19;
= 20;
= 21;
= 22;
= 23;
= 24;
= 25;
59
a lwa ys @ ( po sedg e c l k ) b e g i n
i f ( r e s e t ) b e g i n
s t a t e <= STAND;
lr punch <=0;
s t a l l <= 0;
o p s t a l l i n c <=0;
impact <= 0;
busy <=0;
n e x t
e n e r g y <= e n e r g y ;
n e x t
o p l i f e <= o p l i f e ;
n e x t o p l i f e <= 31;
n e x t l h a n d x <= 300;
n e x t r h a n d x <= 340;
n e x t l h a n d y <= 0;
n e x t r h a n d y <= 0;
n e x t l h a n d p u n c h <= 0;
n e x t r h a n d p u n c h <= 0;
n e x t h e a d x <= 320;
o p h i t <=0;
end e l s e b e g i n
c a s e ( f s m s t a t e )
IDLE : b e g i n
i f ( s t a r t ) begin
busy <=1;
f s m s t a t e<=ACTIVE ;
end e l s e b e g i n
busy <=0;
f s m s t a t e<=IDLE ;
end
end
ACTIVE : b e g i n
s t a l l <= s t a l l + s t a l l i n c ;
case ( hit )
2 ’ b00 : b e g i n p i c t u r e<=p i c t u r e ; end
2 ’ b01 : b e g i n p i c t u r e<=HITRIGHT ; end
2 ’ b10 : b e g i n p i c t u r e<=HITLEFT ; end
2 ’ b11 : b e g i n p i c t u r e<=HITLOW; end
endcase
case ( state )
STAND: b e g i n
n e x t e n e r g y <= e n e r g y ;
n e x t o p l i f e <= o p l i f e ;
o p h i t <=0;
n e x t l h a n d x <= l h a n d x ;
n e x t r h a n d x <= r h a n d x ;
n e x t l h a n d y <= l h a n d y ;
n e x t r h a n d y <= r h a n d y ;
n e x t l h a n d p u n c h <= l h a n d p u n c h ;
n e x t r h a n d p u n c h <= r ha nd punch ;
60
n e x t h e a d x <= (( l h a n d x > >1) + ( r ha nd x > >1));
// s t a l l <= 0;
i f ( s t a l l >0) b e g i n / / might want t o move b e f o r e da ta upda tes
s t a l l <= s t a l l − 1 ;
s t a t e <= STAND;
// i f punch i n i t i a t e d
end e l s e i f ( ( l h a n d p u n c h > 0 && e n e r g y >= l h a n d p u n c h )
| | ( r ha nd punch > 0 && e n e r g y >= r ha nd punch )
| | ( l h a n d p u n c h > 0 && r ha nd punch > 0
&& e n e r g y >= l h a n d p u n c h + r ha nd punch ) )
b e g i n
s t a t e <= PUNCH;
s t a l l <= 7 ’ d20 ;
i f ( r ha nd punch = = 0 ) b e g i n / / l e f t punch
lr punch <=2’b10 ;
punch
x <= l h a n d x ;
punch y <= l
h a n d y ;
p u n c h
s t r <=l h a n d p u n c h ;
c a s e ( l
h a n d p u n c h )
/ / 2 ’ b00 : not p o s s i b l e
2 ’ b01 : b e g i n p i c t u r e <= l
h a n d y ? LJAB :LBODY; end
2 ’ b10 : b e g i n p i c t u r e <= l h a n d y ? LHOOK:LHOOKLOW; end
2 ’ b11 : b e g i n p i c t u r e <= l h a n d y ? LCROSS:LUPPER; end
endcase
// r i g h t punch
end e l s e i f ( l h a n d p u n c h ==0) b e g i n
lr punch <=2’b01 ;
punch x <= r h a n d x ;
punch y <= r
h a n d y ;
p u n c h
s t r <=r ha nd punch ;
c a s e ( r
ha nd punch )
/ / 2 ’ b00 : not p o s s i b l e
2 ’ b01 : b e g i n p i c t u r e <= r
h a n d y ? RJAB:RBODY; end
2 ’ b10 : b e g i n p i c t u r e <= r h a n d y ? RHOOK:RHOOKLOW; end
2 ’ b11 : b e g i n p i c t u r e <= r h a n d y ? RCROSS :RUPPER; end
endcase
end e l s e b e g i n
// someone t h i n k s you punch with both hands
lr punch <=2’b11 ;
punch x <= (( r ha nd x > >1) + ( l h a n d x > >1));
punch y <= r
h a n d y ;
p u n c h
s t r <=(( r hand punch > >1) + ( l ha nd punch > >1));
p i c t u r e <= r h a n d y ? BOTHHIGH:BOTHLOW;
end
// i f b l o c k i n i t i a t e d
end e l s e i f ( l h a n d x > r h a n d x − 128
&& ˜( l
h a n d y ˆ r h a n d y ) ) b e g i n
s t a t e <= BLOCK;
s t a l l <= 7 ’ d0 ;
p i c t u r e <= r
h a n d y ? BLOCKING1: BLOCKING0;
end e l s e b e g i n
s t a t e <= STAND;
61
c a s e ( { l h a n d y , r h a n d y } )
2 ’ b00 : b e g i n p i c t u r e <=
2 ’ b01 : b e g i n p i c t u r e <=
2 ’ b10 : b e g i n p i c t u r e <=
2 ’ b11 : b e g i n p i c t u r e <=
endcase
STANDING00 ;
STANDING01 ;
STANDING10 ;
STANDING11 ;
end
end
end
end
end
end / /STAND
BLOCK: b e g i n
n e x t e n e r g y <= e n e r g y ;
n e x t
o p l i f e <= o p l i f e ;
n e x t
l h a n d x <= l h a n d x ;
n e x t
r h a n d x <= r h a n d x ;
n e x t
l h a n d y <= l h a n d y ;
n e x t
r h a n d y <= r h a n d y ;
n e x t
l h a n d p u n c h <= l h a n d p u n c h ;
n e x t r
h a n d p u n c h <= r ha nd punch ;
n e x t
h e a d x <= (( l h a n d x > >1) + ( r ha nd x > >1));
p i c t u r e <= r
h a n d y ? BLOCKING1: BLOCKING0;
i f ( s t a l l >0) b e g i n
s t a l l <= s t a l l − 1 ;
s t a t e <=BLOCK;
end e l s e i f ( l h a n d x > r h a n d x − 128
&& ˜( l h a n d y ˆ r h a n d y )
&& l h a n d p u n c h==0 && r ha nd punch ==0) b e g i n
s t a t e <= BLOCK;
end e l s e b e g i n
c a s e ( { l
h a n d y , r h a n d y } )
2 ’ b00 : b e g i n p i c t u r e <= STANDING00 ; end
2 ’ b01 : b e g i n p i c t u r e <= STANDING01 ; end
2 ’ b10 : b e g i n p i c t u r e <= STANDING10 ; end
2 ’ b11 : b e g i n p i c t u r e <= STANDING11 ; end
endcase
s t a t e <= STAND;
end
end / /BLOCK
PUNCH: b e g i n
n e x t e n e r g y <= e n e r g y ;
n e x t
o p l i f e <= o p l i f e ;
o p h i t <= 0;
i f ( ˜ impact ) b e g i n
i f ( o p
h e a d x > punch x − 50 && o p h e a d x < punch x + 50 &&
˜ ( o p s t a t e==BLOCK && o p ha nd y == punch y ) ) b e g i n
n e x t o p l i f e <= o p l i f e − p u n c h s t r ;
case ( punch str )
2 ’ b01 : b e g i n o p s t a l l i n c <= 7 ’ d15 ; end
2 ’ b10 : b e g i n o p s t a l l i n c <= 7 ’ d25 ; end
2 ’ b11 : b e g i n o p s t a l l i n c <= 7 ’ d35 ; end
endcase
o p h i t <= ( punch y = = 0 ) ? 2 ’ b11 : l r p u n c h ;
62
end
n e x t
e n e r g y <= e n e r g y − p u n c h s t r ;
impact <= 1;
end e l s e b e g i n
i f ( s t a l l >0) b e g i n
s t a l l <= s t a l l − 1 ;
s t a t e <=PUNCH;
end e l s e b e g i n
impact <= 0;
c a s e ( p u n c h s t r )
/ / 2 ’ b00 : b e g i n s t a l l <= ; c o m b o s t a l l < =
2 ’ b01 : b e g i n s t a l l <= 7 ’ d20 ; c o m b o s t a l l
2 ’ b10 : b e g i n s t a l l <= 7 ’ d40 ; c o m b o s t a l l
2 ’ b11 : b e g i n s t a l l <= 7 ’ d60 ; c o m b o s t a l l
endcase
case ( lrpunch )
/ / 2 ’ b00 : not p o s s i b l e
2 ’ b01 : b e g i n p i c t u r e <= RRECOIL ; end
2 ’ b10 : b e g i n p i c t u r e <= LRECOIL ; end
2 ’ b11 : b e g i n p i c t u r e <= BOTHRECOIL; end
e n d c a s e
s t a t e <= RECOIL ;
end
end
; end
<= 7 ’ d10 ; end
<= 7 ’ d20 ; end
<= 7 ’ d30 ; end
end
RECOIL : b e g i n
n e x t e n e r g y <= e n e r g y ;
n e x t
o p l i f e <= o p l i f e ;
i f ( s t a l l >0) b e g i n
s t a l l <= s t a l l − 1 ;
// i f ha lfwa y thr o ug h r e c o i l check f o r combo
i f ( c o m b o s t a l l >= s t a l l &&
(
// j a b /body−>o p p o s i t e a n y t h i n g
( p u n c h
s t r==1 &&
(
( l r p u n c h ==2’b10 && l h a n d p u n c h==0
&& r hand punch >0)
||
( l r p u n c h ==2’b01 && l ha nd punch >0
&& r ha nd punch==0)
)
)
||
// c r o s s −>o p p o s i t e hook
// hook−>o p p o s i t e hook
(
( p u n c h s t r = = 2 | | ( p u n c h s t r ==3 && punch y == 0))
&& (
( l r p u n c h ==2’b10 && l h a n d p u n c h==0
63
&& r ha nd punch==2)
||
( l r p u n c h ==2’b01 && l h a n d p u n c h==2
&& r ha nd punch==0)
)
)
||
// hook−>o p p o s i t e upper
(
( p u n c h s t r ==2 && punch y==1) &&
(
( l r p u n c h ==2’b10 && l h a n d p u n c h==0 &&
r ha nd punch==3 && r h a n d y==0)
||
( l r p u n c h ==2’b01 && l h a n d p u n c h==3 &&
r ha nd punch==0 && l h a n d y ==0)
)
)
)
) begin
s t a l l <=7’d0 ;
c o m b o s t a l l <=7’d0 ;
case ({ l hand y , r hand y })
2 ’ b00 : b e g i n p i c t u r e <= STANDING00 ; end
2 ’ b01 : b e g i n p i c t u r e <= STANDING01 ; end
2 ’ b10 : b e g i n p i c t u r e <= STANDING10 ; end
2 ’ b11 : b e g i n p i c t u r e <= STANDING11 ; end
e n d c a s e
s t a t e <= STAND;
end e l s e
s t a t e <=RECOIL ;
end e l s e b e g i n
c a s e ( { l
h a n d y , r h a n d y } )
2 ’ b00 : b e g i n p i c t u r e <= STANDING00 ; end
2 ’ b01 : b e g i n p i c t u r e <= STANDING01 ; end
2 ’ b10 : b e g i n p i c t u r e <= STANDING10 ; end
2 ’ b11 : b e g i n p i c t u r e <= STANDING11 ; end
e n d c a s e
s t a t e <= STAND;
end
end
d e f a u l t : s t a t e <= STAND;
e n d c a s e / / s t a t e
busy <=0;
f s m s t a t e<=IDLE ;
end
d e f a u l t : f s m s t a t e<=IDLE ;
64
endcase // fsmstate
end
end
endmodule
65
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
/ / E n g i n e e r :
//
/ / Cr ea te Date :
2 2 : 5 8 : 2 6 0 5 / 0 1 / 0 6
/ / Desig n Name :
/ / Module Name :
a i
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n :
//
/ / Dependencies :
//
/ / R e v i s i o n :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module a i ( c l k , r e s e t , s t a r t , busy ,
f i g h t e r s t a l l , pl head x , p l l x , pl r x ,
lpx , rpx , lpy , rpy , lpp , rpp ) ;
input clk , reset , s t a r t ;
input [ 9 : 0 ] pl head x , p l l x , p l r x ;
input [ 6 : 0 ] f i g h t e r s t a l l ;
o utput busy ;
o utput [ 9 : 0 ] lpx , rpx ;
o utput
lpy , rpy ;
o utput [ 1 : 0 ] lpp , rpp ;
// o utput [ 9 : 0 ] x ;
r e g busy ;
r e g [ 9 : 0 ] lpx , rpx ;
reg
lpy , rpy ;
r e g [ 1 : 0 ] lpp , rpp ;
reg [ 9 : 0 ] x , xdst ;
reg [ 1 : 0 ] state ;
reg [ 7 : 0 ] counter ;
r e g [ 1 : 0 ] movedelay ;
reg [ 5 : 0 ] l o f f s e t , r o f f s e t ;
wire [ 1 5 : 0 ] d e c i s i o n ;
w i r e [ 1 5 : 0 ] mo vedist ;
wire [ 1 5 : 0 ] punchstr ;
66
w i r e [ 1 5 : 0 ] hands ;
reg e n a b l e d e c i s i o n , enable movedist ,
l f s r decision
l f s r movedist
l f s r punchstr
lfsr
ha nds
p r n g ( clk
prng ( clk
prng ( clk
pr ng ( c l k
,
,
,
,
reset
reset
reset
reset
,
,
,
,
16
16
16
16
e n a b l e p u n c h s t r , e n a b l e h a n d s ;
’ d1092 , e n a b l e d e c i s i o n
’ d30541 , e n a b l e m o v e d i s t
’ d2141 , e n a b l e p u n c h s t r
’ d112
,
enable hands
pa r a meter DECISIONRATE = 6 4 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
IDLE
= 2 ’ d0 ;
DECISION = 2 ’ d1 ;
MOVE
= 2 ’ d2 ;
PUNCH = 2 ’ d3 ;
// d e c i s i o n −making
0 −65535
pa r a meter MOVETHRESH = 4 0 0 0 0 ;
pa r a meter PUNCHTHRESH = 0 ;
// pa r a meter DONOTHING
//movement
pa r a meter MOVELEFT
pa r a meter MOVERIGHT
pa r a meter MOVECLOSER
pa r a meter MOVEAWAY
=
=
=
=
// punches
pa r a meter WEAK
pa r a meter MEDIUM
// pa r a meter STRONG
= 3 0 0 0 0 ;
= 2 0 0 0 0 ;
=
// hands
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
=
=
=
=
=
=
FACEBLOCK
BODYBLOCK
FACEOPEN
BODYOPEN
LUPRDOWN
RUPLDOWN
5 5 5 3 5 ;
4 5 5 3 5 ;
2 0 0 0 0 ;
1 5 0 0 0 ;
5 0 0 0 0 ;
4 0 0 0 0 ;
3 0 0 0 0 ;
2 0 0 0 0 ;
1 5 0 0 0 ;
1 0 0 0 0 ;
a lwa ys @( po sedg e c l k ) b e g i n
e n a b l e d e c i s i o n <=0;
e n a b l e m o v e d i s t <=0;
e n a b l e p u n c h s t r <=0;
e n a b l e h a n d s <=0;
lpp <=0;
rpp <=0;
i f ( r e s e t ) begin
l p x <=10 ’d220 ;
rpx <=10 ’d420 ;
67
, decision );
, mo vedist ) ;
, punchstr ) ;
,
hands ) ;
l p y <=1’d1 ;
rpy <=1’d1 ;
l p p <=2’d0 ;
rpp <=2’d0 ;
busy <=0;
s t a t e <=0;
co unter <=0;
movedelay <=0;
x<=320;
x d s t <= 320;
l o f f s e t <=50;
r o f f s e t <=50;
end e l s e b e g i n
c a s e ( s t a t e )
IDLE : b e g i n
i f ( s t a r t ) b e g i n
i f ( f i g h t e r
s t a l l ==0) b e g i n
c o u n t e r <= c o u n t e r + 1 ;
movedelay <= movedelay + 1 ;
end
busy <= 1;
s t a t e <=DECISION ;
end e l s e b e g i n
busy <=0;
s t a t e <=IDLE ;
end
end
DECISION : b e g i n
i f (&( movedelay ) ) b e g i n
i f ( x d s t > x ) x <= x + 1 ;
e l s e i f ( x d s t < x ) x <= x − 1 ;
end
l p x <= x − l o f f s e t ;
rpx <= x + r o f f s e t ;
if
( x>p l l x&&x−p l l x < 5 0 | |
x<p l l x&&p l l x −x < 5 0 | |
x>p l r x&&x−p l r x < 5 0 | |
x<p l r x&&p l r x −x < 5 0 ) b e g i n
i f ( hands > 2 0 0 0 0 ) b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 1;
rpy <= 1;
end e l s e b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 0;
rpy <= 0;
68
end
end e l s e i f ( hands > FACEBLOCK) b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 1;
rpy <= 1;
end e l s e i f ( hands > BODYBLOCK) b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 0;
rpy <= 0;
end e l s e i f ( hands > FACEOPEN) b e g i n
l o f f s e t <= 100;
r o f f s e t <= 100;
l p y <= 1;
rpy <= 1;
end e l s e i f ( hands > BODYOPEN) b e g i n
l o f f s e t <= 100;
r o f f s e t <= 100;
l p y <= 0;
rpy <= 0;
end e l s e i f ( hands > LUPRDOWN) b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 1;
rpy <= 0;
end e l s e i f ( hands > RUPLDOWN) b e g i n
l o f f s e t <= 50;
r o f f s e t <= 50;
l p y <= 0;
rpy <= 1;
end e l s e b e g i n
end
i f ( c o u n t e r==DECISIONRATE) b e g i n
c o u n t e r <= 0;
e n a b l e h a n d s <= 1;
e n a b l e d e c i s i o n <= 1;
busy <=1;
i f ( d e c i s i o n > MOVETHRESH) b e g i n
e n a b l e d e c i s i o n <= 1;
e n a b l e m o v e d i s t <=1;
s t a t e <= MOVE;
end e l s e i f ( d e c i s i o n > PUNCHTHRESH /∗&&
( x>p l h e a d x&&(x−p l h e a d x <64))
| | ( x<p l h e a d x&&(p l h e a d x −x < 6 4 ) ) ∗ / ) b e g i n
e n a b l e p u n c h s t r <=1;
s t a t e <= PUNCH;
end e l s e b e g i n
busy <=0;
69
s t a t e <= IDLE ;
end
end e l s e b e g i n
busy <=0;
s t a t e <= IDLE ;
end
end
MOVE: b e g i n
busy <=0;
movedelay <=0;
s t a t e <= IDLE ;
e n a b l e d e c i s i o n <= 1;// f o r next d e c i s i o n
i f ( d e c i s i o n > MOVELEFT) b e g i n
if
( x > 1 2 8 + mo vedist [ 5 : 0 ] )
x d s t <= x − mo vedist [ 5 : 0 ] ;
e l s e x d s t <= 128;
end e l s e i f ( d e c i s i o n > MOVERIGHT) b e g i n
if
( x < 512 − mo vedist [ 5 : 0 ] )
x d s t <= x + mo vedist [ 5 : 0 ] ;
e l s e x d s t <= 512;
end e l s e i f ( d e c i s i o n > MOVECLOSER) b e g i n
i f ( x > pl head x ) begin
i f (x > pl head x + 64)
x d s t <= x − mo vedist [ 5 : 0 ] ;
e l s e x d s t <= p l h e a d x ;
end e l s e b e g i n
i f ( x < pl head x − 64)
x d s t <= x + mo vedist [ 5 : 0 ] ;
e l s e x d s t <= p l h e a d x ;
end
end e l s e i f ( d e c i s i o n > MOVEAWAY) b e g i n
i f ( x > pl head x ) begin
if
( x < 512 − mo vedist [ 5 : 0 ] )
x d s t <= x + mo vedist [ 5 : 0 ] ;
e l s e x d s t <= 512;
end e l s e b e g i n
if
( x > 1 2 8 + mo vedist [ 5 : 0 ] )
x d s t <= x − mo vedist [ 5 : 0 ] ;
e l s e x d s t <= 128;
end
end e l s e b e g i n
xdst<=x ;
end
end
PUNCH: b e g i n
xdst<=x ;
busy <=0;
s t a t e <= IDLE ;
i f ( p u n c h s t r > WEAK) b e g i n
i f ( punchstr [ 0 ] ) begin
70
l p y <= p u n c h s t r [ 1 0 ] ;
l p p <= 1;
end e l s e b e g i n
rpy <= p u n c h s t r [ 1 0 ] ;
rpp <= 1;
end
end e l s e i f ( p u n c h s t r > MEDIUM) b e g i n
i f ( punchstr [ 0 ] ) begin
l p y <= p u n c h s t r [ 1 0 ] ;
l p p <= 2;
end e l s e b e g i n
rpy <= p u n c h s t r [ 1 0 ] ;
rpp <= 2;
end
end e l s e b e g i n
i f ( punchstr [ 0 ] ) begin
l p y <= p u n c h s t r [ 1 0 ] ;
l p p <= 3;
end e l s e b e g i n
rpy <= p u n c h s t r [ 1 0 ] ;
rpp <= 3;
end
end
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
end
endmodule
71
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
13:54:01 05/03/06
/ / Desig n Name :
/ / Module Name :
communication
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module communication ( bus , game type ,
get index , get data , get ack , get enable ,
s e n d i n d e x , s e n d d a t a , send a ck , s e n d e n a b l e ) ;
// i n p u t c l k , r e s e t ;
i n p u t [ 1 : 0 ] game type ;
i n o u t [ 1 5 : 0 ] bus ;
o utput [ 2 : 0 ] g e t i n d e x ;
o utput [ 9 : 0 ] g e t d a t a ;
input get ack ;
o utput g e t e n a b l e ;
input [ 2 : 0 ] send index ;
input [ 9 : 0 ] send data ;
o utput s e n d a c k ;
input send enable ;
//game t y p e s
pa r a meter ONEPLAYER
pa r a meter TWOPLAYERM
pa r a meter TWOPLAYERS
= 2 ’ d0 ;
= 2 ’ d1 ;
= 2 ’ d2 ;
// da ta p i n s
// bus a d d r e s s
da ta
12:3
index
15:13
m ena ble
1
ack
2
s enable
0
w i r e g e t a c k o v e r r i d e ;
a s s i g n g e t a c k o v e r r i d e = ˜ s e n d e n a b l e && ˜ g e t e n a b l e ? 1 ’ hZ : g e t a c k ;
72
w i r e s l a v e b a c k o u t ;
a s s i g n s l a v e b a c k o u t = ( game type==TWOPLAYERM | | ( game type==TWOPLAYERS && ˜ g e t e n a b l e ) ) ;
a s s i g n bus [ 1 5 : 2 ] = ( / / game type !=TWOPLAYERM && game type !=TWOPLAYERS) ? 1 4 ’ hZ : (
( s e n d e n a b l e && s l a v e b a c k o u t )
}
? { s e n d
i n d e x [ 2 : 0 ] , s e n d d a t a [ 9 : 0 ] , 1 ’ hZ
: { 3 ’ hZ , 1 0 ’ hZ , g e t a c k }// o v e r r i d e }
);
a s s i g n bus [ 1 : 0 ] = ( / / game type !=TWOPLAYERM && game type !=TWOPLAYERS) ? 2 ’ hZ : (
( game type==TWOPLAYERM) ? (
/∗ ma ster ∗/
{ s e n d
e n a b l e , 1 ’ hZ}
) : (
/∗ s l a v e ∗/
{ 1 ’ hZ , s e n d
e n a b l e }
)
);
a s s i g n { g e t i n d e x [ 2 : 0 ] , g e t d a t a [ 9 : 0 ] , s e n d a c k } = bus [ 1 5 : 2 ] ;
a s s i g n g e t e n a b l e = ( game type==TWOPLAYERM) ? bus [ 0 ] : bus [ 1 ] ;
endmodule
73
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
18:21:01 04/30/06
/ / Desig n Name :
/ / Module Name :
getuserdata
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module g e t d i s p d a t a ( c l k , r e s e t , s t a r t , busy , index , data , e n a b l e , ack ,
plx , prx , ply , pry , ohx , o p i c , t i m e l e f t , plb , o lb , peb , oeb , plp ,
prp , endround , v a l i d ) ;
input clk , reset , start , enable ;
input [ 2 : 0 ] index ;
o utput busy ;
o utput [ 2 : 0 ] ack ;
o utput v a l i d ;
i n p u t [ 9 : 0 ] da ta ;
o utput [ 9 : 0 ] plx , prx , ohx ;
o utput ply , pry ;
o utput [ 4 : 0 ] o p i c , plb , o lb , peb , oeb ;
o utput [ 7 : 0 ]
t i m e
l e f t ;
o utput [ 1 : 0 ] plp , prp ;
o utput endround ;
r e g busy ;
r e g [ 2 : 0 ] ack ;
r e g [ 9 : 0 ] plx , prx , ohx ;
r e g ply , pry ;
r e g [ 4 : 0 ] o p i c , plb , o lb , peb , oeb ;
reg [ 7 : 0 ]
t i m e
l e f t ;
r e g [ 1 : 0 ] plp , prp ;
r e g endround ;
reg valid ;
reg state ;
reg enable sync1 , enable sync ;
reg [ 9 : 0 ] data sync1 , data sync ;
74
reg [ 2 : 0 ] index sync2 , index sync1 , index sync ;
pa r a meter IDLE = 0 ;
pa r a meter GET = 1 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
DONE
= 3 ’ d0 ;
PLX
= 3 ’ d1 ; / / 1 0
PRX
= 3 ’ d2 ; / / 1 0
PLRY TL = 3 ’ d3 ; / / 1 , 1 , 8
OHX
= 3 ’ d4 ; / / 1 0
OPIC ENDROUND PLRP= 3 ’ d5 ; / / 5 , o , 2 , 2
LIFEBAR = 3 ’ d6 ; / / 5 , 5
ENERBAR = 3 ’ d7 ; / / 5 , 5
a lwa ys @ ( po sedg e c l k ) b e g i n
e n a b l e s y n c 1 <= e n a b l e ;
e n a b l e s y n c <= e n a b l e s y n c 1 ;
d a t a s y n c 1 <= da ta ;
d a t a
s y n c <= d a t a s y n c 1 ;
i n d e x s y n c 2 <= i n d e x ;
i n d e x
s y n c 1 <= i n d e x s y n c 2 ;
i n d e x s y n c <= i n d e x s y n c 1 ;
i f ( r e s e t ) b e g i n
s t a t e <=IDLE ;
busy <=0;
ack <=2’d0 ;
plx <=300;
prx <=340;
ohx <=300;
ply <=1;
pry <=1;
o p i c <=0;
plb <=31;
o lb <=31;
peb <=31;
oeb <=31;
t i m e
l e f t <=180;
endround <=0;
v a l i d <=0;
end e l s e i f ( s t a r t ) b e g i n
s t a t e <=GET;
ack <=2’d0 ;
busy <=1;
v a l i d <=0;
end e l s e b e g i n
c a s e ( s t a t e )
IDLE : b e g i n
s t a t e <=IDLE ;
busy <=0;
75
end
GET: b e g i n
busy <=1;
s t a t e <=GET;
i f ( i n d e x s y n c != ack ) b e g i n
ack <= i n d e x s y n c ;
case ( index sync )
DONE: b e g i n
s t a t e <= IDLE ;
busy <=0;
v a l i d <=1;
end
PLX: b e g i n
p l x <= da ta ;
end
PRX: b e g i n
prx <= da ta ;
end
PLRY TL : b e g i n
p l y <= da ta [ 9 ] ;
pry <= da ta [ 8 ] ;
t i m e l e f t <= da ta [ 7 : 0 ] ;
end
OHX: b e g i n
ohx <= da ta ;
end
OPIC ENDROUND PLRP: b e g i n
o p i c <= da ta [ 9 : 5 ] ;
endround <=da ta [ 4 ] ;
plp <= da ta [ 3 : 2 ] ;
prp <= da ta [ 1 : 0 ] ;
end
LIFEBAR: b e g i n
p l b <= da ta [ 9 : 5 ] ;
o l b <= da ta [ 4 : 0 ] ;
end
ENERBAR: b e g i n
peb <= da ta [ 9 : 5 ] ;
oeb <= da ta [ 4 : 0 ] ;
// s t a t e <= IDLE ;
// busy <=0;
v a l i d <=1;
end
d e f a u l t : begin
s t a t e <= IDLE ;
busy <=0;
end
endcase
end
76
end
endcase
end
end
endmodule
77
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
18:21:01 04/30/06
/ / Desig n Name :
/ / Module Name :
getuserdata
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module g e t u s e r d a t a ( c l k , r e s e t , s t a r t , busy , index , data , e n a b l e , ack , lpx , rpx ,
lpy , rpy , lpp , rpp , v a l i d ) ;
input clk , reset , start , enable ;
input [ 2 : 0 ] index ;
o utput busy ;
o utput [ 2 : 0 ] ack ;
o utput [ 9 : 0 ] lpx , rpx ;
o utput lpy , rpy ;
o utput [ 1 : 0 ] lpp , rpp ;
i n p u t [ 9 : 0 ] da ta ;
o utput v a l i d ;
r e g busy ;
r e g [ 2 : 0 ] ack ;
r e g [ 9 : 0 ] lpx , rpx ;
r e g lpy , rpy ;
r e g [ 1 : 0 ] lpp , rpp ;
reg valid ;
reg state ;
reg enable sync1 , enable sync ;
reg [ 9 : 0 ] data sync1 , data sync ;
reg [ 2 : 0 ] index sync2 , index sync1 , index sync ;
// r e g d e b o u n c e r e s e t ;
// debounce dbi0 ( d e b o u n c e r e s e t , c l k , i n d e x [ 0 ] , i n d e x s y n c [ 0 ] ) ;
// debounce dbi1 ( d e b o u n c e r e s e t , c l k , i n d e x [ 1 ] , i n d e x s y n c [ 1 ] ) ;
// debounce dbi2 ( d e b o u n c e r e s e t , c l k , i n d e x [ 2 ] , i n d e x s y n c [ 2 ] ) ;
pa r a meter IDLE = 0 ;
78
pa r a meter GET = 1 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
DONE
LPX
RPX
LPYP
RPYP
=
=
=
=
=
3 ’ d0 ;
3 ’ d1 ;
3 ’ d2 ;
3 ’ d3 ;
3 ’ d4 ;
a lwa ys @ ( po sedg e c l k ) b e g i n
e n a b l e s y n c 1 <= e n a b l e ;
e n a b l e
s y n c <= e n a b l e s y n c 1 ;
d a t a
s y n c 1 <= da ta ;
d a t a
s y n c <= d a t a s y n c 1 ;
i n d e x
s y n c 2 <= i n d e x ;
i n d e x
s y n c 1 <= i n d e x s y n c 2 ;
i n d e x
s y n c <= i n d e x s y n c 1 ;
// d e b o u n c e r e s e t <=0;
i f ( r e s e t ) b e g i n
s t a t e <=IDLE ;
busy <=0;
ack <=2’d0 ;
lpx <=0;
rpx <=0;
lpy <=0;
rpy <=0;
lpp <=0;
rpp <=0;
v a l i d <=0;
// d e b o u n c e r e s e t <=1;
end e l s e i f ( s t a r t ) b e g i n
s t a t e <=GET;
// l a s t
i n d e x <=0;
ack <=2’d0 ;
busy <=1;
v a l i d <=0;
end e l s e b e g i n
c a s e ( s t a t e )
IDLE : b e g i n
s t a t e <=IDLE ;
busy <=0;
end
GET: b e g i n
busy <=1;
s t a t e <=GET;
i f ( / ∗ e n a b l e && ∗/ i n d e x s y n c != ack ) b e g i n
ack <= i n d e x s y n c ;
// i f ( e n a b l e )
case ( index sync )
DONE: b e g i n
79
s t a t e <= IDLE ;
busy <=0;
v a l i d <=1;
end
LPX: b e g i n
l p x <= da ta ; / / s y n c ;
end
RPX: b e g i n
rpx <= da ta ; / / s y n c ;
end
LPYP : b e g i n
l p y <= da ta [ 9 ] ; / / s y n c
l p p <= da ta [ 0 ] ; / / s y n c
end
RPYP: b e g i n
rpy <= da ta [ 9 ] ; / / s y n c
rpp <= da ta [ 0 ] ; / / s y n c
// s t a t e <= IDLE ;
// busy <=0;
v a l i d <=1;
end
d e f a u l t : begin
s t a t e <= IDLE ;
busy <=0;
end
endcase
end
end
endcase
end
end
endmodule
80
[9];
[1:0];
[9];
[1:0];
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
19:39:49 04/30/06
/ / Desig n Name :
/ / Module Name :
senddispdata
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module s e n d d i s p d a t a ( c l k , r e s e t , s t a r t , busy , index , data , e n a b l e , ack ,
plx , prx , ply , pry , ohx , o p i c , t i m e l e f t , plb , o lb , peb , oeb , plp , prp , endround ) ;
i n p u t c l k , r e s e t , s t a r t ;
o utput busy , e n a b l e ;
input
input
input
input
input
input
[ 9 : 0 ] plx , prx , ohx ;
ply , pry ;
[ 4 : 0 ] o p i c , plb , o lb , peb , oeb ;
[ 7 : 0 ] t i m e
l e f t ;
[ 1 : 0 ] plp , prp ;
endround ;
o utput [ 2 : 0 ] i n d e x ;
i n p u t [ 2 : 0 ] ack ;
o utput [ 9 : 0 ] da ta ;
reg [ 2 : 0 ] ack sync1 ;
reg [ 2 : 0 ] ack sync ;
reg [ 2 : 0 ] index ;
r e g busy ;
reg state ;
r e g [ 9 : 0 ] da ta ;
pa r a meter IDLE = 0 ;
pa r a meter SEND = 1 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
DONE
= 3 ’ d0 ;
PLX
= 3 ’ d1 ; / / 1 1
PRX
= 3 ’ d2 ; / / 1 1
PLRY TL = 3 ’ d3 ; / / 1 , 1 , 8
OHX
= 3 ’ d4 ; / / 1 1
81
pa r a meter OPIC ENDROUND PLRP= 3 ’ d5 ; / / 5 , 1 , 2 , 2
pa r a meter LIFEBAR = 3 ’ d6 ; / / 5 , 5
pa r a meter ENERBAR = 3 ’ d7 ; / / 5 , 5
a s s i g n e n a b l e = busy ;
a lwa ys @( po sedg e c l k ) b e g i n
a c k s y n c 1 <= ack ;
a c k
s y n c <= a c k s y n c 1 ;
i f ( r e s e t ) b e g i n
a c k s y n c 1 <= 2 ’ b00 ;
a c k
s y n c <= 2 ’ b00 ;
busy <=0;
s t a t e <= IDLE ;
da ta <=0;
i n d e x <=DONE;
end e l s e i f ( s t a r t ) b e g i n
s t a t e <=SEND;
index<=PLX;
busy <=1;
da ta <=p l x ;
end e l s e b e g i n
c a s e ( s t a t e )
IDLE : b e g i n
s t a t e <=IDLE ;
index<=DONE;
busy <=0;
da ta <=0;
end
SEND : b e g i n
busy <= 1;
i f ( a c k s y n c==i n d e x ) b e g i n
case ( index )
DONE : b e g i n
busy <=0;
s t a t e <= IDLE ;
i n d e x <= DONE;
da ta <=0;
end
PLX : b e g i n
s t a t e <= SEND ;
i n d e x <= PRX;
da ta <= prx ;
end
PRX : b e g i n
s t a t e <= SEND ;
i n d e x <= PLRY TL ;
da ta <= {ply , pry , t i m e l e f t } ;
end
PLRY TL : b e g i n
82
s t a t e <= SEND ;
i n d e x <= OHX;
da ta <= ohx ;
end
OHX: b e g i n
s t a t e <= SEND ;
i n d e x <= OPIC ENDROUND PLRP;
da ta <= { o p i c , endround , plp , prp } ;
end
OPIC ENDROUND PLRP : b e g i n
s t a t e <= SEND ;
i n d e x <= LIFEBAR;
da ta <= {plb , o l b } ;
end
LIFEBAR : b e g i n
s t a t e <= SEND ;
i n d e x <= ENERBAR;
da ta <= {peb , oeb } ;
end
ENERBAR : b e g i n
busy <=0;
s t a t e <= IDLE ;
i n d e x <= DONE;
da ta <=0;
end
endcase
end
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
end
endmodule
83
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
18:20:50 04/30/06
/ / Desig n Name :
/ / Module Name :
senduserdata
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module s e n d u s e r d a t a ( c l k , r e s e t , s t a r t , busy , index , data , e n a b l e , ack , lpx , rpx ,
lpy , rpy , lpp , rpp ) ;
input clk , reset , s t a r t ;
i n p u t [ 9 : 0 ] lpx , rpx ;
i n p u t lpy , rpy ;
o utput busy , e n a b l e ;
i n p u t [ 1 : 0 ] lpp , rpp ;
o utput [ 2 : 0 ] i n d e x ;
i n p u t [ 2 : 0 ] ack ;
o utput [ 9 : 0 ] da ta ;
reg [ 2 : 0 ] ack sync1 ;
reg [ 2 : 0 ] ack sync ;
reg [ 2 : 0 ] index ;
r e g busy ;
reg state ;
r e g [ 9 : 0 ] da ta ;
pa r a meter IDLE = 0 ;
pa r a meter SEND = 1 ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
DONE
LPX
RPX
LPYP
RPYP
=
=
=
=
=
3 ’ d0 ;
3 ’ d1 ;
3 ’ d2 ;
3 ’ d3 ;
3 ’ d4 ;
a s s i g n e n a b l e = busy ;
a lwa ys @( po sedg e c l k ) b e g i n
a c k s y n c 1 <= ack ;
84
a c k s y n c <= a c k s y n c 1 ;
i f ( r e s e t ) begin
a c k s y n c 1 <= 2 ’ d0 ;
a c k s y n c <= 2 ’ d0 ;
busy <=0;
s t a t e <= IDLE ;
da ta <=0;
i n d e x <=DONE;
end e l s e i f ( s t a r t ) b e g i n
s t a t e <=SEND;
index<=LPX;
busy <=1;
da ta <=l p x ;
end e l s e b e g i n
case ( state )
IDLE : b e g i n
s t a t e <=IDLE ;
index<=DONE;
busy <=0;
da ta <=0;
end
SEND : b e g i n
busy <= 1;
i f ( a c k s y n c==i n d e x ) b e g i n
case ( index )
DONE:
begin
s t a t e <= IDLE ;
index<=DONE;
busy <=0;
da ta <=0;
end
LPX : b e g i n
s t a t e <= SEND ;
i n d e x <= RPX;
da ta <= rpx ;
end
RPX : b e g i n
s t a t e <= SEND ;
i n d e x <= LPYP ;
da ta <= {lpy , 7 ’ d0 , l p p } ;
end
LPYP : b e g i n
s t a t e <= SEND ;
i n d e x <= RPYP;
da ta <= {rpy , 7 ’ d0 , rpp } ;
end
RPYP: b e g i n
// s t a t e <= IDLE ;
s t a t e <= SEND ;
i n d e x <= DONE;
// busy <=0;
85
da ta <=0;
end
default :
end
endcase
end
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
end
endmodule
86
begin
s t a t e <= IDLE ;
index<=DONE;
busy <=0;
da ta <=0;
/ / Switch Debounce Module
/ / use your system c l o c k f o r t h e c l o c k i n p u t
/ / t o pr o duce a synchr o no us , debounced o utput
module debounce ( r e s e t , c l o c k , n o i s y , c l e a n ) ;
pa r a meter DELAY = 2 7 0 0 0 0 ;
/ / . 0 1 s e c with a 2 7Mhz c l o c k
i n p u t r e s e t , c l o c k , n o i s y ;
o utput c l e a n ;
r e g [ 1 8 : 0 ] co unt ;
r e g new , c l e a n ;
a lwa ys @( po sedg e c l o c k )
i f ( r e s e t )
b e g i n
co unt <= 0;
new <= n o i s y ;
c l e a n <= n o i s y ;
end
e l s e i f ( n o i s y ! = new )
b e g i n
new <= n o i s y ;
co unt <= 0;
end
e l s e i f ( co unt == DELAY)
c l e a n <= new ;
e l s e
co unt <= co unt +1;
endmodule
87
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
16:25:54 03/12/06
/ / Desig n Name :
/ / Module Name :
delay
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module d e l a y ( c l k , in , out ) ;
input clk , in ;
o utput out ;
r e g d e l 1 , d e l 2 , out ;
a lwa ys @ ( po sedg e c l k ) b e g i n
d e l 1 <= i n ;
d e l 2 <= d e l 1 ;
out <= d e l 2 ;
end
endmodule
88
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
//
/ / 6 . 1 1 1 FPGA L a b k i t −− Hex d i s p l a y d r i v e r
//
//
// File :
d i s p l a y
1 6 h e x . v
/ / Date :
24−Sep −05
//
/ / Cr ea ted : A p r i l 2 7 , 2 0 0 4
/ / Author : Nathan I c k e s
//
/ / This module d r i v e s t h e l a b k i t hex d i s p l a y s and shows t h e v a l u e o f
/ / 8 b y t e s ( 1 6 hex d i g i t s ) on t h e d i s p l a y s .
//
// 24 − Sep −05 I k e : updated t o use new r e s e t −o nce s t a t e machine , remove c l e a r
// 02 −Nov−05 I k e : updated t o make i t c o m p l e t e l y synchr o no us
//
// Inputs :
//
//
reset
− a c t i v e hig h
//
clo ck 2 7 mhz − t h e synchr o no us c l o c k
//
da ta
− 64 b i t s ; ea ch 4 b i t s g i v e s a hex d i g i t
//
/ / Outputs :
//
− d i s p l a y l i n e s used i n t h e 6 . 1 1 1 l a b k i t ( r e v 0 0 3 & 0 0 4 )
//
disp ∗
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
module d i s p l a y 1 6 h e x ( r e s e t , clo ck 2 7 mhz , d a t a i n ,
disp blank , disp clock , disp rs , disp ce b ,
disp reset b , disp data out ) ;
i n p u t r e s e t , clo ck 2 7 mhz ;
i n p u t [ 6 3 : 0 ] d a t a
i n ;
/ / c l o c k and r e s e t ( a c t i v e hig h r e s e t )
/ / 1 6 hex n i b b l e s t o d i s p l a y
o utput d i s p b l a n k , d i s p c l o c k , d i s p d a t a o u t , d i s p r s , d i s p c e b ,
disp reset b ;
reg disp data out , disp rs , disp ce b , dis p r es et b ;
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
//
/ / D i s p l a y Clock
//
/ / Gener a te a 5 0 0 kHz c l o c k f o r d r i v i n g t h e d i s p l a y s .
//
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
r e g [ 5 : 0 ] co unt ;
89
//
reg [ 7 : 0 ] reset count ;
reg
old clock ;
wire
dreset ;
wire
c l o c k = ( count < 2 7 ) ? 0 : 1 ;
a lwa ys @( po sedg e clo ck 2 7 mhz )
begin
co unt <= r e s e t ? 0 : ( co unt = = 5 3 ? 0 : co unt + 1 );
r e s e t c o u n t <= r e s e t ? 1 0 0 : ( ( r e s e t c o u n t = = 0 ) ? 0 : r e s e t c o u n t − 1 );
//
o l d c l o c k <= c l o c k ;
end
a s s i g n d r e s e t = ( r e s e t c o u n t ! = 0 ) ;
a s s i g n d i s p c l o c k = ˜ c l o c k ;
wire
c l o c k t i c k = ( ( co unt = = 2 7 ) ? 1 : 0 ) ;
//
wire
clo ck tick = clock & ˜ old clock ;
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
//
/ / D i s p l a y S t a t e Machine
//
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
reg
reg
reg
reg
reg
reg
reg
[ 7 : 0 ] state ;
[ 9 : 0 ] dot index ;
[ 3 1 : 0 ] control ;
[ 3 : 0 ] char index ;
[ 3 9 : 0 ] dots ;
[ 3 : 0 ] nibble ;
[ 6 3 : 0 ] da ta ;
//
//
//
//
//
//
FSM s t a t e
i n d e x t o c u r r e n t dot b e i n g c l o c k e d out
control register
index of current character
dots f o r a s i n g l e d i g i t
hex n i b b l e o f c u r r e n t c h a r a c t e r
a s s i g n d i s p b l a n k = 1 ’ b0 ; / / low <= not bla nked
a lwa ys @( po sedg e clo ck 2 7 mhz )
if ( clock tick )
begin
i f ( dreset )
begin
s t a t e <= 0;
d o t i n d e x <= 0;
c o n t r o l <= 32 ’h7F7F7F7F ;
end
else
casex ( state )
8 ’ h00 :
begin
/ / Reset d i s p l a y s
d i s p d a t a o u t <= 1 ’ b0 ;
d i s p r s <= 1 ’ b0 ; / / dot r e g i s t e r
d i s p c e b <= 1 ’ b1 ;
d i s p r e s e t b <= 1 ’ b0 ;
90
d o t i n d e x <= 0;
s t a t e <= s t a t e +1;
end
8 ’ h01 :
b e g i n
/ / End r e s e t
d i s p r e s e t b <= 1 ’ b1 ;
s t a t e <= s t a t e +1;
end
8 ’ h02 :
b e g i n
/ / I n i t i a l i z e dot r e g i s t e r ( s e t a l l d o t s t o z e r o )
d i s p c e b <= 1 ’ b0 ;
d i s p
d a t a o u t <= 1 ’ b0 ; / / d o t i n d e x [ 0 ] ;
i f ( d o t i n d e x == 639)
s t a t e <= s t a t e +1;
e l s e
d o t
i n d e x <= d o t i n d e x +1;
end
8 ’ h03 :
begin
/ / Latch dot da ta
d i s p c e b <= 1 ’ b1 ;
d o t i n d e x <= 31;
s t a t e <= s t a t e +1;
end
/ / r e−pur po se t o i n i t c t r l r e g
8 ’ h04 :
b e g i n
/ / Setup t h e c o n t r o l r e g i s t e r
d i s p r s <= 1 ’ b1 ; / / S e l e c t t h e c o n t r o l r e g i s t e r
d i s p
c e b <= 1 ’ b0 ;
d i s p
d a t a o u t <= c o n t r o l [ 3 1 ] ;
c o n t r o l <= { c o n t r o l [ 3 0 : 0 ] , 1 ’ b0 } ;
/ / s h i f t l e f t
i f ( d o t i n d e x == 0)
s t a t e <= s t a t e +1;
e l s e
d o t
i n d e x <= d o t i n d e x −1;
end
8 ’ h05 :
b e g i n
/ / Latch t h e c o n t r o l r e g i s t e r da ta / dot da ta
d i s p c e b <= 1 ’ b1 ;
d o t i n d e x <= 39;
/ / i n i t f o r s i n g l e cha r
c h a r i n d e x <= 15;
/ / s t a r t with MS cha r
da ta <= d a t a
i n ;
s t a t e <= s t a t e +1;
91
end
8 ’ h06 :
begin
/ / Load t h e user ’ s dot da ta i n t o t h e
d i s p r s <= 1 ’ b0 ;
d i s p c e b <= 1 ’ b0 ;
d i s p
d a t a o u t <= d o t s [ d o t i n d e x ] ; / /
i f ( d o t i n d e x == 0)
i f ( c h a r i n d e x == 0)
s t a t e <= 5;
else
b e g i n
c h a r
i n d e x <= c h a r i n d e x − 1 ;
da ta <= d a t a i n ;
d o t i n d e x <= 39;
end
e l s e
d o t
i n d e x <= d o t i n d e x −1; / / e l s e
end
dot r eg , cha r by cha r
/ / S e l e c t t h e dot r e g i s t e r
dot da ta from msb
/ / a l l done , l a t c h da ta
/ / g o to next cha r
l o o p thr u a l l d o t s
e n d c a s e / / c a s e x ( s t a t e )
end
a lwa ys @ ( da ta o r c h a r i n d e x )
c a s e ( c h a r i n d e x )
4 ’ h0 :
n i b b l e <=
4 ’ h1 :
n i b b l e <=
4 ’ h2 :
n i b b l e <=
4 ’ h3 :
n i b b l e <=
4 ’ h4 :
n i b b l e <=
4 ’ h5 :
n i b b l e <=
4 ’ h6 :
n i b b l e <=
4 ’ h7 :
n i b b l e <=
4 ’ h8 :
n i b b l e <=
4 ’ h9 :
n i b b l e <=
4 ’hA :
n i b b l e <=
4 ’hB :
n i b b l e <=
4 ’hC :
n i b b l e <=
4 ’hD :
n i b b l e <=
4 ’hE :
n i b b l e <=
4 ’ hF :
n i b b l e <=
endcase
a lwa ys @( n i b b l e )
c a s e ( n i b b l e )
4 ’ h0 : d o t s <=
4 ’ h1 : d o t s <=
4 ’ h2 : d o t s <=
4 ’ h3 : d o t s <=
4 ’ h4 : d o t s <=
40 ’ b 0 0 1 1 1 1 1 0
40 ’ b 0 0 0 0 0 0 0 0
40 ’ b 0 1 1 0 0 0 1 0
40 ’ b 0 0 1 0 0 0 1 0
40 ’ b 0 0 0 1 1 0 0 0
da ta [ 3 : 0 ] ;
da ta [ 7 : 4 ] ;
da ta [ 1 1 : 8 ] ;
da ta [ 1 5 : 1 2 ] ;
da ta [ 1 9 : 1 6 ] ;
da ta [ 2 3 : 2 0 ] ;
da ta [ 2 7 : 2 4 ] ;
da ta [ 3 1 : 2 8 ] ;
da ta [ 3 5 : 3 2 ] ;
da ta [ 3 9 : 3 6 ] ;
da ta [ 4 3 : 4 0 ] ;
da ta [ 4 7 : 4 4 ] ;
da ta [ 5 1 : 4 8 ] ;
da ta [ 5 5 : 5 2 ] ;
da ta [ 5 9 : 5 6 ] ;
da ta [ 6 3 : 6 0 ] ;
01010001
01000010
01010001
01000001
00010100
92
01001001 01000101
0 1 1 1 1 1 1 1
0 1 0 0 0 0 0 0
0 1 0 0 1 0 0 1
0 1 0 0 1 0 0 1
0 1 0 0 1 0 0 1
0 1 0 0 1 0 0 1
0 0 0 1 0 0 1 0
0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 ;
0 0 0 0 0 0 0 0 ;
0 1 0 0 0 1 1 0 ;
0 0 1 1 0 1 1 0 ;
00010000 ;
4 ’ h5 :
4 ’ h6 :
4 ’ h7 :
4 ’ h8 :
4 ’ h9 :
4 ’hA :
4 ’hB :
4 ’hC :
4 ’hD :
4 ’hE :
4 ’ hF :
endcase
dots
dots
dots
dots
dots
dots
dots
dots
dots
dots
dots
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
40 ’ b 0 0 1 0 0 1 1 1
40 ’ b 0 0 1 1 1 1 0 0
40 ’ b 0 0 0 0 0 0 0 1
40 ’ b 0 0 1 1 0 1 1 0
40 ’ b 0 0 0 0 0 1 1 0
40 ’ b 0 1 1 1 1 1 1 0
40 ’ b 0 1 1 1 1 1 1 1
40 ’ b 0 0 1 1 1 1 1 0
40 ’ b 0 1 1 1 1 1 1 1
40 ’ b 0 1 1 1 1 1 1 1
40 ’ b 0 1 1 1 1 1 1 1
01000101
01001010
01110001
01001001
01001001
00001001
01001001
01000001
01000001
01001001
00001001
endmodule
93
01000101
01001001
00001001
01001001
01001001
00001001
01001001
01000001
01000001
01001001
00001001
01000101
01001001
00000101
01001001
00101001
00001001
01001001
01000001
01000001
01001001
00001001
00111001 ;
00110000 ;
00000011 ;
00110110 ;
00011110 ;
01111110 ;
00110110 ;
00100010 ;
00111110 ;
01000001 ;
00000001 ;
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
20:50:52 04/03/06
/ / Desig n Name :
/ / Module Name :
lsfr
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n : G e n e r a t e s pseudorandom numbers from t h e s e e d v a l u e
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module l f s r ( c l k , r e s e t , seed , e n a b l e , out ) ;
input clk ;
input enable ;
input r e s e t ;
input [ 1 5 : 0 ] seed ;
o utput [ 1 5 : 0 ] out ;
r e g [ 1 5 : 0 ] out ;
w i r e feedba ck , x1513 , xx12 ;
a s s i g n x1513 = ( out [ 1 5 ] ˆ out [ 1 3 ] ) ;
a s s i g n xx12 = ( out [ 1 2 ] ˆ x1513 ) ;
a s s i g n f e e d b a c k = ( out [ 1 0 ] ˆ xx12 ) ;
a lwa ys @( po sedg e c l k ) b e g i n
i f ( r e s e t ) begin
out [ 1 5 : 0 ] < = s e e d ;
end e l s e i f ( e n a b l e ) b e g i n
out [ 1 5 : 0 ] < = { out [ 1 4 : 0 ] , f e e d b a c k } ;
end
end
endmodule
94
module t i m e r ( p i x e l c l o c k , r e s e t , t i m e i n , mode , minutes , seco nds , e n a b l e ) ;
input p i x e l c l o c k ;
input r e s e t ;
i n p u t [ 1 : 0 ] mode ;
input [ 7 : 0 ] time in ;
o utput [ 1 : 0 ] minutes ;
o utput [ 5 : 0 ] s e c o n d s ;
o utput e n a b l e ;
r e g [ 1 : 0 ] minutes ;
reg [ 5 : 0 ] seconds ;
reg [ 7 : 0 ] counter ;
wire enable ;
wire t i m e r e s e t ;
a s s i g n t i m e r e s e t = ( t i m e i n ==180);
counter ct ( . clk ( p i x e l c l o c k ) , . r e s e t ( Reset Sync ) , . enable ( enable ) ) ;
/∗
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
i f ( ( ! r e s e t ) | | t i m e r e s e t | | ( mode ! = 1 ) ) b e g i n
// t i m e i n <=180;
// l a s t t i m e i n <=0;
end
e l s e i f ( t i m e i n ==0) co unter <=0;
e l s e i f ( e n a b l e && ( l a s t t i m e i n != c o u n t e r ) ) b e g i n
l a s t t i m e i n <= t i m e i n ;
co unter <=(co unter − 1 );
end ∗/
/∗ i f
else
else
else
( ( ! r e s e t ) | | t i m e r e s e t ) minutes <=3;
i f ( t i m e i n >120) minutes <=2;
i f ( t i m e i n >60) minutes <=1;
minutes <=0;
i f ( ( ! r e s e t ) | | t i m e r e s e t ) seco nds <=0;
e l s e i f ( ( s e c o n d s ==0) && ( minutes ! = 0 ) ) seco nds <=59;
e l s e i f ( s e c o n d s ==0) seco nds <=0;
e l s e i f ( minutes ==2) seco nds<=t i m e i n −120;
∗/
e l s e i f ( minutes ==1) seco nds<=t i m e i n −60;
i f ( ! r e s e t | | t i m e r e s e t ) begin
minutes <=3;
seco nds <=0;
end e l s e i f ( t i m e i n >120) b e g i n
minutes <=2;
seco nds <=t i m e i n − 1 2 0 ;
end e l s e i f ( t i m e i n >60) b e g i n
minutes <=1;
seco nds <=t i m e i n − 6 0 ;
end e l s e b e g i n
95
minutes <=0;
seco nds <=t i m e i n ;
end
end
endmodule
96
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
/ / E n g i n e e r :
//
/ / Cr ea te Date :
1 5 : 4 5 : 3 3 0 4 / 2 3 / 0 6
/ / Desig n Name :
/ / Module Name :
t i m e l e f t f s m
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n :
//
/ / Dependencies :
//
/ / R e v i s i o n :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module t i m e l e f t f s m ( c l k , r e s e t , s t a r t , busy , t i m e
l e f t , n e x t t i m e l e f t ) ;
input
c l k , r e s e t , s t a r t ;
o utput busy ;
i n p u t [ 7 : 0 ] t i m e
l e f t ;
o utput [ 7 : 0 ] n e x t
t i m e l e f t ;
reg [ 6 : 0 ] counter ;
r e g [ 7 : 0 ] n e x t t i m e l e f t ;
r e g s t a t e ;
r e g busy ;
// pa r a meter FRAMERATE = 6 0 ;
pa r a meter FRAMERATE = 3 0 ; / / t w i c e a s f a s t
pa r a meter IDLE = 1 ’ b0 ;
pa r a meter START = 1 ’ b1 ;
a lwa ys @ ( po sedg e c l k ) b e g i n
n e x t t i m e l e f t <= t i m e l e f t ;
i f ( r e s e t ) b e g i n
c o u n t e r <= FRAMERATE;
busy <= 0;
end e l s e b e g i n
c a s e ( s t a t e )
IDLE : b e g i n
i f ( s t a r t ) begin
s t a t e <= START;
busy <= 1;
end e l s e b e g i n
s t a t e <= IDLE ;
busy <= 0;
97
end
end
START : b e g i n
i f ( counter == 0) begin
n e x t t i m e l e f t <= t i m e l e f t − 1 ;
c o u n t e r <= FRAMERATE;
end e l s e b e g i n
c o u n t e r <= c o u n t e r − 1 ;
end
busy <=0;
s t a t e <=IDLE ;
end
d e f a u l t : s t a t e <=IDLE ;
endcase
end
end
endmodule
98
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
/ / E n g i n e e r :
//
/ / Cr ea te Date :
2 1 : 5 0 : 1 6 0 4 / 2 6 / 0 6
/ / Desig n Name :
/ / Module Name :
t i t l e
f s m
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
/ / D e s c r i p t i o n :
//
/ / Dependencies :
//
/ / R e v i s i o n :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module t i t l e f s m ( c l k , r e s e t , s t a r t , busy ,
l h a n d x , r ha nd x , l h a n d y , r ha nd y , l ha nd punch , r hand punch ,
next l hand x , next r hand x ,
next l hand y , next r hand y ,
next mode , game type ) ;
input clk ,
input [ 9 : 0 ]
input
input [ 1 : 0 ]
reset ,
l hand
l hand
l ha nd
start ;
x , r hand x ;
y , r hand y ;
punch , r ha nd punch ;
o utput busy ;
o utput [ 9 : 0 ]
next l hand x , next r hand x ;
o utput
next l hand y , next r hand y ;
o utput [ 1 : 0 ] next mode , game type ;
r e g busy ;
reg [ 9 : 0 ]
n e x t
l h a n d x , n e x t r h a n d x ;
reg
next l hand y , next r hand y ;
r e g [ 1 : 0 ] next mode , game type ;
reg [ 1 : 0 ] state ;
pa r a meter IDLE = 1 ’ b0 ;
pa r a meter ACTIVE= 1 ’ b1 ;
a lwa ys @ ( po sedg e c l k ) b e g i n
i f ( r e s e t ) begin
busy
next l hand x
next r hand x
next l hand y
<=
<= 300;
<= 340;
<= 0;
99
0;
next r hand y
<= 0;
next mode
<= 2’b00 ;
<= 0;
game type
end e l s e b e g i n
case ( state )
IDLE : b e g i n
i f ( s t a r t ) begin
busy <=1;
s t a t e <=ACTIVE ;
end e l s e b e g i n
busy <=0;
s t a t e <=IDLE ;
end
end
ACTIVE : b e g i n
<= l h a n d x ;
next l hand x
next r hand x
<= r h a n d x ;
next l hand y
<= l h a n d y ;
<= r h a n d y ;
next r hand y
next mode
<= 2’b00 ;
game type
<= 0;
i f ( l h a n d p u n c h > 0 | | r ha nd punch > 0 ) b e g i n
next mode <= 2’b01 ;
game type <= 2 ’b00 ;
i f ( r ha nd punch > 0 && r h a n d x < 2 1 3 | |
l h a n d p u n c h > 0 && l h a n d x < 2 1 3 )
game type <= 2 ’ b00 ;
e l s e i f ( r ha nd punch > 0 && r h a n d x > 4 1 4 | |
l h a n d p u n c h > 0 && l h a n d x > 4 1 4 )
game type <= 2 ’ b10 ;
else
game type <= 2 ’ b01 ;
end
busy <=0;
s t a t e <=IDLE ;
end
d e f a u l t : s t a t e <=IDLE ;
e n d c a s e / / msta te
end
end
endmodule
100
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
//
/ / 6 . 1 1 1 FPGA L a b k i t −− Template T o p l e v e l Module f o r Lab 4 ( S p r i n g 2 0 0 6 )
//
//
/ / Cr ea ted : March 1 3 , 2 0 0 6
/ / Author : Nathan I c k e s
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / // / / // / // / / // / // / / // / // / / // / //
module l a b k i t ( beep , a u d i o r e s e t b , a c 9 7 s d a t a o u t , a c 9 7 s d a t a i n , a c9 7 synch ,
ac97 bit clock ,
vga out red , vga out green , vga out blue , vga out sync b ,
vga out blank b , v g a o u t p i x e l c l o c k , vga out hsync ,
vga out vsync ,
tv out ycrcb , tv out reset b , tv out clock , t v o u t i 2 c c l o c k ,
tv out i2c data , tv out pal ntsc , tv out hsync b ,
tv out vsync b , tv out blank b , tv out subcar reset ,
tv
tv
tv
tv
in
in
in
in
ycrcb , tv in data valid , tv in line clo ck1 ,
line clock2 , tv in aef , tv in hff , tv in aff ,
i2c clock , tv in i2c data , tv in fifo read ,
fifo clock , tv in iso , tv in reset b , tv in clock ,
ram0 data , r a m0 a ddr ess , r a m0 a dv ld , r a m0 clk , ram0 cen b ,
r a m0 ce b , ram0 oe b , ram0 we b , ram0 bwe b ,
ram1 data , r a m1 a ddr ess , r a m1 a dv ld , r a m1 clk , ram1 cen b ,
r a m1 ce b , ram1 oe b , ram1 we b , ram1 bwe b ,
clock feedback out , clock feedback in ,
flash data , flash address , flash ce b , flash oe b , flash we b ,
flash reset b , flash sts , flash byte b ,
rs232 txd , rs232 rxd , rs232 rts , rs232 cts ,
mo use clo ck , mouse data , k e y b o a r d c l o c k , keybo a r d da ta ,
clo ck 2 7 mhz , c l o c k 1 , c l o c k 2 ,
disp blank , disp data out , disp clock , disp rs , disp ce b ,
disp reset b , disp data in ,
button0 , button1 , button2 , button3 , b u t t o n e n t e r , b u t t o n r i g h t ,
b u t t o n l e f t , button down , button up ,
switch ,
101
l e d ,
user 1 , user 2 , user 3 , user 4 ,
da ug hter ca r d ,
s y s t e m a c e d a t a , s y s t e m a c e a d d r e s s , s y s t e m a c e c e b ,
systema ce we b , s y s t e m a c e o e b , s y s t e m a c e i r q , systemace mpbrdy ,
analyzer1
analyzer2
analyzer3
analyzer4
data
data
data
data
,
,
,
,
analyzer1
analyzer2
analyzer3
analyzer4
clock
clock
clock
clock
,
,
,
);
o utput beep , a u d i o r e s e t b , a c9 7 synch , a c 9 7 s d a t a o u t ;
input a c 9 7 b i t c l o c k , a c 9 7 s d a t a i n ;
o utput [ 7 : 0 ] v g a o u t r e d , v g a o u t g r e e n , v g a o u t b l u e ;
o utput v g a o u t s y n c b , v g a o u t b l a n k b , v g a o u t p i x e l c l o c k ,
vga out hsync , vga out vsync ;
o utput [ 9 : 0 ] t v o u t y c r c b ;
o utput t v o u t r e s e t b , t v o u t c l o c k , t v o u t i 2 c c l o c k , t v o u t i 2 c d a t a ,
tv out pal ntsc , tv out hsync b , tv out vsync b , tv out blank b ,
tv out subcar reset ;
[ 1 9 : 0 ] tv in ycrcb ;
tv in data valid , tv in line clock1 , tv in line clock2 , tv in aef ,
tv in hff , tv in aff ;
o utput t v i n i 2 c c l o c k , t v i n f i f o r e a d , t v i n f i f o c l o c k , t v i n i s o ,
tv in reset b , tv in clock ;
inout tv i n i 2 c d a ta ;
input
input
inout
o utput
o utput
o utput
[ 3 5 : 0 ] ram0 data ;
[ 1 8 : 0 ] ram0 address ;
r a m0 a dv ld , r a m0 clk , ram0 cen b , r a m0 ce b , ram0 oe b , ram0 we b ;
[ 3 : 0 ] ram0 bwe b ;
inout
o utput
o utput
o utput
[ 3 5 : 0 ] ram1 data ;
[ 1 8 : 0 ] ram1 address ;
r a m1 a dv ld , r a m1 clk , ram1 cen b , r a m1 ce b , ram1 oe b , ram1 we b ;
[ 3 : 0 ] ram1 bwe b ;
input c l o c k f e e d b a c k i n ;
o utput c l o c k f e e d b a c k o u t ;
inout
o utput
o utput
input
[15 :0] flash data ;
[ 2 3 : 0 ] flash address ;
flash ce b , flash oe b , flash we b , flash reset b , flash byte b ;
flash sts ;
102
o utput r s 2 3 2 t x d , r s 2 3 2 r t s ;
input rs232 rxd , r s 2 3 2 c t s ;
input
mo use clo ck , mouse data , k e y b o a r d c l o c k , k e y b o a r d d a t a ;
input
clo ck 2 7 mhz , c l o c k 1 , c l o c k 2 ;
o utput d i s p b l a n k , d i s p c l o c k , d i s p r s , d i s p c e b , d i s p r e s e t b ;
input d i s p d a t a i n ;
o utput d i s p d a t a o u t ;
button0 , button1 , button2 , button3 , b u t t o n e n t e r , b u t t o n r i g h t ,
b u t t o n l e f t , button down , butto n up ;
input
[ 7 : 0 ] s w i t c h ;
o utput [ 7 : 0 ] l e d ;
input
i n o u t [ 3 1 : 0 ] user 1 , user 2 , user 3 , u s e r 4 ;
inout [ 4 3 : 0 ] daughtercard ;
inout
o utput
o utput
input
[ 1 5 : 0 ] systemace data ;
[ 6 : 0 ] systemace address ;
s y s t e m a c e c e b , systema ce we b , s y s t e m a c e o e b ;
s y s t e m a c e
i r q , systemace mpbrdy ;
o utput [ 1 5 : 0 ] a n a l y z e r 1 d a t a , a n a l y z e r 2 d a t a , a n a l y z e r 3 d a t a ,
analyzer4 data ;
o utput a n a l y z e r 1 c l o c k , a n a l y z e r 2 c l o c k , a n a l y z e r 3 c l o c k , a n a l y z e r 4 c l o c k ;
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
//
/ / I /O Assig nments
//
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
/ / Audio Input and Output
a s s i g n beep = 1 ’ b0 ;
a s s i g n a u d i o
r e s e t b = 1 ’ b0 ;
a s s i g n a c 9 7 s y n c h = 1 ’ b0 ;
a s s i g n a c 9 7
s d a t a o u t = 1 ’ b0 ;
/ / Video
assign tv out
assign tv out
assign tv out
assign tv out
assign tv out
assign tv out
assign tv out
assign tv out
assign tv out
Output
y c r c b = 1 0 ’ h0 ;
r e s e t b = 1 ’ b0 ;
c l o c k = 1 ’ b0 ;
i 2 c c l o c k = 1 ’ b0 ;
i 2 c d a t a = 1 ’ b0 ;
p a l n t s c = 1 ’ b0 ;
h s y n c b = 1 ’ b1 ;
v s y n c b = 1 ’ b1 ;
b l a n k b = 1 ’ b1 ;
103
a s s i g n t v o u t s u b c a r r e s e t = 1 ’ b0 ;
/ / Video Input
// a s s i g n t v
i n i 2 c c l o c k = 1 ’ b0 ;
a s s i g n t v
i n f i f o r e a d = 1 ’ b1 ;
a s s i g n t v
i n f i f o c l o c k = 1 ’ b0 ;
a s s i g n t v
i n i s o = 1 ’ b1 ;
// a s s i g n t v
i n r e s e t b = 1 ’ b0 ;
a s s i g n t v i n c l o c k = clo ck
2 7 mhz ; / / 1 ’ b0 ;
// a s s i g n t v
i n i 2 c d a t a = 1 ’ bZ ;
/ / t v
i n y c r c b , t v i n d a t a v a l i d , t v i n l i n e c l o c k 1 , t v i n l i n e c l o c k 2 ,
/ / t v i n a e f , t v i n h f f , and t v i n a f f a r e i n p u t s
/ / SRAMs
/ ∗ change l i n e s below t o e n a b l e ZBT RAM bank0 ∗ /
/∗
assign
assign
assign
assign
assign
ram0 data = 3 6 ’ hZ ;
r a m 0 a d d r e s s = 1 9 ’ h0 ;
r a m 0 c l k = 1 ’ b0 ;
ram0
we b = 1 ’ b1 ;
r a m0 cen b = 1 ’ b0 ;
// clock enable
∗/
/ ∗ e n a b l e RAM p i n s ∗ /
assign
assign
assign
assign
r a m0 ce b = 1 ’ b0 ;
r a m0
o e b = 1 ’ b0 ;
r a m 0 a d v l d = 1 ’ b0 ;
ram0 bwe b = 4 ’ h0 ;
/ ∗ ∗ ∗ ∗ ∗ ∗ ∗∗∗∗ /
a s s i g n ram1 data = 3 6 ’ hZ ;
a s s i g n r a m 1 a d d r e s s = 1 9 ’ h0 ;
a s s i g n r a m 1 a d v l d = 1 ’ b0 ;
a s s i g n r a m 1 c l k = 1 ’ b0 ;
a s s i g n r a m1 cen b = 1 ’ b1 ;
a s s i g n r a m1
ce b = 1 ’ b1 ;
a s s i g n r a m1
o e b = 1 ’ b1 ;
a s s i g n ram1
we b = 1 ’ b1 ;
a s s i g n ram1 bwe b = 4 ’ hF ;
a s s i g n c l o c k
f e e d b a c k o u t = 1 ’ b0 ;
/ / F l a s h ROM
a s s i g n f l a s h d a t a = 1 6 ’ hZ ;
a s s i g n f l a s h
a d d r e s s = 2 4 ’ h0 ;
a s s i g n f l a s h
c e b = 1 ’ b1 ;
a s s i g n f l a s h
o e b = 1 ’ b1 ;
a s s i g n f l a s h
w e b = 1 ’ b1 ;
a s s i g n f l a s h
r e s e t b = 1 ’ b0 ;
a s s i g n f l a s h
b y t e b = 1 ’ b1 ;
104
/ / RS−232 I n t e r f a c e
a s s i g n r s 2 3 2 t x d = 1 ’ b1 ;
a s s i g n r s 2 3 2 r t s = 1 ’ b1 ;
/ / LED
assign
assign
assign
assign
assign
assign
Displays
d i s p b l a n k = 1 ’ b1 ;
d i s p c l o c k = 1 ’ b0 ;
d i s p r s = 1 ’ b0 ;
d i s p c e b = 1 ’ b1 ;
d i s p r e s e t b = 1 ’ b0 ;
d i s p d a t a o u t = 1 ’ b0 ;
/ / Buttons , Switches , and I n d i v i d u a l LEDs
a s s i g n l e d = 8 ’hFF ;
/ / User I /Os
a s s i g n u s e r 1 = 3 2 ’ hZ ;
a s s i g n u s e r 2 = 3 2 ’ hZ ;
// a s s i g n u s e r 3 = 3 2 ’ hZ ;
a s s i g n u s e r 4 [ 3 1 : 1 8 ] = 1 6 ’ hZ ;
/ / Da ug hter ca r d Co nnecto r s
a s s i g n d a u g h t e r c a r d = 4 4 ’ hZ ;
/ / SystemACE M i c r o p r o c e s s o r Port
a s s i g n s y s t e m a c e d a t a = 1 6 ’ hZ ;
a s s i g n s y s t e m a c e a d d r e s s = 7 ’ h0 ;
a s s i g n s y s t e m a c e
c e b = 1 ’ b1 ;
a s s i g n s y s t e m a c e w e b = 1 ’ b1 ;
a s s i g n s y s t e m a c e o e b = 1 ’ b1 ;
/ / L o g i c Ana lyzer
a s s i g n a n a l y z e r 1 d a t a = 1 6 ’ h0 ;
a s s i g n a n a l y z e r 1 c l o c k = 1 ’ b1 ;
a s s i g n a n a l y z e r 2 d a t a = 1 6 ’ h0 ;
a s s i g n a n a l y z e r 2 c l o c k = 1 ’ b1 ;
a s s i g n a n a l y z e r 3 d a t a = 1 6 ’ h0 ;
a s s i g n a n a l y z e r 3 c l o c k = 1 ’ b1 ;
a s s i g n a n a l y z e r 4 d a t a = 1 6 ’ h0 ;
a s s i g n a n a l y z e r 4 c l o c k = 1 ’ b1 ;
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
//
/ / Lab 4 Components
//
/ / / / / / / / / / / / / / / / / / / / // / // / / // / // / // / / // / // / / // / // / // / / // / // / / // / // / // / / // / //
//
/ / Gener a te a 3 1 . 5MHz p i x e l c l o c k from clo ck
2 7 mhz
//
105
w i r e pclk , p i x e l c l o c k ;
DCM p i x e l
c l o c k d c m ( . CLKIN( clo ck 2 7 mhz ) , .CLKFX( p c l k ) ) ;
/ / s y n t h e s i s a t t r i b u t e CLKFX DIVIDE o f p i x e l
c l o c k d c m i s 1 5
/ / s y n t h e s i s a t t r i b u t e CLKFX MULTIPLY o f p i x e l
c l o c k d c m i s 1 4
/ / s y n t h e s i s a t t r i b u t e CLKIN PERIOD o f p i x e l c l o c k d c m i s 3 7
/ / s y n t h e s i s a t t r i b u t e CLK FEEDBACK o f p i x e l
c l o c k d c m
i s ”NONE”
BUFG p i x e l
c l o c k b u f ( . I ( p c l k ) , .O( p i x e l c l o c k ) ) ;
//
/ / VGA o utput s i g n a l s
//
/ / I n v e r t i n g t h e c l o c k t o t h e DAC p r o v i d e s h a l f a c l o c k p e r i o d f o r s i g n a l s
/ / t o p r o p a g a t e from t h e FPGA t o t h e DAC.
assign vga out pixel clock = ˜ pixel clock ;
w i r e r e s e t s y n c ;
debounce debo unceReset ( 1 ’ b0 , p i x e l
c l o c k , b u t t o n e n t e r , r e s e t s y n c ) ;
w i r e [ 9 : 0 ] lpx , rpx ;
wire
lpy , rpy ;
w i r e [ 1 : 0 ] lpp , rpp ;
// a s s i g n l e d = 8 ’ b11111111 ;
// d i s p l a y 1 6 h e x a l p h a d i s p ( ˜ r e s e t s y n c , p i x e l c l o c k , hex ,
//
d i s p b l a n k , d i s p c l o c k , d i s p r s , d i s p c e b ,
//
d i s p
r e s e t b , d i s p d a t a o u t ) ;
///START oF UZOMA’ s CODE
wire clk ;
a s s i g n c l k = p i x e l c l o c k ;
w i r e [ 9 : 0 ] hcount ;
w i r e [ 9 : 0 ] vcount ;
w i r e s t a r t ;
// v g a c o n t r o l l e r vga ( c l k , ˜ r e s e t s y n c , hsync b , vsync b , v g a o u t s y n c b ,
// v g a o u t b l a n k b , hcount , vcount , s t a r t ) ;
// d e l a y dhsync ( c l k , hsync b , v g a o u t h s y n c ) ;
// d e l a y dvsync ( c l k , vsync b , v g a
o u t v s y n c ) ;
// vga vga1 ( c l k , hcount , vcount , hsync , vsync , bla nk ) ;
/ / w i r e up t o ZBT ram
w i r e [ 3 5 : 0 ] v r a m w r i t e d a t a ;
w i r e [ 3 5 : 0 ] v r a m
r e a d d a t a ;
106
w i r e [ 1 8 : 0 ] vram addr ;
wire
vram we ;
z b t 6 1 1 1 zbt1 ( c l k , 1 ’ b1 , vram we , vram addr ,
v r a m
w r i t e d a t a , vr a m r ea d da ta ,
r a m0 clk , ram0 we b , r a m0 a ddr ess , ram0 data , r a m0 cen b ) ;
/ / g e n e r a t e p i x e l v a l u e from r e a d i n g ZBT memory
wire [ 1 7 : 0 ] v r p i x e l ;
w i r e [ 1 8 : 0 ] vram addr1 ;
v r a m d i s p l a y vd1 ( ˜ r e s e t s y n c , c l k , hcount , vcount , v r p i x e l ,
vram addr1 , v r a m r e a d d a t a ) ;
/ / ADV7185 NTSC d e c o d e r i n t e r f a c e co de
/ / adv7185 i n i t i a l i z a t i o n module
a d v 7 1 8 5 i n i t adv7185 ( . r e s e t ( ˜ r e s e t s y n c ) , . clo ck 2 7 mhz ( clo ck 2 7 mhz ) ,
. s o u r c e ( 1 ’ b0 ) , . t v i n r e s e t b ( t v i n r e s e t b ) ,
. tv in i2c clock ( tv in i2c clock ) ,
. tv in i2c data ( tv in i2c data ));
wire [ 2 9 : 0 ] ycrcb ;
wire [ 2 : 0 ] fvh ;
wire
dv ;
/ / v i d e o da ta ( luminance , chr o mina nce )
/ / sync f o r f i e l d , v e r t i c a l , h o r i z o n t a l
/ / da ta v a l i d
n t s c d e c o d e deco de ( . c l k ( t v i n l i n e c l o c k 1 ) , . r e s e t ( ˜ r e s e t s y n c ) ,
. tv in ycrcb ( tv in ycrcb [19:10]) ,
. ycrcb ( ycrcb ) , . f ( fvh [ 2 ] ) ,
. v ( f v h [ 1 ] ) , . h ( f v h [ 0 ] ) , . d a t a v a l i d ( dv ) ) ;
/ / co de t o w r i t e NTSC da ta t o v i d e o memory
wire [ 1 8 : 0 ] ntsc addr ;
wire [ 3 5 : 0 ] ntsc data ;
wire
ntsc we ;
n t s c t o z b t n2z ( c l k , t v i n l i n e c l o c k 1 , fvh , dv , ycr cb ,
ntsc addr , ntsc data , ntsc we ) ;
wire
// w i r e my we
assign
assign
assign
my we = hcount [ 1 : 0 ] = = 2 ’ d2 ;
= n t s c w e ;
vram addr = my we ? n t s c a d d r : vram
addr1 ;
vram we = my we ;
v r a m w r i t e d a t a = n t s c
d a t a ;
// w i r e
bl , hs , vs ;
// delayN dn1 ( c l k , hsync , hs ) ;
// delayN dn2 ( c l k , vsync , vs ) ;
// delayN dn3 ( c l k , blank , b l ) ;
/ / d e l a y by 3 c y c l e s t o sync with ZBT r ea d
w i r e v a l i d p i x e l = ( ( hcount >9) & ( hcount < 6 2 8 )); / / 6 3 9 − 1 1
107
// w i r e v a l i d p i x e l = 1 ;
r e g [ 9 : 0 ] Y, Cr , Cb ;
a lwa ys @( po sedg e c l k )
b e g i n
Y <= { v r
p i x e l [ 1 7 : 1 0 ] , 2 ’ b0 } ;
Cr <={ v r
p i x e l [ 9 : 5 ] , 5 ’ b0 } ;
Cb <={ v r
p i x e l [ 4 : 0 ] , 5 ’ b0 } ;
end
w i r e [ 7 : 0 ] tR , tG , tB ;
YCrCb2RGB c o n v c o l o r ( tR , tG , tB , c l k , ˜ r e s e t
s y n c , Y , Cr , Cb ) ;
/∗
// r e g [ 7 : 0 ] L t h r e s , R t h r e s , G thr es , B t h r e s ;
debounce up1 ( r e s e t , c l k , ˜ button up , u p l e v e l ) ;
debounce down1 ( r e s e t , c l k , ˜ button down , d o w n l e v e l ) ;
r e g upold , downold ;
a lwa ys @ ( po sedg e c l k )
b e g i n
upo ld <= u p l e v e l ;
downold <= d o w n l e v e l ;
end
w i r e up = u p l e v e l & ! upo ld ;
w i r e down = d o w n l e v e l & ! downold ;
w i r e sw0 , sw1 , sw3 , sw7 ;
debounce s0 ( r e s e t , c l k
debounce s1 ( r e s e t , c l k
debounce s3 ( r e s e t , c l k
debounce s7 ( r e s e t , c l k
pa r a meter
pa r a meter
pa r a meter
pa r a meter
L thres
R
t h r e s
G
t h r e s
B
t h r e s
=
=
=
=
,
,
,
,
switch [ 0 ]
switch [ 1 ]
switch [ 3 ]
switch [ 7 ]
,
,
,
,
sw0 ) ;
sw1 ) ;
sw3 ) ;
sw7 ) ;
∗/
8 ’ b10000111 ;
8 ’ b11111011 ;
8 ’ b01111111 ;
8 ’ b11111111 ;
// w i r e [ 9 : 0 ] vcen , hcen ;
w i r e v a l i d c o l o r ;
// f i n d
c e n t e r f c ( c l k , r e s e t , vcount , hcount , v a l i d c o l o r , vcen , hcen ) ;
w i r e [ 9 : 0 ] v c e n l , h c e n l , vcenr , hcenr ;
f i n d l i g h t s f l ( c l k , ˜ r e s e t
s y n c , vcount , hcount , v a l i d c o l o r , v c e n l , h c e n l ,
vcenr , hcenr ) ;
w i r e [ 2 3 : 0 ] c o l o r , c o l o r 2 , c o l o r l e f t , c o l o r r i g h t ;
i n r e c t a n g l e l e f t g l o v e ( vcount , hcount , h c e n l , v c e n l , c o l o r l e f t ) ;
i n r e c t a n g l e r i g h t g l o v e ( vcount , hcount , hcenr , vcenr , c o l o r r i g h t ) ;
// i n r e c t a n g l e l e f t g l o v e ( vcount , hcount , 9 ’ d200 , 9 ’ d150 , c o l o r l e f t ) ;
108
// i n r e c t a n g l e r i g h t g l o v e ( vcount , hcount , 9 ’ d300 , 9 ’ d300 , c o l o r r i g h t ) ;
defparam r i g h t g l o v e .TRUE COLOR = 2 4 ’ h00FF00 ;
assign color2 = ( col orl ef t | colorright );
a s s i g n c o l o r = ( c o l o r 2 ==24’d0 ) ? { tR , tG , tB } : c o l o r 2 ;
a s s i g n v a l i d c o l o r = (Y[ 9 : 2 ] > = 8 ’ b10000111 ) &
( c o l o r [2 3 :1 6 ] > = R t h r e s ) &
( c o l o r [1 5 :8 ] > = G t h r e s ) &
( color [7:0] < B thres ) ;
w i r e s c l k , CONVST;
assign user3
= {2 ’hZ , s c l k , CONVST, 2 6 ’ hZ , s c l k , CONVST} ;
w i r e d a t a i n r = u s e r 3 [ 2 ] ;
w i r e RFSr = u s e r 3 [ 3 ] ;
w i r e d a t a i n l = u s e r 3 [ 3 0 ] ;
w i r e RFSl = u s e r 3 [ 3 1 ] ;
wire [ 1 : 0 ] punchlevell , punchlevelr ;
w i r e [ 7 : 0 ] d a t a o u t l ;
w i r e v a l i d l ;
w i r e [ 9 : 0 ] g l o x , g r o x ;
w i r e g l o
y , g r o y ;
p u n c h d e t e c t o r pd ( clo ck 2 7 mhz , c l k , s c l k , ˜ r e s e t s y n c , CONVST, d a t a i n l , RFSl ,
d a t a i n r , RFSr ,
h c e n l , v c e n l , hcenr , vcenr ,
g l o
x , g l o y , g r o x , g r o y , p u n c h l e v e l l , p u n c h l e v e l r ) ;
// end OF UZOMA’ S CODE
wire
wire
wire
wire
wire
wire
[ 2 : 0 ] index in ;
[ 9 : 0 ] data in ;
enable in ;
[ 2 : 0 ] index out ;
[ 9 : 0 ] data out ;
enable out ;
109
wire
wire
wire
wire
wire
[ 9 : 0 ] player l hand x , player r hand x ;
player l hand y , player r hand y ;
[ 1 : 0 ] player l hand punch , player r hand punch ;
[ 9 : 0 ] opponent head x ;
[ 4 : 0 ] opponent picture ,
p l a y e r l i f e , o p p o n e n t l i f e , player energy , opponent energy ;
wire [ 7 : 0 ] t i m e l e f t ;
w i r e [ 1 : 0 ] mode , round , game type ;
wire [ 2 : 0 ] s t a t e ;
a s s i g n s t a r t = ( hcount ==10’d639 && vcount ==10’d479 ) ;
//game t y p e s
pa r a meter ONEPLAYER
pa r a meter TWOPLAYERM
pa r a meter TWOPLAYERS
// w i r e
// p i n s
= 2 ’ d0 ;
= 2 ’ d1 ;
= 2 ’ d2 ;
m index s i n d e x da ta
17:15
14:12
m ena ble
11:2
s enable
1
0
w i r e sbo ; / / s l a v e back out on c o l l i s i o n
a s s i g n sbo = ( game type==TWOPLAYERM | | ( game type==TWOPLAYERS && ˜ e n a b l e i n ) ) ;
assign enable in
assign index in
= ( game type==TWOPLAYERM) ? u s e r 4 [ 0 ] : u s e r 4 [ 1 ] ;
= ( game type==TWOPLAYERM) ? u s e r 4 [ 1 4 : 1 2 ] : u s e r 4 [ 1 7 : 1 5 ] ;
assign
assign
assign
assign
=
=
=
=
user4 [ 1 7 : 1 5 ]
user4 [ 1 4 : 1 2 ]
user4 [ 1 ]
user4 [ 0 ]
// a s s i g n d a t a i n [ 9 : 0 ]
a s s i g n d a t a
i n [ 9 : 0 ]
assign user4 [ 1 1 : 2 ]
( game
( game
( game
( game
type==TWOPLAYERM)
type==TWOPLAYERM)
type==TWOPLAYERM)
type==TWOPLAYERM)
?
?
?
?
i n d e x o u t [ 2 : 0 ] : 3 ’ hZ ;
3 ’ hZ : i n d e x o u t [ 2 : 0 ] ;
e n a b l e o u t : 1 ’ hZ ;
1 ’ hZ : e n a b l e o u t ;
= u s e r 4 [ 1 1 : 2 ] ; / / : 1 0 ’ b0 ;
= e n a b l e i n ? u s e r 4 [ 1 1 : 2 ] : 1 0 ’ b0 ;
= e n a b l e o u t && sbo ? d a t a o u t [ 9 : 0 ] : 1 0 ’ hZ ;
c o n t r o l u n i t cu ( c l k , ˜ r e s e t s y n c , s t a r t ,
1 0 ’ d640−g r o x , g r o y , p u n c h l e v e l r ,
1 0 ’ d640−g l o x , g l o y , p u n c h l e v e l l ,
player l hand x , player l hand y , player l hand punch ,
player r hand x , player r hand y , player r hand punch ,
o ppo nent hea d x ,
opponent picture ,
player life , opponent life ,
p l a y e r e n e r g y , o ppo nent ener g y ,
t i m e l e f t , mode , round , game type , s t a t e ,
index in ,
data in ,
enable in ,
110
index out , data out , ena ble o ut
);
w i r e hsync , vsync , l h s t a t u s , r h s t a t u s ;
r e g hsync b , v s y n c b ;
assign lhstatus = |( player l hand punch ) ;
assign rhstatus = |( player r hand punch ) ;
top to p1 (
. p i x e l
c l o c k ( p i x e l c l o c k ) ,
. reset sync ( reset sync ) ,
. f1 lhand x ( player l hand x ) ,
. f1 rhand x ( player r hand x ) ,
. f1 lhand y ( player l hand y ) ,
. f1 rhand y ( player r hand y ) ,
. f1 lh status ( lhstatus ) ,
. f1 rh status ( rhstatus ) ,
. f 2 p i c x ( opponent head x ) ,
. f 2 p i c y ( 1 0 ’ d250 ) ,
. f2 s t a t u s ( opponent picture ) ,
. hsync ( hsync ) ,
. vsync ( vsync ) ,
. sync b ( vga out sync b ) ,
. blank b ( vga out blank b ) ,
. r ed ( v g a o u t r e d ) ,
. green ( vga out green ) ,
. blue ( vga out blue ) ,
. f1 lifebar ( player life ) ,
. f1 energybar ( player energy ) ,
. f 2 l i f e b a r ( opponent life ) ,
. f 2 e n e r g y b a r ( o p p o n e n t e n e r g y ) ,
. mode ( mode ) ,
. round ( round ) ,
. p i x e l c o u n t ( hcount ) ,
. l i n e
c o u n t ( vcount ) ,
. time in ( t i me l e ft ) ) ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
hsync
b <= ˜ hsync ;
v s y n c b <= ˜ vsync ;
end
a s s i g n vga out vsync = vsync b ;
a s s i g n v g a o u t h s y n c = hsync b ;
endmodule
111
C
Imaging Source Codes
module b o x i n g r i n g ( p i x e l c l o c k , x , y , red , g r een , b l u e ) ;
i n p u t p i x e l
c l o c k ;
i n p u t [ 9 : 0 ] x , y ;
o utput [ 7 : 0 ] red , g r een , b l u e ;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
PIXELS = 8 0 0 ;
LINES = 5 2 5 ;
FLOOR TOP LX = 1 0 ’ d100 ;
FLOOR TOP RX = 1 0 ’ d540 ;
MAX X = 1 0 ’ d640 ;
FLOOR TOP Y = 1 0 ’ d320 ;
MAX Y = 1 0 ’ d420 ;
SPACE = 1 0 ’ d25 ;
WIDTH = 1 0 ’ d5 ;
POLE WIDTH = 1 0 ’ d10 ;
POLE TOP Y = FLOOR TOP Y−3∗SPACE−5∗WIDTH;
POLE BOTTOM Y = FLOOR TOP Y+WIDTH;
POLE LX = FLOOR TOP LX−10 ’d5 ;
POLE RX = FLOOR TOP RX−10 ’d5 ;
FLOOR COLOR = 2 4 ’ h f f f f f f ;
ROPE1 COLOR = 2 4 ’ h 0 0 0 0 f f ;
ROPE2 COLOR = 2 4 ’ h f f 0 0 0 0 ;
ROPE3 COLOR = 2 4 ’ h f f f f f f ;
POLE COLOR = 2 4 ’ h f f 0 0 0 0 ;
BLACK = 2 4 ’ h000000 ;
wire [ 2 3 : 0 ]
wire [ 9 : 0 ]
wire
wire [ 7 : 0 ]
next RGB ;
next x , n e x t y ;
o u t
o f b o u n d s , h o r i z o n t a l r o p e 1 , h o r i z o n t a l r o p e 2 , h o r i z o n t a l r o p e 3 ,
d i a g o n a l r o p e 1 , d i a g o n a l r o p e 2 ,
d i a g o n a l r o p e 3 , p o l e ;
red , g r een , b l u e ;
reg [ 2 3 : 0 ]
RGB;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
// a s s i g n s next s t a t e
RGB<=next RGB ;
end
// computes whether next p i x e l p o s i t i o n i s w i t h i n b o u n d a r i e s o f bo xing r i n g
a s s i g n o u t o f b o u n d s = ( ( ( next x >=0)&&(next x<=FLOOR TOP LX)&&
( next y <(MAX Y−n e x t x ) ) ) | |
( ( next x>=FLOOR TOP RX)&&( next x<=MAX X)&&
( next y <(FLOOR TOP Y+next x −FLOOR TOP RX ) ) ) | |
( ( next x>=FLOOR TOP LX)&&( next x<=FLOOR TOP RX)&&
( next y <FLOOR TOP Y ) ) ) ;
a s s i g n h o r i z o n t a l
r o p e 1 = ( ( ( next y >=(FLOOR TOP Y−SPACE−WIDTH))&&
( next y <=(FLOOR TOP Y−SPACE)))&&
112
( next x>=FLOOR TOP LX)&&( next x<=FLOOR TOP RX ) ) ;
a s s i g n h o r i z o n t a l
r o p e 2 = ( ( ( next y >=(FLOOR TOP Y−2∗SPACE−2∗WIDTH))&&
( next y <=(FLOOR TOP Y−2∗SPACE−WIDTH)))&&
( next x>=FLOOR TOP LX)&&( next x<=FLOOR TOP RX ) ) ;
a s s i g n h o r i z o n t a l
r o p e 3 = ( ( ( next y >=(FLOOR TOP Y−3∗SPACE−3∗WIDTH))&&
( next y <=(FLOOR TOP Y−3∗SPACE−2∗WIDTH)))&&
( next x>=FLOOR TOP LX)&&( next x<=FLOOR TOP RX ) ) ;
a s s i g n d i a g o n a l r o p e 1 = ( ( ( next x >=0)&&(next x<=FLOOR TOP LX)&&
( next y >=(MAX Y−next
x −SPACE−WIDTH))&&
( next y <=(MAX Y−next x −SPACE ) ) ) | |
( ( next x>=FLOOR TOP RX)&&( next x<=MAX X)&&
( next y >=(FLOOR TOP Y+next x −FLOOR TOP RX−SPACE−WIDTH) )
&&(next y <=(FLOOR TOP Y+next x −FLOOR TOP RX−SPACE ) ) ) ) ;
a s s i g n d i a g o n a l r o p e 2 = ( ( ( next x >=0)&&(next x<=FLOOR TOP LX)&&
( next y >=(MAX Y−next
x −2∗SPACE−2∗WIDTH))&&
( next y <=(MAX Y−next x −2∗SPACE−WIDTH ) ) ) | |
( ( next x>=FLOOR TOP RX)&&( next x<=MAX X)&&
( next y >=(FLOOR TOP Y+next x −FLOOR TOP RX−2∗SPACE−2∗WIDTH) )
&&(next y <=(FLOOR TOP Y+next x −FLOOR TOP RX−2∗SPACE−WIDTH ) ) ) ) ;
a s s i g n d i a g o n a l r o p e 3 = ( ( ( next x >=0)&&(next x<=FLOOR TOP LX)&&
( next y >=(MAX Y−next
x −3∗SPACE−3∗WIDTH))&&
( next y <=(MAX Y−next x −3∗SPACE−2∗WIDTH ) ) ) | |
( ( next x>=FLOOR TOP RX)&&( next x<=MAX X)&&
( next y >=(FLOOR TOP Y+next x −FLOOR TOP RX−3∗SPACE−3∗WIDTH) )
&&(next y <=(FLOOR TOP Y+next x −FLOOR TOP RX−3∗SPACE−2∗WIDTH ) ) ) ) ;
a s s i g n p o l e = ( ( ( next y<=POLE BOTTOM Y)&&( next y>=POLE TOP Y))&&
( ( ( next x>=POLE LX) &&( next
x <=(POLE LX+POLE WIDTH ) ) ) | |
( ( next x>=POLE RX)&&( next x <=(POLE RX+POLE WIDTH ) ) ) ) ) ;
// computes next p i x e l p o s i t i o n
a s s i g n n e x t x = ( x == (PIXELS − 1 ) ) ? 1 0 ’ d0 : x + 1 ’ b1 ;
a s s i g n n e x t
y = ( x == (PIXELS − 1 ) ) ? ( y == LINES − 1 ) ? 1 0 ’ d0 : y + 1 ’ b1 : y ;
// computes next s t a t e
a s s i g n next RGB = ( p o l e ) ? POLE COLOR :
( h o r i z o n t a l r o p e 1 | | d i a g o n a l r o p e 1 ) ? ROPE1 COLOR :
( h o r i z o n t a l r o p e 2 | | d i a g o n a l r o p e 2 ) ? ROPE2 COLOR :
( h o r i z o n t a l r o p e 3 | | d i a g o n a l r o p e 3 ) ? ROPE3 COLOR :
( ! o u t
o f b o u n d s ) ? FLOOR COLOR : BLACK;
a s s i g n r ed = RGB[ 2 3 : 1 6 ] ;
a s s i g n g r e e n = RGB[ 1 5 : 8 ] ;
a s s i g n b l u e = RGB [ 7 : 0 ] ;
endmodule
113
/ / This module p r o v i d e s c o n t r o l s i g n a l s t o t h e ADV7125 .
/ / The r e s o l u t i o n i s 6 4 0 x480 and t h e p i x e l f r e q u e n c y
/ / i s about 2 5MHz
/ / hsync i s a c t i v e low : hig h f o r 6 4 0 p i x e l s o f a c t i v e video ,
/ / hig h f o r 1 6 p i x e l s o f f r o n t porch ,
/ / low f o r 9 6 p i x e l s o f hsync ,
/ / hig h f o r 4 8 p i x e l s o f back po r ch
/ / vsync i s a c t i v e low : hig h f o r 4 8 0 l i n e s o f a c t i v e video ,
/ / hig h f o r 1 1 l i n e s o f f r o n t porch ,
/ / low f o r 2 l i n e s o f vsync ,
/ / hig h f o r 3 1 l i n e s o f back po r ch
module vga ( p i x e l
c l o c k , r e s e t , hsync , vsync , sync b ,
bla nk b , p i x e l c o u n t , l i n e c o u n t , f r a m e p u l s e ) ;
i n p u t p i x e l
c l o c k ; / / 2 5 . 1 7 5 MHz p i x e l c l o c k
i n p u t r e s e t ; / / system r e s e t
o utput hsync ; / / h o r i z o n t a l sync
o utput vsync ; / / v e r t i c a l sync
o utput s y n c
b ; / / ha r dwir ed t o Vdd
o utput b l a n k
b ; / / c o m p o s i t e bla nk
o utput [ 9 : 0 ] p i x e l
c o u n t ; / / number o f t h e c u r r e n t p i x e l
o utput [ 9 : 0 ] l i n e c o u n t ; / / number o f t h e c u r r e n t l i n e
o utput f r a m e p u l s e ;
/ / 6 4 0 x480 6 0 Hz p a r a m e t e r s
pa r a meter PIXELS = 8 0 0 ;
pa r a meter LINES = 5 2 5 ;
pa r a meter HACTIVE VIDEO = 6 4 0 ;
pa r a meter HFRONT PORCH = 1 6 ;
pa r a meter HSYNC PERIOD = 9 6 ;
pa r a meter HBACK PORCH = 4 8 ;
pa r a meter VACTIVE VIDEO = 4 8 0 ;
pa r a meter VFRONT PORCH = 1 1 ;
pa r a meter VSYNC PERIOD = 2 ;
pa r a meter VBACK PORCH = 3 1 ;
/ / c u r r e n t p i x e l co unt
r e g [ 9 : 0 ] p i x e l c o u n t = 1 0 ’ b0 ;
r e g [ 9 : 0 ] l i n e c o u n t = 1 0 ’ b0 ;
/ / r e g i s t e r e d o u t p u t s
// r e g hsync = 1 ’ b1 ;
// r e g vsync = 1 ’ b1 ;
// r e g b l a n k b = 1 ’ b1 ;
w i r e s y n c b ; / / c o n n e c t e d t o Vdd
w i r e f r a m e p u l s e ;
w i r e p i x e l
c l o c k ;
w i r e [ 9 : 0 ] n e x t
p i x e l c o u n t ;
w i r e [ 9 : 0 ] n e x t
l i n e c o u n t ;
r e g hsync = 1 ’ b1 ;
r e g vsync = 1 ’ b1 ;
114
r e g b l a n k b = 1 ’ b1 ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
i f ( ! r e s e t ) b e g i n
p i x e l c o u n t <= 10 ’b0 ;
l i n e c o u n t <= 10 ’b0 ;
hsync <= 1 ’ b1 ;
vsync <= 1 ’ b1 ;
b l a n k b <= 1 ’ b1 ;
end
e l s e begin
p i x e l c o u n t <= n e x t p i x e l c o u n t ;
l i n e c o u n t <= n e x t l i n e c o u n t ;
hsync <=
( n e x t p i x e l c o u n t < HACTIVE VIDEO + HFRONT PORCH ) |
( n e x t p i x e l c o u n t >= HACTIVE VIDEO+HFRONT PORCH+
HSYNC PERIOD) ;
vsync <=
( n e x t l i n e c o u n t < VACTIVE VIDEO+VFRONT PORCH ) |
( n e x t l i n e c o u n t >= VACTIVE VIDEO+VFRONT PORCH+
VSYNC PERIOD) ;
/ / t h i s i s t h e and o f hblank and vbla nk
b l a n k b <=
( n e x t p i x e l c o u n t < HACTIVE VIDEO) &
( n e x t l i n e c o u n t < VACTIVE VIDEO ) ;
end
end
/ / next s t a t e i s computed with c o m b i n a t i o n a l l o g i c
a s s i g n n e x t p i x e l c o u n t = ( p i x e l c o u n t == PIXELS−1) ?
1 0 ’ h000 : p i x e l c o u n t + 1 ’ b1 ;
a s s i g n n e x t l i n e c o u n t = ( p i x e l c o u n t == PIXELS−1) ?
( l i n e c o u n t == LINES − 1 ) ? 1 0 ’ h000 :
l i n e c o u n t + 1 ’ b1 : l i n e c o u n t ;
a s s i g n f r a m e p u l s e = ( ( p i x e l c o u n t == HACTIVE VIDEO−1) &&
( l i n e c o u n t == VACTIVE VIDEO− 1 ) ) ;
/ / s i n c e we a r e p r o v i d i n g hsync and vsync t o t h e d i s p l a y , we
/ / can h a r d w i r e c o m p o s i t e sync t o Vdd .
a s s i g n s y n c b = 1 ’ b1 ;
endmodule
115
module D i s p l a y F i e l d ( p i x e l c l o c k , r e s e t s y n c , p i x e l c o u n t , l i n e c o u n t , f 1 l i f e b a r ,
f1 energybar , f1 lhand x , f1 rhand x , f1 lhand y , f1 rhand y ,
f 1 l h s t a t u s , f 2 l h s t a t u s , f 2 l i f e b a r , f2 energybar , f2 status ,
red , g r een , blue , f r a m e p u l s e , mode , round , t i m e i n ) ;
input p i x e l c l o c k , reset
i n p u t [ 1 : 0 ] mode ;
i n p u t [ 3 : 0 ] round ;
i n p u t [ 9 : 0 ] l i n e
c o u n t ,
i n p u t [ 4 : 0 ] f 1
l i f e b a r ,
i n p u t [ 9 : 0 ] f 1
l h a n d x ,
i n p u t [ 4 : 0 ] f 2
s t a t u s ;
input
f 1
l h a n d y ,
input
f 1
l h s t a t u s
i n p u t [ 7 : 0 ] t i m e
i n ;
o utput [ 7 : 0 ] r ed ;
o utput [ 7 : 0 ] g r e e n ;
o utput [ 7 : 0 ] b l u e ;
s y n c , f r a m e p u l s e ;
p i x e l c o u n t ;
f 2 l i f e b a r , f 1 e n e r g y b a r , f 2 e n e r g y b a r ;
f 1 r h a n d x , f 2 p i c x , f 2 p i c y ;
f 1 r h a n d y ;
, f 1 r h s t a t u s ;
// c o l o r p a r a m e t e r s f o r RGB
pa r a meter
WHITE = 2 4 ’ h f f f f f f ;
pa r a meter
BLUE = 2 4 ’ h 0 0 0 0 f f ;
pa r a meter
LT BLUE = 2 4 ’ h 0 0 0 0 7 f ;
pa r a meter
RED = 2 4 ’ h f f 0 0 0 0 ;
pa r a meter
LT RED = 2 4 ’ h 7 f 0 0 0 0 ;
// p a r a m e t e r s
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
f o r widths , h e i g h t s , and s t a r t i n g p o i n t s
PLAYER2 PIXEL = 1 0 ’ d380 ;
PLAYER1 PIXEL = 1 0 ’ d4 ;
TIME PIXEL = 1 0 ’ d277 ;
COLON = 1 0 ’ d5 ;
BAR HEIGHT = 1 0 ’ d10 ;
TOP = 1 0 ’ d15 ;
ONE PLAYER = 1 0 ’ d0 ;
TWO PLAYER = 1 0 ’ d427 ;
SCREEN HEIGHT = 1 0 ’ d480 ;
SCREEN WIDTH = 1 0 ’ d640 ;
MODE WIDTH = 1 0 ’ d213 ;
// d e f i n i n g c o l o r s o f i n s t a n c e s o f t h e r e c t a n g l e module
defparam
f 1 e .COLOR = BLUE;
defparam
f 2 e .COLOR = BLUE;
defparam
f 1 l .COLOR = RED;
defparam
f 2 l .COLOR = RED;
defparam
f 2 l f a d e .COLOR = LT RED ;
defparam
f 1 l
f a d e .COLOR = LT RED ;
defparam
f 2 e
f a d e .COLOR = LT BLUE ;
defparam
f 1 e
f a d e .COLOR = LT BLUE ;
defparam
t o p c o l o n .COLOR = WHITE;
defparam
b o t t o m c o l o n .COLOR = WHITE;
defparam
o n e p l a y e r .COLOR = 2 4 ’ h0 f8 2 0 d ;
116
defparam
defparam
t w o p l a y e r .COLOR = 2 4 ’ h40d040 ;
ca r d .COLOR = WHITE;
// d e f i n i n g c o l o r s , widths , and h e i g h t s o f i n s t a n c e s o f t h e number module
1 0 ’ d59 ;
defparam
round num .HDIM =
1 0 ’ d79 ;
defparam
round num .VDIM =
defparam
round num .WIDTH = 1 0 ’ d10 ;
defparam
round num .SPACE = 1 0 ’ d24 ;
defparam
round num .COLOR = 2 4 ’ h000000 ;
defparam
round num .BACKGROUND = WHITE;
defparam
one .HDIM =
1 0 ’ d39 ;
defparam
one .VDIM =
1 0 ’ d59 ;
defparam
one .WIDTH = 1 0 ’ d6 ;
defparam
one .SPACE = 1 0 ’ d20 ;
defparam
two .HDIM =
1 0 ’ d39 ;
defparam
two .VDIM =
1 0 ’ d59 ;
defparam
two .WIDTH = 1 0 ’ d6 ;
defparam
two .SPACE = 1 0 ’ d20 ;
reg [ 7 : 0 ]
f 1 l
p i x e l s , f 2 l p i x e l s , f 1 e p i x e l s , f 2 e p i x e l s ;
wire
wire
wire
wire
wire
wire
enable ;
minutes ;
seconds ;
sec ones , s e c te n s ;
f1e width , f2e width ;
next f1l pixels , next f2l pixels , next f1e pixels ,
next f2e pixels ;
red , blue , g r e e n ;
red f1l , red f1e , red f2l , red f2e , red f1l fade , red f1e fade ,
r e d f 2 l f a d e , r e d f 2 e f a d e ,
red min , r e d
s e c t e n s , r e d s e c o n e s , r e d t o p c o l o n , r e d b o t t o m c o l o n ,
r e d b x r , r e d o n e p l a y e r ,
r e d
t w o p l a y e r , r ed r o und , r e d c a r d , r e d o n e , r ed two , g r e e n f 1 l ,
g r e e n f 1 e , g r e e n f 2 l , g r e e n f 2 e ,
g r e e n
f 1 l f a d e , g r e e n f 1 e f a d e , g r e e n f 2 l f a d e , g r e e n f 2 e f a d e ,
g r een min , g r e e n s e c t e n s ,
g r e e n
s e c o n e s , g r e e n t o p c o l o n , g r e e n b o t t o m c o l o n , g r e e n b x r ,
g r e e n o n e p l a y e r , g r e e n t w o p l a y e r ,
g r e e n r o u n d , g r e e n
c a r d , g r e e n o n e , g r een two , b l u e f 1 l , b l u e f 1 e ,
b l u e f 2 l , b l u e f 2 e , b l u e f 1 l f a d e ,
b l u e
f 1 e f a d e , b l u e f 2 l f a d e , b l u e f 2 e f a d e , blue min , b l u e s e c t e n s ,
b l u e s e c o n e s , b l u e t o p c o l o n ,
b l u e
b o t t o m c o l o n , b l u e b x r , b l u e o n e p l a y e r , b l u e t w o p l a y e r ,
blue round , blue card , blue one , blue two ;
[1:0]
[5:0]
[3:0]
[7:0]
[7:0]
wire [ 7 : 0 ]
wire [ 7 : 0 ]
wire [ 2 3 : 0 ]
f1 RGB , f2 RGB ;
// p l a y e r ’ s l i f e bar
117
rectangle f 1l ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER1 PIXEL+(10 ’ d260−n e x t f 1 l p i x e l s ) ) ,
. c o r n e r y (TOP) , . h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , n e x t f 1 l p i x e l s } ) ,
. r ed ( r e d f 1 l ) , . g r e e n ( g r e e n f 1 l ) ,
. b l u e ( b l u e
f 1 l ) , . b l i n k ( 1 ’ b0 ) ) ;
// opponent ’ s l i f e bar
rectangle f 2l ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER2 PIXEL ) , . c o r n e r y (TOP) ,
. h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , n e x t
f 2 l p i x e l s } ) , . r ed ( r e d f 2 l ) ,
. g r e e n ( g r e e n f 2 l ) , . b l u e ( b l u e f 2 l ) , . b l i n k ( 1 ’ b0 ) ) ;
// p l a y e r ’ s e n e r g y bar
rectangle f1e ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER1 PIXEL+(10 ’ d260−f 1 e w i d t h ) ) ,
. c o r n e r y (TOP+10 ’d15 ) , . h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , f 1 e w i d t h } ) ,
. r ed ( r e d f 1 e ) , . g r e e n ( g r e e n f 1 e ) ,
. b l u e ( b l u e f 1 e ) , . b l i n k ( 1 ’ b0 ) ) ;
// opponent ’ s e n e r g y bar
rectangle f2e ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER2 PIXEL ) , . c o r n e r y (TOP+10 ’d15 ) ,
. h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , f 2 e w i d t h } ) , . r ed ( r e d f 2 e ) ,
. g r e e n ( g r e e n f 2 e ) , . b l u e ( b l u e f 2 e ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module t h a t c a u s e s f a d e e f f e c t o f p l a y e r ’ s e n e r g y bar
rectangle f1e fade ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER1 PIXEL+(10 ’ d260−f 1 e p i x e l s ) ) ,
. c o r n e r y (TOP+10 ’d15 ) , . h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , f 1 e p i x e l s } ) ,
. r ed ( r e d f 1 e f a d e ) ,
. g r e e n ( g r e e n
f 1 e f a d e ) , . b l u e ( b l u e f 1 e f a d e ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module t h a t c a u s e s f a d e e f f e c t o f opponent ’ s e n e r g y bar
rectangle f2e fade ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER2 PIXEL ) , . c o r n e r y (TOP+10 ’d15 ) ,
. h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , f 2 e p i x e l s } ) , . r ed ( r e d f 2 e f a d e ) ,
. g r e e n ( g r e e n f 2 e f a d e ) ,
. b l u e ( b l u e
f 2 e f a d e ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module t h a t c a u s e s f a d e e f f e c t o f opponent ’ s l i f e bar
rectangle f 2l f ad e ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER2 PIXEL ) , . c o r n e r y (TOP) ,
. h e i g h t (BAR HEIGHT ) , . width ( { 2 ’ b0 , f 2 l p i x e l s } ) , . r ed ( r e d f 2 l f a d e ) ,
. g r e e n ( g r e e n f 2 l f a d e ) ,
. b l u e ( b l u e
f 2 l f a d e ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module t h a t c a u s e s f a d e e f f e c t o f p l a y e r ’ s l i f e bar
rectangle f 1l f ad e ( . pixel clock ( pixel clock ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (PLAYER1 PIXEL+(10 ’ d260−f 1 l p i x e l s ) ) ,
. c o r n e r y (TOP) , . h e i g h t (BAR HEIGHT ) ,
. width ( { 2 ’ b0 , f 1 l p i x e l s } ) ,
. r ed ( r e d f 1 l f a d e ) ,
. g r e e n ( g r e e n
f 1 l f a d e ) , . b l u e ( b l u e f 1 l f a d e ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module f o r one p l a y e r o p t i o n on s t a r t s c r e e n
rectangle one player ( . pix el clo ck ( pix el clo ck ) ,. x( pixel count ) ,. y( line count ) ,
. c o r n e r x (ONE PLAYER) , . c o r n e r y ( 1 0 ’ d0 ) ,
. h e i g h t (SCREEN HEIGHT) , . width (MODE WIDTH) , . r ed ( r e d o n e p l a y e r ) ,
. green ( green one player ) ,
118
. b l u e ( b l u e o n e p l a y e r ) , . b l i n k ( 1 ’ b0 ) ) ;
// r e c t a n g l e module f o r two p l a y e r o p t i o n on s t a r t s c r e e n
rectangle two player ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x( pixel count ) , . y( line count ) ,
. c o r n e r x (TWO PLAYER) , . c o r n e r y ( 1 0 ’ d0 ) ,
. h e i g h t (SCREEN HEIGHT) , . width (MODE WIDTH) , . r ed ( r e d t w o p l a y e r ) ,
. green ( green two player ) ,
. b l u e ( b l u e t w o p l a y e r ) , . b l i n k ( 1 ’ b0 ) ) ;
//number module f o r number one d i s p l a y e d o v e r t h e one p l a y e r o p t i o n on s t a r t s c r e e n
number one ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x (ONE PLAYER+10 ’d86 ) ,
. c o r n e r y ( 1 0 ’ d220 ) ,
. number ( 4 ’ d1 ) , . r ed ( r e d o n e ) , . g r e e n ( g r e e n o n e ) , . b l u e ( b l u e o n e ) ) ;
//number module f o r number two d i s p l a y e d o v e r t h e one p l a y e r o p t i o n on s t a r t s c r e e n
number two ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x (TWO PLAYER+10 ’d86 ) ,
. c o r n e r
y ( 1 0 ’ d220 ) ,
. number ( 4 ’ d2 ) , . r ed ( r e d t w o ) , . g r e e n ( g r e e n t w o ) , . b l u e ( b l u e t w o ) ) ;
// t i m e r module t o d e t e r m i n e t h e time l e f t i n minutes and s e c o n d s
t i m e r tm ( . p i x e l c l o c k ( p i x e l c l o c k ) , . r e s e t ( r e s e t s y n c ) , . minutes ( minutes ) ,
. seconds ( seconds ) , . time in ( time in ) ) ;
//number module f o r minutes i n t h e time l e f t d i s p l a y e d
number dmin ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x (TIME PIXEL ) , . c o r n e r y (TOP) ,
. number ( { 2 ’ b0 , minutes } ) , . r ed ( r ed min ) , . g r e e n ( g r e e n m i n ) , . b l u e ( b l u e m i n ) ) ;
//number module f o r t e n s o f t h e s e c o n d s i n t h e time l e f t d i s p l a y e d
number d s e c t e n s ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x (TIME PIXEL+10 ’d45 ) ,
. c o r n e r y (TOP) ,
. number ( s e c t e n s ) , . r ed ( r e d
s e c t e n s ) , . g r e e n ( g r e e n s e c t e n s ) ,
. blue ( b l u e s e c t e n s ) ) ;
//number module f o r o nes o f t h e s e c o n d s i n t h e time l e f t d i s p l a y e d
number d s e c o n e s ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x (TIME PIXEL+10 ’d75 ) ,
. c o r n e r y (TOP) ,
. number ( s e c o n e s ) , . r ed ( r e d
s e c o n e s ) , . g r e e n ( g r e e n s e c o n e s ) ,
. b l u e ( b l u e s e c o n e s ) ) ;
// r e c t a n g l e module f o r top c o l o n i n t h e time l e f t d i s p l a y e d
/ / ( b l i n k i n g b e c a u s e b l i n k i s s e t hig h )
r e c t a n g l e t o p c o l o n ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x ( p i x e l c o u n t ) , . y ( l i n e
c o u n t ) ,
. c o r n e r x (TIME PIXEL+10 ’d30 ) , . c o r n e r y (TOP+10 ’d5 ) , . h e i g h t (COLON) ,
. width (COLON) , . r ed ( r e d t o p c o l o n ) ,
. green ( g r e e n t o p c o l o n ) , . blue ( b l u e t o p c o l o n ) ,
. r e s e t s y n c ( r e s e t s y n c ) , . b l i n k ( 1 ’ b1 ) ) ;
// r e c t a n g l e module f o r bottom c o l o n i n t h e time l e f t d i s p l a y e d
/ / ( b l i n k i n g b e c a u s e b l i n k i s s e t hig h )
r e c t a n g l e b o t t o m
c o l o n ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) ,
. c o r n e r x (TIME PIXEL+10 ’d30 ) , . c o r n e r y (TOP+10 ’d15 ) ,
. h e i g h t (COLON) ,
. width (COLON) , . r ed ( r e d
b o t t o m c o l o n ) ,
. green ( green bottom colon ) , . blue ( blue bottom colon ) ,
. r e s e t s y n c ( r e s e t s y n c ) , . b l i n k ( 1 ’ b1 ) ) ;
// bo xing r i n g module t o d i s p l a y bo xing r i n g
b o x i n g r i n g bxr ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . r ed ( r e d b x r ) ,
. green ( green bxr ) , . blue ( blue bxr ) ) ;
119
//number module f o r round number d i s p l a y e d
number round num ( . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) , . c o r n e r x ( 1 0 ’ d290 ) , . c o r n e r y ( 1 0 ’ d200 ) ,
. number ( round ) , . r ed ( r e d r o u n d ) , . g r e e n ( g r e e n r o u n d ) , . b l u e ( b l u e r o u n d ) ) ;
// r e c t a n g l e module f o r round number ca r d d i s p l a y e d
r e c t a n g l e ca r d ( . p i x e l c l o c k ( p i x e l c l o c k ) , . x ( p i x e l c o u n t ) , . y ( l i n e c o u n t ) ,
. c o r n e r x ( 1 0 ’ d128 ) ,
. c o r n e r
y ( 1 0 ’ d80 ) , . h e i g h t ( 1 0 ’ d320 ) ,
. width ( 1 0 ’ d384 ) , . r ed ( r e d c a r d ) , . g r e e n ( g r e e n c a r d ) , . b l u e ( b l u e c a r d ) ,
. b l i n k ( 1 ’ b0 ) ) ;
// F i g h t e r 1 C o n t r o l module f o r p l a y e r g l o v e s d i s p l a y e d
Fighter1 Control f1c ( . p i x e l c l o c k ( p i x e l c l o c k ) , . reset ( reset sync ) ,
. line count ( line count ) ,
. pixel count ( pixel count ) , . f1 lhand x ( f1 lhand x ) ,
. f1 rhand x ( f1 rhand x ) ,
. f1 lhand y ( f1 lhand y ) ,
. lh status ( f1 lh status ) ,. rh status ( f1 rh status ) ,
. f1 rhand y ( f1 rhand y ) ,
.RGB( f1 RGB ) , . mode ( mode ) ) ;
// F i g h t e r 2 C o n t r o l module f o r opponent d i s p l a y e d
Fighter2 Control f2c ( . p i x e l c l o c k ( p i x e l c l o c k ) , . reset ( reset sync ) ,
. line count ( line count ) ,
. pixel count ( pixel count ) ,. pic x ( f2 pic x ) ,. pic y ( f2 pic y ) ,
. f 2 s t a t u s ( f 2 s t a t u s ) , .RGB( f2 RGB ) , . mode ( mode ) ) ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
// Decrements and i n c r e m e n t s t h e f a d e l i f e and e n e r g y b a r s by one u n t i l i t
// r ea ches the a ctua l
// e n e r g y and l i f e l e f t . I n c r e m e n t s t h e a c t u a l e n e r g y b a r s u n t i l i t r e a c h e s
// the a ctua l energy l e f t .
// C r e a t e s f a d e e f f e c t and makes t r a n s i t i o n s smoother .
i f ( ! r e s e t s y n c ) f 1 l p i x e l s <=n e x t f 1 l p i x e l s ;
e l s e i f ( ( f 1 l
p i x e l s >n e x t f 1 l p i x e l s )&& f r a m e p u l s e )
f 1 l
p i x e l s <= f 1 l p i x e l s −1;
i f ( ! r e s e t
s y n c ) f 1 e p i x e l s <=n e x t f 1 e p i x e l s ;
e l s e i f ( ( f 1 e
p i x e l s >n e x t f 1 e p i x e l s )&& f r a m e p u l s e )
f 1 e
p i x e l s <= f 1 e p i x e l s −1;
e l s e i f ( ( f 1 e
p i x e l s <n e x t f 1 e p i x e l s )&& f r a m e p u l s e )
f 1 e p i x e l s <= f 1 e p i x e l s +1;
i f ( ! r e s e t
s y n c ) f 2 l p i x e l s <= n e x t f 2 l p i x e l s ;
e l s e i f ( ( f 2 l
p i x e l s >n e x t f 2 l p i x e l s )&& f r a m e p u l s e )
f 2 l
p i x e l s <= f 2 l p i x e l s −1;
i f ( ! r e s e t
s y n c ) f 2 e p i x e l s <= n e x t f 2 e p i x e l s ;
e l s e i f ( ( f 2 e
p i x e l s >n e x t f 2 e p i x e l s ) && f r a m e p u l s e )
f 2 e
p i x e l s <= f 2 e p i x e l s −1;
e l s e i f ( ( f 2 e
p i x e l s <n e x t f 2 e p i x e l s ) && f r a m e p u l s e )
f 2 e
p i x e l s <= f 2 e p i x e l s +1;
end
// c o n v e r t s e n e r g y and l i f e
l e f t from 5 t o 8 b i t s
120
assign next
assign next
assign next
assign
// c a l c u l a t e s
assign
assign
f 1 l p i x e l s = { f 1 l i f e b a r , 3 ’ b0 } ;
f 2 l p i x e l s = { f 2 l i f e b a r , 3 ’ b0 } ;
f 1 e p i x e l s = { f 1 e n e r g y b a r , 3 ’ b0 } ;
n e x t
f 2 e p i x e l s = { f 2 e n e r g y b a r , 3 ’ b0 } ;
t h e e n e r g y bar widths
f 1 e w i d t h = ( f 1 e p i x e l s >=n e x t f 1 e p i x e l s ) ? n e x t f 1 e p i x e l s :
f 1 e
p i x e l s ;
f 2 e w i d t h = ( f 2 e p i x e l s >=n e x t f 2 e p i x e l s ) ? n e x t f 2 e p i x e l s :
f2e pixels ;
// computes red , g r een , and b l u e s i g n a l s ba sed on t h e mode
assign
r ed = ( ( mode==0) && (f1 RGB != 2 4 ’ d0 ) ) ? ( f1 RGB [ 2 3 : 1 6 ] ) :
( mode = = 0 ) ? ( r e d o n e p l a y e r | r e d t w o p l a y e r | r e d o n e | r e d t w o ) :
( ( mode==2)&&(( r e d r o u n d ==8’d0 ) | | ( r e d c a r d ==8’d0 ) ) ) ? 8 ’ d0 :
( mode = = 2 ) ? ( r e d r o u n d | r e d c a r d ) :
( f1 RGB != 2 4 ’ d0 ) ? ( f1 RGB [ 2 3 : 1 6 ] ) :
( f2 RGB != 2 4 ’ d0 ) ? ( f2 RGB [ 2 3 : 1 6 ] ) :
( r e d
f 1 l | r e d f 1 e | r e d f 2 l | r e d f 2 e | r e d f 1 l f a d e | r e d f 1 e f a d e | r e d f 2 l f a d
r e d f 2 e f a d e | r ed min | r e d s e c t e n s | r e d s e c o n e s | r e d t o p c o l o n |
red bottom colon | red bxr ) ;
assign
g r e e n = ( ( mode==0) && (f1 RGB != 2 4 ’ d0 ) ) ? ( f1 RGB [ 1 5 : 8 ] ) :
( mode= = 0 ) ? ( g r e e n o n e p l a y e r | g r e e n t w o p l a y e r | g r e e n o n e | g r e e n t w o )
( ( mode==2)&&(( g r e e n r o u n d ==8’d0 ) | | ( g r e e n c a r d ==8’d0 ) ) ) ? 8 ’ d0 :
( mode = = 2 ) ? ( g r e e n r o u n d | g r e e n c a r d ) :
( f1 RGB != 2 4 ’ d0 ) ? ( f1 RGB [ 1 5 : 8 ] ) :
( f2 RGB != 2 4 ’ d0 ) ? ( f2 RGB [ 1 5 : 8 ] ) :
( green f1l | green f1e | green f2l | green f2e | green f1l fade | green f1e fa
g r e e n f 2 l f a d e | g r e e n f 2 e f a d e | green min | g r e e n s e c t e n s | g r e e n s e c o n
g r e e n t o p c o l o n |
g r e e n
b o t t o m c o l o n | g r e e n b x r ) ;
assign
b l u e = ( ( mode==0) && (f1 RGB != 2 4 ’ d0 ) ) ? ( f1 RGB [ 7 : 0 ] ) :
( mode = = 0 ) ? ( b l u e o n e p l a y e r | b l u e t w o p l a y e r | b l u e o n e | b l u e t w o ) :
( ( mode==2)&&(( b l u e r o u n d ==8’d0 ) | | ( b l u e c a r d ==8’d0 ) ) ) ? 8 ’ d0 :
( mode = = 2 ) ? ( b l u e r o u n d | b l u e c a r d ) :
( f1 RGB != 2 4 ’ d0 ) ? ( f1 RGB [ 7 : 0 ] ) :
( f2 RGB != 2 4 ’ d0 ) ? ( f2 RGB [ 7 : 0 ] ) :
( blue f1l | blue f1e | blue f2l | blue f2e | blue f1l fade | blue f1e fade |
b l u e f 2 l f a d e |
b l u e
f 2 e f a d e | b l u e m i n | b l u e s e c t e n s | b l u e s e c o n e s | b l u e t o p c o l o n |
blue bottom colon | blue bxr ) ;
// computes t e n s o f t h e s e c o n d s
assign
s e c t e n s = ( ( seco nds >=0)&&(seco nds < 1 0 ) ) ? 0 :
( ( seco nds >=10)&&(seco nds < 2 0 ) ) ? 1
( ( seco nds >=20)&&(seco nds < 3 0 ) ) ? 2
( ( seco nds >=30)&&(seco nds < 4 0 ) ) ? 3
( ( seco nds >=40)&&(seco nds < 5 0 ) ) ? 4
( ( seco nds >=50)&&(seco nds < 6 0 ) ) ? 5
// computes o nes o f t h e s e c o n d s
121
:
:
:
:
: 0;
assign
s e c o n e s = ( seco nds −(10∗ s e c t e n s ) ) ;
endmodule
122
module F i g h t e r 1 C o n t r o l ( p i x e l c l o c k , r e s e t , l i n e c o u n t , p i x e l c o u n t , f 1 l h a n d x ,
f1 rhand x , f1 lhand y , f1 rhand y , lh status , rh status ,
mode , RGB) ;
i n p u t [ 9 : 0 ] l i n e c o u n t ;
i n p u t [ 9 : 0 ] p i x e l
c o u n t ;
input
p i x e l
c l o c k , r e s e t ;
i n p u t [ 9 : 0 ] f 1
l h a n d x , f 1 r h a n d x ;
input
f 1
l h a n d y , f 1 r h a n d y ;
input
l h
s t a t u s , r h s t a t u s ;
i n p u t [ 1 : 0 ] mode ;
o utput [ 2 3 : 0 ] RGB;
wire [ 2 3 : 0 ]
wire [ 9 : 0 ]
wire
wire
wire
wire
wire
wire [ 1 1 : 0 ]
wire [ 3 : 0 ]
reg
reg
reg
reg
reg
[11:0]
[11:0]
[13:0]
[23:0]
RGB;
r e n d p i x e l , l e n d p i x e l , l e n d l i n e , r e n d l i n e , next x , next y ,
lha nd y , r ha nd y ;
r i g h t h a n d ;
l e f t h a n d ;
r i g h t h a n d
n e x t ;
l e f t h a n d
n e x t ;
gm data , game over , g a m e
o v e r n e x t ;
a d d r e s s ;
g l o v e d a t a , g l o v e 0 d a t a , g l o v e 1 d a t a , g l o v e 2 d a t a , g l o v e 3 d a t a ;
r enable x , r enable y , l enable x , l enable y , g enable x ,
g e n a b l e y ;
l h a n d
a d d r e s s ;
r h a n d
a d d r e s s ;
g
a d d r e s s ;
da ta ;
//ROMS c o n t a i n i n g ima g es o f t h e p l a y e r ’ s g l o v e s
g l o v e 0
r o m g 0 r ( . addr ( l h a n d a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( g l o v e 0 d a t a
g l o v e 1 r o m g 1 r ( . addr ( l h a n d a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( g l o v e 1 d a t a
g l o v e 2 r o m g 2 r ( . addr ( r h a n d a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( g l o v e 2 d a t a
g l o v e 3 r o m g 3 r ( . addr ( r h a n d a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( g l o v e 3 d a t a
gameover rom gm1 ( . addr ( g a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( gm data ) ) ;
// d i m e n s i o n s o f t h e p i c t u r e s ( a f t e r b e i n g s c a l e d by 2 )
pa r a meter
PIC DIMENSION X = 1 0 0 ;
pa r a meter
PIC DIMENSION Y = 1 0 0 ;
// l a s t p i x e l co unt and l i n e co unt i n a frame
pa r a meter
PIXELS = 6 3 9 ;
pa r a meter
LINES = 4 7 9 ;
// c o l o r p a r a m e t e r s f o r RGB
pa r a meter
BLACK = 2 4 ’ b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 ;
pa r a meter
DK GRAY =24 ’ b 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1
0 1 0 0 ;
pa r a meter
GRAY=24 ’ b 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1
0 0 1 0 ;
pa r a meter
WHITE=24 ’ b 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 ;
123
));
));
));
));
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
DKR RED = 2 4 ’ b 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
DK RED=24 ’ b 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
RED=24 ’ b 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
LT RED=24 ’ b 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
LT BLUE=24 ’ b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 ;
// s t a r t i n g and ending l i n e and p i x e l o f t h e game o v e r image
/ / ( a f t e r b e i n g s c a l e d by 2 )
pa r a meter
G START LINE = 1 9 5 ;
pa r a meter
G START PIXEL = 8 0 ;
pa r a meter
G END LINE = 2 8 5 ;
pa r a meter
G END PIXEL = 5 6 0 ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
// Computes e n a b l e x f o r t h e l e f t g l o v e ROM which g o e s hig h e v e r y o t h e r
/ / c y c l e which e n a b l e s t h e
// a d d r e s s t o i n c r e m e n t t o t h e next a d d r e s s . This s c a l e s t h e image i n t h e
/ / ROM h o r i z o n t a l l y by two
i f ( ( n e x t
x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) l e n a b l e x <=1;
e l s e i f ( l e f t h a n d n e x t ) l
e n a b l e x <=˜l e n a b l e x ;
// Computes e n a b l e y f o r t h e l e f t g l o v e ROM which g o e s hig h e v e r y o t h e r l i n e
/ / which e n a b l e s t h e
// a d d r e s s t o i n c r e m e n t t o t h e next a d d r e s s on t h e next l i n e i n s t e a d o f f o r c i n g
/ / i t t o decrement t h e
// a d d r e s s by t h e number o f h o r i z o n t a l p i x e l s t h a t c o r r e s p o n d t o t h e image ’ s width .
/ / This s c a l e s t h e
// image i n t h e ROM v e r t i c a l l y by two
i f ( ( n e x t x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) l e n a b l e y <=1;
e l s e i f ( n e x t
x==l e n d p i x e l ) l e n a b l e y <=˜l e n a b l e y ;
// Computes t h e a d d r e s s f o r t h e l e f t g l o v e image
i f ( ( n e x t x==(f 1 l h a n d x −50))&&( l i n e c o u n t==l h a n d y ) ) l h a n d a d d r e s s <=12’d0 ;
e l s e i f ( ( next
y>=l h a n d y ) && ( n e x t x==(f 1 l h a n d x −50)) && l e n a b l e y )
l h a n d
a d d r e s s <=(l h a n d a d d r e s s −12 ’d49 ) ;
e l s e i f ( l e f t h a n d
n e x t && l e n a b l e x ) l h a n d a d d r e s s<=l h a n d a d d r e s s +1;
// Computes e n a b l e x f o r t h e r i g h t g l o v e ROM. . .
i f ( ( n e x t
x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) r e n a b l e x <=1;
e l s e i f ( r i g h t h a n d n e x t ) r
e n a b l e x <=˜r e n a b l e x ;
// Computes e n a b l e y f o r t h e r i g h t g l o v e ROM. . .
i f ( ( n e x t
x==(PIXELS−2)) && ( n e x t y==(LINES − 1 ) ) ) r e n a b l e y <=1;
e l s e i f ( n e x t
x==r e n d p i x e l ) r e n a b l e y <=˜r e n a b l e y ;
// Computes t h e a d d r e s s f o r t h e r i g h t g l o v e ROM
i f ( ( n e x t
x==(f 1 r h a n d x −50))&&( l i n e c o u n t==r ha nd y ) ) r h a n d a d d r e s s <=12’d0 ;
e l s e i f ( ( next
y>=r ha nd y ) && ( n e x t x==(f 1 r h a n d x −50)) && r e n a b l e y )
r h a n d
a d d r e s s <=(r h a n d a d d r e s s −12 ’d49 ) ;
e l s e i f ( r i g h t h a n d
n e x t && r e n a b l e x ) r h a n d a d d r e s s<=r h a n d a d d r e s s +1;
124
// Computes e n a b l e x f o r t h e game o v e r ROM. . .
i f ( ( n e x t
x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) g e n a b l e x <=1;
e l s e i f ( g a m e
o v e r n e x t ) g e n a b l e x <=˜g e n a b l e x ;
// Computes e n a b l e y f o r t h e game o v e r ROM. . .
i f ( ( n e x t
x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) g e n a b l e y <=1;
e l s e i f ( n e x t x==G END PIXEL ) g e n a b l e y <=˜g e n a b l e
y ;
// Computes t h e a d d r e s s f o r t h e game o v e r ROM
i f ( ( n e x t x==G START PIXEL)&&( l i n e c o u n t==G START LINE ) ) g a d d r e s s <=14’d0 ;
e l s e i f ( ( next y>=G START LINE) && ( n e x t x==G START PIXEL) && g e n a b l e y )
g a d d r e s s <=(g a d d r e s s −14 ’ d239 ) ;
e l s e i f ( g a m e
o v e r n e x t && g e n a b l e x ) g a d d r e s s<=g a d d r e s s +1;
// Computes t h e c o l o r ba sed
da ta <= ( g l o v e d a t a ==8) ?
( g l o v e
d a t a ==0) ?
( g l o v e
d a t a ==1) ?
( g l o v e
d a t a ==2) ?
( g l o v e
d a t a ==3) ?
( g l o v e
d a t a ==4) ?
( g l o v e
d a t a ==5) ?
( g l o v e
d a t a ==6) ?
on t h e 4− b i t number o u t p u t t e d from t h e ROM
LT BLUE :
BLACK :
DK GRAY:
GRAY:
WHITE:
DKR RED:
DK RED:
RED : LT RED ;
end
// Computes whether t h e c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e l e f t g l o v e
a s s i g n l e f t h a n d = ( ( p i x e l c o u n t <l e n d p i x e l )&&( p i x e l c o u n t >=(f 1 l h a n d x −50))&&
( l i n e c o u n t <l e n d l i n e )&&( l i n e c o u n t >=l h a n d y ) ) ;
// Computes whether t h e c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e r i g h t g l o v e
a s s i g n r i g h t h a n d = ( ( p i x e l c o u n t <r e n d p i x e l )&&( p i x e l c o u n t >=(f 1 r h a n d x −50))&&
( l i n e c o u n t <r e n d l i n e )&&( l i n e c o u n t >=r ha nd y ) ) ;
// Computes whether t h e next p o s i t i o n i s w i t h i n t h e boundary o f t h e l e f t g l o v e
a s s i g n l e f t h a n d n e x t = ( ( next x <l e n d p i x e l )&&( next x >=(f 1 l h a n d x −50))&&
( next y <l e n d l i n e )&&( next y>=l h a n d y ) ) ;
// Computes whether t h e next p o s i t i o n i s w i t h i n t h e boundary o f t h e r i g h t g l o v e
a s s i g n r i g h t h a n d n e x t = ( ( next x <r e n d p i x e l )&&( next x >=(f 1 r h a n d x −50))&&
( next y <r e n d l i n e )&&( next y>=r ha nd y ) ) ;
// Computes whether t h e c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e game o v e r image
a s s i g n game over = ( next x>=G START PIXEL)&&( next x <G END PIXEL)&&
( next y>=G START LINE) &&( next y <G END LINE ) ;
a s s i g n g a m e o v e r n e x t = ( p i x e l c o u n t >=G START PIXEL)&&( p i x e l c o u n t <G END PIXEL)&&
( l i n e c o u n t >=G START LINE)&&( l i n e c o u n t <G END LINE ) ;
// Computes whether t h e next p o s i t i o n i s w i t h i n t h e boundary o f t h e game o v e r image
a s s i g n n e x t x = ( p i x e l c o u n t == (PIXELS − 3 ) ) ? 1 0 ’ d0 : ( p i x e l c o u n t==(PIXELS − 2 ) ) ?
1 0 ’ d1 :
125
( p i x e l c o u n t==(PIXELS − 1 ) ) ? 1 0 ’ d2 : p i x e l c o u n t + 3 ;
a s s i g n n e x t y = ( ( p i x e l c o u n t >= (PIXELS−3))&&( p i x e l c o u n t <=(PIXELS − 1 ) ) ) ?
( l i n e c o u n t == (LINES − 1 ) ) ? 1 0 ’ d0 : l i n e c o u n t + 1 ’ b1 : l i n e c o u n t ;
// Deter mines which ROM t o r ea d from ba sed on t h e s t a t u s
a s s i g n g l o v e d a t a = ( game over && (mode==3) && gm data ) ? 4 ’ d8 :
( l e f t h a n d && l h s t a t u s ) ? g l o v e 1 d a t a :
( lefthand ? glove0 data :
( r i g h t h a n d && r h s t a t u s ) ? g l o v e 3 d a t a :
( r i g h t h a n d ) ? g l o v e 2 d a t a : 4 ’ b0 ;
// Computes t h e l a s t p i x e l o f t h e l i n e o f t h e l e f t g l o v e image
a s s i g n l e n d p i x e l = ( f 1 l h a n d x −50)+PIC DIMENSION X ;
// Computes t h e l a s t p i x e l o f t h e l i n e o f t h e r i g h t g l o v e image
a s s i g n r e n d p i x e l = ( f 1 r h a n d x −50)+PIC DIMENSION X ;
// Computes t h e l a s t l i n e o f t h e l e f t g l o v e image
a s s i g n l e n d l i n e = l h a n d y+PIC DIMENSION Y ;
// Computes t h e l a s t l i n e o f t h e r i g h t g l o v e image
a s s i g n r e n d l i n e = r ha nd y+PIC DIMENSION Y ;
// A s s i g n s RGB t h e da ta i f i t s c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e e i t h e r
/ / g l o v e o r t h e game o v e r image ,
// o t h e r w i s e i t a s s i g n s i t b l a c k
a s s i g n RGB = ( r i g h t h a n d | | l e f t h a n d | | game over ) ? da ta : 2 4 ’ h0 ;
// A s s i g n s t h e g l o v e s ’ y p o s i t i o n ba sed on a 1− b i t number
a s s i g n l h a n d y =( f 1 l h a n d y ) ? 1 0 ’ d125 : 1 0 ’ d235 ;
a s s i g n r ha nd y =( f 1 r h a n d y ) ? 1 0 ’ d125 : 1 0 ’ d235 ;
endmodule
126
module F i g h t e r 2 C o n t r o l ( p i x e l c l o c k , r e s e t , l i n e c o u n t , p i x e l c o u n t ,
p i c x , p i c y , f 2 s t a t u s , mode , RGB) ;
input p i x e l c l o c k ;
input r e s e t ;
i n p u t [ 1 : 0 ] mode ;
input [ 9 : 0 ] l i n e c o u n t ;
input [ 9 : 0 ] p i x e l c o u n t ;
input [ 9 : 0 ] pic x , p i c y ;
input [ 4 : 0 ] f 2 s t a t u s ;
o utput [ 2 3 : 0 ] RGB;
wire [ 2 3 : 0 ]
wire [ 9 : 0 ]
wire
wire
RGB;
e n d p i x e l , e n d l i n e , next x , n e x t y ;
fighter ;
fighter next ;
wire [ 3 : 0 ]
fighter data , fighter0 data , fighter1 data , fighter2 data , fighter3 data ,
fighter4 data , fighter5 data ,
fighter6 data , fighter7 data , fighter8 data , fighter9 data ,
fighter12 data , fighter13 data , fighter16 data , fighter17 data ,
fighter18 data , fighter19 data , fighter20 data , fighter21 data ,
fighter23 data , fighter24 data , fighter25 data ;
reg [ 1 4 : 0 ]
reg
reg [ 2 3 : 0 ]
address ;
enable x , enable y ;
da ta ;
//ROMs t h a t c o n t a i n t h e bitmaps o f t h e opponent
f i g h t e r 0 r o m f 0 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 0 d a t a ) ) ;
f i g h t e r 1 r o m f 1 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 1 d a t a ) ) ;
f i g h t e r 2 r o m f 2 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 d a t a ) ) ;
f i g h t e r 3 r o m f 3 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 3 d a t a ) ) ;
f i g h t e r 4 r o m f 4 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 4 d a t a ) ) ;
f i g h t e r 5 r o m f 5 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 5 d a t a ) ) ;
f i g h t e r 6 r o m f 6 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 6 d a t a ) ) ;
f i g h t e r 7 r o m f 7 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 7 d a t a ) ) ;
f i g h t e r 8 r o m f 8 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 8 d a t a ) ) ;
f i g h t e r 9 r o m f 9 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 9 d a t a ) ) ;
f i g h t e r 1 6 r o m f 1 6 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 1 6 d a t a
f i g h t e r 1 7 r o m f 1 7 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 1 7 d a t a
f i g h t e r 1 8 r o m f 1 8 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 1 8 d a t a
f i g h t e r 1 9 r o m f 1 9 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 1 9 d a t a
f i g h t e r 2 0 r o m f 2 0 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 0 d a t a
f i g h t e r 2 1 r o m f 2 1 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 1 d a t a
f i g h t e r 2 3 r o m f 2 3 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 3 d a t a
f i g h t e r 2 4 r o m f 2 4 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 4 d a t a
f i g h t e r 2 5 r o m f 2 5 r ( . addr ( a d d r e s s ) , . c l k ( p i x e l c l o c k ) , . dout ( f i g h t e r 2 5 d a t a
// d i m e n s i o n s o f t h e p i c t u r e s ( a f t e r b e i n g s c a l e d by 2 )
127
));
));
));
));
));
));
));
));
));
pa r a meter
pa r a meter
PIC DIMENSION X = 2 0 0 ;
PIC DIMENSION Y = 5 0 0 ;
// l a s t p i x e l co unt and l i n e co unt i n a frame
pa r a meter
PIXELS = 6 3 9 ;
pa r a meter
LINES = 4 7 9 ;
// c o l o r p a r a m e t e r s f o r RGB
pa r a meter
BLACK = 2 4 ’ b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 ;
pa r a meter
DK GRAY =24 ’ b 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 ;
pa r a meter
GRAY=24 ’ b 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 ;
pa r a meter
WHITE=24 ’ b 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ;
pa r a meter
DKR RED = 2 4 ’ b 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
DK RED=24 ’ b 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
RED=24 ’ b 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
LT RED=24 ’ b 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
DK BLUE=24 ’ b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 ;
pa r a meter
LT BLUE=24 ’ b 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 ;
pa r a meter
DKR BROWN=24 ’ b 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
DK BROWN=24 ’ b 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 ;
pa r a meter
LT BROWN=24 ’ b 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
pa r a meter
DK YELLOW=24 ’ b 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 ;
pa r a meter
LT YELLOW=24 ’ b 1 0 1 0 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
// Computes e n a b l e x which g o e s hig h e v e r y o t h e r c y c l e which e n a b l e s t h e
/ / a d d r e s s t o i n c r e m e n t t o t h e next a d d r e s s
// This s c a l e s t h e image i n t h e ROM h o r i z o n t a l l y by two
i f ( ( n e x t
x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) e n a b l e x <=1;
e l s e i f ( f i g h t e r
n e x t ) e n a b l e x <=˜e n a b l e x ;
// Computes e n a b l e y which g o e s hig h e v e r y o t h e r l i n e which e n a b l e s t h e a d d r e s s
/ / t o i n c r e m e n t t o t h e next a d d r e s s on
// t h e next l i n e i n s t e a d o f f o r c i n g i t t o decrement t h e a d d r e s s by t h e number o f
// h o r i z o n t a l p i x e l s that correspond
// t o t h e image ’ s width . This s c a l e s t h e image i n t h e ROM v e r t i c a l l y by two
i f ( ( n e x t x==(PIXELS−3)) && ( n e x t y==(LINES − 1 ) ) ) e n a b l e y <=1;
e l s e i f ( n e x t
x==e n d p i x e l ) e n a b l e y <=˜e n a b l e y ;
// Computes t h e a d d r e s s
i f ( ( n e x t
x==(p i c x −100))&&( l i n e c o u n t ==(p i c y − 2 5 0 ) ) ) a d d r e s s <=15’d0 ;
e l s e i f ( ( next
y >=(p i c y −250)) && ( n e x t x==(p i c x −100)) && e n a b l e y )
a d d r e s s <=(a d d r e s s −15 ’d99 ) ;
e l s e i f ( f i g h t e r
n e x t && e n a b l e x ) a d d r e s s<=a d d r e s s +1;
// Computes t h e c o l o r ba sed
da ta <= ( f i g h t e r d a t a ==0)
( f i g h t e r
d a t a ==1)
( f i g h t e r
d a t a ==2)
( f i g h t e r
d a t a ==3)
( f i g h t e r
d a t a ==4)
on t h e 4− b i t number o u t p u t t e d from t h e ROM
? BLACK :
? GRAY:
? WHITE:
? DK RED:
? RED:
128
( fighter
( f i g h t e r
( f i g h t e r
( f i g h t e r
( f i g h t e r
( f i g h t e r
( f i g h t e r
( f i g h t e r
( f i g h t e r
d a t a ==5) ? LT RED :
d a t a ==6) ? DK BLUE :
d a t a ==7) ? LT BLUE :
d a t a ==8) ? DK BROWN:
d a t a ==9) ? LT BROWN:
d a t a ==10) ? DK YELLOW:
d a t a ==12) ? DKR BROWN:
d a t a ==13) ? DKR RED :
d a t a ==14) ? DKR BROWN: LT YELLOW;
end
// Computes whether t h e next p o s i t i o n i s w i t h i n t h e boundary o f t h e opponent
a s s i g n f i g h t e r n e x t = ( next x >=(p i c x −100))&&( next x <e n d p i x e l )&&( next y >=(p i c y −250))
&&(next y <e n d l i n e ) ;
// Computes whether t h e c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e opponent
a s s i g n f i g h t e r = ( p i x e l c o u n t >=(p i c x −100))&&( p i x e l c o u n t <e n d p i x e l)&&
( l i n e c o u n t >=(p i c y −250))&&( l i n e c o u n t <e n d l i n e ) ;
// Computes t h e next p o s i t i o n
a s s i g n n e x t x = ( p i x e l c o u n t == (PIXELS − 3 ) ) ? 1 0 ’ d0
1 0 ’ d1 :
( p i x e l
c o u n t==(PIXELS − 1 ) ) ? 1 0 ’ d2 :
a s s i g n n e x t y = ( ( p i x e l c o u n t >= (PIXELS−3))&&( p i x e l
( l i n e c o u n t == (LINES − 1 ) ) ? 1 0 ’ d0 :
: ( p i x e l c o u n t==(PIXELS − 2 ) ) ?
pixel count + 3;
c o u n t <=(PIXELS − 1 ) ) ) ?
l i n e c o u n t + 1 ’ b1 : l i n e c o u n t ;
// Computes t h e l a s t l i n e o f t h e image
a s s i g n e n d l i n e = p i c y+PIC DIMENSION Y−250;
// Computes t h e l a s t p i x e l o f t h e l i n e o f t h e image
a s s i g n e n d p i x e l = p i c x+PIC DIMENSION X−100;
// A s s i g n s RGB t h e da ta i f i t s c u r r e n t p o s i t i o n i s w i t h i n t h e boundary o f t h e opponent ,
/ / o t h e r w i s e i t a s s i g n s i t b l a c k
a s s i g n RGB = ( f i g h t e r ) ? da ta : 2 4 ’ h0 ;
// Deter mines which ROM t o r ea d from ba sed on t h e s t a t u s
a s s i g n f i g h t e r d a t a = ( ( f 2 s t a t u s = = 0 )||( f 2 s t a t u s = = 2 2 )) ? f i g h t e r 0 d a t a :
( f 2 s t a t u s ==1) ? f i g h t e r 1 d a t a :
( f 2 s t a t u s ==2) ? f i g h t e r 2 d a t a :
( f 2 s t a t u s ==3) ? f i g h t e r 3 d a t a :
( f 2 s t a t u s ==4) ? f i g h t e r 4 d a t a :
( f 2 s t a t u s ==5) ? f i g h t e r 5 d a t a :
( ( f 2 s t a t u s = = 6 )||( f 2 s t a t u s = = 1 0 )||( f 2 s t a t u s ==14)) ?
fighter6 data :
( ( f 2 s t a t u s = = 7 )||( f 2 s t a t u s = = 1 1 )||( f 2 s t a t u s ==15)) ?
fighter7 data :
( ( f 2 s t a t u s = = 8 )||( f 2 s t a t u s = = 1 2 )) ? f i g h t e r 8 d a t a :
( ( f 2 s t a t u s = = 9 )||( f 2 s t a t u s = = 1 3 )) ? f i g h t e r 9 d a t a :
( f 2 s t a t u s ==16) ? f i g h t e r 1 6 d a t a :
( f 2 s t a t u s ==17) ? f i g h t e r 1 7 d a t a :
129
( f2
( f2
( f2
( f2
( f2
( f2
s t a t u s ==18)
s t a t u s ==19)
s t a t u s ==20)
s t a t u s ==21)
s t a t u s ==23)
s t a t u s ==24)
endmodule
130
?
?
?
?
?
?
fighter18
fighter19
fighter20
fighter21
fighter23
fighter24
data
data
data
data
data
data
:
:
:
:
:
: fighter25 data ;
//
a
//
−−−−
//
|
|
//
f | g | b
//
−−−−
//
|
|
//
e |
| c
//
−−−−
//
d
module number ( x , y , c o r n e r x , c o r n e r y , num , red , g r een , b l u e ) ;
i n p u t [ 9 : 0 ] x , y , c o r n e r
x , c o r n e r y ;
input [ 3 : 0 ]
num ;
o utput [ 7 : 0 ] r ed ;
o utput [ 7 : 0 ] g r e e n ;
o utput [ 7 : 0 ] b l u e ;
reg [ 2 3 : 0 ]
RGB;
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
pa r a meter
ZERO = 0 ;
ONE = 1 ;
TWO = 2 ;
THREE = 3 ;
FOUR = 4 ;
FIVE = 5 ;
SIX = 6 ;
SEVEN = 7 ;
EIGHT = 8 ;
NINE = 9 ;
HDIM = 1 4 ;
VDIM = 2 4 ;
WIDTH = 3 ;
SPACE = 6 ;
COLOR = 2 4 ’ h f f f f f f ;
BACKGROUND = 2 4 ’ d0 ;
wire
a , b , c , d , e , f , g ; / / seg ments a s d e f i n e d above
a lwa ys @ ( num o r a o r b o r c o r d o r e o r f o r g ) b e g i n
c a s e ( num)
ZERO:
RGB = ( a | | b | | c | | d | | e | | f ) ? COLOR : BACKGROUND;
ONE:
RGB = ( b | | c ) ? COLOR :
BACKGROUND;
TWO:
RGB = ( a | | b | | d | | e | | g ) ? COLOR : BACKGROUND;
THREE: RGB = ( a | | b | | c | | d | | g ) ? COLOR : BACKGROUND;
FOUR:
RGB = ( b | | c | | f | | g ) ? COLOR : BACKGROUND;
FIVE :
RGB = ( a | | c | | d | | f | | g ) ? COLOR : BACKGROUND;
SIX :
RGB = ( a | | c | | d | | e | | f | | g ) ? COLOR : BACKGROUND;
SEVEN: RGB = ( a | | b | | c ) ? COLOR : BACKGROUND;
EIGHT : RGB = ( a | | b | | c | | d | | e | | f | | g ) ? COLOR : BACKGROUND;
NINE :
RGB = ( a | | b | | c | | d | | f | | g ) ? COLOR : BACKGROUND;
d e f a u l t : RGB = BACKGROUND;
e n d c a s e
131
end
a s s i g n a = ( ( x>=(c o r n e r x+WIDTH))&&(x<=(c o r n e r x+HDIM−WIDTH))&&(y>=c o r n e r y )
&&(y<=(c o r n e r y+WIDTH ) ) ) ;
a s s i g n b = ( ( x>=(c o r n e r x+HDIM−WIDTH))&&(x<=(c o r n e r x+HDIM))&&
( y>=(c o r n e r y+WIDTH))&&(y<=(c o r n e r y+WIDTH+SPACE ) ) ) ;
a s s i g n c = ( ( x>=(c o r n e r
x+HDIM−WIDTH))&&(x<=(c o r n e r x+HDIM))&&
( y>=(c o r n e r y +2∗WIDTH+SPACE))&&(y<=(c o r n e r y+VDIM−WIDTH ) ) ) ;
a s s i g n d = ( ( x>=(c o r n e r x+WIDTH))&&(x<=(c o r n e r
x+HDIM−WIDTH))&&
( y>=(c o r n e r y+VDIM−WIDTH))&&(y<=(c o r n e r y+VDIM ) ) ) ;
a s s i g n e = ( ( x>=c o r n e r
x )&&(x<=(c o r n e r x+WIDTH))&&(y>=(c o r n e r y +2∗WIDTH+SPACE) )
&&(y<=(c o r n e r y+VDIM−WIDTH ) ) ) ;
a s s i g n f = ( ( x>=c o r n e r
x )&&(x<=(c o r n e r x+WIDTH))&&(y>=(c o r n e r y+WIDTH))&&
( y<=(c o r n e r y+WIDTH+SPACE ) ) ) ;
a s s i g n g = ( ( x>=(c o r n e r x+WIDTH))&&(x<=(c o r n e r
x+HDIM−WIDTH))&&
( y>=(c o r n e r y+WIDTH+SPACE))&&(y<=(c o r n e r y +2∗WIDTH+SPACE ) ) ) ;
a s s i g n r ed = RGB[ 2 3 : 1 6 ] ;
a s s i g n g r e e n = RGB[ 1 5 : 8 ] ;
a s s i g n b l u e = RGB [ 7 : 0 ] ;
endmodule
132
module r e c t a n g l e ( p i x e l c l o c k , r e s e t , x , y , c o r n e r x , c o r n e r y , h e i g h t , width , red , g r een ,
blue , b l i n k ) ;
i n p u t p i x e l
c l o c k , r e s e t , b l i n k ;
i n p u t [ 9 : 0 ] x , y , c o r n e r
x , c o r n e r y , h e i g h t , width ;
o utput [ 7 : 0 ] red , g r een , b l u e ;
wire [ 7 : 0 ]
wire [ 2 3 : 0 ]
red , g r een , b l u e ;
RGB;
pa r a meter
defparam
COLOR=24 ’ b 0 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 ;
c t . endcount = 2 5 1 7 4 9 9 9 ;
counter ct ( . clk ( p i x e l c l o c k ) , . Reset Sync ( r e s e t ) , . enable ( enable ) ) ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
i f ( ! r e s e t
s y n c ) co unter <=0;
e l s e i f ( e n a b l e && ( c o u n t e r==2) && b l i n k ) co unter <=0;
e l s e i f ( e n a b l e && b l i n k ) co unter <=(c o u n t e r + 1 );
end
a s s i g n RGB = ( ( x>=c o r n e r
( y<( c o r n e r
a s s i g n RGB = ( ( x>=c o r n e r
( y<( c o r n e r
x ) && ( y>=c o r n e r y ) && ( x<( c o r n e r x+width )) &&
y+h e i g h t )) & & ( c o u n t e r ! = 2 ) ) ? COLOR : 2 4 ’ h0 ;
x ) && ( y>=c o r n e r y ) && ( x<( c o r n e r x+width )) &&
y+h e i g h t ) ) ) ? COLOR : 2 4 ’ h0 ;
a s s i g n r ed = RGB[ 2 3 : 1 6 ] ;
a s s i g n g r e e n = RGB[ 1 5 : 8 ] ;
a s s i g n b l u e = RGB [ 7 : 0 ] ;
endmodule
133
module t i m e r ( p i x e l c l o c k , r e s e t , mode , minutes , s e c o n d s ) ;
i n p u t p i x e l
c l o c k ;
i n p u t r e s e t ;
i n p u t mode ;
o utput [ 1 : 0 ] minutes ;
o utput [ 5 : 0 ] s e c o n d s ;
r e g e n a b l e ;
r e g [ 7 : 0 ] c o u n t e r ;
a lwa ys @ ( po sedg e p i x e l c l o c k ) b e g i n
i f ( ! r e s e t ) co unter <=180;
e l s e i f ( e n a b l e && ( c o u n t e r ==0)) co unter <=0;
e l s e i f ( e n a b l e ) co unter <=co unter −1;
if (!
else
else
else
r e s e t ) minutes <=3;
i f ( ( c o u n t e r ==180) && e n a b l e ) minutes <=2;
i f ( ( c o u n t e r ==121) && e n a b l e ) minutes <=1;
i f ( ( c o u n t e r ==61) && e n a b l e ) minutes <=0;
if (!
else
else
else
r e s e t ) seco nds <=0;
i f ( ( s e c o n d s ==0) && e n a b l e && ( minutes ! = 0 ) ) seco nds <=59;
i f ( ( s e c o n d s ==0) && e n a b l e ) seco nds <=0;
i f ( e n a b l e ) seco nds <=seco nds −1;
end
endmodule
134
‘ t i m e s c a l e 1 ns / 1 ps
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
/ / Company :
// Engineer :
//
/ / Cr ea te Date :
14:18:06 04/23/06
/ / Desig n Name :
/ / Module Name :
top
/ / P r o j e c t Name :
/ / Ta r g et Device :
/ / Tool v e r s i o n s :
// Description :
//
/ / Dependencies :
//
// Revision :
/ / R e v i s i o n 0 . 0 1 − F i l e Cr ea ted
/ / A d d i t i o n a l Comments :
//
/ / / / / / / / / / / / / / / / / / / / / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / / // / // / // / / // / // /
module top ( p i x e l c l o c k , r e s e t s y n c , round , mode , f 1 l h a n d x , f 1 r h a n d x , f 1 l h a n d y ,
f1 rhand y , f 1 l h s t a t u s , f1 rh status , f 1 l i f e b a r , f1 energybar , f2 pic x ,
f 2 p i c y , f 2 s t a t u s , f 2 l i f e b a r , f 2 e n e r g y b a r , hsync , vsync ,
sync b , bla nk b , red , g r een , blue , p i x e l c o u n t , l i n e c o u n t , t i m e i n ,
frame pulse ) ;
i n p u t p i x e l c l o c k ;
i n p u t r e s e t
s y n c ;
i n p u t [ 1 : 0 ] mode ;
i n p u t [ 3 : 0 ] round ;
i n p u t [ 4 : 0 ] f 1
l i f e b a r , f 1 e n e r g y b a r , f 2 l i f e b a r , f 2 e n e r g y b a r ;
i n p u t [ 9 : 0 ] f 1
l h a n d x , f 1 r h a n d x , f 2 p i c x , f 2 p i c y ;
i n p u t [ 4 : 0 ] f 2
s t a t u s ;
input
f 1
l h a n d y , f 1 r h a n d y ;
input
f 1
l h s t a t u s , f 1 r h s t a t u s ;
i n p u t [ 7 : 0 ] t i m e
i n ;
o utput
hsync , vsync , sync b , bla nk
b , f r a m e p u l s e ;
o utput [ 7 : 0 ] red , g r een , b l u e ;
o utput [ 9 : 0 ] p i x e l
c o u n t , l i n e c o u n t ;
wire [ 9 : 0 ]
wire [ 2 3 : 0 ]
wire
p i x e l c o u n t , l i n e c o u n t ;
f1 RGB , f2 RGB ;
r e s e t
s y n c , f r a m e p u l s e ;
Display Field df ( . p i x e l c l o c k ( p i x e l c l o c k ) , . r e s e t s y n c ( r e s e t s y n c ) ,
. pixel count ( pixel count ) ,. line count ( line count ) ,
. f 1 l i f e b a r ( f 1 l i f e b a r ) , . f1 energybar ( f1 energybar ) ,
. f 2 l i f e b a r ( f 2 l i f e b a r ) , . f2 energybar ( f2 energybar ) ,
. f1 lhand x ( f1 lhand x ) , . f1 rhand x ( f1 rhand x ) ,
. f1 lhand y ( f1 lhand y ) , . lh status ( f1 l h s ta tu s ) ,
. rh status ( f 1 r h s t a t u s ) , . f1 rhand y ( f1 rhand y ) ,
135
. f2 pic x ( f2 pic x ) ,. f2 pic y ( f2 pic y ) ,. f2 status ( f2 status ) ,
. r ed ( r ed ) , . g r e e n ( g r e e n ) , . b l u e ( b l u e ) , . f r a m e p u l s e ( f r a m e p u l s e ) ,
. mode ( mode ) , . round ( round ) , . t i m e i n ( t i m e i n ) ) ;
vga vga1 ( . p i x e l c l o c k ( p i x e l c l o c k ) , . r e s e t ( r e s e t s y n c ) , . hsync ( hsync ) , . vsync ( vsync ) ,
. sync b ( sync b ) , . blank b ( blank b ) , . p i x e l c o u n t ( p i x e l c o u n t ) ,
. line count ( line count ) , . frame pulse ( frame pulse ) ) ;
endmodule
136
impo r t
impo r t
impo r t
impo r t
impo r t
impo r t
impo r t
j a v a . awt . image . B u f f e r e d I m a g e ;
j a v a . i o . B u f f e r e d W r i t e r ;
j a v a . i o . F i l e ;
j a v a . i o . F i l e W r i t e r ;
j a v a . i o . IO E xceptio n ;
j a v a . u t i l . ∗ ;
j a v a . u t i l . A r r a y L i s t ;
impo r t j a v a x . i m a g e i o . ImageIO ;
/∗∗
∗
∗/
/∗∗
∗ @author David Blau
∗
∗/
p u b l i c c l a s s NewImageConvert {
/∗∗
∗ @param a r g s
∗/
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {
f o r ( i n t i = 0 ; i < 4 ; i ++){
S t r i n g i m a g e f i l e n a m e , c o e f i l e n a m e ;
i f ( i <10){
i m a g e f i l e n a m e = ” g l o v e 0 0 0”+ i +”.bmp ” ;
c o e f i l e n a m e = ” newcoe/ g l o v e ”+ i +”. c o e ” ;
}
else {
i m a g e f i l e n a m e = ” f i g h t e r 0 0”+ i +”.bmp ” ;
c o e f i l e n a m e = ” newcoe/ f i g h t e r ”+ i +”. c o e ” ;
}
// L i s t <S t r i n g > e l e m e n t s = new A r r a y L i s t<S t r i n g > ( ) ;
i f ( args . length !=0) {
imagefilename = args [ 0 ] ;
coefilename = args [ 1 ] ;
}
F i l e i m a g e F i l e = new F i l e ( i m a g e f i l e n a m e ) ;
B u f f e r e d I m a g e image = n u l l ;
t r y {
image = ImageIO . r ea d ( i m a g e F i l e ) ;
} c a t c h ( IO E xception i o e ) {
System . e r r . p r i n t l n ( ” E r r o r r e a d i n g image : ” + i m a g e f i l e n a m e ) ;
return ;
}
i n t h e i g h t = image . g e t H e i g h t ( ) ;
137
i n t width = image . getWidth ( ) ;
i n t rgb =0;
S t r i n g r g b S t r i n g ;
i n t r ed ;
i n t g r e e n ;
i n t b l u e ;
S t r i n g o u t p u t S t r i n g ;
i f ( ! c o e f i l e n a m e . endsWith ( ” . c o e ” ) ) c o e f i l e n a m e +=”. c o e ” ;
try {
B u f f e r e d W r i t e r out = new B u f f e r e d W r i t e r ( new F i l e W r i t e r ( c o e f i l e n a m e ) ) ;
out . w r i t e ( ” m e m o r y i n i t i a l i z a t i o n r a d i x =2;\n”+
” m e m o r y i n i t i a l i z a t i o n v e c t o r =\n\n ” ) ;
f o r ( i n t y=0;y<h e i g h t ; y++){
f o r ( i n t x=0;x<width ; x++){
rgb = image . getRGB ( x , y ) ;
r g b S t r i n g = I n t e g e r . t o B i n a r y S t r i n g ( rgb ) ;
// System . out . p r i n t l n ( r g b S t r i n g ) ;
r ed = I n t e g e r . p a r s e I n t ( r g b S t r i n g . s u b s t r i n g ( 8 , 1 1 ) , 2 ) ;
g r e e n = I n t e g e r . p a r s e I n t ( r g b S t r i n g . s u b s t r i n g ( 1 6 , 1 9 ) , 2 ) ;
b l u e = I n t e g e r . p a r s e I n t ( r g b S t r i n g . s u b s t r i n g ( 2 4 , 2 7 ) , 2 ) ;
System . out . p r i n t l n ( r ed ) ;
i f ( ( r ed==g r e e n ) && ( g r e e n==b l u e ) ) {
i f ( r ed ==0) o u t p u t S t r i n g =”0000”;
e l s e i f ( red <3) o u t p u t S t r i n g = ” 1 1 0 0 ” ;
e l s e i f ( red <6) o u t p u t S t r i n g =”0001”;
e l s e o u t p u t S t r i n g =”0010”;
}
e l s e i f ( ( g r e e n==0)&&(b l u e ==0)){
i f ( r ed ==1) o u t p u t S t r i n g =”1101”;
e l s e i f ( red <4) o u t p u t S t r i n g =”0011”;
e l s e i f ( red <6) o u t p u t S t r i n g =”0100”;
e l s e outputString = ”0101”;
}
e l s e i f ( ( r ed==0)&&(g r e e n ==0)){
i f ( blue <2) o u t p u t S t r i n g =”1100”;
e l s e i f ( blue <5) o u t p u t S t r i n g =”0110”;
e l s e o u t p u t S t r i n g =”0111”;
}
e l s e i f ( ( ( red −1)==g r e e n )&&(( g r een −1)==b l u e ) ) {
i f ( red <3) o u t p u t S t r i n g = ” 1 1 1 0 ” ;
e l s e i f ( red <5) o u t p u t S t r i n g =”1000”;
e l s e o u t p u t S t r i n g =”1001”;
}
e l s e i f ( ( r ed==g r e e n ) && ( blue<r ed ) ) {
i f ( red <3) o u t p u t S t r i n g =”1100”;
e l s e i f ( ( red <5) && ( red−blue > 1 )) o u t p u t S t r i n g =”1010”;
e l s e i f ( red−blue >1) o u t p u t S t r i n g =”1011”;
e l s e i f ( red <6) o u t p u t S t r i n g =”0001”;
138
e l s e o u t p u t S t r i n g =”0010”;
}
e l s e i f ( ( red>g r e e n ) && ( red>b l u e ) && ( g r e e n != b l u e ) ) {
i f ( red <3) o u t p u t S t r i n g =”1110”;
e l s e i f ( red <5) o u t p u t S t r i n g =”1000”;
e l s e o u t p u t S t r i n g =”1001”;
}
e l s e i f ( ( red>g r e e n )&&(red>b l u e ) ) {
i f ( r ed ==1) o u t p u t S t r i n g =”1101”;
e l s e i f ( red <4) o u t p u t S t r i n g =”0011”;
e l s e i f ( red <6) o u t p u t S t r i n g =”0100”;
e l s e outputString = ”0101”;
}
e l s e i f ( ( g r een>r ed ) && ( g r een>b l u e ) ) {
i f ( g r een <3) o u t p u t S t r i n g =”1110”;
e l s e i f ( ( g r een <5) && (( g r een−b l u e ) > 1 ) ) o u t p u t S t r i n g =”1010”;
e l s e i f ( ( g r een−b l u e ) >1) o u t p u t S t r i n g =”1011”;
e l s e i f ( g r een <6) o u t p u t S t r i n g =”0001”;
e l s e o u t p u t S t r i n g =”0010”;
}
e l s e i f ( ( blue>r ed ) && ( blue>g r e e n ) ) {
i f ( blue <2) o u t p u t S t r i n g =”1100”;
e l s e i f ( blue <5) o u t p u t S t r i n g =”0110”;
e l s e o u t p u t S t r i n g =”0111”;
}
else {
i f ( blue <3) o u t p u t S t r i n g =”1100”;
e l s e i f ( blue <6) o u t p u t S t r i n g =”0001”;
e l s e o u t p u t S t r i n g =”0010”;
}
w h i l e ( r g b S t r i n g . l e n g t h () <8)
r g b S t r i n g = ”0”+ r g b S t r i n g ;
// i f ( ! e l e m e n t s . c o n t a i n s ( o u t p u t S t r i n g ) ) {
// e l e m e n t s . add ( o u t p u t S t r i n g ) ;
i f ( x==width −1 && y==h e i g h t −1)
out . w r i t e ( o u t p u t S t r i n g +”;\n ” ) ;
else
out . w r i t e ( o u t p u t S t r i n g +” ,\n ” ) ;
//}
}
}
out . c l o s e ( ) ;
} c a t c h ( IO E xception e ) {
System . e r r . p r i n t l n ( ” E r r o r w r i t i n g c o e : ” + c o e f i l e n a m e ) ;
}
}
}
}
139
Download