Advertisement
AnthonyCagliano

Untitled

Jan 2nd, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. ; Yatzee for TI-83+/84+
  2. ; Version 1.0
  3. ; by ACagliano (http://clrhome.org)
  4.  
  5. .nolist
  6. #include "ti83plus.inc"
  7. #include "dcs7.inc"
  8. .list
  9. ; defines/equates
  10. #define diceOne 0
  11. #define diceTwo 1
  12. #define diceThree 2
  13. #define diceFour 3
  14. #define diceFive 4
  15. #define diceSix 5
  16. #define comboFlags saferam1
  17. #define threeOnes 0
  18. #define threeTwos 1
  19. #define threeThrees 2
  20. #define threeFours 3
  21. #define threeFives 4
  22. #define threeSixes 5
  23. #define threeOfaKind 6
  24. #define fourOfaKind 7
  25. ; comboFlags+1
  26. #define fullHouse 0
  27. #define smStraight 1
  28. #define lgStraight 2
  29. #define chance 3
  30. #define yatzee 4
  31. #define gameScore comboFlags+2
  32. #define curRolls gameScore+2
  33. #define dieValues curRolls+1
  34. #define dieHoldFlags dieValues+5
  35. #define threesPoints dieHoldFlags+1
  36. #define saveSize threesPoints-comboFlags
  37. #define selectedCombo dieHoldFlags+1
  38. #define ptsforSelected selectedCombo+1
  39. #define rollBonus ptsforSelected+2
  40.  
  41.  
  42.  
  43. .db $BB,$6D
  44. .org progstart
  45.  
  46. Start:
  47. bcall(_ClrLCDFull)
  48. ld a,r ;\
  49. ld h,a ; |
  50. xor 77 ; |Seed the RNG
  51. ld l,a ; |
  52. ld (seed1),hl ; |
  53. ld (seed2),hl ;/
  54. push iy \ ld iy,dieValues ; save system flags location, and point index register to game flags
  55. ld a,0 \ ld (iy),a \ ld (iy+1),a ; reset game flags to 0
  56. ld (curRolls),a ; reset number of rolls
  57. ld (dieHoldFlags),a ; reset die hold flags
  58. ld l,0 \ ld h,0 \ ld (gameScore),hl ; reset game score
  59. call die_setZero ; set all die to 0
  60. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym) ; locate game save file
  61. jr c,StartGame ; if exist, skip loading
  62. ld b,a \ or a \ jr z,{1@} ; if in RAM, skip unarchiving
  63. bcall(_Arc_Unarc) \ bcall(_ChkFindSym) ; if in Archive, unarchive
  64. @: ex de,hl \ ld de,comboFlags ; put data source into hl, data target into de
  65. inc hl \ inc hl ; skip past size word
  66. ld bc,saveSize ; put size of data to load into bc
  67. ldir ; load bc bytes from hl into de
  68. StartGame:
  69. KeywaitLoop:
  70. ld a,(kbdScanCode) \ or a \ jr z,waitloop
  71. cp skYEqu \ jp holdDice1
  72. cp skWindow \ jp holdDice2
  73. cp skZoom \ jp holdDice3
  74. cp skTrace \ jp holdDice4
  75. cp skGraph \ jp holdDice5
  76. cp sk2nd \ jp throwDie
  77. cp skLeft \ jp cycleLeftCombos
  78. cp skRight \ jp cycleRightCombos
  79. cp skEnter \ jp EnterScore
  80. cp skClear \ jp QuitGame
  81. jr KeywaitLoop
  82.  
  83. holdDice1:
  84. ld a,(iy) \ xor 80h \ ld (iy),a
  85. jp KeywaitLoop
  86. holdDice2:
  87. ld a,(iy+1) \ xor 80h \ ld (iy+1),a
  88. jp KeywaitLoop
  89. holdDice3:
  90. ld a,(iy+2) \ xor 80h \ ld (iy+2),a
  91. jp KeywaitLoop
  92. holdDice4:
  93. ld a,(iy+3) \ xor 80h \ ld (iy+3),a
  94. jp KeywaitLoop
  95. holdDice5:
  96. ld a,(iy+4) \ xor 80h \ ld (iy+4),a
  97. jp KeywaitLoop
  98.  
  99.  
  100. cycleLeftCombos:
  101. ld a,(selectedCombo)
  102. inc a
  103. ld (selectedCombo),a
  104. call calcScore
  105. jp KeywaitLoop
  106. cycleRightCombos:
  107. ld a,(selectedCombo)
  108. inc a
  109. ld (selectedCombo),a
  110. call calcScore
  111. jp KeywaitLoop
  112.  
  113. calcScore:
  114.  
  115. ret
  116.  
  117.  
  118. throwDie:
  119. ; randomize the value of each die, if the hold flag for that die is not set
  120. ld hl,dieValues-1
  121. call roll
  122. call roll
  123. call roll
  124. call roll
  125. call roll
  126.  
  127.  
  128. EnterScore:
  129. ld hl,(gameScore)
  130. ld bc,(ptsforSelected)
  131. add hl,bc
  132. ld a,(selectedCombo)
  133. cp 5 \ jr c,{1@}
  134. ld hl,(threesPoints)
  135. add hl,bc \ ld (threesPoints),hl
  136. ld bc,0
  137. ld a,(threesPoints)
  138. cp 12 \ jr nz,{1@} ; check for yatzee
  139. ld bc,50 \ jr addbonus
  140. @: cp 5 \ jr c,{1@} ; check for scoring against a 3 of combo
  141. ld a,(threesPoints) \ cp 63 \ jr c,addbonus \ ld bc,35 ; if total of three of combos is 63 or greater, add 35
  142. addbonus:
  143. add hl,bc
  144. ld (gameScore),hl
  145. jp KeywaitLoop
  146.  
  147. QuitGame:
  148. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym)
  149. jr nc,{1@} ; if save exists already, skip to saving
  150. ld hl,saveSize \ bcall(_CreateAppVar) ; if it doesn't, create it
  151. @: ld hl,comboFlags \ inc de \ inc de ; set read address to RAM state, set write address to after size word
  152. ld bc,saveSize \ ldir ; set size, load
  153. bcall(_ClrLCDFull) ; clear screen
  154. ret ; exit game
  155.  
  156.  
  157.  
  158. die_setZero:
  159. ld hl,dieValues ; set read address to dieValues
  160. ld a,0 \ ld (hl),a ; set dieValues to 0
  161. ld de,dieValues+1 ; set write address to dieValues+1
  162. ld bc,4 \ ldir ; copy 4 bytes from read address to write address
  163. ret
  164.  
  165. ; ########################
  166. ; Random Number Generator
  167. ; ########################
  168.  
  169. prng16:
  170. ;collab with Runer112
  171. ;;Output:
  172. ;; HL is a pseudo-random int
  173. ;; A and BC are also, but much weaker and smaller cycles
  174. ;; Preserves DE
  175. ;;148cc, super fast
  176. ;;26 bytes
  177. ;;period length: 4,294,901,760
  178. seed1=$+1
  179. ld hl,9999
  180. ld b,h
  181. ld c,l
  182. add hl,hl
  183. add hl,hl
  184. inc l
  185. add hl,bc
  186. ld (seed1),hl
  187. seed2=$+1
  188. ld hl,987
  189. add hl,hl
  190. sbc a,a
  191. and %00101101
  192. xor l
  193. ld l,a
  194. ld (seed2),hl
  195. add hl,bc
  196. ret
  197. roll:
  198. ;;Input: A is the range.
  199. ;;Output: Returns in A a random number from 0 to B-1.
  200. ;; B=0
  201. ;; DE is not changed
  202. ;;Destroys:
  203. ;; HL
  204. ;;Speed:
  205. ;; 322cc to 373cc, 347.5cc average
  206. inc hl
  207. ld a,(hl) \ add a,a
  208. ret nc
  209. push hl
  210. call prng16
  211. ld l,h \ ld h,0
  212. ld b,h \ ld c,l
  213. add hl,hl \ add hl,bc \ add hl,hl
  214. inc h \ ld a,h
  215. pop hl
  216. ld (hl),a
  217. ret
  218.  
  219.  
  220.  
  221. GameSave:
  222. .db AppVarObj,"YatSave",0
  223.  
  224. ComboNameText:
  225. .db "Ones",0
  226. .db "Twos",0
  227. .db "Threes",0
  228. .db "Fours",0
  229. .db "Fives",0
  230. .db "Sixes",0
  231. .db "3 of a",0
  232. .db "4 of a",0
  233. .db "Full House",0
  234. .db "Sm. Strt",0
  235. .db "Lg. Strt",0
  236. .db "Chance",0
  237. .db "Yatzee",0
  238.  
  239.  
  240. Sprites:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement