-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.asm
140 lines (124 loc) · 2.21 KB
/
sequence.asm
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
;;; Code for handling scripted events
SequenceFrame: subroutine
ldx sqtimer
dex
beq .advance
stx sqtimer
rts
.advance
.checkseq
ldy sqidx
lda sequence,y
bne .nend ; are we in a sequence?
rts
.nend
bmi .getmem ; is it just a simple set/offset?
cmp #$20
bcs .nwait ; is it a control command?
sta sqtimer
iny
sty sqidx
rts
.nwait cmp #$40
bcs .ncall ; is it a call command?
iny
sty sqidx
and #$1f
tax
jsr CallFromTable
jmp .checkseq
.ncall cmp #$60
bcs .nplay ; is it a play command?
;; play code goes here
.nplay
; if we reach here it's a set memory address command
; set the memory address and continue like a simple set/offset
and #$1f
sta tmp0
iny
lda sequence,y
sta tmp1
rol
rol
and #$1
tax
lda tmp1
and #$3f
sta sqvar0,x
jmp .setval
.getmem
sta tmp1
and #$1f
sta tmp0
lda sequence,y
rol
rol
rol
rol
and #$1
tax
.setval
lda sqvar0,x
tax
lda tmp0
bit tmp1
bvs .offset
sta $0,x
jmp .opdone
.offset
clc
adc $0,x
sta $0,x
jmp .opdone
.reset
.opdone
iny
sty sqidx
bne .checkseq
PlaySequence: subroutine
ldy sqidx
lda sequence,y
beq .nalready ; if a sequence is already being played, do nothing
rts
.nalready
ldy SequencesTable,x
ldx #$ff
txa
pha
dey
.copy
iny
inx
lda Sequences,y
sta tmp3
and #$e0
cmp #$40
bne .nnest
; put the return index into stack and continue from new index
tya
pha
lda tmp3
and #$1f
tay
lda SequencesTable,y
tay
dex
dey
bne .copy
.nnest
lda tmp3
sta sequence,x
bne .copy
; if here, either a nest is closed or we're done
pla
cmp #$ff
beq .done
dex
tay
bne .copy
.done
ldy #0
sty sqidx
iny
sty sqtimer
rts