Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with the exception of rendering a few text strings and looping that dice->LCD code, game is done. Things of note...
- 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.
- 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.
- ; Yatzee for TI-83+/84+
- ; Version 1.0
- ; by ACagliano
- .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 comboScores 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
- #define fullHouse 8
- #define smStraight 9
- #define lgStraight 10
- #define chance 11
- #define yatzee 12
- #define threesBonus 13
- #define gameScore comboScores+threesBonus
- #define entryMode gameScore+2
- #define spin 0
- #define score 1
- #define highScore entryMode+1
- #define curRolls highScore+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 rollBonuses ptsforSelected+2
- #define ctOnes rollBonuses+1
- #define ctTwos ctOnes+1
- #define ctThrees ctTwos+1
- #define ctFours ctThrees+1
- #define ctFives ctFours+1
- #define ctSixes ctFives+1
- .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,comboScores ; push system flags location, set IY to comboScores address
- ld ix,dieValues ; set IX to 5-byte die roll values
- ld hl,gameScore \ ld b,ctSixes-comboScores \ call zeroData ; zero the RAM savestate
- ld hl,GameSave \ rst 20h \ bcall(_ChkFindSym) ; \
- jr c,StartGame ; | check whether save file exists
- ld b,a \ or a \ jr z,{1@} ; | if it doesn't skip to game start
- bcall(_Arc_Unarc) \ bcall(_ChkFindSym) ; | if it does and is unarchived, skip to loading
- @: ex de,hl \ ld de,comboFlags ; | if it does and is archived, unarchive it
- inc hl \ inc hl ; | load the savestate into RAM
- ld bc,saveSize ; |
- ldir ; /
- StartGame:
- call renderDie
- call renderStats
- ld hl,entryMode \ set spin,(hl) ; enable spinning, but not scoring yet
- KeywaitLoop:
- ld a,(kbdScanCode) \ or a \ jr z,KeywaitLoop
- ld hl,entryMode
- bit score,(hl) \ jr z,{1@} ; if the score bit is reset, you are not allowed to score now
- cp skLeft \ jp cycleLeftCombos
- cp skRight \ jp cycleRightCombos
- cp skEnter \ jp EnterScore
- bit spin,(hl) \ jr z,KeywaitLoop ; if the spin bit is reset, you are not allowed to spin now
- @: sub 54 \ add a,5 \ jp c,holdDice
- add a,49
- cp sk2nd \ jp throwDie
- cp skClear \ jp QuitGame
- jr KeywaitLoop
- holdDice:
- ld hl,dieValues
- add a,l \ ld l,a \ jr nc,$+3
- inc h \ ld a,(hl)
- xor 80h \ ld (hl),a
- jp KeywaitLoop
- ; ### Select Combo and Compute Score ###
- cycleLeftCombos:
- ld hl,selectedCombo \ dec (hl)
- call calcScore
- jp KeywaitLoop
- cycleRightCombos:
- ld hl,selectedCombo \ inc (hl)
- call calcScore
- jp KeywaitLoop
- calcScore:
- #define checkQuantity inc hl \ sub (hl)
- ld hl,dieValues-1
- call getDieValue
- call getDieValue
- call getDieValue
- call getDieValue
- call getDieValue
- ; now we test the combo that is active. Score is either returned, or 0.
- 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
- ld a,(selectedCombo)
- or a \ jr z,isThreeOnes
- cp threeTwos \ jr z,isThreeTwos
- cp threeThrees \ jr z,isThreeThrees
- cp threeFours \ jr z,isThreeFours
- cp threeFives \ jr z,isThreeFives
- cp threeSixes \ jr z,isThreeSixes
- cp threeOfaKind \ jr z,isThreeOfaKind
- cp fourOfaKind \ jr z,isFourOfaKind
- cp fullHouse \ jr z,isFullHouse
- cp smStraight \ jr z,isSmStraight
- cp lgStraight \ jr z,isLgStraight
- cp chance \ jr z,sumtheDie
- cp yatzee \ jr z,isYatzee
- calcBonuses:
- dec a \ ld (ptsforSelected),a
- call isYatzee \ or a \ jr z,{1@}
- dec a \ ld (rollBonuses),a
- @: ld a,(threesBonus) \ or a \ call z,isFullTopSix
- ld hl,rollBonuses \ add a,(hl)
- call rendertPoints
- ret
- isThreeOnes:
- ld a,(ctOnes) \ inc a \ ret
- isThreeTwos:
- ld a,(ctTwos)
- rla \ inc a \ ret
- isThreeThrees:
- ld a,(ctThrees)
- ld b,a \ rla \ add a,b
- inc a \ ret
- isThreeFours:
- ld a,(ctFours)
- rla \ rla
- inc a \ ret
- isThreeFives:
- ld a,(ctFives)
- ld b,a \ rla \ rla \ add a,b
- inc a \ ret
- isThreeSixes:
- ld a,(ctSixes)
- rla \ rla \ rla
- inc a \ ret
- isThreeOfaKind:
- ld a,2 \ jr {1@}
- isFourOfaKind:
- ld a,3
- @: ld hl,ctOnes-1
- checkQuantity \ jr c,sumtheDie
- checkQuantity \ jr c,sumtheDie
- checkQuantity \ jr c,sumtheDie
- checkQuantity \ jr c,sumtheDie
- checkQuantity \ jr c,sumtheDie
- ld a,0
- ret
- isFullHouse:
- ld a,2 \ ld hl,ctOnes-1
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- jr {3@}
- @: ld a,1 \ ld hl,ctOnes-1
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- jr {2@}
- @: ld a,26 \ ret
- @: ld a,0 \ ret
- isSmStraight:
- ld hl,ctOnes \ ld a,(hl)
- or a \ jr z,strt_start_2
- ld b,3
- inc hl \ and (hl)
- djnz $-2
- jr nz,{1@}
- strt_start_2:
- inc hl \ ld a,(hl)
- or a \ jr z,strt_start_3
- ld b,3
- inc hl \ and (hl)
- djnz $-2
- jr nz,{}
- strt_start_3:
- inc hl \ ld a,(hl)
- or a \ ret z
- ld b,3
- inc hl \ and (hl)
- djnz $-2
- ret z
- @: ld a,31 \ ret
- isLgStraight
- ld hl,ctOnes \ ld a,(hl)
- or a \ jr z,strt_1_to_5
- ;strt_2_to_6:
- inc hl
- strt_1_to5:
- ld a,(hl) \ ld b,3
- inc hl \ and (hl)
- djnz $-2
- ret z
- ld a,41 \ ret
- @: ld a,0 \ ret
- isYatzee:
- ld hl,ctOnes-1 \ ld a,4
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- checkQuantity \ jr c,{1@}
- ld a,0 \ ret
- @: ld a,51 \ ret
- isFullTopSix:
- ld hl,comboScores \ ld a,0
- ld b,6
- @: add a,(hl) \ inc hl
- djnz {-1@}
- cp 62 \ jr c,{1@}
- ld a,0 \ ret
- @: ld a,1 \ ld (threesBonus),a \ ld a,35 \ ret
- sumtheDie:
- ld a,0 \ ld hl,dieValues
- ld b,5
- @: add a,(hl) \ inc hl
- djnz {-1@}
- inc a
- ret
- getDieValue:
- inc hl
- ld a,(hl) \ and %01111111 ; reset high byte in A, not in memory
- cp 1 \ jr nz,{1@}
- ld a,(ctOnes) \ inc a \ ld (ctOnes),a \ ret
- @: cp 2 \ jr nz,{1@}
- ld a,(ctTwos) \ inc a \ ld (ctTwos),a \ ret
- @: cp 3 \ jr nz,{1@}
- ld a,(ctThrees) \ inc a \ ld (ctThrees),a \ ret
- @: cp 4 \ jr nz,{1@}
- ld a,(ctFours) \ inc a \ ld (ctFours),a \ ret
- @: cp 5 \ jr nz,{1@}
- ld a,(ctFives) \ inc a \ ld (ctFives),a \ ret
- @: cp 6 \ ret nz
- ld a,(ctSixes) \ inc a \ ld (ctSixes),a \ 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
- call renderDie
- ld hl,entryMode \ set score,(hl) ; allow scoring once die rolled
- ld hl,curRolls \ inc (hl) ; increment number of rolls by one
- ld a,3 \ sub (hl) \ jr nz,KeywaitLoop ; if rolls != 3, leave routine
- ld hl,entryMode \ res spin,(hl) ; if rolls = 3, disable rolling
- jr KeywaitLoop
- EnterScore:
- ld hl,comboScores
- ld a,(selectedCombo) \ ld c,a \ ld b,0
- add hl,bc
- ld a,(hl) \ or a \ jr nz,{1@}
- ld a,(ptsforSelected) \ ld (hl),a
- cp -1 \ jr z,{1@}
- ld hl,(gameScore)
- ld bc,(ptsforSelected)
- add hl,bc ; add score to game score
- ld b,0 \ ld c,(rollBonuses)
- add hl,bc ; add bonuses to game score
- ld (gameScore),hl ; write new score back
- ld hl,entryMode \ res score,(hl) \ set spin,(hl) ; disable scoring, enable spinning
- ld a,0 \ ld (curRolls),a ; set back to 0 rolls
- @: 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
- pop iy ; restore system flags
- ret ; exit game
- renderDie:
- ld hl,Sprites
- ret
- renderStats:
- ret
- rendertPoints:
- ld a,(selectedCombo)
- ld hl,ComboNameText \ ld b,a
- or a \ jr z,{2@}
- @: add hl,7
- djnz {-1@}
- @: ; set penCol and penRow
- bcall(_vPutS)
- ld a,(ptsforSelected)
- ; convert byte value into text string
- ret
- 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
- zeroData:
- ld a,0
- ld (hl),a \ inc hl
- djnz zeroData
- 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
- ; ########################
- ; ## Rendering Routines ##
- ; ########################
- drawSprite_6_Bit:
- ld a,d \ add a,$79 ; Y coord into A
- ld b,12 ; Loop this 12 times
- drawSprite_outerloop:
- inc a \ push af
- out ($10),a \ call lcdwait
- ld a,e \ add a,$20
- out ($10),a \ call lcdwait ; use outi instead
- ld c,$11
- outi \ call lcdwait
- outi \ call lcdwait
- pop bc \ pop af
- djnz drawSprite_outerloop
- lcdwait:
- in a,($10) ;bit 7 set if LCD is busy
- rla \ jr c,lcdwait
- 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 "F.Hse.",0
- .db "Sm.St.",0
- .db "Lg.St.",0
- .db "Chance",0
- .db "Yatzee",0
- Sprites:
- ; empty die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; one die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000110,%00010000
- .db %10000110,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; two die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000110,%00010000
- .db %10000110,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000110,%00010000
- .db %10000110,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; three die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10000000,%11010000
- .db %10000000,%11010000
- .db %10000000,%00010000
- .db %10000110,%00010000
- .db %10000110,%00010000
- .db %10000000,%00010000
- .db %10110000,%00010000
- .db %10110000,%00010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; four die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10110000,%11010000
- .db %10110000,%11010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10000000,%00010000
- .db %10110000,%11010000
- .db %10110000,%11010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; five die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10011001,%10010000
- .db %10011001,%10010000
- .db %10000000,%00010000
- .db %10000110,%00010000
- .db %10000110,%00010000
- .db %10000000,%00010000
- .db %10011001,%10010000
- .db %10011001,%10010000
- .db %10000000,%00010000
- .db %11111111,%11110000
- ; six die
- .db %11111111,%11110000
- .db %10000000,%00010000
- .db %10011001,%10010000
- .db %10011001,%10010000
- .db %10000000,%00010000
- .db %10011001,%10010000
- .db %10011001,%10010000
- .db %10000000,%00010000
- .db %10011001,%10010000
- .db %10011001,%10010000
- .db %10000000,%00010000
- .db %11111111,%11110000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement