Skip to content

Commit 412cf32

Browse files
committed
fix usbsid driver init, patch by LouD. Also updated the usbsid lib, which fixes some warning(s)
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45805 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent e477680 commit 412cf32

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ int us_device_open(void)
113113
/* Gather settings from resources */
114114
resources_get_int("SidUSBSIDReadMode", &r_readmode);
115115
resources_get_int("SidUSBSIDAudioMode", &r_audiomode);
116-
resources_get_int("SidUSBSIDDiffSize", &r_readmode);
117-
resources_get_int("SidUSBSIDBufferSize", &r_diffsize);
116+
resources_get_int("SidUSBSIDDiffSize", &r_diffsize);
117+
resources_get_int("SidUSBSIDBufferSize", &r_buffsize);
118118
/* Apply settings to local variables */
119119
readmode = r_readmode;
120120
audiomode = r_audiomode;
@@ -162,9 +162,10 @@ int us_device_open(void)
162162
int us_device_close(void)
163163
{
164164
log_message(usbsid_log, "Start device closing");
165-
if (usbsid) {
165+
if (usbsid != NULL) {
166166
mute_USBSID(usbsid);
167167
close_USBSID(usbsid);
168+
usbsid = NULL;
168169
}
169170

170171
/* Clean up vars */

vice/src/lib/libusbsiddrv/USBSID.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ void USBSID_Class::USBSID_ToggleStereo(void)
433433

434434
/* SYNCHRONOUS */
435435

436-
void USBSID_Class::USBSID_SingleWrite(unsigned char *buff, size_t len)
436+
void USBSID_Class::USBSID_SingleWrite(unsigned char *buff, int len)
437437
{
438438
if (!us_Initialised) return;
439439
int actual_length = 0;
@@ -462,7 +462,7 @@ unsigned char USBSID_Class::USBSID_SingleRead(uint8_t reg)
462462
return result[0];
463463
}
464464

465-
unsigned char USBSID_Class::USBSID_SingleReadConfig(unsigned char *buff, size_t len)
465+
unsigned char USBSID_Class::USBSID_SingleReadConfig(unsigned char *buff, int len)
466466
{
467467
if (!us_Initialised) return 0;
468468
int actual_length;
@@ -550,8 +550,8 @@ void USBSID_Class::USBSID_WriteCycled(uint8_t reg, uint8_t val, uint16_t cycles)
550550
write_buffer[0] = (CYCLED_WRITE << 6);
551551
write_buffer[1] = (reg & 0xFF);
552552
write_buffer[2] = val;
553-
write_buffer[3] = (cycles >> 8);
554-
write_buffer[4] = (cycles & 0xFF);
553+
write_buffer[3] = (uint8_t)(cycles >> 8);
554+
write_buffer[4] = (uint8_t)(cycles & 0xFF);
555555
USBSID_Write(write_buffer, 5);
556556
return;
557557
}
@@ -655,8 +655,8 @@ int USBSID_Class::USBSID_InitThread(void)
655655
flush_buffer = 0;
656656
run_thread = buffer_pos = 1;
657657
threaded = withcycles = true;
658-
pthread_mutex_lock(&us_mutex);
659658
USBSID_InitRingBuffer(ring_size, diff_size);
659+
pthread_mutex_lock(&us_mutex);
660660
us_thread++;
661661
pthread_mutex_unlock(&us_mutex);
662662
int error;
@@ -843,8 +843,8 @@ void USBSID_Class::USBSID_FlushBuffer(void)
843843
? (buffer_pos >= 5)
844844
: (buffer_pos >= 3))) {
845845
thread_buffer[0] = (withcycles == 1)
846-
? (CYCLED_WRITE << 6 | (buffer_pos - 1))
847-
: (WRITE << 6 | (buffer_pos - 1));
846+
? (uint8_t)(CYCLED_WRITE << 6 | (buffer_pos - 1))
847+
: (uint8_t)(WRITE << 6 | (buffer_pos - 1));
848848
memcpy(out_buffer, thread_buffer, buffer_pos);
849849
buffer_pos = 1;
850850
flush_buffer = 0;
@@ -876,8 +876,8 @@ void USBSID_Class::USBSID_WriteRingCycled(uint8_t reg, uint8_t val, uint16_t cyc
876876
if (threaded && withcycles) {
877877
USBSID_RingPut(reg);
878878
USBSID_RingPut(val);
879-
USBSID_RingPut((cycles >> 8) & 0xFF);
880-
USBSID_RingPut(cycles & 0xFF);
879+
USBSID_RingPut((uint8_t)(cycles >> 8) & 0xFF);
880+
USBSID_RingPut((uint8_t)(cycles & 0xFF));
881881
} else {
882882
USBERR(stderr, "[USBSID] Function '%s' cannot be used when threaded = %d and withcycles = %d\n", __func__, threaded, withcycles);
883883
}
@@ -895,7 +895,7 @@ void USBSID_Class::USBSID_RingPopCycled(void)
895895
|| buffer_pos == len_out_buffer
896896
|| flush_buffer == 1) {
897897
flush_buffer = 0;
898-
thread_buffer[0] = (CYCLED_WRITE << 6 | (buffer_pos - 1));
898+
thread_buffer[0] = (uint8_t)((CYCLED_WRITE << 6) | (buffer_pos - 1));
899899
memcpy(out_buffer, thread_buffer, buffer_pos);
900900
buffer_pos = 1;
901901
libusb_submit_transfer(transfer_out);
@@ -917,7 +917,7 @@ void USBSID_Class::USBSID_RingPop(void)
917917
|| buffer_pos == len_out_buffer
918918
|| flush_buffer == 1) {
919919
flush_buffer = 0;
920-
thread_buffer[0] = (WRITE << 6 | (buffer_pos - 1));
920+
thread_buffer[0] = (uint8_t)((WRITE << 6) | (buffer_pos - 1));
921921
memcpy(out_buffer, thread_buffer, buffer_pos);
922922
buffer_pos = 1;
923923
libusb_submit_transfer(transfer_out);
@@ -951,14 +951,14 @@ uint8_t USBSID_Class::USBSID_Address(uint16_t addr)
951951
static uint8_t a;
952952
switch (addr) {
953953
case 0xD400 ... 0xD499:
954-
a = (addr & SIDLMASK); /* $D400 -> $D479 1, 2, 3 & 4 */
954+
a = (uint8_t)(addr & SIDLMASK); /* $D400 -> $D479 1, 2, 3 & 4 */
955955
break;
956956
case 0xD500 ... 0xD599:
957957
case 0xDE00 ... 0xDF99:
958958
a = ((SID3ADDR | (addr & SID2MASK)) & SIDLMASK);
959959
break;
960960
default:
961-
a = (addr & SIDLMASK);
961+
a = (uint8_t)(addr & SIDLMASK);
962962
break;
963963
}
964964
return a;
@@ -973,15 +973,15 @@ uint_fast64_t USBSID_Class::USBSID_CycleFromTimestamp(timestamp_t timestamp)
973973
USBSID_GetClockRate(); /* Make sure we use the right clockrate */
974974
us_InvCPUcycleDurationNanoSeconds = 1.0 / (ratio_t::den / (float)cycles_per_sec);
975975
auto nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(timestamp - m_StartTime);
976-
return (int_fast64_t)(nsec.count() * us_InvCPUcycleDurationNanoSeconds);
976+
return (int_fast64_t)((double)nsec.count() * us_InvCPUcycleDurationNanoSeconds);
977977
}
978978

979979
uint_fast64_t USBSID_Class::USBSID_WaitForCycle(uint_fast16_t cycles)
980980
{ /* Returns the waited microseconds since last target time ~ not the actual cycles */
981981
if (!us_Initialised) return 0;
982982
USBSID_GetClockRate(); /* Make sure we use the right clockrate */
983983
timestamp_t now = std::chrono::high_resolution_clock::now();
984-
double dur = cycles * us_CPUcycleDuration; /* duration in nanoseconds */
984+
double dur = (double)cycles * us_CPUcycleDuration; /* duration in nanoseconds */
985985
duration_t duration = (duration_t)(int_fast64_t)dur; /* equals dur but as chrono nanoseconds */
986986
auto target_time = m_LastTime + duration; /* ns to wait since m_LastTime (now + duration for actual wait time) */
987987
// auto target_time = now + duration; /* ns to wait since m_LastTime (now + duration for actual wait time) */
@@ -993,7 +993,7 @@ uint_fast64_t USBSID_Class::USBSID_WaitForCycle(uint_fast16_t cycles)
993993
}
994994
m_LastTime = target_time;
995995
/* int_fast64_t waited_cycles = wait_usec.count(); */
996-
int_fast64_t waited_cycles = (wait_nsec.count() * us_InvCPUcycleDurationNanoSeconds);
996+
int_fast64_t waited_cycles = (int_fast64_t)((double)wait_nsec.count() * us_InvCPUcycleDurationNanoSeconds);
997997
// USBDBG(stdout, "[C] %ld [WC] %ld [us] %ld [ns] %ld [ts] %lu\n",
998998
// cycles, waited_cycles, wait_usec.count(), wait_nsec.count(), USBSID_CycleFromTimestamp(now));
999999
// return (wait_nsec.count() > 0) ? waited_cycles : 0;
@@ -1031,7 +1031,7 @@ void USBSID_Class::LIBUSB_CloseDevice(void)
10311031
return;
10321032
}
10331033

