-
Notifications
You must be signed in to change notification settings - Fork 10
/
script.s
248 lines (224 loc) · 6.74 KB
/
script.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
SCRIPT_TITLE = 0
SCRIPT_ENEMIES = 1
EP_TITLE = $0000
EP_MOVEDROID = $0100
EP_MOVEFLYINGCRAFT = $0101
EP_MOVEWALKER = $0102
EP_MOVETANK = $0103
EP_MOVEFLOATINGMINE = $0104
EP_MOVEROLLINGMINE = $0105
EP_MOVETURRET = $0106
EP_MOVEFIRE = $0107
EP_MOVESMOKECLOUD = $0108
EP_MOVERAT = $0109
EP_MOVESPIDER = $010a
EP_MOVEFLY = $010b
EP_MOVEBAT = $010c
EP_MOVEFISH = $010d
EP_MOVEROCK = $010e
EP_MOVEFIREBALL = $010f
EP_MOVESTEAM = $0110
EP_MOVEORGANICWALKER = $0111
EP_DESTROYFIRE = $0112
EP_RATDEATH = $0113
EP_SPIDERDEATH = $0114
EP_FLYDEATH = $0115
EP_BATDEATH = $0116
EP_DESTROYROCK = $0117
EP_ORGANICWALKERDEATH = $0118
EP_MOVELARGEWALKER = $0119
EP_EXPLODE2_8 = $011a
EP_EXPLODE2_8_OFS6 = $011b
EP_EXPLODE2_8_OFS10 = $011c
EP_EXPLODE3_OFS15 = $011d
EP_EXPLODE4_OFS15 = $011e
EP_MOVESCRAPMETAL = $011f
EP_MOVEROCKTRAP = $0120
EP_DESTROYCPU = $0121
EP_MOVEEYESTAGE1 = $0122
EP_MOVEEYESTAGE2 = $0123
EP_DESTROYEYE = $0124
EP_MOVEJORMUNGANDR = $0200
EP_DESTROYJORMUNGANDR = $0201
AT_ADD = 1
AT_REMOVE = 2
AT_DESTROY = 4
AT_NEAR = 8
SPEECHBUBBLEOFFSET = -40*8
; Set or modify trigger for an actor type
;
; Parameters: A Script entrypoint, X script file, Y actor type, temp1 trigger mask
; Returns: -
; Modifies: A,X,Y,zpSrcLo
SetActorTrigger:pha
jsr ATSearch ;Either search for existing or create new
pla
sta atScriptEP,y
txa
sta atScriptF,y
lda zpSrcLo
sta atType,y
lda temp1
sta atMask,y
rts
; Remove trigger from an actor type
;
; Parameters: Y actor type
; Returns: -
; Modifies: A,Y,zpSrcLo
RemoveActorTrigger:
jsr ATSearch
bcc RAT_NotFound
RAT_Loop: lda atType+1,y
sta atType,y
lda atScriptEP+1,y
sta atScriptEP,y
lda atScriptF+1,y
sta atScriptF,y
lda atMask+1,y
sta atMask,y
iny
cpy #MAX_ACTORTRIGGERS
bcc RAT_Loop
RAT_NotFound: rts
ATSearch: sty zpSrcLo
ldy #$00
ATSearch_Loop: lda atType,y
beq ATSearch_NotFound
ATSearch_Cmp: cmp zpSrcLo
beq ATSearch_Found ;C=1 if found existing
iny
bne ATSearch_Loop
ATSearch_NotFound:
clc
ATSearch_Found: rts
; Run an actor trigger routine
;
; Parameters: Y trigger type (mask bit), X actor number
; Returns: -
; Modifies: A,Y,loader temp vars
ActorTrigger: lda actFlags,x
and #AF_USETRIGGERS ;First check: does the actor use triggers at all?
beq AT_Fail
ActorTriggerNoFlagCheck:
sty ES_ParamY+1
ldy actT,x
jsr ATSearch
bcc AT_Fail
lda atMask,y
AT_MaskCheck: and ES_ParamY+1
beq AT_Fail
stx ES_ParamX+1
lda atScriptEP,y
ldx atScriptF,y
jsr ExecScript
ldx ES_ParamX+1
ES_LoadOnly:
AT_Fail: rts
; Execute a script
;
; Parameters: A script entrypoint, X script file, ES_ParamX+1, ES_ParamY+1 (or Y in ExecScriptParam)
; Returns: -
; Modifies: A,X,Y,loader temp vars
ExecScriptParam:sty ES_ParamY+1
ExecScript: pha
ES_LoadedScriptFile:
cpx #$ff ;Check if same file already loaded
beq ES_SameFile
stx ES_LoadedScriptFile+1
txa
ldx #F_SCRIPT
jsr MakeFileName
lda #<scriptCodeStart
ldx #>scriptCodeStart
jsr LoadFileRetry
ES_SameFile: pla
bmi ES_LoadOnly
asl
tax
lda scriptCodeStart,x
sta ES_ScriptJump+1
lda scriptCodeStart+1,x
sta ES_ScriptJump+2
ES_ParamX: ldx #$00
ES_ParamY: ldy #$00
ES_ScriptJump: jmp $1000
; Set/stop a continuous script
;
; Parameters: A script entrypoint, X script file (negative = stop)
; Returns: -
; Modifies: -
StopScript: ldx #$ff
SetScript: stx scriptF
sta scriptEP
rts
; NPC speak a line
;
; Parameters: Y actor type, A,X text address
; Returns: -
; Modifies: A,X,Y,temp1-temp4
SpeakLine: sty SL_ActT+1
jsr PrintPanelTextIndefinite
SL_ActT: lda #$00
jsr FindActor
bcc SL_NoSpeechBubble
lda #ACTI_FIRSTEFFECT
ldy #ACTI_LASTEFFECT
jsr GetFreeActor
bcc SL_NoSpeechBubble
lda #$00
sta temp1
sta temp2
lda #<SPEECHBUBBLEOFFSET
sta temp3
lda #>SPEECHBUBBLEOFFSET
sta temp4
lda #ACT_SPEECHBUBBLE
jsr SpawnWithOffset
SL_NoSpeechBubble:
ldx #MENU_DIALOGUE
jmp SetMenuMode
; Get the value of a plotbit
;
; Parameters: A plotbit number
; Returns: A nonzero if set
; Modifies: A,Y
GetPlotBit: jsr DecodeBit
and plotBits,y
rts
; Set a plotbit
;
; Parameters: A plotbit number
; Returns: -
; Modifies: A,Y
SetPlotBit: jsr DecodeBit
ora plotBits,y
bne CPB_Store
; Clear a plotbit
;
; Parameters: A plotbit number
; Returns: -
; Modifies: A,Y
ClearPlotBit: jsr DecodeBit
eor #$ff
and plotBits,y
CPB_Store: sta plotBits,y
rts
; Turn a number into a byte offset into a bit-table and a bitmask
;
; Parameters: A number
; Returns: A bitmask, Y byte offset
; Modifies: A,Y
DecodeBit: pha
and #$07
tay
lda keyRowBit,y
eor #$ff
sta DB_Value+1
pla
lsr
lsr
lsr
tay
DB_Value: lda #$00
SameLevel: rts