1 / 22

BlackJack On The W8Y 3.0

BlackJack On The W8Y 3.0. Prepared by: Alok Vimawala Dan Scheutz Hani Nadra CSE 378, Fall 2001. The W8Y 3.0. M. R. P1. T. Microcontroller. 0. 0. 1. 1. Pmux. Rmux. psel. rinsel. Rin. Pin. clr. rsel. BTN(1:4). BTNchk. clk. rload. clr. pload. PC. rdec. pushed. clk.

shilah
Download Presentation

BlackJack On The W8Y 3.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BlackJack On The W8Y 3.0 Prepared by: Alok Vimawala Dan Scheutz Hani Nadra CSE 378, Fall 2001

  2. The W8Y 3.0 M R P1 T Microcontroller 0 0 1 1 Pmux Rmux psel rinsel Rin Pin clr rsel BTN(1:4) BTNchk clk rload clr pload PC rdec pushed clk pinc clr clr ReturnStack rand_cnt plus1 P clk_2 clk T(3:0) rpush rpop clk Ram 16x12 N BTNsig W8Y_rom Rand we E M R T(7:0) M 4 0 1 2 3 clr DSmux LDreg ldload dssel(1:0) clk clr IR DS irload clk LD(1:8) tload T icode nload nsel ssel N(7:0) T(7:0) R clr clr clk DataStack_ALU BCDload bcdreg clk dpush T dpop NBCD TBCD clk BTN(1:4) W8Y_control osc_4k tsel(1:0) M clr clk_2 step_display clr alusel(3:0) clk clk pushed clr SW(1) A(3:0) AtoG(6:0)

  3. New Instructions clr rand_cnt clk_2 clr T(3:0) BTN(1:4) BTNchk clk pushed clk Ram 16x12 N we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  4. New Instructions clr rand_cnt clk_2 clr -- Fetch a random number and push -- it on the stack: when randfrom => dssel <= "011" ; tload <= '1' ; tsel <= "01" ; nload <= '1' ; dpush <= '1' ; ssel <= '0' ; T(3:0) BTN(1:4) BTNchk clk pushed clk Ram 16x12 N we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  5. New Instructions clr rand_cnt -- Push ones on Data_Stack if a button -- is pushed, zeros otherwise: when qbtn => if ( pushed = '1' ) then alusel <= "1011" ; tload <= '1' ; nload <= '1' ; dpush <= '1' ; else alusel <= "1100" ; tload <= '1' ; nload <= '1' ; dpush <= '1' ; end if ; clk_2 clr T(3:0) BTN(1:4) BTNchk clk pushed clk Ram 16x12 N we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  6. New Instructions clr rand_cnt clk_2 clr -- Push the number of the last button -- pushed on the Data_Stack: when getbtn => tload <= '1' ; tsel <= "01" ; dssel <= "010" ; nload <= '1' ; dpush <= '1' ; T(3:0) BTN(1:4) BTNchk clk pushed clk N Ram 16x12 we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  7. New Instructions N(7:0) T(7:0) BCDreg clk Nhextobcd Thextobcd BCDload clk clk clr clr Nbcdreg Tbcdreg clr BCDload BCDload -- Display N and T: when display => BCDload <= '1'; Nbcd(7:4) Nbcd(3:0) Tbcd(7:4) Tbcd(3:0) step_display dig1(3:0) dig2(3:0) dig3(3:0) dig4(3:0) clk anode dig2 dig3 dig1 dig4 "1111" clr dig7seg A(4:1) AtoG(6:0)

  8. New Instructions clr rand_cnt clk_2 clr -- Fetch word at memory address T, -- pop T, and push the word on Stack: when cfetch => tload <= '1' ; tsel <= "01" ; dssel <= "100" ; T(3:0) BTN(1:4) BTNchk clk pushed clk N Ram 16x12 we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  9. New 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 <= '1' ; tsel <= "11" ; tload <= '1' ; nsel <= '1' ; nload <= '1' ; dpop <= '1' ; T(3:0) BTN(1:4) BTNchk clk pushed clk N Ram 16x12 we Rand BTNsig E M R 4 0 1 2 3 DSmux dssel(1:0) DS tload T nload nsel ssel N clr clk DataStack_ALU dpush dpop tsel(1:0) alusel(3:0)

  10. WHYP Subroutines • Delay and Comparisons. • Memory manipulations. • Cards Dealing. • Display Subroutines. • Updating Scores. • Main Subroutine.

  11. Delay and Comparisons • DELAY ( -- ) (delay) • < ( n1 n2 -- f ) (less-than) • > ( n1 n2 -- f ) (greater-than) • = ( n1 n2 -- f ) (equals) • <= ( n1 n2 -- f ) (less or equal) • >= ( n1 n2 -- f ) (greater or equal) • get.next.btn ( -- n ) (get BTN pushed)

  12. Memory Manipulations • Push on Stack: : HSUM ( -- HSUM ) 2 C@ ; • Move T to RAM: : =>PSCR ( w -- ) 1 C! DROP ; • Copy T into RAM: : >HFACE ( w -- w ) 3 C! ;

  13. Cards 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

  14. Cards Dealing • Deal card to player: : CARDTOP ( -- ) CARD / push a card on Stack DUP 1 = IF / if it’s an Ace PSUM B < IF / if the player sum < 11 DROP B / count Ace as 11 THEN THEN PSUM + =>PSUM ; / update PSUM

  15. Display Subroutines : OUT_HSUM_PSUM ( -- ) HSUM PSUM DISPLAY DROP DROP FF LD! DROP ; : OUT_HFACE_PSUM ( -- ) HFACE PSUM DISPLAY DROP DROP AF LD! DROP ;                 : OUT_BLACK_JACK ( -- ) HFACE PSUM DISPLAY DROP DROP AA LD! DROP ; : OUT_PSCR_HSCR ( -- ) HSCR PSCR DISPLAY DROP DROP 81 LD! DROP ;                

  16. Updating Scores : WIN ( -- ) PSCR 1+ =>PSCR / PSCR ++ FFF =>DONE ; / DONE = True : LOSE ( -- ) HSCR 1+ =>HSCR / HSCR ++ FFF =>DONE ; / DONE = True

  17. : INIT ( -- ) 0 =>PSUM 0 =>HSUM 0 =>DONE ; : MAIN ( -- ) 0 =>PSCR 0 =>HSCR BEGIN WAITBTN4 INIT 2 FOR CARDTOP CARDTOH NEXT Main Program 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

  18. PSUM 15 = / Win IF WIN DROP 3 ELSE / Lose PSUM 15 > IF LOSE DROP 3 THEN THEN THEN Main Program 3 = / if BTN3 is pushed, DONE OR / or round is done, UNTIL / exit Loop THEN / Stay DONE 0 = / if round isn’t done, IF BEGIN / Deal to House HSUM 11 < / while HSUM < 17 WHILE CARDTOH OUT_HSUM_PSUM DELAY REPEAT

  19. OUT_HSUM_PSUM HSUM 15 = IF LOSE ELSE HSUM 15 > IF WIN ELSE HSUM PSUM < IF WIN THEN Main Program HSUM PSUM > IF LOSE THEN THEN THEN THEN / Show scores on BTN4 WAITBTN1 OUT_PSCR_HSCR AGAIN ;

  20. 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: Demonstration HFACE PSUM         HSUM PSUM         PSCR HSCR         BLACK JACK        

  21. Questions?

  22. BlackJack On The W8Y 3.0 Prepared by: Alok Vimawala Dan Scheutz Hani Nadra CSE 378, Fall 2001

More Related