-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.asm
670 lines (607 loc) · 12.8 KB
/
options.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
; OPTIONS MENU
; Palette change to recover
; Unbuffer screen for this area
;----------------------------------------------
options.msg2:
db orange*&11,60,45
dm " OPTIONS"
db eof
options.msg: ; Main menu structure
db white*&11,60,44
dm " OPTIONS"
db cr,cr,orange
dm "RETURN"
db cr
dm "REDEFINE KEYS"
db cr
dm "MUSIC"
db cr,pale_blue
dm " VOLUME"
db cr
dm " TUNE"
db cr,orange
dm "SFX"
db cr,pale_blue
dm " VOLUME"
db eof
options.on.msg: ; Generic on/off messages
db white
dm "ON"
db blue
dm "/"
db orange
dm "OFF"
db eof
options.off.msg:
db orange
dm "ON"
db blue
dm "/"
db white
dm "OFF"
db eof
options.music.tanaka.msg: ; Labels for tunes types available
dm "TANAKA'S TUNE"
db eof
options.music.korobushka.msg:
dm "KOROBUSHKA"
db eof
options.music.medley.msg: ; This should swap between tunes every few rounds
dm "MEDLEY"
db eof
;----------------------------------------------
options.tune.lut:
; Lookup table to find tune titles in ASCII form, and value to put in main.game_music
@korobushka: equ 0
dw options.music.korobushka.msg
db music.korobushka
@tanaka: equ 1
dw options.music.tanaka.msg
db music.tanaka
@medley: equ 2
options.tune.medley: equ 2
dw options.music.medley.msg
db music.korobushka ; Start with Korobushka
options.music.tune: db @medley ; Current music type
options.heart.y: db 1 ; Current selection 0-6
options.functions.lut:
; Lookup table of functions when option selected, for moving left, right and pressing rotate
dw options.nothing,options.return,options.return ; Return
dw options.nothing,options.redefine,options.redefine ; Redefine keys
dw options.set_music_on,options.set_music_off,options.toggle_music ; Music on/off
dw options.music_vol_down,options.music_vol_up,options.music_vol_up_loop; Music volume
dw options.tune_down,options.tune_up,options.tune_up_loop ; Music tune
dw options.set_sfx_on,options.set_sfx_off,options.toggle_sfx ; SFX on/off
dw options.sfx_vol_down,options.sfx_vol_up,options.sfx_vol_up_loop ; SFX volume
;----------------------------------------------
options.start:
; Invoked on attract mode when escape is pressed
ld a,int_mode.game
call music.set_modeA
call house.double_buffer.off
ld hl,house.palette
call house.set_paletteHL
call house.set_curr_palette
call options.clear
call options.print_logo
xor a
ld (options.heart.y),a
call options.print_menu
@loop:
call house.wait_frame_im2
call options.reprint_heart
ld a,(keys.processed)
bit Escape,a
jp nz,options.end
bit Down,a
call nz,options.down
bit Up,a
call nz,options.up
bit Left,a
call nz,@+function_left
bit Right,a
call nz,@+function_right
bit RotateC,a
call nz,@+function_fire
bit RotateAC,a
call nz,@+function_fire
jp @-loop
options.end:
call house.double_buffer.on
call house.clear_screens
call attract.init
di
ld a,int_mode.attract
call music.set_modeA
ei
pop hl
jp main.attract.loop
@function_left:
ld e,0
jp @+process_function
@function_right:
ld e,2
jp @+process_function
@function_fire:
ld e,4
@process_function:
push af
ld a,(options.heart.y)
ld d,a
add a
add d
add a
add e
ld e,a
ld d,0
ld hl,options.functions.lut
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
ld (@+addr+1),de
@addr: call 0
pop af
ret
;----------------------------------------------
options.clear:
; clear lower portion of screen
ld hl,37*128
ld de,37*128+1
ld (hl),0
ld bc,(192-37)*128-1
ldir
ret
;----------------------------------------------
options.prep_logo:
; Make simple version of logo for printing when options screen is displayed
ld hl,logo.data
@print_logo_loop:
ld a,(hl)
@test_term_token:
cp -1
jr z,@+outline
ld e,a
inc hl
ld d,(hl)
inc hl
push hl
ld c,e
ld b,d
ex de,hl
add hl,hl
add hl,hl
add hl,bc
ld bc,&0444
add hl,bc
ex de,hl
call attract.print_block
call house.pal_up
pop hl
jp @-print_logo_loop
@outline:
ld hl,&0442 ; ! More magic numbers
ld de,&23b8
ld c,white
ld b,%01011010
ld ix,logo.fore_cols
call gfx.outlineIXHLDEBC
@grab:
ld a,33
ld hl,&0342/2
ld de,options.logo_data
@yloop:
push hl
ld bc,60
ldir
call house.pal_up
pop hl
ld bc,128
add hl,bc
dec a
jr nz,@-yloop
call house.clear_screens
ret
options.print_logo:
; Print logo for options menu, from previously cached copy
ld de,&0342/2
ld hl,options.logo_data
ld a,33
@yprint:
ld bc,60
ldir
ld bc,128-60
ex de,hl
add hl,bc
ex de,hl
dec a
jr nz,@-yprint
ret
options.logo_data:
ds 33*60
;----------------------------------------------
options.print_menu:
@print_main:
call font.set_masked
ld hl,options.msg2
call font.print_string.colHL
ld hl,options.msg
call font.print_string.colHL
call font.set_simple
call options.pick_tune
@print_music_on:
ld a,(music.on)
ld de,&5c7c
call @+print_onADE
@print_music_vol:
call music.get_vol
ld de,&687c
call @+print_volADE
@print_sfx_on:
ld a,(sfx.on)
ld de,&807c
call @+print_onADE
@print_sfx_vol:
ld a,(sfx.volume)
ld de,&8c7c
call @+print_volADE
ret
;----------------------------------------------
options.pick_tune:
; Select the current tune, set to initiate, reprint title
@clear_title:
ld hl,&747c/2
ld de,(&747c/2)+1
ld a,7
@loop:
ld (hl),0
ld bc,13*4-1
ldir
ld bc,128-(13*4)+1
add hl,bc
ex de,hl
add hl,bc
ex de,hl
dec a
jr nz,@-loop
ld a,(options.music.tune)
ld e,a
add a
add e
ld e,a
ld d,0
ld hl,options.tune.lut
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
inc hl
@store_current_tune:
ld a,(hl)
ld (main.game_music+1),a
ex de,hl
@print_tune_message:
ld a,pale_blue
call font.set_colA
ld de,&747c
call font.print_stringHLDE
ret
;----------------------------------------------
@print_onADE:
; Print on/off message mirroring A, to coords DE
ld hl,options.on.msg
cp On
jp z,@+skip
ld hl,options.off.msg
@skip:
call font.print_stringHLDE
ret
;----------------------------------------------
@print_volADE:
; Print volume graphic to volume A, to coords DE
srl d
rr e
ex de,hl
inc a
ld c,a
ld b,15
ld a,white*&10
@loop:
dec c
jp nz,@+skip
@turn_off:
ld a,orange*&10
@skip:
call @+print_bar
inc hl
djnz @-loop
ret
@print_bar:
push bc
push hl
ld b,7
ld de,128
@loop:
ld (hl),a
add hl,de
djnz @-loop
pop hl
pop bc
ret
;----------------------------------------------
options.reprint_heart:
@clear:
@prev_pos: ld hl,0
ld e,l
ld d,h
inc e
ld a,8
@loop:
ld (hl),0
for 3,ldi
ld bc,128-3
add hl,bc
ex de,hl
add hl,bc
ex de,hl
dec a
jp nz,@-loop
@print:
ld a,(options.heart.y)
ld b,a
add a
add b
add a
add &22
ld h,a
ld l,&19
ld (@-prev_pos+1),hl
ld b,gfx.heart
call gfx.print_blockBHL
ret
;----------------------------------------------
options.down:
; Move down selected option if available
push af
ld a,(options.heart.y)
cp 6
jr z,@+end
inc a
ld (options.heart.y),a
@end:
pop af
ret
options.up:
push af
ld a,(options.heart.y)
or a
jr z,@+end
dec a
ld (options.heart.y),a
@end:
pop af
ret
;----------------------------------------------
; Functions supporting the menu
options.nothing: ; Some keypresses are ignored
ret
options.return:
; Return to main attract sequence
for 3,pop hl ; Junk three levels of call instructions
jp options.end
options.redefine:
; Jump to redefine keys routine
call keys.redefine
@clear_lower:
ld hl,38*128
ld de,38*128+1
ld (hl),0
ld bc,(192-38)*128-1
ldir
jp options.return
options.set_music_on:
; Turn music on
push af
ld a,On
ld (music.on),a
ld de,&5c7c
call @-print_onADE
pop af
ret
options.set_music_off:
; Turn music off
push af
ld a,Off
ld (music.on),a
ld de,&5c7c
call @-print_onADE
pop af
ret
options.toggle_music:
; If fire pressed, assume toggle between options
push af
ld a,(music.on)
xor &ff
ld (music.on),a
ld de,&5c7c
call @-print_onADE
pop af
ret
options.music_vol_down:
; Reduce volume if possible, send to global music volume setting, reprint graphic
push af
call music.get_vol
or a
jr z,@+end
dec a
@check_vol1: ; Volume 1 is silent for envelope voices, so skip this setting
cp 1
jr nz,@+skip
dec a
@skip:
call music.set_volA
ld de,&687c
call @-print_volADE
@end:
pop af
ret
options.music_vol_up:
; Increase volume if possible
push af
call music.get_vol
cp 15
jr z,@+end
inc a
@check_vol1:
cp 1
jr nz,@+skip
inc a
@skip:
call music.set_volA
ld de,&687c
call @-print_volADE
@end:
pop af
ret
options.music_vol_up_loop:
; Increase volume unless we're at the maximum, then reset to 0
push af
call music.get_vol
cp 15
jr nz,@+skip
@reset:
ld a,-1
@skip:
inc a
@check_vol1:
cp 1
jr nz,@+skip
inc a
@skip:
call music.set_volA
ld de,&687c
call @-print_volADE
pop af
ret
options.set_sfx_on:
; Turn SFX on, reprint graphic, make sound effect to reflect this
push af
ld a,On
ld (sfx.on),a
ld de,&807c
call @-print_onADE
ld c,sfx.move_side
call sfx.setC.out
pop af
ret
options.set_sfx_off:
; Turn SFX off, no sound effect this time
push af
ld a,Off
ld (sfx.on),a
ld de,&807c
call @-print_onADE
pop af
ret
options.toggle_sfx:
; Toggle sound effect value. Sound effect won't sound if turned off
push af
ld a,(sfx.on)
xor &ff
ld (sfx.on),a
ld de,&807c
call @-print_onADE
ld c,sfx.move_side
call sfx.setC.out
pop af
ret
options.sfx_vol_down:
; Reduce SFX volume if possible, reprint graphic, and make sound to give feedback to player
push af
ld a,(sfx.volume)
or a
jr z,@+end
dec a
ld (sfx.volume),a
ld de,&8c7c
call @-print_volADE
@end:
ld c,sfx.move_side
call sfx.setC.out
pop af
ret
options.sfx_vol_up:
; Increase SFX volume if possible
push af
ld a,(sfx.volume)
cp 15
jr z,@+end
inc a
ld (sfx.volume),a
ld de,&8c7c
call @-print_volADE
@end:
ld c,sfx.move_side
call sfx.setC.out
pop af
ret
options.sfx_vol_up_loop:
; Volume up unless we're at the top, then reset to 0
push af
ld a,(sfx.volume)
cp 15
jr nz,@+skip
@reset:
ld a,-1
@skip:
inc a
@check_vol1:
cp 1
jr nz,@+skip
inc a
@skip:
ld (sfx.volume),a
ld de,&8c7c
call @-print_volADE
ld c,sfx.move_side
call sfx.setC.out
pop af
ret
options.tune_down:
; Swap to previous tune option (only two tunes and 'medley' available), set to play, reprint tune title
push af
ld a,(options.music.tune)
or a
jr z,@+end
dec a
ld (options.music.tune),a
call options.pick_tune
@end:
pop af
ret
options.tune_up:
; Swap to next tune option.
push af
ld a,(options.music.tune)
cp 2
jr z,@+end
inc a
ld (options.music.tune),a
call options.pick_tune
@end:
pop af
ret
options.tune_up_loop:
; Swap to next tune option unless at final choice, then loop to start
push af
ld a,(options.music.tune)
cp 2
jr nz,@+skip
@reset:
ld a,-1
@skip:
inc a
ld (options.music.tune),a
call options.pick_tune
pop af
ret