Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dice = scrap ;5 bytes, current dice state
- round=scrap+5 ;counter for which round we are on
- Yahtzee:
- ld a,r ;\
- ld h,a ; |
- xor 77 ; |initialize PRNG seeds
- ld l,a ; |
- ld (seed1),hl ; |
- ld (seed2),hl ;/
- main:
- ld hl,$8080 ;\
- ld (dice),hl ; |Reset the dice to the "needs rerolling state"
- ld (dice+2),hl ; |
- ld (dice+3),hl ;/
- call roll ;Roll the dice for the first step
- ld bc,200h ;number of rerolls is B, C is the current selected die
- ld hl,dice ;HL points to the current selected die
- waitloop:
- ld a,(kbdScanCode) \ or a \ jr z,waitloop
- cp 15 \ jp z,exit
- cp 55 \ call z,mode \ jr z,waitloop
- cp 10 \ jr nc,$+10 \ call selection \ call render_dice \ jr waitloop
- cp 54 \ jr nz,waitloop
- push hl
- call roll
- pop hl
- djnz waitloop
- scorecheck:
- ;;Check if it's a winning combination
- ;;Also need some quitting condition. I don't know when the game is over.
- jp main
- exit:
- ;;not sure if you want to do something fancy before exiting
- ret
- mode:
- ;;Bring up options and stuff
- push af
- push hl
- push bc
- pop bc
- pop hl
- pop af
- ret
- selection:
- ;;DOWN needs to deselect the current die from being rerolled.
- ;;LEFT needs to move the selector to the left, wrapping around.
- ;;RIGHT needs to move the selector to the right, wrapping around.
- ;;UP selects the current die for rerolling.
- ;;ENTER toggles whether o not it gets rerolled
- dec a \ jr nz,$+5 \ res 7,(hl)\ ret
- dec a \ jr nz,$+11 \ dec hl \ dec c \ ret p \ ld c,4 \ ld hl,dice+4 \ ret
- dec a \ jr nz,$+13 \ inc hl \ inc c \ ld a,c \ sub 5 \ ret nz \ ld c,a \ ld hl,dice \ ret
- dec a \ jr nz,$+5 \ set 7,(hl) \ ret
- ld a,(hl) \ xor 80h \ ld (hl),a
- ret
- roll:
- push af
- push hl
- push de
- push bc
- ld hl,dice-1
- call rollSub
- call rollSub
- call rollSub
- call rollSub
- call rollSub
- pop bc
- pop de
- pop hl
- pop af
- render_dice:
- ;;render the scene including dice values
- ;;Things to consider:
- ;; B is the number of rerolls left.
- ;; C is the current selected die.
- ;; Any dice with bit 7 set means it is up for reroll. If A is the die value:
- ;; add a,a \ jr nc,$+ \ <<adjust coord>>
- ;; rlca
- ;; call drawdie
- push af
- push hl
- push de
- push bc
- pop bc
- pop de
- pop hl
- pop af
- ret
- rollsub:
- inc hl
- ld a,(hl) \ add a,a
- ret nc
- push hl
- push bc
- 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
- 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 bc
- pop hl
- ld (hl),a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement