Skip to content

Commit

Permalink
refs ignore シーク処理改善
Browse files Browse the repository at this point in the history
* 通常シーク処理の最適化
* タイムゲージの反応位置を調整
  • Loading branch information
dgrfactory committed Oct 15, 2023
1 parent 1e96d46 commit da91927
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 65 deletions.
35 changes: 31 additions & 4 deletions snesapu.dll/APU.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
; Copyright (C) 2003-2023 degrade-factory
;
;List of users and dates who/when modified this file:
; - degrade-factory in 2023-10-01
; - degrade-factory in 2023-10-15
;===================================================================================================

CPU 386
Expand Down Expand Up @@ -720,7 +720,7 @@ USES ECX,EDX
RetZF
Mov ECX,64000
Div ECX
Mov ECX,EAX
Mov ECX,EAX ;ECX = time / 64000
IMul EDX,APU_CLK/64000 ;EDX = (time % 64000) * (APU_CLK / 64000)

Test byte [fast],-1 ;Fast mode completely bypasses the DSP emulation
Expand All @@ -741,21 +741,48 @@ USES ECX,EDX

.DoneSeek:
Call SetSPCDbg,-1,0 ;Re-enable writes to the DSP registers
Jmp short .Done
Jmp .Done

.Slow:
Mov EAX,[dspOpts]
Push EAX ;Save APU options
Or EAX,DSP_ENVSPD+DSP_NOSAFE
Call SetAPUOpt,-1,-1,-1,-1,-1,EAX
Mov EAX,[smpRAdj]
Push EAX ;Save APU speed

Push EDI
Mov EAX,EDI
ShR EAX,16
JNZ short .MinSpeed ;When APU speed is less than 100%, temporarily increase
Mov EDI,10000h ; it to 100% to speed up processing

.MinSpeed:
Test EDX,EDX
JZ short .EmuAPU

Call SetAPUSmpClk,EDI
Call EmuAPU,0,EDX,0
Test ECX,ECX
JZ short .Done
JZ short .DoneSlow

.EmuAPU:
XOr EAX,EAX
Test ECX,ECX
SetZ AL
Dec EAX
Or EAX,EDI
Call SetAPUSmpClk,EAX
Call EmuAPU,0,APU_CLK,0
Dec ECX
JNZ short .EmuAPU

.DoneSlow:
Pop EDI,EAX
Call SetAPUSmpClk,EAX ;Restore APU speed
Pop EAX
Call SetAPUOpt,-1,-1,-1,-1,-1,EAX ;Restore APU options

.Done:
Call FixSeek,[fast] ;Fixup DSP after seeking

Expand Down
35 changes: 17 additions & 18 deletions snesapu.dll/DSP.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
; Copyright (C) 2003-2023 degrade-factory
;
;List of users and dates who/when modified this file:
; - degrade-factory in 2023-10-01
; - degrade-factory in 2023-10-15
;===================================================================================================

CPU 386
Expand Down Expand Up @@ -902,7 +902,7 @@ USES ECX,EBX,EDI

.ClrMix:
Mov BL,[EDI+mFlg]
And BL,MFLG_USER ;Leave voice muted, noise
And BL,MFLG_USER ;Leave user voice flags (mute and noise)
Or BL,MFLG_OFF ;Set voice to inactive

Mov CL,32
Expand Down Expand Up @@ -1566,7 +1566,7 @@ USES ECX,EDI
.ResetMix:
Mov [EDI+eVal],EAX
Mov [EDI+mOut],EAX
And byte [EDI+mFlg],MFLG_USER ;Leave voice muted, noise
And byte [EDI+mFlg],MFLG_USER ;Leave user voice flags (mute and noise)
Or byte [EDI+mFlg],MFLG_OFF ;Set voice to inactive
Sub EDI,-80h

Expand Down Expand Up @@ -2033,12 +2033,14 @@ PROC StartEnv
USES ESI

XOr EAX,EAX
; Mov [EBX+eVal],EAX ;Envelope starts at 0
Mov [EBX+eVal],EAX ;Envelope starts at 0
Mov [EBX+mOut],EAX
Mov [EBX+eRIdx],AL ;Reset envelope counter
Mov EDX,[rateTab]
Mov [EBX+eRate],EDX ;Reset rate of adjustment
Mov [EBX+eCnt],EDX
; Mov [ESI+envx],AL ;Reset envelope height
Mov [ESI+envx],AL ;Reset envelope height
Mov [ESI+outx],AL
Mov byte [EBX+eMode],E_ATT << 4 ;If envelope gets switched out of gain mode, start ADSR

Test byte [ESI+adsr],80h ;Is the envelope in ADSR mode?
Expand Down Expand Up @@ -2496,19 +2498,17 @@ ENDP
JZ %%Skip

