From ec0d17992c448e99a0c046c967a74b1891684d00 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 12 Dec 2006 19:38:01 +0200 Subject: [PATCH] imported winuaesrc1340b4a.zip --- filesys.c | 22 +- main.c | 2 - newcpu.c | 6 +- od-win32/bsdsock.c | 425 +++++++++++++++++++---------------- od-win32/mman.c | 6 +- od-win32/parser.c | 59 +++-- od-win32/sounddep/sound.c | 58 +++-- od-win32/win32.c | 22 +- od-win32/win32gui.c | 6 +- od-win32/winuaechangelog.txt | 11 +- uaeserial.c | 30 +-- 11 files changed, 357 insertions(+), 290 deletions(-) diff --git a/filesys.c b/filesys.c index c8f45cb8..300b137b 100644 --- a/filesys.c +++ b/filesys.c @@ -3874,7 +3874,7 @@ int rdb_checksum (char *id, uae_u8 *p, int block) sum = -sum; if (sum) { write_log ("RDB: block %d ('%s') checksum error\n", block, id); - return 1; + return 0; } return 1; } @@ -3915,10 +3915,10 @@ static char *device_dupfix (uaecptr expbase, char *devname) return strdup (newname); } -static void dump_partinfo (char *name, int num, uaecptr pp) +static void dump_partinfo (char *name, int num, uaecptr pp, int partblock) { uae_u32 dostype = get_long (pp + 80); - write_log ("RDB: '%s' dostype=%08.8X\n", name, dostype); + write_log ("RDB: '%s' dostype=%08.8X. PartBlock=%d\n", name, dostype, partblock); write_log ("BlockSize: %d, Surfaces: %d, SectorsPerBlock %d\n", get_long (pp + 20) * 4, get_long (pp + 28), get_long (pp + 32)); write_log ("SectorsPerTrack: %d, Reserved: %d, LowCyl %d, HighCyl %d\n", @@ -3993,9 +3993,18 @@ static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacke hfd->sectors = rl (bufrdb + 68); hfd->heads = rl (bufrdb + 72); fileblock = rl (bufrdb + 32); - partblock = rl (bufrdb + 28); + + if (partnum == 0) { + write_log("RDB: RDSK detected at %d, FSHD=%d, C=%d S=%d H=%d\n", + rdblock, fileblock, hfd->cylinders, hfd->sectors, hfd->heads); + } + buf = xmalloc (readblocksize); for (i = 0; i <= partnum; i++) { + if (i == 0) + partblock = rl (bufrdb + 28); + else + partblock = rl (buf + 4 * 4); if (!legalrdbblock (uip, partblock)) { err = -2; goto error; @@ -4006,7 +4015,6 @@ static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacke err = -2; goto error; } - partblock = rl (buf + 4 * 4); } rdbmnt @@ -4028,7 +4036,7 @@ static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacke put_long (parmpacket + 12, 0); /* Device flags */ for (i = 0; i < PP_MAXSIZE; i++) put_byte (parmpacket + 16 + i, buf[128 + i]); - dump_partinfo (buf + 37, uip->devno, parmpacket); + dump_partinfo (buf + 37, uip->devno, parmpacket, partblock); dostype = get_long (parmpacket + 80); if (dostype == 0) { @@ -4072,14 +4080,12 @@ static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacke } if (!legalrdbblock (uip, fileblock)) { write_log("RDB: corrupt FSHD pointer %d\n", fileblock); - err = -1; goto error; } memset (buf, 0, readblocksize); hdf_read (hfd, buf, fileblock * hfd->blocksize, readblocksize); if (!rdb_checksum ("FSHD", buf, fileblock)) { write_log("RDB: checksum error in FSHD block %d\n", fileblock); - err = -1; goto error; } fileblock = rl (buf + 16); diff --git a/main.c b/main.c index 96c9137c..64ad24cd 100644 --- a/main.c +++ b/main.c @@ -318,8 +318,6 @@ void fixup_prefs (struct uae_prefs *p) if (p->cpu_cycle_exact) p->gfx_framerate = 1; #endif - if (err) - write_log ("Please use \"uae -h\" to get usage information.\n"); } int quit_program = 0; diff --git a/newcpu.c b/newcpu.c index 30364bee..b10137bc 100644 --- a/newcpu.c +++ b/newcpu.c @@ -1574,7 +1574,7 @@ unsigned long REGPARAM2 op_illg (uae_u32 opcode, struct regstruct *regs) if ((opcode & 0xF000) == 0xF000) { if (warned < 20) { - write_log ("B-Trap %x at %x (%p)\n", opcode, m68k_getpc (regs) + m68kpc_offset, regs->pc_p); + write_log ("B-Trap %x at %x (%p)\n", opcode, pc, regs->pc_p); warned++; } Exception(0xB, regs, 0); @@ -1587,6 +1587,10 @@ unsigned long REGPARAM2 op_illg (uae_u32 opcode, struct regstruct *regs) m68k_handle_trap (opcode & 0xFFF, regs); } #endif + if (warned < 20) { + write_log ("A-Trap %x at %x (%p)\n", opcode, pc, regs->pc_p); + warned++; + } Exception(0xA, regs, 0); return 4; } diff --git a/od-win32/bsdsock.c b/od-win32/bsdsock.c index 4a0c4a1b..82566d1b 100644 --- a/od-win32/bsdsock.c +++ b/od-win32/bsdsock.c @@ -35,15 +35,54 @@ #include "mmsystem.h" #include "win32.h" -static HWND hSockWnd; -static LRESULT CALLBACK SocketWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); +static int hWndSelector = 0; /* Set this to zero to get hSockWnd */ + +#define MAX_SELECT_THREADS 64 +#define MAX_GET_THREADS 64 + +struct selt { + HANDLE hThreads[MAX_SELECT_THREADS]; + struct threadargsw *threadargsw[MAX_SELECT_THREADS]; + HANDLE hEvents[MAX_SELECT_THREADS]; +}; + +struct gett { + HANDLE hGetThreads[MAX_GET_THREADS]; + struct threadargs *threadGetargs[MAX_GET_THREADS]; + int threadGetargs_inuse[MAX_GET_THREADS]; + HANDLE hGetEvents[MAX_GET_THREADS]; +}; + +struct pendingasync { + struct socketbase *asyncsb[MAXPENDINGASYNC]; + SOCKET asyncsock[MAXPENDINGASYNC]; + uae_u32 asyncsd[MAXPENDINGASYNC]; + int asyncindex; +}; + +struct bsdsockdata { + HWND hSockWnd; + HANDLE hSockThread; + HANDLE hSockReq; + HANDLE hSockReqHandled; + CRITICAL_SECTION csSigQueueLock; + CRITICAL_SECTION SockThreadCS; + DWORD threadid; + WSADATA wsbData; + + struct selt *st; + struct gett *gt; + struct pendingasync *as; +}; + +static struct bsdsockdata *bsd; + +static unsigned int __stdcall sock_thread(void *); + extern HWND hAmigaWnd; -static int hWndSelector = 0; /* Set this to zero to get hSockWnd */ -static CRITICAL_SECTION csSigQueueLock; -static DWORD threadid; -#define THREAD(func,arg) (HANDLE)_beginthreadex(NULL, 0, func, arg, 0, &threadid) +#define THREAD(func,arg) (HANDLE)_beginthreadex(NULL, 0, func, arg, 0, &bsd->threadid) #define THREADEND(result) _endthreadex(result) #define SETERRNO bsdsocklib_seterrno(sb, WSAGetLastError() - WSABASEERR) @@ -56,21 +95,13 @@ static DWORD threadid; #define FIOSETOWN _IOW('f', 124, long) /* set owner (struct Task *) */ #define FIOGETOWN _IOR('f', 123, long) /* get owner (struct Task *) */ -#define BEGINBLOCKING if (sb->ftable[sd-1] & SF_BLOCKING) sb->ftable[sd - 1] |= SF_BLOCKINGINPROGRESS -#define ENDBLOCKING sb->ftable[sd-1] &= ~SF_BLOCKINGINPROGRESS +#define BEGINBLOCKING if (sb->ftable[sd - 1] & SF_BLOCKING) sb->ftable[sd - 1] |= SF_BLOCKINGINPROGRESS +#define ENDBLOCKING sb->ftable[sd - 1] &= ~SF_BLOCKINGINPROGRESS -static WSADATA wsbData; +static LRESULT CALLBACK SocketWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static int PASCAL WSAEventSelect(SOCKET,HANDLE,long); -#define MAX_SELECT_THREADS 64 -static HANDLE hThreads[MAX_SELECT_THREADS]; -static struct threadargsw *threadargsw[MAX_SELECT_THREADS]; -static HANDLE hEvents[MAX_SELECT_THREADS]; - -#define MAX_GET_THREADS 64 -static HANDLE hGetThreads[MAX_GET_THREADS]; - struct threadargs { struct socketbase *sb; uae_u32 args1; @@ -89,17 +120,8 @@ struct threadargsw { uae_u32 timeout; }; -static struct threadargs *threadGetargs[MAX_GET_THREADS]; -static int threadGetargs_inuse[MAX_GET_THREADS]; -static HANDLE hGetEvents[MAX_GET_THREADS]; - -static HANDLE hSockThread; -static HANDLE hSockReq, hSockReqHandled; -static unsigned int __stdcall sock_thread(void *); - -static CRITICAL_SECTION SockThreadCS; -#define PREPARE_THREAD EnterCriticalSection(&SockThreadCS) -#define TRIGGER_THREAD { SetEvent(hSockReq); WaitForSingleObject(hSockReqHandled, INFINITE); LeaveCriticalSection(&SockThreadCS); } +#define PREPARE_THREAD EnterCriticalSection(&bsd->SockThreadCS) +#define TRIGGER_THREAD { SetEvent(bsd->hSockReq); WaitForSingleObject(bsd->hSockReqHandled, INFINITE); LeaveCriticalSection(&bsd->SockThreadCS); } #define SOCKVER_MAJOR 2 #define SOCKVER_MINOR 2 @@ -129,9 +151,14 @@ static int mySockStartup(void) SOCKET dummy; DWORD lasterror; - if (WSAStartup(MAKEWORD(SOCKVER_MAJOR, SOCKVER_MINOR), &wsbData)) { + if (!bsd) { + bsd = calloc (sizeof (struct bsdsockdata), 1); + bsd->st = calloc (sizeof (struct selt), 1); + bsd->gt = calloc (sizeof (struct gett), 1); + bsd->as = calloc (sizeof (struct pendingasync), 1); + } + if (WSAStartup(MAKEWORD(SOCKVER_MAJOR, SOCKVER_MINOR), &bsd->wsbData)) { lasterror = WSAGetLastError(); - if(lasterror == WSAVERNOTSUPPORTED) { char szMessage[MAX_DPATH]; WIN32GUI_LoadUIString(IDS_WSOCK2NEEDED, szMessage, MAX_DPATH); @@ -141,14 +168,14 @@ static int mySockStartup(void) return 0; } - if (LOBYTE (wsbData.wVersion) != SOCKVER_MAJOR || HIBYTE (wsbData.wVersion) != SOCKVER_MINOR) { + if (LOBYTE (bsd->wsbData.wVersion) != SOCKVER_MAJOR || HIBYTE (bsd->wsbData.wVersion) != SOCKVER_MINOR) { char szMessage[MAX_DPATH]; WIN32GUI_LoadUIString(IDS_WSOCK2NEEDED, szMessage, MAX_DPATH); gui_message(szMessage); return 0; } else { - write_log("BSDSOCK: using %s\n", wsbData.szDescription); + write_log("BSDSOCK: using %s\n", bsd->wsbData.szDescription); // make sure WSP/NSPStartup gets called from within the regular stack // (Windows 95/98 need this) if((dummy = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) != INVALID_SOCKET) { @@ -172,14 +199,14 @@ int init_socket_layer(void) if (currprefs.socket_emu) { if((result = mySockStartup())) { - InitializeCriticalSection(&csSigQueueLock); + InitializeCriticalSection(&bsd->csSigQueueLock); - if(hSockThread == NULL) { + if(bsd->hSockThread == NULL) { WNDCLASS wc; // Set up an invisible window and dummy wndproc - InitializeCriticalSection(&SockThreadCS); - hSockReq = CreateEvent(NULL, FALSE, FALSE, NULL); - hSockReqHandled = CreateEvent(NULL, FALSE, FALSE, NULL); + InitializeCriticalSection(&bsd->SockThreadCS); + bsd->hSockReq = CreateEvent(NULL, FALSE, FALSE, NULL); + bsd->hSockReqHandled = CreateEvent(NULL, FALSE, FALSE, NULL); wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW; wc.lpfnWndProc = SocketWindowProc; @@ -192,13 +219,13 @@ int init_socket_layer(void) wc.lpszMenuName = 0; wc.lpszClassName = "SocketFun"; if(RegisterClass(&wc)) { - hSockWnd = CreateWindowEx (0, + bsd->hSockWnd = CreateWindowEx (0, "SocketFun", "WinUAE Socket Window", WS_POPUP, 0, 0, 1, 1, NULL, NULL, 0, NULL); - hSockThread = THREAD(sock_thread, NULL); + bsd->hSockThread = THREAD(sock_thread, NULL); } } } @@ -214,19 +241,19 @@ void deinit_socket_layer(void) if (currprefs.socket_emu) { WSACleanup(); if(socket_layer_initialized) { - DeleteCriticalSection(&csSigQueueLock); - if(hSockThread) { - DeleteCriticalSection(&SockThreadCS); - CloseHandle(hSockReq); - hSockReq = NULL; - CloseHandle(hSockReqHandled); - WaitForSingleObject(hSockThread, INFINITE); - CloseHandle(hSockThread); + DeleteCriticalSection(&bsd->csSigQueueLock); + if(bsd->hSockThread) { + DeleteCriticalSection(&bsd->SockThreadCS); + CloseHandle(bsd->hSockReq); + bsd->hSockReq = NULL; + CloseHandle(bsd->hSockReqHandled); + WaitForSingleObject(bsd->hSockThread, INFINITE); + CloseHandle(bsd->hSockThread); } for (i = 0; i < MAX_SELECT_THREADS; i++) { - if (hThreads[i]) { - CloseHandle(hThreads[i]); - hThreads[i] = NULL; + if (bsd->st->hThreads[i]) { + CloseHandle(bsd->st->hThreads[i]); + bsd->st->hThreads[i] = NULL; } } } @@ -237,12 +264,12 @@ void deinit_socket_layer(void) void locksigqueue(void) { - EnterCriticalSection(&csSigQueueLock); + EnterCriticalSection(&bsd->csSigQueueLock); } void unlocksigqueue(void) { - LeaveCriticalSection(&csSigQueueLock); + LeaveCriticalSection(&bsd->csSigQueueLock); } // Asynchronous completion notification @@ -260,11 +287,6 @@ void unlocksigqueue(void) // Blocking sockets with asynchronous event notification are currently not safe to use. -static struct socketbase *asyncsb[MAXPENDINGASYNC]; -static SOCKET asyncsock[MAXPENDINGASYNC]; -static uae_u32 asyncsd[MAXPENDINGASYNC]; -static int asyncindex; - int host_sbinit(TrapContext *context, SB) { sb->sockAbort = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); @@ -294,14 +316,20 @@ void host_sbcleanup(SB) { int i; - for (i = 0; i < MAXPENDINGASYNC; i++) if (asyncsb[i] == sb) asyncsb[i] = NULL; + for (i = 0; i < MAXPENDINGASYNC; i++) { + if (bsd->as->asyncsb[i] == sb) + bsd->as->asyncsb[i] = NULL; + } - if (sb->hEvent != NULL) CloseHandle(sb->hEvent); + if (sb->hEvent != NULL) + CloseHandle(sb->hEvent); for (i = sb->dtablesize; i--; ) { - if (sb->dtable[i] != INVALID_SOCKET) host_closesocketquick(sb->dtable[i]); + if (sb->dtable[i] != INVALID_SOCKET) + host_closesocketquick(sb->dtable[i]); - if (sb->mtable[i]) asyncsb[(sb->mtable[i] - 0xb000) / 2] = NULL; + if (sb->mtable[i]) + bsd->as->asyncsb[(sb->mtable[i] - 0xb000) / 2] = NULL; } shutdown(sb->sockAbort,1); @@ -312,10 +340,15 @@ void host_sbcleanup(SB) void host_sbreset(void) { - memset(asyncsb, 0, sizeof asyncsb); - memset(asyncsock, 0, sizeof asyncsock); - memset(asyncsd, 0, sizeof asyncsd); - memset(threadargsw, 0, sizeof threadargsw); + int i; + for (i = 0; i < MAXPENDINGASYNC; i++) { + bsd->as->asyncsb[i] = 0; + bsd->as->asyncsock[i] = 0; + bsd->as->asyncsd[i] = 0; + } + for (i = 0; i < MAX_GET_THREADS; i++) { + bsd->st->threadargsw[i] = 0; + } } void sockmsg(unsigned int msg, WPARAM wParam, LPARAM lParam) @@ -325,19 +358,19 @@ void sockmsg(unsigned int msg, WPARAM wParam, LPARAM lParam) int sdi; index = (msg-0xb000)/2; - sb = asyncsb[index]; + sb = bsd->as->asyncsb[index]; if (!(msg & 1)) { // is this one really for us? - if ((SOCKET)wParam != asyncsock[index]) + if ((SOCKET)wParam != bsd->as->asyncsock[index]) { // cancel socket event - WSAAsyncSelect((SOCKET)wParam, hWndSelector ? hAmigaWnd : hSockWnd, 0, 0); + WSAAsyncSelect((SOCKET)wParam, hWndSelector ? hAmigaWnd : bsd->hSockWnd, 0, 0); return; } - sdi = asyncsd[index] - 1; + sdi = bsd->as->asyncsd[index] - 1; // asynchronous socket event? if (sb && !(sb->ftable[sdi] & SF_BLOCKINGINPROGRESS) && sb->mtable[sdi]) @@ -370,7 +403,7 @@ void sockmsg(unsigned int msg, WPARAM wParam, LPARAM lParam) { - asyncsb[index] = NULL; + bsd->as->asyncsb[index] = NULL; if (WSAGETASYNCERROR(lParam)) { @@ -393,19 +426,20 @@ static unsigned int allocasyncmsg(SB,uae_u32 sd,SOCKET s) int i; locksigqueue(); - for (i = asyncindex+1; i != asyncindex; i++) { + for (i = bsd->as->asyncindex+1; i != bsd->as->asyncindex; i++) { if (i == MAXPENDINGASYNC) i = 0; - if (!asyncsb[i]) { - asyncsb[i] = sb; - if (++asyncindex == MAXPENDINGASYNC) asyncindex = 0; + if (!bsd->as->asyncsb[i]) { + bsd->as->asyncsb[i] = sb; + if (++bsd->as->asyncindex == MAXPENDINGASYNC) + bsd->as->asyncindex = 0; unlocksigqueue(); if (s == INVALID_SOCKET) { - return i*2+0xb001; + return i * 2 + 0xb001; } else { - asyncsd[i] = sd; - asyncsock[i] = s; - return i * 2+0xb000; + bsd->as->asyncsd[i] = sd; + bsd->as->asyncsock[i] = s; + return i * 2 + 0xb000; } } } @@ -423,10 +457,10 @@ static void cancelasyncmsg(TrapContext *context, unsigned int wMsg) wMsg = (wMsg-0xb000)/2; - sb = asyncsb[wMsg]; + sb = bsd->as->asyncsb[wMsg]; if (sb != NULL) { - asyncsb[wMsg] = NULL; + bsd->as->asyncsb[wMsg] = NULL; CANCELSIGNAL; } } @@ -463,10 +497,10 @@ void setWSAAsyncSelect(SB, uae_u32 sd, SOCKET s, long lEvent ) wsbevents |= FD_CLOSE; wsbevents |= lEvent; i = (sb->mtable[sd-1]-0xb000)/2; - asyncsb[i] = sb; - asyncsd[i] = sd; - asyncsock[i] = s; - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],wsbevents); + bsd->as->asyncsb[i] = sb; + bsd->as->asyncsd[i] = sd; + bsd->as->asyncsock[i] = s; + WSAAsyncSelect(s, hWndSelector ? hAmigaWnd : bsd->hSockWnd, sb->mtable[sd-1], wsbevents); unlocksigqueue(); } @@ -641,10 +675,10 @@ void host_accept(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 nam if (s2 == INVALID_SOCKET) { SETERRNO; - if (sb->ftable[sd-1] & SF_BLOCKING && sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR) { + if (sb->ftable[sd-1] & SF_BLOCKING && sb->sb_errno == WSAEWOULDBLOCK - WSABASEERR) { if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) { if (sb->mtable[sd-1] == 0) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_ACCEPT); + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd->hSockWnd, wMsg, FD_ACCEPT); } else { setWSAAsyncSelect(sb,sd,s,FD_ACCEPT); } @@ -757,7 +791,7 @@ static BOOL HandleStuff( void ) BOOL quit = FALSE; SB = NULL; BOOL handled = TRUE; - if (hSockReq) { + if (bsd->hSockReq) { // 100ms sleepiness might need some tuning... //if(WaitForSingleObject( hSockReq, 100 ) == WAIT_OBJECT_0 ) { @@ -804,7 +838,7 @@ static BOOL HandleStuff( void ) SETERRNO; } } - SetEvent( hSockReqHandled ); + SetEvent(bsd->hSockReqHandled); } } else { quit = TRUE; @@ -832,7 +866,7 @@ static unsigned int __stdcall sock_thread(void *blah) HANDLE WaitHandle; MSG msg; - if(hSockWnd) { + if(bsd->hSockWnd) { // Make sure we're outrunning the wolves int pri = THREAD_PRIORITY_ABOVE_NORMAL; if (!os_winnt) { @@ -845,9 +879,9 @@ static unsigned int __stdcall sock_thread(void *blah) SetThreadPriority(GetCurrentThread(), pri); while(TRUE) { - if(hSockReq) { + if(bsd->hSockReq) { DWORD wait; - WaitHandle = hSockReq; + WaitHandle = bsd->hSockReq; wait = MsgWaitForMultipleObjects (1, &WaitHandle, FALSE,INFINITE, QS_POSTMESSAGE); if (wait == WAIT_OBJECT_0) { if(HandleStuff()) // See if its time to quit... @@ -855,9 +889,9 @@ static unsigned int __stdcall sock_thread(void *blah) } if (wait == WAIT_OBJECT_0 +1) { Sleep(10); - while( PeekMessage(&msg, NULL, WM_USER, 0xB000+MAXPENDINGASYNC*2, PM_REMOVE) > 0) { - TranslateMessage( &msg ); - DispatchMessage( &msg ); + while(PeekMessage(&msg, NULL, WM_USER, 0xB000 + MAXPENDINGASYNC * 2, PM_REMOVE) > 0) { + TranslateMessage(&msg); + DispatchMessage(&msg); } } } @@ -885,9 +919,9 @@ void host_connect(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 na if (namelen <= MAXADDRLEN) { if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) { if (sb->mtable[sd-1] == 0) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_CONNECT); + WSAAsyncSelect(s, hWndSelector ? hAmigaWnd : bsd->hSockWnd, wMsg, FD_CONNECT); } else { - setWSAAsyncSelect(sb,sd,s,FD_CONNECT); + setWSAAsyncSelect(sb, sd, s, FD_CONNECT); } BEGINBLOCKING; @@ -1064,7 +1098,7 @@ void host_sendto(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len, if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) { if (sb->mtable[sd-1] == 0) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_WRITE); + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd->hSockWnd,wMsg,FD_WRITE); } else { setWSAAsyncSelect(sb,sd,s,FD_WRITE); } @@ -1146,9 +1180,9 @@ void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 le { if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) { if (sb->mtable[sd-1] == 0) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_READ|FD_CLOSE); + WSAAsyncSelect(s, hWndSelector ? hAmigaWnd : bsd->hSockWnd, wMsg, FD_READ|FD_CLOSE); } else { - setWSAAsyncSelect(sb,sd,s,FD_READ|FD_CLOSE); + setWSAAsyncSelect(sb, sd, s, FD_READ|FD_CLOSE); } WAITSIGNAL; @@ -1156,7 +1190,7 @@ void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 le if (sb->mtable[sd-1] == 0) { cancelasyncmsg(context, wMsg); } else { - setWSAAsyncSelect(sb,sd,s,0); + setWSAAsyncSelect(sb, sd, s, 0); } if (sb->eintr) { @@ -1261,7 +1295,7 @@ void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 opt wsbevents |= FD_CLOSE; if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],wsbevents); + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd->hSockWnd,sb->mtable[sd-1],wsbevents); sb->resultval = 0; } else sb->resultval = -1; @@ -1418,7 +1452,8 @@ uae_u32 host_IoctlSocket(TrapContext *context, SB, uae_u32 sd, uae_u32 request, TRACE(("[FIOASYNC] -> enabled\n")); if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],FD_ACCEPT | FD_CONNECT | FD_OOB | FD_READ | FD_WRITE | FD_CLOSE); + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd-> hSockWnd, sb->mtable[sd-1], + FD_ACCEPT | FD_CONNECT | FD_OOB | FD_READ | FD_WRITE | FD_CLOSE); success = 0; break; } @@ -1450,7 +1485,7 @@ int host_CloseSocket(TrapContext *context, SB, int sd) if (s != INVALID_SOCKET) { if (sb->mtable[sd-1]) { - asyncsb[(sb->mtable[sd-1]-0xb000)/2] = NULL; + bsd->as->asyncsb[(sb->mtable[sd-1]-0xb000)/2] = NULL; sb->mtable[sd-1] = 0; } @@ -1474,7 +1509,7 @@ int host_CloseSocket(TrapContext *context, SB, int sd) break; if ((wMsg = allocasyncmsg(sb,sd,s)) != 0) { - WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_CLOSE); + WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : bsd->hSockWnd,wMsg,FD_CLOSE); WAITSIGNAL; @@ -1596,9 +1631,9 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp) SB; for (;;) { - WaitForSingleObject(hEvents[index],INFINITE); + WaitForSingleObject(bsd->st->hEvents[index],INFINITE); - if ((args = threadargsw[index]) != NULL) { + if ((args = bsd->st->threadargsw[index]) != NULL) { sb = args->sb; nfds = args->nfds; readfds = args->readfds; @@ -1665,7 +1700,7 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp) SETSIGNAL; - threadargsw[index] = NULL; + bsd->st->threadargsw[index] = NULL; SetEvent(sb->hEvent); } } @@ -1732,17 +1767,17 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua sb->needAbort = 1; for (i = 0; i < MAX_SELECT_THREADS; i++) { - if (hThreads[i] && !threadargsw[i]) + if (bsd->st->hThreads[i] && !bsd->st->threadargsw[i]) break; } if (i >= MAX_SELECT_THREADS) { for (i = 0; i < MAX_SELECT_THREADS; i++) { - if (!hThreads[i]) { - hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); - hThreads[i] = THREAD(thread_WaitSelect,&i); - if (hEvents[i] == NULL || hThreads[i] == NULL) { - hThreads[i] = 0; + if (!bsd->st->hThreads[i]) { + bsd->st->hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); + bsd->st->hThreads[i] = THREAD(thread_WaitSelect,&i); + if (bsd->st->hEvents[i] == NULL || bsd->st->hThreads[i] == NULL) { + bsd->st->hThreads[i] = 0; write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n", GetLastError()); bsdsocklib_seterrno(sb,12); // ENOMEM @@ -1750,7 +1785,7 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua return; } // this should improve responsiveness - SetThreadPriority(hThreads[i],THREAD_PRIORITY_TIME_CRITICAL); + SetThreadPriority(bsd->st->hThreads[i], THREAD_PRIORITY_TIME_CRITICAL); break; } } @@ -1768,9 +1803,9 @@ void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, ua taw.exceptfds = exceptfds; taw.timeout = timeout; - threadargsw[i] = &taw; + bsd->st->threadargsw[i] = &taw; - SetEvent(hEvents[i]); + SetEvent(bsd->st->hEvents[i]); m68k_dreg(&context->regs,0) = (((uae_u32)1)<signal)|sb->eintrsigs|wssigs; sigs = CallLib(context, get_long(4),-0x13e); // Wait() @@ -1892,12 +1927,12 @@ static unsigned int __stdcall thread_get(void *indexp) SB; for (;;) { - WaitForSingleObject(hGetEvents[index], INFINITE); - if (threadGetargs_inuse[index] == -1) { - threadGetargs_inuse[index] = 0; - threadGetargs[index] = NULL; + WaitForSingleObject(bsd->gt->hGetEvents[index], INFINITE); + if (bsd->gt->threadGetargs_inuse[index] == -1) { + bsd->gt->threadGetargs_inuse[index] = 0; + bsd->gt->threadGetargs[index] = NULL; } - if ((args = threadGetargs[index]) != NULL) { + if ((args = bsd->gt->threadGetargs[index]) != NULL) { sb = args->sb; if (args->args1 == 0) { // gethostbyname or gethostbyaddr @@ -1915,7 +1950,7 @@ static unsigned int __stdcall thread_get(void *indexp) } else { host = gethostbyaddr(name_rp,namelen,addrtype); } - if (threadGetargs_inuse[index] != -1) { + if (bsd->gt->threadGetargs_inuse[index] != -1) { // No CTRL-C Signal if (host == 0) { // Error occured @@ -1936,7 +1971,7 @@ static unsigned int __stdcall thread_get(void *indexp) buf = args->args5; name_rp = get_real_address(name); proto = getprotobyname (name_rp); - if (threadGetargs_inuse[index] != -1) { // No CTRL-C Signal + if (bsd->gt->threadGetargs_inuse[index] != -1) { // No CTRL-C Signal if (proto == 0) { // Error occured SETERRNO; @@ -1969,7 +2004,7 @@ static unsigned int __stdcall thread_get(void *indexp) name_rp = get_real_address(nameport); serv = getservbyname(name_rp,proto_rp); } - if (threadGetargs_inuse[index] != -1) { + if (bsd->gt->threadGetargs_inuse[index] != -1) { // No CTRL-C Signal if (serv == 0) { // Error occured @@ -1984,11 +2019,11 @@ static unsigned int __stdcall thread_get(void *indexp) TRACE(("-> ")); - if (threadGetargs_inuse[index] != -1) + if (bsd->gt->threadGetargs_inuse[index] != -1) SETSIGNAL; - threadGetargs_inuse[index] = 0; - threadGetargs[index] = NULL; + bsd->gt->threadGetargs_inuse[index] = 0; + bsd->gt->threadGetargs[index] = NULL; } } @@ -2044,23 +2079,23 @@ void host_gethostbynameaddr(TrapContext *context, SB, uae_u32 name, uae_u32 name args.args5 = buf; for (i = 0; i < MAX_GET_THREADS; i++) { - if (threadGetargs_inuse[i] == -1) { - threadGetargs_inuse[i] = 0; - threadGetargs[i] = NULL; + if (bsd->gt->threadGetargs_inuse[i] == -1) { + bsd->gt->threadGetargs_inuse[i] = 0; + bsd->gt->threadGetargs[i] = NULL; } - if (hGetThreads[i] && !threadGetargs_inuse[i]) break; + if (bsd->gt->hGetThreads[i] && !bsd->gt->threadGetargs_inuse[i]) break; } if (i >= MAX_GET_THREADS) { for (i = 0; i < MAX_GET_THREADS; i++) { - if (hGetThreads[i] == NULL) { - hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); - hGetThreads[i] = THREAD(thread_get, &i); - if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) { - hGetThreads[i] = NULL; + if (bsd->gt->hGetThreads[i] == NULL) { + bsd->gt->hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); + bsd->gt->hGetThreads[i] = THREAD(thread_get, &i); + if (bsd->gt->hGetEvents[i] == NULL || bsd->gt->hGetThreads[i] == NULL) { + bsd->gt->hGetThreads[i] = NULL; write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n", GetLastError()); - bsdsocklib_seterrno(sb,12); // ENOMEM + bsdsocklib_seterrno(sb, 12); // ENOMEM sb->resultval = -1; return; } @@ -2072,17 +2107,17 @@ void host_gethostbynameaddr(TrapContext *context, SB, uae_u32 name, uae_u32 name if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many gethostbyname()s\n"); else { - bsdsetpriority (hGetThreads[i]); - threadGetargs[i] = &args; - threadGetargs_inuse[i] = 1; + bsdsetpriority (bsd->gt->hGetThreads[i]); + bsd->gt->threadGetargs[i] = &args; + bsd->gt->threadGetargs_inuse[i] = 1; - SetEvent(hGetEvents[i]); + SetEvent(bsd->gt->hGetEvents[i]); } sb->eintr = 0; - while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) { + while (bsd->gt->threadGetargs_inuse[i] != 0 && sb->eintr == 0) { WAITSIGNAL; if (sb->eintr == 1) - threadGetargs_inuse[i] = -1; + bsd->gt->threadGetargs_inuse[i] = -1; } CANCELSIGNAL; @@ -2167,21 +2202,21 @@ void host_getprotobyname(TrapContext *context, SB, uae_u32 name) args.args5 = buf; for (i = 0; i < MAX_GET_THREADS; i++) { - if (threadGetargs_inuse[i] == -1) { - threadGetargs_inuse[i] = 0; - threadGetargs[i] = NULL; + if (bsd->gt->threadGetargs_inuse[i] == -1) { + bsd->gt->threadGetargs_inuse[i] = 0; + bsd->gt->threadGetargs[i] = NULL; } - if (hGetThreads[i] && !threadGetargs_inuse[i]) break; + if (bsd->gt->hGetThreads[i] && !bsd->gt->threadGetargs_inuse[i]) break; } if (i >= MAX_GET_THREADS) { for (i = 0; i < MAX_GET_THREADS; i++) { - if (!hGetThreads[i]) { - hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); - hGetThreads[i] = THREAD(thread_get,&i); - if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) { - hGetThreads[i] = 0; - write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",GetLastError()); - bsdsocklib_seterrno(sb,12); // ENOMEM + if (!bsd->gt->hGetThreads[i]) { + bsd->st->hEvents[i] = CreateEvent(NULL, FALSE, FALSE, NULL); + bsd->gt->hGetThreads[i] = THREAD(thread_get, &i); + if (bsd->gt->hGetEvents[i] == NULL || bsd->gt->hGetThreads[i] == NULL) { + bsd->gt->hGetThreads[i] = 0; + write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n", GetLastError()); + bsdsocklib_seterrno(sb, 12); // ENOMEM sb->resultval = -1; return; } @@ -2193,19 +2228,19 @@ void host_getprotobyname(TrapContext *context, SB, uae_u32 name) if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n"); else { - bsdsetpriority (hGetThreads[i]); + bsdsetpriority (bsd->gt->hGetThreads[i]); - threadGetargs[i] = &args; - threadGetargs_inuse[i] = 1; + bsd->gt->threadGetargs[i] = &args; + bsd->gt->threadGetargs_inuse[i] = 1; - SetEvent(hGetEvents[i]); + SetEvent(bsd->gt->hGetEvents[i]); } sb->eintr = 0; - while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) { + while (bsd->gt->threadGetargs_inuse[i] != 0 && sb->eintr == 0) { WAITSIGNAL; if (sb->eintr == 1) - threadGetargs_inuse[i] = -1; + bsd->gt->threadGetargs_inuse[i] = -1; } CANCELSIGNAL; @@ -2245,15 +2280,15 @@ void host_getprotobyname(TrapContext *context, SB, uae_u32 name) put_long(sb->protoent+8,p->p_proto); for (i = 0; i < numaliases; i++) - put_long(sb->protoent+12+i*4,addstr(&aptr,p->p_aliases[i])); - put_long(sb->protoent+12+numaliases*4,0); - put_long(sb->protoent,aptr); - addstr(&aptr,p->p_name); - TRACE(("OK (%s, %d)\n",p->p_name,p->p_proto)); + put_long(sb->protoent + 12 + i * 4, addstr(&aptr, p->p_aliases[i])); + put_long(sb->protoent + 12 + numaliases * 4,0); + put_long(sb->protoent, aptr); + addstr(&aptr, p->p_name); + TRACE(("OK (%s, %d)\n", p->p_name, p->p_proto)); bsdsocklib_seterrno(sb,0); } else { - TRACE(("failed (%d)\n",sb->sb_errno)); + TRACE(("failed (%d)\n", sb->sb_errno)); } } @@ -2292,21 +2327,21 @@ void host_getservbynameport(TrapContext *context, SB, uae_u32 nameport, uae_u32 args.args5 = buf; for (i = 0; i < MAX_GET_THREADS; i++) { - if (threadGetargs_inuse[i] == -1) { - threadGetargs_inuse[i] = 0; - threadGetargs[i] = NULL; + if (bsd->gt->threadGetargs_inuse[i] == -1) { + bsd->gt->threadGetargs_inuse[i] = 0; + bsd->gt->threadGetargs[i] = NULL; } - if (hGetThreads[i] && !threadGetargs_inuse[i]) break; + if (bsd->gt->hGetThreads[i] && !bsd->gt->threadGetargs_inuse[i]) break; } if (i >= MAX_GET_THREADS) { for (i = 0; i < MAX_GET_THREADS; i++) { - if (!hGetThreads[i]) { - hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL); - hGetThreads[i] = THREAD(thread_get,&i); - if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) { - hGetThreads[i] = 0; + if (!bsd->gt->hGetThreads[i]) { + bsd->gt->hGetEvents[i] = CreateEvent(NULL, FALSE, FALSE, NULL); + bsd->gt->hGetThreads[i] = THREAD(thread_get, &i); + if (bsd->gt->hGetEvents[i] == NULL || bsd->gt->hGetThreads[i] == NULL) { + bsd->gt->hGetThreads[i] = 0; write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",GetLastError()); - bsdsocklib_seterrno(sb,12); // ENOMEM + bsdsocklib_seterrno(sb, 12); // ENOMEM sb->resultval = -1; return; } @@ -2319,19 +2354,19 @@ void host_getservbynameport(TrapContext *context, SB, uae_u32 nameport, uae_u32 if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n"); else { - bsdsetpriority (hGetThreads[i]); + bsdsetpriority (bsd->gt->hGetThreads[i]); - threadGetargs[i] = &args; - threadGetargs_inuse[i] = 1; + bsd->gt->threadGetargs[i] = &args; + bsd->gt->threadGetargs_inuse[i] = 1; - SetEvent(hGetEvents[i]); + SetEvent(bsd->gt->hGetEvents[i]); } sb->eintr = 0; - while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) { + while (bsd->gt->threadGetargs_inuse[i] != 0 && sb->eintr == 0) { WAITSIGNAL; if (sb->eintr == 1) - threadGetargs_inuse[i] = -1; + bsd->gt->threadGetargs_inuse[i] = -1; } CANCELSIGNAL; @@ -2358,28 +2393,28 @@ void host_getservbynameport(TrapContext *context, SB, uae_u32 nameport, uae_u32 if (!sb->servent) { write_log("BSDSOCK: WARNING - getservby%s() ran out of Amiga memory (couldn't allocate %ld bytes)\n",type ? "port" : "name",size); - bsdsocklib_seterrno(sb,12); // ENOMEM + bsdsocklib_seterrno(sb, 12); // ENOMEM return; } sb->serventsize = size; - aptr = sb->servent+20+numaliases*4; + aptr = sb->servent + 20 + numaliases * 4; // transfer servent to Amiga memory - put_long(sb->servent+4,sb->servent+16); - put_long(sb->servent+8,(unsigned short)htons(s->s_port)); + put_long(sb->servent + 4, sb->servent + 16); + put_long(sb->servent + 8, (unsigned short)htons(s->s_port)); for (i = 0; i < numaliases; i++) - put_long(sb->servent+16+i*4,addstr(&aptr,s->s_aliases[i])); - put_long(sb->servent+16+numaliases*4,0); - put_long(sb->servent,aptr); - addstr(&aptr,s->s_name); - put_long(sb->servent+12,aptr); - addstr(&aptr,s->s_proto); - - TRACE(("OK (%s, %d)\n",s->s_name,(unsigned short)htons(s->s_port))); - bsdsocklib_seterrno(sb,0); + put_long(sb->servent + 16 + i * 4,addstr(&aptr,s->s_aliases[i])); + put_long(sb->servent + 16 + numaliases * 4,0); + put_long(sb->servent, aptr); + addstr(&aptr, s->s_name); + put_long(sb->servent + 12, aptr); + addstr(&aptr, s->s_proto); + + TRACE(("OK (%s, %d)\n", s->s_name, (unsigned short)htons(s->s_port))); + bsdsocklib_seterrno(sb, 0); } else { TRACE(("failed (%d)\n",sb->sb_errno)); diff --git a/od-win32/mman.c b/od-win32/mman.c index 1eaad80b..0305f114 100644 --- a/od-win32/mman.c +++ b/od-win32/mman.c @@ -19,9 +19,9 @@ static uae_u32 gfxoffs; uae_u8 *natmem_offset = NULL; #ifdef CPU_64_BIT -uae_u32 max_allowed_mman = 2048; +static uae_u32 max_allowed_mman = 2048; #else -uae_u32 max_allowed_mman = 512; +static uae_u32 max_allowed_mman = 512; #endif void cache_free(void *cache) @@ -70,6 +70,8 @@ void init_shm(void) total64 = memstatsex.ullAvailPageFile + memstatsex.ullAvailPhys; } } + if (totalphys64 >= (uae_u64)1800 * 1024 * 1024 && max_allowed_mman < 1024) + max_allowed_mman = 1024; } size64 = 16 * 1024 * 1024; diff --git a/od-win32/parser.c b/od-win32/parser.c index 99d99cb1..16b9d590 100644 --- a/od-win32/parser.c +++ b/od-win32/parser.c @@ -418,19 +418,19 @@ void openprinter( void ) DocInfo.pOutputFile = NULL; DocInfo.pDatatype = "RAW"; // Inform the spooler the document is beginning. - if( (dwJob = StartDocPrinter( hPrt, 1, (LPSTR)&DocInfo )) == 0 ) { - ClosePrinter( hPrt ); + if( (dwJob = StartDocPrinter(hPrt, 1, (LPSTR)&DocInfo)) == 0) { + ClosePrinter(hPrt ); hPrt = INVALID_HANDLE_VALUE; - } else if( StartPagePrinter( hPrt ) ) { + } else if(StartPagePrinter(hPrt)) { prtopen = 1; } } else { hPrt = INVALID_HANDLE_VALUE; // Stupid bug in Win32, where OpenPrinter fails, but hPrt ends up being zero } } - if( hPrt != INVALID_HANDLE_VALUE ) { + if (hPrt != INVALID_HANDLE_VALUE) { write_log( "PRINTER: Opening printer \"%s\" with handle 0x%x.\n", currprefs.prtname, hPrt ); - } else if( *currprefs.prtname ) { + } else if (*currprefs.prtname) { write_log( "PRINTER: ERROR - Couldn't open printer \"%s\" for output.\n", currprefs.prtname ); } } @@ -486,7 +486,7 @@ struct uaeserialdatawin32 HANDLE hCom; HANDLE evtr, evtw, evtt, evtwce; OVERLAPPED olr, olw, olwce; - int readactive, writeactive; + int writeactive; void *readdata, *writedata; volatile int threadactive; uae_thread_id tid; @@ -597,11 +597,11 @@ static void *uaeser_trap_thread (void *arg) sd->threadactive = 1; uae_sem_post (&sd->sync_sem); startwce(sd, &evtmask); - while (sd->threadactive) { + while (sd->threadactive == 1) { int sigmask = 0; uae_sem_wait (&sd->change_sem); if (WaitForSingleObject(sd->evtwce, 0) == WAIT_OBJECT_0) { - if ((evtmask & EV_RXCHAR) && !sd->readactive) + if (evtmask & EV_RXCHAR) sigmask |= 1; if ((evtmask & EV_TXEMPTY) && !sd->writeactive) sigmask |= 2; @@ -610,14 +610,6 @@ static void *uaeser_trap_thread (void *arg) cnt = 0; handles[cnt++] = sd->evtt; handles[cnt++] = sd->evtwce; - if (sd->readactive) { - if (GetOverlappedResult (sd->hCom, &sd->olr, &actual, FALSE)) { - sd->readactive = 0; - sigmask |= 1; - } else { - handles[cnt++] = sd->evtr; - } - } if (sd->writeactive) { if (GetOverlappedResult (sd->hCom, &sd->olw, &actual, FALSE)) { sd->writeactive = 0; @@ -627,11 +619,8 @@ static void *uaeser_trap_thread (void *arg) } } if (!sd->writeactive) - sigmask |= 1; - if (!sd->readactive) sigmask |= 2; - if (sigmask) - uaeser_signal (sd->user, sigmask); + uaeser_signal (sd->user, sigmask | 1); uae_sem_post (&sd->change_sem); WaitForMultipleObjects(cnt, handles, FALSE, INFINITE); } @@ -662,12 +651,18 @@ int uaeser_write (struct uaeserialdatawin32 *sd, uae_u8 *data, uae_u32 len) int uaeser_read (struct uaeserialdatawin32 *sd, uae_u8 *data, uae_u32 len) { int ret = 1; + DWORD err; + COMSTAT ComStat; + + if (!ClearCommError (sd->hCom, &err, &ComStat)) + return 0; + if (len > ComStat.cbInQue) + return 0; if (!ReadFile (sd->hCom, data, len, NULL, &sd->olr)) { - sd->readactive = 1; - if (GetLastError() != ERROR_IO_PENDING) { + if (GetLastError() == ERROR_IO_PENDING) + WaitForSingleObject(sd->evtr, INFINITE); + else ret = 0; - sd->readactive = 0; - } } SetEvent (sd->evtt); return ret; @@ -722,6 +717,13 @@ end: void uaeser_close (struct uaeserialdatawin32 *sd) { + if (sd->threadactive) { + sd->threadactive = -1; + SetEvent (sd->evtt); + while (sd->threadactive) + Sleep(10); + CloseHandle (sd->evtt); + } if (sd->hCom) CloseHandle(sd->hCom); if (sd->evtr) @@ -730,15 +732,6 @@ void uaeser_close (struct uaeserialdatawin32 *sd) CloseHandle(sd->evtw); if (sd->evtwce) CloseHandle(sd->evtwce); - if (sd->evtt) { - if (sd->threadactive) { - sd->threadactive = 0; - SetEvent (sd->evtt); - while (sd->threadactive) - Sleep(10); - } - CloseHandle (sd->evtt); - } uaeser_initdata (sd, sd->user); } diff --git a/od-win32/sounddep/sound.c b/od-win32/sounddep/sound.c index 345cd927..db1acba0 100644 --- a/od-win32/sounddep/sound.c +++ b/od-win32/sounddep/sound.c @@ -62,9 +62,15 @@ static char *sound_devices[MAX_SOUND_DEVICES]; GUID sound_device_guid[MAX_SOUND_DEVICES]; static int num_sound_devices; -static LPDIRECTSOUND8 lpDS; static LPDIRECTSOUNDBUFFER lpDSBprimary; + +#ifdef USE_DS8 +static LPDIRECTSOUND8 lpDS; static LPDIRECTSOUNDBUFFER8 lpDSBsecondary; +#else +static LPDIRECTSOUND lpDS; +static LPDIRECTSOUNDBUFFER lpDSBsecondary; +#endif static DWORD writepos; @@ -222,11 +228,22 @@ static int open_audio_ds (int size) if (sndbufsize > SND_MAX_BUFFER) sndbufsize = SND_MAX_BUFFER; +#ifdef USE_DS8 hr = DirectSoundCreate8 (&sound_device_guid[currprefs.win32_soundcard], &lpDS, NULL); +#else + hr = DirectSoundCreate (&sound_device_guid[currprefs.win32_soundcard], &lpDS, NULL); +#endif if (FAILED(hr)) { write_log ("SOUND: DirectSoundCreate() failure: %s\n", DXError (hr)); return 0; } + + hr = IDirectSound_SetCooperativeLevel (lpDS, hMainWnd, DSSCL_PRIORITY); + if (FAILED(hr)) { + write_log ("SOUND: Can't set cooperativelevel: %s\n", DXError (hr)); + goto error; + } + memset (&DSCaps, 0, sizeof (DSCaps)); DSCaps.dwSize = sizeof (DSCaps); hr = IDirectSound_GetCaps (lpDS, &DSCaps); @@ -254,7 +271,7 @@ static int open_audio_ds (int size) memset (&sound_buffer, 0, sizeof (sound_buffer)); sound_buffer.dwSize = sizeof (sound_buffer); - sound_buffer.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2; + sound_buffer.dwFlags = DSBCAPS_PRIMARYBUFFER; hr = IDirectSound_CreateSoundBuffer (lpDS, &sound_buffer, &lpDSBprimary, NULL); if (FAILED(hr)) { write_log ("SOUND: Primary CreateSoundBuffer() failure: %s\n", DXError (hr)); @@ -269,19 +286,19 @@ static int open_audio_ds (int size) goto error; } - hr = IDirectSound_SetCooperativeLevel (lpDS, hMainWnd, DSSCL_PRIORITY); - if (FAILED(hr)) { - write_log ("SOUND: Can't set cooperativelevel: %s\n", DXError (hr)); - goto error; - } - memset (&wavfmt, 0, sizeof (WAVEFORMATEX)); wavfmt.wFormatTag = WAVE_FORMAT_PCM; wavfmt.nChannels = (currprefs.sound_stereo == 3 || currprefs.sound_stereo == 2) ? 4 : (currprefs.sound_stereo ? 2 : 1); wavfmt.nSamplesPerSec = freq; wavfmt.wBitsPerSample = 16; - wavfmt.nBlockAlign = 16 / 8 * wavfmt.nChannels; - wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * freq; + wavfmt.nBlockAlign = wavfmt.wBitsPerSample / 8 * wavfmt.nChannels; + wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec; + + hr = IDirectSoundBuffer_SetFormat (lpDSBprimary, &wavfmt); + if (FAILED(hr)) { + write_log ("SOUND: Primary SetFormat() failure: %s\n", DXError (hr)); + goto error; + } max_sndbufsize = size * 4; if (max_sndbufsize > SND_MAX_BUFFER2) @@ -305,7 +322,7 @@ static int open_audio_ds (int size) sound_buffer.dwBufferBytes = dsoundbuf; sound_buffer.lpwfxFormat = &wavfmt; sound_buffer.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; - sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE; + sound_buffer.dwFlags |= DSBCAPS_CTRLVOLUME | DSBCAPS_STATIC; sound_buffer.guid3DAlgorithm = GUID_NULL; hr = IDirectSound_CreateSoundBuffer(lpDS, &sound_buffer, &pdsb, NULL); @@ -313,18 +330,18 @@ static int open_audio_ds (int size) write_log ("SOUND: Secondary CreateSoundBuffer() failure: %s\n", DXError (hr)); goto error; } +#ifdef USE_DS8 hr = IDirectSound_QueryInterface(pdsb, &IID_IDirectSoundBuffer8, (LPVOID*)&lpDSBsecondary); if (FAILED(hr)) { write_log ("SOUND: Primary QueryInterface() failure: %s\n", DXError (hr)); goto error; } IDirectSound_Release(pdsb); +#else + lpDSBsecondary = pdsb; + pdsb = NULL; +#endif - hr = IDirectSoundBuffer_SetFormat (lpDSBprimary, &wavfmt); - if (FAILED(hr)) { - write_log ("SOUND: Primary SetFormat() failure: %s\n", DXError (hr)); - goto error; - } setvolume (); cleardsbuffer (); init_sound_table16 (); @@ -459,6 +476,8 @@ void sound_setadjust (double v) static int safedist; +#define cf(x) if ((x) >= dsoundbuf) (x) -= dsoundbuf; + void restart_sound_buffer(void) { DWORD playpos, safed; @@ -469,13 +488,10 @@ void restart_sound_buffer(void) hr = IDirectSoundBuffer_GetCurrentPosition (lpDSBsecondary, &playpos, &safed); if (FAILED(hr)) return; - writepos = snd_writeoffset + safedist + playpos; - if (writepos >= dsoundbuf) - writepos -= dsoundbuf; + writepos = playpos + snd_writeoffset; + cf (writepos); } -#define cf(x) if ((x) >= dsoundbuf) (x) -= dsoundbuf; - static void finish_sound_buffer_ds (void) { static int tfprev; diff --git a/od-win32/win32.c b/od-win32/win32.c index 00e52da2..a9cd52a3 100644 --- a/od-win32/win32.c +++ b/od-win32/win32.c @@ -107,6 +107,7 @@ int ignore_messages_all; int pause_emulation; static int didmousepos; +static int sound_closed; int mouseactive, focus; static int mm_timerres; @@ -514,7 +515,6 @@ static int avioutput_video = 0; void setpriority (struct threadpriorities *pri) { int err; - write_log ("changing priority to %s\n", pri->name); if (os_winnt) err = SetPriorityClass (GetCurrentProcess (), pri->classvalue); else @@ -539,7 +539,6 @@ static void winuae_active (HWND hWnd, int minimized) timeend(); focus = 1; - write_log ("WinUAE now active via WM_ACTIVATE\n"); pri = &priorities[currprefs.win32_inactive_priority]; #ifndef _DEBUG if (!minimized) @@ -555,6 +554,14 @@ static void winuae_active (HWND hWnd, int minimized) if (emulation_paused > 0) emulation_paused = -1; ShowWindow (hWnd, SW_RESTORE); + if (sound_closed) { +#ifdef AHI + ahi_open_sound (); +#endif + set_audio (); + sound_closed = 0; + } +#if 0 #ifdef AHI ahi_close_sound (); #endif @@ -563,6 +570,7 @@ static void winuae_active (HWND hWnd, int minimized) ahi_open_sound (); #endif set_audio (); +#endif if (WIN32GFX_IsPicassoScreen ()) WIN32GFX_EnablePicasso(); getcapslock (); @@ -582,7 +590,6 @@ static void winuae_inactive (HWND hWnd, int minimized) if (minimized) exit_gui (0); focus = 0; - write_log ("WinUAE now inactive via WM_ACTIVATE\n"); wait_keyrelease (); setmouseactive (0); pri = &priorities[currprefs.win32_inactive_priority]; @@ -595,6 +602,7 @@ static void winuae_inactive (HWND hWnd, int minimized) #ifdef AHI ahi_close_sound (); #endif + sound_closed = 1; } if (!avioutput_video) { set_inhibit_frame (IHF_WINDOWHIDDEN); @@ -605,12 +613,14 @@ static void winuae_inactive (HWND hWnd, int minimized) ahi_close_sound (); #endif emulation_paused = 1; + sound_closed = 1; } } else { if (currprefs.win32_inactive_nosound) { close_sound (); #ifdef AHI ahi_close_sound (); + sound_closed = 1; #endif } } @@ -619,16 +629,18 @@ static void winuae_inactive (HWND hWnd, int minimized) #ifdef FILESYS filesys_flush_cache (); #endif +#if 0 close_sound (); #ifdef AHI ahi_close_sound (); #endif - if (gui_active) + if (gui_active) return; set_audio (); #ifdef AHI ahi_open_sound (); #endif +#endif } void minimizewindow (void) @@ -639,10 +651,12 @@ void minimizewindow (void) void disablecapture (void) { setmouseactive (0); +#if 0 close_sound (); #ifdef AHI ahi_close_sound (); #endif +#endif } static void handleXbutton (WPARAM wParam, int updown) diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index 8938fd3d..cdf5e619 100644 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -365,11 +365,7 @@ static HWND cachedlist = NULL; #define MIN_SLOW_MEM 0 #define MAX_SLOW_MEM 4 #define MIN_Z3_MEM 0 -#if defined(WIN64) -#define MAX_Z3_MEM 12 -#else -#define MAX_Z3_MEM 10 -#endif +#define MAX_Z3_MEM ((max_z3fastmem >> 20) <= 512 ? 10 : ((max_z3fastmem >> 20) == 1024) ? 11 : 12) #define MIN_P96_MEM 0 #define MAX_P96_MEM 7 #define MIN_M68K_PRIORITY 1 diff --git a/od-win32/winuaechangelog.txt b/od-win32/winuaechangelog.txt index 332d12cf..08aa0432 100644 --- a/od-win32/winuaechangelog.txt +++ b/od-win32/winuaechangelog.txt @@ -1,4 +1,13 @@ +Beta 4: + +- uaeserial.device tweaks +- added more logging to RDB parser +- 1G Z3 fast RAM allowed (only if NT-based Windows and >=2G RAM) +- do not reopen DirectSound when losing/gaining focus +- reverted DirectSound initialization to pre-1.3.3 version, perhaps + it helps with VIA AC97 pitch change issue.. + Beta 3: - uaeserial.device implemented, serial.device-like device that maps @@ -16,7 +25,7 @@ Beta 3: - more blitter tweaks, try to be compatible with broken programs that write to blitter registers while previous blit has not yet finished. - some DirectSound tweaks - + Beta 2: - fixed possible crash when input recording stops (introduced in b1) diff --git a/uaeserial.c b/uaeserial.c index 245f9ffc..735a73d8 100644 --- a/uaeserial.c +++ b/uaeserial.c @@ -3,14 +3,13 @@ * * uaeserial.device * - * Copyright 2004 Toni Wilen + * Copyright 2004/2006 Toni Wilen * */ #include "sysconfig.h" #include "sysdeps.h" -#include "uae.h" #include "threaddep/thread.h" #include "options.h" #include "memory.h" @@ -155,12 +154,6 @@ static void io_log (char *msg, uaecptr request) get_long (request + 32), get_byte (request + 31)); } -static void memcpyha (uae_u32 dst, char *src, int size) -{ - while (size--) - put_byte (dst++, *src++); -} - static struct devstruct *getdevstruct (int uniq) { int i; @@ -183,8 +176,8 @@ static int start_thread (struct devstruct *dev) static void dev_close_3 (struct devstruct *dev) { - dev->unit = -1; uaeser_close (dev->sysdata); + dev->unit = -1; xfree (dev->sysdata); write_comm_pipe_u32 (&dev->requests, 0, 1); } @@ -213,7 +206,7 @@ static int setparams(struct devstruct *dev, uaecptr req) rbuffer = get_long (req + io_RBufLen); v = get_long (req + io_ExtFlags); if (v) { - write_log ("UAESER: io_ExtFlags=%d, not supported\n", v); + write_log ("UAESER: io_ExtFlags=%08.8x, not supported\n", v); return 5; } baud = get_long (req + io_Baud); @@ -238,7 +231,8 @@ static int setparams(struct devstruct *dev, uaecptr req) write_log ("UAESER: Read=%d, Write=%d, Stop=%d, not supported\n", rbits, wbits, sbits); return 5; } - write_log ("UAESER: BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PARITY=%d\n", + write_log ("%s:%d BAUD=%d BUF=%d BITS=%d+%d RTSCTS=%d PARITY=%d\n", + getdevname(), dev->unit, baud, rbuffer, rbits, sbits, rtscts, parity); v = uaeser_setparams (dev->sysdata, baud, rbuffer, rbits, sbits, rtscts, parity); if (!v) @@ -403,21 +397,21 @@ void uaeser_signal (struct devstruct *dev, int sigmask) uae_u32 io_error = 0, io_actual = 0; uae_u8 *addr; int io_done = 0; - int v; switch (command) { case CMD_READ: if (sigmask & 1) { - if (uaeser_query (dev->sysdata, NULL, &v)) { - if (v >= io_length) { - io_error = -5; - addr = memmap(io_data, io_length); - if (addr && uaeser_read (dev->sysdata, addr, io_length)) - io_error = 0; + addr = memmap(io_data, io_length); + if (addr) { + if (uaeser_read (dev->sysdata, addr, io_length)) { + io_error = 0; io_actual = io_length; io_done = 1; } + } else { + io_error = -6; + io_done = 1; } } break; -- 2.47.3