|
|
1.1 ! root 1: /**************************************************************************** ! 2: * ! 3: * config.c ! 4: * ! 5: * Copyright (c) 1991-1992 Microsoft Corporation. All Rights Reserved. ! 6: * ! 7: ***************************************************************************/ ! 8: ! 9: #include <windows.h> ! 10: #include <mmsystem.h> ! 11: #include "registry.h" ! 12: #include "sndblst.h" ! 13: ! 14: /***************************************************************************** ! 15: ! 16: internal function prototypes ! 17: ! 18: ****************************************************************************/ ! 19: void Configure(HWND hDlg); ! 20: ! 21: static int PortToId(DWORD wPort) ! 22: { ! 23: switch(wPort) { ! 24: case 0x210: return IDC_210; ! 25: case 0x220: return IDC_220; ! 26: case 0x230: return IDC_230; ! 27: case 0x240: return IDC_240; ! 28: case 0x250: return IDC_250; ! 29: case 0x260: return IDC_260; ! 30: default: return -1; ! 31: } ! 32: } ! 33: ! 34: static DWORD IdToPort(int id) ! 35: { ! 36: switch(id) { ! 37: case IDC_210: return 0x210; ! 38: case IDC_220: return 0x220; ! 39: case IDC_230: return 0x230; ! 40: case IDC_240: return 0x240; ! 41: case IDC_250: return 0x250; ! 42: case IDC_260: return 0x260; ! 43: default: return (DWORD)-1; ! 44: } ! 45: } ! 46: ! 47: static int IntToId(DWORD Int) ! 48: { ! 49: switch(Int) { ! 50: case 2: return IDC_2; ! 51: case 9: return IDC_2; ! 52: case 3: return IDC_3; ! 53: case 5: return IDC_5; ! 54: case 7: return IDC_7; ! 55: case 10: return IDC_10; ! 56: default: return (DWORD)-1; ! 57: } ! 58: } ! 59: ! 60: static DWORD IdToInt(int id) ! 61: { ! 62: switch(id) { ! 63: case IDC_2: return 9; ! 64: case IDC_3: return 3; ! 65: case IDC_5: return 5; ! 66: case IDC_7: return 7; ! 67: case IDC_10: return 10; ! 68: default: return (DWORD)-1; ! 69: } ! 70: } ! 71: ! 72: /***************************************************************************/ ! 73: ! 74: void ConfigErrorMsgBox(HWND hDlg, UINT StringId) ! 75: { ! 76: WCHAR szErrorBuffer[MAX_ERR_STRING]; /* buffer for error messages */ ! 77: ! 78: LoadString(ghModule, StringId, szErrorBuffer, sizeof(szErrorBuffer)); ! 79: MessageBox(hDlg, szErrorBuffer, STR_PRODUCTNAME, MB_OK|MB_ICONEXCLAMATION); ! 80: } ! 81: ! 82: /***************************************************************************/ ! 83: ! 84: LRESULT ConfigRemove(HWND hDlg) ! 85: { ! 86: ! 87: LRESULT rc; ! 88: ! 89: // ! 90: // Remove the soundblaster driver entry from the registry ! 91: // ! 92: ! 93: rc = DrvRemoveDriver(&RegAccess); ! 94: ! 95: if (rc == DRVCNF_CANCEL) { ! 96: ! 97: /* ! 98: * Tell the user there's a problem ! 99: */ ! 100: ConfigErrorMsgBox(hDlg, IDS_FAILREMOVE); ! 101: ! 102: } ! 103: ! 104: return rc; ! 105: } ! 106: ! 107: /**************************************************************************** ! 108: * @doc INTERNAL ! 109: * ! 110: * @api int | Config | This puts up the configuration dialog box. ! 111: * ! 112: * @parm HWND | hWnd | Our Window handle. ! 113: * ! 114: * @parm HANDLE | hInstance | Our instance handle. ! 115: * ! 116: * @rdesc Returns whatever was returned from the dialog box procedure. ! 117: ***************************************************************************/ ! 118: int Config(HWND hWnd, HANDLE hInstance) ! 119: { ! 120: return DialogBox(hInstance, ! 121: MAKEINTATOM(DLG_CONFIG), ! 122: hWnd, ! 123: (DLGPROC)ConfigDlgProc); ! 124: } ! 125: ! 126: /**************************************************************************** ! 127: * @doc INTERNAL ! 128: * ! 129: * @api BOOL | SetDriverConfig | Callback to set config info in the registry ! 130: * does not write uninitialized values (-1) ! 131: * ! 132: * @parm PVOID | Context | Our context. ! 133: * ! 134: * @rdesc Returns TRUE if success, FALSE otherwise. ! 135: ***************************************************************************/ ! 136: BOOL SetDriverConfig(PVOID Context) ! 137: { ! 138: SB_CONFIG *Config; ! 139: ! 140: Config = (SB_CONFIG *)Context; ! 141: ! 142: /* We set the IO port and interrupt values */ ! 143: /* and set the returned version to 0 */ ! 144: /* */ ! 145: /* If any of these calls fail then give up */ ! 146: ! 147: if (Config->Port != (DWORD)-1 && ! 148: DrvSetDeviceParameter( ! 149: &RegAccess, ! 150: SOUND_REG_PORT, ! 151: Config->Port) != ERROR_SUCCESS || ! 152: Config->Int != (DWORD)-1 && ! 153: DrvSetDeviceParameter( ! 154: &RegAccess, ! 155: SOUND_REG_INTERRUPT, ! 156: Config->Int) != ERROR_SUCCESS || ! 157: DrvSetDeviceParameter( ! 158: &RegAccess, ! 159: TEXT("DSP Version"), ! 160: 0) != ERROR_SUCCESS) { ! 161: ! 162: return FALSE; ! 163: } else { ! 164: return TRUE; ! 165: } ! 166: } ! 167: ! 168: /**************************************************************************** ! 169: * @doc INTERNAL ! 170: * ! 171: * @api void | GetPortAndInt | Determines which port and interrupt settings ! 172: * the user has chosen in the configuration dialog box. ! 173: * ! 174: * @parm HWND | hDlg | Handle to the configuration dialog box. ! 175: * ! 176: * @rdesc Structure containing new port and interrupt ! 177: ***************************************************************************/ ! 178: SB_CONFIG GetPortAndInt(HWND hDlg) ! 179: { ! 180: SB_CONFIG NewConfig; ! 181: int id; ! 182: ! 183: NewConfig.Port = (DWORD)-1; ! 184: NewConfig.Int = (DWORD)-1; ! 185: ! 186: for (id = IDC_FIRSTPORT; id <= IDC_LASTPORT; id++) ! 187: if (IsDlgButtonChecked(hDlg, id)) { ! 188: NewConfig.Port = IdToPort(id); ! 189: break; ! 190: } ! 191: ! 192: for (id = IDC_FIRSTINT; id <= IDC_LASTINT; id++) ! 193: if (IsDlgButtonChecked(hDlg, id)) { ! 194: NewConfig.Int = IdToInt(id); ! 195: break; ! 196: } ! 197: ! 198: return NewConfig; ! 199: } ! 200: ! 201: /**************************************************************************** ! 202: * @doc INTERNAL ! 203: * ! 204: * @api int | ConfigDlgProc | Dialog proc for the configuration dialog box. ! 205: * ! 206: * @parm HWND | hDlg | Handle to the configuration dialog box. ! 207: * ! 208: * @parm WORD | msg | Message sent to the dialog box. ! 209: * ! 210: * @parm WORD | wParam | Message dependent parameter. ! 211: * ! 212: * @parm LONG | lParam | Message dependent parameter. ! 213: * ! 214: * @rdesc Returns DRV_RESTART if the user has changed settings, which will ! 215: * cause the drivers applet which launched this to give the user a ! 216: * message about having to restart Windows for the changes to take ! 217: * effect. If the user clicks on "Cancel" or if no settings have changed, ! 218: * DRV_CANCEL is returned. ! 219: ***************************************************************************/ ! 220: int ConfigDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) ! 221: { ! 222: int id; ! 223: static SB_CONFIG StartConfig; /* Initial port */ ! 224: ! 225: switch (msg) { ! 226: case WM_INITDIALOG: ! 227: StartConfig.Int = ConfigGetIRQ(); ! 228: StartConfig.Port = ConfigGetPortBase(); ! 229: ! 230: if ((id = PortToId(StartConfig.Port)) != -1) ! 231: CheckRadioButton(hDlg, IDC_FIRSTPORT, IDC_LASTPORT, id); ! 232: ! 233: if ((id = IntToId(StartConfig.Int)) != -1) ! 234: CheckRadioButton(hDlg, IDC_FIRSTINT, IDC_LASTINT, id); ! 235: break; ! 236: ! 237: case WM_COMMAND: ! 238: switch (LOWORD(wParam)) { ! 239: case IDOK: ! 240: Configure(hDlg); ! 241: break; ! 242: ! 243: case IDCANCEL: ! 244: ! 245: /* ! 246: * Restore to state on entry to dialog if we ! 247: * possibly can ! 248: */ ! 249: ! 250: if (bInstall) { ! 251: DrvRemoveDriver(&RegAccess); ! 252: } else { ! 253: ! 254: DrvConfigureDriver(&RegAccess, ! 255: STR_DRIVERNAME, ! 256: SoundDriverTypeNormal, ! 257: SetDriverConfig, ! 258: &StartConfig); ! 259: } ! 260: ! 261: EndDialog(hDlg, DRVCNF_CANCEL); ! 262: break; ! 263: ! 264: case IDC_210: ! 265: case IDC_220: ! 266: case IDC_230: ! 267: case IDC_240: ! 268: case IDC_250: ! 269: case IDC_260: ! 270: CheckRadioButton(hDlg, IDC_FIRSTPORT, IDC_LASTPORT, wParam); ! 271: break; ! 272: ! 273: case IDC_2: ! 274: case IDC_3: ! 275: case IDC_5: ! 276: case IDC_7: ! 277: case IDC_10: ! 278: CheckRadioButton(hDlg, IDC_FIRSTINT, IDC_LASTINT, wParam); ! 279: break; ! 280: ! 281: default: ! 282: break; ! 283: } ! 284: break; ! 285: ! 286: default: ! 287: return FALSE; ! 288: } ! 289: ! 290: return TRUE; ! 291: } ! 292: ! 293: ! 294: ! 295: /************************************************************************** ! 296: * ! 297: * Function : Configure ! 298: * ! 299: * Arguments : ! 300: * ! 301: * NewPort ! 302: * NewInterrupt ! 303: * NewChannel ! 304: * ! 305: * Description ! 306: * ! 307: * The user has selected a (new) configuration. There are a number ! 308: * of (binary) state varibles to consider : ! 309: * ! 310: * 1) Is this a new install? ! 311: * ! 312: * 2) Was the driver previously loaded? ! 313: * ! 314: * 3) Has the configuration changed? ! 315: * ! 316: * 4) If the driver was previously loaded could it be unloaded? ! 317: * ! 318: * 5) Could the driver be loaded ? ! 319: * ! 320: * Possible actions are : ! 321: * ! 322: * a. Try unload ! 323: * ! 324: * b. Try reload ! 325: * ! 326: * c. Warn user parameters are not accepted by driver ! 327: * ! 328: * d. Put up reboot menu ! 329: * ! 330: * e. Update registry with new config data ! 331: * ! 332: * f. Check version and issue necessary warnings ! 333: * ! 334: * Notes : ! 335: * A - 1 & 2 should not happen ! 336: * ! 337: * B - ~2 => 4 irrelevant ! 338: * ! 339: * C - configuration change irrelevant for new install ! 340: * ! 341: * There's never and point in unloading ! ! 342: * ! 343: * If the configuration changes we have to put it in the registry to ! 344: * test it. ! 345: * ! 346: * We must correctly detect the 'not loaded' state via SC manager ! 347: * ! 348: * Don't warn them about the version if it's not an install (how ! 349: * do we know ?) ! 350: * ! 351: * ! 352: * The logic is : ! 353: * ! 354: * 1 2 3 4 5 | a b c d e f Comments ! 355: * ----------|------------------------------------------------------------- ! 356: * 0 0 0 0 0 | Config not changed, not new so don't load ! 357: * 0 0 0 0 1 | Config not changed, not new so don't load ! 358: * 0 0 0 1 0 | B ! 359: * 0 0 0 1 1 | B ! 360: * 0 0 1 0 0 | X X X Assume load failed due to config failure ! 361: * 0 0 1 0 1 | X X Was not loaded, config changed, now loaded OK ! 362: * 0 0 1 1 0 | B ! 363: * 0 0 1 1 1 | B ! 364: * 0 1 0 0 0 | Config not changed, driver loaded so OK ! 365: * 0 1 0 0 1 | Config not changed, driver loaded so OK ! 366: * 0 1 0 1 0 | Config not changed, driver loaded so OK ! 367: * 0 1 0 1 1 | Config not changed, driver loaded so OK ! 368: * 0 1 1 0 0 | X X Driver was running OK with old config ! 369: * 0 1 1 0 1 | X X Driver was running OK with old config ! 370: * 0 1 1 1 0 | X X Driver was running OK with old config ! 371: * 0 1 1 1 1 | X X Driver was running OK with old config ! 372: * 1 0 0 0 0 | X X X Assume load failed due to config failure ! 373: * 1 0 0 0 1 | X X X Good install and load ! 374: * 1 0 0 1 0 | B ! 375: * 1 0 0 1 1 | B ! 376: * 1 0 1 0 0 | C ! 377: * 1 0 1 0 1 | C ! 378: * 1 0 1 1 0 | B ! 379: * 1 0 1 1 1 | B ! 380: * 1 1 0 0 0 | A ! 381: * 1 1 0 0 1 | A ! 382: * 1 1 0 1 0 | A ! 383: * 1 1 0 1 1 | A ! 384: * 1 1 1 0 0 | A ! 385: * 1 1 1 0 1 | A ! 386: * 1 1 1 1 0 | A ! 387: * 1 1 1 1 1 | A ! 388: * ! 389: **************************************************************************/ ! 390: ! 391: void Configure(HWND hDlg) ! 392: { ! 393: DWORD DspVersion; ! 394: SB_CONFIG NewConfig; /* New port and int chosen in config box */ ! 395: BOOL Success; ! 396: ! 397: /* ! 398: * Get the new configuration which the user entered ! 399: */ ! 400: ! 401: NewConfig = GetPortAndInt(hDlg); ! 402: ! 403: /* ! 404: * NOTE - even if the configuration has not changed the driver ! 405: * may now load in some cases - so even in this case try it. ! 406: * ! 407: * Put the new config in the registry ! 408: * ! 409: * unload the driver if needed (note this may fail but we've ! 410: * no way of telling whether it was loaded in the first place). ! 411: * ! 412: * if the driver is not loaded ! 413: * ! 414: * try loading the driver ! 415: * ! 416: * if the load failed put up a message ! 417: * ! 418: * if the load succeeded put up a warning if we don't like ! 419: * the version ! 420: * ! 421: * if the driver is already loaded ask them if they would like ! 422: * to reboot (ie return DRVCNF_RESTART (note that if the driver ! 423: * is currently loaded then changing the config will stop it ! 424: * working !). ! 425: * ! 426: */ ! 427: ! 428: ! 429: /* ! 430: * We have a new config - Configure the driver for this configuration ! 431: */ ! 432: ! 433: Success = DrvConfigureDriver(&RegAccess, ! 434: STR_DRIVERNAME, ! 435: SoundDriverTypeNormal, ! 436: SetDriverConfig, ! 437: &NewConfig); ! 438: /* ! 439: * Find out what we got back ! 440: */ ! 441: ! 442: // ! 443: // get the version from the registry if the driver put it there ! 444: // ! 445: ! 446: if (DrvQueryDeviceParameter(&RegAccess, ! 447: TEXT("DSP Version"), ! 448: &DspVersion) ! 449: != ERROR_SUCCESS) { ! 450: DspVersion = 0; ! 451: } ! 452: ! 453: /* ! 454: * See if we succeeded and interpret the 'version number' ! 455: * accordingly. ! 456: */ ! 457: ! 458: if (!Success) { ! 459: ! 460: /* ! 461: * Private interface to kernel driver. ! 462: * Flag 0x8000 set says it's a thunderboard ! 463: * Flag 0x4000 set says wrong port ! 464: * Flag 0x2000 set says wrong interrupt ! 465: * Flag 0x1000 set says interrupt is in use by someone else ! 466: */ ! 467: ! 468: ConfigErrorMsgBox(hDlg, ! 469: DspVersion & 0x4000 ? IDS_ERRBADPORT : ! 470: DspVersion & 0x2000 ? IDS_ERRBADINT : ! 471: DspVersion & 0x1000 ? IDS_ERRINTINUSE : ! 472: IDS_ERRBADCONFIG); ! 473: ! 474: } else { ! 475: ! 476: /* ! 477: * If we're an install then check out the version ! 478: */ ! 479: ! 480: if (bInstall) { ! 481: ! 482: /* Advise upgrade if on <= 1.00 DSP */ ! 483: if (DspVersion <= DSP_VERSION_REQD) { ! 484: /* display error and DON'T write INI settings - */ ! 485: /* this way the driver will never enable */ ! 486: ConfigErrorMsgBox(hDlg, IDS_ERRBADVERSION); ! 487: } ! 488: ! 489: /* high bit set if Thunder Board - warn them */ ! 490: /* but continue installing */ ! 491: if (DspVersion & 0x8000) ! 492: ConfigErrorMsgBox(hDlg, IDS_WARNTHUNDER); ! 493: ! 494: /* if installing on a Pro spectrum card, warn them */ ! 495: /* but continue installing */ ! 496: else if (DspVersion & 0x800) ! 497: ConfigErrorMsgBox(hDlg, IDS_WARNPROSPEC); ! 498: ! 499: ! 500: /* if installing on a Pro card, warn them */ ! 501: /* but continue installing */ ! 502: else if (DspVersion >= DSP_VERSION_PRO) ! 503: ConfigErrorMsgBox(hDlg, IDS_WARNPROCARD); ! 504: ! 505: bInstall = FALSE; ! 506: } ! 507: EndDialog(hDlg, DRVCNF_RESTART); ! 508: return; ! 509: } ! 510: } ! 511:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.