-
Notifications
You must be signed in to change notification settings - Fork 3
/
7bag.s
62 lines (53 loc) · 1.19 KB
/
7bag.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;
; Mod that uses a 7-bag for choosing tetriminos
;
.include "build/tetris.inc"
.include "ips.inc"
.segment "PICK_TETRIMINO_PATCH"
ips_segment "PICK_TETRIMINO_PATCH",pickRandomTetrimino,$0038
pickRandomTetrimino_7bag:
lda spawnID
bne @countBits
lda #$7F
sta spawnID
; Count number of pieces remaining in bag
@countBits:
ldx #0
@shiftLoop:
lsr a
bcc @bitClear
inx ; Trashes Z, so bne is unconditional
@bitClear:
bne @shiftLoop
; Bounded random
@mult: tay ; Set y=0
@multLoop:
clc
adc rng_seed
bcc @noCarry
iny
@noCarry:
dex
bne @multLoop
; Find chosen piece
lda spawnID
iny ; THINGS ARE WEIRD HERE
@nextBit:
inx
lsr a
bcc @nextBit
dey
bne @nextBit
; Clear chosen piece in spawnID
txa
tay
lda #$00
sec
@shiftLeft:
rol
dey
bne @shiftLeft
eor spawnID
sta spawnID
lda spawnTable,x
rts