SCGUESS.C 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "scguess.h"
  5. int getSBParam(char *string, char field)
  6. {
  7. char *p;
  8. int rc;
  9. p = strchr(string, field);
  10. if (!p) return -1;
  11. else p++;
  12. if (field == 'A' || field == 'P') sscanf(p, "%x", &rc); // hex field
  13. else sscanf(p, "%d", &rc); // decimal field
  14. return rc;
  15. }
  16. /*
  17. * Returns 1 if it senses the BLASTER environment variable, 0 if it
  18. * doesn't. If it does return 1, it will also fill in as many fields
  19. * as it can extract from the environment variable. Any fields *not*
  20. * filled in will be set to -1. Of course, if the midi field is filled,
  21. * that means only that it's an SB16 and does not confirm whether the
  22. * WaveBlaster is present.
  23. */
  24. int SmellsLikeSB(int *addr, int *irq, int *dma, int *midi)
  25. {
  26. char *var = getenv("BLASTER");
  27. if (!var) return 0;
  28. *addr = getSBParam(var, 'A');
  29. *irq = getSBParam(var, 'I');
  30. *dma = getSBParam(var, 'D');
  31. *midi = getSBParam(var, 'P');
  32. return 1;
  33. }
  34. /*
  35. * Returns 1 if it senses the ULTRASND environment variable, 0 if it
  36. * doesn't. If it does return 1, it will also fill in as many fields
  37. * as it can extract from the environment variable. Any fields *not*
  38. * filled in will be set to -1.
  39. */
  40. int SmellsLikeGUS(int *addr, int *irq, int *dma)
  41. {
  42. char *var = getenv("ULTRASND");
  43. int dummy;
  44. if (!var) return 0;
  45. else
  46. {
  47. sscanf(var, "%x,%d,%d,%d,%d", addr, dma, &dummy, irq, &dummy);
  48. return 1;
  49. }
  50. }