; ------------------------------------------------------------------------------ ; Original Unisonic Champion ROM image ORG $800 ROMW 10 ; ------------------------------------------------------------------------------ ; Unisonic memory map Usc PROC @@scratch QEQU $0 @@sound QEQU @@scratch + $96 @@deck QEQU @@scratch + $97 @@deckEnd QEQU @@scratch + $cb @@aceCount1 QEQU @@scratch + $cb @@aceCount2 QEQU @@scratch + $cc @@aceCountd QEQU @@scratch + $cd @@bet1 QEQU @@scratch + $ce @@bet2 QEQU @@scratch + $cf @@betTmp1 QEQU @@scratch + $d0 @@betTmp2 QEQU @@scratch + $d1 @@lost1 QEQU @@scratch + $d2 @@lost2 QEQU @@scratch + $d3 @@lostd QEQU @@scratch + $d4 @@round QEQU @@scratch + $d5 @@bankTmpLo QEQU @@scratch + $d6 @@bankTmpHi QEQU @@scratch + $d7 ;@@unused QEQU @@scratch + $d8 ;@@unused QEQU @@scratch + $d9 ;@@unused QEQU @@scratch + $da ;@@unused QEQU @@scratch + $db ;@@unused QEQU @@scratch + $dc ;@@unused QEQU @@scratch + $dd @@total1 QEQU @@scratch + $de @@total2 QEQU @@scratch + $df @@totald QEQU @@scratch + $e0 @@dealer21 QEQU @@scratch + $e1 @@double1 QEQU @@scratch + $e2 @@double2 QEQU @@scratch + $e3 @@player QEQU @@scratch + $e4 @@numberPlayers QEQU @@scratch + $e5 @@gameType QEQU @@scratch + $e6 ;@@unused QEQU @@scratch + $e7 @@nextCardNo QEQU @@scratch + $e8 ;@@unused QEQU @@scratch + $e9 ;@@unused QEQU @@scratch + $ea @@bank1Hi QEQU @@scratch + $eb @@bank1Lo QEQU @@scratch + $ec @@bank2Hi QEQU @@scratch + $ed @@bank2Lo QEQU @@scratch + $ee @@numberAddrHi QEQU @@scratch + $ef @@card QEQU @@scratch + $ef @@numberAddrLo QEQU @@scratch + $f0 @@listPtr QEQU @@scratch + $f1 @@numberScrPtr QEQU @@scratch + $f2 @@numberResPtr QEQU @@scratch + $f3 @@randomLo QEQU @@scratch + $f4 @@randomHi QEQU @@scratch + $f5 ENDP ; ------------------------------------------------------------------------------ ; Reset - located at $0800 ; Clear all RAM (clearing the screen in the process) ; Initialise the deck of cards Reset PROC CLRR R3 ; R3 = value to be written CLRR R4 ; R4 = address to write ; @@loop ; ; MVO@ R3, R4 ; clear location CMPI #$100, R4 ; BNEQ @@loop ; if R4 != $100, goto @@loop ; MVII #$7e, R0 ; card value MVII #Usc.deck, R4 ; starting deck address ; @@writeCard ; ; MVO@ R0, R4 ; write current card value CMPI #Usc.deckEnd, R4 ; BEQ CartridgeTest ; if 52 cards written, goto CartridgeTest ; DECR R0 ; decrement card value MOVR R0, R1 ; ANDI #$f, R1 ; mask out face value CMPI #$1, R1 ; BNEQ @@writeCard ; if card face value != 1, goto writeCard ; SUBI #$3, R0 ; skip to next ace B @@writeCard ; goto writeCard ; ENDP ; ; ------------------------------------------------------------------------------ ; Test for an external cartridge and run it if present CartridgeTest SETC ; test for cartridge at $1000 RRC R3, 2 ; RRC R3, 2 ; R3 = $1000 MVI@ R3, R0 ; R0 = [$1000] TSTR R0 ; BNEQ ChooseGame ; if R1 != 0, goto ChooseGame ; INCR R3 ; MOVR R3, R7 ; kick off cartridge execution at $1001 ; ------------------------------------------------------------------------------ ; Show the game choice menu and wait for key to be pressed ChooseGame PROC MVII #$2, R0 ; MVO R0, $58 ; [$58] = 'B' MVO R0, $72 ; [$72] = 'B' INCR R0 ; MVO R0, $73 ; [$73] = 'C' MVII #$a, R0 ; MVO R0, $59 ; [$59] = 'J' ; @@chooseBj ; ; MVII #$5a, R1 ; load address for question mark MVII #$3, R2 ; game = blackjack ; @@showCursor ; ; MVII #$3f, R0 ; R0 = '?' MVO@ R0, R1 ; print question mark SDBD ; MVII #$1fff, R0 ; loop period ; @@loop ; ; BEXT @@keyPressed, $1 ; test player 1 yes key pressed ; BEXT @@keyPressed, $4 ; test player 2 yes key pressed ; DECR R0 ; BNEQ @@loop ; if key not pressed, goto loop ; MVO@ R0, R1 ; clear '?' DECR R2 ; game = bacarat CMPI #$1, R2 ; BEQ @@chooseBj ; if game != bacarat, reset to blackjack ; ADDI #$1a, R1 ; move question mark down 2 lines B @@showCursor ; print question mark ; @@keyPressed ; ; MVO R0, Usc.randomLo ; store time remaining as random seed MVO R2, Usc.gameType ; store game choice ; ENDP ; ; ------------------------------------------------------------------------------ ; Show the number of players choice menu and wait for key to be pressed ChoosePlayers PROC JSR R5, ScrClearAll ; clear the screen ; JSR R5, Pause ; pause for a while DECLE $96 ; delay period ; SDBD ; MVII #MsgPlayer, R4 ; pointer to player message MVII #$66, R5 ; pointer to screen location ; @@loop ; ; MVI@ R4, R3 ; load character MVO@ R3, R5 ; print character TSTR R3 ; check for end of string BNEQ @@loop ; if not end of string, goto loop ; @@printNumber ; ; MVII #$31, R0 ; MVO R0, $64 ; print '1' JSR R5, IsKeyPressed ; check for key pressed ; TSTR R0 ; has key been pressed? BEQ @@player2 ; if key not pressed, goto player2 ; BC @@player2 ; if 'no' key pressed, goto player2 ; CLRR R0 ; one player game B ScrDrawLeft ; done ; @@player2 ; ; MVII #$32, R0 ; MVO R0, $64 ; print '2' JSR R5, IsKeyPressed ; check for key pressed ; ; there is a bug at this point no ; TSTR R0 instruction means the next BEQ ; will never be triggered, loop is ; dependent on C being set BEQ @@printNumber ; if key not pressed, try again ; BC @@printNumber ; if 'no' key pressed, try again ; MVII #$1, R0 ; two player game ; ENDP ; ; ------------------------------------------------------------------------------ ; Draw the left hand side of the screen ScrDrawLeft MVO R0, Usc.numberPlayers ; store number of players JSR R5, ScrClearRight ; clear right hand side of the screen ; JSR R5, Pause ; pause for a while DECLE $fa ; delay period ; MVII #$2, R3 ; MOVR R3, R2 ; MVO R3, $12 ; [$12] = 'B' MVO R3, $2a ; [$2a] = 'B' MVO R3, $c ; [$c] = 'B' MVO R3, $24 ; [$24] = 'B' SLL R3, 2 ; MVO R3, $18 ; [$18] = 'H' MVO R3, $30 ; [$30] = 'H' MVII #$12, R3 ; MVO R3, $d ; [$d] = 'R' MVO R3, $25 ; [$25] = 'R' ADDR R2, R3 ; MVO R3, $13 ; [$13] = 'T' MVO R3, $19 ; [$19] = 'T' MVO R3, $2b ; [$2b] = 'T' MVO R3, $31 ; [$31] = 'T' JSR R5, ScrClearRight ; clear right hand side of the screen ; JSR R5, Pause ; pause for a while DECLE $7f ; delay period ; ------------------------------------------------------------------------------ ; Get bank amounts MVII #Usc.bank1Lo, R0 ; load result address MVO R0, Usc.numberResPtr ; MVII #$f, R0 ; screen address for number MVO R0, Usc.numberScrPtr ; load screen location SDBD ; MVII #BankList, R0 ; load the list of amounts MVO R0, Usc.numberAddrHi ; SWAP R0 ; MVO R0, Usc.numberAddrLo ; JSR R6, ChooseNumber ; display the list and choose ; MVI Usc.numberPlayers, R0 ; TSTR R0 ; BEQ PrintGameType ; if one player game, show the game type ; MVO R0, Usc.player ; store player MVII #Usc.bank2Hi, R0 ; load result address MVO R0, Usc.numberResPtr ; MVII #$27, R0 ; screen address for number MVO R0, Usc.numberScrPtr ; load screen location SDBD ; MVII #BankList, R0 ; load the list of amounts MVO R0, Usc.numberAddrHi ; SWAP R0 ; MVO R0, Usc.numberAddrLo ; JSR R6, ChooseNumber ; display the list and choose ; B PrintGameType ; show the game type BankList DECLE 100, 50, 20, 10, 0 MsgPlayer DECLE $10, $c, $1, $19, $5, $12, $00 ; ------------------------------------------------------------------------------ ; Print game type (blackjack or bacarat) and number of players PrintGameType PROC JSR R5, ShuffleDeck ; shuffle the deck ; MVI Usc.gameType, R2 ; load the game type CMPI #$2, R2 ; BEQ @@bacarat ; if bacarat, show that ; DECR R2 ; MVO R2, $1 ; print 'B' MVII #$a, R2 ; MVO R2, $2 ; print 'J' B @@printPlayers ; ; @@bacarat ; ; MVO R2, $1 ; print 'B' INCR R2 ; MVO R2, $2 ; print 'C' ; @@printPlayers ; ; MVII #$31, R2 ; load '0' ADD Usc.numberPlayers, R2 ; add player count MVO R2, $3 ; write to screen B PrintBank ; ; ENDP ; ; ------------------------------------------------------------------------------ ; Display player bank StartHand JSR R5, Pause ; pause for a while DECLE $1ff ; delay period ; PrintBank ; ; MVI Usc.bank1Hi, R0 ; load player 1 bank SWAP R0 ; XOR Usc.bank1Lo, R0 ; TSTR R0 ; BMI BankNegative ; if out of cash, goto BankNegative ; MVII #$f, R3 ; load screen address MVO R3, Usc.numberScrPtr ; JSR R5, ScrPrintNumber ; show player 1 bank ; MVI Usc.numberPlayers, R3 ; TSTR R3 ; BEQ ResetHand ; if one player, goto ResetHand ; MVI Usc.bank2Hi, R0 ; load player 2 bank SWAP R0 ; XOR Usc.bank2Lo, R0 ; TSTR R0 ; BMI BankNegative ; if out of cash, goto BankNegative ; MVII #$27, R3 ; load screen address MVO R3, Usc.numberScrPtr ; JSR R5, ScrPrintNumber ; show player 2 bank ; CLRR R0 ; clear player 1 bet MVII #$15, R4 ; MVO@ R0, R4 ; MVO@ R0, R4 ; MVO@ R0, R4 ; MVII #$2d, R4 ; clear player 2 bet MVO@ R0, R4 ; MVO@ R0, R4 ; MVO@ R0, R4 ; ; ------------------------------------------------------------------------------ ; Reset hand data ResetHand PROC JSR R5, ScrClearRight ; clear right side of the screen MVII #Usc.deckEnd, R4 ; CLRR R3 ; ; @@loop ; ; MVO@ R3, R4 ; clear RAM from $cb to $e5 CMPI #Usc.numberPlayers, R4 ; BNEQ @@loop ; ; MVI Usc.numberPlayers, R3 ; load number of players XORI #$1, R3 ; force player 2 to be lost in one MVO R3, Usc.lost2 ; player games JSR R5, Pause ; pause a while DECLE $7f ; delay period ; MVI Usc.nextCardNo, R3 ; load the number of the next card CMPI #$26, R3 ; BLE GetBetAmount ; if < 38 cards dealt, goto GetBetAmount ; JSR R5, ShuffleDeck ; shuffle deck ; ENDP ; ; ------------------------------------------------------------------------------ ; Get bet amount for each player GetBetAmount MVII #Usc.bet1, R0 ; request bid amount from player 1 MVO R0, Usc.numberResPtr ; MVII #$15, R0 ; set up screen address MVO R0, Usc.numberScrPtr ; SDBD ; MVII #BidAmounts, R0 ; set up pointer to amount list MVO R0, Usc.numberAddrHi ; SWAP R0 ; MVO R0, Usc.numberAddrLo ; JSR R6, ChooseNumber ; show the list and choose ; MVI Usc.numberPlayers, R0 ; check for two player game TSTR R0 ; BEQ DealCards ; ; MVO R0, Usc.player ; request bid amount from player 2 MVII #$2d, R0 ; set up screen address MVO R0, Usc.numberScrPtr ; SDBD ; MVII #BidAmounts, R0 ; set up pointer to amount list MVO R0, Usc.numberAddrHi ; SWAP R0 ; MVO R0, Usc.numberAddrLo ; JSR R6, ChooseNumber ; show the list and choose ; ------------------------------------------------------------------------------ ; Deal initial cards DealCards PROC CLRR R0 ; MVO R0, Usc.player ; set player 1 JSR R5, DealScoreCard ; deal card DECLE Usc.total1 ; address to store total ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; display the card JSR R5, ScrPrintCard ; ; MVI Usc.numberPlayers, R0 ; TSTR R0 ; BEQ @@dealDealer ; if one player game, goto dealDealer ; MVO R0, Usc.player ; set player 2 JSR R5, DealScoreCard ; deal card DECLE Usc.total2 ; address to store result ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; display the card JSR R5, ScrPrintCard ; ; @@dealDealer ; ; MVII #$2, R3 ; set dealer MVO R3, Usc.player ; JSR R5, DealScoreCard ; deal card DECLE Usc.totald ; address to store result ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; check for final round of cards TSTR R0 ; BEQ @@showCard ; if not final round, goto showCard ; MVI Usc.numberAddrHi, R3 ; hide dealers' final card XORI #$80, R3 ; MVO R3, Usc.numberAddrHi ; ; @@showCard ; ; JSR R5, ScrPrintCard ; display card ; MVI Usc.round, R0 ; check for final round of cards TSTR R0 ; BNEQ DoubleBets ; ; INCR R0 ; increment round of cards MVO R0, Usc.round ; B DealCards ; deal next round ; ENDP ; ; ------------------------------------------------------------------------------ ; Ask the players if they want to double DoubleBets PROC MVI Usc.gameType, R0 ; check for bacarat SARC R0 ; BNC NoDouble ; if bacarat, goto NoDouble ; CLRR R0 ; set player 1 MVO R0, Usc.player ; JSR R6, CheckDealerAce ; check whether the dealer has an ace ; MVI Usc.dealer21, R0 ; load whether the dealer has 21 TSTR R0 ; BNEQ IsPlayer1Win ; if dealer has 21, goto IsPlayer1Win ; MVO R0, Usc.player ; MVI Usc.gameType, R0 ; check for ??? SARC R0, 2 ; BNC @@bacarat ; if ???, don't offer double ; JSR R6, AskDouble ; ask player whether to double ; @@bacarat ; ; JSR R5, Pause ; pause for a while DECLE $7f ; delay period ; MVO R1, Usc.player ; set player 1 MVI Usc.double1, R0 ; load player1 double TSTR R0 ; BNEQ @@dontShowTotal ; if player1 doubled, goto dontShowTotal ; JSR R5, ScrPrintNumberIndirect ; display player 1 hand total DECLE $5f, Usc.total1 ; screen and values addresses ; JSR R5, GmeIs21 ; check for blackjack ; @@dontShowTotal ; ; MVI Usc.numberPlayers, R3 ; load number of players TSTR R3 ; BEQ @@checkLost ; if one player game, goto checkLost ; MVO R3, Usc.player ; set player 2 MVI Usc.double2, R0 ; load player 2 double TSTR R0 ; BNEQ @@checkLost ; if player 2 doubled, goto checkLost ; JSR R5, ScrPrintNumberIndirect ; display player 2 hand total DECLE $79, Usc.total2 ; screen and values addresses ; JSR R5, GmeIs21 ; check for blackjack ; @@checkLost ; ; MVI Usc.lost1, R3 ; TSTR R3 ; BEQ @@isDealerVictory ; if player 1 not lost, goto isDealerVictory ; MVI Usc.lost2, R3 ; TSTR R3 ; BNEQ StartHand ; if player 2 lost, goto StartHand ; @@isDealerVictory ; ; MVII #$2, R3 ; set dealer MVO R3, Usc.player ; JSR R5, GmeIs21 ; check for dealer victory ; MVI Usc.lostd, R3 ; check for dealer lost TSTR R3 ; BNEQ CheckWinner ; if dealer lost, goto CheckWinner ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle each round, repeatedly ask player 1 to hit NoDouble PROC CLRR R3 ; MVO R3, Usc.player ; clear player number ; @@hitAgain ; ; MVI Usc.round, R3 ; load and increment round INCR R3 ; MVO R3, Usc.round ; MVI Usc.gameType, R2 ; load game type SARC R2 ; BC @@checkLost ; if blackjack, goto checkLost ; CMPI #$3, R3 ; BEQ InitialiseRound ; if round = 3, goto InitialiseRound ; B @@hitPlayer1 ; ; @@checkLost ; ; JSR R5, CheckAlreadyLost ; check if player 1 has already lost ; TSTR R3 ; BNEQ DonePlayer1Hit ; if player lost, goto DonePlayer1Hit ; JSR R5, ScrPrintNumberIndirect ; DECLE $5f, Usc.total1 ; screen pointer and value ; @@hitPlayer1 ; ; MVII #$3f, R3 ; print '?' MVO R3, $1a ; JSR R5, IsKeyPressed ; wait for key press ; TSTR R0 ; BEQ @@keyNotPressed ; if key not pressed, goto keyNotPressed ; CLRR R0 ; clear '?' MVO R0, $1a ; BNC @@dealPlayer1 ; if yes key pressed, goto dealPlayer1 ; B DonePlayer1Hit ; if no key pressed, goto DonePlayer1Hit ; @@keyNotPressed ; ; MVO R0, $1a ; clear '?' JSR R5, IsKeyPressed ; ; TSTR R0 ; BEQ @@hitPlayer1 ; if key not pressed, goto hitPlayer1 ; BC DonePlayer1Hit ; if no key pressed, goto DonePlayer1Hit ; @@dealPlayer1 ; ; JSR R5, DealScoreCard ; deal next card DECLE Usc.total1 ; ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; show the card JSR R5, ScrPrintCard ; ; JSR R5, Pause ; pause for a while DECLE $c0 ; delay period ; B @@hitAgain ; goto hitAgain ; ENDP ; ; ------------------------------------------------------------------------------ ; Repeatedly ask player 1 to hit DonePlayer1Hit PROC MVI Usc.gameType, R0 ; load game type SARC R0 ; BNC InitialiseRound ; if bacarat, goto InitialiseRound ; MVI Usc.double1, R0 ; load doubled TSTR R0 ; BNEQ InitialiseRound ; if doubled, goto InitialiseRound ; JSR R5, ScrPrintNumberIndirect ; print player 1 hand total DECLE $5f, Usc.total1 ; ; ENDP ; ; ------------------------------------------------------------------------------ ; Initialise a round InitialiseRound ; ; MVII #$1, R3 ; MVO R3, Usc.round ; set round 1 MVI Usc.numberPlayers, R0 ; load number of players TSTR R0 ; BEQ DealerTurn ; if single player, goto DealerTurn ; MVO R0, Usc.player ; set player 2 ; ------------------------------------------------------------------------------ ; Start of each round IncrementRound PROC ; ; MVI Usc.round, R3 ; load, increment and store round INCR R3 ; MVO R3, Usc.round ; MVI Usc.gameType, R2 ; SARC R2 ; BC Player2Check ; if blackjack, goto Player2Check ; CMPI #$3, R3 ; BEQ DealerTurn ; if round = 3, goto DealerTurn ; B @@hitPlayer2 ; goto hitPlayer2 ; Player2Check ; ; JSR R5, CheckAlreadyLost ; check if player 2 has lost ; TSTR R3 ; BNEQ DonePlayer2Hit ; if player 2 lost, goto DonePlayer2Hit ; JSR R5, ScrPrintNumberIndirect ; print player 2 hand total DECLE $79, Usc.total2 ; ; @@hitPlayer2 ; ; MVII #$3f, R3 ; print '?' MVO R3, $32 ; JSR R5, IsKeyPressed ; is key pressed ; TSTR R0 ; BEQ @@keyNotPressed ; if key not pressed, goto keyNotPressed ; CLRR R0 ; clear '?' MVO R0, $32 ; BNC @@dealPlayer2 ; if yes key pressed, goto dealPlayer2 ; B DonePlayer2Hit ; goto DonePlayer2Hit ; @@keyNotPressed ; ; MVO R0, $32 ; clear '?' JSR R5, IsKeyPressed ; ; TSTR R0 ; BEQ @@hitPlayer2 ; if key not pressed, goto hitPlayer2 ; BC DonePlayer2Hit ; if no key pressed, goto DonePlayer2Hit ; @@dealPlayer2 ; ; JSR R5, DealScoreCard ; deal next card DECLE Usc.total2 ; ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; show the card JSR R5, ScrPrintCard ; ; JSR R5, Pause ; pause for a while DECLE $c0 ; delay period ; B IncrementRound ; ; ENDP ; ; DonePlayer2Hit ; ; MVI Usc.double2, R0 ; load player 2 double TSTR R0 ; BNEQ DealerTurn ; if doubled, goto DealerTurn ; MVI Usc.gameType, R0 ; load game type SARC R0 ; BNC DealerTurn ; if bacarat, goto DealerTurn ; JSR R5, ScrPrintNumberIndirect ; show player 2 hand total DECLE $79, Usc.total2 ; ; ------------------------------------------------------------------------------ ; Handle dealer's turn DealerTurn PROC ; ; MVII #$1, R3 ; MVO R3, Usc.round ; set round 1 INCR R3 ; MVO R3, Usc.player ; set player to dealer MVI Usc.gameType, R3 ; load game type SARC R3 ; BNC BacaratDealer ; if bacarat, goto BacaratDealer ; MVI Usc.lost1, R3 ; TSTR R3 ; BEQ @@showCard ; if player 1 not lost, goto showCard ; MVI Usc.lost2, R3 ; TSTR R3 ; BEQ @@showCard ; if player 2 not lost, goto showCard ; B StartHand ; goto StartHand ; @@showCard ; ; MVI $8c, R3 ; show hidden card ANDI #$7f, R3 ; MVO R3, $8c ; ; @@checkDealerLost ; ; JSR R5, CheckAlreadyLost ; check to see if the dealer has lost ; TSTR R3 ; BEQ @@dealerDeal ; if lost, goto dealerDeal ; JSR R5, ScrPrintNumberIndirect ; show dealer total DECLE $93, Usc.totald ; ; MVI Usc.totald, R3 ; load dealer hand total CMPI #$15, R3 ; BLE CheckWinner ; if total <= 21, goto CheckWinner ; MVI Usc.aceCountd, R0 ; load dealer ace count TSTR R0 ; BEQ @@dealerBust ; if no aces, goto ; DECR R0 ; decrement and store ace count MVO R0, Usc.aceCountd ; SUBI #$a, R3 ; subtract 10 from the dealer total MVO R3, Usc.totald ; store total B @@checkDealerLost ; try again ; @@dealerBust ; ; SDBD ; MVII #MsgBust, R5 ; load pointer to bust message MVII #$80, R4 ; pointer to output message ; @@charLoop ; ; MVI@ R5, R3 ; load character TSTR R3 ; BEQ CheckPlayer1Lost ; if end of message, goto CheckPlayer1Lost ; MVO@ R3, R4 ; write message B @@charLoop ; goto charLoop ; @@dealerDeal ; ; JSR R5, ScrPrintNumberIndirect ; print dealer total DECLE $93, Usc.totald ; screen address, value ; JSR R5, DealScoreCard ; deal a card DECLE Usc.totald ; total address ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; load and increment round INCR R0 ; MVO R0, Usc.round ; JSR R5, ScrPrintCard ; show the card ; JSR R5, Pause ; pause for a bit DECLE $ff ; delay period ; B @@checkDealerLost ; go again ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle Bacarat dealer's turn BacaratDealer PROC MVI $8c, R3 ; show dealer's card ANDI #$7f, R3 ; MVO R3, $8c ; ; @@roundLoop ; ; MVI Usc.totald, R3 ; load dealer total ; @@subLoop ; ; CMPI #$a, R3 ; BLT @@doneSub ; if total less than 10, goto doneSub ; SUBI #$a, R3 ; subtract 10 from total B @@subLoop ; goto subLoop ; @@doneSub ; ; TSTR R3 ; BEQ @@total0 ; if total = 0, goto total0 ; MVI Usc.round, R0 ; load round CMPI #$2, R0 ; BGE BacaratCheckWinner ; if round >= 2, goto BacaratCheckWinner ; CMPI #$4, R3 ; BGT BacaratCheckWinner ; if total > 4, goto BacaratCheckWinner ; @@total0 ; ; MVI Usc.round, R0 ; load round CMPI #$5, R0 ; BEQ BacaratCheckWinner ; if round = 5, goto BacaratCheckWinner ; JSR R5, DealScoreCard ; deal a card DECLE Usc.totald ; address to store result ; MVI Usc.round, R0 ; increment round INCR R0 ; MVO R0, Usc.round ; JSR R5, ScrPrintCard ; display the card ; JSR R5, Pause ; pause for a while DECLE $ff ; delay period ; B @@roundLoop ; goto roundLoop ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle end of game when bank is negative BankNegative PROC JSR R5, ScrClearAll ; clear the screen ; SDBD ; MVII #MsgBust, R4 ; load message pointer MVII #$4c, R5 ; load screen address ; @@loop ; ; MVI@ R4, R3 ; load character MVO@ R3, R5 ; print character to screen TSTR R3 ; BNEQ @@loop ; if not end of message, goto loop ; JSR R5, Pause ; pause for a while DECLE $12c ; delay period ; B Reset ; goto Reset ; ENDP ; ; ------------------------------------------------------------------------------ ; Check who if anyone is a winner CheckWinner PROC MVI Usc.lost1, R0 ; TSTR R0 ; BNEQ @@player2 ; if player 1 lost, goto player2 ; CLRR R6 ; set player 0 ; @@playerLoop ; ; MVO R6, Usc.player ; store player number JSR R5, CheckLoss ; check for loss ; @@player2 ; ; MVI Usc.lost2, R0 ; TSTR R0 ; BNEQ @@isDealerLost ; if player 2 lost, goto isDealerLost ; MVI Usc.player, R6 ; load player TSTR R6 ; BNEQ @@isDealerLost ; if not player 0, goto isDealerLost ; INCR R6 ; increment player B @@playerLoop ; ; @@isDealerLost ; ; MVI Usc.lostd, R3 ; TSTR R3 ; BEQ IsPlayer1Win ; if dealer not lost, goto IsPlayer1Win ; CheckPlayer1Lost ; ; MVI Usc.lost1, R3 ; TSTR R3 ; BNEQ @@isPlayer2Lost ; if player 1 lost, goto isPlayer2Lost ; MVO R3, Usc.player ; set player 1 JSR R5, HandEnd ; player 1 wins DECLE 0 ; ; @@isPlayer2Lost ; ; MVI Usc.lost2, R3 ; TSTR R3 ; BNEQ StartHand ; if player 2 lost, goto StartHand ; INCR R3 ; MVO R3, Usc.player ; set player 2 JSR R5, HandEnd ; player 2 wins DECLE 0 ; ; B StartHand ; goto StartHand ; IsPlayer1Win ; ; MVO R3, Usc.player ; store player MVI Usc.lost1, R3 ; load player 1 lost TSTR R3 ; BNEQ @@isPlayer2Win ; if lost, goto isPlayer2Win ; MVI Usc.total1, R3 ; load player total CMP Usc.totald, R3 ; compare to dealer total BNEQ @@player1Different ; if different, goto player1Different ; JSR R5, Draw ; goto Draw ; B @@isPlayer2Win ; goto isPlayer2Win ; @@player1Different ; ; BGT @@player1Win ; if player > dealer, goto player1Win ; JSR R5, HandEnd ; dealer wins DECLE 1 ; ; B @@isPlayer2Win ; goto isPlayer2Win ; @@player1Win ; ; JSR R5, HandEnd ; player wins DECLE 0 ; ; @@isPlayer2Win ; ; MVI Usc.numberPlayers, R3 ; load number of players TSTR R3 ; BEQ StartHand ; if one player, goto StartHand ; MVO R3, Usc.player ; store player MVI Usc.lost2, R3 ; load player 2 lost TSTR R3 ; BNEQ StartHand ; if doubled, goto StartHand ; MVI Usc.total2, R3 ; load player 2 total CMP Usc.totald, R3 ; compare to dealer total BNEQ @@player2Different ; if different, goto player2Different ; JSR R5, Draw ; ; B StartHand ; goto StartHand ; @@player2Different ; ; BGT player2Win ; if player > dealer, goto player2Win ; JSR R5, HandEnd ; dealer wins DECLE 1 ; ; B StartHand ; goto StartHand ; player2Win ; ; JSR R5, HandEnd ; player 2 wins DECLE 0 ; ; B StartHand ; goto StartHand ; ENDP ; ; ------------------------------------------------------------------------------ ; Check for winner in bacarat BacaratCheckWinner PROC CLRR R6 ; MVO R6, Usc.player ; set player 1 MVII #$a, R0 ; MVI Usc.total1, R3 ; load player 1 total ; @@subLoop1 ; ; CMPR R0, R3 ; BLT @@player2Sub ; if total1 < 10, goto player2Sub ; SUBR R0, R3 ; total1 -= 10 B @@subLoop1 ; goto subLoop1 ; @@player2Sub ; ; MVI Usc.total2, R2 ; load player 2 total ; @@subLoop2 ; ; CMPR R0, R2 ; if total2 < 10, goto dealerSub BLT @@dealerSub ; ; SUBR R0, R2 ; total2 -= 10 B @@subLoop2 ; goto subLoop2 ; @@dealerSub ; ; MVO R2, Usc.total2 ; store total2 MVI Usc.totald, R1 ; load totald ; @@subLoopd ; ; CMPR R0, R1 ; if totald < 10, goto BLT @@checkWinner ; ; SUBR R0, R1 ; totald -= 10 B @@subLoopd ; goto subLoopd ; @@checkWinner ; ; MVO R1, Usc.totald ; store totald ; @@playerLoop ; ; CMPR R1, R3 ; compare totald and total1 BNEQ @@winLose ; if different, goto winLose ; JSR R5, Draw ; handle draw ; B @@nextPlayer ; ; @@winLose ; ; BGT @@playerWins ; if total1 > totald, goto playerWins ; JSR R5, HandEnd ; dealer wins DECLE $1 ; ; B @@nextPlayer ; ; @@playerWins ; ; JSR R5, HandEnd ; player wins DECLE $0 ; ; @@nextPlayer ; ; MVI Usc.numberPlayers, R3 ; load number of players TSTR R3 ; BEQ StartHand ; if one player game, goto StartHand ; MVO R3, Usc.player ; store player TSTR R6 ; BNEQ StartHand ; if player 2, goto StartHand ; INCR R6 ; increment player MVI Usc.total2, R3 ; load player 2 total MVI Usc.totald, R1 ; load player 1 total B @@playerLoop ; goto playerLoop ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle draw Draw PROC SDBD MVII #MsgPush, R3 ; load message pointer SDBD ; MVII #MsgScreenAddress, R4 ; load base screen address pointer ADD Usc.player, R4 ; add player offset MVI@ R4, R4 ; ; @@charLoop ; ; MVI@ R3, R2 ; load message character MVO@ R2, R4 ; write character to screen INCR R3 ; increment input character TSTR R2 ; test for end of message BNEQ @@charLoop ; ; JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Data BidAmounts DECLE 10, 5, 2, 1, 0 MsgPush DECLE $10, $15, $13, $8, $0 MsgYouWin DECLE $19, $f, $15, $20, $20, $17, $9, $e, $0 MsgYouLose DECLE $19, $f, $15, $20, $c, $f, $13, $5, $0 MsgBust DECLE $2, $15, $13, $14, $0 ; ------------------------------------------------------------------------------ ; Write a list of values on screen to choose from ChooseNumber PROC MVII #Usc.numberAddrHi, R4 ; load list address SDBD ; MVI@ R4, R1 ; R1 = address list MVII #$fb, R4 ; MVO R4, Usc.numberAddrLo ; Usc.numberAddrLo = $fb? ; @@copyList ; copy the list of values ; MVI@ R1, R0 ; load value INCR R1 ; increment address pointer MVO@ R0, R4 ; write out value TSTR R0 ; list done? BNEQ @@copyList ; if list not done, goto copyList ; @@resetList ; ; MVI Usc.numberAddrLo, R5 ; reset item pointer MVO R5, Usc.listPtr ; ; @@nextItem ; ; MVI Usc.listPtr, R5 ; load next item address MVI@ R5, R0 ; load next item MVO R5, Usc.listPtr ; store incremented address TSTR R0 ; BEQ @@resetList ; if end of list, goto resetList ; JSR R5, ScrPrintNumber ; print the number ; JSR R5, IsKeyPressed ; check to see if a key is pressed ; TSTR R0 ; BEQ @@keyNotPressed ; if key not pressed, goto keyNotPressed ; BNC @@yesKey ; if yes key pressed, goto yesKey ; CLRR R0 ; ; @@keyNotPressed ; ; MVI Usc.numberScrPtr, R4 ; load target screen address MVO@ R0, R4 ; clear text MVO@ R0, R4 ; MVO@ R0, R4 ; JSR R5, Pause ; pause for a bit DECLE $c8 ; delay period ; B @@nextItem ; display the next item in the list ; @@yesKey ; ; MVI Usc.listPtr, R3 ; load result value address DECR R3 ; MVI@ R3, R0 ; load result MVI Usc.numberResPtr, R4 ; load result address ADDR R1, R4 ; MVO@ R0, R4 ; store result MOVR R6, R7 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Deal and score the next card DealScoreCard PROC MVI Usc.nextCardNo, R1 ; load and increment card number INCR R1 ; MVO R1, Usc.nextCardNo ; ADDI #Usc.deck, R1 ; add start of deck MVI@ R1, R0 ; R0 = card MVO R0, Usc.card ; numberAddrHi = card ANDI #$f, R0 ; isolate face value MVI Usc.gameType, R2 ; load game type CMPI #$1, R2 ; BLE @@numberCard ; if ???, goto numberCard ; CMPI #$b, R0 ; blackjack card scoring BLT @@numberCard ; if card < jack, goto numberCard ; CMPI #$e, R0 ; check for picture card BNEQ @@pictureCard ; if true, goto pictureCard ; CMPI #$2, R2 ; BNEQ @@blackjackAce ; if blackjack, goto blackjackAce ; MVII #$1, R0 ; ace value = 1 in bacarat B @@numberCard ; goto numberCard ; @@blackjackAce ; ; MVII #$b, R0 ; ace value = 11 in blackjack B @@numberCard ; ; @@pictureCard ; ; MVII #$a, R0 ; picture card value = 10 in blackjack ; @@numberCard ; ; MOVR R0, R4 ; MVI@ R5, R1 ; load address to store result CMPI #$1, R2 ; BEQ @@bacarat ; if bacarat, goto bacarat scoring ; ADD@ R1, R0 ; add total to card value MVO@ R0, R1 ; store updated total JR R5 ; done ; @@bacarat ; ; MVI Usc.round, R3 ; load round number SLR R3 ; divide by 2 ADDR R3, R1 ; add round to target MVO@ R0, R1 ; store total JR R5 ; done ; ENDP ; ; It is not clear what this decle does MVI@ R5, R0 ; $0CEE 02A8 [. ] ; ------------------------------------------------------------------------------ ; Display a card ScrPrintCard PROC SLL R0 ; double round number (row location) MVI Usc.player, R2 ; load player SDBD ; MVII #@@displayAddress, R3 ; ADDR R2, R3 ; evaluate player's base screen address MVI@ R3, R3 ; load pointer to screen address ADDR R0, R3 ; add on round offset MVI Usc.card, R0 ; load card to display MVO@ R0, R3 ; display the card JSR R4, SoundPulses ; beep, beep DECLE $1, $1 ; pulse count, pitch ; JR R5 ; done ; @@displayAddress ; screen addresses for each player's ; first card DECLE $56, $70, $8A ; ; ENDP ; ; ------------------------------------------------------------------------------ ; Test whether a key has been pressed on a given controller IsKeyPressed PROC SDBD ; MVII #$1fff, R0 ; initialise loop MVI Usc.player, R1 ; load the controller to check ; @@loop ; ; TSTR R1 ; BNEQ @@player2 ; test player 2 ; BEXT @@yesButton, $1 ; check for yes button ; BEXT @@noButton, $2 ; check for no button ; B @@endLoop ; iterate ; @@player2 ; ; BEXT @@yesButton, $4 ; check for yes button ; BEXT @@noButton, $8 ; check for no button ; @@endLoop ; ; DECR R0 ; decrement pause BNEQ @@loop ; iterate ; JR R5 ; done ; @@yesButton ; ; CLRC ; mark yes button pressed JR R5 ; done ; @@noButton ; ; SETC ; mark no button pressed JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle dealer's first card being an ace CheckDealerAce ; MVI $8a, R3 ; load dealer's first card ANDI #$f, R3 ; CMPI #$e, R3 ; BEQ AskPlayersIn ; if ace, goto AskPlayersIn ; MOVR R6, R7 ; done ; ------------------------------------------------------------------------------ ; Ask players if they are in AskPlayersIn PROC CLRR R0 ; set player 1 ; @@playerLoop1 ; ; MVII #$5a, R5 ; load screen address TSTR R0 ; BEQ @@showMessage ; if player 1, goto showMessage ; ADDI #$1a, R5 ; increment screen row for player 2 ; @@showMessage ; ; MVO R5, Usc.numberAddrLo ; store start screen address MVII #$9, R3 ; print 'I' MVO@ R3, R5 ; MVII #$e, R3 ; print 'N' MVO@ R3, R5 ; MVII #$3f, R3 ; print '?' MVO@ R3, R5 ; ; @@keyLoop ; ; JSR R4, SoundPulses ; beep, beep DECLE $1, $2 ; pulse count, pitch ; JSR R5, IsKeyPressed ; ; TSTR R0 ; BEQ @@keyLoop ; if key not pressed, goto keyLoop ; GSWD R0 ; store key result MVI Usc.numberAddrLo, R5 ; load screen start address CLRR R3 ; clear 'IN?' message MVO@ R3, R5 ; MVO@ R3, R5 ; MVO@ R3, R5 ; RSWD R0 ; restore key result BNC @@yesKey ; if yes key pressed, goto @@yesKey ; MVI Usc.betTmp1, R0 ; TSTR R0 ; BNEQ @@isPlayer1Bet0 ; if betTmp1 != 0, goto isPlayer1Bet0 ; MVI Usc.player, R0 ; load player TSTR R0 ; BNEQ @@done ; if player 2, goto done ; @@isAnotherPlayer ; ; MVI Usc.numberPlayers, R0 ; load number of players MVO R0, Usc.player ; store player TSTR R0 ; BNEQ @@playerLoop1 ; if two player, goto playerLoop1 ; B @@isPlayer1Bet0 ; goto isPlayer1Bet0 ; @@yesKey ; ; MVII #Usc.bet1, R4 ; load bet base address ADD Usc.player, R4 ; add player number MVI@ R4, R3 ; load bet INCR R4 ; MVO@ R3, R4 ; store bet in lost value MVI Usc.player, R0 ; load player TSTR R0 ; BEQ @@isAnotherPlayer ; if player 1, goto isAnotherPlayer ; @@isPlayer1Bet0 ; ; MVI Usc.totald, R3 ; load dealer total MVII #$15, R2 ; CMPR R2, R3 ; BNEQ DealerWonBank ; if total != 21, goto DealerWonBank ; MVO R2, Usc.dealer21 ; mark dealer as having 21 CLRR R0 ; MVI Usc.total1, R3 ; load total 1 CMPR R2, R3 ; compare with dealer BNEQ @@isPlayer2Bet0 ; if not equal, goto isPlayer2Bet0 ; MVO R0, Usc.bet1 ; set player 1 bet = 0 ; @@isPlayer2Bet0 ; ; MVI Usc.total2, R3 ; load total 2 CMPR R2, R3 ; BNEQ DealerAceShowCard ; if not equal, goto DealerAceShowCard ; MVO R0, Usc.bet2 ; set bet 2 = 0 ; ------------------------------------------------------------------------------ ; Show dealers card DealerAceShowCard ; ; MVI $8c, R3 ; show dealer's card XORI #$80, R3 ; MVO R3, $8c ; MVII #$1, R0 ; MVO R0, Usc.lostd ; set dealer lost CLRR R4 ; ; @@player1 ; ; CLRR R0 ; set player 1 ; @@playerLoop2 ; ; MVII #Usc.bank1Hi, R1 ; load bank 1 address MVII #Usc.betTmp1, R2 ; load betTmp1 address ADDR R0, R2 ; add player number to betTmp1 SLL R0 ; double player number ADDR R0, R1 ; add player number to bank address MVI@ R1, R3 ; load bank value SWAP R3 ; INCR R1 ; XOR@ R1, R3 ; TSTR R4 ; BNEQ @@playerLost ; if player lost, goto platerLost ; ADD@ R2, R3 ; add bet to bank INCR R7 ; skip next instruction ; @@playerLost ; ; SUB@ R2, R3 ; subtract bet from bank MVO@ R3, R1 ; store bank SWAP R3 ; DECR R1 ; MVO@ R3, R1 ; TSTR R0 ; BNEQ @@done ; if player2, goto done ; INCR R0 ; increment player B @@playerLoop2 ; goto playerLoop2 ; DealerWonBank ; ; MVII #$1, R4 ; set dealer won B @@player1 ; goto player1 ; @@done ; ; JR R6 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Ask the players whether they want to double AskDouble PROC CLRR R0 ; mark the first time through ; @@playerLoop ; ; MVII #$5a, R5 ; set screen address TSTR R0 ; BEQ @@printMessage ; if first time, goto printMessage ; ADDI #$1a, R5 ; shift 2 rows down ; @@printMessage ; ; MVO R5, Usc.numberAddrLo ; load message pointer MVII #$4, R3 ; print 'D' MVO@ R3, R5 ; SLR R3 ; print 'B' MVO@ R3, R5 ; MVII #$c, R3 ; print 'L' MVO@ R3, R5 ; MVII #$3f, R3 ; print '?' MVO@ R3, R5 ; ; @@keyLoop ; ; JSR R4, SoundPulses ; beep beep DECLE $1, $2 ; pulse count & pitch ; JSR R5, IsKeyPressed ; ; TSTR R0 ; BEQ @@keyLoop ; if no key pressed, goto keyLoop ; GSWD R0 ; store key MVI Usc.numberAddrLo, R5 ; clear message from screen CLRR R3 ; MVO@ R3, R5 ; MVO@ R3, R5 ; MVO@ R3, R5 ; MVO@ R3, R5 ; MVO R3, Usc.numberAddrLo ; RSWD R0 ; restore key press BNC @@yesKey ; if yes, goto yesKey ; MVI Usc.player, R0 ; load player number TSTR R0 ; BNEQ @@done ; if player 2, goto done ; @@player2 ; ; MVI Usc.numberPlayers, R0 ; load number of players MVO R0, Usc.player ; store player TSTR R0 ; BNEQ @@playerLoop ; if two player, goto playerLoop ; @@done ; ; MOVR R6, R7 ; done ; ------------------------------------------------------------------------------ ; Execute double @@yesKey ; ; JSR R5, DealScoreCard ; deal another card DECLE Usc.numberAddrLo ; result address ; JSR R5, AceCount ; count aces ; MVI Usc.round, R0 ; load and increment round INCR R0 ; JSR R5, ScrPrintCard ; display the card ; MVI Usc.player, R2 ; load player MOVR R2, R1 ; MVII #$15, R3 ; BEQ @@player1 ; if player 1, goto player1 ; ADDI #$18, R3 ; shift down 4 rows ; @@player1 ; ; MVO R3, Usc.numberScrPtr ; ADDI #Usc.bet1, R1 ; MVI@ R1, R0 ; load bet SLL R0 ; double value MVO@ R0, R1 ; store result MVII #Usc.double1, R1 ; ADDR R2, R1 ; MVII #$1, R3 ; MVO@ R3, R1 ; store 1 in doubled ADDI #Usc.total1, R2 ; MVI@ R2, R3 ; load hand total ADD Usc.numberAddrLo, R3 ; add card value MVO@ R3, R2 ; store total JSR R5, ScrPrintNumber ; display new bet ; JSR R5, CheckLoss ; goto CheckLoss ; MVI Usc.player, R0 ; load player TSTR R0 ; BNEQ @@showPlayer2 ; if player 2, goto showPlayer2 ; JSR R5, ScrPrintNumberIndirect ; DECLE $5f, Usc.total1 ; screen and value addresses ; B @@yesDone ; done ; @@showPlayer2 ; ; JSR R5, ScrPrintNumberIndirect ; DECLE $79, Usc.total2 ; screen and value addresses ; @@yesDone ; ; MVI Usc.player, R0 ; load player number TSTR R0 ; BEQ @@player2 ; if player 1, goto player2 ; MOVR R6, R7 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Play a series of sound pulses SoundPulses PROC MVI@ R4, R1 ; load pulse count MVI@ R4, R0 ; load pulse pitch ; @@pulseLoop ; ; MVO R0, Usc.sound ; start sound SDBD ; MVII #$7ff, R2 ; load pause count MOVR R2, R3 ; duplicate pause ; @@soundLoop ; ; DECR R3 ; pause for a bit BNEQ @@soundLoop ; ; MVO R3, Usc.sound ; silence speaker MOVR R2, R3 ; duplicate pause ; @@silenceLoop ; ; DECR R3 ; pause for a bit BNEQ @@silenceLoop ; ; DECR R1 ; loop on pulse count BNEQ @@pulseLoop ; ; JR R4 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Count the number of aces for each player AceCount PROC MVI Usc.player, R2 ; load player CMPI #$b, R4 ; BNEQ @@done ; if card not ace, goto done ; ADDI #Usc.aceCount1, R2 ; increment ace count MVI@ R2, R3 ; INCR R3 ; MVO@ R3, R2 ; ; @@done ; ; JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Clear the whole screen ScrClearAll CLRR R4 ; initialise start of screen B ScrClear ; ; ------------------------------------------------------------------------------ ; Clear the right pane of the screen ScrClearRight PROC MVII #$48, R4 ; initialise start of right pane ; ScrClear ; ; CLRR R3 ; clear screen ; @@loop ; ; MVO@ R3, R4 ; write current position CMPI #Usc.deck, R4 ; BNEQ @@loop ; if not end of screen, goto @@loop ; JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; N squared pause Pause PROC MVI@ R5, R0 ; load Pause MOVR R0, R1 ; square it ; @@outer ; ; DECR R1 ; R1-- BEQ @@done ; MOVR R1, R0 ; reset inner loop ; @@inner ; ; DECR R0 ; BNEQ @@inner ; iterate inner loop ; B @@outer ; iterate outer loop ; @@done ; ; MVO R0, Usc.sound ; silence the speaker JR R5 ; done ENDP ; ------------------------------------------------------------------------------ ; Screen addresses for messages MsgScreenAddress DECLE $4b, $65 ; ------------------------------------------------------------------------------ ; Write a 3 digit number indirectly ScrPrintNumberIndirect PROC MVI@ R5, R0 ; load screen address MVO R0, Usc.numberScrPtr ; store ready for call MVI@ R5, R1 ; load address of value MVI@ R1, R0 ; load value MOVR R5, R2 ; copy return address MVO R2, Usc.numberAddrLo ; store lower byte SWAP R2 ; MVO R2, Usc.listPtr ; store upper byte JSR R5, ScrPrintNumber ; print the number ; MVII #Usc.numberAddrLo, R5 ; restore return address SDBD ; MVI@ R5, R7 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Write a 3 digit number ScrPrintNumber CMPI #$3e7, R0 ; BGT @@reset ; if number > 999, goto reset ; TSTR R0 ; BPL @@resetCount ; if number > 0, goto resetCount ; @@reset ; ; CLRR R0 ; reset number ; @@resetCount ; ; CLRR R2 ; clear hundreds CLRR R3 ; clear tens CLRR R4 ; clear units ; @@count ; ; DECR R0 ; count BMI @@countDone ; if done, goto countDone ; INCR R4 ; increment units CMPI #$9, R4 ; BLE @@count ; if no rollover, goto count ; CLRR R4 ; reset units INCR R3 ; increment tens CMPI #$9, R3 ; BLE @@count ; if no rollover, goto count ; CLRR R3 ; reset tens INCR R2 ; increment hundreds B @@count ; goto count ; @@countDone ; ; MVII #$30, R0 ; evaluate characters ADDR R0, R2 ; ADDR R0, R3 ; ADDR R0, R4 ; CMPR R0, R2 ; is there a hundreds digit? BNEQ @@printDigits ; if digit, start printing ; CLRR R2 ; clear hundreds CMPR R0, R3 ; is there a tens digit? BNEQ @@printDigits ; if digit, start printing ; CLRR R3 ; clear tens ; @@printDigits ; ; MVI Usc.numberScrPtr, R1 ; load screen location MVO@ R2, R1 ; write out hundreds INCR R1 ; step on MVO@ R3, R1 ; write out tens INCR R1 ; step on MVO@ R4, R1 ; write out units JR R5 ; done ; ------------------------------------------------------------------------------ ; Shuffle deck of cards ShuffleDeck PROC MVII #$64, R6 ; load number of cards to shuffle ; @@loop ; ; JSR R4, ChooseCard ; choose a card ; MOVR R1, R2 ; store card JSR R4, ChooseCard ; choose a card ; ; ADDI #Usc.deck, R2 ; add deck start to card MVI@ R2, R4 ; load card ADDI #Usc.deck, R1 ; add deck start to card MVI@ R1, R3 ; load card MVO@ R4, R1 ; store card in deck MVO@ R3, R2 ; store card in deck DECR R6 ; BNEQ @@loop ; if enough cards done stop ; MVO R6, Usc.nextCardNo ; clear nextCardNo JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Select a card ChooseCard PROC MVI Usc.randomHi, R1 ; load random number SWAP R1 ; XOR Usc.randomLo, R1 ; MOVR R1, R0 ; copy address SLL R1, 2 ; multiply address by 16 SLL R1, 2 ; ADDR R0, R1 ; add on 3x original ADDR R0, R1 ; ADDR R0, R1 ; MVO R1, Usc.randomLo ; write out new random number SWAP R1 ; MVO R1, Usc.randomHi ; ANDI #$3f, R1 ; limit range CMPI #$33, R1 ; BGT ChooseCard ; if < 52 cards, goto ChooseCard ; JR R4 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Evaluate whether a player's hand is 21 GmeIs21 PROC MVII #Usc.total1, R3 ; MVII #Usc.double1, R2 ; MVI Usc.player, R1 ; load player ADDR R1, R2 ; MVI@ R2, R2 ; load double TSTR R2 ; BNEQ @@done ; if doubled, goto done ; ADDR R1, R3 ; MVI@ R3, R2 ; load hand total CMPI #$15, R2 ; BEQ @@player21 ; if total = 21, goto player21 ; JR R5 ; done ; @@player21 ; ; CMPI #$2, R1 ; BEQ @@done ; if player = dealer, goto done ; MVI Usc.totald, R0 ; load dealer total CMPI #$15, R0 ; BNEQ @@youWin ; if total != 21, goto youWin ; MVII #Usc.lost1, R2 ; ADDR R1, R2 ; MVO@ R0, R1 ; store total SDBD ; MVII #MsgPush, R3 ; load pointer to push message B @@printMessage ; ; @@youWin ; ; SDBD ; MVII #MsgYouWin, R3 ; load pointer to you win message ; @@printMessage ; ; SDBD ; MVII #MsgScreenAddress, R4 ; ADDR R1, R4 ; MVI@ R4, R4 ; load screen address ; @@charLoop ; ; MVI@ R3, R2 ; load character MVO@ R2, R4 ; print character INCR R3 ; increment input pointer TSTR R2 ; check for last character BNEQ @@charLoop ; if not 0, goto charLoop ; MVII #Usc.lost1, R3 ; ADDR R1, R3 ; MVII #$1, R2 ; MVO@ R2, R3 ; CMPI #$2, R1 ; BEQ @@done ; ; MOVR R1, R3 ; SLL R1 ; ADDI #Usc.bank1Hi, R1 ; MVI@ R1, R0 ; SWAP R0 ; INCR R1 ; XOR@ R1, R0 ; ADDI #Usc.bet1, R3 ; ADD@ R3, R0 ; ADD@ R3, R0 ; MVO@ R0, R1 ; DECR R1 ; SWAP R0 ; MVO@ R0, R1 ; ; @@done ; ; JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Check whether the current player has already lost CheckAlreadyLost PROC MVI Usc.player, R0 ; load player MVII #Usc.lost1, R3 ; ADDR R0, R3 ; MVI@ R3, R3 ; load player lost flag TSTR R3 ; BEQ @@notLost ; if not lost, goto notLost ; @@done ; ; JR R5 ; done ; @@notLost ; ; CMPI #$2, R0 ; BEQ CheckLoss ; if dealer, goto CheckLoss ; MVII #Usc.double1, R3 ; load player double ADDR R0, R3 ; MVI@ R3, R3 ; TSTR R3 ; BNEQ @@done ; if doubled, goto done ; ENDP ; ; ------------------------------------------------------------------------------ ; Check for lost game CheckLoss PROC MVII #Usc.total1, R3 ; evaluate hand total to check MVI Usc.player, R4 ; ADDR R4, R3 ; MVI@ R3, R0 ; load hand total CMPI #$2, R4 ; BEQ @@dealer ; if dealer, goto dealer ; CMPI #$15, R0 ; BGT @@aceCheck ; if total > 21, goto aceCheck ; B @@is5Cards ; ; @@dealer ; ; CMPI #$10, R0 ; BLE @@is5Cards ; if total <= 16, goto is5Cards ; MVII #$2, R4 ; CMP Usc.aceCountd, R4 ; BLE @@aceCheck ; if dealer's ace count <= 2, goto aceCheck ; JR R5 ; done ; @@is5Cards ; ; MVI Usc.round, R3 ; load round number CMPI #$5, R3 ; BEQ @@done ; if 5 cards dealt, goto done ; CLRR R3 ; clear R3 ; @@done ; ; JR R5 ; done ; @@aceCheck ; ; MVII #Usc.aceCount1, R2 ; ADD Usc.player, R2 ; MVI@ R2, R1 ; load player's ace count TSTR R1 ; BEQ @@bust ; if no aces, goto bust ; DECR R1 ; decrement and store ace count MVO@ R1, R2 ; SUBI #$a, R0 ; decrement total by 10 and store MVO@ R0, R3 ; B CheckAlreadyLost ; check player already having lost ; @@bust ; ; SDBD ; MVII #MsgScreenAddress, R4 ; ADD Usc.player, R4 ; MVI@ R4, R4 ; load screen address for bust message SDBD ; MVII #MsgBust, R3 ; load pointer for bust message ; @@charLoop ; ; MVI@ R3, R2 ; load message character MVO@ R2, R4 ; write character INCR R3 ; increment pointer TSTR R2 ; BNEQ @@charLoop ; if not done, goto charLoop ; MVII #Usc.lost1, R3 ; mark player as lost MVI Usc.player, R1 ; ADDR R1, R3 ; MVII #$1, R2 ; MVO@ R2, R3 ; store lost marker CMPI #$2, R1 ; BEQ @@bustDone ; if dealer, goto bustDone ; MVII #Usc.bank1Hi, R3 ; load bank address TSTR R1 ; BEQ @@adjustBank ; if player 1, goto adjustBank ; ADDI #$2, R3 ; increment to player 2 bank ; @@adjustBank ; ; MVI@ R3, R2 ; load bank (complicated because of SWAP R2 ; 8 bit RAM) INCR R3 ; XOR@ R3, R2 ; ADDI #Usc.bet1, R1 ; SUB@ R1, R2 ; reduce bank by bet MVO@ R2, R3 ; store new bank (complicated...) DECR R3 ; SWAP R2 ; MVO@ R2, R3 ; ; @@bustDone ; ; JR R5 ; done ; ENDP ; ; ------------------------------------------------------------------------------ ; Handle lost game HandEnd PROC MVII #Usc.bank1Hi, R2 ; load bank hi pointer MVI Usc.player, R3 ; load player TSTR R3 ; BEQ @@loadBank ; if player 1, goto loadBank ; ADDI #$2, R2 ; increment bank hi for player 2 ; @@loadBank ; ; MVI@ R2, R0 ; load bank SWAP R0 ; INCR R2 ; XOR@ R2, R0 ; MVII #Usc.bet1, R4 ; load bet 1 pointer ADDR R3, R4 ; MVI@ R5, R3 ; load win or loss TSTR R3 ; BNEQ @@adjustLoss ; if loss goto adjustLoss ; ADD@ R4, R0 ; increment bank and skip next instr INCR R7 ; ; @@adjustLoss ; ; SUB@ R4, R0 ; decrement bank MVO@ R0, R2 ; store update bank SWAP R0 ; DECR R2 ; MVO@ R0, R2 ; MVI Usc.gameType, R2 ; load game type SARC R2, 2 ; BNOV @@done ; if ???, goto done ; SDBD ; MVII #MsgScreenAddress, R4 ; load base bust message address ADD Usc.player, R4 ; increment address for player MVI@ R4, R4 ; load bust message address MVO R0, Usc.bankTmpLo ; store bank SWAP R0 ; MVO R0, Usc.bankTmpHi ; TSTR R3 ; BNEQ @@loseMessage ; if loss, goto loseMessage ; SDBD ; MVII #MsgYouWin, R3 ; set up you win message MVII #$1, R0 ; B @@charLoop ; ; @@loseMessage ; ; SDBD ; MVII #MsgYouLose, R3 ; set up you lose message MVII #$4, R0 ; ; @@charLoop ; ; MVI@ R3, R2 ; load message character MVO@ R2, R4 ; write out INCR R3 ; increment input pointer TSTR R2 ; check for end of message BNEQ @@charLoop ; if not end, loop again ; MVII #$18, R1 ; JSR R4, SoundPulses.pulseLoop ; beep beep ; MVII #Usc.bankTmpLo, R4 ; reload bank SDBD ; MVI@ R4, R0 ; ; @@done ; ; JR R5 ; done ; ENDP ; ; DECLE $0, $0, $0, $0, $0, $0, $0 ;