From 84a395dbf3f0d785be8c859689bfdeaa8470a32f Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Thu, 17 Jun 2010 06:31:30 +0000 Subject: [PATCH] fixed an error with Z80 reset from previous changes --- source/genesis.c | 35 ++++++++++++++++++----------------- source/sound/sound.c | 8 ++++---- source/system.c | 16 ++++------------ 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/source/genesis.c b/source/genesis.c index a822234..3f49b17 100644 --- a/source/genesis.c +++ b/source/genesis.c @@ -258,18 +258,19 @@ unsigned int gen_bankswitch_r(void) -----------------------------------------------------------------------*/ void gen_zbusreq_w(unsigned int state, unsigned int cycles) { - if (state) /* Z80 Bus Requested */ + if (state) /* !ZBUSREQ asserted */ { /* if z80 was running, resynchronize with 68k */ if (zstate == 1) z80_run(cycles); - /* request Z80 bus */ + /* update Z80 bus status */ zstate |= 2; - /* enable 68k access */ + /* check if Z80 reset is released */ if (zstate & 1) { + /* enable 68k access to Z80 bus */ _m68k_memory_map *base = &m68k_memory_map[0xa0]; base->read8 = z80_read_byte; base->read16 = z80_read_word; @@ -277,13 +278,13 @@ void gen_zbusreq_w(unsigned int state, unsigned int cycles) base->write16 = z80_write_word; } } - else /* Z80 Bus Released */ + else /* !ZBUSREQ released */ { /* if z80 is restarted, resynchronize with 68k */ if (zstate == 3) mcycles_z80 = cycles; - /* release Z80 bus */ + /* update Z80 bus status */ zstate &= 1; /* disable 68k access */ @@ -301,21 +302,19 @@ void gen_zreset_w(unsigned int state, unsigned int cycles) if (state == (zstate & 1)) return; - if (state) /* !ZRESET inactive */ + if (state) /* !ZRESET released */ { /* if z80 is restarted, resynchronize with 68k */ - if (zstate == 0) + if (!zstate) mcycles_z80 = cycles; - /* reset Z80 */ - z80_reset(); - - /* negate Z80 reset */ + /* update Z80 bus status */ zstate |= 1; - /* enable 68k access */ - if (zstate & 1) + /* check if Z80 bus has been requested */ + if (zstate & 2) { + /* enable 68k access to Z80 bus */ _m68k_memory_map *base = &m68k_memory_map[0xa0]; base->read8 = z80_read_byte; base->read16 = z80_read_word; @@ -323,13 +322,17 @@ void gen_zreset_w(unsigned int state, unsigned int cycles) base->write16 = z80_write_word; } } - else /* !ZRESET active */ + else /* !ZRESET asserted */ { /* if z80 was running, resynchronize with 68k */ if (zstate == 1) z80_run(cycles); - /* assert Z80 reset */ + /* reset Z80 & YM2612 */ + z80_reset(); + fm_reset(cycles); + + /* update Z80 bus status */ zstate &= 2; /* disable 68k access */ @@ -340,8 +343,6 @@ void gen_zreset_w(unsigned int state, unsigned int cycles) base->write16 = m68k_unused_16_w; } - /* reset YM2612 */ - fm_reset(cycles); } void gen_zbank_w (unsigned int state) diff --git a/source/sound/sound.c b/source/sound/sound.c index 2ca16a6..bc721f4 100644 --- a/source/sound/sound.c +++ b/source/sound/sound.c @@ -42,10 +42,10 @@ static inline void fm_update(unsigned int cycles) fm_cycles_count += cycles; /* number of samples during period */ - uint32 cnt = cycles / fm_cycles_ratio; + unsigned int cnt = cycles / fm_cycles_ratio; /* remaining cycles */ - uint32 remain = cycles % fm_cycles_ratio; + unsigned int remain = cycles % fm_cycles_ratio; if (remain) { /* one sample ahead */ @@ -82,10 +82,10 @@ static inline void psg_update(unsigned int cycles) psg_cycles_count += cycles; /* number of samples during period */ - uint32 cnt = cycles / psg_cycles_ratio; + unsigned int cnt = cycles / psg_cycles_ratio; /* remaining cycles */ - uint32 remain = cycles % psg_cycles_ratio; + unsigned int remain = cycles % psg_cycles_ratio; if (remain) { /* one sample ahead */ diff --git a/source/system.c b/source/system.c index 37e2b98..812c2c6 100644 --- a/source/system.c +++ b/source/system.c @@ -80,7 +80,7 @@ int audio_update (void) if (config.hq_fm) { /* resample into FM output buffer */ - Fir_Resampler_read(fm,size); + Fir_Resampler_read(fm, size); #ifdef LOGSOUND error("%d FM samples remaining\n",Fir_Resampler_written() >> 1); @@ -89,7 +89,7 @@ int audio_update (void) else { /* adjust remaining samples in FM output buffer*/ - snd.fm.pos -= (size << 1); + snd.fm.pos -= (size * 2); #ifdef LOGSOUND error("%d FM samples remaining\n",(snd.fm.pos - snd.fm.buffer)>>1); @@ -154,8 +154,8 @@ int audio_update (void) rrp = rr; /* keep remaining samples for next frame */ - memcpy(snd.fm.buffer, fm, (snd.fm.pos - snd.fm.buffer) << 2); - memcpy(snd.psg.buffer, psg, (snd.psg.pos - snd.psg.buffer) << 1); + memcpy(snd.fm.buffer, fm, (snd.fm.pos - snd.fm.buffer) * 4); + memcpy(snd.psg.buffer, psg, (snd.psg.pos - snd.psg.buffer) * 2); #ifdef LOGSOUND error("%d samples returned\n\n",size); @@ -191,20 +191,12 @@ int audio_init (int samplerate, float framerate) #endif /* SN76489 stream buffers */ -#ifndef NGC snd.psg.buffer = (int16 *) malloc(snd.buffer_size * sizeof(int16)); -#else - snd.psg.buffer = (int16 *) memalign(32, snd.buffer_size * sizeof(int16)); -#endif if (!snd.psg.buffer) return (-1); /* YM2612 stream buffers */ -#ifndef NGC snd.fm.buffer = (int32 *) malloc(snd.buffer_size * sizeof(int32) * 2); -#else - snd.fm.buffer = (int32 *) memalign(32,snd.buffer_size * sizeof(int32) * 2); -#endif if (!snd.fm.buffer) return (-1);