Player: Pause / resume support.

Press the P key to pause playback.

Call Player_Stop to pause and call Player_Resume to resume.
5 files changed, 180 insertions(+), 16 deletions(-)

M src/COM.asm
M src/Makoto.asm
M src/Neotron.asm
M src/Player.asm
M src/SFG.asm
M src/COM.asm +12 -1
@@ 72,7 72,18 @@ Main_Tick_Loop:
 	pop bc
 	and a
 	jr z,Main_Loop
-	call Player_Stop
+	push bc
 	ld c,_INNOE
 	call BDOS
+	pop bc
+	or 20H  ; lower-case
+	cp "p"
+	jr nz,Main_End
+Main_Pause:
+	push bc
+	call Player_TogglePause
+	pop bc
+	jr Main_Loop
+Main_End:
+	call Player_Stop
 	ret

          
M src/Makoto.asm +39 -4
@@ 105,6 105,24 @@ Makoto_Frequency2:
 
 ; hl = sound data
 Makoto_Instrument:
+	and 7
+	ex de,hl
+	ld c,a
+	ld b,0
+	ld hl,Player_instruments
+	add hl,bc
+	add hl,bc
+	ld (hl),e
+	inc hl
+	ld (hl),d
+	ex de,hl
+	call Makoto_Instrument_Set
+	jr Makoto_Process_Loop
+
+; a = channel
+; hl = sound data
+; hl <- next sound data
+Makoto_Instrument_Set:
 	bit 2,a
 	jr nz,Makoto_Instrument2
 Makoto_Instrument1:

          
@@ 122,8 140,7 @@ Makoto_Instrument1_Loop:
 	ld d,a
 	ld e,(hl)
 	inc hl
-	call Makoto_WriteRegister1
-	jp Makoto_Process_Loop
+	jp Makoto_WriteRegister1
 Makoto_Instrument2:
 	and 3
 	add a,30H

          
@@ 139,8 156,7 @@ Makoto_Instrument2_Loop:
 	ld d,a
 	ld e,(hl)
 	inc hl
-	call Makoto_WriteRegister2
-	jp Makoto_Process_Loop
+	jp Makoto_WriteRegister2
 
 Makoto_Mute:
 	ld b,10H

          
@@ 158,6 174,25 @@ Makoto_Mute_KeyOffLoop:
 	djnz Makoto_Mute_KeyOffLoop
 	ret
 
+Makoto_Restore:
+	ld a,0
+	ld hl,Player_instruments
+Makoto_Restore_Loop:
+	ld e,(hl)
+	inc hl
+	ld d,(hl)
+	inc hl
+	push af
+	push hl
+	ex de,hl
+	call Makoto_Instrument_Set
+	pop hl
+	pop af
+	inc a
+	cp 8
+	jr c,Makoto_Restore_Loop
+	ret
+
 ; d = register
 ; e = value
 Makoto_WriteRegister1:

          
M src/Neotron.asm +50 -4
@@ 126,6 126,24 @@ Neotron_Frequency2:
 
 ; hl = sound data
 Neotron_Instrument:
+	and 7
+	ex de,hl
+	ld c,a
+	ld b,0
+	ld hl,Player_instruments
+	add hl,bc
+	add hl,bc
+	ld (hl),e
+	inc hl
+	ld (hl),d
+	ex de,hl
+	call Neotron_Instrument_Set
+	jr Neotron_Process_Loop
+
+; a = channel
+; hl = sound data
+; hl <- next sound data
+Neotron_Instrument_Set:
 	bit 2,a
 	jr nz,Neotron_Instrument2
 	and 3

          
@@ 142,8 160,7 @@ Neotron_Instrument1_Loop:
 	ld d,a
 	ld e,(hl)
 	inc hl
-	call Neotron_WriteRegister1
-	jp Neotron_Process_Loop
+	jp Neotron_WriteRegister1
 Neotron_Instrument2:
 	and 3
 	add a,30H

          
@@ 159,8 176,7 @@ Neotron_Instrument2_Loop:
 	ld d,a
 	ld e,(hl)
 	inc hl
-	call Neotron_WriteRegister2
-	jp Neotron_Process_Loop
+	jp Neotron_WriteRegister2
 
 Neotron_Mute:
 	ld h,Neotron_BASE >> 8

          
@@ 189,6 205,36 @@ Neotron_Mute_KeyOffLoop:
 	ei
 	ret
 
+Neotron_Restore:
+	ld h,Neotron_BASE >> 8
+	call Memory_GetSlot
+	ex af,af'
+	ld a,(Neotron_slot)
+	ld h,Neotron_BASE >> 8
+	call ENASLT
+	ei
+	ld a,0
+	ld hl,Player_instruments
+Neotron_Restore_Loop:
+	ld e,(hl)
+	inc hl
+	ld d,(hl)
+	inc hl
+	push af
+	push hl
+	ex de,hl
+	call Neotron_Instrument_Set
+	pop hl
+	pop af
+	inc a
+	cp 8
+	jr c,Neotron_Restore_Loop
+	ex af,af'
+	ld h,Neotron_BASE >> 8
+	call ENASLT
+	ei
+	ret
+
 ; d = register
 ; e = value
 Neotron_WriteRegister1:

          
