[go: up one dir, main page]

Menu

[r132]: / psrp / asm / t2a.asm  Maximize  Restore  History

Download this file

354 lines (258 with data), 5.6 kB

  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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
;
; Item window drawer (generic)
;
; Written in TASM 3.0.1
;
#include "vars.asm"
.org $7e3e ; $2fe3e-2ffff
inventory:
ld b,$08 ; 8 items total
next_item:
push bc
push hl
di
ld a,$7f000/$4000 ; move to page 0
ld ($fff0),a
; FIX: I've changed this to not use paging in slot 0 because too many
; emulators, and the GG/SMSPro flash carts, don't support it.
; Rather than fix up a load of references, I've instead left these in
; taking space but harmlessly writing to $fff0 instead.
ld a,(hl) ; grab item #
ld hl,ITEMS ; table start
push de
; call $3d8d ; copy string to RAM
call $3eca ; copy string to RAM ; changed address
pop de
ld a,$00 ; reload page 0
ld ($fff0),a
ei
ld hl,TEMP_STR ; start of text
call start_write ; write out 2 lines of text
call wait_vblank
call start_write
call wait_vblank
pop hl
pop bc
inc hl ; next item
djnz next_item
ret
; ________________________________________________________
shop:
ld b,$03 ; 3 items total
next_shop:
push bc
push hl
di
ld a,$7f000/$4000 ; move to page 0
ld ($fff0),a
ld a,$03 ; shop bank
ld ($ffff),a
ld a,(hl) ; grab item #
ld (FULL_STR),hl ; save current shop ptr
ld hl,ITEMS ; table start
push de
; call $3d8d ; copy string to RAM
call $3eca ; copy string to RAM
pop de
ld a,$00 ; reload page 0
ld ($fff0),a
ei
ld hl,TEMP_STR ; start of text
call start_write ; write out 2 lines of text
push hl ; hacky workaround
push de
ld c,$01 ; write out price
call shop_price
pop de
pop hl
ld a,$02 ; restore page 2
ld ($ffff),a
call start_write
push hl ; hacky workaround
push de
ld c,$00 ; do not write price
call shop_price
pop de
pop hl
pop hl ; restore old parameters
pop bc
inc hl ; next item
inc hl
inc hl
djnz next_shop
ret
; ________________________________________________________
enemy:
di
ld a,$7f000/$4000 ; move to page 0
ld ($fff0),a
ld a,$03 ; shop bank
ld ($ffff),a
ld a,($c2e6) ; grab enemy #
ld hl,ENEMY ; table start
push de
; call $3d8d ; copy string to RAM
call $3eca ; copy string to RAM
pop de
ld a,$00 ; reload page 0
ld ($fff0),a
ei
ld hl,TEMP_STR ; start of text
call start_write ; write out line of text
ld a,(LEN) ; optionally write next line
or a
call nz,start_write
call wait_vblank
ret
; ________________________________________________________
equipment:
ld b,$03 ; 3 items total
next_equipment:
push bc
push hl
di
ld a,$7f000/$4000 ; move to page 0
ld ($fff0),a
ld a,$03 ; shop bank
ld ($ffff),a
ld a,(hl) ; grab item #
ld hl,ITEMS ; table start
push de
; call $3d8d ; copy string to RAM
call $3eca ; copy string to RAM
pop de
ld a,$00 ; reload page 0
ld ($fff0),a
ei
ld hl,TEMP_STR ; start of text
call start_write ; write out 2 lines of text
call wait_vblank
call start_write
call wait_vblank
pop hl
pop bc
inc hl ; next item
djnz next_equipment
ret
; ________________________________________________________
start_write:
di
push bc
push de
rst 08h ; set vram address
push af
pop af
ld a,$f3 ; left border
out ($be),a
push af
pop af
ld a,$11
out ($be),a
ld a,(LEN) ; string length
ld c,a
ld b,$0a ; 10-width
; ---------------------------------------------
check_length:
ld a,c ; check for zero string
or a
jr z,blank_line
read_byte:
ld a,(hl) ; read character
inc hl ; bump pointer
dec c ; shrink length
cp $4f ; normal text
jr c,bump_text
space:
jr z,blank_line ; non-narrative WS
newline:
cp $50 ; pad rest of line with WS
jr nz,hyphen
newline_flush:
xor a
call write_nt
djnz newline_flush
jr right_border
hyphen:
cp $51 ; add '-'
jr nz,skip_htext
ld a,$46
jr bump_text
skip_htext:
cp $52 ; ignore other codes
jr nz,check_length
loop_hskip:
ld a,(hl) ; eat character
inc hl
dec c
cp $53 ; check for 'end' or length done
jr nz,loop_hskip
jr check_length
blank_line:
xor a ; write out WS for rest of the line
bump_text:
call write_nt
djnz check_length
; ---------------------------------------------
right_border:
ld a,c ; store length
ld (LEN),a
push af ; right border
pop af
ld a,$f3
out ($be),a
push af
pop af
ld a,$13
out ($be),a
pop de ; restore stack
pop bc
; ---------------------------------------------------
push hl
ld hl,10*2+2 ; left border + 10-char width
add hl,de ; save VRAM ptr
ld (FULL_STR+2),hl
ld hl,$0040 ; VRAM newline
add hl,de
ex de,hl
pop hl
ei ; wait for vblank
ret
; ----------------------------------------------------------
write_nt:
add a,a ; lookup NT
ld de,$8000
add a,e
ld e,a
adc a,d
sub e
ld d,a
ld a,(de) ; write NT + VDP delay
out ($be),a
push af
pop af
inc de
ld a,(de)
out ($be),a
ret
; __________________________________________________________
wait_vblank:
ld a,$08 ; stable value
call $0056
ret
; __________________________________________________________
shop_price:
di
ld de,(FULL_STR+2) ; restore VRAM ptr
rst 08H
ld a,$03 ; shop bank
ld ($ffff),a
ld hl,(FULL_STR) ; shop ptr
ld a,(hl) ; check for blank item
or a
jr nz,write_price
ld c,$00 ; no price
write_price:
push de ; parameter
push hl ; parameter
jp $3a9a ; write price
.end ; tasm-only