Advertisement
AnthonyCagliano

Untitled

Jan 6th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.38 KB | None | 0 0
  1. with the exception of rendering a few text strings and looping that dice->LCD code, game is done. Things of note...
  2.  
  3. 1. In the game, if you CANNOT score against a combo, you are forced to enter a score of 0 on an open combo. In this code, this is written as a value of -1. Every score is therefore upped by 1, so I can just dec a before saving it. The code to see if a combo is available (under EnterScore) should exit if a non-zero value exists for that combo.
  4.  
  5. 2. entryMode now controls what actions you can perform. Bit0 is throwing the dice, Bit1 is scoring against a combo. In this code, if both bits are set, you should be able to do everything. If only bit 0 is set, you should be able to roll the dice, and hold a dice, but do nothing else. If only bit 1 is set, you should be able to toggle combos and select one, but do nothing else. You should always be able to bring up the instructions and quit the game.
  6.  
  7.  
  8. ; Yatzee for TI-83+/84+
  9. ; Version 1.0
  10. ; by ACagliano
  11.  
  12. .nolist
  13. #include "ti83plus.inc"
  14. #include "dcs7.inc"
  15. .list
  16. ; defines/equates
  17. #define diceOne 0
  18. #define diceTwo 1
  19. #define diceThree 2
  20. #define diceFour 3
  21. #define diceFive 4
  22. #define diceSix 5
  23. #define comboScores saferam1
  24. #define threeOnes 0
  25. #define threeTwos 1
  26. #define threeThrees 2
  27. #define threeFours 3
  28. #define threeFives 4
  29. #define threeSixes 5
  30. #define threeOfaKind 6
  31. #define fourOfaKind 7
  32. #define fullHouse 8
  33. #define smStraight 9
  34. #define lgStraight 10
  35. #define chance 11
  36. #define yatzee 12
  37. #define threesBonus 13
  38. #define gameScore comboScores+threesBonus
  39. #define entryMode gameScore+2
  40. #define spin 0
  41. #define score 1
  42. #define highScore entryMode+1
  43. #define curRolls highScore+2
  44. #define dieValues curRolls+1
  45. #define dieHoldFlags dieValues+5
  46. #define threesPoints dieHoldFlags+1
  47. #define saveSize threesPoints-comboFlags
  48.  
  49. #define selectedCombo dieHoldFlags+1
  50. #define ptsforSelected selectedCombo+1
  51. #define rollBonuses ptsforSelected+2
  52. #define ctOnes rollBonuses+1
  53. #define ctTwos ctOnes+1
  54. #define ctThrees ctTwos+1
  55. #define ctFours ctThrees+1
  56. #define ctFives ctFours+1
  57. #define ctSixes ctFives+1
  58.  
  59.  
  60. .db $BB,$6D
  61. .org progstart
  62.  
  63. Start:
  64. bcall(_ClrLCDFull)
  65. ld a,r ;\
  66. ld h,a ; |
  67. xor 77 ; |Seed the RNG
  68. ld l,a ; |
  69. ld (seed1),hl ; |
  70. ld (seed2),hl ;/
  71.  
  72. push iy \ ld iy,comboScores ; push system flags location, set IY to comboScores address
  73. ld ix,dieValues ; set IX to 5-byte die roll values
  74.  
  75. ld hl,gameScore \ ld b,ctSixes-comboScores \ call zeroData ; zero the RAM savestate
  76.  
  77. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym) ; \
  78. jr c,StartGame ; | check whether save file exists
  79. ld b,a \ or a \ jr z,{1@} ; | if it doesn't skip to game start
  80. bcall(_Arc_Unarc) \ bcall(_ChkFindSym) ; | if it does and is unarchived, skip to loading
  81. @: ex de,hl \ ld de,comboFlags ; | if it does and is archived, unarchive it
  82. inc hl \ inc hl ; | load the savestate into RAM
  83. ld bc,saveSize ; |
  84. ldir ; /
  85. StartGame:
  86. call renderDie
  87. call renderStats
  88. ld hl,entryMode \ set spin,(hl) ; enable spinning, but not scoring yet
  89. KeywaitLoop:
  90. ld a,(kbdScanCode) \ or a \ jr z,KeywaitLoop
  91. ld hl,entryMode
  92. bit score,(hl) \ jr z,{1@} ; if the score bit is reset, you are not allowed to score now
  93. cp skLeft \ jp cycleLeftCombos
  94. cp skRight \ jp cycleRightCombos
  95. cp skEnter \ jp EnterScore
  96. bit spin,(hl) \ jr z,KeywaitLoop ; if the spin bit is reset, you are not allowed to spin now
  97.  
  98. @: sub 54 \ add a,5 \ jp c,holdDice
  99. add a,49
  100. cp sk2nd \ jp throwDie
  101. cp skClear \ jp QuitGame
  102. jr KeywaitLoop
  103.  
  104. holdDice:
  105. ld hl,dieValues
  106. add a,l \ ld l,a \ jr nc,$+3
  107. inc h \ ld a,(hl)
  108. xor 80h \ ld (hl),a
  109. jp KeywaitLoop
  110.  
  111.  
  112. ; ### Select Combo and Compute Score ###
  113.  
  114. cycleLeftCombos:
  115. ld hl,selectedCombo \ dec (hl)
  116. call calcScore
  117. jp KeywaitLoop
  118. cycleRightCombos:
  119. ld hl,selectedCombo \ inc (hl)
  120. call calcScore
  121. jp KeywaitLoop
  122.  
  123. calcScore:
  124. #define checkQuantity inc hl \ sub (hl)
  125. ld hl,dieValues-1
  126. call getDieValue
  127. call getDieValue
  128. call getDieValue
  129. call getDieValue
  130. call getDieValue
  131. ; now we test the combo that is active. Score is either returned, or 0.
  132. ld hl,calcBonuses \ push hl ; we do this so we can use ret at the end of the routines ahead and it acts like a jump
  133. ld a,(selectedCombo)
  134. or a \ jr z,isThreeOnes
  135. cp threeTwos \ jr z,isThreeTwos
  136. cp threeThrees \ jr z,isThreeThrees
  137. cp threeFours \ jr z,isThreeFours
  138. cp threeFives \ jr z,isThreeFives
  139. cp threeSixes \ jr z,isThreeSixes
  140. cp threeOfaKind \ jr z,isThreeOfaKind
  141. cp fourOfaKind \ jr z,isFourOfaKind
  142. cp fullHouse \ jr z,isFullHouse
  143. cp smStraight \ jr z,isSmStraight
  144. cp lgStraight \ jr z,isLgStraight
  145. cp chance \ jr z,sumtheDie
  146. cp yatzee \ jr z,isYatzee
  147. calcBonuses:
  148. dec a \ ld (ptsforSelected),a
  149. call isYatzee \ or a \ jr z,{1@}
  150. dec a \ ld (rollBonuses),a
  151. @: ld a,(threesBonus) \ or a \ call z,isFullTopSix
  152. ld hl,rollBonuses \ add a,(hl)
  153. call rendertPoints
  154. ret
  155.  
  156. isThreeOnes:
  157. ld a,(ctOnes) \ inc a \ ret
  158. isThreeTwos:
  159. ld a,(ctTwos)
  160. rla \ inc a \ ret
  161. isThreeThrees:
  162. ld a,(ctThrees)
  163. ld b,a \ rla \ add a,b
  164. inc a \ ret
  165. isThreeFours:
  166. ld a,(ctFours)
  167. rla \ rla
  168. inc a \ ret
  169. isThreeFives:
  170. ld a,(ctFives)
  171. ld b,a \ rla \ rla \ add a,b
  172. inc a \ ret
  173. isThreeSixes:
  174. ld a,(ctSixes)
  175. rla \ rla \ rla
  176. inc a \ ret
  177. isThreeOfaKind:
  178. ld a,2 \ jr {1@}
  179. isFourOfaKind:
  180. ld a,3
  181. @: ld hl,ctOnes-1
  182. checkQuantity \ jr c,sumtheDie
  183. checkQuantity \ jr c,sumtheDie
  184. checkQuantity \ jr c,sumtheDie
  185. checkQuantity \ jr c,sumtheDie
  186. checkQuantity \ jr c,sumtheDie
  187. ld a,0
  188. ret
  189.  
  190. isFullHouse:
  191. ld a,2 \ ld hl,ctOnes-1
  192. checkQuantity \ jr c,{1@}
  193. checkQuantity \ jr c,{1@}
  194. checkQuantity \ jr c,{1@}
  195. checkQuantity \ jr c,{1@}
  196. checkQuantity \ jr c,{1@}
  197. jr {3@}
  198. @: ld a,1 \ ld hl,ctOnes-1
  199. checkQuantity \ jr c,{1@}
  200. checkQuantity \ jr c,{1@}
  201. checkQuantity \ jr c,{1@}
  202. checkQuantity \ jr c,{1@}
  203. checkQuantity \ jr c,{1@}
  204. jr {2@}
  205. @: ld a,26 \ ret
  206. @: ld a,0 \ ret
  207.  
  208. isSmStraight:
  209. ld hl,ctOnes \ ld a,(hl)
  210. or a \ jr z,strt_start_2
  211. ld b,3
  212. inc hl \ and (hl)
  213. djnz $-2
  214. jr nz,{1@}
  215. strt_start_2:
  216. inc hl \ ld a,(hl)
  217. or a \ jr z,strt_start_3
  218. ld b,3
  219. inc hl \ and (hl)
  220. djnz $-2
  221. jr nz,{}
  222. strt_start_3:
  223. inc hl \ ld a,(hl)
  224. or a \ ret z
  225. ld b,3
  226. inc hl \ and (hl)
  227. djnz $-2
  228. ret z
  229. @: ld a,31 \ ret
  230.  
  231. isLgStraight
  232. ld hl,ctOnes \ ld a,(hl)
  233. or a \ jr z,strt_1_to_5
  234. ;strt_2_to_6:
  235. inc hl
  236. strt_1_to5:
  237. ld a,(hl) \ ld b,3
  238. inc hl \ and (hl)
  239. djnz $-2
  240. ret z
  241. ld a,41 \ ret
  242. @: ld a,0 \ ret
  243.  
  244. isYatzee:
  245. ld hl,ctOnes-1 \ ld a,4
  246. checkQuantity \ jr c,{1@}
  247. checkQuantity \ jr c,{1@}
  248. checkQuantity \ jr c,{1@}
  249. checkQuantity \ jr c,{1@}
  250. checkQuantity \ jr c,{1@}
  251. ld a,0 \ ret
  252. @: ld a,51 \ ret
  253.  
  254. isFullTopSix:
  255. ld hl,comboScores \ ld a,0
  256. ld b,6
  257. @: add a,(hl) \ inc hl
  258. djnz {-1@}
  259. cp 62 \ jr c,{1@}
  260. ld a,0 \ ret
  261. @: ld a,1 \ ld (threesBonus),a \ ld a,35 \ ret
  262.  
  263.  
  264.  
  265.  
  266. sumtheDie:
  267. ld a,0 \ ld hl,dieValues
  268. ld b,5
  269. @: add a,(hl) \ inc hl
  270. djnz {-1@}
  271. inc a
  272. ret
  273.  
  274.  
  275.  
  276.  
  277. getDieValue:
  278. inc hl
  279. ld a,(hl) \ and %01111111 ; reset high byte in A, not in memory
  280. cp 1 \ jr nz,{1@}
  281. ld a,(ctOnes) \ inc a \ ld (ctOnes),a \ ret
  282. @: cp 2 \ jr nz,{1@}
  283. ld a,(ctTwos) \ inc a \ ld (ctTwos),a \ ret
  284. @: cp 3 \ jr nz,{1@}
  285. ld a,(ctThrees) \ inc a \ ld (ctThrees),a \ ret
  286. @: cp 4 \ jr nz,{1@}
  287. ld a,(ctFours) \ inc a \ ld (ctFours),a \ ret
  288. @: cp 5 \ jr nz,{1@}
  289. ld a,(ctFives) \ inc a \ ld (ctFives),a \ ret
  290. @: cp 6 \ ret nz
  291. ld a,(ctSixes) \ inc a \ ld (ctSixes),a \ ret
  292.  
  293.  
  294.  
  295.  
  296.  
  297. throwDie:
  298. ; randomize the value of each die, if the hold flag for that die is not set
  299. ld hl,dieValues-1
  300. call roll
  301. call roll
  302. call roll
  303. call roll
  304. call roll
  305. call renderDie
  306. ld hl,entryMode \ set score,(hl) ; allow scoring once die rolled
  307. ld hl,curRolls \ inc (hl) ; increment number of rolls by one
  308. ld a,3 \ sub (hl) \ jr nz,KeywaitLoop ; if rolls != 3, leave routine
  309. ld hl,entryMode \ res spin,(hl) ; if rolls = 3, disable rolling
  310. jr KeywaitLoop
  311.  
  312.  
  313. EnterScore:
  314. ld hl,comboScores
  315. ld a,(selectedCombo) \ ld c,a \ ld b,0
  316. add hl,bc
  317. ld a,(hl) \ or a \ jr nz,{1@}
  318. ld a,(ptsforSelected) \ ld (hl),a
  319. cp -1 \ jr z,{1@}
  320. ld hl,(gameScore)
  321. ld bc,(ptsforSelected)
  322. add hl,bc ; add score to game score
  323. ld b,0 \ ld c,(rollBonuses)
  324. add hl,bc ; add bonuses to game score
  325. ld (gameScore),hl ; write new score back
  326. ld hl,entryMode \ res score,(hl) \ set spin,(hl) ; disable scoring, enable spinning
  327. ld a,0 \ ld (curRolls),a ; set back to 0 rolls
  328. @: jp KeywaitLoop
  329.  
  330. QuitGame:
  331. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym)
  332. jr nc,{1@} ; if save exists already, skip to saving
  333. ld hl,saveSize \ bcall(_CreateAppVar) ; if it doesn't, create it
  334. @: ld hl,comboFlags \ inc de \ inc de ; set read address to RAM state, set write address to after size word
  335. ld bc,saveSize \ ldir ; set size, load
  336. bcall(_ClrLCDFull) ; clear screen
  337. pop iy ; restore system flags
  338. ret ; exit game
  339.  
  340. renderDie:
  341. ld hl,Sprites
  342.  
  343. ret
  344.  
  345. renderStats:
  346.  
  347. ret
  348.  
  349.  
  350.  
  351. rendertPoints:
  352. ld a,(selectedCombo)
  353. ld hl,ComboNameText \ ld b,a
  354. or a \ jr z,{2@}
  355. @: add hl,7
  356. djnz {-1@}
  357. @: ; set penCol and penRow
  358. bcall(_vPutS)
  359. ld a,(ptsforSelected)
  360. ; convert byte value into text string
  361. ret
  362.  
  363. die_setZero:
  364. ld hl,dieValues ; set read address to dieValues
  365. ld a,0 \ ld (hl),a ; set dieValues to 0
  366. ld de,dieValues+1 ; set write address to dieValues+1
  367. ld bc,4 \ ldir ; copy 4 bytes from read address to write address
  368. ret
  369.  
  370. zeroData:
  371. ld a,0
  372. ld (hl),a \ inc hl
  373. djnz zeroData
  374. ret
  375.  
  376. ; ########################
  377. ; Random Number Generator
  378. ; ########################
  379.  
  380. prng16:
  381. ;collab with Runer112
  382. ;;Output:
  383. ;; HL is a pseudo-random int
  384. ;; A and BC are also, but much weaker and smaller cycles
  385. ;; Preserves DE
  386. ;;148cc, super fast
  387. ;;26 bytes
  388. ;;period length: 4,294,901,760
  389. seed1=$+1
  390. ld hl,9999
  391. ld b,h
  392. ld c,l
  393. add hl,hl
  394. add hl,hl
  395. inc l
  396. add hl,bc
  397. ld (seed1),hl
  398. seed2=$+1
  399. ld hl,987
  400. add hl,hl
  401. sbc a,a
  402. and %00101101
  403. xor l
  404. ld l,a
  405. ld (seed2),hl
  406. add hl,bc
  407. ret
  408. roll:
  409. ;;Input: A is the range.
  410. ;;Output: Returns in A a random number from 0 to B-1.
  411. ;; B=0
  412. ;; DE is not changed
  413. ;;Destroys:
  414. ;; HL
  415. ;;Speed:
  416. ;; 322cc to 373cc, 347.5cc average
  417. inc hl
  418. ld a,(hl) \ add a,a
  419. ret nc
  420. push hl
  421. call prng16
  422. ld l,h \ ld h,0
  423. ld b,h \ ld c,l
  424. add hl,hl \ add hl,bc \ add hl,hl
  425. inc h \ ld a,h
  426. pop hl
  427. ld (hl),a
  428. ret
  429.  
  430. ; ########################
  431. ; ## Rendering Routines ##
  432. ; ########################
  433.  
  434. drawSprite_6_Bit:
  435. ld a,d \ add a,$79 ; Y coord into A
  436. ld b,12 ; Loop this 12 times
  437. drawSprite_outerloop:
  438. inc a \ push af
  439. out ($10),a \ call lcdwait
  440. ld a,e \ add a,$20
  441. out ($10),a \ call lcdwait ; use outi instead
  442. ld c,$11
  443. outi \ call lcdwait
  444. outi \ call lcdwait
  445. pop bc \ pop af
  446. djnz drawSprite_outerloop
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455. lcdwait:
  456. in a,($10) ;bit 7 set if LCD is busy
  457. rla \ jr c,lcdwait
  458. ret
  459.  
  460.  
  461.  
  462. GameSave:
  463. .db AppVarObj,"YatSave",0
  464.  
  465. ComboNameText:
  466. .db "Ones ",0
  467. .db "Twos ",0
  468. .db "Threes",0
  469. .db "Fours ",0
  470. .db "Fives ",0
  471. .db "Sixes ",0
  472. .db "3.of.a",0
  473. .db "4.of.a.",0
  474. .db "F.Hse.",0
  475. .db "Sm.St.",0
  476. .db "Lg.St.",0
  477. .db "Chance",0
  478. .db "Yatzee",0
  479.  
  480.  
  481. Sprites:
  482. ; empty die
  483. .db %11111111,%11110000
  484. .db %10000000,%00010000
  485. .db %10000000,%00010000
  486. .db %10000000,%00010000
  487. .db %10000000,%00010000
  488. .db %10000000,%00010000
  489. .db %10000000,%00010000
  490. .db %10000000,%00010000
  491. .db %10000000,%00010000
  492. .db %10000000,%00010000
  493. .db %10000000,%00010000
  494. .db %11111111,%11110000
  495. ; one die
  496. .db %11111111,%11110000
  497. .db %10000000,%00010000
  498. .db %10000000,%00010000
  499. .db %10000000,%00010000
  500. .db %10000000,%00010000
  501. .db %10000110,%00010000
  502. .db %10000110,%00010000
  503. .db %10000000,%00010000
  504. .db %10000000,%00010000
  505. .db %10000000,%00010000
  506. .db %10000000,%00010000
  507. .db %11111111,%11110000
  508. ; two die
  509. .db %11111111,%11110000
  510. .db %10000000,%00010000
  511. .db %10000000,%00010000
  512. .db %10000110,%00010000
  513. .db %10000110,%00010000
  514. .db %10000000,%00010000
  515. .db %10000000,%00010000
  516. .db %10000110,%00010000
  517. .db %10000110,%00010000
  518. .db %10000000,%00010000
  519. .db %10000000,%00010000
  520. .db %11111111,%11110000
  521. ; three die
  522. .db %11111111,%11110000
  523. .db %10000000,%00010000
  524. .db %10000000,%11010000
  525. .db %10000000,%11010000
  526. .db %10000000,%00010000
  527. .db %10000110,%00010000
  528. .db %10000110,%00010000
  529. .db %10000000,%00010000
  530. .db %10110000,%00010000
  531. .db %10110000,%00010000
  532. .db %10000000,%00010000
  533. .db %11111111,%11110000
  534. ; four die
  535. .db %11111111,%11110000
  536. .db %10000000,%00010000
  537. .db %10110000,%11010000
  538. .db %10110000,%11010000
  539. .db %10000000,%00010000
  540. .db %10000000,%00010000
  541. .db %10000000,%00010000
  542. .db %10000000,%00010000
  543. .db %10110000,%11010000
  544. .db %10110000,%11010000
  545. .db %10000000,%00010000
  546. .db %11111111,%11110000
  547. ; five die
  548. .db %11111111,%11110000
  549. .db %10000000,%00010000
  550. .db %10011001,%10010000
  551. .db %10011001,%10010000
  552. .db %10000000,%00010000
  553. .db %10000110,%00010000
  554. .db %10000110,%00010000
  555. .db %10000000,%00010000
  556. .db %10011001,%10010000
  557. .db %10011001,%10010000
  558. .db %10000000,%00010000
  559. .db %11111111,%11110000
  560. ; six die
  561. .db %11111111,%11110000
  562. .db %10000000,%00010000
  563. .db %10011001,%10010000
  564. .db %10011001,%10010000
  565. .db %10000000,%00010000
  566. .db %10011001,%10010000
  567. .db %10011001,%10010000
  568. .db %10000000,%00010000
  569. .db %10011001,%10010000
  570. .db %10011001,%10010000
  571. .db %10000000,%00010000
  572. .db %11111111,%11110000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement