Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; YAHTZEE CE EDITION
- ; Version 0.1 beta
- ; by ACagliano
- #include "inc/ti84pce.inc"
- .assume ADL=1
- .org userMem-2
- .db tExtTok,tAsm84CeCmp
- cRed equ 224
- cWhite equ 255
- cBlue equ 24
- cBlack equ 0
- cGreen equ 4
- cYellow equ 231
- gameRAM equ pixelShadow
- scratchRAM equ YahtzeeDataEnd-YahtzeeData+gameRAM
- Start:
- ld hl, LibLoadAppVar
- call _Mov9ToOP1
- ld a, AppVarObj
- ld (OP1), a
- _: call _ChkFindSym
- jr c, NotFound
- call _ChkInRAM
- jr nz, InArc
- call _PushOP1
- call _Arc_UnArc
- call _PopOP1
- jr -_
- InArc:
- ex de, hl
- ld de, 9
- add hl, de
- ld e, (hl)
- add hl, de
- inc hl
- inc hl
- inc hl
- ld de, RelocationStart
- jp (hl)
- NotFound:
- call _ClrScrn
- call _HomeUp
- ld hl, MissingAppVar
- call _PutS
- call _NewLine
- jp _PutS
- MissingAppVar:
- .db "LIBLOAD not present!",0
- RelocationStart:
- .db 0C0h, "GRAPHX", 0, 4
- gfx_Begin:
- jp 0
- gfx_End:
- jp 1*3
- gfx_SetDraw:
- jp 9*3
- gfx_SetDefaultPalette:
- jp 3*3
- gfx_FillScreen:
- jp 5*3
- gfx_PrintChar:
- jp 42
- gfx_PrintStringXY:
- jp 18*3
- gfx_SetTextBGColor:
- jp 20*3
- gfx_SetTextFGColor:
- jp 63
- gfx_Sprite:
- jp 57*3
- gfx_SSprite:
- jp 62*3
- gfx_FillRectangle:
- jp 36*3
- gfx_SetTextScale:
- jp 74*3
- ; Set up and initialize graphics
- di
- call _ClrScrn
- call _RunIndicOff
- ld a,r ;\
- ld h,a ; |
- xor 77 ; |Seed the RNG
- ld l,a ; |
- ld (seed1),hl ; |
- ld (seed2),hl ;/
- ld hl,lcdbpp8
- push hl
- call gfx_Begin
- pop hl
- ld hl, 0 \ push hl
- call gfx_SetDraw
- pop hl
- ; Check for game save
- ld hl, YahtzeeSave
- call _Mov9ToOP1
- ld a, AppVarObj
- ld (OP1), a
- call _ChkFindSym ; return pointer to savefile, or set carry flag if not found
- jr c,_initfile ; if file not found, skip save file loading
- ;loadfile: ; check if file is in RAM or Archive. If not in RAM, put it there
- call _ChkInRAM
- jr z,SaveFile_InRAM
- call _PushOP1
- call _Arc_UnArc
- call _PopOP1
- SaveFile_InRAM: ; once file in RAM, copy saved game to gamestate and then start (resume) gameplay
- ld de, gameRAM
- ld hl, YahtzeeData
- ld bc, YahtzeeDataEnd-YahtzeeData
- ldir
- jp GameStart
- _initfile: ; if save file not found, zero gamestate. Then start gameplay
- ld hl, gameRAM
- ld bc, YahtzeeDataEnd-YahtzeeData
- ld a, 0
- call _MemSet
- call MainMenu
- ld a, 0
- splash_GetCSC_loop:
- call _kbdscan
- ld a, (kbdScanCode)
- or a \ jr z, splash_GetCSC_loop
- ; main menu
- GameStart:
- ld a, 0
- KeyGetLoop:
- call _kbdscan
- ld a, (kbdScanCode)
- or a \ jr z, KeyGetLoop
- ; keypad reading
- ld hl, playsAllowedFlags
- bit playRoll, (hl)
- jr z, noRolls
- cp sk2nd
- jp z, RollDie
- bit playScore, (hl)
- jr z, noScores
- noRolls:
- ; Scoring
- cp skDown
- jp z, SwapRow
- cp skUp
- jp z, SwapRow
- cp skRight
- jp z, MoveRight
- cp skLeft
- jp z, MoveLeft
- cp skEnter
- jp z, ScoreCombo
- noScores:
- cp skClear
- jp z, Quit
- cp skMode
- jp z, ShowControls
- ld a, 0 \ jr KeyGetLoop
- GameLoop_End:
- call RefreshScreen
- call CalcCurrentScore
- ld hl, comboFlags1 \ ld a, (hl)
- cp %00111111 \ jr nz, GameStart
- ld hl, comboFlags2 \ ld a, (hl)
- cp %01111111 \ jr nz, GameStart
- jr GameOver
- ; exit game conditions
- jr GameStart
- GameOver:
- ld hl, Score \ ld bc, (hl)
- ld hl, HighScore \ ld hl, (hl)
- or a \ sbc hl, bc \ jp nc, MainMenu
- ld hl, HighScore \ ld (hl), bc
- jp MainMenu
- MoveRight:
- ld hl, comboSelected
- ld a, (hl)
- cp 12
- jp z, GameLoop_End
- inc a
- jr Move_End
- MoveLeft:
- ld hl, comboSelected
- ld a, (hl)
- cp 0
- jp z, GameLoop_End
- dec a
- Move_End:
- ld (hl), a
- jp GameLoop_End
- SwapRow:
- ld hl, comboSelected
- ld a, (hl)
- cp 12
- jp z, GameLoop_End
- cp 6
- jr c, swap_tobottom
- ;swap_totop:
- sub 6
- jr swap_end
- swap_tobottom:
- ld b,6
- add a,b
- swap_end:
- ld (hl), a
- jp GameLoop_End
- RollDie:
- ld de, dieValues
- ld a, 5 \ call rand \ inc a
- ld (de), a \ inc de
- ld a, 5 \ call rand \ inc a
- ld (de), a \ inc de
- ld a, 5 \ call rand \ inc a
- ld (de), a \ inc de
- ld a, 5 \ call rand \ inc a
- ld (de), a \ inc de
- ld a, 5 \ call rand \ inc a
- ld (de), a \ inc de
- jp GameLoop_End
- Quit:
- call _ClrScrn
- ld a,lcdbpp16
- ld (mpLcdCtrl),a
- call _DrawStatusBar
- ei
- ret
- RefreshScreen:
- ret
- ShowControls
- call _GetKey
- jp GameStart
- rand:
- ;;Input: A is the range.
- ;;Output: Returns in A a random number from 0 to (input)A-1.
- ;; B=0
- ;; DE is a pseudo-random 16-bit integer.
- ;;Destroys:
- ;; HL
- ;;Speed:
- push af
- call prng24
- ex de,hl
- pop af
- or a \ sbc hl,hl
- ld b,h
- add a,a \ jr nc,$+5 \ push de \ pop hl
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
- add hl,hl \ rla \ ret nc \ add hl,de \ adc a,b
- ret
- prng24:
- ;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
- TitleText:
- .db "TI - Yahtzee",0
- AnyKeyText:
- .db "Press any key to start",0
- LibLoadAppVar:
- .db 0,"LibLoad",0
- YahtzeeSave:
- .db 0,"YahtSav",0
- YahtzeeData:
- .dw 0,0 ; Score, High Score (6 bytes)
- .db 0,0,0,0,0 ; Die Values (5 bytes)
- .db %00000000 ; Die Held? (1 byte)
- .db 0 ; Number Rolls (1 byte)
- .db %00000001 ; Plays Allowed - Roll Only, Score Only, Both
- .db %00000000 ; Combo Scored 1's - 6's (1 byte)
- .db %00000000 ; Combo Scored 3k, 4k, FH, SS, LS, CH, YATZ (1 byte)
- .db 0,0,0,0,0,0 ; Combo Scores 1's - 6's (6 bytes)
- .db 0,0,0,0,0,0,0 ; Combo Scores 3k - YATZ (7 bytes)
- .db 0,0,0,0 ; Selected Combo, Calculated Score, 1-6s Bonus, Yahtzee Bonus
- .db %00000000 ; bonus flags (0 = 1-6's)
- .db %00000000 ; bonus apply flags (yatz = 0, Ns = 1)
- YahtzeeDataEnd:
- Score equ gameRAM
- HighScore equ Score+3
- dieValues equ HighScore+3
- dieHoldFlags equ dieValues+5
- dieRolls equ dieHoldFlags+1
- playsAllowedFlags equ dieRolls+1
- comboFlags1 equ dieHoldFlags+1
- comboFlags2 equ comboFlags1+1
- comboScores equ comboFlags2+1
- comboSelected equ comboScores+13
- calcedScore equ comboSelected+1
- calcedNsBonus equ calcedScore+1
- calcedYatzBonus equ calcedNsBonus+1
- bonusFlags equ calcedBonus+1
- bonusApplyFlags equ bonusFlags+1
- ; bit values for Plays Allowed
- playRoll equ 0
- playScore equ 1
- ; bit balues for combo flags 1
- c1s equ 0
- c2s equ 1
- c3s equ 2
- c4s equ 3
- c5s equ 4
- c6s equ 5
- ; bit values for combo flags 2
- c3K equ 0
- c4K equ 1
- cFH equ 2
- cSS equ 3
- cLS equ 4
- cCH equ 5
- cYATZ equ 6
- #include "source/yahtzee/gfx.asm"
- #include "source/yahtzee/combos.asm"
- #include "source/yahtzee/data.asm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement