Revision: 45805
http://sourceforge.net/p/vice-emu/code/45805
Author: gpz
Date: 2025-10-25 13:19:46 +0000 (Sat, 25 Oct 2025)
Log Message:
-----------
fix usbsid driver init, patch by LouD. Also updated the usbsid lib, which fixes some warning(s)
Modified Paths:
--------------
trunk/vice/src/arch/shared/hwsiddrv/us-unixwin-device.c
trunk/vice/src/lib/libusbsiddrv/USBSID.cpp
trunk/vice/src/lib/libusbsiddrv/USBSID.h
trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.cpp
trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.h
Modified: trunk/vice/src/arch/shared/hwsiddrv/us-unixwin-device.c
===================================================================
--- trunk/vice/src/arch/shared/hwsiddrv/us-unixwin-device.c 2025-10-25 13:09:13 UTC (rev 45804)
+++ trunk/vice/src/arch/shared/hwsiddrv/us-unixwin-device.c 2025-10-25 13:19:46 UTC (rev 45805)
@@ -113,8 +113,8 @@
/* Gather settings from resources */
resources_get_int("SidUSBSIDReadMode", &r_readmode);
resources_get_int("SidUSBSIDAudioMode", &r_audiomode);
- resources_get_int("SidUSBSIDDiffSize", &r_readmode);
- resources_get_int("SidUSBSIDBufferSize", &r_diffsize);
+ resources_get_int("SidUSBSIDDiffSize", &r_diffsize);
+ resources_get_int("SidUSBSIDBufferSize", &r_buffsize);
/* Apply settings to local variables */
readmode = r_readmode;
audiomode = r_audiomode;
@@ -162,9 +162,10 @@
int us_device_close(void)
{
log_message(usbsid_log, "Start device closing");
- if (usbsid) {
+ if (usbsid != NULL) {
mute_USBSID(usbsid);
close_USBSID(usbsid);
+ usbsid = NULL;
}
/* Clean up vars */
Modified: trunk/vice/src/lib/libusbsiddrv/USBSID.cpp
===================================================================
--- trunk/vice/src/lib/libusbsiddrv/USBSID.cpp 2025-10-25 13:09:13 UTC (rev 45804)
+++ trunk/vice/src/lib/libusbsiddrv/USBSID.cpp 2025-10-25 13:19:46 UTC (rev 45805)
@@ -433,7 +433,7 @@
/* SYNCHRONOUS */
-void USBSID_Class::USBSID_SingleWrite(unsigned char *buff, size_t len)
+void USBSID_Class::USBSID_SingleWrite(unsigned char *buff, int len)
{
if (!us_Initialised) return;
int actual_length = 0;
@@ -462,7 +462,7 @@
return result[0];
}
-unsigned char USBSID_Class::USBSID_SingleReadConfig(unsigned char *buff, size_t len)
+unsigned char USBSID_Class::USBSID_SingleReadConfig(unsigned char *buff, int len)
{
if (!us_Initialised) return 0;
int actual_length;
@@ -550,8 +550,8 @@
write_buffer[0] = (CYCLED_WRITE << 6);
write_buffer[1] = (reg & 0xFF);
write_buffer[2] = val;
- write_buffer[3] = (cycles >> 8);
- write_buffer[4] = (cycles & 0xFF);
+ write_buffer[3] = (uint8_t)(cycles >> 8);
+ write_buffer[4] = (uint8_t)(cycles & 0xFF);
USBSID_Write(write_buffer, 5);
return;
}
@@ -655,8 +655,8 @@
flush_buffer = 0;
run_thread = buffer_pos = 1;
threaded = withcycles = true;
+ USBSID_InitRingBuffer(ring_size, diff_size);
pthread_mutex_lock(&us_mutex);
- USBSID_InitRingBuffer(ring_size, diff_size);
us_thread++;
pthread_mutex_unlock(&us_mutex);
int error;
@@ -843,8 +843,8 @@
? (buffer_pos >= 5)
: (buffer_pos >= 3))) {
thread_buffer[0] = (withcycles == 1)
- ? (CYCLED_WRITE << 6 | (buffer_pos - 1))
- : (WRITE << 6 | (buffer_pos - 1));
+ ? (uint8_t)(CYCLED_WRITE << 6 | (buffer_pos - 1))
+ : (uint8_t)(WRITE << 6 | (buffer_pos - 1));
memcpy(out_buffer, thread_buffer, buffer_pos);
buffer_pos = 1;
flush_buffer = 0;
@@ -876,8 +876,8 @@
if (threaded && withcycles) {
USBSID_RingPut(reg);
USBSID_RingPut(val);
- USBSID_RingPut((cycles >> 8) & 0xFF);
- USBSID_RingPut(cycles & 0xFF);
+ USBSID_RingPut((uint8_t)(cycles >> 8) & 0xFF);
+ USBSID_RingPut((uint8_t)(cycles & 0xFF));
} else {
USBERR(stderr, "[USBSID] Function '%s' cannot be used when threaded = %d and withcycles = %d\n", __func__, threaded, withcycles);
}
@@ -895,7 +895,7 @@
|| buffer_pos == len_out_buffer
|| flush_buffer == 1) {
flush_buffer = 0;
- thread_buffer[0] = (CYCLED_WRITE << 6 | (buffer_pos - 1));
+ thread_buffer[0] = (uint8_t)((CYCLED_WRITE << 6) | (buffer_pos - 1));
memcpy(out_buffer, thread_buffer, buffer_pos);
buffer_pos = 1;
libusb_submit_transfer(transfer_out);
@@ -917,7 +917,7 @@
|| buffer_pos == len_out_buffer
|| flush_buffer == 1) {
flush_buffer = 0;
- thread_buffer[0] = (WRITE << 6 | (buffer_pos - 1));
+ thread_buffer[0] = (uint8_t)((WRITE << 6) | (buffer_pos - 1));
memcpy(out_buffer, thread_buffer, buffer_pos);
buffer_pos = 1;
libusb_submit_transfer(transfer_out);
@@ -951,7 +951,7 @@
static uint8_t a;
switch (addr) {
case 0xD400 ... 0xD499:
- a = (addr & SIDLMASK); /* $D400 -> $D479 1, 2, 3 & 4 */
+ a = (uint8_t)(addr & SIDLMASK); /* $D400 -> $D479 1, 2, 3 & 4 */
break;
case 0xD500 ... 0xD599:
case 0xDE00 ... 0xDF99:
@@ -958,7 +958,7 @@
a = ((SID3ADDR | (addr & SID2MASK)) & SIDLMASK);
break;
default:
- a = (addr & SIDLMASK);
+ a = (uint8_t)(addr & SIDLMASK);
break;
}
return a;
@@ -973,7 +973,7 @@
USBSID_GetClockRate(); /* Make sure we use the right clockrate */
us_InvCPUcycleDurationNanoSeconds = 1.0 / (ratio_t::den / (float)cycles_per_sec);
auto nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(timestamp - m_StartTime);
- return (int_fast64_t)(nsec.count() * us_InvCPUcycleDurationNanoSeconds);
+ return (int_fast64_t)((double)nsec.count() * us_InvCPUcycleDurationNanoSeconds);
}
uint_fast64_t USBSID_Class::USBSID_WaitForCycle(uint_fast16_t cycles)
@@ -981,7 +981,7 @@
if (!us_Initialised) return 0;
USBSID_GetClockRate(); /* Make sure we use the right clockrate */
timestamp_t now = std::chrono::high_resolution_clock::now();
- double dur = cycles * us_CPUcycleDuration; /* duration in nanoseconds */
+ double dur = (double)cycles * us_CPUcycleDuration; /* duration in nanoseconds */
duration_t duration = (duration_t)(int_fast64_t)dur; /* equals dur but as chrono nanoseconds */
auto target_time = m_LastTime + duration; /* ns to wait since m_LastTime (now + duration for actual wait time) */
// auto target_time = now + duration; /* ns to wait since m_LastTime (now + duration for actual wait time) */
@@ -993,7 +993,7 @@
}
m_LastTime = target_time;
/* int_fast64_t waited_cycles = wait_usec.count(); */
- int_fast64_t waited_cycles = (wait_nsec.count() * us_InvCPUcycleDurationNanoSeconds);
+ int_fast64_t waited_cycles = (int_fast64_t)((double)wait_nsec.count() * us_InvCPUcycleDurationNanoSeconds);
// USBDBG(stdout, "[C] %ld [WC] %ld [us] %ld [ns] %ld [ts] %lu\n",
// cycles, waited_cycles, wait_usec.count(), wait_nsec.count(), USBSID_CycleFromTimestamp(now));
// return (wait_nsec.count() > 0) ? waited_cycles : 0;
@@ -1031,7 +1031,7 @@
return;
}
-int USBSID_Class::LIBUSB_Available(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id)
+int USBSID_Class::LIBUSB_Available(uint16_t vendor_id, uint16_t product_id)
{
struct libusb_device **devs;
struct libusb_device *dev;
@@ -1239,7 +1239,7 @@
libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, 0);
/* Check for an available USBSID-Pico */
- if (LIBUSB_Available(ctx, VENDOR_ID, PRODUCT_ID) <= 0) {
+ if (LIBUSB_Available(VENDOR_ID, PRODUCT_ID) <= 0) {
USBDBG(stderr, "[USBSID] USBSID-Pico not connected\n");
goto out;
}
Modified: trunk/vice/src/lib/libusbsiddrv/USBSID.h
===================================================================
--- trunk/vice/src/lib/libusbsiddrv/USBSID.h 2025-10-25 13:09:13 UTC (rev 45804)
+++ trunk/vice/src/lib/libusbsiddrv/USBSID.h 2025-10-25 13:19:46 UTC (rev 45805)
@@ -287,7 +287,7 @@
/* LIBUSB */
int LIBUSB_Setup(bool start_threaded, bool with_cycles);
int LIBUSB_Exit(void);
- int LIBUSB_Available(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
+ int LIBUSB_Available(uint16_t vendor_id, uint16_t product_id);
void LIBUSB_StopTransfers(void);
int LIBUSB_OpenDevice(void);
void LIBUSB_CloseDevice(void);
@@ -365,9 +365,9 @@
void USBSID_ToggleStereo(void); /* Toggle between mono and stereo ~ v1.3 PCB only */
/* Synchronous direct */
- void USBSID_SingleWrite(unsigned char *buff, size_t len); /* Single write buffer of size_t ~ example: config writing */
+ void USBSID_SingleWrite(unsigned char *buff, int len); /* Single write buffer of size_t ~ example: config writing */
unsigned char USBSID_SingleRead(uint8_t reg); /* Single read register, return result */
- unsigned char USBSID_SingleReadConfig(unsigned char *buff, size_t len); /* Single to buffer of specified length ~ example: config reading */
+ unsigned char USBSID_SingleReadConfig(unsigned char *buff, int len); /* Single to buffer of specified length ~ example: config reading */
/* Asynchronous direct */
void USBSID_Write(unsigned char *buff, size_t len); /* Write buffer of size_t len */
Modified: trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.cpp
===================================================================
--- trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.cpp 2025-10-25 13:09:13 UTC (rev 45804)
+++ trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.cpp 2025-10-25 13:19:46 UTC (rev 45805)
@@ -117,7 +117,7 @@
if( p == NULL ) return -1;
return ((USBSID_Class*)p)->us_Found;
}
- void writesingle_USBSID(USBSIDitf p, unsigned char *buff, size_t len){
+ void writesingle_USBSID(USBSIDitf p, unsigned char *buff, int len){
if( p == NULL ) return;
return ((USBSID_Class*)p)->USBSID_SingleWrite(buff, len);
};
@@ -125,7 +125,7 @@
if( p == NULL ) return 0;
return ((USBSID_Class*)p)->USBSID_SingleRead(reg);
};
- void writebuffer_USBSID(USBSIDitf p, unsigned char *buff, size_t len){
+ void writebuffer_USBSID(USBSIDitf p, unsigned char *buff, int len){
if( p == NULL ) return;
return ((USBSID_Class*)p)->USBSID_Write(buff, len);
};
Modified: trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.h
===================================================================
--- trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.h 2025-10-25 13:09:13 UTC (rev 45804)
+++ trunk/vice/src/lib/libusbsiddrv/USBSIDInterface.h 2025-10-25 13:19:46 UTC (rev 45805)
@@ -62,11 +62,11 @@
int found_USBSID(USBSIDitf);
/* Synchronous direct */
- void writesingle_USBSID(USBSIDitf, unsigned char *buff, size_t len);
+ void writesingle_USBSID(USBSIDitf, unsigned char *buff, int len);
unsigned char readsingle_USBSID(USBSIDitf, uint8_t reg);
/* Asynchronous direct */
- void writebuffer_USBSID(USBSIDitf, unsigned char *buff, size_t len);
+ void writebuffer_USBSID(USBSIDitf, unsigned char *buff, int len);
void write_USBSID(USBSIDitf, uint8_t reg, uint8_t val);
void writecycled_USBSID(USBSIDitf, uint8_t reg, uint8_t val, uint16_t cycles);
unsigned char read_USBSID(USBSIDitf p, uint8_t reg);
@@ -79,6 +79,7 @@
void enablethread_USBSID(USBSIDitf);
void disablethread_USBSID(USBSIDitf);
void setflush_USBSID(USBSIDitf);
+ void flush_USBSID(USBSIDitf);
void restartringbuffer_USBSID(USBSIDitf);
void setbuffsize_USBSID(USBSIDitf, int size);
void setdiffsize_USBSID(USBSIDitf, int size);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|