M src/Player.asm +31 -5
@@ 10,28 10,35 @@ Player_Detect:
 	call SFG_Detect
 	ld bc,SFG_Process
 	ld de,SFG_Mute
+	ld hl,SFG_Restore
 	jr c,Player_SetProcessAndMute
 	call Makoto_Detect
 	ld bc,Makoto_Process
 	ld de,Makoto_Mute
+	ld hl,Makoto_Restore
 	jr c,Player_SetProcessAndMute
 	call Neotron_Detect
 	ld bc,Neotron_Process
 	ld de,Neotron_Mute
+	ld hl,Neotron_Restore
 	jr c,Player_SetProcessAndMute
 	ld a,0C9H  ; ret
 	ld (Player_Process),a
 	ld (Player_Mute),a
+	ld (Player_Restore),a
 	ret
 
 ; bc = process function
 ; de = mute function
+; hl = restore function
 Player_SetProcessAndMute:
 	ld a,0C3H  ; jp
 	ld (Player_Process),a
 	ld (Player_Process + 1),bc
 	ld (Player_Mute),a
 	ld (Player_Mute + 1),de
+	ld (Player_Restore),a
+	ld (Player_Restore + 1),hl
 	ret
 
 ; hl = sound data

          
@@ 39,33 46,52 @@ Player_Play:
 	ld (Player_position),hl
 	ld a,1
 	ld (Player_wait),a
+	ld (Player_playing),a
 	ret
 
 Player_Stop:
-	ld hl,0
-	ld (Player_position),hl
+	xor a
+	ld (Player_playing),a
 	call Player_Mute
 	ret
 
+Player_Resume:
+	ld a,1
+	ld (Player_playing),a
+	call Player_Restore
+	ret
+
+Player_TogglePause:
+	ld a,(Player_playing)
+	and a
+	jr z,Player_Resume
+	jr Player_Stop
+
 Player_Tick:
+	ld a,(Player_playing)
+	and a
+	ret z
 	ld hl,Player_wait
 	dec (hl)
 	ret nz
 	ld hl,(Player_position)
-	ld a,l
-	or h
-	ret z
 	call Player_Process
 	ld (Player_wait),a
 	ld (Player_position),hl
 	ret
 
 ; Data in RAM
+Player_playing:
+	db 0
 Player_position:
 	dw 0
 Player_wait:
 	db 0
+Player_instruments:
+	ds 8 * 2
 Player_Process:
 	db 0C9H, 0, 0
 Player_Mute:
 	db 0C9H, 0, 0
+Player_Restore:
+	db 0C9H, 0, 0

          
M src/SFG.asm +48 -2
@@ 94,6 94,23 @@ SFG_Frequency:
 ; hl = sound data
 SFG_Instrument:
 	and 7
+	ex de,hl
+	ld c,a
+	ld b,0
+	ld hl,Player_instruments
+	add hl,bc
+	add hl,bc
+	ld (hl),e
+	inc hl
+	ld (hl),d
+	ex de,hl
+	call SFG_Instrument_Set
+	jr SFG_Process_Loop
+
+; a = channel
+; hl = sound data
+; hl <- next sound data
+SFG_Instrument_Set:
 	add a,40H
 	ld b,24
 SFG_Instrument_Loop:

          
@@ 107,8 124,7 @@ SFG_Instrument_Loop:
 	ld d,a
 	ld e,(hl)
 	inc hl
-	call SFG_WriteRegister
-	jr SFG_Process_Loop
+	jp SFG_WriteRegister
 
 SFG_Mute:
 	ld h,SFG_BASE >> 8

          
@@ 136,6 152,36 @@ SFG_Mute_KeyOffLoop:
 	ei
 	ret
 
+SFG_Restore:
+	ld h,SFG_BASE >> 8
+	call Memory_GetSlot
+	ex af,af'
+	ld a,(SFG_slot)
+	ld h,SFG_BASE >> 8
+	call ENASLT
+	ei
+	ld a,0
+	ld hl,Player_instruments
+SFG_Restore_Loop:
+	ld e,(hl)
+	inc hl
+	ld d,(hl)
+	inc hl
+	push af
+	push hl
+	ex de,hl
+	call SFG_Instrument_Set
+	pop hl
+	pop af
+	inc a
+	cp 8
+	jr c,SFG_Restore_Loop
+	ex af,af'
+	ld h,SFG_BASE >> 8
+	call ENASLT
+	ei
+	ret
+
 ; d = register
 ; e = value
 SFG_WriteRegister: