diff --git a/Makefile.win32 b/Makefile.win32 index 2358232..4c4c20d 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -6,9 +6,9 @@ # # Defines : # -DLSB_FIRST : for little endian systems. -# -DBUILD_TABLES: do not use const tables for 68k instructions (obsolete) # -DLOGERROR : enable message logging # -DLOGVDP : enable VDP debug messages +# -DLOGSOUND : enable AUDIO debug messages # -DLOG_SCD : enable SCD debug messages # -DLOG_CDD : enable CDD debug messages # -DLOG_CDC : enable CDC debug messages @@ -23,125 +23,124 @@ NAME = gen_sdl.exe CC = gcc CFLAGS = `sdl-config --cflags` -march=i686 -O6 -fomit-frame-pointer -Wall -Wno-strict-aliasing -ansi -std=c89 -pedantic-errors -#-ansi -pedantic-errors #-g -ggdb -pg #-fomit-frame-pointer -LDFLAGS = +#LDFLAGS = -pg DEFINES = -DLSB_FIRST -DUSE_16BPP_RENDERING - -INCLUDES = -I. -I.. -I../z80 -I../m68k -I../sound -I../input_hw -I../cart_hw -I../cd_hw -I../cart_hw/svp -I../ntsc + +INCLUDES = -Isource -Isource/z80 -Isource/m68k -Isource/sound -Isource/input_hw -Isource/cart_hw -Isource/cd_hw -Isource/cart_hw/svp -Isource/ntsc -Isource/win LIBS = `sdl-config --libs` -lz -lm -OBJECTS = obj/z80.o +OBJDIR = ./build_sdl -OBJECTS += obj/m68kcpu.o \ - obj/s68kcpu.o \ +OBJECTS = $(OBJDIR)/z80.o -OBJECTS += obj/genesis.o \ - obj/vdp_ctrl.o \ - obj/vdp_render.o \ - obj/system.o \ - obj/io_ctrl.o \ - obj/mem68k.o \ - obj/memz80.o \ - obj/membnk.o \ - obj/state.o +OBJECTS += $(OBJDIR)/m68kcpu.o \ + $(OBJDIR)/s68kcpu.o -OBJECTS += obj/input.o \ - obj/gamepad.o \ - obj/lightgun.o \ - obj/mouse.o \ - obj/activator.o \ - obj/xe_a1p.o \ - obj/teamplayer.o \ - obj/paddle.o \ - obj/sportspad.o \ - obj/terebi_oekaki.o +OBJECTS += $(OBJDIR)/genesis.o \ + $(OBJDIR)/vdp_ctrl.o \ + $(OBJDIR)/vdp_render.o \ + $(OBJDIR)/system.o \ + $(OBJDIR)/io_ctrl.o \ + $(OBJDIR)/mem68k.o \ + $(OBJDIR)/memz80.o \ + $(OBJDIR)/membnk.o \ + $(OBJDIR)/state.o \ + $(OBJDIR)/loadrom.o +OBJECTS += $(OBJDIR)/input.o \ + $(OBJDIR)/gamepad.o \ + $(OBJDIR)/lightgun.o \ + $(OBJDIR)/mouse.o \ + $(OBJDIR)/activator.o \ + $(OBJDIR)/xe_a1p.o \ + $(OBJDIR)/teamplayer.o \ + $(OBJDIR)/paddle.o \ + $(OBJDIR)/sportspad.o \ + $(OBJDIR)/terebi_oekaki.o -OBJECTS += obj/sound.o \ - obj/sn76489.o \ - obj/ym2413.o \ - obj/ym2612.o +OBJECTS += $(OBJDIR)/sound.o \ + $(OBJDIR)/sn76489.o \ + $(OBJDIR)/ym2413.o \ + $(OBJDIR)/ym2612.o -OBJECTS += obj/blip_buf.o +OBJECTS += $(OBJDIR)/blip_buf.o -OBJECTS += obj/eq.o \ +OBJECTS += $(OBJDIR)/eq.o -OBJECTS += obj/sram.o \ - obj/svp.o \ - obj/ssp16.o \ - obj/ggenie.o \ - obj/areplay.o \ - obj/eeprom_93c.o \ - obj/eeprom_i2c.o \ - obj/eeprom_spi.o \ - obj/md_cart.o \ - obj/sms_cart.o +OBJECTS += $(OBJDIR)/sram.o \ + $(OBJDIR)/svp.o \ + $(OBJDIR)/ssp16.o \ + $(OBJDIR)/ggenie.o \ + $(OBJDIR)/areplay.o \ + $(OBJDIR)/eeprom_93c.o \ + $(OBJDIR)/eeprom_i2c.o \ + $(OBJDIR)/eeprom_spi.o \ + $(OBJDIR)/md_cart.o \ + $(OBJDIR)/sms_cart.o + +OBJECTS += $(OBJDIR)/scd.o \ + $(OBJDIR)/cdd.o \ + $(OBJDIR)/cdc.o \ + $(OBJDIR)/gfx.o \ + $(OBJDIR)/pcm.o \ + $(OBJDIR)/cd_cart.o -OBJECTS += obj/scd.o \ - obj/cdd.o \ - obj/cdc.o \ - obj/gfx.o \ - obj/pcm.o \ - obj/cd_cart.o +OBJECTS += $(OBJDIR)/sms_ntsc.o \ + $(OBJDIR)/md_ntsc.o -OBJECTS += obj/main.o \ - obj/config.o \ - obj/error.o \ - obj/unzip.o \ - obj/fileio.o \ - obj/loadrom.o +OBJECTS += $(OBJDIR)/main.o \ + $(OBJDIR)/config.o \ + $(OBJDIR)/error.o \ + $(OBJDIR)/unzip.o \ + $(OBJDIR)/fileio.o -OBJECTS += obj/sms_ntsc.o \ - obj/md_ntsc.o - -OBJECTS += obj/icon.o +OBJECTS += $(OBJDIR)/icon.o all: $(NAME) -$(NAME): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@ -Wl,-Map,genplus.map +$(NAME): $(OBJDIR) $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@ -obj/%.o : ../%.c ../%.h +$(OBJDIR) : + @[ -d $@ ] || mkdir -p $@ + +$(OBJDIR)/%.o : source/%.c source/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ - -obj/%.o : ../asm/%.s - $(AS) $< -o $@ - -obj/%.o : ../sound/%.c ../sound/%.h - $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../sound/%.c + +$(OBJDIR)/%.o : source/sound/%.c source/sound/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../input_hw/%.c ../input_hw/%.h +$(OBJDIR)/%.o : source/input_hw/%.c source/input_hw/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../cart_hw/%.c ../cart_hw/%.h +$(OBJDIR)/%.o : source/cart_hw/%.c source/cart_hw/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../cart_hw/svp/%.c - $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../cart_hw/svp/%.c ../cart_hw/svp/%.h +$(OBJDIR)/%.o : source/cart_hw/svp/%.c $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../cd_hw/%.c +$(OBJDIR)/%.o : source/cart_hw/svp/%.c source/cart_hw/svp/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../z80/%.c ../z80/%.h +$(OBJDIR)/%.o : source/cd_hw/%.c source/cd_hw/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../m68k/%.c +$(OBJDIR)/%.o : source/z80/%.c source/z80/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ./%.c ./%.h +$(OBJDIR)/%.o : source/m68k/%.c $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ -obj/%.o : ../ntsc/%.c ../ntsc/%.h +$(OBJDIR)/%.o : source/ntsc/%.c source/ntsc/%.h $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ - -obj/icon.o : - windres icon.rc $@ + +$(OBJDIR)/%.o : source/win/%.c source/win/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +$(OBJDIR)/icon.o : + windres source/win/icon.rc $@ pack : strip $(NAME) diff --git a/libretro/libretro.c b/libretro/libretro.c index 89573f6..c414fbd 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -213,7 +213,7 @@ static void config_default(void) config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; - config.psgBoostNoise = 0; + config.psgBoostNoise = 1; config.filter = 0; config.lp_range = 50; config.low_freq = 880; @@ -221,8 +221,7 @@ static void config_default(void) config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; - config.rolloff = 0.990; - config.dac_bits = 14; + config.dac_bits = 14; config.ym2413 = 2; /* AUTO */ /* system options */ @@ -243,6 +242,7 @@ static void config_default(void) config.yscale = 0; config.aspect = 0; config.overscan = 0; /* 3 == FULL */ + config.gg_extra = 0; /* 1 = show extended Game Gear screen (256x192) */ #if defined(USE_NTSC) config.ntsc = 1; #endif @@ -272,12 +272,9 @@ static void config_default(void) config.hot_swap &= 1; } -static const double pal_fps = 53203424.0 / (3420.0 * 313.0); -static const double ntsc_fps = 53693175.0 / (3420.0 * 262.0); - static void init_audio(void) { - audio_init(44100, vdp_pal ? pal_fps : ntsc_fps); + audio_init(44100, 0); } static void configure_controls(void) @@ -978,6 +975,7 @@ void retro_init(void) void retro_deinit(void) { + audio_shutdown(); #if defined(USE_NTSC) free(md_ntsc); free(sms_ntsc); diff --git a/source/cd_hw/cdd.c b/source/cd_hw/cdd.c index 5973c2d..c42e7ec 100644 --- a/source/cd_hw/cdd.c +++ b/source/cd_hw/cdd.c @@ -751,11 +751,21 @@ void cdd_read_audio(unsigned int samples) blip_add_delta_fast(blip[1], i, delta); /* update CD-DA fader volume (one step/sample) */ - if (curVol < endVol) curVol++; - else if (curVol > endVol) curVol--; - - /* audio is muted */ - if (!endVol) break; + if (curVol < endVol) + { + /* fade-in */ + curVol++; + } + else if (curVol > endVol) + { + /* fade-out */ + curVol--; + } + else if (!curVol) + { + /* audio will remain muted until next setup */ + break; + } } /* save current CD-DA fader volume */ diff --git a/source/gx/config.c b/source/gx/config.c index 2f9a4fa..57f2d0d 100644 --- a/source/gx/config.c +++ b/source/gx/config.c @@ -99,15 +99,15 @@ void config_default(void) config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; - config.psgBoostNoise = 0; + config.psgBoostNoise = 1; config.filter = 0; - config.lp_range = 50; + config.lp_range = 60; config.low_freq = 880; config.high_freq = 5000; config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; - config.dac_bits = 14; + config.dac_bits = 14; config.ym2413 = 2; /* AUTO */ /* system options */ diff --git a/source/gx/gui/menu.c b/source/gx/gui/menu.c index a41db02..ae0daf5 100644 --- a/source/gx/gui/menu.c +++ b/source/gx/gui/menu.c @@ -903,11 +903,11 @@ static void soundmenu () config.psg_preamp = (int)(psg_volume * 100.0 + 0.5); if ((system_hw & SYSTEM_PBC) == SYSTEM_MD) { - SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff); } else { - SN76489_Config(config.psg_preamp, config.psgBoostNoise, io_reg[6]); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, io_reg[6]); } break; } @@ -918,11 +918,11 @@ static void soundmenu () sprintf (items[5].text, "PSG Noise Boost: %s", config.psgBoostNoise ? "ON":"OFF"); if ((system_hw & SYSTEM_PBC) == SYSTEM_MD) { - SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff); } else { - SN76489_Config(config.psg_preamp, config.psgBoostNoise, io_reg[6]); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, io_reg[6]); } break; } diff --git a/source/gx/gx_video.c b/source/gx/gx_video.c index e7a6ee5..3e8ee41 100644 --- a/source/gx/gx_video.c +++ b/source/gx/gx_video.c @@ -1629,7 +1629,7 @@ int gx_video_Update(void) /* copy EFB to XFB */ GX_DrawDone(); - GX_CopyDisp(xfb[whichfb], GX_FALSE); + GX_CopyDisp(xfb[whichfb], GX_TRUE); GX_Flush(); /* XFB is ready to be displayed */ diff --git a/source/io_ctrl.c b/source/io_ctrl.c index a8642a5..2b4f924 100644 --- a/source/io_ctrl.c +++ b/source/io_ctrl.c @@ -547,7 +547,7 @@ void io_gg_write(unsigned int offset, unsigned int data) case 6: /* PSG Stereo output control */ io_reg[6] = data; - SN76489_Config(config.psg_preamp, config.psgBoostNoise, data); + SN76489_Config(Z80.cycles, config.psg_preamp, config.psgBoostNoise, data); return; default: /* Read-only */ diff --git a/source/sound/sn76489.c b/source/sound/sn76489.c index b507ac6..78a051d 100644 --- a/source/sound/sn76489.c +++ b/source/sound/sn76489.c @@ -157,29 +157,6 @@ void SN76489_Reset() SN76489.clocks = 0; } -void SN76489_Config(int preAmp, int boostNoise, int stereo) -{ - int i; - - for (i=0; i<4; i++) - { - /* stereo channel pre-amplification */ - SN76489.PreAmp[i][0] = preAmp * ((stereo >> (i*2)) & 1); - SN76489.PreAmp[i][1] = preAmp * ((stereo >> (i*2 + 1)) & 1); - - /* noise channel boost */ - if (i == 3) - { - SN76489.PreAmp[3][0] = SN76489.PreAmp[3][0] << boostNoise; - SN76489.PreAmp[3][1] = SN76489.PreAmp[3][1] << boostNoise; - } - - /* update stereo channel amplitude */ - SN76489.Channel[i][0]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][0]) / 100; - SN76489.Channel[i][1]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][1]) / 100; - } -} - void *SN76489_GetContextPtr(void) { return (uint8 *)&SN76489; @@ -331,6 +308,39 @@ static void SN76489_RunUntil(unsigned int clocks) } } +void SN76489_Config(unsigned int clocks, int preAmp, int boostNoise, int stereo) +{ + int i; + + /* cycle-accurate Game Gear stereo */ + if (clocks > SN76489.clocks) + { + /* Run chip until current timestamp */ + SN76489_RunUntil(clocks); + + /* Update internal M-cycle counter */ + SN76489.clocks += ((clocks - SN76489.clocks + PSG_MCYCLES_RATIO - 1) / PSG_MCYCLES_RATIO) * PSG_MCYCLES_RATIO; + } + + for (i=0; i<4; i++) + { + /* stereo channel pre-amplification */ + SN76489.PreAmp[i][0] = preAmp * ((stereo >> (i + 4)) & 1); + SN76489.PreAmp[i][1] = preAmp * ((stereo >> (i + 0)) & 1); + + /* noise channel boost */ + if (i == 3) + { + SN76489.PreAmp[3][0] = SN76489.PreAmp[3][0] << boostNoise; + SN76489.PreAmp[3][1] = SN76489.PreAmp[3][1] << boostNoise; + } + + /* update stereo channel amplitude */ + SN76489.Channel[i][0]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][0]) / 100; + SN76489.Channel[i][1]= (PSGVolumeValues[SN76489.Registers[i*2 + 1]] * SN76489.PreAmp[i][1]) / 100; + } +} + void SN76489_Update(unsigned int clocks) { int i; @@ -424,7 +434,7 @@ void SN76489_Write(unsigned int clocks, unsigned int data) SN76489.NoiseShiftRegister = NoiseInitialState; /* set noise signal generator frequency */ - SN76489.NoiseFreq = (0x10 << (data&0x3)) * PSG_MCYCLES_RATIO; + SN76489.NoiseFreq = 0x10 << (data&0x3); break; } diff --git a/source/sound/sn76489.h b/source/sound/sn76489.h index 3c59611..19d4a86 100644 --- a/source/sound/sn76489.h +++ b/source/sound/sn76489.h @@ -14,7 +14,7 @@ /* Function prototypes */ extern void SN76489_Init(blip_t* left, blip_t* right, int type); extern void SN76489_Reset(void); -extern void SN76489_Config(int preAmp, int boostNoise, int stereo); +extern void SN76489_Config(unsigned int clocks, int preAmp, int boostNoise, int stereo); extern void SN76489_Write(unsigned int clocks, unsigned int data); extern void SN76489_Update(unsigned int cycles); extern void *SN76489_GetContextPtr(void); diff --git a/source/sound/sound.c b/source/sound/sound.c index d36d349..868c2cf 100644 --- a/source/sound/sound.c +++ b/source/sound/sound.c @@ -102,7 +102,7 @@ void sound_init( void ) } /* Initialize PSG chip */ - SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff); } void sound_reset(void) diff --git a/source/state.c b/source/state.c index 7ee3fb9..e5b75f6 100644 --- a/source/state.c +++ b/source/state.c @@ -117,12 +117,12 @@ int state_load(unsigned char *state) if ((system_hw & SYSTEM_PBC) == SYSTEM_MD) { SN76489_Init(snd.blips[0][0], snd.blips[0][1], SN_INTEGRATED); - SN76489_Config(config.psg_preamp, config.psgBoostNoise, 0xff); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, 0xff); } else { SN76489_Init(snd.blips[0][0], snd.blips[0][1], (system_hw < SYSTEM_MARKIII) ? SN_DISCRETE : SN_INTEGRATED); - SN76489_Config(config.psg_preamp, config.psgBoostNoise, io_reg[6]); + SN76489_Config(0, config.psg_preamp, config.psgBoostNoise, io_reg[6]); } /* 68000 */ diff --git a/source/win/config.c b/source/win/config.c index 4e09c3d..812dfcf 100644 --- a/source/win/config.c +++ b/source/win/config.c @@ -12,8 +12,8 @@ void set_config_defaults(void) config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; - config.psgBoostNoise = 0; - config.filter = 1; + config.psgBoostNoise = 1; + config.filter = 0; config.low_freq = 200; config.high_freq = 8000; config.lg = 1.0; @@ -34,7 +34,7 @@ void set_config_defaults(void) config.lock_on = 0; /* = OFF (can be TYPE_SK, TYPE_GG & TYPE_AR) */ /* display options */ - config.overscan = 0; /* = both ON (0 = no borders , 1 = vertical borders only, 2 = horizontal borders only) */ + config.overscan = 0; /* 3 = all borders (0 = no borders , 1 = vertical borders only, 2 = horizontal borders only) */ config.gg_extra = 0; /* 1 = show extended Game Gear screen (256x192) */ config.render = 0; /* 1 = double resolution output (only when interlaced mode 2 is enabled) */ diff --git a/source/win/main.c b/source/win/main.c index 3c452b4..34acdaa 100644 --- a/source/win/main.c +++ b/source/win/main.c @@ -892,7 +892,6 @@ int main (int argc, char **argv) } } - system_shutdown(); audio_shutdown(); error_shutdown();