Prev: D462 Up: Map Next: EC01
EB9E: Start playing a tune (AY-3-8912 music driver)
A = tune number. Looks up the tune's 7-byte entry (index = A*7, via the ADD A,A / ADD A,C doubling sequence at EBA7-EBAB) in the table at F225: 1 tempo/speed byte followed by 3 x 2-byte pattern-data pointers, one per channel. Uses that entry to initialise the 3 channel-tracker records at $EC01/$EC26/$EC4B (37 bytes each, stride $25 -- offsets used elsewhere in this sound driver: +$00 note/status, +$01/+$02 pattern pointer, +$03/+$04 envelope or effect pointer, +$05 initial speed, +$06 counter, +$10 enable flag, +$1D/+$1F/+$20/+$21 misc playback state) before flagging the tune active via $F223 for the per-frame service routine at ts_music_service.
The per-channel effect/envelope pointer (+$01/+$02) is not read from the tune table directly -- it is read from the first 2 bytes of the pattern data that the channel's own pattern pointer (+$03/+$04) points to (EBDF-$EBE2), i.e. every pattern begins with an envelope-pointer header. advance_channel_pattern and compute_channel_ay_registers (referenced by ts_music_service below) do the actual per-frame pattern-data processing.
Used by the routine at titlescr_start_tune.
Input
A The tune number to start
start_tune EB9E LD HL,$F223 Clear the "tune active" flag and its companion
EBA1 LD (HL),$00 byte at $F224
EBA3 INC HL
EBA4 LD (HL),$00
EBA6 LD C,A BC = A * 7 (2A, +A = 3A, doubled = 6A, +A = 7A):
EBA7 ADD A,A the $F225 table's 7-byte-per-tune entry stride
EBA8 ADD A,C
EBA9 ADD A,A
EBAA ADD A,C
EBAB LD C,A
EBAC LD B,$00
EBAE LD HL,$F225 HL -> this tune's entry in the tune-select table
EBB1 ADD HL,BC
EBB2 LD A,(HL) First byte = tempo/speed, saved for later use
EBB3 LD ($EC9A),A Self modify 'LD A,x' at EC99 to set the tempo-counter reload value to this tune's tempo byte
EBB6 INC HL
EBB7 LD IX,$EC01 IX -> first of the 3 channel-tracker records
EBBB LD C,$25 Record stride (37 bytes)
EBBD LD A,$03 3 channels
stu_channel_loop EBBF LD E,(HL) Read this channel's pattern-data pointer from the
EBC0 INC HL tune table
EBC1 LD D,(HL)
EBC2 INC HL
EBC3 PUSH HL
EBC4 LD (IX+$20),$00 Reset misc playback state for this channel
EBC8 LD (IX+$21),$00
EBCC LD (IX+$10),$01 Enable the channel
EBD0 LD (IX+$00),B B = 0 here: clear note/status
EBD3 LD (IX+$1D),B
EBD6 LD (IX+$1F),B
EBD9 LD (IX+$03),E Store the pattern pointer
EBDC LD (IX+$04),D
EBDF EX DE,HL Follow the pattern pointer to read a second,
EBE0 LD E,(HL) effect/envelope pointer from the start of the
EBE1 INC HL pattern data itself
EBE2 LD D,(HL)
EBE3 LD (IX+$05),$02 Initial speed/divider = 2
EBE7 LD (IX+$06),B Counter = 0
EBEA POP HL
EBEB LD (IX+$01),E Store the effect/envelope pointer
EBEE LD (IX+$02),D
EBF1 ADD IX,BC Next channel record
EBF3 DEC A
EBF4 JR NZ,stu_channel_loop
EBF6 LD ($EED1),A A = 0 here: clear a driver-internal flag
EBF9 INC A A = 1: mark the tempo counter for an immediate
EBFA LD ($EC70),A refresh (see ts_music_service)
EBFD LD ($F223),A Flag the tune as active
EC00 RET
Prev: D462 Up: Map Next: EC01