bug fixes in drc, audio, display

This commit is contained in:
kub 2020-01-14 22:49:03 +01:00
parent 8ac9ab7fcb
commit b9bc876c9c
14 changed files with 130 additions and 93 deletions

View file

@ -580,7 +580,6 @@ void PicoFrame32x(void)
PicoFrameStart();
PicoFrameHints();
sh2_drc_frame();
elprintf(EL_32X, "poll: %02x %02x %02x",
Pico32x.emu_flags & 3, msh2.state, ssh2.state);

View file

@ -137,11 +137,15 @@ static void dmac_memcpy(struct dma_chan *chan, SH2 *sh2)
if (!up || chan->tcr < 4)
return;
// XXX Mars Check Program fills a 64K buffer, then copies 32K longwords from
// DRAM to SDRAM in 4-longword mode, which is 128K. This overwrites a comm
// area in SDRAM, which is why the check fails.
// Is this a buswidth mismatch problem? As a kludge, usw 16-bit width xfers
if (size == 3 && (chan->sar & 0xdf000000) == 0x04000000) size = 1;
#if MARS_CHECK_HACK
// XXX Mars Check Program copies 32K longwords (128KB) from a 64KB buffer in
// ROM or DRAM to SDRAM in 4-longword mode, overwriting an SDRAM comm area in
// turn, which crashes the test on emulators without CPU cache emulation.
// This may be a bug in Mars Check. As a kludge limit the transfer to 64KB,
// which is what the check program test uses for checking the result.
// A better way would clearly be to have a mechanism to patch the ROM...
if (size == 3 && chan->tcr == 32768 && chan->dar == 0x06020000) size = 1;
#endif
if (size == 3) size = 2; // 4-word xfer mode still counts in words
// XXX check TCR being a multiple of 4 in 4-word xfer mode?
// XXX check alignment of sar/dar, generating a bus error if unaligned?

View file

