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
- jp _NewLine
- 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
- _initfile: ; if save file not found, zero gamestate. Then start gameplay
- ld de, gameRAM
- ld hl, YahtzeeData
- ld bc, YahtzeeDataEnd-YahtzeeData
- ldir
- ld hl, playsAllowedFlags
- set playRoll, (hl)
- call MainMenu
- ld a, 0
- splash_GetCSC_loop:
- call _kbdscan
- ld a, (kbdScanCode)
- cp skEnter \ jr nz, splash_GetCSC_loop
- ; main menu
- GameStart:
- call RefreshScreen
- 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
- cp skYequ \ jp z, holdDie
- cp skWindow \ jp z, holdDie
- cp skZoom \ jp z, holdDie
- cp skTrace \ jp z, holdDie
- cp skGraph \ jp z, holdDie
- bit playScore, (hl)
- jr z, noScores
- noRolls:
- ; Scoring
- bit playScore, (hl)
- jr z, noScores
- 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
- ld a, 0 \ jr KeyGetLoop
- GameLoop_End:
- call CalcCurrentScore
- ld hl, comboFlags1 \ ld a, (hl)
- cp %00111111 \ jr nz, GameStart
- ld hl, comboFlags2 \ ld a, (hl)
- cp %01111111 \ jp nz, GameStart
- jr GameOver
- ; exit game conditions
- jp 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
- holdDie:
- jp GameLoop_End
- RollDie:
- ld de, dieValues
- ; roll die 1
- ld a, 6
- push de \ call rand \ pop de
- inc a
- ld (de), a \ inc de
- ; roll die 2
- ld a, 6
- push de \ call rand \ pop de
- inc a
- ld (de), a \ inc de
- ; roll die 3
- ld a, 6
- push de \ call rand \ pop de
- inc a
- ld (de), a \ inc de
- ; roll die 4
- ld a, 6
- push de \ call rand \ pop de
- inc a
- ld (de), a \ inc de
- ; roll die 5
- ld a, 6
- push de \ call rand \ pop de
- inc a
- ld (de), a
- ld hl, playsAllowedFlags
- set playScore, (hl)
- jp GameLoop_End
- Quit:
- call _ClrScrn
- call gfx_End
- ld iy, flags
- jp _DrawStatusBar
- RefreshScreen:
- call gfx_ClearVram
- ld a, cYellow \ ld hl, 0
- ld l, a
- push hl
- call gfx_SetTextFGColor
- pop hl
- ld a, cRed \ ld l, a
- push hl
- call gfx_SetTextBGColor
- pop hl
- ; draw game banner
- ld hl, 320*220+vram
- ld bc, 20*320
- ld a, cRed
- call _MemSet
- ld hl,1
- push hl
- push hl
- call gfx_setTextScale
- pop hl
- pop hl
- ld hl,227 \ push hl
- ld hl, 5 \ push hl
- ld hl, GameLBannerText \ push hl
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ; draw key assist
- ld hl, 320*155+vram
- ld bc, 320*65
- ld a, cYellow
- call _MemSet
- ld a, cRed \ ld hl, 0
- ld l, a
- push hl
- call gfx_SetTextFGColor
- pop hl
- ld a, cYellow \ ld l, a
- push hl
- call gfx_SetTextBGColor
- pop hl
- ld hl, 180 \ push hl
- ld hl, 30 \ push hl
- ld hl, KeyAssistHold \ push hl
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ld hl, 190 \ push hl
- ld hl, 30 \ push hl
- ld hl, KeyAssistArrows \ push hl
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ld hl, 200 \ push hl
- ld hl, 30 \ push hl
- ld hl, KeyAssistScore \ push hl
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ld hl, 210 \ push hl
- ld hl, 30 \ push hl
- ld hl, KeyAssistRoll \ push hl
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ld hl, 320*175+vram
- ld bc, 320
- ld a, cRed
- call _MemSet
- ld hl, 320*155+vram
- ld bc, 320
- call _MemSet
- ld hl, 162 \ push hl
- ld hl, 20 \ push hl
- ld hl, playsAllowedFlags \ ld a, (hl)
- cp %00000001 \ jr nz, gameScrn_skipRoll
- ld hl, MoveAssistRoll \ push hl
- jr gameScrn_endActionText
- gameScrn_skipRoll:
- cp %00000010 \ jr nz, gameScrn_skipScore
- ld hl, MoveAssistScore \ push hl
- jr gameScrn_endActionText
- gameScrn_skipScore:
- ld hl, MoveAssistBoth \ push hl
- gameScrn_endActionText:
- call gfx_PrintStringXY
- pop hl
- pop hl
- pop hl
- ld a, cRed
- ld hl, vram
- ld bc, 36*320
- call _MemSet
- ld hl, 2 \ push hl \ push hl
- ld hl, 2 \ push hl
- ld hl, 70
- ld de, dieValues-1 \ ld b, 5
- dierender_foreach:
- ; we enter this loop with the sprite x and y scale, and y position pushed
- ; the x position is in hl, and the pointer to the die value array -1 is in ix
- push hl
- ld hl, scratchRAM \ ld (hl), bc
- call sprite_getPointer
- push hl
- call gfx_SSprite
- pop hl
- ld hl, scratchRAM \ ld bc, (hl)
- pop hl
- ld a, b
- ld bc, 34 \ add hl, bc
- ld b, a
- djnz dierender_foreach
- pop hl
- pop hl
- pop hl
- ret
- sprite_getPointer:
- ; in = ix pointing to byte before die value
- ; out = ix advanced 1, hl points to sprite
- push bc
- inc de \ ld a, (de) \ inc a
- ld hl, DieSpritesStart-258
- ld bc, 258
- ld b, a
- jumptospriteloop:
- add hl, bc
- djnz jumptospriteloop
- pop bc
- ret
- 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 [Enter] to start",0
- GameLBannerText:
- .db "Yahtzee CE, Version 1.0, by ACagliano",0
- KeyAssistHold:
- .db "[Y= <> Graph] = Hold Die",0
- KeyAssistArrows:
- .db "[Arrow Keys] = Select Combo",0
- KeyAssistScore:
- .db "[Enter] = Score Combo",0
- KeyAssistRoll:
- .db "[2nd] = Roll Die, [Clear] = Quit",0
- MoveAssistRoll:
- .db "Roll Die Now!",0
- MoveAssistScore:
- .db "Score a Combo Now!",0
- MoveAssistBoth:
- .db "Roll Die or Score Combo",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