1034-
int USBSID_Class::LIBUSB_Available(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id)
1034+
int USBSID_Class::LIBUSB_Available(uint16_t vendor_id, uint16_t product_id)
10351035
{
10361036
struct libusb_device **devs;
10371037
struct libusb_device *dev;
@@ -1239,7 +1239,7 @@ int USBSID_Class::LIBUSB_Setup(bool start_threaded, bool with_cycles)
12391239
libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, 0);
12401240

12411241
/* Check for an available USBSID-Pico */
1242-
if (LIBUSB_Available(ctx, VENDOR_ID, PRODUCT_ID) <= 0) {
1242+
if (LIBUSB_Available(VENDOR_ID, PRODUCT_ID) <= 0) {
12431243
USBDBG(stderr, "[USBSID] USBSID-Pico not connected\n");
12441244
goto out;
12451245
}

vice/src/lib/libusbsiddrv/USBSID.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ namespace USBSID_NS
287287
/* LIBUSB */
288288
int LIBUSB_Setup(bool start_threaded, bool with_cycles);
289289
int LIBUSB_Exit(void);
290-
int LIBUSB_Available(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
290+
int LIBUSB_Available(uint16_t vendor_id, uint16_t product_id);
291291
void LIBUSB_StopTransfers(void);
292292
int LIBUSB_OpenDevice(void);
293293
void LIBUSB_CloseDevice(void);
@@ -365,9 +365,9 @@ namespace USBSID_NS
365365
void USBSID_ToggleStereo(void); /* Toggle between mono and stereo ~ v1.3 PCB only */
366366

367367
/* Synchronous direct */
368-
void USBSID_SingleWrite(unsigned char *buff, size_t len); /* Single write buffer of size_t ~ example: config writing */
368+
void USBSID_SingleWrite(unsigned char *buff, int len); /* Single write buffer of size_t ~ example: config writing */
369369
unsigned char USBSID_SingleRead(uint8_t reg); /* Single read register, return result */
370-
unsigned char USBSID_SingleReadConfig(unsigned char *buff, size_t len); /* Single to buffer of specified length ~ example: config reading */
370+
unsigned char USBSID_SingleReadConfig(unsigned char *buff, int len); /* Single to buffer of specified length ~ example: config reading */
371371

372372
/* Asynchronous direct */
373373
void USBSID_Write(unsigned char *buff, size_t len); /* Write buffer of size_t len */

vice/src/lib/libusbsiddrv/USBSIDInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ extern "C"
117117
if( p == NULL ) return -1;
118118
return ((USBSID_Class*)p)->us_Found;
119119
}
120-
void writesingle_USBSID(USBSIDitf p, unsigned char *buff, size_t len){
120+
void writesingle_USBSID(USBSIDitf p, unsigned char *buff, int len){
121121
if( p == NULL ) return;
122122
return ((USBSID_Class*)p)->USBSID_SingleWrite(buff, len);
123123
};
124124
unsigned char readsingle_USBSID(USBSIDitf p, uint8_t reg){
125125
if( p == NULL ) return 0;
126126
return ((USBSID_Class*)p)->USBSID_SingleRead(reg);
127127
};
128-
void writebuffer_USBSID(USBSIDitf p, unsigned char *buff, size_t len){
128+
void writebuffer_USBSID(USBSIDitf p, unsigned char *buff, int len){
129129
if( p == NULL ) return;
130130
return ((USBSID_Class*)p)->USBSID_Write(buff, len);
131131
};

vice/src/lib/libusbsiddrv/USBSIDInterface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ extern "C" {
6262
int found_USBSID(USBSIDitf);
6363

6464
/* Synchronous direct */
65-
void writesingle_USBSID(USBSIDitf, unsigned char *buff, size_t len);
65+
void writesingle_USBSID(USBSIDitf, unsigned char *buff, int len);
6666
unsigned char readsingle_USBSID(USBSIDitf, uint8_t reg);
6767

6868
/* Asynchronous direct */
69-
void writebuffer_USBSID(USBSIDitf, unsigned char *buff, size_t len);
69+
void writebuffer_USBSID(USBSIDitf, unsigned char *buff, int len);
7070
void write_USBSID(USBSIDitf, uint8_t reg, uint8_t val);
7171
void writecycled_USBSID(USBSIDitf, uint8_t reg, uint8_t val, uint16_t cycles);
7272
unsigned char read_USBSID(USBSIDitf p, uint8_t reg);
@@ -79,6 +79,7 @@ extern "C" {
7979
void enablethread_USBSID(USBSIDitf);
8080
void disablethread_USBSID(USBSIDitf);
8181
void setflush_USBSID(USBSIDitf);
82+
void flush_USBSID(USBSIDitf);
8283
void restartringbuffer_USBSID(USBSIDitf);
8384
void setbuffsize_USBSID(USBSIDitf, int size);
8485
void setdiffsize_USBSID(USBSIDitf, int size);

0 commit comments

Comments
 (0)