XOr EDX,EDX
And byte [EBX+mFlg],MFLG_USER ;Leave voice muted, noise
And byte [EBX+mFlg],MFLG_USER ;Leave user voice flags (mute and noise)
Mov byte [EBX+mKOn],KON_DELAY ;Set delay time from writing KON to output
Mov [EBX+eVal],EDX ;Reset envelope and wave height
Mov [EBX+mOut],EDX
Mov [ESI+envx],DL
Mov [EBX+eVal],EDX ;Reset envelope and wave height, because noise may be
Mov [EBX+mOut],EDX ; mixed in when the channel volume is changed immediately
Mov [ESI+envx],DL ; after KON.
Mov [ESI+outx],DL

Or [konRun],CH ;Start KON working

Not CH
And [dsp+endx],CH ;Clear ENDX register if started KON
Not CH

Jmp %%Skip

%%CheckKOff:
Expand All @@ -2526,7 +2526,6 @@ ENDP
Not CH
And [konRun],CH ;Cancel KON working
Not CH

Jmp %%Skip

%%CheckEnv:
Expand All @@ -2541,7 +2540,7 @@ ENDP
%%StartKON:
Dec byte [EBX+mKOn] ;Did time for enabled voice pass after KON had been
JNZ %%Skip ; written? No, do nothing
And byte [EBX+mFlg],MFLG_USER ;Leave voice muted, noise
And byte [EBX+mFlg],MFLG_USER ;Leave user voice flags (mute and noise)

;Set voice volume ------------------
%if STEREO
Expand Down Expand Up @@ -2594,8 +2593,8 @@ ENDP
Pop EDX,EAX ;Restore ADSR/Gain parameters
Mov [ESI+adsr],AX
Mov [ESI+gain],DL
Or [voiceMix],CH ;Mark voice as being on internally

Or [voiceMix],CH ;Mark voice as being on internally
Not CH
And [konRun],CH ;KON working was finished
Not CH
Expand Down Expand Up @@ -3063,7 +3062,7 @@ RFlg:
Mov AL,8

.MFlg:
And byte [EBX],MFLG_USER ;Leave voice muted, noise
And byte [EBX],MFLG_USER ;Leave user voice flags (mute and noise)
Or byte [EBX],MFLG_OFF ;Set voice to inactive
Sub EBX,-80h

Expand Down Expand Up @@ -3325,6 +3324,7 @@ ENDP
Not CH
And [voiceMix],CH ;Don't include voice in mixing process
Not CH

Mov dword [EBX+eVal],0 ;Reset envelope and wave height
Mov dword [EBX+mOut],0
Or byte [EBX+mFlg],MFLG_OFF ;Set voice to inactive
Expand Down Expand Up @@ -3493,8 +3493,7 @@ ENDP
Test byte [ESI+adsr],80h ;Is envelope flag in ADSR?
JZ %%EnvDone ; No

Mov byte [EBX+vRsv],0

Mov [EBX+vRsv],AL ;Reset ADSR/Gain changed flag
Test CL,E_DEST ;Switch to next mode
JNZ short %%EnvSust

Expand Down Expand Up @@ -4772,13 +4771,13 @@ ENDP
%endmacro

%macro InitSampling 0
XOr EBX,EBX
XOr EDX,EDX

Mov EAX,[smpCnt] ;smpCnt = (smpCnt + smpDec) % smpRate
Add EAX,[smpDec]
Cmp EAX,[smpRate]
SetB BL
MovZX EBX,BL
Dec EBX
And EBX,[smpRate]
Sub EAX,EBX ;If the number of times is the least common multiple of
Expand Down
89 changes: 46 additions & 43 deletions spcplay.exe/spcplay.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,8 @@ const
WM_APP_EMU_APU = $FFFE0000; // �����G�~�����[�g ($FFFE????)
WM_APP_EMU_DEBUG = $FFFF0000; // SPC700 �]���e�X�g ($FFFF???X, X:Flag)

DRAW_INFO_ALWAYS = $1; // ��ɕ`��

FILE_TYPE_NOTEXIST = $1; // ���݂��Ȃ�
FILE_TYPE_NOTREAD = $2; // �ǂݍ��ݕs��
FILE_TYPE_UNKNOWN = $3; // �s���Ȍ`��
Expand All @@ -2562,9 +2564,12 @@ const
FILE_TYPE_FOLDER = $13; // �t�H���_
FILE_TYPE_SCRIPT700 = $14; // Script700

STATUS_OPEN = $1; // Open �t���O
STATUS_PLAY = $2; // Play �t���O
STATUS_PAUSE = $4; // Pause �t���O
FUNCTION_TYPE_SEPARATE = $1; // ���E�g�U�x
FUNCTION_TYPE_FEEDBACK = $2; // �t�B�[�h�o�b�N���]�x
FUNCTION_TYPE_SPEED = $3; // ���t���x
FUNCTION_TYPE_AMP = $4; // ����
FUNCTION_TYPE_SEEK = $5; // �V�[�N
FUNCTION_TYPE_NO_TIMER = $80000000; // �^�C�}�[�ݒ�Ȃ�

