Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Yatzee for TI-83+/84+
- ; Version 1.0
- ; by ACagliano (http://clrhome.org)
- .nolist
- #include "ti83plus.inc"
- #include "dcs7.inc"
- .list
- ; defines/equates
- #define diceOne 0
- #define diceTwo 1
- #define diceThree 2
- #define diceFour 3
- #define diceFive 4
- #define diceSix 5
- #define comboFlags saferam1
- #define threeOnes 0
- #define threeTwos 1
- #define threeThrees 2
- #define threeFours 3
- #define threeFives 4
- #define threeSixes 5
- #define threeOfaKind 6
- #define fourOfaKind 7
- ; comboFlags+1
- #define fullHouse 0
- #define smStraight 1
- #define lgStraight 2
- #define chance 3
- #define yatzee 4
- #define gameScore comboFlags+2
- #define curRolls gameScore+2
- #define dieValues curRolls+1
- #define dieHoldFlags dieValues+5
- #define threesPoints dieHoldFlags+1
- #define saveSize threesPoints-comboFlags
- #define selectedCombo dieHoldFlags+1
- #define ptsforSelected selectedCombo+1
- #define rollBonus ptsforSelected+2
- .db $BB,$6D
- .org progstart
- Start:
- bcall(_ClrLCDFull)
- ld a,r ;\
- ld h,a ; |
- xor 77 ; |Seed the RNG
- ld l,a ; |
- ld (seed1),hl ; |
- ld (seed2),hl ;/
- push iy \ ld iy,dieValues ; save system flags location, and point index register to game flags
- ld a,0 \ ld (iy),a \ ld (iy+1),a ; reset game flags to 0
- ld (curRolls),a ; reset number of rolls
- ld (dieHoldFlags),a ; reset die hold flags
- ld l,0 \ ld h,0 \ ld (gameScore),hl ; reset game score
- call die_setZero ; set all die to 0
- ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym) ; locate game save file
- jr c,StartGame ; if exist, skip loading
- ld b,a \ or a \ jr z,{1@} ; if in RAM, skip unarchiving
- bcall(_Arc_Unarc) \ bcall(_ChkFindSym) ; if in Archive, unarchive
- @: ex de,hl \ ld de,comboFlags ; put data source into hl, data target into de
- inc hl \ inc hl ; skip past size word
- ld bc,saveSize ; put size of data to load into bc
- ldir ; load bc bytes from hl into de
- StartGame:
- KeywaitLoop:
- ld a,(kbdScanCode) \ or a \ jr z,waitloop
- cp skYEqu \ jp holdDice1
- cp skWindow \ jp holdDice2
- cp skZoom \ jp holdDice3
- cp skTrace \ jp holdDice4
- cp skGraph \ jp holdDice5
- cp sk2nd \ jp throwDie
- cp skLeft \ jp cycleLeftCombos
- cp skRight \ jp cycleRightCombos
- cp skEnter \ jp EnterScore
- cp skClear \ jp QuitGame
- jr KeywaitLoop
- holdDice1:
- ld a,(iy) \ xor 80h \ ld (iy),a
- jp KeywaitLoop
- holdDice2:
- ld a,(iy+1) \ xor 80h \ ld (iy+1),a
- jp KeywaitLoop
- holdDice3:
- ld a,(iy+2) \ xor 80h \ ld (iy+2),a
- jp KeywaitLoop
- holdDice4:
- ld a,(iy+3) \ xor 80h \ ld (iy+3),a
- jp KeywaitLoop
- holdDice5:
- ld a,(iy+4) \ xor 80h \ ld (iy+4),a
- jp KeywaitLoop
- cycleLeftCombos:
- ld a,(selectedCombo)
- inc a
- ld (selectedCombo),a
- call calcScore
- jp KeywaitLoop
- cycleRightCombos:
- ld a,(selectedCombo)
- inc a
- ld (selectedCombo),a
- call calcScore
- jp KeywaitLoop
- calcScore:
- ret
- throwDie:
- ; randomize the value of each die, if the hold flag for that die is not set
- ld hl,dieValues-1
- call roll
- call roll
- call roll
- call roll
- call roll
- EnterScore:
- ld hl,(gameScore)
- ld bc,(ptsforSelected)
- add hl,bc
- ld a,(selectedCombo)
- cp 5 \ jr c,{1@}
- ld hl,(threesPoints)
- add hl,bc \ ld (threesPoints),hl
- ld bc,0
- ld a,(threesPoints)
- cp 12 \ jr nz,{1@} ; check for yatzee
- ld bc,50 \ jr addbonus
- @: cp 5 \ jr c,{1@} ; check for scoring against a 3 of combo
- ld a,(threesPoints) \ cp 63 \ jr c,addbonus \ ld bc,35 ; if total of three of combos is 63 or greater, add 35
- addbonus:
- add hl,bc
- ld (gameScore),hl
- jp KeywaitLoop
- QuitGame:
- ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym)
- jr nc,{1@} ; if save exists already, skip to saving
- ld hl,saveSize \ bcall(_CreateAppVar) ; if it doesn't, create it
- @: ld hl,comboFlags \ inc de \ inc de ; set read address to RAM state, set write address to after size word
- ld bc,saveSize \ ldir ; set size, load
- bcall(_ClrLCDFull) ; clear screen
- ret ; exit game
- die_setZero:
- ld hl,dieValues ; set read address to dieValues
- ld a,0 \ ld (hl),a ; set dieValues to 0
- ld de,dieValues+1 ; set write address to dieValues+1
- ld bc,4 \ ldir ; copy 4 bytes from read address to write address
- ret
- ; ########################
- ; Random Number Generator
- ; ########################
- prng16:
- ;collab with Runer112
- ;;Output:
- ;; HL is a pseudo-random int
- ;; A and BC are also, but much weaker and smaller cycles
- ;; Preserves DE
- ;;148cc, super fast
- ;;26 bytes
- ;;period length: 4,294,901,760
- seed1=$+1
- ld hl,9999
- ld b,h
- ld c,l
- add hl,hl
- add hl,hl
- inc l
- add hl,bc
- ld (seed1),hl
- seed2=$+1
- ld hl,987
- add hl,hl
- sbc a,a
- and %00101101
- xor l
- ld l,a
- ld (seed2),hl
- add hl,bc
- ret
- roll:
- ;;Input: A is the range.
- ;;Output: Returns in A a random number from 0 to B-1.
- ;; B=0
- ;; DE is not changed
- ;;Destroys:
- ;; HL
- ;;Speed:
- ;; 322cc to 373cc, 347.5cc average
- inc hl
- ld a,(hl) \ add a,a
- ret nc
- push hl
- call prng16
- ld l,h \ ld h,0
- ld b,h \ ld c,l
- add hl,hl \ add hl,bc \ add hl,hl
- inc h \ ld a,h
- pop hl
- ld (hl),a
- ret
- GameSave:
- .db AppVarObj,"YatSave",0
- ComboNameText:
- .db "Ones",0
- .db "Twos",0
- .db "Threes",0
- .db "Fours",0
- .db "Fives",0
- .db "Sixes",0
- .db "3 of a",0
- .db "4 of a",0
- .db "Full House",0
- .db "Sm. Strt",0
- .db "Lg. Strt",0
- .db "Chance",0
- .db "Yatzee",0
- Sprites:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement