Advertisement
AnthonyCagliano

Untitled

Jan 6th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 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 comboScores 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. #define fullHouse 8
  26. #define smStraight 9
  27. #define lgStraight 10
  28. #define chance 11
  29. #define yatzee 12
  30. #define gameScore comboScores+yatzee
  31. #define highScore gameScore+2
  32. #define curRolls highScore+2
  33. #define dieValues curRolls+1
  34. #define dieHoldFlags dieValues+5
  35. #define threesPoints dieHoldFlags+1
  36. #define saveSize threesPoints-comboFlags
  37.  
  38. #define selectedCombo dieHoldFlags+1
  39. #define ptsforSelected selectedCombo+1
  40. #define rollBonuses ptsforSelected+2
  41. #define ctOnes rollBonuses+1
  42. #define ctTwos ctOnes+1
  43. #define ctThrees ctTwos+1
  44. #define ctFours ctThrees+1
  45. #define ctFives ctFours+1
  46. #define ctSixes ctFives+1
  47.  
  48.  
  49. .db $BB,$6D
  50. .org progstart
  51.  
  52. Start:
  53. bcall(_ClrLCDFull)
  54. ld a,r ;\
  55. ld h,a ; |
  56. xor 77 ; |Seed the RNG
  57. ld l,a ; |
  58. ld (seed1),hl ; |
  59. ld (seed2),hl ;/
  60.  
  61. push iy \ ld iy,comboScores ; push system flags location, set IY to comboScores address
  62. ld ix,dieValues ; set IX to 5-byte die roll values
  63.  
  64. ld hl,gameScore \ ld b,ctSixes-comboScores \ call zeroData ; zero the RAM savestate
  65.  
  66. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym) ; \
  67. jr c,StartGame ; | check whether save file exists
  68. ld b,a \ or a \ jr z,{1@} ; | if it doesn't skip to game start
  69. bcall(_Arc_Unarc) \ bcall(_ChkFindSym) ; | if it does and is unarchived, skip to loading
  70. @: ex de,hl \ ld de,comboFlags ; | if it does and is archived, unarchive it
  71. inc hl \ inc hl ; | load the savestate into RAM
  72. ld bc,saveSize ; |
  73. ldir ; /
  74. StartGame:
  75. call renderDie
  76. call renderStats
  77. KeywaitLoop:
  78. ld a,(kbdScanCode) \ or a \ jr z,waitloop
  79. sub 54 \ add a,5 \ jp c,holdDice
  80. add a,49
  81. cp skMode \ jp renderInstr
  82. cp skYEqu \ jp holdDice1
  83. cp skWindow \ jp holdDice2
  84. cp skZoom \ jp holdDice3
  85. cp skTrace \ jp holdDice4
  86. cp skGraph \ jp holdDice5
  87. cp sk2nd \ jp throwDie
  88. cp skLeft \ jp cycleLeftCombos
  89. cp skRight \ jp cycleRightCombos
  90. cp skEnter \ jp EnterScore
  91. cp skClear \ jp QuitGame
  92. jr KeywaitLoop
  93.  
  94. holdDice:
  95. ld hl,dieValues
  96. add a,l \ ld l,a \ jr nc,$+3
  97. inc h \ ld a,(hl)
  98. xor 80h \ ld (hl),a
  99. jp KeywaitLoop
  100.  
  101.  
  102. ; ### Select Combo and Compute Score ###
  103.  
  104. cycleLeftCombos:
  105. ld hl,selectedCombo \ dec (hl)
  106. call calcScore
  107. jp KeywaitLoop
  108. cycleRightCombos:
  109. ld hl,selectedCombo \ inc (hl)
  110. call calcScore
  111. jp KeywaitLoop
  112.  
  113. calcScore:
  114. #define checkQuantity inc hl \ sub (hl)
  115. ld hl,dieValues-1
  116. call getDieValue
  117. call getDieValue
  118. call getDieValue
  119. call getDieValue
  120. call getDieValue
  121. ; now we test the combo that is active. Score is either returned, or 0.
  122. 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
  123. ld a,(selectedCombo)
  124. or a \ jr z,isThreeOnes
  125. cp threeTwos \ jr z,isThreeTwos
  126. cp threeThrees \ jr z,isThreeThrees
  127. cp threeFours \ jr z,isThreeFours
  128. cp threeFives \ jr z,isThreeFives
  129. cp threeSixes \ jr z,isThreeSixes
  130. cp threeOfaKind \ jr z,isThreeOfaKind
  131. cp fourOfaKind \ jr z,isFourOfaKind
  132. cp fullHouse \ jr z,isFullHouse
  133. cp smStraight \ jr z,isSmStraight
  134. cp lgStraight \ jr z,isLgStraight
  135. cp chance \ jr z,isChance
  136. cp yatzee \ jr z,isYatzee
  137. calcBonuses:
  138. ld (ptsforSelected),a
  139. ; render the possible score for this combo
  140. call rendertPoints
  141. ret
  142.  
  143. isThreeOnes:
  144. ld a,(ctOnes) \ ret
  145. isThreeTwos:
  146. ld a,(ctTwos)
  147. rla \ ret
  148. isThreeThrees:
  149. ld a,(ctThrees)
  150. ld b,a \ rla \ add a,b
  151. ret
  152. isThreeFours:
  153. ld a,(ctFours)
  154. rla \ rla
  155. ret
  156. isThreeFives:
  157. ld a,(ctFives)
  158. ld b,a \ rla \ rla \ add a,b
  159. ret
  160. isThreeSixes:
  161. ld a,(ctSixes)
  162. rla \ rla \ rla
  163. ret
  164. isThreeOfaKind:
  165. ld a,2 \ jr {1@}
  166. isFourOfaKind:
  167. ld a,3
  168. @: ld hl,ctOnes-1
  169. checkQuantity \ jr c,sumtheDie
  170. checkQuantity \ jr c,sumtheDie
  171. checkQuantity \ jr c,sumtheDie
  172. checkQuantity \ jr c,sumtheDie
  173. checkQuantity \ jr c,sumtheDie
  174. ld a,0
  175. ret
  176. isFullHouse:
  177. ; check and see if 3 of one number and 2 of another
  178. ret
  179. isSmStraight:
  180. ; check and see if 4 numbers in a row
  181. ret
  182. isLgStraight
  183. ; check and see if 5 numbers in a row
  184. ret
  185. isYatzee:
  186. ld hl,ctOnes-1 \ ld a,4
  187. checkQuantity \ jr c,{1@}
  188. checkQuantity \ jr c,{1@}
  189. checkQuantity \ jr c,{1@}
  190. checkQuantity \ jr c,{1@}
  191. checkQuantity \ jr c,{1@}
  192. ld a,0 \ ret
  193. @: ld a,50 \ ret
  194.  
  195.  
  196.  
  197. isChance:
  198. call sumtheDie
  199. jr showScore
  200.  
  201.  
  202.  
  203.  
  204. sumtheDie:
  205. ld hl,0 \ push ix \ dec ix \ ld b,5
  206. @: inc ix
  207. push bc \ ld b,0
  208. ld a,(iy) \ ld c,a \ add hl,bc
  209. pop bc \ djnz {-1@}
  210. pop ix \ ld a,l
  211. ret
  212.  
  213.  
  214.  
  215.  
  216. getDieValue:
  217. inc hl
  218. ld a,(hl) \ and %01111111 ; reset high byte in A, not in memory
  219. cp 1 \ jr nz,{1@}
  220. ld a,(ctOnes) \ inc a \ ld (ctOnes),a \ ret
  221. @: cp 2 \ jr nz,{1@}
  222. ld a,(ctTwos) \ inc a \ ld (ctTwos),a \ ret
  223. @: cp 3 \ jr nz,{1@}
  224. ld a,(ctThrees) \ inc a \ ld (ctThrees),a \ ret
  225. @: cp 4 \ jr nz,{1@}
  226. ld a,(ctFours) \ inc a \ ld (ctFours),a \ ret
  227. @: cp 5 \ jr nz,{1@}
  228. ld a,(ctFives) \ inc a \ ld (ctFives),a \ ret
  229. @: cp 6 \ ret nz
  230. ld a,(ctSixes) \ inc a \ ld (ctSixes),a \ ret
  231.  
  232.  
  233.  
  234.  
  235.  
  236. throwDie:
  237. ; randomize the value of each die, if the hold flag for that die is not set
  238. ld hl,dieValues-1
  239. call roll
  240. call roll
  241. call roll
  242. call roll
  243. call roll
  244. call renderDie
  245. jr KeywaitLoop
  246.  
  247.  
  248. EnterScore:
  249. ld hl,(gameScore)
  250. ld bc,(ptsforSelected)
  251. add hl,bc
  252. ld a,(selectedCombo)
  253. cp 5 \ jr c,{1@}
  254. ld hl,(threesPoints)
  255. add hl,bc \ ld (threesPoints),hl
  256. ld bc,0
  257. ld a,(threesPoints)
  258. cp 12 \ jr nz,{1@} ; check for yatzee
  259. ld bc,50 \ jr addbonus
  260. @: cp 5 \ jr c,{1@} ; check for scoring against a 3 of combo
  261. ld a,(threesPoints) \ cp 63 \ jr c,addbonus \ ld bc,35 ; if total of three of combos is 63 or greater, add 35
  262. addbonus:
  263. add hl,bc
  264. ld (gameScore),hl
  265. jp KeywaitLoop
  266.  
  267. QuitGame:
  268. ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym)
  269. jr nc,{1@} ; if save exists already, skip to saving
  270. ld hl,saveSize \ bcall(_CreateAppVar) ; if it doesn't, create it
  271. @: ld hl,comboFlags \ inc de \ inc de ; set read address to RAM state, set write address to after size word
  272. ld bc,saveSize \ ldir ; set size, load
  273. bcall(_ClrLCDFull) ; clear screen
  274. pop iy ; restore system flags
  275. ret ; exit game
  276.  
  277. renderDie:
  278. ld hl,Sprites
  279.  
  280. ret
  281.  
  282. renderStats:
  283.  
  284. ret
  285.  
  286.  
  287.  
  288. rendertPoints:
  289. ld a,(selectedCombo)
  290. ld hl,ComboNameText \ ld b,a
  291. or a \ jr z,{2@}
  292. @: add hl,7
  293. djnz {-1@}
  294. @: ; set penCol and penRow
  295. bcall(_vPutS)
  296. ld a,(ptsforSelected)
  297. ; convert byte value into text string
  298. ret
  299.  
  300. die_setZero:
  301. ld hl,dieValues ; set read address to dieValues
  302. ld a,0 \ ld (hl),a ; set dieValues to 0
  303. ld de,dieValues+1 ; set write address to dieValues+1
  304. ld bc,4 \ ldir ; copy 4 bytes from read address to write address
  305. ret
  306.  
  307. zeroData:
  308. ld a,0
  309. ld (hl),a \ inc hl
  310. djnz zeroData
  311. ret
  312.  
  313. ; ########################
  314. ; Random Number Generator
  315. ; ########################
  316.  
  317. prng16:
  318. ;collab with Runer112
  319. ;;Output:
  320. ;; HL is a pseudo-random int
  321. ;; A and BC are also, but much weaker and smaller cycles
  322. ;; Preserves DE
  323. ;;148cc, super fast
  324. ;;26 bytes
  325. ;;period length: 4,294,901,760
  326. seed1=$+1
  327. ld hl,9999
  328. ld b,h
  329. ld c,l
  330. add hl,hl
  331. add hl,hl
  332. inc l
  333. add hl,bc
  334. ld (seed1),hl
  335. seed2=$+1
  336. ld hl,987
  337. add hl,hl
  338. sbc a,a
  339. and %00101101
  340. xor l
  341. ld l,a
  342. ld (seed2),hl
  343. add hl,bc
  344. ret
  345. roll:
  346. ;;Input: A is the range.
  347. ;;Output: Returns in A a random number from 0 to B-1.
  348. ;; B=0
  349. ;; DE is not changed
  350. ;;Destroys:
  351. ;; HL
  352. ;;Speed:
  353. ;; 322cc to 373cc, 347.5cc average
  354. inc hl
  355. ld a,(hl) \ add a,a
  356. ret nc
  357. push hl
  358. call prng16
  359. ld l,h \ ld h,0
  360. ld b,h \ ld c,l
  361. add hl,hl \ add hl,bc \ add hl,hl
  362. inc h \ ld a,h
  363. pop hl
  364. ld (hl),a
  365. ret
  366.  
  367. ; ########################
  368. ; ## Rendering Routines ##
  369. ; ########################
  370.  
  371. drawSprite_6_Bit:
  372. ld a,d \ add a,$79 ; Y coord into A
  373. ld b,12 ; Loop this 12 times
  374. drawSprite_outerloop:
  375. inc a \ push af
  376. out ($10),a \ call lcdwait
  377. ld a,e \ add a,$20
  378. out ($10),a \ call lcdwait ; use outi instead
  379. ld c,$11
  380. outi \ call lcdwait
  381. outi \ call lcdwait
  382. pop bc \ pop af
  383. djnz drawSprite_outerloop
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392. lcdwait:
  393. in a,($10) ;bit 7 set if LCD is busy
  394. rla \ jr c,lcdwait
  395. ret
  396.  
  397.  
  398.  
  399. GameSave:
  400. .db AppVarObj,"YatSave",0
  401.  
  402. ComboNameText:
  403. .db "Ones ",0
  404. .db "Twos ",0
  405. .db "Threes",0
  406. .db "Fours ",0
  407. .db "Fives ",0
  408. .db "Sixes ",0
  409. .db "3.of.a",0
  410. .db "4.of.a.",0
  411. .db "F.Hse.",0
  412. .db "Sm.St.",0
  413. .db "Lg.St.",0
  414. .db "Chance",0
  415. .db "Yatzee",0
  416.  
  417.  
  418. Sprites:
  419. ; empty die
  420. .db %11111111,%11110000
  421. .db %10000000,%00010000
  422. .db %10000000,%00010000
  423. .db %10000000,%00010000
  424. .db %10000000,%00010000
  425. .db %10000000,%00010000
  426. .db %10000000,%00010000
  427. .db %10000000,%00010000
  428. .db %10000000,%00010000
  429. .db %10000000,%00010000
  430. .db %10000000,%00010000
  431. .db %11111111,%11110000
  432. ; one die
  433. .db %11111111,%11110000
  434. .db %10000000,%00010000
  435. .db %10000000,%00010000
  436. .db %10000000,%00010000
  437. .db %10000000,%00010000
  438. .db %10000110,%00010000
  439. .db %10000110,%00010000
  440. .db %10000000,%00010000
  441. .db %10000000,%00010000
  442. .db %10000000,%00010000
  443. .db %10000000,%00010000
  444. .db %11111111,%11110000
  445. ; two die
  446. .db %11111111,%11110000
  447. .db %10000000,%00010000
  448. .db %10000000,%00010000
  449. .db %10000110,%00010000
  450. .db %10000110,%00010000
  451. .db %10000000,%00010000
  452. .db %10000000,%00010000
  453. .db %10000110,%00010000
  454. .db %10000110,%00010000
  455. .db %10000000,%00010000
  456. .db %10000000,%00010000
  457. .db %11111111,%11110000
  458. ; three die
  459. .db %11111111,%11110000
  460. .db %10000000,%00010000
  461. .db %10000000,%11010000
  462. .db %10000000,%11010000
  463. .db %10000000,%00010000
  464. .db %10000110,%00010000
  465. .db %10000110,%00010000
  466. .db %10000000,%00010000
  467. .db %10110000,%00010000
  468. .db %10110000,%00010000
  469. .db %10000000,%00010000
  470. .db %11111111,%11110000
  471. ; four die
  472. .db %11111111,%11110000
  473. .db %10000000,%00010000
  474. .db %10110000,%11010000
  475. .db %10110000,%11010000
  476. .db %10000000,%00010000
  477. .db %10000000,%00010000
  478. .db %10000000,%00010000
  479. .db %10000000,%00010000
  480. .db %10110000,%11010000
  481. .db %10110000,%11010000
  482. .db %10000000,%00010000
  483. .db %11111111,%11110000
  484. ; five die
  485. .db %11111111,%11110000
  486. .db %10000000,%00010000
  487. .db %10011001,%10010000
  488. .db %10011001,%10010000
  489. .db %10000000,%00010000
  490. .db %10000110,%00010000
  491. .db %10000110,%00010000
  492. .db %10000000,%00010000
  493. .db %10011001,%10010000
  494. .db %10011001,%10010000
  495. .db %10000000,%00010000
  496. .db %11111111,%11110000
  497. ; six die
  498. .db %11111111,%11110000
  499. .db %10000000,%00010000
  500. .db %10011001,%10010000
  501. .db %10011001,%10010000
  502. .db %10000000,%00010000
  503. .db %10011001,%10010000
  504. .db %10011001,%10010000
  505. .db %10000000,%00010000
  506. .db %10011001,%10010000
  507. .db %10011001,%10010000
  508. .db %10000000,%00010000
  509. .db %11111111,%11110000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement