Title: BlackJack On The W8Y 3.0
1BlackJack On The W8Y 3.0
Prepared by Alok Vimawala Dan Scheutz Hani
Nadra CSE 378, Fall 2001
2The W8Y 3.0
R
M
T
P1
Microcontroller
0
0
1
1
Rmux
Pmux
psel
rinsel
Rin
Pin
clr
rsel
BTNchk
BTN(14)
clk
rload
clr
pload
PC
rdec
pushed
clk
pinc
clr
clr
ReturnStack
rand_cnt
plus1
P
clk
clk_2
T(30)
rpush
rpop
clk
Ram 16x12
N
BTNsig
W8Y_rom
Rand
we
E
R
M
T(70)
M
4
clr
1
0
2
3
DSmux
LDreg
ldload
clk
dssel(10)
clr
IR
DS
irload
clk
LD(18)
tload
T
icode
nload
nsel
T(70)
N(70)
ssel
R
clr
clr
clk
DataStack_ALU
bcdreg
BCDload
clk
dpush
T
dpop
TBCD
NBCD
BTN(14)
clk
W8Y_control
tsel(10)
osc_4k
M
clr
clk_2
step_display
clr
alusel(30)
clk
clk
pushed
SW(1)
clr
A(30)
AtoG(60)
3New Instructions
clr
rand_cnt
clk_2
clr
T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
4New Instructions
clr
rand_cnt
clk_2
clr
-- Fetch a random number and push -- it on the
stack when randfrom dssel T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
5New Instructions
clr
rand_cnt
clk_2
-- Push ones on Data_Stack if a button -- is
pushed, zeros otherwise when qbtn if (
pushed '1' ) then alusel else alusel nload clr
T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
6New Instructions
clr
rand_cnt
clk_2
clr
-- Push the number of the last button -- pushed
on the Data_Stack when getbtn tload tsel dpush T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
7New Instructions
T(70)
N(70)
BCDreg
clk
Nhextobcd
Thextobcd
BCDload
clk
clk
clr
clr
Nbcdreg
Tbcdreg
clr
BCDload
BCDload
-- Display N and T when display BCDload '1'
Nbcd(74)
Nbcd(30)
Tbcd(74)
Tbcd(30)
step_display
dig1(30)
dig2(30)
dig3(30)
dig4(30)
clk
anode
dig2
dig3
dig1
dig4
"1111"
clr
dig7seg
A(41)
AtoG(60)
8New Instructions
clr
rand_cnt
clk_2
clr
-- Fetch word at memory address T, -- pop T, and
push the word on Stack when cfetch
tload T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
9New Instructions
clr
rand_cnt
clk_2
clr
-- Store the word in N at memory -- address T,
and pop the stack -- ( word stays in
T ) when cstore ram_we "11" tload '1' dpop T(30)
BTNchk
BTN(14)
clk
pushed
clk
Ram 16x12
N
we
Rand
BTNsig
E
R
M
4
1
0
2
3
DSmux
dssel(10)
DS
tload
T
nload
nsel
ssel
N
clr
clk
DataStack_ALU
dpush
dpop
tsel(10)
alusel(30)
10WHYP Subroutines
- Delay and Comparisons.
- Memory manipulations.
- Cards Dealing.
- Display Subroutines.
- Updating Scores.
- Main Subroutine.
11Delay and Comparisons
- DELAY ( -- ) (delay)
- ( n1 n2 -- f ) (greater-than)
- ( n1 n2 -- f ) (equals)
- ( n1 n2 -- f ) (greater or equal)
- get.next.btn ( -- n ) (get BTN pushed)
12Memory Manipulations
- Push on Stack
- HSUM ( -- HSUM )
- 2 C_at_
- Move T to RAM
- PSCR ( w -- )
- 1 C! DROP
- Copy T into RAM
- HFACE ( w -- w )
- 3 C!
13Cards Dealing
- Push a card on Stack
- CARD ( -- card )
- RAND / push rnd / rnd
- DUP A / rnd rnd 0A
- / rnd flag
- IF / if (rnd 10) / rnd
- DROP A / drop it and push 10 / 0A
- THEN / card
14Cards Dealing
- Deal card to player
- CARDTOP ( -- )
- CARD / push a card on Stack
- DUP 1
- IF / if its an Ace
- PSUM B
- IF / if the player sum
- DROP B / count Ace as 11
- THEN
- THEN
- PSUM PSUM / update PSUM
15Display Subroutines
- OUT_HFACE_PSUM ( -- )
- HFACE PSUM
- DISPLAY
- DROP DROP
- AF LD! DROP
OUT_HSUM_PSUM ( -- ) HSUM
PSUM DISPLAY DROP DROP FF LD! DROP
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
OUT_BLACK_JACK ( -- ) HFACE
PSUM DISPLAY DROP DROP AA LD! DROP
OUT_PSCR_HSCR ( -- ) HSCR
PSCR DISPLAY DROP DROP 81 LD! DROP
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
16Updating Scores
- WIN ( -- )
- PSCR 1 PSCR / PSCR
- FFF DONE / DONE True
LOSE ( -- ) HSCR 1 HSCR / HSCR
FFF DONE / DONE True
17Main Program
- INIT ( -- )
- 0 PSUM
- 0 HSUM
- 0 DONE
- MAIN ( -- )
- 0 PSCR
- 0 HSCR
- BEGIN
- WAITBTN4
- INIT
- 2 FOR
- CARDTOP CARDTOH
- NEXT
OUT_HFACE_PSUM PSUM 15 IF OUT_BLACK_JACK
WIN ELSE BEGIN / Loop get.next.btn DUP 2
/ Hit on BTN2 IF CARDTOP OUT_HFACE_PSUM
18Main Program
- PSUM 15 / Win
- IF
- WIN
- DROP 3
- ELSE / Lose
- PSUM 15
- IF
- LOSE
- DROP 3
- THEN
- THEN
- THEN
3 / if BTN3 is pushed, DONE OR / or round
is done, UNTIL / exit Loop THEN / Stay DONE 0
/ if round isnt done, IF BEGIN / Deal to
House HSUM 11 17 WHILE CARDTOH OUT_HSUM_PSUM DELAY REPEAT
19Main Program
- OUT_HSUM_PSUM
- HSUM 15
- IF
- LOSE
- ELSE
- HSUM 15
- IF
- WIN
- ELSE
- HSUM PSUM
- IF
- WIN
- THEN
-
HSUM PSUM IF LOSE THEN THEN T
HEN THEN / Show scores on BTN4 WAITBTN1 OUT
_PSCR_HSCR AGAIN
20Demonstration
- How To play
- Clear (switch one) to start a new game.
- Push BTN4 to start round.
- Push BTN2 to hit.
- Push BTN3 to stay.
- When the game ends, press BTN4 to display scores.
- Displays
HFACE PSUM ? ? ? ? ? ? ? ?
HSUM PSUM ? ? ? ? ? ? ? ?
PSCR HSCR ? ? ? ? ? ? ? ?
BLACK JACK ? ? ? ? ? ? ? ?
21Questions?
22BlackJack On The W8Y 3.0
Prepared by Alok Vimawala Dan Scheutz Hani
Nadra CSE 378, Fall 2001