ID666_UNKNOWN = $0; // �s��
ID666_TEXT = $1; // ID666 �e�L�X�g�t�H�[�}�b�g
Expand All @@ -2580,6 +2585,11 @@ const
INFO_SPC_2 = $7; // SPC ��� 2
INFO_SCRIPT700 = $8; // Script700 �f�o�b�O

LIST_PLAY_INDEX_SELECTED = -1; // �v���C���X�g�I���ς݃A�C�e��
LIST_PLAY_INDEX_RANDOM = -2; // �v���C���X�g���烉���_���I��
LIST_NEXT_PLAY_SELECT = $10000; // �v���C���X�g����A�C�e���I��
LIST_NEXT_PLAY_CENTER = $20000; // �v���C���X�g�����I��

PLAY_TYPE_AUTO = $0; // ���t�����I��
PLAY_TYPE_PLAY = $1; // ���t�J�n
PLAY_TYPE_PAUSE = $2; // �ꎞ��~
Expand All @@ -2599,31 +2609,21 @@ const
PLAY_ORDER_FIRST = $6; // �ŏ�����
PLAY_ORDER_LAST = $7; // �Ōォ��

FUNCTION_TYPE_SEPARATE = $1; // ���E�g�U�x
FUNCTION_TYPE_FEEDBACK = $2; // �t�B�[�h�o�b�N���]�x
FUNCTION_TYPE_SPEED = $3; // ���t���x
FUNCTION_TYPE_AMP = $4; // ����
FUNCTION_TYPE_SEEK = $5; // �V�[�N
FUNCTION_TYPE_NO_TIMER = $80000000; // �^�C�}�[�ݒ�Ȃ�

LIST_PLAY_INDEX_SELECTED = -1; // �v���C���X�g�I���ς݃A�C�e��
LIST_PLAY_INDEX_RANDOM = -2; // �v���C���X�g���烉���_���I��
LIST_NEXT_PLAY_SELECT = $10000; // �v���C���X�g����A�C�e���I��
LIST_NEXT_PLAY_CENTER = $20000; // �v���C���X�g�����I��

READY_INITIALIZE = $0; // ��������
READY_ACTIVE = $1; // ���s��
READY_INACTIVE = $2; // �\����~��

TITLE_HIDE = $0; // ��\��
TITLE_NORMAL = $100; // �W��
TITLE_MINIMIZE = $200; // �ŏ���
TITLE_ALWAYS_FLAG = $FF00; // �W�� + �ŏ���
TITLE_INFO_SEPARATE = $1; // ���E�g�U�x
TITLE_INFO_FEEDBACK = $2; // �t�B�[�h�o�b�N���]�x
TITLE_INFO_SPEED = $3; // ���t���x
TITLE_INFO_AMP = $4; // ����
TITLE_INFO_SEEK = $5; // �V�[�N
REDRAW_OFF = $0; // �ĕ`��Ȃ�
REDRAW_LOCK_CRITICAL = $1; // �`�惍�b�N (����)
REDRAW_LOCK_READY = $2; // �`�惍�b�N (����`�拖��)
REDRAW_ON = $4; // �ĕ`�悠��

STATIC_SEEKBAR_TOP = 24; // �V�[�N�o�[���o�ʒu (��)
STATIC_SEEKBAR_BOTTOM = 35; // �V�[�N�o�[���o�ʒu (��)

STATUS_OPEN = $1; // Open �t���O
STATUS_PLAY = $2; // Play �t���O
STATUS_PAUSE = $4; // Pause �t���O

TIMER_ID_READY = $1; // ��������
TIMER_ID_OPTION_DISPLAY = $2; // �I�v�V�������\��
Expand All @@ -2634,12 +2634,27 @@ const
TIMER_INTERVAL_OPTION_LOCK = 300; // �I�v�V�����ύX���b�N�̎���
TIMER_INTERVAL_REDRAW_RESUME = 1000; // �T�X�y���h���A��̃E�B���h�E�ĕ`��̎���

REDRAW_OFF = $0; // �ĕ`��Ȃ�
REDRAW_LOCK_CRITICAL = $1; // �`�惍�b�N (����)
REDRAW_LOCK_READY = $2; // �`�惍�b�N (����`�拖��)
REDRAW_ON = $4; // �ĕ`�悠��
TITLE_HIDE = $0; // ��\��
TITLE_NORMAL = $100; // �W��
TITLE_MINIMIZE = $200; // �ŏ���
TITLE_ALWAYS_FLAG = $FF00; // �W�� + �ŏ���
TITLE_INFO_SEPARATE = $1; // ���E�g�U�x
TITLE_INFO_FEEDBACK = $2; // �t�B�[�h�o�b�N���]�x
TITLE_INFO_SPEED = $3; // ���t���x
TITLE_INFO_AMP = $4; // ����
TITLE_INFO_SEEK = $5; // �V�[�N

