From: Toni Wilen Date: Tue, 10 Oct 2006 16:27:06 +0000 (+0300) Subject: imported winuaesrc1330b4.zip X-Git-Tag: 2100~269 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=4b68c87dae9dc2ab4c5915e4cf77d2977b39bf99;p=francis%2Fwinuae.git imported winuaesrc1330b4.zip --- diff --git a/audio.c b/audio.c index 3cf13ba6..80cb4eed 100755 --- a/audio.c +++ b/audio.c @@ -941,19 +941,22 @@ static int audio_work_to_do; static void audio_deactivate(void) { - write_log ("Audio stopped\n"); + if (!currprefs.sound_auto) + return; gui_data.sndbuf_status = 3; gui_data.sndbuf = 0; clear_sound_buffers(); } -STATIC_INLINE void audio_active(void) +int audio_activate(void) { + int ret = 0; if (!audio_work_to_do) { - write_log ("Audio started\n"); restart_sound_buffer(); + ret = 1; } - audio_work_to_do = 2 * maxvpos * 50; + audio_work_to_do = 4 * maxvpos * 50; + return ret; } STATIC_INLINE int is_audio_active(void) { @@ -1044,7 +1047,7 @@ static void audio_handler (int nr, int timed) int napnav = (!audav && !audap) || audav; int evtime = cdp->evtime; - audio_active(); + audio_activate(); cdp->evtime = MAX_EV; switch (cdp->state) { @@ -1218,7 +1221,7 @@ STATIC_INLINE int sound_prefs_changed (void) || changed_prefs.sound_mixed_stereo != currprefs.sound_mixed_stereo || changed_prefs.sound_maxbsiz != currprefs.sound_maxbsiz || changed_prefs.sound_freq != currprefs.sound_freq - || changed_prefs.sound_adjust != currprefs.sound_adjust + || changed_prefs.sound_auto != currprefs.sound_auto || changed_prefs.sound_interpol != currprefs.sound_interpol || changed_prefs.sound_volume != currprefs.sound_volume || changed_prefs.sound_stereo_swap_paula != currprefs.sound_stereo_swap_paula @@ -1257,7 +1260,9 @@ void check_prefs_changed_audio (void) #ifdef AVIOUTPUT AVIOutput_Restart (); #endif + clear_sound_buffers(); set_audio(); + audio_activate(); } void set_audio(void) @@ -1268,7 +1273,7 @@ void set_audio(void) currprefs.sound_stereo = changed_prefs.sound_stereo; currprefs.sound_stereo_separation = changed_prefs.sound_stereo_separation; currprefs.sound_mixed_stereo = changed_prefs.sound_mixed_stereo; - currprefs.sound_adjust = changed_prefs.sound_adjust; + currprefs.sound_auto = changed_prefs.sound_auto; currprefs.sound_interpol = changed_prefs.sound_interpol; currprefs.sound_freq = changed_prefs.sound_freq; currprefs.sound_maxbsiz = changed_prefs.sound_maxbsiz; @@ -1433,14 +1438,14 @@ void audio_hsync (int dmaaction) int nr, handle; static int old_dma; + if (!isaudio()) + return; + if (old_dma != (dmacon & (DMA_MASTER | 15))) { old_dma = dmacon & (DMA_MASTER | 15); - audio_active(); + audio_activate(); } - if (!isaudio()) - return; - if (audio_work_to_do > 0) { audio_work_to_do--; if (audio_work_to_do == 0) @@ -1517,7 +1522,7 @@ void AUDxDAT (int nr, uae_u16 v) write_log ("AUD%dDAT: %04.4X STATE=%d IRQ=%d %08.8X\n", nr, v, cdp->state, isirq(nr) ? 1 : 0, M68K_GETPC); #endif - audio_active(); + audio_activate(); update_audio (); cdp->dat2 = v; cdp->request_word = -1; @@ -1532,7 +1537,7 @@ void AUDxDAT (int nr, uae_u16 v) void AUDxLCH (int nr, uae_u16 v) { - audio_active(); + audio_activate(); update_audio (); audio_channel[nr].lc = (audio_channel[nr].lc & 0xffff) | ((uae_u32)v << 16); #ifdef DEBUG_AUDIO @@ -1543,7 +1548,7 @@ void AUDxLCH (int nr, uae_u16 v) void AUDxLCL (int nr, uae_u16 v) { - audio_active(); + audio_activate(); update_audio (); audio_channel[nr].lc = (audio_channel[nr].lc & ~0xffff) | (v & 0xFFFE); #ifdef DEBUG_AUDIO @@ -1555,9 +1560,9 @@ void AUDxLCL (int nr, uae_u16 v) void AUDxPER (int nr, uae_u16 v) { unsigned long per = v * CYCLE_UNIT; - update_audio (); - audio_active(); + audio_activate(); + update_audio (); if (per == 0) per = PERIOD_MAX - 1; @@ -1581,6 +1586,7 @@ void AUDxPER (int nr, uae_u16 v) void AUDxLEN (int nr, uae_u16 v) { + audio_activate(); update_audio (); audio_channel[nr].len = v; #ifdef DEBUG_AUDIO @@ -1592,7 +1598,8 @@ void AUDxLEN (int nr, uae_u16 v) void AUDxVOL (int nr, uae_u16 v) { int v2 = v & 64 ? 63 : v & 63; - audio_active(); + + audio_activate(); update_audio (); audio_channel[nr].vol = v2; #ifndef MULTIPLICATION_PROFITABLE @@ -1635,7 +1642,7 @@ void audio_update_adkmasks (void) audio_channel[2].adk_mask = (((t >> 2) & 1) - 1); audio_channel[3].adk_mask = (((t >> 3) & 1) - 1); if ((prevcon & 0xff) != (adkcon & 0xff)) { - audio_active(); + audio_activate(); #ifdef DEBUG_AUDIO write_log("ADKCON=%02.2x %08.8X\n", adkcon & 0xff, M68K_GETPC); #endif diff --git a/cfgfile.c b/cfgfile.c index 74e7ae72..e59fdaee 100755 --- a/cfgfile.c +++ b/cfgfile.c @@ -148,7 +148,7 @@ static const char *obsolete[] = { "gfx_immediate_blits", "gfx_ntsc", "win32", "gfx_filter_bits", "sound_pri_cutoff", "sound_pri_time", "sound_min_buff", "gfx_test_speed", "gfxlib_replacement", "enforcer", "catweasel_io", - "kickstart_key_file", "fast_copper", + "kickstart_key_file", "fast_copper", "sound_adjust", 0 }; @@ -286,15 +286,14 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) cfgfile_write (f, "sound_channels=%s\n", stereomode[p->sound_stereo]); cfgfile_write (f, "sound_stereo_separation=%d\n", p->sound_stereo_separation); cfgfile_write (f, "sound_stereo_mixing_delay=%d\n", p->sound_mixed_stereo >= 0 ? p->sound_mixed_stereo : 0); - cfgfile_write (f, "sound_max_buff=%d\n", p->sound_maxbsiz); cfgfile_write (f, "sound_frequency=%d\n", p->sound_freq); cfgfile_write (f, "sound_latency=%d\n", p->sound_latency); cfgfile_write (f, "sound_interpol=%s\n", interpolmode[p->sound_interpol]); - cfgfile_write (f, "sound_adjust=%d\n", p->sound_adjust); cfgfile_write (f, "sound_filter=%s\n", soundfiltermode1[p->sound_filter]); cfgfile_write (f, "sound_filter_type=%s\n", soundfiltermode2[p->sound_filter_type]); cfgfile_write (f, "sound_volume=%d\n", p->sound_volume); + cfgfile_write (f, "sound_auto=%s\n", p->sound_auto ? "yes" : "no"); cfgfile_write (f, "comp_trustbyte=%s\n", compmode[p->comptrustbyte]); cfgfile_write (f, "comp_trustword=%s\n", compmode[p->comptrustword]); @@ -648,7 +647,6 @@ static int cfgfile_parse_host (struct uae_prefs *p, char *option, char *value) || cfgfile_intval (option, value, "state_replay_rate", &p->statecapturerate, 1) || cfgfile_intval (option, value, "state_replay_buffer", &p->statecapturebuffersize, 1) || cfgfile_intval (option, value, "sound_frequency", &p->sound_freq, 1) - || cfgfile_intval (option, value, "sound_adjust", &p->sound_adjust, 1) || cfgfile_intval (option, value, "sound_volume", &p->sound_volume, 1) || cfgfile_intval (option, value, "sound_stereo_separation", &p->sound_stereo_separation, 1) || cfgfile_intval (option, value, "sound_stereo_mixing_delay", &p->sound_mixed_stereo, 1) @@ -692,6 +690,7 @@ static int cfgfile_parse_host (struct uae_prefs *p, char *option, char *value) return 1; if (cfgfile_yesno (option, value, "use_debugger", &p->start_debugger) + || cfgfile_yesno (option, value, "sound_auto", &p->sound_auto) || cfgfile_yesno (option, value, "state_replay", &p->statecapture) || cfgfile_yesno (option, value, "avoid_cmov", &p->avoid_cmov) || cfgfile_yesno (option, value, "avoid_dga", &p->avoid_dga) @@ -2417,6 +2416,7 @@ void default_prefs (struct uae_prefs *p, int type) p->sound_interpol = 1; p->sound_filter = FILTER_SOUND_EMUL; p->sound_filter_type = 0; + p->sound_auto = 1; p->comptrustbyte = 0; p->comptrustword = 0; diff --git a/custom.c b/custom.c index ea74b0c4..14a3d12c 100755 --- a/custom.c +++ b/custom.c @@ -3219,11 +3219,11 @@ void dump_aga_custom (void) c2 = c1 + 64; c3 = c2 + 64; c4 = c3 + 64; - rgb1 = current_colors.acolors[c1]; - rgb2 = current_colors.acolors[c2]; - rgb3 = current_colors.acolors[c3]; - rgb4 = current_colors.acolors[c4]; - console_out("%3d %06.6X %3d %06.6X %3d %06.6X %3d %06.6X\n", + rgb1 = current_colors.color_regs_aga[c1]; + rgb2 = current_colors.color_regs_aga[c2]; + rgb3 = current_colors.color_regs_aga[c3]; + rgb4 = current_colors.color_regs_aga[c4]; + console_out("%3d %08.8X %3d %08.8X %3d %08.8X %3d %08.8X\n", c1, rgb1, c2, rgb2, c3, rgb3, c4, rgb4); } } diff --git a/driveclick.c b/driveclick.c index 634522d3..643a33cc 100755 --- a/driveclick.c +++ b/driveclick.c @@ -17,6 +17,7 @@ #include "zfile.h" #include "events.h" #include "driveclick.h" +#include "audio.h" static struct drvsample drvs[4][DS_END]; static int freq = 44100; @@ -228,6 +229,18 @@ void driveclick_free (void) wave_initialized = 0; } +static int driveclick_active(void) +{ + int i; + for (i = 0; i < 4; i++) { + if (currprefs.dfxclick[i]) { + if (drv_spinning[i] || drv_starting[i]) + return 1; + } + } + return 0; +} + STATIC_INLINE uae_s16 getsample(void) { uae_s32 smp = 0; @@ -325,6 +338,12 @@ void driveclick_mix (uae_s16 *sndbuffer, int size) } } +static void dr_audio_activate(void) +{ + if (audio_activate()) + clickcnt = 0; +} + void driveclick_click (int drive, int cyl) { static int prevcyl[4]; @@ -335,6 +354,7 @@ void driveclick_click (int drive, int cyl) return; if (prevcyl[drive] == 0 && cyl == 0) // "noclick" check return; + dr_audio_activate(); prevcyl[drive] = cyl; if (!wave_initialized) { driveclick_fdrawcmd_seek (currprefs.dfxclick[drive] - 2, cyl); @@ -361,6 +381,7 @@ void driveclick_motor (int drive, int running) drv_spinning[drive] = 0; } else { if (drv_spinning[drive] == 0) { + dr_audio_activate(); drv_starting[drive] = 1; drv_spinning[drive] = 1; if (drv_has_disk[drive] && drv_has_spun[drive] == 0 && drvs[drive][DS_SNATCH].pos >= drvs[drive][DS_SNATCH].len) @@ -382,6 +403,8 @@ void driveclick_insert (int drive, int eject) return; if (eject) drv_has_spun[drive] = 0; + if (drv_has_disk[drive] == 0 && !eject) + dr_audio_activate(); drv_has_disk[drive] = !eject; } @@ -390,6 +413,8 @@ void driveclick_check_prefs (void) int i; driveclick_fdrawcmd_vsync(); + if (driveclick_active()) + dr_audio_activate(); if (currprefs.dfxclickvolume != changed_prefs.dfxclickvolume || currprefs.dfxclick[0] != changed_prefs.dfxclick[0] || currprefs.dfxclick[1] != changed_prefs.dfxclick[1] || diff --git a/expansion.c b/expansion.c index 81d9dba7..72c37e95 100755 --- a/expansion.c +++ b/expansion.c @@ -883,8 +883,6 @@ static void expamem_init_z3fastmem (void) expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/ - z3fastmem_start = currprefs.z3fastmem_start; - map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, allocated_z3fastmem); @@ -1089,6 +1087,7 @@ void expamem_reset (void) card_map[cardno++] = expamem_map_clear; } + z3fastmem_start = currprefs.z3fastmem_start; (*card_init[0]) (); } diff --git a/identify.c b/identify.c index cd5ba347..b9404dea 100755 --- a/identify.c +++ b/identify.c @@ -395,10 +395,9 @@ const struct customData custd[] = { "RESERVED", 0xdff1Fa }, /* Reserved (forever i guess!) */ #endif { "FMODE", 0xdff1FC, 2|8 }, /* Fetch mode register */ -#if 0 - { "NO-OP(NULL)", 0xdff1FE }, /* Can also indicate last 2 or 3 refresh + { "NO-OP(NULL)", 0xdff1FE }, /* Can also indicate last 2 or 3 refresh cycles or the restart of the COPPER after lockup.*/ -#endif + { NULL } }; #endif diff --git a/include/audio.h b/include/audio.h index e4d086cc..cdc6021a 100755 --- a/include/audio.h +++ b/include/audio.h @@ -32,6 +32,7 @@ extern void audio_update_irq (uae_u16); extern void update_sound (int freq); extern void led_filter_audio (void); extern void set_audio(void); +extern int audio_activate(void); extern void audio_sampleripper(int); extern int sampleripper_enabled; diff --git a/include/options.h b/include/options.h index c400f390..8ac4cf2e 100755 --- a/include/options.h +++ b/include/options.h @@ -91,12 +91,12 @@ struct uae_prefs { int sound_maxbsiz; int sound_latency; int sound_interpol; - int sound_adjust; int sound_filter; int sound_filter_type; int sound_volume; int sound_stereo_swap_paula; int sound_stereo_swap_ahi; + int sound_auto; int comptrustbyte; int comptrustword; diff --git a/main.c b/main.c index 4d328838..909d65b1 100755 --- a/main.c +++ b/main.c @@ -159,8 +159,7 @@ void fixup_prefs (struct uae_prefs *p) write_log ("Can't use a graphics card or Zorro III fastmem when using a 24 bit\n" "address space - sorry.\n"); } - if (p->bogomem_size != 0 && p->bogomem_size != 0x80000 && p->bogomem_size != 0x100000 && p->bogomem_size != 0x180000 && p->bogomem_size != 0x1c0000) - { + if (p->bogomem_size != 0 && p->bogomem_size != 0x80000 && p->bogomem_size != 0x100000 && p->bogomem_size != 0x180000 && p->bogomem_size != 0x1c0000) { p->bogomem_size = 0; write_log ("Unsupported bogomem size!\n"); err = 1; diff --git a/memory.c b/memory.c index e6bfb11d..fba0d350 100755 --- a/memory.c +++ b/memory.c @@ -2059,11 +2059,11 @@ void memory_reset (void) int t = allocated_bogomem >> 16; if (t > 0x1C) t = 0x1C; - if (t > 0x10 && ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_level > 1)) + if (t > 0x10 && ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_level >= 2)) t = 0x10; - map_banks (&bogomem_bank, 0xC0, t, allocated_bogomem); + map_banks (&bogomem_bank, 0xC0, t, 0); } - if ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_level > 1) + if ((currprefs.chipset_mask & CSMASK_AGA) || currprefs.cpu_level >= 2) map_banks (&gayle_bank, 0xD8, 7, 0); map_banks (&clock_bank, 0xDC, 1, 0); @@ -2227,11 +2227,8 @@ void map_banks (addrbank *bank, int start, int size, int realsize) realsize = size << 16; if ((size << 16) < realsize) { - //write_log ("Please report to bmeyer@cs.monash.edu.au, and mention:\n"); - write_log ("Broken mapping, size=%x, realsize=%x\n", size, realsize); - write_log ("Start is %x\n", start); - write_log ("Reducing memory sizes, especially chipmem, may fix this problem\n"); - abort (); + gui_message ("Broken mapping, size=%x, realsize=%x\nStart is %x\n", + size, realsize, start); } #ifndef ADDRESS_SPACE_24BIT diff --git a/od-win32/avioutput.c b/od-win32/avioutput.c index eef5d8ed..6c679586 100755 --- a/od-win32/avioutput.c +++ b/od-win32/avioutput.c @@ -923,7 +923,9 @@ void AVIOutput_Begin(void) if (!avioutput_requested) return; + changed_prefs.sound_auto = currprefs.sound_auto = 0; reset_sound (); + if (avioutput_audio == AVIAUDIO_WAV) { ext1 = ".wav"; ext2 = ".avi"; } else { diff --git a/od-win32/build68k_msvc/build68k.rc b/od-win32/build68k_msvc/build68k.rc deleted file mode 100755 index c1017f88..00000000 --- a/od-win32/build68k_msvc/build68k.rc +++ /dev/null @@ -1,61 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE 11, 1 -#pragma code_page(1252) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/od-win32/keyboard_win32.c b/od-win32/keyboard_win32.c index 13b0dba1..4d747775 100755 --- a/od-win32/keyboard_win32.c +++ b/od-win32/keyboard_win32.c @@ -310,15 +310,6 @@ void my_kbd_handler (int keyboard, int scancode, int newstate) int code = 0; static int swapperdrive = 0; - extern int last_n, last_n2; - extern void blehint(void); - if (newstate && scancode == DIK_F1) - write_log("%d %d\n", last_n, last_n2); - if (newstate && scancode == DIK_F2) { - blehint(); - write_log("INT\n"); - } - //write_log( "keyboard = %d scancode = 0x%02.2x state = %d\n", keyboard, scancode, newstate ); if (newstate) { switch (scancode) diff --git a/od-win32/picasso96_win.c b/od-win32/picasso96_win.c index 34be99b9..73088d47 100755 --- a/od-win32/picasso96_win.c +++ b/od-win32/picasso96_win.c @@ -1656,26 +1656,26 @@ static void FillBoardInfo (uaecptr amigamemptr, struct LibResolution *res, struc put_long (amigamemptr + PSSO_ModeInfo_PixelClock, dm->res.width * dm->res.height * (currprefs.gfx_refreshrate ? abs (currprefs.gfx_refreshrate) : default_freq)); } -static int AssignModeID( int i, int count ) +static int AssignModeID(int i, int count) { int result; - if( DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 200 ) + if(DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 200) result = 0x50001000; - else if( DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 240 ) + else if(DisplayModes[i].res.width == 320 && DisplayModes[i].res.height == 240) result = 0x50011000; - else if( DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 400 ) + else if(DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 400) result = 0x50021000; - else if( DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 480 ) + else if(DisplayModes[i].res.width == 640 && DisplayModes[i].res.height == 480) result = 0x50031000; - else if( DisplayModes[i].res.width == 800 && DisplayModes[i].res.height == 600 ) + else if(DisplayModes[i].res.width == 800 && DisplayModes[i].res.height == 600) result = 0x50041000; - else if( DisplayModes[i].res.width == 1024 && DisplayModes[i].res.height == 768 ) + else if(DisplayModes[i].res.width == 1024 && DisplayModes[i].res.height == 768) result = 0x50051000; - else if( DisplayModes[i].res.width == 1152 && DisplayModes[i].res.height == 864 ) + else if(DisplayModes[i].res.width == 1152 && DisplayModes[i].res.height == 864) result = 0x50061000; - else if( DisplayModes[i].res.width == 1280 && DisplayModes[i].res.height == 1024 ) + else if(DisplayModes[i].res.width == 1280 && DisplayModes[i].res.height == 1024) result = 0x50071000; - else if( DisplayModes[i].res.width == 1600 && DisplayModes[i].res.height == 1280 ) + else if(DisplayModes[i].res.width == 1600 && DisplayModes[i].res.height == 1280) result = 0x50081000; else result = 0x50091000 + count * 0x10000; @@ -1728,7 +1728,7 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs) while (DisplayModes[i].depth >= 0) { int j = i; /* Add a LibResolution structure to the ResolutionsList MinList in our BoardInfo */ - res.DisplayID = AssignModeID( i, LibResolutionStructureCount ); + res.DisplayID = AssignModeID(i, LibResolutionStructureCount); res.BoardInfo = AmigaBoardInfo; res.Width = DisplayModes[i].res.width; res.Height = DisplayModes[i].res.height; @@ -1745,8 +1745,8 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs) /* Handle this display mode's depth */ /* New: Only add the modes when there is enough P96 RTG memory to hold the bitmap */ - if( ( allocated_gfxmem - 32768 ) > - ( DisplayModes[i].res.width * DisplayModes[i].res.height * DisplayModes[i].depth ) ) + if((allocated_gfxmem - 32768) > + (DisplayModes[i].res.width * DisplayModes[i].res.height * DisplayModes[i].depth)) { amigamemptr = gfxmem_start + allocated_gfxmem - (PSSO_ModeInfo_sizeof * ModeInfoStructureCount++); FillBoardInfo(amigamemptr, &res, &DisplayModes[i]); diff --git a/od-win32/posixemu.c b/od-win32/posixemu.c index 6f35b012..1c28d235 100755 --- a/od-win32/posixemu.c +++ b/od-win32/posixemu.c @@ -235,6 +235,6 @@ int uae_start_thread (void *(*f)(void *), void *arg, uae_thread_id *tid) void uae_set_thread_priority (int pri) { /* workaround for filesystem emulation freeze with some dual core systems */ - //SetThreadAffinityMask(GetCurrentThread(), 1); + SetThreadAffinityMask(GetCurrentThread(), 1); } diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index f516f95e..ee7afda1 100755 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -857,6 +857,7 @@ #define IDC_LANGUAGE 1706 #define IDC_CREATE_NAME 1707 #define IDC_FILTERAUTORES 1708 +#define IDC_SOUND_AUTO 1709 #define ID__FLOPPYDRIVES 40004 #define ID_FLOPPYDRIVES_DF0 40005 #define ID_ST_CONFIGURATION 40010 @@ -877,7 +878,7 @@ #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 253 #define _APS_NEXT_COMMAND_VALUE 40021 -#define _APS_NEXT_CONTROL_VALUE 1709 +#define _APS_NEXT_CONTROL_VALUE 1710 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index f27eae78..87837414 100755 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -227,47 +227,44 @@ BEGIN CONTROL "Include network drives",IDC_MAPDRIVES_NET,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,216,101,10,0,HIDC_MAPDRIVES_NET END -IDD_SOUND DIALOGEX 0, 0, 300, 244 +IDD_SOUND DIALOGEX 0, 0, 300, 231 STYLE DS_SETFONT | DS_3DLOOK | DS_CONTROL | WS_CHILD FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN RTEXT "Sound device:",IDC_SOUNDCARD,8,9,51,13,SS_CENTERIMAGE COMBOBOX IDC_SOUNDCARDLIST,64,9,229,50,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Sound Emulation",IDC_SOUNDSETTINGS,5,30,120,68 + GROUPBOX "Sound Emulation",IDC_SOUNDSETTINGS,5,30,120,81 CONTROL "Disabled",IDC_SOUND0,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,13,45,43,10 CONTROL "Disabled, but emulated",IDC_SOUND1,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,13,57,88,10 CONTROL "Enabled",IDC_SOUND2,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,13,69,42,10 CONTROL "Enabled, 100% accurate",IDC_SOUND3,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,13,81,93,10 - GROUPBOX "Volume",IDC_STATIC,131,30,164,31 - CONTROL "",IDC_SOUNDVOLUME,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,137,38,105,20 - EDITTEXT IDC_SOUNDVOLUME2,247,41,40,12,ES_CENTER | ES_READONLY - GROUPBOX "Sound Buffer Size",IDC_STATIC,132,67,164,31 - CONTROL "Slider1",IDC_SOUNDBUFFERRAM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,138,75,106,19 - EDITTEXT IDC_SOUNDBUFFERMEM,248,78,40,12,ES_CENTER | ES_READONLY - GROUPBOX "Settings",IDC_SOUNDINTERPOLATION2,6,101,290,60 - LTEXT "Frequency:",IDC_SOUNDFREQTXT,11,111,37,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDFREQ,13,120,51,75,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP - LTEXT "Audio filter:",IDC_SOUNDFILTERTXT,209,135,34,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDFILTER,209,144,80,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Stereo mode:",IDC_SOUNDSTEREOTXT,74,111,41,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDSTEREO,73,120,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Interpolation:",IDC_SOUNDINTERPOLATIONTXT,209,111,41,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDINTERPOLATION,209,119,80,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Stereo separation:",IDC_SOUNDSTEREOSEPTXT,141,111,56,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDSTEREOSEP,142,120,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Stereo mixing delay:",IDC_SOUNDSTEREOMIXTXT,141,135,63,8,SS_CENTERIMAGE - COMBOBOX IDC_SOUNDSTEREOMIX,142,144,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Floppy Drive Sound Emulation",IDC_STATIC,6,164,290,46 - CONTROL "",IDC_SOUNDDRIVEVOLUME,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,14,172,107,19 - EDITTEXT IDC_SOUNDDRIVEVOLUME2,124,178,40,12,ES_CENTER | ES_READONLY - COMBOBOX IDC_SOUNDDRIVE,237,174,46,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_SOUNDDRIVESELECT,18,192,265,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Audio Driver Lag Compensation",IDC_STATIC,6,211,290,31 - CONTROL "Slider1",IDC_SOUNDADJUST,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,14,221,107,19 - EDITTEXT IDC_SOUNDADJUSTNUM,124,224,40,12,ES_CENTER | ES_READONLY - PUSHBUTTON "Calibrate",IDC_SOUNDCALIBRATE,183,223,40,14 - COMBOBOX IDC_SOUNDSWAP,73,144,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Swap channels:",IDC_SOUNDSWAPTXT,74,135,50,8,SS_CENTERIMAGE + GROUPBOX "Volume",IDC_STATIC,131,36,164,31 + CONTROL "",IDC_SOUNDVOLUME,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,137,44,105,20 + EDITTEXT IDC_SOUNDVOLUME2,247,47,40,12,ES_CENTER | ES_READONLY + GROUPBOX "Sound Buffer Size",IDC_STATIC,132,73,164,31 + CONTROL "Slider1",IDC_SOUNDBUFFERRAM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,138,81,106,19 + EDITTEXT IDC_SOUNDBUFFERMEM,248,84,40,12,ES_CENTER | ES_READONLY + GROUPBOX "Settings",IDC_SOUNDINTERPOLATION2,6,114,290,60 + LTEXT "Frequency:",IDC_SOUNDFREQTXT,11,124,37,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDFREQ,13,133,51,75,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP + LTEXT "Audio filter:",IDC_SOUNDFILTERTXT,209,148,34,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDFILTER,209,157,80,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Stereo mode:",IDC_SOUNDSTEREOTXT,74,124,41,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDSTEREO,73,133,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Interpolation:",IDC_SOUNDINTERPOLATIONTXT,209,124,41,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDINTERPOLATION,209,132,80,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Stereo separation:",IDC_SOUNDSTEREOSEPTXT,141,124,56,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDSTEREOSEP,142,133,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Stereo mixing delay:",IDC_SOUNDSTEREOMIXTXT,141,148,63,8,SS_CENTERIMAGE + COMBOBOX IDC_SOUNDSTEREOMIX,142,157,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Floppy Drive Sound Emulation",IDC_STATIC,6,177,290,46 + CONTROL "",IDC_SOUNDDRIVEVOLUME,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,14,185,107,19 + EDITTEXT IDC_SOUNDDRIVEVOLUME2,124,191,40,12,ES_CENTER | ES_READONLY + COMBOBOX IDC_SOUNDDRIVE,237,187,46,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SOUNDDRIVESELECT,18,205,265,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SOUNDSWAP,73,157,62,75,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Swap channels:",IDC_SOUNDSWAPTXT,74,148,50,8,SS_CENTERIMAGE + CONTROL "Automatic switching",IDC_SOUND_AUTO,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_GROUP | WS_TABSTOP,14,95,103,10 END IDD_LOADSAVE DIALOGEX 0, 0, 302, 241 @@ -744,7 +741,7 @@ GUIDELINES DESIGNINFO BEGIN IDD_SOUND, DIALOG BEGIN - BOTTOMMARGIN, 243 + BOTTOMMARGIN, 230 END IDD_LOADSAVE, DIALOG diff --git a/od-win32/sounddep/sound.c b/od-win32/sounddep/sound.c index 864d622c..1ca59f0b 100755 --- a/od-win32/sounddep/sound.c +++ b/od-win32/sounddep/sound.c @@ -43,15 +43,15 @@ static int have_sound; static int paused; static int mute; -#define SND_MAX_BUFFER2 262144 -#define SND_MAX_BUFFER 512 +#define SND_MAX_BUFFER2 524288 +#define SND_MAX_BUFFER 8192 uae_u16 sndbuffer[SND_MAX_BUFFER]; uae_u16 *sndbufpt; int sndbufsize; static int max_sndbufsize, snd_configsize, dsoundbuf; -static int snd_writeoffset, snd_maxoffset, snd_totalmaxoffset; +static int snd_writeoffset, snd_maxoffset, snd_totalmaxoffset_uf, snd_totalmaxoffset_of; static int waiting_for_buffer; static uae_sem_t sound_sem, sound_init_sem; @@ -94,7 +94,7 @@ void update_sound (int freq) } } -static void clearbuffer (void) +static void cleardsbuffer (void) { void *buffer; DWORD size; @@ -110,7 +110,6 @@ static void clearbuffer (void) } memset (buffer, 0, size); IDirectSoundBuffer_Unlock (lpDSBsecondary, buffer, size, NULL, 0); - memset (sndbuffer, 0, sizeof (sndbuffer)); } static void pause_audio_ds (void) @@ -118,13 +117,13 @@ static void pause_audio_ds (void) waiting_for_buffer = 0; IDirectSoundBuffer_Stop (lpDSBsecondary); IDirectSoundBuffer_SetCurrentPosition (lpDSBsecondary, 0); - clearbuffer (); + cleardsbuffer (); } static void resume_audio_ds (void) { paused = 0; - clearbuffer (); + cleardsbuffer (); waiting_for_buffer = 1; } @@ -169,49 +168,6 @@ static int getpos (void) return playpos; } -static int calibrate (void) -{ - int len = 1000; - int pos, lastpos, tpos, expected, diff; - int mult = (currprefs.sound_stereo == 3) ? 8 : (currprefs.sound_stereo ? 4 : 2); - double qv, pct; - HRESULT hr; - - if (!QueryPerformanceFrequency(&qpf)) { - write_log ("SOUND: no QPF, can't calibrate\n"); - return 100 * 10; - } - pos = 1000; - pause_audio_ds (); - resume_audio_ds (); - hr = IDirectSoundBuffer_Play (lpDSBsecondary, 0, 0, DSBPLAY_LOOPING); - if (FAILED(hr)) - return 100 * 10; - while (pos >= 1000) - pos = getpos(); - while (pos < 1000) - pos = getpos(); - lastpos = getpos(); - storeqpf (); - tpos = 0; - do { - pos = getpos(); - if (pos < lastpos) { - tpos += dsoundbuf - lastpos + pos; - } else { - tpos += pos - lastpos; - } - lastpos = pos; - qv = getqpf(); - } while (qv < len); - expected = (int)(len / 1000.0 * currprefs.sound_freq); - tpos /= mult; - diff = tpos - expected; - pct = tpos * 100.0 / expected; - write_log ("SOUND: calibration: %d %d (%d %.2f%%)\n", tpos, expected, diff, pct); - return (int)(pct * 10); -} - static void close_audio_ds (void) { waiting_for_buffer = 0; @@ -339,7 +295,8 @@ static int open_audio_ds (int size) snd_writeoffset = max_sndbufsize * 3 / 4; snd_maxoffset = max_sndbufsize; - snd_totalmaxoffset = max_sndbufsize + (dsoundbuf - max_sndbufsize) / 2; + snd_totalmaxoffset_of = max_sndbufsize + (dsoundbuf - max_sndbufsize) / 3; + snd_totalmaxoffset_uf = max_sndbufsize + (dsoundbuf - max_sndbufsize) * 2 / 3; memset (&sound_buffer, 0, sizeof (sound_buffer)); sound_buffer.dwSize = sizeof (sound_buffer); @@ -366,7 +323,7 @@ static int open_audio_ds (int size) goto error; } setvolume (); - clearbuffer (); + cleardsbuffer (); init_sound_table16 (); if (currprefs.sound_stereo == 3) sample_handler = sample16ss_handler; @@ -447,7 +404,7 @@ void pause_sound (void) if (!have_sound) return; pause_audio_ds (); - clearbuffer(); + cleardsbuffer(); } void resume_sound (void) @@ -456,7 +413,7 @@ void resume_sound (void) return; if (!have_sound) return; - clearbuffer (); + cleardsbuffer (); resume_audio_ds (); } @@ -464,7 +421,7 @@ void reset_sound (void) { if (!have_sound) return; - clearbuffer (); + cleardsbuffer (); } #ifdef JIT @@ -482,7 +439,7 @@ void sound_setadjust (double v) { double mult; - mult = (1000.0 + currprefs.sound_adjust + v); + mult = (1000.0 + v); if ((currprefs.gfx_vsync && currprefs.gfx_afullscreen) || (avioutput_audio && !compiled_code)) { vsynctime = vsynctime_orig; scaled_sample_evtime = (long)(((double)scaled_sample_evtime_orig) * mult / 1000.0); @@ -514,6 +471,8 @@ void restart_sound_buffer(void) writepos -= dsoundbuf; } +#define cf(x) if ((x) >= dsoundbuf) (x) -= dsoundbuf; + static void finish_sound_buffer_ds (void) { DWORD playpos, safepos, status; @@ -530,6 +489,8 @@ static void finish_sound_buffer_ds (void) if (statuscnt == 0) gui_data.sndbuf_status = 0; } + if (gui_data.sndbuf_status == 3) + gui_data.sndbuf_status = 0; if (!waiting_for_buffer) return; @@ -552,16 +513,22 @@ static void finish_sound_buffer_ds (void) return; } safedist -= playpos; + safedist += sndbufsize; if (safedist < 0) safedist += dsoundbuf; - safedist += sndbufsize; - snd_totalmaxoffset += safedist; + cf(safedist); + snd_totalmaxoffset_uf += safedist; + cf (snd_totalmaxoffset_uf); + snd_totalmaxoffset_of += safedist; + cf (snd_totalmaxoffset_of); snd_maxoffset += safedist; + cf (snd_maxoffset); snd_writeoffset += safedist; + cf (snd_writeoffset); waiting_for_buffer = -1; restart_sound_buffer(); - write_log("SOUND: safedist=%d snd_total=%d snd_max=%d snd_write=%d\n", - safedist, snd_totalmaxoffset, snd_maxoffset, snd_writeoffset); + write_log("SOUND: safe=%d w=%d max=%d tof=%d tuf=%d\n", + safedist, snd_writeoffset, snd_maxoffset, snd_totalmaxoffset_of, snd_totalmaxoffset_uf); } hr = IDirectSoundBuffer_GetStatus (lpDSBsecondary, &status); @@ -592,7 +559,7 @@ static void finish_sound_buffer_ds (void) else diff = dsoundbuf - playpos + writepos; - if (diff < safedist) { + if (diff < safedist || diff > snd_totalmaxoffset_uf) { hr = IDirectSoundBuffer_Lock (lpDSBsecondary, writepos, safedist, &b1, &s1, &b2, &s2, 0); if (SUCCEEDED(hr)) { memset (b1, 0, s1); @@ -603,17 +570,15 @@ static void finish_sound_buffer_ds (void) gui_data.sndbuf_status = -1; statuscnt = SND_STATUSCNT; writepos += safedist; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; + cf(writepos); break; } - if (diff > snd_totalmaxoffset) { + if (diff > snd_totalmaxoffset_of) { gui_data.sndbuf_status = 2; statuscnt = SND_STATUSCNT; writepos = safepos + snd_writeoffset; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; + cf(writepos); diff = snd_writeoffset; break; } @@ -666,10 +631,10 @@ static void finish_sound_buffer_ds (void) } writepos += sndbufsize; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; + cf(writepos); - sound_setadjust (skipmode); + if (!avioutput_audio) + sound_setadjust (skipmode); gui_data.sndbuf = vdiff * 1000 / snd_maxoffset; } @@ -729,26 +694,6 @@ char **enumerate_sound_devices (int *total) return 0; } -int sound_calibrate (HWND hwnd, struct uae_prefs *p) -{ - HWND old = hMainWnd; - int pct = 100 * 10; - - hMainWnd = hwnd; - currprefs.sound_freq = p->sound_freq; - currprefs.sound_stereo = p->sound_stereo; - if (open_sound ()) { - SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_HIGHEST); - pct = calibrate (); - SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_NORMAL); - close_sound (); - } - if (pct > 995 && pct < 1005) - pct = 1000; - hMainWnd = old; - return pct; -} - void sound_volume (int dir) { if (dir == 0) diff --git a/od-win32/sounddep/sound3.c b/od-win32/sounddep/sound3.c deleted file mode 100755 index c9cc9a17..00000000 --- a/od-win32/sounddep/sound3.c +++ /dev/null @@ -1,856 +0,0 @@ - /* - * UAE - The Un*x Amiga Emulator - * - * Win32 sound interface (DirectSound) - * - * Copyright 1997 Mathias Ortmann - * Copyright 1997-2001 Brian King - * Copyright 2000-2002 Bernd Roesch - * Copyright 2002-2003 Toni Wilen - */ - -#include "sysconfig.h" -#include "sysdeps.h" - -#include "options.h" -#include "memory.h" -#include "events.h" -#include "custom.h" -#include "gensound.h" -#include "sounddep/sound.h" -#include "threaddep/thread.h" -#include "avioutput.h" -#include "gui.h" -#include "dxwrap.h" -#include "win32.h" -#include "savestate.h" -#include "driveclick.h" -#include "audio.h" - -#include -#include -#include -#include - -#include - -#define ADJUST_SIZE 10 -#define EXP 1.3 - -static int sndbuffer_slot_size = 4000; -static int sndbuffer_slot_num = 16; - -//#define SOUND_DEBUG - -static int obtainedfreq; -static int have_sound; -static int paused; -static int mute; - -static int sndbuffer_size; - -uae_u16 sndbuffer[262144]; -uae_u16 *sndbufpt; -int sndbufsize; - -static uae_sem_t sound_sem, sound_init_sem; - -#define MAX_SOUND_DEVICES 10 - -static char *sound_devices[MAX_SOUND_DEVICES]; -GUID sound_device_guid[MAX_SOUND_DEVICES]; -static int num_sound_devices; - -static LPDIRECTSOUND8 lpDS; -static LPDIRECTSOUNDBUFFER lpDSBprimary; -static LPDIRECTSOUNDBUFFER8 lpDSBsecondary; - -int setup_sound (void) -{ - sound_available = 1; - return 1; -} - -int scaled_sample_evtime_orig; -static int lastfreq; -void update_sound (int freq) -{ - if (freq < 0) - freq = lastfreq; - lastfreq = freq; - if (have_sound) { - if ((currprefs.gfx_vsync && currprefs.gfx_afullscreen) || currprefs.chipset_refreshrate) { - if (currprefs.ntscmode) - scaled_sample_evtime_orig = (unsigned long)(MAXHPOS_NTSC * MAXVPOS_NTSC * freq * CYCLE_UNIT + obtainedfreq - 1) / obtainedfreq; - else - scaled_sample_evtime_orig = (unsigned long)(MAXHPOS_PAL * MAXVPOS_PAL * freq * CYCLE_UNIT + obtainedfreq - 1) / obtainedfreq; - } else { - scaled_sample_evtime_orig = (unsigned long)(312.0 * 50 * CYCLE_UNIT / (obtainedfreq / 227.5)); - } - scaled_sample_evtime = scaled_sample_evtime_orig; - } -} - -static int prevplayslot, writeslot, writeoffset; -uae_sem_t audiosem; - -static void clearbuffer (void) -{ - void *buffer; - DWORD size; - HRESULT hr; - - uae_sem_wait(&audiosem); - prevplayslot = 0; - writeslot = sndbuffer_slot_num / 3 + 2; - memset (sndbuffer, 0, sndbuffer_size); - hr = IDirectSoundBuffer_Lock (lpDSBsecondary, 0, sndbuffer_size, &buffer, &size, NULL, NULL, 0); - if (hr == DSERR_BUFFERLOST) { - IDirectSoundBuffer_Restore (lpDSBsecondary); - hr = IDirectSoundBuffer_Lock (lpDSBsecondary, 0, sndbuffer_size, &buffer, &size, NULL, NULL, 0); - } - if (FAILED(hr)) { - write_log ("SOUND: failed to Lock sound buffer (clear): %s\n", DXError (hr)); - uae_sem_post(&audiosem); - return; - } - memset (buffer, 0, size); - IDirectSoundBuffer_Unlock (lpDSBsecondary, buffer, size, NULL, 0); - uae_sem_post(&audiosem); -} - -static void pause_audio_ds (void) -{ - IDirectSoundBuffer_Stop (lpDSBsecondary); - clearbuffer (); -} - -static void resume_audio_ds (void) -{ - HRESULT hr; - - paused = 0; - clearbuffer (); - hr = IDirectSoundBuffer_SetCurrentPosition (lpDSBsecondary, 0); - hr = IDirectSoundBuffer_Play (lpDSBsecondary, 0, 0, DSBPLAY_LOOPING); - if (FAILED(hr)) - write_log ("SOUND: play failed: %s\n", DXError (hr)); -} - -static int restore (DWORD hr) -{ - if (hr != DSERR_BUFFERLOST) - return 0; -#ifdef SOUND_DEBUG - write_log ("sound buffer lost\n"); -#endif - hr = IDirectSoundBuffer_Restore (lpDSBsecondary); - if (FAILED(hr)) { - write_log ("SOUND: restore failed %s\n", DXError (hr)); - return 1; - } - pause_audio_ds (); - resume_audio_ds (); - return 1; -} - -static LARGE_INTEGER qpfc, qpf; -static void storeqpf (void) -{ - QueryPerformanceCounter(&qpfc); -} -static double getqpf (void) -{ - LARGE_INTEGER qpfc2; - QueryPerformanceCounter(&qpfc2); - return (qpfc2.QuadPart - qpfc.QuadPart) / (qpf.QuadPart / 1000.0); -} - -static int getpos (void) -{ - DWORD playpos, safepos; - HRESULT hr; - - hr = IDirectSoundBuffer_GetCurrentPosition (lpDSBsecondary, &playpos, &safepos); - if (FAILED(hr)) { - write_log ("SOUND: GetCurrentPosition failed: %s\n", DXError (hr)); - return -1; - } - return playpos; -} - -static int calibrate (void) -{ - int len = 1000; - int pos, lastpos, tpos, expected, diff; - int mult = (currprefs.sound_stereo == 3) ? 8 : (currprefs.sound_stereo ? 4 : 2); - double qv, pct; - - if (!QueryPerformanceFrequency(&qpf)) { - write_log ("SOUND: no QPF, can't calibrate\n"); - return 100 * 10; - } - pos = 1000; - pause_audio_ds (); - resume_audio_ds (); - while (pos >= 1000) - pos = getpos(); - while (pos < 1000) - pos = getpos(); - lastpos = getpos(); - storeqpf (); - tpos = 0; - do { - pos = getpos(); - if (pos < lastpos) { - tpos += sndbuffer_size - lastpos + pos; - } else { - tpos += pos - lastpos; - } - lastpos = pos; - qv = getqpf(); - } while (qv < len); - expected = (int)(len / 1000.0 * currprefs.sound_freq); - tpos /= mult; - diff = tpos - expected; - pct = tpos * 100.0 / expected; - write_log ("SOUND: calibration: %d %d (%d %.2f%%)\n", tpos, expected, diff, pct); - return (int)(pct * 10); -} - -extern HWND hMainWnd; - -static void setvolume (void) -{ - HRESULT hr; - LONG vol = DSBVOLUME_MIN; - - if (currprefs.sound_volume < 100 && !mute) - vol = (LONG)((DSBVOLUME_MIN / 2) + (-DSBVOLUME_MIN / 2) * log (1 + (2.718281828 - 1) * (1 - currprefs.sound_volume / 100.0))); - hr = IDirectSoundBuffer_SetVolume (lpDSBsecondary, vol); - if (FAILED(hr)) - write_log ("SOUND: SetVolume(%d) failed: %s\n", vol, DXError (hr)); -} - -static volatile int notificationthread_mode; -static HANDLE notifyevent, notifyevent2; - -static unsigned __stdcall notifythread(void *data) -{ - notificationthread_mode = 2; - write_log("SOUND: notificationthread running\n"); - while (notificationthread_mode == 2) { - HRESULT hr; - DWORD status, playpos, safepos; - int slot, cnt, incoming, usedslot; - void *b1, *b2; - DWORD s1, s2; - double skipmode; - - WaitForSingleObject(notifyevent, INFINITE); - if (!have_sound) - continue; - - uae_sem_wait (&audiosem); - hr = IDirectSoundBuffer_GetStatus (lpDSBsecondary, &status); - if (FAILED(hr)) { - write_log ("SOUND: GetStatus() failed: %s\n", DXError(hr)); - goto nreset; - } - if (status & DSBSTATUS_BUFFERLOST) { - write_log ("SOUND: buffer lost\n"); - restore (DSERR_BUFFERLOST); - goto nreset; - } - if ((status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) != (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) { - write_log ("SOUND: status = %08.8X\n", status); - restore (DSERR_BUFFERLOST); - goto nreset; - } - hr = IDirectSoundBuffer_GetCurrentPosition (lpDSBsecondary, &playpos, &safepos); - if (FAILED(hr)) { - write_log ("SOUND: GetCurrentPosition failed: %s\n", DXError (hr)); - restore (hr); - goto nreset; - } - slot = playpos / sndbuffer_slot_size; - - usedslot = prevplayslot; - while (slot != prevplayslot) { - if (writeslot == prevplayslot) { - write_log ("UF: missed\n"); - writeslot = prevplayslot + 1; - writeslot %= sndbuffer_slot_num; - writeoffset = 0; - } - prevplayslot++; - prevplayslot %= sndbuffer_slot_num; - } - - incoming = (uae_u8*)sndbufpt - (uae_u8*)sndbuffer; - //write_log ("%d.%d.%d.%d ", playslot, slot, writeslot, incoming); - //write_log ("%d ", incoming); - - // handle possible buffer underflow - if (slot == writeslot) { - writeslot++; - writeslot %= sndbuffer_slot_num; - if (incoming <= sndbuffer_slot_size) { - write_log ("UF: skipped\n"); - writeslot++; - writeslot %= sndbuffer_slot_num; - writeoffset = 0; - } else if (incoming < sndbuffer_slot_size + (sndbuffer_slot_size - writeoffset)) { - write_log ("UF: miniskip\n"); - writeoffset = sndbuffer_slot_size - (incoming - sndbuffer_slot_size); - } - } - - // copy new data if available - if (incoming > 0) { - IDirectSoundBuffer_Lock (lpDSBsecondary, writeslot * sndbuffer_slot_size + writeoffset, incoming, - &b1, &s1, &b2, &s2, 0); - memcpy (b1, sndbuffer, s1); - if (b2) - memcpy (b2, (uae_u8*)sndbuffer + s1, s2); - IDirectSoundBuffer_Unlock (lpDSBsecondary, b1, s1, b2, s2); - writeslot += (writeoffset + incoming) / sndbuffer_slot_size; - writeslot %= sndbuffer_slot_num; - writeoffset = (writeoffset + incoming) % sndbuffer_slot_size; - } - - // clear already played slot(s) - cnt = (usedslot >= slot ? sndbuffer_slot_num - usedslot + slot : slot - usedslot) - 1; - if (0 && cnt > 0) { - IDirectSoundBuffer_Lock (lpDSBsecondary, usedslot * sndbuffer_slot_size, cnt * sndbuffer_slot_size, - &b1, &s1, &b2, &s2, 0); - if (FAILED(hr)) { - write_log ("SOUND: lock failed: %s (%d %d)\n", DXError (hr), usedslot, cnt); - goto nreset; - } - memset (b1, 0, s1); - if (b2) - memset (b2, 0, s2); - IDirectSoundBuffer_Unlock (lpDSBsecondary, b1, s1, b2, s2); - } - - cnt = (writeslot > slot ? sndbuffer_slot_num - writeslot + slot : slot - writeslot) - 1; - write_log ("%d ", cnt); - if (cnt <= 0) - cnt = 0; - sndbufsize = cnt * sndbuffer_slot_size; - sndbufpt = sndbuffer; - uae_sem_post(&audiosem); - SetEvent(notifyevent2); - //sound_setadjust (-50); - continue; -nreset: - write_log ("SOUND: reset\n"); - sndbufpt = sndbuffer; - sndbufsize = sndbuffer_size; - clearbuffer(); - uae_sem_post(&audiosem); - SetEvent(notifyevent2); - continue; - } - write_log("SOUND: notificationthread exiting\n"); - notificationthread_mode = 4; - return 0; -} - -#if 0 - - DWORD playpos, safepos, status; - HRESULT hr; - void *b1, *b2; - DWORD s1, s2; - int diff; - int counter = 1000; - double vdiff, m, skipmode; - - hr = IDirectSoundBuffer_GetStatus (lpDSBsecondary, &status); - if (FAILED(hr)) { - write_log ("SOUND: GetStatus() failed: %s\n", DXError(hr)); - return; - } - if (status & DSBSTATUS_BUFFERLOST) { - write_log ("SOUND: buffer lost\n"); - restore (DSERR_BUFFERLOST); - return; - } - if ((status & (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) != (DSBSTATUS_PLAYING | DSBSTATUS_LOOPING)) { - write_log ("SOUND: status = %08.8X\n", status); - restore (DSERR_BUFFERLOST); - return; - } - for (;;) { - hr = IDirectSoundBuffer_GetCurrentPosition (lpDSBsecondary, &playpos, &safepos); - if (FAILED(hr)) { - restore (hr); - write_log ("SOUND: GetCurrentPosition failed: %s\n", DXError (hr)); - return; - } - - if (savestate_state) - return; - - if (writepos >= playpos) - diff = writepos - playpos; - else - diff = dsoundbuf - playpos + writepos; - - if (diff >= max_sndbufsize) { - writepos = safepos + snd_configsize; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; - diff = snd_configsize; - break; - } - - if (diff > max_sndbufsize * 6 / 8) { - sleep_millis_busy (1); - counter--; - if (counter < 0) { - write_log ("SOUND: sound system got stuck!?\n"); - restore (DSERR_BUFFERLOST); - return; - } - continue; - } - break; - } - - hr = IDirectSoundBuffer_Lock (lpDSBsecondary, writepos, sndbufsize, &b1, &s1, &b2, &s2, 0); - if (restore (hr)) - return; - if (FAILED(hr)) { - write_log ("SOUND: lock failed: %s (%d %d)\n", DXError (hr), writepos, sndbufsize); - return; - } - memcpy (b1, sndbuffer, sndbufsize >= s1 ? s1 : sndbufsize); - if (b2) - memcpy (b2, (uae_u8*)sndbuffer + s1, sndbufsize - s1); - IDirectSoundBuffer_Unlock (lpDSBsecondary, b1, s1, b2, s2); - - vdiff = diff - snd_configsize; - m = 100.0 * vdiff / max_sndbufsize; - skipmode = pow (m < 0 ? -m : m, EXP)/ 10.0; - - if (m < 0) skipmode = -skipmode; - if (skipmode < -ADJUST_SIZE) skipmode = -ADJUST_SIZE; - if (skipmode > ADJUST_SIZE) skipmode = ADJUST_SIZE; - -#ifdef SOUND_DEBUG - if (!(timeframes % 10)) { - write_log ("b=%5d,%5d,%5d,%5d diff=%5d vdiff=%5.0f vdiff2=%5d skip=%+02.1f\n", - sndbufsize, snd_configsize, max_sndbufsize, dsoundbuf, diff, vdiff, diff - snd_configsize, skipmode); - } -#endif - - writepos += sndbufsize; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; - - sound_setadjust (skipmode); -} - -#endif - -static void close_audio_ds (void) -{ - uae_sem_wait (&audiosem); - if (notificationthread_mode == 2) { - notificationthread_mode = 3; - SetEvent(notifyevent); - while (notificationthread_mode == 3) - Sleep(10); - notificationthread_mode = 0; - } - if (notifyevent) - CloseHandle(notifyevent); - notifyevent = NULL; - if (notifyevent2) - CloseHandle(notifyevent2); - notifyevent2 = NULL; - - if (lpDSBsecondary) - IDirectSound_Release (lpDSBsecondary); - if (lpDSBprimary) - IDirectSound_Release (lpDSBprimary); - lpDSBsecondary = 0; - lpDSBprimary = 0; - if (lpDS) { - IDirectSound_Release (lpDS); - write_log ("SOUND: DirectSound driver freed\n"); - } - lpDS = 0; - uae_sem_post (&audiosem); -} - -static int open_audio_ds (int size) -{ - int i; - HRESULT hr; - DSBUFFERDESC sound_buffer; - DSCAPS DSCaps; - DSBCAPS DSBCaps; - WAVEFORMATEX wavfmt; - int freq = currprefs.sound_freq; - LPDIRECTSOUNDBUFFER pdsb; - DSBPOSITIONNOTIFY *dsbpn; - LPDIRECTSOUNDNOTIFY8 lpDsNotify; - HANDLE thread; - unsigned ttid; - - enumerate_sound_devices (0); - if (currprefs.sound_stereo == 3) { - size <<= 3; - } else { - size <<= 1; - if (currprefs.sound_stereo) - size <<= 1; - } - sndbuffer_size = sndbuffer_slot_size * sndbuffer_slot_num; - sndbufsize = sndbuffer_size; - - hr = DirectSoundCreate8 (&sound_device_guid[currprefs.win32_soundcard], &lpDS, NULL); - if (FAILED(hr)) { - write_log ("SOUND: DirectSoundCreate() failure: %s\n", DXError (hr)); - return 0; - } - memset (&DSCaps, 0, sizeof (DSCaps)); - DSCaps.dwSize = sizeof (DSCaps); - hr = IDirectSound_GetCaps (lpDS, &DSCaps); - if (FAILED(hr)) { - write_log ("SOUND: Error getting DirectSound capabilities: %s\n", DXError (hr)); - goto error; - } - if (DSCaps.dwFlags & DSCAPS_EMULDRIVER) { - write_log ("SOUND: Emulated DirectSound driver detected, don't complain if sound quality is crap :)\n"); - } - if (DSCaps.dwFlags & DSCAPS_CONTINUOUSRATE) { - int minfreq = DSCaps.dwMinSecondarySampleRate; - int maxfreq = DSCaps.dwMaxSecondarySampleRate; - if (minfreq > freq && freq < 22050) { - freq = minfreq; - changed_prefs.sound_freq = currprefs.sound_freq = freq; - write_log("SOUND: minimum supported frequency: %d\n", minfreq); - } - if (maxfreq < freq && freq > 44100) { - freq = maxfreq; - changed_prefs.sound_freq = currprefs.sound_freq = freq; - write_log("SOUND: maximum supported frequency: %d\n", maxfreq); - } - } - - memset (&sound_buffer, 0, sizeof (sound_buffer)); - sound_buffer.dwSize = sizeof (sound_buffer); - sound_buffer.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2; - hr = IDirectSound_CreateSoundBuffer (lpDS, &sound_buffer, &lpDSBprimary, NULL); - if (FAILED(hr)) { - write_log ("SOUND: Primary CreateSoundBuffer() failure: %s\n", DXError (hr)); - goto error; - } - - memset(&DSBCaps, 0, sizeof(DSBCaps)); - DSBCaps.dwSize = sizeof(DSBCaps); - hr = IDirectSoundBuffer_GetCaps(lpDSBprimary, &DSBCaps); - if (FAILED(hr)) { - write_log ("SOUND: Primary GetCaps() failure: %s\n", DXError (hr)); - goto error; - } - - wavfmt.wFormatTag = WAVE_FORMAT_PCM; - wavfmt.nChannels = (currprefs.sound_stereo == 3 || currprefs.sound_stereo == 2) ? 4 : (currprefs.sound_stereo ? 2 : 1); - wavfmt.nSamplesPerSec = freq; - wavfmt.wBitsPerSample = 16; - wavfmt.nBlockAlign = 16 / 8 * wavfmt.nChannels; - wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * freq; - wavfmt.cbSize = 0; - - hr = IDirectSound_SetCooperativeLevel (lpDS, hMainWnd, DSSCL_PRIORITY); - if (FAILED(hr)) { - write_log ("SOUND: Can't set cooperativelevel: %s\n", DXError (hr)); - goto error; - } - - memset (&sound_buffer, 0, sizeof (sound_buffer)); - sound_buffer.dwSize = sizeof (sound_buffer); - sound_buffer.dwBufferBytes = sndbuffer_size; - sound_buffer.lpwfxFormat = &wavfmt; - sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; - sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPOSITIONNOTIFY; - - hr = IDirectSound_CreateSoundBuffer(lpDS, &sound_buffer, &pdsb, NULL); - if (FAILED(hr)) { - write_log ("SOUND: Secondary CreateSoundBuffer() failure: %s\n", DXError (hr)); - goto error; - } - hr = IDirectSound_QueryInterface(pdsb, &IID_IDirectSoundBuffer8, (LPVOID*)&lpDSBsecondary); - if (FAILED(hr)) { - write_log ("SOUND: QueryInterface(DirectSoundBuffer8) failure: %s\n", DXError (hr)); - goto error; - } - IDirectSound_Release(pdsb); - - hr = IDirectSoundBuffer_SetFormat (lpDSBprimary, &wavfmt); - if (FAILED(hr)) { - write_log ("SOUND: Primary SetFormat() failure: %s\n", DXError (hr)); - goto error; - } - - hr = IDirectSound_QueryInterface(lpDSBsecondary, &IID_IDirectSoundNotify8, (LPVOID*)&lpDsNotify); - if (FAILED(hr)) { - write_log ("SOUND: QueryInterface(DirectSoundNotify8) failed: %s\n", DXError (hr)); - goto error; - } - uae_sem_init(&audiosem, 0, 1); - notifyevent = CreateEvent(NULL, FALSE, FALSE, NULL); - notifyevent2 = CreateEvent(NULL, FALSE, FALSE, NULL); - dsbpn = xmalloc (sizeof (DSBPOSITIONNOTIFY) * sndbuffer_slot_num); - for (i = 0; i < sndbuffer_slot_num; i++) { - dsbpn[i].dwOffset = i * sndbuffer_slot_size; - dsbpn[i].hEventNotify = notifyevent; - } - IDirectSoundNotify_SetNotificationPositions(lpDsNotify, sndbuffer_slot_num, dsbpn); - IDirectSound_Release(lpDsNotify); - - notificationthread_mode = 1; - thread = (HANDLE)_beginthreadex(NULL, 0, notifythread, NULL, 0, &ttid); - if (thread == NULL) { - write_log(" SOUND: NotificationThread failed to start: %d\n", GetLastError()); - goto error; - } - SetThreadPriority (thread, THREAD_PRIORITY_HIGHEST); - SetThreadPriority (thread, THREAD_PRIORITY_TIME_CRITICAL); - - setvolume (); - clearbuffer (); - - init_sound_table16 (); - if (currprefs.sound_stereo == 3) - sample_handler = sample16ss_handler; - else - sample_handler = currprefs.sound_stereo ? sample16s_handler : sample16_handler; - - write_log ("DS driver '%s'/%d/%d bits/%d Hz/buffer %d*%d=%d\n", - sound_devices[currprefs.win32_soundcard], - currprefs.sound_stereo, - 16, freq, sndbuffer_slot_num, sndbuffer_slot_size, sndbuffer_size); - obtainedfreq = currprefs.sound_freq; - - return 1; - -error: - close_audio_ds (); - return 0; -} - -static int open_sound (void) -{ - int ret; - int size = currprefs.sound_maxbsiz; - - if (!currprefs.produce_sound) - return 0; - /* Always interpret buffer size as number of samples, not as actual - buffer size. Of course, since 8192 is the default, we'll have to - scale that to a sane value (assuming that otherwise 16 bits and - stereo would have been enabled and we'd have done the shift by - two anyway). */ - size >>= 2; - if (size & (size - 1)) - size = DEFAULT_SOUND_MAXB; - if (size < 512) - size = 512; - - ret = open_audio_ds (size); - if (!ret) - return 0; - - have_sound = 1; - sound_available = 1; - update_sound (fake_vblank_hz); - sndbufpt = sndbuffer; - driveclick_init (); - - return 1; -} - -void close_sound (void) -{ - if (! have_sound) - return; - have_sound = 0; - pause_sound (); - close_audio_ds (); -} - -int init_sound (void) -{ - if (have_sound) - return 1; - if (!open_sound ()) - return 0; - paused = 1; - driveclick_reset (); - resume_sound (); - return 1; -} - -void pause_sound (void) -{ - if (paused) - return; - paused = 1; - if (!have_sound) - return; - pause_audio_ds (); - clearbuffer(); -} - -void resume_sound (void) -{ - if (!paused) - return; - if (!have_sound) - return; - clearbuffer (); - resume_audio_ds (); -} - -void reset_sound (void) -{ - if (!have_sound) - return; - clearbuffer (); -} - -#ifdef JIT -extern uae_u8* compiled_code; -#else -static int compiled_code; -#endif -extern int vsynctime_orig; - -#ifndef AVIOUTPUT -static int avioutput_audio; -#endif - -void sound_setadjust (double v) -{ - double mult; - - mult = (1000.0 + currprefs.sound_adjust + v); - if ((currprefs.gfx_vsync && currprefs.gfx_afullscreen) || (avioutput_audio && !compiled_code)) { - vsynctime = vsynctime_orig; - scaled_sample_evtime = (long)(((double)scaled_sample_evtime_orig) * mult / 1000.0); - } else if (compiled_code || currprefs.m68k_speed != 0) { - vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); - scaled_sample_evtime = scaled_sample_evtime_orig; - } else { - vsynctime = (long)(((double)vsynctime_orig) * mult / 1000.0); - scaled_sample_evtime = scaled_sample_evtime_orig; - } -} - -static void finish_sound_buffer_ds (void) -{ - uae_sem_post(&audiosem); - ResetEvent(notifyevent2); - for (;;) { - SetEvent(notifyevent); - WaitForSingleObject(notifyevent2, INFINITE); - if (sndbufpt == sndbuffer && sndbufsize > 0) - break; - } - uae_sem_wait(&audiosem); -} - -static void channelswap(uae_s16 *sndbuffer, int len) -{ - int i; - for (i = 0; i < len; i += 2) { - uae_s16 t = sndbuffer[i]; - sndbuffer[i] = sndbuffer[i + 1]; - sndbuffer[i + 1] = t; - } -} - -void finish_sound_buffer (void) -{ - if (turbo_emulation) - return; - if (ISSTEREO(currprefs) && currprefs.sound_stereo_swap_paula) - channelswap((uae_s16*)sndbuffer, sndbufsize / 2); -#ifdef DRIVESOUND - driveclick_mix ((uae_s16*)sndbuffer, sndbufsize / 2); -#endif -#ifdef AVIOUTPUT - if (avioutput_audio) - AVIOutput_WriteAudio ((uae_u8*)sndbuffer, sndbufsize); - if (avioutput_enabled && (!avioutput_framelimiter || avioutput_nosoundoutput)) - return; -#endif - if (!have_sound) - return; - finish_sound_buffer_ds (); -} - -static BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) -{ - int i = num_sound_devices; - if (i == MAX_SOUND_DEVICES) - return TRUE; - if (lpGUID != NULL) - memcpy (&sound_device_guid[i], lpGUID, sizeof (GUID)); - sound_devices[i] = my_strdup (lpszDesc); - num_sound_devices++; - return TRUE; -} - -char **enumerate_sound_devices (int *total) -{ - if (!num_sound_devices) - DirectSoundEnumerate ((LPDSENUMCALLBACK)DSEnumProc, 0); - if (total) - *total = num_sound_devices; - if (currprefs.win32_soundcard >= num_sound_devices) - currprefs.win32_soundcard = 0; - if (num_sound_devices) - return sound_devices; - return 0; -} - -int sound_calibrate (HWND hwnd, struct uae_prefs *p) -{ - HWND old = hMainWnd; - int pct = 100 * 10; - - hMainWnd = hwnd; - currprefs.sound_freq = p->sound_freq; - currprefs.sound_stereo = p->sound_stereo; - if (open_sound ()) { - SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_HIGHEST); - pct = calibrate (); - SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_NORMAL); - close_sound (); - } - if (pct > 995 && pct < 1005) - pct = 1000; - hMainWnd = old; - return pct; -} - -void sound_volume (int dir) -{ - if (dir == 0) - mute = mute ? 0 : 1; - currprefs.sound_volume -= dir * 10; - if (currprefs.sound_volume < 0) - currprefs.sound_volume = 0; - if (currprefs.sound_volume > 100) - currprefs.sound_volume = 100; - changed_prefs.sound_volume = currprefs.sound_volume; - setvolume (); -} diff --git a/od-win32/win32.c b/od-win32/win32.c index 21c5f73d..2000cc04 100755 --- a/od-win32/win32.c +++ b/od-win32/win32.c @@ -2807,12 +2807,12 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin DWORD_PTR oldaff; thread = GetCurrentThread(); - //oldaff = SetThreadAffinityMask(thread, 1); + oldaff = SetThreadAffinityMask(thread, 1); __try { WinMain2 (hInstance, hPrevInstance, lpCmdLine, nCmdShow); } __except(ExceptionFilter(GetExceptionInformation(), GetExceptionCode())) { } - //SetThreadAffinityMask(thread, oldaff); + SetThreadAffinityMask(thread, oldaff); return FALSE; } diff --git a/od-win32/win32.h b/od-win32/win32.h index 45f70315..b6af09da 100755 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -22,7 +22,7 @@ extern int manual_palette_refresh_needed; extern int mouseactive, focus; extern int ignore_messages_all; #define WINUAEBETA 1 -#define WINUAEBETASTR " Beta 3" +#define WINUAEBETASTR " Beta 4" extern char start_path_exe[MAX_DPATH]; extern char start_path_data[MAX_DPATH]; diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index 93aef605..f1d34960 100755 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -71,6 +71,7 @@ #include "catweasel.h" #include "lcd.h" #include "uaeipc.h" +#include "crc32.h" #define DISK_FORMAT_STRING "(*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.exe)\0*.adf;*.adz;*.gz;*.dms;*.fdi;*.ipf;*.zip;*.rar;*.7z;*.exe;*.ima\0" #define ROM_FORMAT_STRING "(*.rom;*.roz)\0*.rom;*.zip;*.rar;*.7z;*.roz\0" @@ -399,8 +400,10 @@ static struct romdata *scan_single_rom_2 (struct zfile *f, uae_u8 *keybuf, int k zfile_fseek (f, 0, SEEK_END); size = zfile_ftell (f); zfile_fseek (f, 0, SEEK_SET); - if (size > 1760 * 512) /* don't skip KICK disks */ + if (size > 1760 * 512) {/* don't skip KICK disks */ + write_log ("'%s': too big %d, ignored\n", zfile_getname(f), size); return 0; + } zfile_fread (buffer, 1, 11, f); if (!memcmp (buffer, "KICK", 4)) { zfile_fseek (f, 512, SEEK_SET); @@ -424,6 +427,9 @@ static struct romdata *scan_single_rom_2 (struct zfile *f, uae_u8 *keybuf, int k } if (!cl) rd = getromdatabydata (rombuf, size); + if (!rd) + write_log ("'%s' %d, unknown CRC32 %04.4x\n", + zfile_getname(f), size, get_crc32(rombuf, size)); free (rombuf); return rd; } @@ -1700,7 +1706,6 @@ static int disk_swap (int entry, int mode) if ((drv = disk_in_drive (entry)) >= 0) { if (mode < 0) { workprefs.df[drv][0] = 0; - disk_eject (drv); return 1; } @@ -1709,7 +1714,6 @@ static int disk_swap (int entry, int mode) disk_insert (drv, workprefs.df[drv]); } else { workprefs.df[drv][0] = 0; - disk_eject (drv); } if (drvs[0] < 0 || drvs[1] < 0 || drvs[2] < 0 || drvs[3] < 0) { drv++; @@ -5170,23 +5174,15 @@ static void update_soundgui (HWND hDlg) char txt[20]; bufsize = exact_log2 (workprefs.sound_maxbsiz / 1024); - sprintf (txt, "%d (%dms)", bufsize, 1000 * (workprefs.sound_maxbsiz >> 1) / workprefs.sound_freq ); + sprintf (txt, "%d (%dms)", + bufsize, ((1000 * (workprefs.sound_maxbsiz >> 1) / workprefs.sound_freq) + 30) / 10 * 10); SetDlgItemText (hDlg, IDC_SOUNDBUFFERMEM, txt); - if (workprefs.sound_adjust < -100) - workprefs.sound_adjust = -100; - if (workprefs.sound_adjust > 30) - workprefs.sound_adjust = 30; - SendDlgItemMessage( hDlg, IDC_SOUNDADJUST, TBM_SETPOS, TRUE, workprefs.sound_adjust ); - - sprintf (txt, "%.1f%%", workprefs.sound_adjust / 10.0); - SetDlgItemText (hDlg, IDC_SOUNDADJUSTNUM, txt); - - SendDlgItemMessage( hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.sound_volume ); + SendDlgItemMessage( hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.sound_volume); sprintf (txt, "%d%%", 100 - workprefs.sound_volume); SetDlgItemText (hDlg, IDC_SOUNDVOLUME2, txt); - SendDlgItemMessage( hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume ); + SendDlgItemMessage( hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 100 - workprefs.dfxclickvolume); sprintf (txt, "%d%%", 100 - workprefs.dfxclickvolume); SetDlgItemText (hDlg, IDC_SOUNDDRIVEVOLUME2, txt); } @@ -5267,7 +5263,8 @@ static void values_to_sounddlg (HWND hDlg) sprintf (txt, "%d", i + 1); SendDlgItemMessage(hDlg, IDC_SOUNDSTEREOMIX, CB_ADDSTRING, 0, (LPARAM)txt); } - SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_SETCURSEL, workprefs.sound_mixed_stereo > 0 ? workprefs.sound_mixed_stereo : 0, 0); + SendDlgItemMessage (hDlg, IDC_SOUNDSTEREOMIX, CB_SETCURSEL, + workprefs.sound_mixed_stereo > 0 ? workprefs.sound_mixed_stereo : 0, 0); SendDlgItemMessage(hDlg, IDC_SOUNDINTERPOLATION, CB_RESETCONTENT, 0, 0); WIN32GUI_LoadUIString (IDS_SOUND_INTERPOL_DISABLED, txt, sizeof (txt)); @@ -5289,7 +5286,7 @@ static void values_to_sounddlg (HWND hDlg) i++; } sprintf (txt, "%d", workprefs.sound_freq); - SendDlgItemMessage( hDlg, IDC_SOUNDFREQ, WM_SETTEXT, 0, (LPARAM)txt); + SendDlgItemMessage(hDlg, IDC_SOUNDFREQ, WM_SETTEXT, 0, (LPARAM)txt); switch (workprefs.produce_sound) { case 0: which_button = IDC_SOUND0; break; @@ -5297,17 +5294,19 @@ static void values_to_sounddlg (HWND hDlg) case 2: which_button = IDC_SOUND2; break; case 3: which_button = IDC_SOUND3; break; } - CheckRadioButton( hDlg, IDC_SOUND0, IDC_SOUND3, which_button ); + CheckRadioButton(hDlg, IDC_SOUND0, IDC_SOUND3, which_button); + + CheckDlgButton(hDlg, IDC_SOUND_AUTO, workprefs.sound_auto); workprefs.sound_maxbsiz = 1 << exact_log2 (workprefs.sound_maxbsiz); if (workprefs.sound_maxbsiz < 2048) workprefs.sound_maxbsiz = 2048; - SendDlgItemMessage( hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, exact_log2 (workprefs.sound_maxbsiz / 2048)); + SendDlgItemMessage(hDlg, IDC_SOUNDBUFFERRAM, TBM_SETPOS, TRUE, exact_log2 (workprefs.sound_maxbsiz / 2048)); - SendDlgItemMessage( hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 0); - SendDlgItemMessage( hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 0); + SendDlgItemMessage(hDlg, IDC_SOUNDVOLUME, TBM_SETPOS, TRUE, 0); + SendDlgItemMessage(hDlg, IDC_SOUNDDRIVEVOLUME, TBM_SETPOS, TRUE, 0); - SendDlgItemMessage( hDlg, IDC_SOUNDCARDLIST, CB_SETCURSEL, workprefs.win32_soundcard, 0 ); + SendDlgItemMessage(hDlg, IDC_SOUNDCARDLIST, CB_SETCURSEL, workprefs.win32_soundcard, 0); idx = SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_GETCURSEL, 0, 0); if (idx < 0) @@ -5315,7 +5314,7 @@ static void values_to_sounddlg (HWND hDlg) SendDlgItemMessage(hDlg, IDC_SOUNDDRIVE, CB_RESETCONTENT, 0, 0); for (i = 0; i < 4; i++) { sprintf (txt, "DF%d:", i); - SendDlgItemMessage( hDlg, IDC_SOUNDDRIVE, CB_ADDSTRING, 0, (LPARAM)txt); + SendDlgItemMessage(hDlg, IDC_SOUNDDRIVE, CB_ADDSTRING, 0, (LPARAM)txt); } SendDlgItemMessage (hDlg, IDC_SOUNDDRIVE, CB_SETCURSEL, idx, 0); SendDlgItemMessage(hDlg, IDC_SOUNDDRIVESELECT, CB_RESETCONTENT, 0, 0); @@ -5378,6 +5377,9 @@ static void values_from_sounddlg (HWND hDlg) workprefs.produce_sound = (IsDlgButtonChecked (hDlg, IDC_SOUND0) ? 0 : IsDlgButtonChecked (hDlg, IDC_SOUND1) ? 1 : IsDlgButtonChecked (hDlg, IDC_SOUND2) ? 2 : 3); + + workprefs.sound_auto = IsDlgButtonChecked (hDlg, IDC_SOUND_AUTO) ? 1 : 0; + idx = SendDlgItemMessage (hDlg, IDC_SOUNDSTEREO, CB_GETCURSEL, 0, 0); if (idx != CB_ERR) workprefs.sound_stereo = idx; @@ -5487,11 +5489,7 @@ static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM if (recursive > 0) break; recursive++; - if (LOWORD (wParam) == IDC_SOUNDCALIBRATE) { - int pct = sound_calibrate (hDlg, &workprefs); - workprefs.sound_adjust = (pct - 1000); - update_soundgui (hDlg); - } else if(LOWORD (wParam) == IDC_SOUNDDRIVE) { + if(LOWORD (wParam) == IDC_SOUNDDRIVE) { values_to_sounddlg (hDlg); } values_from_sounddlg (hDlg); @@ -5501,7 +5499,6 @@ static INT_PTR CALLBACK SoundDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM case WM_HSCROLL: workprefs.sound_maxbsiz = 2048 << SendMessage(GetDlgItem(hDlg, IDC_SOUNDBUFFERRAM), TBM_GETPOS, 0, 0); - workprefs.sound_adjust = SendMessage(GetDlgItem(hDlg, IDC_SOUNDADJUST), TBM_GETPOS, 0, 0); workprefs.sound_volume = 100 - SendMessage(GetDlgItem(hDlg, IDC_SOUNDVOLUME), TBM_GETPOS, 0, 0); workprefs.dfxclickvolume = 100 - SendMessage(GetDlgItem(hDlg, IDC_SOUNDDRIVEVOLUME), TBM_GETPOS, 0, 0); update_soundgui (hDlg); @@ -6541,7 +6538,6 @@ static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA break; case IDC_EJECT0: case IDC_EJECT0Q: - disk_eject(0); SetDlgItemText (hDlg, IDC_DF0TEXT, ""); SetDlgItemText (hDlg, IDC_DF0TEXTQ, ""); workprefs.df[0][0] = 0; @@ -6549,20 +6545,17 @@ static INT_PTR CALLBACK FloppyDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA break; case IDC_EJECT1: case IDC_EJECT1Q: - disk_eject(1); SetDlgItemText (hDlg, IDC_DF1TEXT, ""); SetDlgItemText (hDlg, IDC_DF1TEXTQ, ""); workprefs.df[1][0] = 0; addfloppytype (hDlg, 1); break; case IDC_EJECT2: - disk_eject(2); SetDlgItemText (hDlg, IDC_DF2TEXT, ""); workprefs.df[2][0] = 0; addfloppytype (hDlg, 2); break; case IDC_EJECT3: - disk_eject(3); SetDlgItemText (hDlg, IDC_DF3TEXT, ""); workprefs.df[3][0] = 0; addfloppytype (hDlg, 3); @@ -6745,10 +6738,8 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR int i; if (workprefs.dfxtype[drv] >= 0 && entry >= 0) { for (i = 0; i < 4; i++) { - if (!strcmp (workprefs.df[i], workprefs.dfxlist[entry])) { + if (!strcmp (workprefs.df[i], workprefs.dfxlist[entry])) workprefs.df[i][0] = 0; - disk_eject (i); - } } strcpy (workprefs.df[drv], workprefs.dfxlist[entry]); disk_insert (drv, workprefs.df[drv]); @@ -6763,7 +6754,7 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR case 10208: { int drv = LOWORD (wParam) - 10201; - disk_eject (drv); + workprefs.df[drv][0] = 0; InitializeListView (hDlg); swapperhili (hDlg, entry); } @@ -9371,7 +9362,7 @@ void gui_led (int led, int on) if (gui_data.sndbuf_status < 3) { sprintf(ptr, "SND: %.0f%%", (double)((gui_data.sndbuf) / 10.0)); } else { - ptr[0] = 0; + strcpy (ptr, "SND: -"); on = 0; } }