Skip to content

Commit 0dcb3bd

Browse files
authored
Support changing the default base address by using the DOS environment variable RESETOPL
If a command line parameter is not specified, use the RESETOPL DOS environment variable as the source for the base address of the OPL2/3 chip. Useful for users of Ad Lib-compatible sound cards (including the Resound cards from TexElec), as they need only put "SET RESETOPL=0x388" in their autoexec.bat file and now they save having to type the base address each time they need to reset their OPL chip.
1 parent e5a114b commit 0dcb3bd

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ C:\> resetopl 0x240
1616
Resetting OPL3 at 0x240
1717
```
1818

19+
You can change the base by setting the DOS environment variable `resetopl`:
20+
```
21+
C:\> set resetopl=0x388
22+
C:\> resetopl
23+
Resetting OPL3 at 0x388
24+
```
25+
26+
The argument still overrides the base specified in the environment variable:
27+
```
28+
C:\> set resetopl=0x388
29+
C:\> resetopl 0x240
30+
Resetting OPL3 at 0x240
31+
```
32+
1933
The utility detects if the OPL-chip is present and will abort if the chip
2034
is not detected:
2135
```

resetopl.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,23 @@ void set_registers(unsigned int base, unsigned char low, unsigned char high, uns
5252
int main(int argc, char **argv) {
5353
unsigned int base;
5454
unsigned char val1, val2;
55+
char *dosenvvar = NULL;
5556
int opl3 = 0;
5657

5758
if (argc == 1) {
58-
base = 0x220;
59-
printf("No argument given, assuming base at 0x%x\n", base);
59+
dosenvvar = getenv("RESETOPL");
60+
if (dosenvvar == NULL) {
61+
base = 0x220;
62+
printf("No argument given, assuming base at 0x%x\n", base);
63+
}
64+
else {
65+
char *endp;
66+
base = strtoul(dosenvvar, &endp, 0);
67+
if (*endp != '\0') {
68+
fprintf(stderr, "Invalid base address %s in environment variable!\n", dosenvvar);
69+
exit(1);
70+
}
71+
}
6072
} else if (argc == 2) {
6173
char *endp;
6274
base = strtoul(argv[1], &endp, 0);

0 commit comments

Comments
 (0)