DRAW_INFO_ALWAYS = $1; // ��ɕ`��
WAVE_DEVICE_SET_ONLY = $0; // �f�o�C�X ID �I���̂�
WAVE_DEVICE_UPDATE_LIST = $1; // �f�o�C�X�ꗗ���X�V
WAVE_DEVICE_UPDATE_SELECT = $2; // �I���f�o�C�X���X�V
WAVE_DEVICE_INITIALIZE = $3; // ������

WAVE_FORMAT_TYPE_SIZE = 2;
WAVE_FORMAT_TYPE_ARRAY: array[0..WAVE_FORMAT_TYPE_SIZE - 1] of longword = (WAVE_FORMAT_DIRECT, NULL);
WAVE_FORMAT_TAG_SIZE = 2;
WAVE_FORMAT_TAG_ARRAY: array[0..WAVE_FORMAT_TAG_SIZE - 1] of word = (WAVE_FORMAT_EXTENSIBLE, WAVE_FORMAT_PCM);
WAVE_FORMAT_INDEX_EXTENSIBLE = 0;
WAVE_FORMAT_INDEX_PCM = 1;

WAVE_PROC_GRAPH_ONLY = $0; // �C���W�P�[�^�̂ݕ`��
WAVE_PROC_NO_GRAPH = $FFFF; // �C���W�P�[�^��`�悵�Ȃ�
Expand All @@ -2653,18 +2668,6 @@ const
WAVE_THREAD_DEVICE_OPENED = $2; // �f�o�C�X�̃I�[�v������
WAVE_THREAD_DEVICE_CLOSED = $4; // �f�o�C�X�̃N���[�Y����

WAVE_DEVICE_SET_ONLY = $0; // �f�o�C�X ID �I���̂�
WAVE_DEVICE_UPDATE_LIST = $1; // �f�o�C�X�ꗗ���X�V
WAVE_DEVICE_UPDATE_SELECT = $2; // �I���f�o�C�X���X�V
WAVE_DEVICE_INITIALIZE = $3; // ������

WAVE_FORMAT_TYPE_SIZE = 2;
WAVE_FORMAT_TYPE_ARRAY: array[0..WAVE_FORMAT_TYPE_SIZE - 1] of longword = (WAVE_FORMAT_DIRECT, NULL);
WAVE_FORMAT_TAG_SIZE = 2;
WAVE_FORMAT_TAG_ARRAY: array[0..WAVE_FORMAT_TAG_SIZE - 1] of word = (WAVE_FORMAT_EXTENSIBLE, WAVE_FORMAT_PCM);
WAVE_FORMAT_INDEX_EXTENSIBLE = 0;
WAVE_FORMAT_INDEX_PCM = 1;

COLOR_BAR_NUM = 6; // �C���W�P�[�^�o�[�̐�
COLOR_BAR_NUM_X3 = 18;
COLOR_BAR_NUM_X7 = 42;
Expand Down Expand Up @@ -10534,7 +10537,7 @@ begin
Y := Trunc(longint(Y shl 1) / Status.dwScale);
end;
// �V�[�N�o�[��Ń_�u���N���b�N���ꂽ�ꍇ�͏I��
if not ((X < 140) or (X > 280) or (Y < 27) or (Y >= 32)) then begin
if not ((X < 140) or (X > 280) or (Y < STATIC_SEEKBAR_TOP) or (Y >= STATIC_SEEKBAR_BOTTOM)) then begin
if longbool(Option.dwSeekBar) or (Option.dwPlayMax > PLAY_MAX_ENDLESS) then exit;
end;
// ���\���ؑ�
Expand Down Expand Up @@ -10649,7 +10652,7 @@ begin
Y := Trunc(longint(Y shl 1) / Status.dwScale);
end;
// �N���b�N�ʒu���͈͊O�̏ꍇ�͏I��
if (X < 140) or (X > 280) or (Y < 27) or (Y >= 32) then exit;
if (X < 140) or (X > 280) or (Y < STATIC_SEEKBAR_TOP) or (Y >= STATIC_SEEKBAR_BOTTOM) then exit;
// �N���b�N�ʒu�̊������擾
Y := Trunc((X - 139) / 141 * Status.dwDefaultTimeout) + 1;
if X = 140 then X := 0 else X := Trunc((X - 140) / 141 * Status.dwDefaultTimeout) + 1;
Expand Down

0 comments on commit da91927

Please sign in to comment.