Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit e501d7c

Browse files
committed
Add optional commandline parameters (that save) for tuning the buffer size and head->tail difference size
1 parent ba1431c commit e501d7c

File tree

10 files changed

+183
-5
lines changed

10 files changed

+183
-5
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Use `-usaudiomode 1` to enable Stereo mode, default is Mono mode. Works on PCB v
1010
x64sc -usreadmode 1 -usaudiomode 1
1111
vsid -usreadmode 1 -usaudiomode 1
1212
```
13+
# Optional tuning of write buffer and it's head->tail difference size
14+
Buffer and difference size must always be a multiple of 8!
15+
Use `-usdiffsize 64` to set the head->tail difference size
16+
Use `-usbuffsize 8192` to set the buffer size
17+
```shell
18+
# Examples
19+
x64sc -usdiffsize 64 -usbuffsize 512
20+
vsid -usdiffsize 64 -usbuffsize 512
21+
```
1322

1423
# Linux Building and installing
1524
For building you can mostly follow the instructions in the [Linux-GTK3-Howto](vice/doc/building/Linux-GTK3-Howto.txt) \

vice/src/arch/shared/hwsiddrv/us-unixwin-device.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
static int rc = -1, sids_found = -1, no_sids = -1;
7070
static int r_audiomode = -1, audiomode = -1;
7171
static int r_readmode = -1, readmode = -1;
72+
static int buffsize = -1, diffsize = -1;
73+
static int r_buffsize = -1, r_diffsize = -1;
74+
const int d_buffsize = 8192, d_diffsize = 64;
7275
static uint8_t sidbuf[0x20 * US_MAXSID];
7376

7477
static CLOCK usid_main_clk;
@@ -125,6 +128,12 @@ int us_device_open(void)
125128
resources_get_int("SidUSBSIDAudioMode", &r_audiomode);
126129
// log_message(usbsid_log, "SidUSBSIDAudioMode: %d, readmode: %d\r", r_audiomode, audiomode);
127130
audiomode = r_audiomode;
131+
resources_get_int("SidUSBSIDDiffSize", &r_readmode);
132+
// log_message(usbsid_log, "SidUSBSIDReadMode: %d, readmode: %d\r", r_readmode, readmode);
133+
diffsize = r_diffsize;
134+
resources_get_int("SidUSBSIDBufferSize", &r_diffsize);
135+
// log_message(usbsid_log, "SidUSBSIDAudioMode: %d, readmode: %d\r", r_audiomode, audiomode);
136+
buffsize = r_buffsize;
128137
}
129138

130139
if (readmode == 1) {
@@ -247,12 +256,42 @@ void us_set_readmode(int val)
247256
void us_set_audiomode(int val)
248257
{ /* Gets set by x64sc from SID settings and by VSID at SID file change */
249258
resources_get_int("SidUSBSIDAudioMode", &r_audiomode);
250-
log_message(usbsid_log, "Audio mode is '%s'\r", (r_audiomode == 1 ? "Stereo" : "Mono"));
259+
log_message(usbsid_log, "Audio mode is '%s' (resource:%d val:%d)\r", (r_audiomode == 1 ? "Stereo" : "Mono"), r_audiomode, val);
251260
audiomode = r_audiomode;
252261

253262
setstereo_USBSID(usbsid, audiomode);
254263
}
255264

265+
void us_restart_ringbuffer(void)
266+
{ /* Restarts the ringbuffer with a new value */
267+
if (buffsize != d_buffsize) {
268+
log_message(usbsid_log, "Restarting ringbuffer with buffer size:%d & diff size:%d\r", buffsize, diffsize);
269+
restartringbuffer_USBSID(usbsid);
270+
}
271+
}
272+
273+
void us_set_buffsize(int val)
274+
{ /* Set the ringbuffer size */
275+
resources_get_int("SidUSBSIDBufferSize", &r_buffsize);
276+
buffsize = r_buffsize;
277+
if (r_buffsize != d_buffsize) {
278+
log_message(usbsid_log, "Setting ringbuffer size to: %d (val:%d default:%d)\r", buffsize, val, d_buffsize);
279+
setbuffsize_USBSID(usbsid, buffsize);
280+
us_restart_ringbuffer();
281+
}
282+
}
283+
284+
void us_set_diffsize(int val)
285+
{ /* Set the ringbuffer head to tail difference size */
286+
resources_get_int("SidUSBSIDDiffSize", &r_diffsize);
287+
diffsize = r_diffsize;
288+
if (r_diffsize != d_diffsize) {
289+
log_message(usbsid_log, "Setting ringbuffer diff size to: %d (val:%d default:%d)\r", diffsize, val, d_diffsize);
290+
setdiffsize_USBSID(usbsid, diffsize);
291+
}
292+
293+
}
294+
256295
static void usbsid_alarm_handler(CLOCK offset, void *data)
257296
{
258297
CLOCK cycles = (usid_alarm_clk + offset) - usid_main_clk;

vice/src/arch/shared/hwsiddrv/us-unixwin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ void us_set_readmode(int val);
5858

5959
void us_set_audiomode(int val);
6060

61+
void us_restart_ringbuffer(void);
62+
63+
void us_set_buffsize(int val);
64+
65+
void us_set_diffsize(int val);
66+
6167
void us_device_state_read(int chipno, struct sid_us_snapshot_state_s *sid_state);
6268

6369
void us_device_state_write(int chipno, struct sid_us_snapshot_state_s *sid_state);

vice/src/arch/shared/hwsiddrv/usbsid-unixwin-drv.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ void usbsid_drv_set_audiomode(int val)
115115
}
116116
}
117117

118+
void usbsid_drv_restart_ringbuffer(void)
119+
{
120+
if (use_us_device) {
121+
us_restart_ringbuffer();
122+
}
123+
}
124+
125+
void usbsid_drv_set_buffsize(int val)
126+
{
127+
if (use_us_device) {
128+
us_set_buffsize(val);
129+
}
130+
}
131+
132+
void usbsid_drv_set_diffsize(int val)
133+
{
134+
if (use_us_device) {
135+
us_set_diffsize(val);
136+
}
137+
}
138+
118139
void usbsid_drv_state_read(int chipno, struct sid_us_snapshot_state_s *sid_state)
119140
{
120141
if (use_us_device) {

vice/src/sid/sid-cmdline-options.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ static const struct engine_s engine_match[] = {
132132
{ NULL, -1 }
133133
};
134134

135+
#ifdef HAVE_USBSID
136+
int us_setparam(const char *param, void *extra_param)
137+
{
138+
printf("KUT: %s %s %s\n", param, (char *)&extra_param, (char *)extra_param);
139+
if ((!strcmp(((char *)extra_param), "rw")) && (strlen(param) >= 1)) {
140+
int r = atoi(param);
141+
printf("R: %d\n", r);
142+
resources_set_int("SidUSBSIDReadMode", r);
143+
usbsid_set_readmode(r);
144+
}
145+
if ((!strcmp(((char *)extra_param), "audio")) && (strlen(param) >= 1)) {
146+
int a = atoi(param);
147+
printf("A: %d\n", a);
148+
resources_set_int("SidUSBSIDAudioMode", a);
149+
usbsid_set_audiomode(a);
150+
}
151+
if ((!strcmp(((char *)extra_param), "diff")) && (strlen(param) >= 1)) {
152+
int d = atoi(param);
153+
printf("D: %d\n", d);
154+
resources_set_int("SidUSBSIDDiffSize", d);
155+
usbsid_set_diffsize(d);
156+
}
157+
if ((!strcmp(((char *)extra_param), "buff")) && (strlen(param) >= 1)) {
158+
int b = atoi(param);
159+
printf("B: %d\n", b);
160+
resources_set_int("SidUSBSIDBufferSize", b);
161+
usbsid_set_buffsize(b);
162+
}
163+
return 0;
164+
}
165+
#endif
166+
135167
int sid_common_set_engine_model(const char *param, void *extra_param)
136168
{
137169
int engine;
@@ -240,12 +272,32 @@ static const cmdline_option_t hardsid_cmdline_options[] =
240272
#ifdef HAVE_USBSID
241273
static const cmdline_option_t usbsid_cmdline_options[] =
242274
{
275+
243276
{ "-usreadmode", SET_RESOURCE, CMDLINE_ATTRIB_NEED_ARGS,
244277
NULL, NULL, "SidUSBSIDReadMode", NULL,
245278
"<1 or 0>", "Enable USBSID read mode (disables cycled writing & digiplay)" },
246279
{ "-usaudiomode", SET_RESOURCE, CMDLINE_ATTRIB_NEED_ARGS,
247280
NULL, NULL, "SidUSBSIDAudioMode", NULL,
248281
"<1 or 0>", "Set audio to Stereo(1) or Mono(0) (Default)" },
282+
{ "-usdiffsize", SET_RESOURCE, CMDLINE_ATTRIB_NEED_ARGS,
283+
NULL, NULL, "SidUSBSIDDiffSize", NULL,
284+
"<n divisable by 8>", "Write buffer head -> tail diff size (default: 64)" },
285+
{ "-usbuffsize", SET_RESOURCE, CMDLINE_ATTRIB_NEED_ARGS,
286+
NULL, NULL, "SidUSBSIDBufferSize", NULL,
287+
"<n divisable by 8>", "Write buffer size (default: 8192)" },
288+
289+
// { "-usreadmode", CALL_FUNCTION, CMDLINE_ATTRIB_NEED_ARGS,
290+
// us_setparam, "rw", "SidUSBSIDReadMode", NULL,
291+
// "<1 or 0>", "Enable USBSID read mode (disables cycled writing & digiplay)" },
292+
// { "-usaudiomode", CALL_FUNCTION, CMDLINE_ATTRIB_NEED_ARGS,
293+
// us_setparam, "audio", "SidUSBSIDAudioMode", NULL,
294+
// "<1 or 0>", "Set audio to Stereo(1) or Mono(0) (Default)" },
295+
// { "-usbuffsize", CALL_FUNCTION, CMDLINE_ATTRIB_NEED_ARGS,
296+
// us_setparam, "buff", "SidUSBSIDBufferSize", NULL,
297+
// "<n divisable by 8>", "Write buffer size (default: 8192)" },
298+
// { "-usdiffsize", CALL_FUNCTION, CMDLINE_ATTRIB_NEED_ARGS,
299+
// us_setparam, "diff", "SidUSBSIDDiffSize", NULL,
300+
// "<n divisable by 8>", "Write buffer head -> tail diff size (default: 64)" },
249301
CMDLINE_LIST_END
250302
};
251303
#endif
@@ -493,7 +545,7 @@ static char *build_sid_engine_cmdline_option(int sid_type)
493545
#endif
494546

495547
#ifdef HAVE_USBSID
496-
/* add hardsid options if available */
548+
/* add usbsid options if available */
497549
if (usbsid_available()) {
498550
new = util_concat(old, ", 5: USBSID", NULL);
499551
lib_free(old);

vice/src/sid/sid-cmdline-options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
int sid_cmdline_options_init(int sid_type);
3232
int sid_common_set_engine_model(const char *param, void *extra_param);
3333

34+
#ifdef HAVE_USBSID
35+
int us_setparam(const char *param, void *extra_param);
36+
#endif
37+
3438
void sid_cmdline_options_shutdown(void);
3539

3640
#endif

vice/src/sid/sid-resources.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ static int sid_hardsid_right;
9090
#ifdef HAVE_USBSID
9191
static int sid_usbsid_readmode;
9292
static int sid_usbsid_audiomode;
93+
static int sid_usbsid_buffsize;
94+
static int sid_usbsid_diffsize;
9395
#endif
9496

9597
static int set_sid_engine(int set_engine, void *param)
@@ -383,6 +385,22 @@ static int set_sid_usbsid_audiomode(int val, void *param)
383385

384386
return 0;
385387
}
388+
389+
static int set_sid_usbsid_buffsize(int val, void *param)
390+
{
391+
sid_usbsid_buffsize = (unsigned int)val;
392+
usbsid_drv_set_buffsize(sid_usbsid_buffsize);
393+
394+
return 0;
395+
}
396+
397+
static int set_sid_usbsid_diffsize(int val, void *param)
398+
{
399+
sid_usbsid_diffsize = (unsigned int)val;
400+
usbsid_drv_set_diffsize(sid_usbsid_diffsize);
401+
402+
return 0;
403+
}
386404
#endif
387405

388406

@@ -474,6 +492,10 @@ static const resource_int_t usbsid_resources_int[] = {
474492
&sid_usbsid_readmode, set_sid_usbsid_readmode, NULL },
475493
{ "SidUSBSIDAudioMode", 0, RES_EVENT_NO, NULL,
476494
&sid_usbsid_audiomode, set_sid_usbsid_audiomode, NULL },
495+
{ "SidUSBSIDDiffSize", 64, RES_EVENT_NO, NULL,
496+
&sid_usbsid_diffsize, set_sid_usbsid_diffsize, NULL },
497+
{ "SidUSBSIDBufferSize", 8192, RES_EVENT_NO, NULL,
498+
&sid_usbsid_buffsize, set_sid_usbsid_buffsize, NULL },
477499
RESOURCE_INT_LIST_END
478500
};
479501
#endif
@@ -519,11 +541,9 @@ int sid_common_resources_init(void)
519541
#endif
520542

521543
#ifdef HAVE_USBSID
522-
// if (usbsid_available()) {
523544
if (resources_register_int(usbsid_resources_int) < 0) {
524545
return -1;
525546
}
526-
// }
527547
#endif
528548

529549
return resources_register_int(common_resources_int);

vice/src/sid/sid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void sid_sound_machine_reset(sound_t *psid, CLOCK cpu_clk)
639639
{
640640
sid_engine.reset(psid, cpu_clk);
641641
#ifdef HAVE_USBSID
642-
usbsid_reset(false); /* This is called when the STOP button is pressed */
642+
usbsid_reset(true); /* This is called when the STOP button is pressed */
643643
#endif
644644
}
645645

vice/src/sid/usbsid.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,27 @@ void usbsid_set_audiomode(int val)
156156
}
157157
}
158158

159+
void usbsid_restart_ringbuffer(void)
160+
{
161+
if (!usbsid_is_open) {
162+
usbsid_drv_restart_ringbuffer();
163+
}
164+
}
165+
166+
void usbsid_set_buffsize(int val)
167+
{
168+
if (!usbsid_is_open) {
169+
usbsid_drv_set_buffsize(val);
170+
}
171+
}
172+
173+
void usbsid_set_diffsize(int val)
174+
{
175+
if (!usbsid_is_open) {
176+
usbsid_drv_set_diffsize(val);
177+
}
178+
}
179+
159180

160181
/* ---------------------------------------------------------------------*/
161182

vice/src/usbsid.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void usbsid_set_machine_parameter(long cycles_per_sec);
4343
int usbsid_available(void);
4444
void usbsid_set_audiomode(int val);
4545
void usbsid_set_readmode(int val);
46+
void usbsid_restart_ringbuffer(void);
47+
void usbsid_set_buffsize(int val);
48+
void usbsid_set_diffsize(int val);
4649

4750
int usbsid_drv_open(void);
4851
int usbsid_drv_close(void);
@@ -53,6 +56,9 @@ void usbsid_drv_set_machine_parameter(long cycles_per_sec);
5356
int usbsid_drv_available(void);
5457
void usbsid_drv_set_audiomode(int val);
5558
void usbsid_drv_set_readmode(int val);
59+
void usbsid_drv_restart_ringbuffer(void);
60+
void usbsid_drv_set_buffsize(int val);
61+
void usbsid_drv_set_diffsize(int val);
5662

5763
void usbsid_state_read(int chipno, struct sid_us_snapshot_state_s *sid_state);
5864
void usbsid_state_write(int chipno, struct sid_us_snapshot_state_s *sid_state);

0 commit comments

Comments
 (0)