slot_machine.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. PromptUserToPlaySlots:
  2. call SaveScreenTilesToBuffer2
  3. ld a, BANK(DisplayTextIDInit)
  4. ld [wAutoTextBoxDrawingControl], a
  5. ld b, a
  6. ld hl, DisplayTextIDInit
  7. call Bankswitch
  8. ld hl, PlaySlotMachineText
  9. call PrintText
  10. call YesNoChoice
  11. ld a, [wCurrentMenuItem]
  12. and a
  13. jr nz, .done ; if player chose No
  14. dec a
  15. ld [wUpdateSpritesEnabled], a
  16. ld hl, wSlotMachineRerollCounter
  17. xor a
  18. ld [hli], a
  19. ld [hl], SMILE_BUBBLE
  20. predef EmotionBubble
  21. call GBPalWhiteOutWithDelay3
  22. call LoadSlotMachineTiles
  23. call LoadFontTilePatterns
  24. ld b, SET_PAL_SLOTS
  25. call RunPaletteCommand
  26. call GBPalNormal
  27. ld a, $e4
  28. ld [rOBP0], a
  29. ld hl, wd730
  30. set 6, [hl]
  31. xor a
  32. ld [wSlotMachineAllowMatchesCounter], a
  33. ld hl, wStoppingWhichSlotMachineWheel
  34. ld bc, $0014
  35. call FillMemory
  36. call MainSlotMachineLoop
  37. ld hl, wd730
  38. res 6, [hl]
  39. xor a
  40. ld [wSlotMachineAllowMatchesCounter], a
  41. call GBPalWhiteOutWithDelay3
  42. ld a, $1
  43. ld [wUpdateSpritesEnabled], a
  44. call RunDefaultPaletteCommand
  45. call ReloadMapSpriteTilePatterns
  46. call ReloadTilesetTilePatterns
  47. .done
  48. call LoadScreenTilesFromBuffer2
  49. call Delay3
  50. call GBPalNormal
  51. ld a, [wSlotMachineSavedROMBank]
  52. push af
  53. jp CloseTextDisplay
  54. PlaySlotMachineText:
  55. TX_FAR _PlaySlotMachineText
  56. db "@"
  57. MainSlotMachineLoop:
  58. call SlotMachine_PrintCreditCoins
  59. xor a
  60. ld hl, wPayoutCoins
  61. ld [hli], a
  62. ld [hl], a
  63. call SlotMachine_PrintPayoutCoins
  64. ld hl, BetHowManySlotMachineText
  65. call PrintText
  66. call SaveScreenTilesToBuffer1
  67. .loop
  68. ld a, A_BUTTON | B_BUTTON
  69. ld [wMenuWatchedKeys], a
  70. ld a, 2
  71. ld [wMaxMenuItem], a
  72. ld a, 12
  73. ld [wTopMenuItemY], a
  74. ld a, 15
  75. ld [wTopMenuItemX], a
  76. xor a
  77. ld [wCurrentMenuItem], a
  78. ld [wLastMenuItem], a
  79. ld [wMenuWatchMovingOutOfBounds], a
  80. coord hl, 14, 11
  81. ld b, 5
  82. ld c, 4
  83. call TextBoxBorder
  84. coord hl, 16, 12
  85. ld de, CoinMultiplierSlotMachineText
  86. call PlaceString
  87. call HandleMenuInput
  88. and B_BUTTON
  89. jp nz, LoadScreenTilesFromBuffer1
  90. ld a, [wCurrentMenuItem]
  91. ld b, a
  92. ld a, 3
  93. sub b
  94. ld [wSlotMachineBet], a
  95. ld hl, wPlayerCoins
  96. ld c, a
  97. ld a, [hli]
  98. and a
  99. jr nz, .skip1
  100. ld a, [hl]
  101. cp c
  102. jr nc, .skip1
  103. ld hl, NotEnoughCoinsSlotMachineText
  104. call PrintText
  105. jr .loop
  106. .skip1
  107. call LoadScreenTilesFromBuffer1
  108. call SlotMachine_SubtractBetFromPlayerCoins
  109. call SlotMachine_LightBalls
  110. call SlotMachine_SetFlags
  111. ld a, 4
  112. ld hl, wSlotMachineWheel1SlipCounter
  113. ld [hli], a
  114. ld [hli], a
  115. ld [hl], a
  116. call WaitForSoundToFinish
  117. ld a, SFX_SLOTS_NEW_SPIN
  118. call PlaySound
  119. ld hl, StartSlotMachineText
  120. call PrintText
  121. call SlotMachine_SpinWheels
  122. call SlotMachine_CheckForMatches
  123. ld hl, wPlayerCoins
  124. ld a, [hli]
  125. or [hl]
  126. jr nz, .skip2
  127. ld hl, OutOfCoinsSlotMachineText
  128. call PrintText
  129. ld c, 60
  130. jp DelayFrames
  131. .skip2
  132. ld hl, OneMoreGoSlotMachineText
  133. call PrintText
  134. coord hl, 14, 12
  135. lb bc, 13, 15
  136. xor a ; YES_NO_MENU
  137. ld [wTwoOptionMenuID], a
  138. ld a, TWO_OPTION_MENU
  139. ld [wTextBoxID], a
  140. call DisplayTextBoxID
  141. ld a, [wCurrentMenuItem]
  142. and a
  143. ret nz
  144. call SlotMachine_PutOutLitBalls
  145. jp MainSlotMachineLoop
  146. CoinMultiplierSlotMachineText:
  147. db "×3"
  148. next "×2"
  149. next "×1@"
  150. OutOfCoinsSlotMachineText:
  151. TX_FAR _OutOfCoinsSlotMachineText
  152. db "@"
  153. BetHowManySlotMachineText:
  154. TX_FAR _BetHowManySlotMachineText
  155. db "@"
  156. StartSlotMachineText:
  157. TX_FAR _StartSlotMachineText
  158. db "@"
  159. NotEnoughCoinsSlotMachineText:
  160. TX_FAR _NotEnoughCoinsSlotMachineText
  161. db "@"
  162. OneMoreGoSlotMachineText:
  163. TX_FAR _OneMoreGoSlotMachineText
  164. db "@"
  165. SlotMachine_SetFlags:
  166. ld hl, wSlotMachineFlags
  167. bit 7, [hl]
  168. ret nz
  169. ld a, [wSlotMachineAllowMatchesCounter]
  170. and a
  171. jr nz, .allowMatches
  172. call Random
  173. and a
  174. jr z, .setAllowMatchesCounter ; 1/256 (~0.4%) chance
  175. ld b, a
  176. ld a, [wSlotMachineSevenAndBarModeChance]
  177. cp b
  178. jr c, .allowSevenAndBarMatches
  179. ld a, 210
  180. cp b
  181. jr c, .allowMatches ; 55/256 (~21.5%) chance
  182. ld [hl], 0
  183. ret
  184. .allowMatches
  185. set 6, [hl]
  186. ret
  187. .setAllowMatchesCounter
  188. ld a, 60
  189. ld [wSlotMachineAllowMatchesCounter], a
  190. ret
  191. .allowSevenAndBarMatches
  192. set 7, [hl]
  193. ret
  194. SlotMachine_SpinWheels:
  195. ld c, 20
  196. .loop1
  197. push bc
  198. call SlotMachine_AnimWheel1
  199. call SlotMachine_AnimWheel2
  200. call SlotMachine_AnimWheel3
  201. ld c, 2
  202. call DelayFrames
  203. pop bc
  204. dec c
  205. jr nz, .loop1
  206. xor a
  207. ld [wStoppingWhichSlotMachineWheel], a
  208. .loop2
  209. call SlotMachine_HandleInputWhileWheelsSpin
  210. call SlotMachine_StopOrAnimWheel1
  211. call SlotMachine_StopOrAnimWheel2
  212. call SlotMachine_StopOrAnimWheel3
  213. ret c
  214. ld a, [wOnSGB]
  215. xor $1
  216. inc a
  217. ld c, a
  218. call DelayFrames
  219. jr .loop2
  220. ; Note that the wheels can only stop when a symbol is centred in the wheel
  221. ; and thus 3 full symbols rather than 2 full symbols and 2 half symbols are
  222. ; visible. The 3 functions below ensure this by checking if the wheel offset
  223. ; is even before stopping the wheel.
  224. SlotMachine_StopOrAnimWheel1:
  225. ld a, [wStoppingWhichSlotMachineWheel]
  226. cp 1
  227. jr c, .animWheel
  228. ld de, wSlotMachineWheel1Offset
  229. ld a, [de]
  230. rra
  231. jr nc, .animWheel ; check that a symbol is centred in the wheel
  232. ld hl, wSlotMachineWheel1SlipCounter
  233. ld a, [hl]
  234. and a
  235. ret z
  236. dec [hl]
  237. call SlotMachine_StopWheel1Early
  238. ret nz
  239. .animWheel
  240. jp SlotMachine_AnimWheel1
  241. SlotMachine_StopOrAnimWheel2:
  242. ld a, [wStoppingWhichSlotMachineWheel]
  243. cp 2
  244. jr c, .animWheel
  245. ld de, wSlotMachineWheel2Offset
  246. ld a, [de]
  247. rra
  248. jr nc, .animWheel ; check that a symbol is centred in the wheel
  249. ld hl, wSlotMachineWheel2SlipCounter
  250. ld a, [hl]
  251. and a
  252. ret z
  253. dec [hl]
  254. call SlotMachine_StopWheel2Early
  255. ret z
  256. .animWheel
  257. jp SlotMachine_AnimWheel2
  258. SlotMachine_StopOrAnimWheel3:
  259. ld a, [wStoppingWhichSlotMachineWheel]
  260. cp 3
  261. jr c, .animWheel
  262. ld de, wSlotMachineWheel3Offset
  263. ld a, [de]
  264. rra
  265. jr nc, .animWheel ; check that a symbol is centred in the wheel
  266. ; wheel 3 stops as soon as possible
  267. scf
  268. ret
  269. .animWheel
  270. call SlotMachine_AnimWheel3
  271. and a
  272. ret
  273. SlotMachine_StopWheel1Early:
  274. call SlotMachine_GetWheel1Tiles
  275. ld hl, wSlotMachineWheel1BottomTile
  276. ld a, [wSlotMachineFlags]
  277. and $80
  278. jr nz, .sevenAndBarMode
  279. ; Stop early if the middle symbol is not a cherry.
  280. inc hl
  281. ld a, [hl]
  282. cp SLOTSCHERRY >> 8
  283. jr nz, .stopWheel
  284. ret
  285. ; It looks like this was intended to make the wheel stop when a 7 symbol was
  286. ; visible, but it has a bug and so the wheel stops randomly.
  287. .sevenAndBarMode
  288. ld c, $3
  289. .loop
  290. ld a, [hli]
  291. cp SLOTS7 >> 8
  292. jr c, .stopWheel ; condition never true
  293. dec c
  294. jr nz, .loop
  295. ret
  296. .stopWheel
  297. inc a
  298. ld hl, wSlotMachineWheel1SlipCounter
  299. ld [hl], 0
  300. ret
  301. SlotMachine_StopWheel2Early:
  302. call SlotMachine_GetWheel2Tiles
  303. ld a, [wSlotMachineFlags]
  304. and $80
  305. jr nz, .sevenAndBarMode
  306. ; Stop early if any symbols are lined up in the first two wheels.
  307. call SlotMachine_FindWheel1Wheel2Matches
  308. ret nz
  309. jr .stopWheel
  310. ; Stop early if two 7 symbols or two bar symbols are lined up in the first two
  311. ; wheels OR if no symbols are lined up and the bottom symbol in wheel 2 is a
  312. ; 7 symbol or bar symbol. The second part could be a bug or a way to reduce the
  313. ; player's odds.
  314. .sevenAndBarMode
  315. call SlotMachine_FindWheel1Wheel2Matches
  316. ld a, [de]
  317. cp (SLOTSBAR >> 8) + 1
  318. ret nc
  319. .stopWheel
  320. xor a
  321. ld [wSlotMachineWheel2SlipCounter], a
  322. ret
  323. SlotMachine_FindWheel1Wheel2Matches:
  324. ; return whether wheel 1 and wheel 2's current positions allow a match (given
  325. ; that wheel 3 stops in a good position) in Z
  326. ld hl, wSlotMachineWheel1BottomTile
  327. ld de, wSlotMachineWheel2BottomTile
  328. ld a, [de]
  329. cp [hl] ; wheel 1 bottom, wheel 2 bottom
  330. ret z
  331. inc de
  332. ld a, [de]
  333. cp [hl] ; wheel 1 bottom, wheel 2 middle
  334. ret z
  335. inc hl
  336. cp [hl] ; wheel 1 middle, wheel 2 middle
  337. ret z
  338. inc hl
  339. cp [hl] ; wheel 1 top, wheel 2 middle
  340. ret z
  341. inc de
  342. ld a, [de]
  343. cp [hl] ; wheel 1 top, wheel 2 top
  344. ret z
  345. dec de
  346. dec de
  347. ret
  348. SlotMachine_CheckForMatches:
  349. call SlotMachine_GetWheel3Tiles
  350. ld a, [wSlotMachineBet]
  351. cp 2
  352. jr z, .checkMatchesFor2CoinBet
  353. cp 1
  354. jr z, .checkMatchFor1CoinBet
  355. ; 3 coin bet allows diagonal matches (plus the matches for 1/2 coin bets)
  356. ld hl, wSlotMachineWheel1BottomTile
  357. ld de, wSlotMachineWheel2MiddleTile
  358. ld bc, wSlotMachineWheel3TopTile
  359. call SlotMachine_CheckForMatch
  360. jp z, .foundMatch
  361. ld hl, wSlotMachineWheel1TopTile
  362. ld de, wSlotMachineWheel2MiddleTile
  363. ld bc, wSlotMachineWheel3BottomTile
  364. call SlotMachine_CheckForMatch
  365. jr z, .foundMatch
  366. ; 2 coin bet allows top/bottom horizontal matches (plus the match for a 1 coin bet)
  367. .checkMatchesFor2CoinBet
  368. ld hl, wSlotMachineWheel1TopTile
  369. ld de, wSlotMachineWheel2TopTile
  370. ld bc, wSlotMachineWheel3TopTile
  371. call SlotMachine_CheckForMatch
  372. jr z, .foundMatch
  373. ld hl, wSlotMachineWheel1BottomTile
  374. ld de, wSlotMachineWheel2BottomTile
  375. ld bc, wSlotMachineWheel3BottomTile
  376. call SlotMachine_CheckForMatch
  377. jr z, .foundMatch
  378. ; 1 coin bet only allows a middle horizontal match
  379. .checkMatchFor1CoinBet
  380. ld hl, wSlotMachineWheel1MiddleTile
  381. ld de, wSlotMachineWheel2MiddleTile
  382. ld bc, wSlotMachineWheel3MiddleTile
  383. call SlotMachine_CheckForMatch
  384. jr z, .foundMatch
  385. ld a, [wSlotMachineFlags]
  386. and $c0
  387. jr z, .noMatch
  388. ld hl, wSlotMachineRerollCounter
  389. dec [hl]
  390. jr nz, .rollWheel3DownByOneSymbol
  391. .noMatch
  392. ld hl, NotThisTimeText
  393. call PrintText
  394. .done
  395. xor a
  396. ld [wMuteAudioAndPauseMusic], a
  397. ret
  398. .rollWheel3DownByOneSymbol
  399. call SlotMachine_AnimWheel3
  400. call DelayFrame
  401. call SlotMachine_AnimWheel3
  402. call DelayFrame
  403. jp SlotMachine_CheckForMatches
  404. .foundMatch
  405. ld a, [wSlotMachineFlags]
  406. and $c0
  407. jr z, .rollWheel3DownByOneSymbol ; roll wheel if player isn't allowed to win
  408. and $80
  409. jr nz, .acceptMatch
  410. ; if 7/bar matches aren't enabled and the match was a 7/bar symbol, roll wheel
  411. ld a, [hl]
  412. cp (SLOTSBAR >> 8) + 1
  413. jr c, .rollWheel3DownByOneSymbol
  414. .acceptMatch
  415. ld a, [hl]
  416. sub $2
  417. ld [wSlotMachineWinningSymbol], a
  418. ld hl, SlotRewardPointers
  419. ld c, a
  420. ld b, 0
  421. add hl, bc
  422. ld a, [hli]
  423. ld e, a
  424. ld a, [hli]
  425. ld d, a
  426. push de
  427. ld a, [hli]
  428. ld h, [hl]
  429. ld l, a
  430. ld de, wcf4b
  431. ld bc, 4
  432. call CopyData
  433. pop hl
  434. ld de, .flashScreenLoop
  435. push de
  436. jp hl
  437. .flashScreenLoop
  438. ld a, [rBGP]
  439. xor $40
  440. ld [rBGP], a
  441. ld c, 5
  442. call DelayFrames
  443. dec b
  444. jr nz, .flashScreenLoop
  445. ld hl, wPayoutCoins
  446. ld [hl], d
  447. inc hl
  448. ld [hl], e
  449. call SlotMachine_PrintPayoutCoins
  450. ld hl, SymbolLinedUpSlotMachineText
  451. call PrintText
  452. call WaitForTextScrollButtonPress
  453. call SlotMachine_PayCoinsToPlayer
  454. call SlotMachine_PrintPayoutCoins
  455. ld a, $e4
  456. ld [rOBP0], a
  457. jp .done
  458. SymbolLinedUpSlotMachineText:
  459. TX_ASM
  460. push bc
  461. call SlotMachine_PrintWinningSymbol
  462. ld hl, LinedUpText
  463. pop bc
  464. inc bc
  465. inc bc
  466. inc bc
  467. inc bc
  468. ret
  469. LinedUpText:
  470. TX_FAR _LinedUpText
  471. db "@"
  472. SlotRewardPointers:
  473. dw SlotReward300Func
  474. dw SlotReward300Text
  475. dw SlotReward100Func
  476. dw SlotReward100Text
  477. dw SlotReward8Func
  478. dw SlotReward8Text
  479. dw SlotReward15Func
  480. dw SlotReward15Text
  481. dw SlotReward15Func
  482. dw SlotReward15Text
  483. dw SlotReward15Func
  484. dw SlotReward15Text
  485. SlotReward300Text:
  486. db "300@"
  487. SlotReward100Text:
  488. db "100@"
  489. SlotReward8Text:
  490. db "8@"
  491. SlotReward15Text:
  492. db "15@"
  493. NotThisTimeText:
  494. TX_FAR _NotThisTimeText
  495. db "@"
  496. ; compares the slot machine tiles at bc, de, and hl
  497. SlotMachine_CheckForMatch:
  498. ld a, [de]
  499. cp [hl]
  500. ret nz
  501. ld a, [bc]
  502. cp [hl]
  503. ret
  504. SlotMachine_GetWheel3Tiles:
  505. ld de, wSlotMachineWheel3BottomTile
  506. ld hl, SlotMachineWheel3
  507. ld a, [wSlotMachineWheel3Offset]
  508. call SlotMachine_GetWheelTiles
  509. SlotMachine_GetWheel2Tiles:
  510. ld de, wSlotMachineWheel2BottomTile
  511. ld hl, SlotMachineWheel2
  512. ld a, [wSlotMachineWheel2Offset]
  513. call SlotMachine_GetWheelTiles
  514. SlotMachine_GetWheel1Tiles:
  515. ld de, wSlotMachineWheel1BottomTile
  516. ld hl, SlotMachineWheel1
  517. ld a, [wSlotMachineWheel1Offset]
  518. SlotMachine_GetWheelTiles:
  519. ld c, a
  520. ld b, 0
  521. add hl, bc
  522. ld c, 3
  523. .loop
  524. ld a, [hli]
  525. ld [de], a
  526. inc de
  527. inc hl
  528. dec c
  529. jr nz, .loop
  530. ret
  531. SlotReward8Func:
  532. ld hl, wSlotMachineAllowMatchesCounter
  533. ld a, [hl]
  534. and a
  535. jr z, .skip
  536. dec [hl]
  537. .skip
  538. ld b, $2
  539. ld de, 8
  540. ret
  541. SlotReward15Func:
  542. ld hl, wSlotMachineAllowMatchesCounter
  543. ld a, [hl]
  544. and a
  545. jr z, .skip
  546. dec [hl]
  547. .skip
  548. ld b, $4
  549. ld de, 15
  550. ret
  551. SlotReward100Func:
  552. ld a, SFX_GET_KEY_ITEM
  553. call PlaySound
  554. xor a
  555. ld [wSlotMachineFlags], a
  556. ld b, $8
  557. ld de, 100
  558. ret
  559. SlotReward300Func:
  560. ld hl, YeahText
  561. call PrintText
  562. ld a, SFX_GET_ITEM_2
  563. call PlaySound
  564. call Random
  565. cp $80
  566. ld a, $0
  567. jr c, .skip
  568. ld [wSlotMachineFlags], a
  569. .skip
  570. ld [wSlotMachineAllowMatchesCounter], a
  571. ld b, $14
  572. ld de, 300
  573. ret
  574. YeahText:
  575. TX_FAR _YeahText
  576. TX_DELAY
  577. db "@"
  578. SlotMachine_PrintWinningSymbol:
  579. ; prints winning symbol and down arrow in text box
  580. coord hl, 2, 14
  581. ld a, [wSlotMachineWinningSymbol]
  582. add $25
  583. ld [hli], a
  584. inc a
  585. ld [hld], a
  586. inc a
  587. ld de, -SCREEN_WIDTH
  588. add hl, de
  589. ld [hli], a
  590. inc a
  591. ld [hl], a
  592. coord hl, 18, 16
  593. ld [hl], "▼"
  594. ret
  595. SlotMachine_SubtractBetFromPlayerCoins:
  596. ld hl, wTempCoins2 + 1
  597. ld a, [wSlotMachineBet]
  598. ld [hld], a
  599. xor a
  600. ld [hli], a
  601. ld de, wPlayerCoins + 1
  602. ld c, $2
  603. predef SubBCDPredef
  604. SlotMachine_PrintCreditCoins:
  605. coord hl, 5, 1
  606. ld de, wPlayerCoins
  607. ld c, $2
  608. jp PrintBCDNumber
  609. SlotMachine_PrintPayoutCoins:
  610. coord hl, 11, 1
  611. ld de, wPayoutCoins
  612. lb bc, LEADING_ZEROES | 2, 4 ; 2 bytes, 4 digits
  613. jp PrintNumber
  614. SlotMachine_PayCoinsToPlayer:
  615. ld a, $1
  616. ld [wMuteAudioAndPauseMusic], a
  617. call WaitForSoundToFinish
  618. ; Put 1 in the temp coins variable. This value is added to the player's coins
  619. ; repeatedly so the player can watch the value go up 1 coin at a time.
  620. ld hl, wTempCoins1
  621. xor a
  622. ld [hli], a
  623. inc a
  624. ld [hl], a
  625. ld a, 5
  626. ld [wAnimCounter], a
  627. ; Subtract 1 from the payout amount and add 1 to the player's coins each
  628. ; iteration until the payout amount reaches 0.
  629. .loop
  630. ld a, [wPayoutCoins + 1]
  631. ld l, a
  632. ld a, [wPayoutCoins]
  633. ld h, a
  634. or l
  635. ret z
  636. ld de, -1
  637. add hl, de
  638. ld a, l
  639. ld [wPayoutCoins + 1], a
  640. ld a, h
  641. ld [wPayoutCoins], a
  642. ld hl, wTempCoins1 + 1
  643. ld de, wPlayerCoins + 1
  644. ld c, $2
  645. predef AddBCDPredef
  646. call SlotMachine_PrintCreditCoins
  647. call SlotMachine_PrintPayoutCoins
  648. ld a, SFX_SLOTS_REWARD
  649. call PlaySound
  650. ld a, [wAnimCounter]
  651. dec a
  652. jr nz, .skip1
  653. ld a, [rOBP0]
  654. xor $40 ; make the slot wheel symbols flash
  655. ld [rOBP0], a
  656. ld a, 5
  657. .skip1
  658. ld [wAnimCounter], a
  659. ld a, [wSlotMachineWinningSymbol]
  660. cp (SLOTSBAR >> 8) + 1
  661. ld c, 8
  662. jr nc, .skip2
  663. srl c ; c = 4 (make the the coins transfer faster if the symbol was 7 or bar)
  664. .skip2
  665. call DelayFrames
  666. jr .loop
  667. SlotMachine_PutOutLitBalls:
  668. ld a, $23
  669. ld [wNewSlotMachineBallTile], a
  670. jr SlotMachine_UpdateThreeCoinBallTiles
  671. SlotMachine_LightBalls:
  672. ld a, $14
  673. ld [wNewSlotMachineBallTile], a
  674. ld a, [wSlotMachineBet]
  675. dec a
  676. jr z, SlotMachine_UpdateOneCoinBallTiles
  677. dec a
  678. jr z, SlotMachine_UpdateTwoCoinBallTiles
  679. SlotMachine_UpdateThreeCoinBallTiles:
  680. coord hl, 3, 2
  681. call SlotMachine_UpdateBallTiles
  682. coord hl, 3, 10
  683. call SlotMachine_UpdateBallTiles
  684. SlotMachine_UpdateTwoCoinBallTiles:
  685. coord hl, 3, 4
  686. call SlotMachine_UpdateBallTiles
  687. coord hl, 3, 8
  688. call SlotMachine_UpdateBallTiles
  689. SlotMachine_UpdateOneCoinBallTiles:
  690. coord hl, 3, 6
  691. SlotMachine_UpdateBallTiles:
  692. ld a, [wNewSlotMachineBallTile]
  693. ld [hl], a
  694. ld bc, 13
  695. add hl, bc
  696. ld [hl], a
  697. ld bc, 7
  698. add hl, bc
  699. inc a
  700. ld [hl], a
  701. ld bc, 13
  702. add hl, bc
  703. ld [hl], a
  704. ret
  705. SlotMachine_AnimWheel1:
  706. ld bc, SlotMachineWheel1
  707. ld de, wSlotMachineWheel1Offset
  708. ld hl, wOAMBuffer
  709. ld a, $30
  710. ld [wBaseCoordX], a
  711. jr SlotMachine_AnimWheel
  712. SlotMachine_AnimWheel2:
  713. ld bc, SlotMachineWheel2
  714. ld de, wSlotMachineWheel2Offset
  715. ld hl, wOAMBuffer + $30
  716. ld a, $50
  717. ld [wBaseCoordX], a
  718. jr SlotMachine_AnimWheel
  719. SlotMachine_AnimWheel3:
  720. ld bc, SlotMachineWheel3
  721. ld de, wSlotMachineWheel3Offset
  722. ld hl, wOAMBuffer + $60
  723. ld a, $70
  724. ld [wBaseCoordX], a
  725. SlotMachine_AnimWheel:
  726. ld a, $58
  727. ld [wBaseCoordY], a
  728. push de
  729. ld a, [de]
  730. ld d, b
  731. add c
  732. ld e, a
  733. jr nc, .loop
  734. inc d
  735. .loop
  736. ld a, [wBaseCoordY]
  737. ld [hli], a
  738. ld a, [wBaseCoordX]
  739. ld [hli], a
  740. ld a, [de]
  741. ld [hli], a
  742. ld a, $80
  743. ld [hli], a
  744. ld a, [wBaseCoordY]
  745. ld [hli], a
  746. ld a, [wBaseCoordX]
  747. add $8
  748. ld [hli], a
  749. ld a, [de]
  750. inc a
  751. ld [hli], a
  752. ld a, $80
  753. ld [hli], a
  754. inc de
  755. ld a, [wBaseCoordY]
  756. sub $8
  757. ld [wBaseCoordY], a
  758. cp $28
  759. jr nz, .loop
  760. pop de
  761. ld a, [de]
  762. inc a ; advance the offset so that the wheel animates
  763. cp 30
  764. jr nz, .skip
  765. xor a ; wrap around to 0 when the offset reaches 30
  766. .skip
  767. ld [de], a
  768. ret
  769. SlotMachine_HandleInputWhileWheelsSpin:
  770. call DelayFrame
  771. call JoypadLowSensitivity
  772. ld a, [hJoy5]
  773. and A_BUTTON
  774. ret z
  775. ld hl, wStoppingWhichSlotMachineWheel
  776. ld a, [hl]
  777. dec a
  778. ld de, wSlotMachineWheel1SlipCounter
  779. jr z, .skip
  780. dec a
  781. ld de, wSlotMachineWheel2SlipCounter
  782. jr z, .skip
  783. .loop
  784. inc [hl]
  785. ld a, SFX_SLOTS_STOP_WHEEL
  786. jp PlaySound
  787. .skip
  788. ld a, [de]
  789. and a
  790. ret nz
  791. jr .loop
  792. LoadSlotMachineTiles:
  793. call DisableLCD
  794. ld hl, SlotMachineTiles2
  795. ld de, vChars0
  796. ld bc, $1c0
  797. ld a, BANK(SlotMachineTiles2)
  798. call FarCopyData2
  799. ld hl, SlotMachineTiles1
  800. ld de, vChars2
  801. ld bc, $250
  802. ld a, BANK(SlotMachineTiles1)
  803. call FarCopyData2
  804. ld hl, SlotMachineTiles2
  805. ld de, vChars2 + $250
  806. ld bc, $1c0
  807. ld a, BANK(SlotMachineTiles2)
  808. call FarCopyData2
  809. ld hl, SlotMachineMap
  810. coord de, 0, 0
  811. ld bc, SlotMachineMapEnd - SlotMachineMap
  812. call CopyData
  813. call EnableLCD
  814. ld hl, wSlotMachineWheel1Offset
  815. ld a, $1c
  816. ld [hli], a
  817. ld [hli], a
  818. ld [hl], a
  819. call SlotMachine_AnimWheel1
  820. call SlotMachine_AnimWheel2
  821. jp SlotMachine_AnimWheel3
  822. SlotMachineMap:
  823. INCBIN "gfx/tilemaps/slotmachine.map"
  824. SlotMachineMapEnd:
  825. INCLUDE "data/slot_machine_wheels.asm"
  826. SlotMachineTiles1:
  827. IF DEF(_RED)
  828. INCBIN "gfx/red/slotmachine1.2bpp"
  829. ENDC
  830. IF DEF(_BLUE)
  831. INCBIN "gfx/blue/slotmachine1.2bpp"
  832. ENDC