Prev: 38221 Up: Map Next: 38265
38222: Draw Cards
Used by the routine at PlayGame.
Input
IX Pointer to either the player or girls hand
If a card value in the players hand is 255 this indicates that a card needs to be drawn.
If a card value in CardDeck is 255 this indicates that the card has already been chosen.
DrawCards 38222 PUSH IX Stash IX on the stack.
38224 PUSH IX DE=IX (using the stack).
38226 POP DE
38227 LD B,5 A hand consists of 5 cards.
DrawCards_Loop 38229 PUSH BC Stash the card count on the stack.
DrawCards_RePick 38230 LD HL,38331 HL=CardDeck.
Only draw a card if the current position in the hand is marked as needing to be picked.
38233 LD A,(DE) Jump to DrawCards_Next if the hand pointer is not equal to 255.
38234 CP 255
38236 JR NZ,DrawCards_Next
38238 PUSH DE Stash the hand and deck pointers on the stack temporarily.
38239 PUSH HL
38240 CALL GetRandomNumber Call GetRandomNumber.
38243 POP HL Restore the deck and hand pointers from the stack.
38244 POP DE
38245 LD C,A Create an offset in BC.
38246 LD B,0
38248 DEC BC Decrease the card count by one.
38249 ADD HL,BC HL+=BC.
38250 LD A,(HL) Jump to DrawCards_RePick if this card has already been picked (if the chosen card "value" is equal to 255).
38251 CP 255
38253 JR Z,DrawCards_RePick
The picked card is valid and able to be drawn into the hand.
38255 LD (DE),A Write the drawn card to the current hand position.
38256 LD (HL),255 Now mark the card in the deck as being unavailable so it can't be chosen again.
DrawCards_Next 38258 POP BC Restore the card count from the stack.
38259 INC DE Increment the hand pointer by one.
38260 DJNZ DrawCards_Loop Decrease the card count by one and loop back to DrawCards_Loop until the deck is filled.
38262 POP IX Restore IX from the stack.
38264 RET Return.
Prev: 38221 Up: Map Next: 38265