Synchronize OPL4 track finalization

This commit is contained in:
2026-09-15 18:00:52 +03:00
parent 3ef0b1dc95
commit ffee082140
6 changed files with 41 additions and 33 deletions
+15 -19
View File
@@ -29,6 +29,7 @@
.globl _isr_play_seconds
.globl _isr_read_ptr
.globl _isr_done
.globl _isr_final_pending
.globl _cmd_buf_a
.globl _cmd_buf_b
.globl _isr_init
@@ -56,7 +57,7 @@ WC_IM2_VEC = 0x5BFF
CMD_WRITE_AY = 0x00
CMD_INC_SEC = 0x10
CMD_WRITE_AY2 = 0x20
CMD_CALL_WC = 0x30
CMD_FINALIZE = 0x30
CMD_WRITE_B0 = 0x40
CMD_SKIP_TICKS= 0x50
CMD_WRITE_SAA = 0x60
@@ -301,8 +302,8 @@ _isr_cmd_loop:
jp z, _isr_cmd_done
cp #CMD_INC_SEC
jp z, _isr_inc_sec
cp #CMD_CALL_WC
jp z, _isr_call_wc
cp #CMD_FINALIZE
jp z, _isr_cmd_finalize
; Unknown command: skip 3 bytes, continue
inc de
inc de
@@ -589,29 +590,23 @@ _skip_spec_next:
; ISR зацикливается на этой команде, не переключает буферы.
; Main loop ждёт isr_done == 1 перед завершением.
_isr_cmd_done:
inc de
inc de
inc de ; пропустить 3 байта параметров
; Выставить флаг готовности к завершению
ld a, #1
ld (_isr_done), a
; Перемотать read_ptr на начало CMD_ISR_DONE (DE - 4)
jr _isr_cmd_freeze
;--- CMD_FINALIZE: музыкальный поток полностью исполнен -----------------
; Замереть на маркере и попросить main собрать shutdown как при ESC.
_isr_cmd_finalize:
ld a, #1
ld (_isr_final_pending), a
_isr_cmd_freeze:
; DE уже указывает на первый параметр: вернуть read_ptr на opcode.
ex de, hl
dec hl
dec hl
dec hl
dec hl
ld (_isr_read_ptr), hl
jp _isr_exit
;--- CMD_CALL_WC: вызов оригинального WC handler [0,0,0] ------------------
; Внутренняя команда ISR (не используется buffer filler, зарезервировано)
_isr_call_wc:
inc de
inc de
inc de ; пропустить 3 байта параметров
jp _isr_cmd_loop ; просто пропустить
;==============================================================================
; call_wc_handler() — Вызов WC ISR из main loop (C-callable)
;
@@ -641,6 +636,7 @@ _isr_play_seconds:: .dw 0 ; инкрементируется CMD_INC_SE
_isr_read_ptr:: .dw 0
_isr_wait_ctr:: .dw 0
_isr_done:: .db 0 ; 1 = ISR замер на CMD_ISR_DONE, готов к завершению
_isr_final_pending:: .db 0 ; 1 = последний VGM 0x66 уже исполнен
_pos_ptr: .dw 0 ; инициализируется в isr_init()
_isr_saved_vec: .dw 0 ; сохранённый вектор WC (#5BFF)