@ -157,6 +157,8 @@ static void DrawWindowFull(int start, int end, int prio, struct PicoEState *est)
{
nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
nametab_step = 1<<5;
if (!(PicoIn.opt&POPT_DIS_32C_BORDER))
scrpos += 32;
}
nametab += nametab_step*start;
@ -240,6 +242,8 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend,
else nametab=(pvid->reg[4]&0x07)<<12; // B
scrpos = est->Draw2FB;
if (!(pvid->reg[12]&1) && !(PicoIn.opt&POPT_DIS_32C_BORDER))
scrpos += 32;
scrpos+=8*LINE_WIDTH*(planestart-START_ROW);
// Get vertical scroll value:
@ -315,6 +319,8 @@ static void DrawTilesFromCacheF(int *hc, struct PicoEState *est)
short blank=-1; // The tile we know is blank
unsigned char *scrpos = est->Draw2FB, *pd = 0;
if (!(Pico.video.reg[12]&1) && !(PicoIn.opt&POPT_DIS_32C_BORDER))
scrpos += 32;
// *hcache++ = code|(dx<<16)|(trow<<27); // cache it
scrpos+=(*hc++)*LINE_WIDTH - START_ROW*LINE_WIDTH*8;
@ -377,6 +383,8 @@ static void DrawSpriteFull(unsigned int *sprite, struct PicoEState *est)
while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; }
scrpos = est->Draw2FB;
if (!(Pico.video.reg[12]&1) && !(PicoIn.opt&POPT_DIS_32C_BORDER))
scrpos += 32;
scrpos+=(sy-START_ROW*8)*LINE_WIDTH;
for (; height > 0; height--, sy+=8, tile+=tdeltay)
@ -502,6 +510,11 @@ static void DrawDisplayFull(void)
maxw = 264; maxcolc = 32;
}
// 32C border for centering? (for asm)
est->rendstatus &= ~PDRAW_BORDER_32;
if ((est->rendstatus&PDRAW_32_COLS) && !(PicoIn.opt&POPT_DIS_32C_BORDER))
est->rendstatus |= PDRAW_BORDER_32;
// horizontal window?
if ((win=pvid->reg[0x12]))
{

View file

@ -414,7 +414,10 @@ DrawLayerFull:
ldr r11,[sp, #9*4] @ est
sub r4, r9, #(START_ROW<<24)
ldr r7, [r11, #OFS_EST_rendstatus]
ldr r11, [r11, #OFS_EST_Draw2FB]
tst r7, #0x100 @ H32 border mode?
addne r11, r11, #32
mov r4, r4, asr #24
mov r7, #328*8
mla r11, r4, r7, r11 @ scrpos+=8*328*(planestart-START_ROW);
@ -590,8 +593,11 @@ DrawTilesFromCacheF:
mov r9, #0xff000000 @ r9=prevcode=-1
mvn r6, #0 @ r6=prevy=-1
ldr r7, [r1, #OFS_EST_rendstatus]
ldr r4, [r1, #OFS_EST_Draw2FB]
ldr r2, [r0], #4 @ read y offset
tst r7, #0x100 @ H32 border mode?
addne r4, r4, #32
mov r7, #328
mla r2, r7, r2, r4
sub r12, r2, #(328*8*START_ROW) @ r12=scrpos
@ -688,13 +694,18 @@ DrawWindowFull:
ldr r4, [r11, #OFS_Pico_video_reg+12]
mov r5, #1 @ nametab_step
ldr r11, [r3, #OFS_EST_Draw2FB]
tst r4, #1 @ 40 cell mode?
andne r12, r12, #0xf000 @ 0x3c<<10
andeq r12, r12, #0xf800
movne r5, r5, lsl #7
moveq r5, r5, lsl #6 @ nametab_step
bne 0f
ldr r7, [r3, #OFS_EST_rendstatus]
and r12, r12, #0xf800
mov r5, r5, lsl #6 @ nametab_step
tst r7, #0x100
addne r11, r11, #32 @ center screen in H32 mode
and r4, r0, #0xff
0: and r4, r0, #0xff
mla r12, r5, r4, r12 @ nametab += nametab_step*start;
ldr r10, [r3, #OFS_EST_PicoMem_vram]
@ -715,7 +726,6 @@ DrawWindowFull:
mov r9, #0xff000000 @ r9=prevcode=-1
ldr r11, [r3, #OFS_EST_Draw2FB]
and r4, r0, #0xff
add r11, r11, #328*8
sub r4, r4, #START_ROW
@ -915,8 +925,11 @@ DrawSpriteFull:
and r3, lr, #0x6000
mov r3, r3, lsr #9 @ r3=pal=((code>>9)&0x30);
ldr r0, [r1, #OFS_EST_rendstatus]
ldr r11, [r1, #OFS_EST_Draw2FB]
ldr r10, [r1, #OFS_EST_PicoMem_vram]
tst r0, #0x100 @ H32 border mode?
addne r11, r11, #32
sub r1, r12, #(START_ROW*8)
mov r0, #328
mla r11, r1, r0, r11 @ scrpos+=(sy-START_ROW*8)*328;

View file

@ -204,6 +204,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est);
#define PDRAW_PLANE_HI_PRIO (1<<6) // have layer with all hi prio tiles (mk3)
#define PDRAW_SHHI_DONE (1<<7) // layer sh/hi already processed
#define PDRAW_32_COLS (1<<8) // 32 column mode
#define PDRAW_BORDER_32 (1<<9) // center H32 in buffer (32 px border)
extern int rendstatus_old;
extern int rendlines;

View file

@ -176,10 +176,10 @@ m16_32_s2_no_unal2:
@ filter out DC offset
@ in=int_sample (max 20 bit), y=filter memory, r3=tmp
.macro DCfilt in y
rsb r3, \y, \in, asl #12 @ fixpoint 20.12
rsb r3, \y, \in, lsl #12 @ fixpoint 20.12
add \y, \y, r3, asr #13
sub \in, \in, \y, asr #12
sub \in, \in, \in, asr #2 @ reduce audio lvl some
sub r3, r3, r3, asr #2 @ reduce audio lvl some
asr \in, r3, #12
.endm
@ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio with left channel only

View file

@ -38,7 +38,7 @@ static void dac_recalculate(void)
for(i = 0; i <= lines; i++)
{
dac_info[i] = ((pos+(1<<15)) >> 16); // round to nearest
dac_info[i] = ((pos+0x8000) >> 16); // round to nearest
pos += Pico.snd.fm_mult;
}
for (i = lines+1; i < sizeof(dac_info) / sizeof(dac_info[0]); i++)
@ -85,10 +85,10 @@ void PsndRerate(int preserve_state)
// calculate Pico.snd.len
Pico.snd.len = PicoIn.sndRate / target_fps;
Pico.snd.len_e_add = ((PicoIn.sndRate - Pico.snd.len * target_fps) << 16) / target_fps;
Pico.snd.len_e_cnt = 0;
Pico.snd.len_e_cnt = 0; // Q16
// samples per line
Pico.snd.fm_mult = 65536.0 * PicoIn.sndRate / (target_fps*target_lines);
// samples per line (Q16)
Pico.snd.fm_mult = 65536LL * PicoIn.sndRate / (target_fps*target_lines);
// recalculate dac info
dac_recalculate();
@ -176,7 +176,7 @@ PICO_INTERNAL void PsndDoFM(int line_to)
int pos, len;
int stereo = 0;
// Q16, number of samples to fill in buffer
// Q16, number of samples since last call
len = ((line_to-1) * Pico.snd.fm_mult) - Pico.snd.fm_pos;
// don't do this too often (no more than 256 per sec)
@ -184,9 +184,9 @@ PICO_INTERNAL void PsndDoFM(int line_to)
return;
// update position and calculate buffer offset and length
pos = Pico.snd.fm_pos >> 16;
pos = (Pico.snd.fm_pos+0x8000) >> 16;
Pico.snd.fm_pos += len;
len = (Pico.snd.fm_pos >> 16) - pos;
len = ((Pico.snd.fm_pos+0x8000) >> 16) - pos;
// fill buffer
if (PicoIn.opt & POPT_EN_STEREO) {
@ -195,8 +195,6 @@ PICO_INTERNAL void PsndDoFM(int line_to)
}
if (PicoIn.opt & POPT_EN_FM)
YM2612UpdateOne(PsndBuffer + pos, len, stereo, 1);
else
memset32(PsndBuffer + pos, 0, len<<stereo);
}
// cdda
@ -258,6 +256,8 @@ PICO_INTERNAL void PsndClear(void)
memset32((int *) out, 0, len/2);
if (len & 1) out[len-1] = 0;
}
if (!(PicoIn.opt & POPT_EN_FM))
memset32(PsndBuffer, 0, PicoIn.opt & POPT_EN_STEREO ? len*2 : len);
}
@ -265,7 +265,7 @@ static int PsndRender(int offset, int length)
{
int *buf32;
int stereo = (PicoIn.opt & 8) >> 3;
int fmlen = (Pico.snd.fm_pos >> 16) - offset;
int fmlen = ((Pico.snd.fm_pos+0x8000) >> 16) - offset;
offset <<= stereo;
buf32 = PsndBuffer+offset;
@ -282,15 +282,11 @@ static int PsndRender(int offset, int length)
int *fmbuf = buf32 + (fmlen << stereo);
if (PicoIn.opt & POPT_EN_FM)
YM2612UpdateOne(fmbuf, length-fmlen, stereo, 1);
else
memset32(fmbuf, 0, (length-fmlen)<<stereo);
Pico.snd.fm_pos += (length-fmlen)<<16;
}
// CD: PCM sound
if (PicoIn.AHW & PAHW_MCD) {
pcd_pcm_update(buf32, length, stereo);
//buf32_updated = 1;
}
// CD: CDDA audio

View file

@ -564,7 +564,7 @@ INLINE void FM_KEYON(int c , int s )
SLOT->ssg ^= SLOT->ssgn;
SLOT->ssgn = 0;
SLOT->state = (SLOT->sl == MIN_ATT_INDEX) ? EG_SUS : EG_DEC;
if (SLOT->ar + SLOT->ksr < 32+62) {
if (SLOT->ar_ksr < 32+62) {
if (SLOT->volume > MIN_ATT_INDEX) SLOT->state = EG_ATT;
} else {
SLOT->volume = MIN_ATT_INDEX;
@ -619,6 +619,7 @@ INLINE void set_ar_ksr(FM_CH *CH, FM_SLOT *SLOT, int v)
int eg_sh_ar, eg_sel_ar;
SLOT->ar = (v&0x1f) ? 32 + ((v&0x1f)<<1) : 0;
SLOT->ar_ksr = SLOT->ar + SLOT->ksr;
SLOT->KSR = 3-(v>>6);
if (SLOT->KSR != old_KSR)
@ -627,10 +628,10 @@ INLINE void set_ar_ksr(FM_CH *CH, FM_SLOT *SLOT, int v)
}
/* refresh Attack rate */
if ((SLOT->ar + SLOT->ksr) < 32+62)
if ((SLOT->ar_ksr) < 32+62)
{
eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ];
eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ];
eg_sh_ar = eg_rate_shift [SLOT->ar_ksr];
eg_sel_ar = eg_rate_select[SLOT->ar_ksr];
}
else
{
@ -872,7 +873,7 @@ INLINE void update_ssg_eg_phase(FM_SLOT *SLOT)
if (SLOT->state != EG_ATT) {
SLOT->state = (SLOT->sl == MIN_ATT_INDEX) ? EG_SUS : EG_DEC;
if (SLOT->ar + SLOT->ksr < 32+62) {
if (SLOT->ar_ksr < 32+62) {
if (SLOT->volume > MIN_ATT_INDEX) SLOT->state = EG_ATT;
} else {
SLOT->volume = MIN_ATT_INDEX;
@ -972,7 +973,7 @@ static void chan_render_loop(chan_rend_context *ct, int *buffer, int length)
ct->vol_out3 = (SLOT->vol_ipol*ifrac1 + SLOT->vol_out*ifrac0) >> EG_SH;
SLOT = &ct->CH->SLOT[SLOT4];
ct->vol_out4 = (SLOT->vol_ipol*ifrac1 + SLOT->vol_out*ifrac0) >> EG_SH;
#else
#elif 1
switch (ct->eg_timer >> EG_SH)
{
case 0:
@ -997,6 +998,23 @@ static void chan_render_loop(chan_rend_context *ct, int *buffer, int length)
ct->vol_out4 = (ct->CH->SLOT[SLOT4].vol_ipol +
ct->CH->SLOT[SLOT4].vol_out) >> 1;
}
#elif 0
if (ct->eg_timer >> (EG_SH-1) < EG_TIMER_OVERFLOW >> EG_SH) {
ct->vol_out1 = ct->CH->SLOT[SLOT1].vol_ipol;
ct->vol_out2 = ct->CH->SLOT[SLOT2].vol_ipol;
ct->vol_out3 = ct->CH->SLOT[SLOT3].vol_ipol;
ct->vol_out4 = ct->CH->SLOT[SLOT4].vol_ipol;
} else {
ct->vol_out1 = ct->CH->SLOT[SLOT1].vol_out;
ct->vol_out2 = ct->CH->SLOT[SLOT2].vol_out;
ct->vol_out3 = ct->CH->SLOT[SLOT3].vol_out;
ct->vol_out4 = ct->CH->SLOT[SLOT4].vol_out;
}
#else
ct->vol_out1 = ct->CH->SLOT[SLOT1].vol_out;
ct->vol_out2 = ct->CH->SLOT[SLOT2].vol_out;
ct->vol_out3 = ct->CH->SLOT[SLOT3].vol_out;
ct->vol_out4 = ct->CH->SLOT[SLOT4].vol_out;
#endif
if (ct->pack & 4) continue; /* output disabled */
@ -1335,12 +1353,13 @@ INLINE void refresh_fc_eg_slot(FM_SLOT *SLOT, int fc, int kc)
{
int eg_sh, eg_sel;
SLOT->ksr = ksr;
SLOT->ar_ksr = SLOT->ar + ksr;
/* calculate envelope generator rates */
if ((SLOT->ar + ksr) < 32+62)
if ((SLOT->ar_ksr) < 32+62)
{
eg_sh = eg_rate_shift [SLOT->ar + ksr ];
eg_sel = eg_rate_select[SLOT->ar + ksr ];
eg_sh = eg_rate_shift [SLOT->ar_ksr];
eg_sel = eg_rate_select[SLOT->ar_ksr];
}
else
{

View file

@ -56,8 +56,9 @@ typedef struct
UINT8 ssg; /* 0x30 SSG-EG waveform */
UINT8 ssgn;
UINT16 vol_out; /* 0x32 current output from EG (without LFO) */
UINT16 vol_ipol; /* 0x34 interpolator memory */
UINT16 ar_ksr; /* 0x32 ar+ksr */
UINT16 vol_out; /* 0x34 current output from EG (without LFO) */
UINT16 vol_ipol; /* 0x36 interpolator memory */
} FM_SLOT;

View file

@ -42,10 +42,10 @@
@ r5=slot, r1=eg_cnt, trashes: r0,r2,r3
@ writes output to routp, but only if vol_out changes
.macro update_eg_phase_slot slot
ldrh r0, [r5,#0x32] @ vol_out
ldrh r0, [r5,#0x34] @ vol_out
ldrb r2, [r5,#0x17] @ state
add r3, r5, #0x1c
strh r0, [r5,#0x34] @ vol_ipol
strh r0, [r5,#0x36] @ vol_ipol
tst r2, r2
beq 0f @ EG_OFF
@ -182,7 +182,7 @@
11:
ldrh r3, [r5,#0x18] @ tl
add r0, r0, r3 @ volume += tl
strh r0, [r5,#0x32] @ vol_out
strh r0, [r5,#0x34] @ vol_out
.if \slot == SLOT1
mov r6, r6, lsr #16
orr r6, r0, r6, lsl #16
@ -207,11 +207,9 @@
ldrh r0, [r5,#0x30] @ ssg+ssgn
ldrb r2, [r5,#0x17] @ state
ldrh r3, [r5,#0x1a] @ volume
tst r0, #0x08 @ ssg enabled?
beq 9f
cmp r2, #EG_REL @ state > EG_REL?
ble 9f
cmp r3, #0x200 @ volume >= 0x200?
cmp r0, #0x08 @ ssg enabled &&
cmpge r2, #EG_REL+1 @ state > EG_REL &&
cmpge r3, #0x200 @ volume >= 0x200?
blt 9f
tst r0, #0x01
@ -226,35 +224,33 @@
eor r0, r0, #0x4 @ if ( !(ssg&0x04 )
tst r0, #0x4
cmpne r2, #EG_ATT @ if ( state != EG_ATT )
movne r0, #0x400
subne r0, r0, #1
strneh r0, [r5,#0x1a] @ volume = MAX_ATT
movne r3, #0x400
subne r3, r3, #1
strneh r3, [r5,#0x1a] @ volume = MAX_ATT
b 9f
1: tst r0, #0x02
eorne r0, r0, #0x4 @ ssg ^= 4
eorne r0, r0, #0x400 @ ssgn ^= 4
strneh r0, [r5,#0x30]
moveq r3, #0
streq r3, [r5,#0x0c] @ phase = 0
moveq r0, #0
streq r0, [r5,#0x0c] @ phase = 0
cmp r2, #EG_ATT @ if ( state != EG_ATT )
beq 9f
ldr r3, [r5,#0x1c] @ sl
ldr r0, [r5,#0x1c] @ sl
mov r2, #EG_SUS @ state = sl==MIN_ATT ? EG_SUS:EG_DEC
cmp r3, #0
ldr r0, [r5,#0x04] @ ar
ldr r3, [r5,#0x14] @ ksr
movne r2, #EG_DEC
add r0, r0, r3
cmp r0, #32+62 @ if ( ar+ksr >= 32+62 )
ldrlt r0, [r5,#0x1a]
movge r0, #0
strgeh r0, [r5,#0x1a] @ volume = MIN_ATT
cmp r0, #0
ldrh r0, [r5,#0x32] @ ar+ksr
movne r2, #EG_DEC
cmp r0, #32+62 @ if ( ar+ksr >= 32+62 )
movge r3, #0
strgeh r3, [r5,#0x1a] @ volume = MIN_ATT
bge 9f
cmp r3, #0
movgt r2, #EG_ATT
strb r2, [r5,#0x17] @ state
9:
@ -673,10 +669,10 @@ chan_render_loop:
ldr r10, [lr, #0x54] @ op1_out
@ ldmia lr, {r6,r7} @ load volumes
ldr r5, [lr, #0x40] @ CH
ldrh r6, [r5, #0x32] @ vol_out values for all slots
ldrh r2, [r5, #0x32+SLOT_STRUCT_SIZE*2]
ldrh r7, [r5, #0x32+SLOT_STRUCT_SIZE]
ldrh r3, [r5, #0x32+SLOT_STRUCT_SIZE*3]
ldrh r6, [r5, #0x34] @ vol_out values for all slots
ldrh r2, [r5, #0x34+SLOT_STRUCT_SIZE*2]
ldrh r7, [r5, #0x34+SLOT_STRUCT_SIZE]
ldrh r3, [r5, #0x34+SLOT_STRUCT_SIZE*3]
orr r6, r6, r2, lsl #16
orr r7, r7, r3, lsl #16
@ -756,28 +752,28 @@ eg_done:
cmp r3, #(EG_TIMER_OVERFLOW>>EG_SH)/2
bgt 0f @ mix is vol_out
ldrh r0, [r5,#0x34] @ SLOT1 vol_ipol
ldrh r0, [r5,#0x36] @ SLOT1 vol_ipol
lsleq r2, r6, #16
addeq r0, r0, r2, lsr #16
lsreq r0, r0, #1
mov r6, r6, lsr #16
orr r6, r0, r6, lsl #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE*2] @ SLOT2 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE*2] @ SLOT2 vol_ipol
addeq r0, r0, r6, lsr #16
lsreq r0, r0, #1
mov r6, r6, lsl #16
orr r6, r6, r0
ror r6, r6, #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE] @ SLOT3 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE] @ SLOT3 vol_ipol
lsleq r2, r7, #16
addeq r0, r0, r2, lsr #16
lsreq r0, r0, #1
mov r7, r7, lsr #16
orr r7, r0, r7, lsl #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE*3] @ SLOT4 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE*3] @ SLOT4 vol_ipol
addeq r0, r0, r7, lsr #16
lsreq r0, r0, #1
mov r7, r7, lsl #16
@ -787,22 +783,22 @@ eg_done:
@ super-basic... just take value closest to sample point
mov r3, r8, lsr #EG_SH-1 @ eg_timer, [0..3<<EG_SH) after loop
cmp r3, #(EG_TIMER_OVERFLOW>>EG_SH)
bgt 0f @ mix is vol_out
bge 0f @ mix is vol_out
ldrh r0, [r5,#0x34] @ SLOT1 vol_ipol
ldrh r0, [r5,#0x36] @ SLOT1 vol_ipol
mov r6, r6, lsr #16
orr r6, r0, r6, lsl #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE*2] @ SLOT2 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE*2] @ SLOT2 vol_ipol
mov r6, r6, lsl #16
orr r6, r6, r0
ror r6, r6, #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE] @ SLOT3 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE] @ SLOT3 vol_ipol
mov r7, r7, lsr #16
orr r7, r0, r7, lsl #16
ldrh r0, [r5,#0x34+SLOT_STRUCT_SIZE*3] @ SLOT4 vol_ipol
ldrh r0, [r5,#0x36+SLOT_STRUCT_SIZE*3] @ SLOT4 vol_ipol
mov r7, r7, lsl #16
orr r7, r7, r0
ror r7, r7, #16