From f05cd77eb463296ff43240f89fcc64c5b42739b8 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 00:54:21 -0700 Subject: [PATCH 01/19] Renamed ASM_SYM_FOR_FUNC to ASM_SYM. Use ASM_SYM in place of __asm__ in a couple places. --- BasiliskII/src/BeOS/sysdeps.h | 4 ++-- BasiliskII/src/Unix/sysdeps.h | 4 ++-- BasiliskII/src/Windows/sysdeps.h | 4 ++-- BasiliskII/src/uae_cpu/m68k.h | 4 ++-- BasiliskII/src/uae_cpu/newcpu.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BasiliskII/src/BeOS/sysdeps.h b/BasiliskII/src/BeOS/sysdeps.h index abeadbd3..ed3ba9c3 100644 --- a/BasiliskII/src/BeOS/sysdeps.h +++ b/BasiliskII/src/BeOS/sysdeps.h @@ -108,7 +108,7 @@ static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" #define X86_ASSEMBLY #define UNALIGNED_PROFITABLE #define OPTIMIZED_FLAGS -#define ASM_SYM_FOR_FUNC(a) __asm__(a) +#define ASM_SYM(a) __asm__(a) #define REGPARAM __attribute__((regparm(3))) #else @@ -122,7 +122,7 @@ static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = v;} #undef X86_ASSEMBLY #define UNALIGNED_PROFITABLE #undef OPTIMIZED_FLAGS -#define ASM_SYM_FOR_FUNC(a) +#define ASM_SYM(a) #define REGPARAM #endif diff --git a/BasiliskII/src/Unix/sysdeps.h b/BasiliskII/src/Unix/sysdeps.h index f53293a7..df291939 100644 --- a/BasiliskII/src/Unix/sysdeps.h +++ b/BasiliskII/src/Unix/sysdeps.h @@ -493,9 +493,9 @@ static inline uae_u32 do_byteswap_16(uae_u32 v) #define write_log printf #if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) -#define ASM_SYM_FOR_FUNC(a) __asm__(a) +#define ASM_SYM(a) __asm__(a) #else -#define ASM_SYM_FOR_FUNC(a) +#define ASM_SYM(a) #endif #ifndef REGPARAM diff --git a/BasiliskII/src/Windows/sysdeps.h b/BasiliskII/src/Windows/sysdeps.h index b9bdc44c..b64a19fa 100755 --- a/BasiliskII/src/Windows/sysdeps.h +++ b/BasiliskII/src/Windows/sysdeps.h @@ -297,9 +297,9 @@ static inline uae_u32 do_byteswap_16_g(uae_u32 v) #define ATTRIBUTE_PACKED __attribute__((packed)) #if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) -#define ASM_SYM_FOR_FUNC(a) __asm__(a) +#define ASM_SYM(a) __asm__(a) #else -#define ASM_SYM_FOR_FUNC(a) +#define ASM_SYM(a) #endif #ifndef REGPARAM diff --git a/BasiliskII/src/uae_cpu/m68k.h b/BasiliskII/src/uae_cpu/m68k.h index 36c6c04d..75063082 100644 --- a/BasiliskII/src/uae_cpu/m68k.h +++ b/BasiliskII/src/uae_cpu/m68k.h @@ -59,7 +59,7 @@ struct flag_struct { #define COPY_CARRY (regflags.x = regflags.cznv) -extern struct flag_struct regflags __asm__ ("regflags"); +extern struct flag_struct regflags ASM_SYM ("regflags"); static __inline__ int cctrue(int cc) { @@ -202,7 +202,7 @@ struct flag_struct { #define COPY_CARRY (regflags.x = (regflags.cznv)>>8) -extern struct flag_struct regflags __asm__ ("regflags"); +extern struct flag_struct regflags ASM_SYM("regflags"); static __inline__ int cctrue(int cc) { diff --git a/BasiliskII/src/uae_cpu/newcpu.h b/BasiliskII/src/uae_cpu/newcpu.h index 408e475a..1d07c36b 100644 --- a/BasiliskII/src/uae_cpu/newcpu.h +++ b/BasiliskII/src/uae_cpu/newcpu.h @@ -61,7 +61,7 @@ struct cputbl { uae_u16 opcode; }; -extern cpuop_func *cpufunctbl[65536] ASM_SYM_FOR_FUNC ("cpufunctbl"); +extern cpuop_func *cpufunctbl[65536] ASM_SYM("cpufunctbl"); #if USE_JIT typedef void compop_func (uae_u32) REGPARAM; From 3271fc9d2883e3c5c5abfcf6e76916989456e2cb Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:02:19 -0700 Subject: [PATCH 02/19] Added lengthof. --- BasiliskII/src/include/main.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BasiliskII/src/include/main.h b/BasiliskII/src/include/main.h index d886eb29..1ba7b6ac 100644 --- a/BasiliskII/src/include/main.h +++ b/BasiliskII/src/include/main.h @@ -74,4 +74,15 @@ extern uint32 InterruptFlags; // Currently pending interrupts extern void SetInterruptFlag(uint32 flag); // Set/clear interrupt flags extern void ClearInterruptFlag(uint32 flag); +// Array length +#if __cplusplus >= 201103L || (_MSC_VER >= 1900 && defined __cplusplus) +template +constexpr size_t lengthof(T (& a)[size]) +{ + return size; +} +#else +#define lengthof(a) (sizeof(a) / sizeof(a[0])) +#endif + #endif From 0daa18ab2a7e0c8f3d813cd2e916555a0a3b623a Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:11:28 -0700 Subject: [PATCH 03/19] slirp compiles cleanly in MSVC. Use standard C prototypes instead of K&R. --- BasiliskII/src/slirp/bootp.h | 2 +- BasiliskII/src/slirp/debug.c | 15 +- BasiliskII/src/slirp/debug.h | 22 +- BasiliskII/src/slirp/if.c | 9 +- BasiliskII/src/slirp/if.h | 4 +- BasiliskII/src/slirp/ip.h | 6 +- BasiliskII/src/slirp/ip_icmp.c | 10 +- BasiliskII/src/slirp/ip_icmp.h | 8 +- BasiliskII/src/slirp/ip_input.c | 2 +- BasiliskII/src/slirp/ip_output.c | 9 +- BasiliskII/src/slirp/mbuf.c | 37 +- BasiliskII/src/slirp/mbuf.h | 22 +- BasiliskII/src/slirp/misc.c | 170 ++--- BasiliskII/src/slirp/misc.h | 38 +- BasiliskII/src/slirp/sbuf.c | 31 +- BasiliskII/src/slirp/sbuf.h | 14 +- BasiliskII/src/slirp/slirp.c | 184 ++--- BasiliskII/src/slirp/slirp.h | 140 ++-- BasiliskII/src/slirp/slirp_config.h | 8 - BasiliskII/src/slirp/socket.c | 45 +- BasiliskII/src/slirp/socket.h | 38 +- BasiliskII/src/slirp/tcp.h | 6 +- BasiliskII/src/slirp/tcp_input.c | 1024 ++++++++++++++------------- BasiliskII/src/slirp/tcp_output.c | 32 +- BasiliskII/src/slirp/tcp_subr.c | 76 +- BasiliskII/src/slirp/tcp_timer.h | 8 +- BasiliskII/src/slirp/tftp.h | 2 +- BasiliskII/src/slirp/udp.c | 12 +- BasiliskII/src/slirp/udp.h | 18 +- 29 files changed, 921 insertions(+), 1071 deletions(-) diff --git a/BasiliskII/src/slirp/bootp.h b/BasiliskII/src/slirp/bootp.h index 5c2e62ab..54a86ca2 100644 --- a/BasiliskII/src/slirp/bootp.h +++ b/BasiliskII/src/slirp/bootp.h @@ -115,7 +115,7 @@ struct bootp_t { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif void bootp_input(struct mbuf *m); diff --git a/BasiliskII/src/slirp/debug.c b/BasiliskII/src/slirp/debug.c index d3d8c579..916b9a8e 100644 --- a/BasiliskII/src/slirp/debug.c +++ b/BasiliskII/src/slirp/debug.c @@ -16,8 +16,6 @@ int dostats = 0; #endif int slirp_debug = 0; -extern char *strerror _P((int)); - /* Carry over one item from main.c so that the tty's restored. * Only done when the tty being used is /dev/tty --RedWolf */ extern struct termios slirp_tty_settings; @@ -294,6 +292,7 @@ mbufstats() void sockstats() { + char addr[INET_ADDRSTRLEN]; char buff[256]; int n; struct socket *so; @@ -311,9 +310,11 @@ sockstats() buff[17] = 0; lprint("%s %3d %15s %5d ", buff, so->s, - inet_ntoa(so->so_laddr), ntohs(so->so_lport)); + inet_ntop(AF_INET, &so->so_laddr, addr, sizeof(addr)), + ntohs(so->so_lport)); lprint("%15s %5d %5d %5d\r\n", - inet_ntoa(so->so_faddr), ntohs(so->so_fport), + inet_ntop(AF_INET, &so->so_faddr, addr, sizeof(addr)), + ntohs(so->so_fport), so->so_rcv.sb_cc, so->so_snd.sb_cc); } @@ -325,9 +326,11 @@ sockstats() buff[17] = 0; lprint("%s %3d %15s %5d ", buff, so->s, - inet_ntoa(so->so_laddr), ntohs(so->so_lport)); + inet_ntop(AF_INET, &so->so_laddr, addr, sizeof(addr)), + ntohs(so->so_lport)); lprint("%15s %5d %5d %5d\r\n", - inet_ntoa(so->so_faddr), ntohs(so->so_fport), + inet_ntop(AF_INET, &so->so_faddr, addr, sizeof(addr)), + ntohs(so->so_fport), so->so_rcv.sb_cc, so->so_snd.sb_cc); } } diff --git a/BasiliskII/src/slirp/debug.h b/BasiliskII/src/slirp/debug.h index 6e8444da..c5d42195 100644 --- a/BasiliskII/src/slirp/debug.h +++ b/BasiliskII/src/slirp/debug.h @@ -36,15 +36,15 @@ extern int slirp_debug; #endif -void debug_init _P((char *, int)); -//void ttystats _P((struct ttys *)); -void allttystats _P((void)); -void ipstats _P((void)); -void vjstats _P((void)); -void tcpstats _P((void)); -void udpstats _P((void)); -void icmpstats _P((void)); -void mbufstats _P((void)); -void sockstats _P((void)); -void slirp_exit _P((int)); +void debug_init(char *, int); +//void ttystats(struct ttys *); +void allttystats(void); +void ipstats(void); +void vjstats(void); +void tcpstats(void); +void udpstats(void); +void icmpstats(void); +void mbufstats(void); +void sockstats(void); +void slirp_exit(int); diff --git a/BasiliskII/src/slirp/if.c b/BasiliskII/src/slirp/if.c index eab8a46e..9185dcf6 100644 --- a/BasiliskII/src/slirp/if.c +++ b/BasiliskII/src/slirp/if.c @@ -7,11 +7,11 @@ #include -int if_mtu, if_mru; +size_t if_mtu, if_mru; int if_comp; int if_maxlinkhdr; -int if_queued = 0; /* Number of packets queued so far */ -int if_thresh = 10; /* Number of packets queued before we start sending +int if_queued = 0; /* Number of packets queued so far */ +int if_thresh = 10; /* Number of packets queued before we start sending * (to prevent allocing too many mbufs) */ struct mbuf if_fastq; /* fast queue (for interactive data) */ @@ -116,7 +116,8 @@ if_input(ttyp) DEBUG_MISC((dfd, " read %d bytes\n", if_n)); if (if_n <= 0) { - if (if_n == 0 || (errno != EINTR && errno != EAGAIN)) { + int error = WSAGetLastError(); + if (if_n == 0 || (error != WSAEINTR && error != EAGAIN)) { if (ttyp->up) link_up--; tty_detached(ttyp, 0); diff --git a/BasiliskII/src/slirp/if.h b/BasiliskII/src/slirp/if.h index 5d96a903..a2564ab1 100644 --- a/BasiliskII/src/slirp/if.h +++ b/BasiliskII/src/slirp/if.h @@ -15,8 +15,8 @@ /* Needed for FreeBSD */ #undef if_mtu -extern int if_mtu; -extern int if_mru; /* MTU and MRU */ +extern size_t if_mtu; +extern size_t if_mru; /* MTU and MRU */ extern int if_comp; /* Flags for compression */ extern int if_maxlinkhdr; extern int if_queued; /* Number of packets queued so far */ diff --git a/BasiliskII/src/slirp/ip.h b/BasiliskII/src/slirp/ip.h index dffebac3..e0c7de96 100644 --- a/BasiliskII/src/slirp/ip.h +++ b/BasiliskII/src/slirp/ip.h @@ -98,7 +98,7 @@ struct ip { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif #define IP_MAXPACKET 65535 /* maximum packet size */ @@ -168,7 +168,7 @@ struct ip_timestamp { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif /* flag bits for ipt_flg */ @@ -230,7 +230,7 @@ struct ipovly { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif /* diff --git a/BasiliskII/src/slirp/ip_icmp.c b/BasiliskII/src/slirp/ip_icmp.c index 7cbda790..75a4614a 100644 --- a/BasiliskII/src/slirp/ip_icmp.c +++ b/BasiliskII/src/slirp/ip_icmp.c @@ -223,9 +223,9 @@ icmp_error(msrc, type, code, minsize, message) if(!msrc) goto end_error; ip = mtod(msrc, struct ip *); #if DEBUG - { char bufa[20], bufb[20]; - strcpy(bufa, inet_ntoa(ip->ip_src)); - strcpy(bufb, inet_ntoa(ip->ip_dst)); + { char bufa[INET_ADDRSTRLEN], bufb[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &ip->ip_src, bufa, sizeof(bufa)); + inet_ntop(AF_INET, &ip->ip_dst, bufb, sizeof(bufb)); DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb)); } #endif @@ -244,7 +244,7 @@ icmp_error(msrc, type, code, minsize, message) /* make a copy */ if(!(m=m_get())) goto end_error; /* get mbuf */ - { int new_m_size; + { u_int new_m_size; new_m_size=sizeof(struct ip )+ICMP_MINLEN+msrc->m_len+ICMP_MAXDATALEN; if(new_m_size>m->m_size) m_inc(m, new_m_size); } @@ -299,7 +299,7 @@ icmp_error(msrc, type, code, minsize, message) /* fill in ip */ ip->ip_hl = hlen >> 2; - ip->ip_len = m->m_len; + ip->ip_len = (u_int16_t)m->m_len; ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ diff --git a/BasiliskII/src/slirp/ip_icmp.h b/BasiliskII/src/slirp/ip_icmp.h index 6968daa7..683dc87f 100644 --- a/BasiliskII/src/slirp/ip_icmp.h +++ b/BasiliskII/src/slirp/ip_icmp.h @@ -95,7 +95,7 @@ struct icmp { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif /* @@ -161,8 +161,8 @@ struct icmp { (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) -void icmp_input _P((struct mbuf *, int)); -void icmp_error _P((struct mbuf *, u_char, u_char, int, char *)); -void icmp_reflect _P((struct mbuf *)); +void icmp_input(struct mbuf *, int); +void icmp_error(struct mbuf *, u_char, u_char, int, char *); +void icmp_reflect(struct mbuf *); #endif diff --git a/BasiliskII/src/slirp/ip_input.c b/BasiliskII/src/slirp/ip_input.c index b9a60ede..d9426997 100644 --- a/BasiliskII/src/slirp/ip_input.c +++ b/BasiliskII/src/slirp/ip_input.c @@ -68,7 +68,7 @@ ip_input(m) struct mbuf *m; { register struct ip *ip; - int hlen; + u_int hlen; DEBUG_CALL("ip_input"); DEBUG_ARG("m = %lx", (long)m); diff --git a/BasiliskII/src/slirp/ip_output.c b/BasiliskII/src/slirp/ip_output.c index 0d1ae1b2..fb9a9420 100644 --- a/BasiliskII/src/slirp/ip_output.c +++ b/BasiliskII/src/slirp/ip_output.c @@ -55,8 +55,9 @@ ip_output(so, m0) { register struct ip *ip; register struct mbuf *m = m0; - register int hlen = sizeof(struct ip ); - int len, off, error = 0; + register u_int hlen = sizeof(struct ip); + u_int len, off; + int error = 0; DEBUG_CALL("ip_output"); DEBUG_ARG("so = %lx", (long)so); @@ -128,7 +129,7 @@ ip_output(so, m0) */ m0 = m; mhlen = sizeof (struct ip); - for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) { + for (off = hlen + len; off < ip->ip_len; off += len) { register struct ip *mhip; m = m_get(); if (m == 0) { @@ -173,7 +174,7 @@ ip_output(so, m0) * and updating header, then send each fragment (in order). */ m = m0; - m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len); + m_adj(m, hlen + firstlen - ip->ip_len); ip->ip_len = htons((u_int16_t)m->m_len); ip->ip_off = htons((u_int16_t)(ip->ip_off | IP_MF)); ip->ip_sum = 0; diff --git a/BasiliskII/src/slirp/mbuf.c b/BasiliskII/src/slirp/mbuf.c index 2b53bc3e..5a16fab8 100644 --- a/BasiliskII/src/slirp/mbuf.c +++ b/BasiliskII/src/slirp/mbuf.c @@ -24,18 +24,16 @@ int mbuf_alloced = 0; struct mbuf m_freelist, m_usedlist; int mbuf_thresh = 30; int mbuf_max = 0; -int msize; +size_t msize; -void -m_init() +void m_init() { m_freelist.m_next = m_freelist.m_prev = &m_freelist; m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist; msize_init(); } -void -msize_init() +void msize_init() { /* * Find a nice value for msize @@ -53,8 +51,7 @@ msize_init() * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, * which tells m_free to actually free() it */ -struct mbuf * -m_get() +struct mbuf *m_get() { register struct mbuf *m; int flags = 0; @@ -89,9 +86,7 @@ end_error: return m; } -void -m_free(m) - struct mbuf *m; +void m_free(struct mbuf *m) { DEBUG_CALL("m_free"); @@ -124,9 +119,7 @@ m_free(m) * the other.. if result is too big for one mbuf, malloc() * an M_EXT data segment */ -void -m_cat(m, n) - register struct mbuf *m, *n; +void m_cat(register struct mbuf *m, register struct mbuf *n) { /* * If there's no room, realloc @@ -142,10 +135,7 @@ m_cat(m, n) /* make m size bytes large */ -void -m_inc(m, size) - struct mbuf *m; - int size; +void m_inc(struct mbuf *m, u_int size) { int datasize; @@ -179,10 +169,7 @@ m_inc(m, size) -void -m_adj(m, len) - struct mbuf *m; - int len; +void m_adj(struct mbuf *m, int len) { if (m == NULL) return; @@ -202,9 +189,7 @@ m_adj(m, len) * Copy len bytes from m, starting off bytes into n */ int -m_copy(n, m, off, len) - struct mbuf *n, *m; - int off, len; +m_copy(struct mbuf *n, struct mbuf *m, u_int off, u_int len) { if (len > M_FREEROOM(n)) return -1; @@ -220,9 +205,7 @@ m_copy(n, m, off, len) * XXX This is a kludge, I should eliminate the need for it * Fortunately, it's not used often */ -struct mbuf * -dtom(dat) - void *dat; +struct mbuf *dtom(void *dat) { struct mbuf *m; diff --git a/BasiliskII/src/slirp/mbuf.h b/BasiliskII/src/slirp/mbuf.h index 183254a0..11b252bb 100644 --- a/BasiliskII/src/slirp/mbuf.h +++ b/BasiliskII/src/slirp/mbuf.h @@ -63,11 +63,11 @@ struct m_hdr { struct mbuf *mh_prevpkt; /* Flags aren't used in the output queue */ int mh_flags; /* Misc flags */ - int mh_size; /* Size of data */ + size_t mh_size; /* Size of data */ struct socket *mh_so; caddr_t mh_data; /* Location of data */ - int mh_len; /* Amount of data in this mbuf */ + size_t mh_len; /* Amount of data in this mbuf */ }; /* @@ -130,14 +130,14 @@ extern int mbuf_alloced; extern struct mbuf m_freelist, m_usedlist; extern int mbuf_max; -void m_init _P((void)); -void msize_init _P((void)); -struct mbuf * m_get _P((void)); -void m_free _P((struct mbuf *)); -void m_cat _P((register struct mbuf *, register struct mbuf *)); -void m_inc _P((struct mbuf *, int)); -void m_adj _P((struct mbuf *, int)); -int m_copy _P((struct mbuf *, struct mbuf *, int, int)); -struct mbuf * dtom _P((void *)); +void m_init(void); +void msize_init(void); +struct mbuf * m_get(void); +void m_free(struct mbuf *); +void m_cat(register struct mbuf *, register struct mbuf *); +void m_inc(struct mbuf *, u_int); +void m_adj(struct mbuf *, int); +int m_copy(struct mbuf *, struct mbuf *, u_int, u_int); +struct mbuf * dtom(void *); #endif diff --git a/BasiliskII/src/slirp/misc.c b/BasiliskII/src/slirp/misc.c index d4c498fc..2f3f00e2 100644 --- a/BasiliskII/src/slirp/misc.c +++ b/BasiliskII/src/slirp/misc.c @@ -17,10 +17,7 @@ int x_port = -1; int x_display = 0; int x_screen = 0; -int -show_x(buff, inso) - char *buff; - struct socket *inso; +int show_x(char *buff, struct socket *inso) { if (x_port < 0) { lprint("X Redir: X not being redirected.\r\n"); @@ -40,12 +37,7 @@ show_x(buff, inso) /* * XXX Allow more than one X redirection? */ -void -redir_x(inaddr, start_port, display, screen) - u_int32_t inaddr; - int start_port; - int display; - int screen; +void redir_x(u_int32_t inaddr, int start_port, int display, int screen) { int i; @@ -69,34 +61,34 @@ redir_x(inaddr, start_port, display, screen) #endif #ifndef HAVE_INET_ATON -int -inet_aton(cp, ia) - const char *cp; - struct in_addr *ia; +int inet_aton(const char *cp, struct in_addr *ia) { - u_int32_t addr = inet_addr(cp); - if (addr == 0xffffffff) - return 0; - ia->s_addr = addr; - return 1; + return inet_pton(AF_INET, cp, &ia->s_addr); } #endif /* * Get our IP address and put it in our_addr */ -void -getouraddr() +void getouraddr() { char buff[256]; struct hostent *he = NULL; - + if (gethostname(buff,256) == 0) - he = gethostbyname(buff); - if (he) - our_addr = *(struct in_addr *)he->h_addr; - if (our_addr.s_addr == 0) - our_addr.s_addr = loopback_addr.s_addr; + { + struct addrinfo hints = { 0 }; + hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = AF_INET; + struct addrinfo* ai; + if (getaddrinfo(buff, NULL, &hints, &ai) == 0) + { + our_addr = *(struct in_addr *)ai->ai_addr->sa_data; + freeaddrinfo(ai); + } + } + if (our_addr.s_addr == 0) + our_addr.s_addr = loopback_addr.s_addr; } #if SIZEOF_CHAR_P == 8 @@ -106,10 +98,7 @@ struct quehead_32 { u_int32_t qh_rlink; }; -inline void -insque_32(a, b) - void *a; - void *b; +inline void insque_32(void *a, void *b) { register struct quehead_32 *element = (struct quehead_32 *) a; register struct quehead_32 *head = (struct quehead_32 *) b; @@ -120,9 +109,7 @@ insque_32(a, b) = (u_int32_t)element; } -inline void -remque_32(a) - void *a; +inline void remque_32(void *a) { register struct quehead_32 *element = (struct quehead_32 *) a; ((struct quehead_32 *)(element->qh_link))->qh_rlink = element->qh_rlink; @@ -137,9 +124,7 @@ struct quehead { struct quehead *qh_rlink; }; -void -insque(a, b) - void *a, *b; +void insque(void *a, void *b) { register struct quehead *element = (struct quehead *) a; register struct quehead *head = (struct quehead *) b; @@ -150,9 +135,7 @@ insque(a, b) = (struct quehead *)element; } -void -remque(a) - void *a; +void remque(void *a) { register struct quehead *element = (struct quehead *) a; ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink; @@ -164,13 +147,7 @@ remque(a) /* #endif */ -int -add_exec(ex_ptr, do_pty, exec, addr, port) - struct ex_list **ex_ptr; - int do_pty; - char *exec; - int addr; - int port; +int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, int addr, int port) { struct ex_list *tmp_ptr; @@ -199,9 +176,7 @@ add_exec(ex_ptr, do_pty, exec, addr, port) extern int sys_nerr; extern char *sys_errlist[]; -char * -strerror(error) - int error; +char *strerror(int error) { if (error < sys_nerr) return sys_errlist[error]; @@ -214,11 +189,7 @@ strerror(error) #ifdef _WIN32 -int -fork_exec(so, ex, do_pty) - struct socket *so; - char *ex; - int do_pty; +int fork_exec(struct socket *so, char *ex, int do_pty) { /* not implemented */ return 0; @@ -226,9 +197,7 @@ fork_exec(so, ex, do_pty) #else -int -slirp_openpty(amaster, aslave) - int *amaster, *aslave; +int slirp_openpty(int *amaster, int *aslave) { register int master, slave; @@ -302,11 +271,7 @@ slirp_openpty(amaster, aslave) * do_pty = 1 Fork/exec using slirp.telnetd * do_ptr = 2 Fork/exec using pty */ -int -fork_exec(so, ex, do_pty) - struct socket *so; - char *ex; - int do_pty; +int fork_exec(struct socket *so, char *ex, int do_pty) { int s; struct sockaddr_in addr; @@ -462,9 +427,7 @@ fork_exec(so, ex, do_pty) #endif #ifndef HAVE_STRDUP -char * -strdup(str) - const char *str; +char *strdup(const char *str) { char *bptr; @@ -476,9 +439,7 @@ strdup(str) #endif #if 0 -void -snooze_hup(num) - int num; +void snooze_hup(int num) { int s, ret; #ifndef NO_UNIX_SOCKETS @@ -518,8 +479,7 @@ snooze_hup(num) } -void -snooze() +void snooze() { sigset_t s; int i; @@ -543,9 +503,7 @@ snooze() exit(255); } -void -relay(s) - int s; +void relay(int s) { char buf[8192]; int n; @@ -605,25 +563,14 @@ relay(s) } #endif -int (*lprint_print) _P((void *, const char *, va_list)); +int (*lprint_print)(void *, const char *, va_list); char *lprint_ptr, *lprint_ptr2, **lprint_arg; -void -#ifdef __STDC__ -lprint(const char *format, ...) -#else -lprint(va_alist) va_dcl -#endif +void lprint(const char *format, ...) { va_list args; -#ifdef __STDC__ - va_start(args, format); -#else - char *format; - va_start(args); - format = va_arg(args, char *); -#endif + va_start(args, format); #if 0 /* If we're printing to an sbuf, make sure there's enough room */ /* XXX +100? */ @@ -672,9 +619,7 @@ lprint(va_alist) va_dcl va_end(args); } -void -add_emu(buff) - char *buff; +void add_emu(char *buff) { u_int lport, fport; u_int8_t tos = 0, emu = 0; @@ -766,42 +711,24 @@ add_emu(buff) * Some BSD-derived systems have a sprintf which returns char * */ -int -vsprintf_len(string, format, args) - char *string; - const char *format; - va_list args; +int vsprintf_len(char *string, const char *format, va_list args) { vsprintf(string, format, args); return strlen(string); } -int -#ifdef __STDC__ -sprintf_len(char *string, const char *format, ...) -#else -sprintf_len(va_alist) va_dcl -#endif +int sprintf_len(char *string, const char *format, ...) { va_list args; -#ifdef __STDC__ va_start(args, format); -#else - char *string; - char *format; - va_start(args); - string = va_arg(args, char *); - format = va_arg(args, char *); -#endif vsprintf(string, format, args); + va_end(args); return strlen(string); } #endif -void -u_sleep(usec) - int usec; +void u_sleep(int usec) { struct timeval t; fd_set fdset; @@ -818,9 +745,7 @@ u_sleep(usec) * Set fd blocking and non-blocking */ -void -fd_nonblock(fd) - int fd; +void fd_nonblock(int fd) { #if defined USE_FIONBIO && defined FIONBIO ioctlsockopt_t opt = 1; @@ -835,9 +760,7 @@ fd_nonblock(fd) #endif } -void -fd_block(fd) - int fd; +void fd_block(int fd) { #if defined USE_FIONBIO && defined FIONBIO ioctlsockopt_t opt = 0; @@ -857,13 +780,8 @@ fd_block(fd) /* * invoke RSH */ -int -rsh_exec(so,ns, user, host, args) - struct socket *so; - struct socket *ns; - char *user; - char *host; - char *args; +int rsh_exec(struct socket *so, struct socket *ns, + char *user, char *host, char *args) { int fd[2]; int fd0[2]; diff --git a/BasiliskII/src/slirp/misc.h b/BasiliskII/src/slirp/misc.h index efea9ff8..381f5f3e 100644 --- a/BasiliskII/src/slirp/misc.h +++ b/BasiliskII/src/slirp/misc.h @@ -19,15 +19,15 @@ struct ex_list { extern struct ex_list *exec_list; extern u_int curtime, time_fasttimo, last_slowtimo, detach_time, detach_wait; -extern int (*lprint_print) _P((void *, const char *, va_list)); +extern int (*lprint_print)(void *, const char *, va_list); extern char *lprint_ptr, *lprint_ptr2, **lprint_arg; extern struct sbuf *lprint_sb; #ifndef HAVE_STRDUP -char *strdup _P((const char *)); +char *strdup(const char *); #endif -void do_wait _P((int)); +void do_wait(int); #define EMU_NONE 0x0 @@ -67,21 +67,21 @@ extern struct emu_t *tcpemu; extern int x_port, x_server, x_display; -int show_x _P((char *, struct socket *)); -void redir_x _P((u_int32_t, int, int, int)); -void getouraddr _P((void)); -void slirp_insque _P((void *, void *)); -void slirp_remque _P((void *)); -int add_exec _P((struct ex_list **, int, char *, int, int)); -int slirp_openpty _P((int *, int *)); -int fork_exec _P((struct socket *, char *, int)); -void snooze_hup _P((int)); -void snooze _P((void)); -void relay _P((int)); -void add_emu _P((char *)); -void u_sleep _P((int)); -void fd_nonblock _P((int)); -void fd_block _P((int)); -int rsh_exec _P((struct socket *, struct socket *, char *, char *, char *)); +int show_x(char *, struct socket *); +void redir_x(u_int32_t, int, int, int); +void getouraddr(void); +void slirp_insque(void *, void *); +void slirp_remque(void *); +int add_exec(struct ex_list **, int, char *, int, int); +int slirp_openpty(int *, int *); +int fork_exec(struct socket *, char *, int); +void snooze_hup(int); +void snooze(void); +void relay(int); +void add_emu(char *); +void u_sleep(int); +void fd_nonblock(int); +void fd_block(int); +int rsh_exec(struct socket *, struct socket *, char *, char *, char *); #endif diff --git a/BasiliskII/src/slirp/sbuf.c b/BasiliskII/src/slirp/sbuf.c index 2d078f38..6af075e7 100644 --- a/BasiliskII/src/slirp/sbuf.c +++ b/BasiliskII/src/slirp/sbuf.c @@ -16,17 +16,12 @@ * } */ -void -sbfree(sb) - struct sbuf *sb; +void sbfree(struct sbuf *sb) { free(sb->sb_data); } -void -sbdrop(sb, num) - struct sbuf *sb; - int num; +void sbdrop(struct sbuf *sb, u_int num) { /* * We can only drop how much we have @@ -41,10 +36,7 @@ sbdrop(sb, num) } -void -sbreserve(sb, size) - struct sbuf *sb; - int size; +void sbreserve(struct sbuf *sb, size_t size) { if (sb->sb_data) { /* Already alloced, realloc if necessary */ @@ -72,10 +64,7 @@ sbreserve(sb, size) * this prevents an unnecessary copy of the data * (the socket is non-blocking, so we won't hang) */ -void -sbappend(so, m) - struct socket *so; - struct mbuf *m; +void sbappend(struct socket *so, struct mbuf *m) { int ret = 0; @@ -134,10 +123,7 @@ sbappend(so, m) * Copy the data from m into sb * The caller is responsible to make sure there's enough room */ -void -sbappendsb(sb, m) - struct sbuf *sb; - struct mbuf *m; +void sbappendsb(struct sbuf *sb, struct mbuf *m) { int len, n, nn; @@ -173,12 +159,7 @@ sbappendsb(sb, m) * Don't update the sbuf rptr, this will be * done in sbdrop when the data is acked */ -void -sbcopy(sb, off, len, to) - struct sbuf *sb; - int off; - int len; - char *to; +void sbcopy(struct sbuf *sb, u_int off, u_int len, char *to) { char *from; diff --git a/BasiliskII/src/slirp/sbuf.h b/BasiliskII/src/slirp/sbuf.h index 161e0bb7..04f7981c 100644 --- a/BasiliskII/src/slirp/sbuf.h +++ b/BasiliskII/src/slirp/sbuf.h @@ -8,6 +8,8 @@ #ifndef _SBUF_H_ #define _SBUF_H_ +#include + #define sbflush(sb) sbdrop((sb),(sb)->sb_cc) #define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc) @@ -21,11 +23,11 @@ struct sbuf { char *sb_data; /* Actual data */ }; -void sbfree _P((struct sbuf *)); -void sbdrop _P((struct sbuf *, int)); -void sbreserve _P((struct sbuf *, int)); -void sbappend _P((struct socket *, struct mbuf *)); -void sbappendsb _P((struct sbuf *, struct mbuf *)); -void sbcopy _P((struct sbuf *, int, int, char *)); +void sbfree(struct sbuf *); +void sbdrop(struct sbuf *, u_int); +void sbreserve(struct sbuf *, size_t); +void sbappend(struct socket *, struct mbuf *); +void sbappendsb(struct sbuf *, struct mbuf *); +void sbcopy(struct sbuf *, u_int, u_int, char *); #endif diff --git a/BasiliskII/src/slirp/slirp.c b/BasiliskII/src/slirp/slirp.c index 86591f1a..d8f2a954 100644 --- a/BasiliskII/src/slirp/slirp.c +++ b/BasiliskII/src/slirp/slirp.c @@ -220,14 +220,14 @@ int slirp_select_fill(int *pnfds, * See if we need a tcp_fasttimo */ if (time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) - time_fasttimo = curtime; /* Flag when we want a fasttimo */ + time_fasttimo = curtime; /* Flag when we want a fasttimo */ /* * NOFDREF can include still connecting to local-host, * newly socreated() sockets etc. Don't want to select these. */ if (so->so_state & SS_NOFDREF || so->s == -1) - continue; + continue; /* * Set for reading sockets which are accepting @@ -346,18 +346,18 @@ int slirp_select_fill(int *pnfds, void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) { - struct socket *so, *so_next; - int ret; + struct socket *so, *so_next; + int ret; - global_readfds = readfds; - global_writefds = writefds; - global_xfds = xfds; + global_readfds = readfds; + global_writefds = writefds; + global_xfds = xfds; /* Update time */ updtime(); - + /* - * See if anything has timed out + * See if anything has timed out */ if (link_up) { if (time_fasttimo && ((curtime - time_fasttimo) >= FAST_TIMO)) { @@ -370,7 +370,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) last_slowtimo = curtime; } } - + /* * Check sockets */ @@ -380,21 +380,21 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) */ for (so = tcb.so_next; so != &tcb; so = so_next) { so_next = so->so_next; - + /* * FD_ISSET is meaningless on these sockets * (and they can crash the program) */ if (so->so_state & SS_NOFDREF || so->s == -1) - continue; - + continue; + /* * Check for URG data * This will soread as well, so no need to * test for readfds below if this succeeds */ if (FD_ISSET(so->s, xfds)) - sorecvoob(so); + sorecvoob(so); /* * Check sockets for reading */ @@ -407,86 +407,92 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) continue; } /* else */ ret = soread(so); - + /* Output it if we read something */ if (ret > 0) - tcp_output(sototcpcb(so)); + tcp_output(sototcpcb(so)); } - + /* * Check sockets for writing */ if (FD_ISSET(so->s, writefds)) { - /* - * Check for non-blocking, still-connecting sockets - */ - if (so->so_state & SS_ISFCONNECTING) { - /* Connected */ - so->so_state &= ~SS_ISFCONNECTING; - - ret = send(so->s, &ret, 0, 0); - if (ret < 0) { - /* XXXXX Must fix, zero bytes is a NOP */ - if (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS || errno == ENOTCONN) - continue; - - /* else failed */ - so->so_state = SS_NOFDREF; - } - /* else so->so_state &= ~SS_ISFCONNECTING; */ - - /* - * Continue tcp_input - */ - tcp_input((struct mbuf *)NULL, sizeof(struct ip), so); - /* continue; */ - } else - ret = sowrite(so); - /* - * XXXXX If we wrote something (a lot), there - * could be a need for a window update. - * In the worst case, the remote will send - * a window probe to get things going again - */ + /* + * Check for non-blocking, still-connecting sockets + */ + if (so->so_state & SS_ISFCONNECTING) { + /* Connected */ + so->so_state &= ~SS_ISFCONNECTING; + + ret = send(so->s, (char*)&ret, 0, 0); + if (ret < 0) { + /* XXXXX Must fix, zero bytes is a NOP */ + int error = WSAGetLastError(); + if (error == EAGAIN || error == WSAEWOULDBLOCK || + error == WSAEINPROGRESS || error == WSAENOTCONN) + continue; + + /* else failed */ + so->so_state = SS_NOFDREF; + } + /* else so->so_state &= ~SS_ISFCONNECTING; */ + + /* + * Continue tcp_input + */ + tcp_input((struct mbuf *)NULL, sizeof(struct ip), so); + /* continue; */ + } + else + ret = sowrite(so); + /* + * XXXXX If we wrote something (a lot), there + * could be a need for a window update. + * In the worst case, the remote will send + * a window probe to get things going again + */ } - + /* * Probe a still-connecting, non-blocking socket * to check if it's still alive - */ + */ #ifdef PROBE_CONN if (so->so_state & SS_ISFCONNECTING) { - ret = recv(so->s, (char *)&ret, 0,0); - - if (ret < 0) { - /* XXX */ - if (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS || errno == ENOTCONN) - continue; /* Still connecting, continue */ - - /* else failed */ - so->so_state = SS_NOFDREF; - - /* tcp_input will take care of it */ - } else { - ret = send(so->s, &ret, 0,0); - if (ret < 0) { - /* XXX */ - if (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS || errno == ENOTCONN) - continue; - /* else failed */ - so->so_state = SS_NOFDREF; - } else - so->so_state &= ~SS_ISFCONNECTING; - - } - tcp_input((struct mbuf *)NULL, sizeof(struct ip),so); - } /* SS_ISFCONNECTING */ + ret = recv(so->s, (char *)&ret, 0, 0); + + if (ret < 0) { + /* XXX */ + int error = WSAGetLastError(); + if (error == EAGAIN || error == WSAEWOULDBLOCK || + error == WSAEINPROGRESS || error == WSAENOTCONN) + continue; /* Still connecting, continue */ + + /* else failed */ + so->so_state = SS_NOFDREF; + + /* tcp_input will take care of it */ + } + else { + ret = send(so->s, &ret, 0, 0); + if (ret < 0) { + /* XXX */ + int error = WSAGetLastError(); + if (error == EAGAIN || error == WSAEWOULDBLOCK || + error == WSAEINPROGRESS || error == WSAENOTCONN) + continue; + /* else failed */ + so->so_state = SS_NOFDREF; + } + else + so->so_state &= ~SS_ISFCONNECTING; + + } + tcp_input((struct mbuf *)NULL, sizeof(struct ip), so); + } /* SS_ISFCONNECTING */ #endif - } - + } + /* * Now UDP sockets. * Incoming packets are sent straight away, they're not buffered. @@ -494,27 +500,27 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds) */ for (so = udb.so_next; so != &udb; so = so_next) { so_next = so->so_next; - + if (so->s != -1 && FD_ISSET(so->s, readfds)) { - sorecvfrom(so); - } + sorecvfrom(so); + } } - } - +} + /* * See if we can start outputting */ if (if_queued && link_up) - if_start(); + if_start(); /* clear global file descriptor sets. * these reside on the stack in vl.c * so they're unusable if we're not in * slirp_select_fill or slirp_select_poll. */ - global_readfds = NULL; - global_writefds = NULL; - global_xfds = NULL; + global_readfds = NULL; + global_writefds = NULL; + global_xfds = NULL; } #define ETH_ALEN 6 diff --git a/BasiliskII/src/slirp/slirp.h b/BasiliskII/src/slirp/slirp.h index 8c6803a8..b845caa7 100644 --- a/BasiliskII/src/slirp/slirp.h +++ b/BasiliskII/src/slirp/slirp.h @@ -22,18 +22,12 @@ typedef char *caddr_t; typedef int socklen_t; typedef unsigned long ioctlsockopt_t; -# include # include +# include # include # include # define USE_FIONBIO 1 -# define EWOULDBLOCK WSAEWOULDBLOCK -# define EINPROGRESS WSAEINPROGRESS -# define ENOTCONN WSAENOTCONN -# define EHOSTUNREACH WSAEHOSTUNREACH -# define ENETUNREACH WSAENETUNREACH -# define ECONNREFUSED WSAECONNREFUSED /* Basilisk II Router defines those */ # define udp_read_completion slirp_udp_read_completion @@ -41,6 +35,14 @@ typedef unsigned long ioctlsockopt_t; # define init_udp slirp_init_udp # define final_udp slirp_final_udp #else +# define WSAGetLastError() (int)(errno) +# define WSASetLastError(e) (void)(errno = (e)) +# define WSAEWOULDBLOCK EWOULDBLOCK +# define WSAEINPROGRESS EINPROGRESS +# define WSAENOTCONN ENOTCONN +# define WSAEHOSTUNREACH EHOSTUNREACH +# define WSAENETUNREACH ENETUNREACH +# define WSAECONNREFUSED ECONNREFUSED typedef int ioctlsockopt_t; # define ioctlsocket ioctl # define closesocket(s) close(s) @@ -55,7 +57,9 @@ typedef int ioctlsockopt_t; # include #endif +#ifndef _WIN32 #include +#endif #ifdef NEED_TYPEDEFS typedef char int8_t; @@ -125,17 +129,6 @@ typedef u_int32_t uint32; #ifndef _WIN32 #include -#endif - -#ifndef _P -#ifndef NO_PROTOTYPES -# define _P(x) x -#else -# define _P(x) () -#endif -#endif - -#ifndef _WIN32 #include #include #endif @@ -146,20 +139,23 @@ typedef u_int32_t uint32; /* Systems lacking strdup() definition in . */ #if defined(ultrix) -char *strdup _P((const char *)); +char *strdup(const char *); #endif /* Systems lacking malloc() definition in . */ #if defined(ultrix) || defined(hcx) -void *malloc _P((size_t arg)); -void free _P((void *ptr)); +void *malloc(size_t arg); +void free(void *ptr); #endif #ifndef HAVE_INET_ATON -int inet_aton _P((const char *cp, struct in_addr *ia)); +int inet_aton(const char *cp, struct in_addr *ia); #endif #include +#ifdef _WIN32 +#include +#endif #ifndef NO_UNIX_SOCKETS #include #endif @@ -191,11 +187,7 @@ int inet_aton _P((const char *cp, struct in_addr *ia)); #include #endif -#ifdef __STDC__ #include -#else -#include -#endif #include @@ -212,8 +204,13 @@ int inet_aton _P((const char *cp, struct in_addr *ia)); #if defined __GNUC__ #define PACKED__ __attribute__ ((packed)) +#elif defined _MSC_VER +#define PRAGMA_PACK_SUPPORTED 1 +#define PACK_RESET +#define PACKED__ #elif defined __sgi #define PRAGMA_PACK_SUPPORTED 1 +#define PACK_RESET 0 #define PACKED__ #else #error "Packed attribute or pragma shall be supported" @@ -249,38 +246,38 @@ extern struct ttys *ttys_unit[MAX_INTERFACES]; #endif #ifndef FULL_BOLT -void if_start _P((void)); +void if_start(void); #else -void if_start _P((struct ttys *)); +void if_start(struct ttys *); #endif #ifdef BAD_SPRINTF # define vsprintf vsprintf_len # define sprintf sprintf_len - extern int vsprintf_len _P((char *, const char *, va_list)); - extern int sprintf_len _P((char *, const char *, ...)); + extern int vsprintf_len(char *, const char *, va_list); + extern int sprintf_len(char *, const char *, ...); #endif #ifdef DECLARE_SPRINTF # ifndef BAD_SPRINTF - extern int vsprintf _P((char *, const char *, va_list)); + extern int vsprintf(char *, const char *, va_list); # endif - extern int vfprintf _P((FILE *, const char *, va_list)); + extern int vfprintf(FILE *, const char *, va_list); #endif #ifndef HAVE_STRERROR - extern char *strerror _P((int error)); + extern char *strerror(int error); #endif #ifndef HAVE_INDEX - char *index _P((const char *, int)); + char *index(const char *, int); #endif #ifndef HAVE_GETHOSTID - long gethostid _P((void)); + long gethostid(void); #endif -void lprint _P((const char *, ...)); +void lprint(const char *, ...); extern int do_echo; @@ -288,8 +285,8 @@ extern int do_echo; # define insque_32 insque # define remque_32 remque #else - extern inline void insque_32 _P((void *, void *)); - extern inline void remque_32 _P((void *)); + extern inline void insque_32(void *, void *); + extern inline void remque_32(void *); #endif #ifndef _WIN32 @@ -302,47 +299,47 @@ extern int do_echo; int cksum(struct mbuf *m, int len); /* if.c */ -void if_init _P((void)); -void if_output _P((struct socket *, struct mbuf *)); +void if_init(void); +void if_output(struct socket *, struct mbuf *); /* ip_input.c */ -void ip_init _P((void)); -void ip_input _P((struct mbuf *)); -struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *)); -void ip_freef _P((struct ipq *)); -void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *)); -void ip_deq _P((register struct ipasfrag *)); -void ip_slowtimo _P((void)); -void ip_stripoptions _P((register struct mbuf *, struct mbuf *)); +void ip_init(void); +void ip_input(struct mbuf *); +struct ip * ip_reass(register struct ipasfrag *, register struct ipq *); +void ip_freef(struct ipq *); +void ip_enq(register struct ipasfrag *, register struct ipasfrag *); +void ip_deq(register struct ipasfrag *); +void ip_slowtimo(void); +void ip_stripoptions(register struct mbuf *, struct mbuf *); /* ip_output.c */ -int ip_output _P((struct socket *, struct mbuf *)); +int ip_output(struct socket *, struct mbuf *); /* tcp_input.c */ -int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *)); -void tcp_input _P((register struct mbuf *, int, struct socket *)); -void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *)); -void tcp_xmit_timer _P((register struct tcpcb *, int)); -int tcp_mss _P((register struct tcpcb *, u_int)); +int tcp_reass(register struct tcpcb *, register struct tcpiphdr *, struct mbuf *); +void tcp_input(register struct mbuf *, int, struct socket *); +void tcp_dooptions(struct tcpcb *, u_char *, int, struct tcpiphdr *); +void tcp_xmit_timer(register struct tcpcb *, int); +u_int tcp_mss(register struct tcpcb *, u_int); /* tcp_output.c */ -int tcp_output _P((register struct tcpcb *)); -void tcp_setpersist _P((register struct tcpcb *)); +int tcp_output(register struct tcpcb *); +void tcp_setpersist(register struct tcpcb *); /* tcp_subr.c */ -void tcp_init _P((void)); -void tcp_template _P((struct tcpcb *)); -void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int)); -struct tcpcb * tcp_newtcpcb _P((struct socket *)); -struct tcpcb * tcp_close _P((register struct tcpcb *)); -void tcp_drain _P((void)); -void tcp_sockclosed _P((struct tcpcb *)); -int tcp_fconnect _P((struct socket *)); -void tcp_connect _P((struct socket *)); -int tcp_attach _P((struct socket *)); -u_int8_t tcp_tos _P((struct socket *)); -int tcp_emu _P((struct socket *, struct mbuf *)); -int tcp_ctl _P((struct socket *)); +void tcp_init(void); +void tcp_template(struct tcpcb *); +void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int); +struct tcpcb * tcp_newtcpcb(struct socket *); +struct tcpcb * tcp_close(register struct tcpcb *); +void tcp_drain(void); +void tcp_sockclosed(struct tcpcb *); +int tcp_fconnect(struct socket *); +void tcp_connect(struct socket *); +int tcp_attach(struct socket *); +u_int8_t tcp_tos(struct socket *); +int tcp_emu(struct socket *, struct mbuf *); +int tcp_ctl(struct socket *); struct tcpcb *tcp_drop(struct tcpcb *tp, int err); #ifdef USE_PPP @@ -358,9 +355,4 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err); #define max(x,y) ((x) > (y) ? (x) : (y)) #endif -#ifdef _WIN32 -#undef errno -#define errno (WSAGetLastError()) -#endif - #endif diff --git a/BasiliskII/src/slirp/slirp_config.h b/BasiliskII/src/slirp/slirp_config.h index e583dcc8..237268fa 100644 --- a/BasiliskII/src/slirp/slirp_config.h +++ b/BasiliskII/src/slirp/slirp_config.h @@ -40,11 +40,6 @@ */ #undef USE_LOWCPU -/* Define this if your compiler doesn't like prototypes */ -#ifndef __STDC__ -#define NO_PROTOTYPES -#endif - /*********************************************************/ /* * Autoconf defined configuration options @@ -77,9 +72,6 @@ /* Define if you have sys/stropts.h */ #undef HAVE_SYS_STROPTS_H -/* Define if your compiler doesn't like prototypes */ -#undef NO_PROTOTYPES - /* Define if you don't have u_int32_t etc. typedef'd */ #undef NEED_TYPEDEFS #ifdef __sun__ diff --git a/BasiliskII/src/slirp/socket.c b/BasiliskII/src/slirp/socket.c index f3d10e53..5a36bb0e 100644 --- a/BasiliskII/src/slirp/socket.c +++ b/BasiliskII/src/slirp/socket.c @@ -97,11 +97,12 @@ int soread(so) struct socket *so; { - int n, nn, lss, total; + int n, nn; + u_int lss, total; struct sbuf *sb = &so->so_snd; - int len = sb->sb_datalen - sb->sb_cc; + u_int len = sb->sb_datalen - sb->sb_cc; struct iovec iov[2]; - int mss = so->so_tcpcb->t_maxseg; + u_int mss = so->so_tcpcb->t_maxseg; DEBUG_CALL("soread"); DEBUG_ARG("so = %lx", (long )so); @@ -159,7 +160,8 @@ soread(so) nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0); #endif if (nn <= 0) { - if (nn < 0 && (errno == EINTR || errno == EAGAIN)) + int error = WSAGetLastError(); + if (nn < 0 && (error == WSAEINTR || error == EAGAIN)) return 0; else { DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); @@ -297,7 +299,7 @@ sowrite(so) { int n,nn; struct sbuf *sb = &so->so_rcv; - int len = sb->sb_cc; + u_int len = sb->sb_cc; struct iovec iov[2]; DEBUG_CALL("sowrite"); @@ -344,9 +346,12 @@ sowrite(so) nn = send(so->s, iov[0].iov_base, iov[0].iov_len,0); #endif /* This should never happen, but people tell me it does *shrug* */ - if (nn < 0 && (errno == EAGAIN || errno == EINTR)) - return 0; - + if (nn < 0) { + int error = WSAGetLastError(); + if (error == EAGAIN || error == WSAEINTR) + return 0; + } + if (nn <= 0) { DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n", so->so_state, errno)); @@ -405,8 +410,9 @@ sorecvfrom(so) if(len == -1 || len == 0) { u_char code=ICMP_UNREACH_PORT; - if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; - else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; + int error = WSAGetLastError(); + if(error == WSAEHOSTUNREACH) code=ICMP_UNREACH_HOST; + else if(error == WSAENETUNREACH) code=ICMP_UNREACH_NET; DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n", errno,strerror(errno))); @@ -419,7 +425,7 @@ sorecvfrom(so) udp_detach(so); } else { /* A "normal" UDP packet */ struct mbuf *m; - int len; + u_int len; ioctlsockopt_t n; if (!(m = m_get())) return; @@ -447,8 +453,9 @@ sorecvfrom(so) if(m->m_len<0) { u_char code=ICMP_UNREACH_PORT; - if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; - else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; + int error = WSAGetLastError(); + if(error == WSAEHOSTUNREACH) code=ICMP_UNREACH_HOST; + else if(error == WSAENETUNREACH) code=ICMP_UNREACH_NET; DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code)); icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno)); @@ -513,7 +520,9 @@ sosendto(so, m) addr.sin_addr = so->so_faddr; addr.sin_port = so->so_fport; - DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); + char addrstr[INET_ADDRSTRLEN]; + DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", + ntohs(addr.sin_port), inet_ntop(AF_INET, &addr.sin_addr, addrstr, sizeof(addrstr)))); /* Don't care what port we get */ ret = sendto(so->s, m->m_data, m->m_len, 0, @@ -584,16 +593,12 @@ solisten(port, laddr, lport, flags) (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) || (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) || (listen(s,1) < 0)) { - int tmperrno = errno; /* Don't clobber the real reason we failed */ + int error = WSAGetLastError(); /* Don't clobber the real reason we failed */ close(s); sofree(so); /* Restore the real errno */ -#ifdef _WIN32 - WSASetLastError(tmperrno); -#else - errno = tmperrno; -#endif + WSASetLastError(error); return NULL; } setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); diff --git a/BasiliskII/src/slirp/socket.h b/BasiliskII/src/slirp/socket.h index d05354c8..3b0fee16 100644 --- a/BasiliskII/src/slirp/socket.h +++ b/BasiliskII/src/slirp/socket.h @@ -81,24 +81,24 @@ struct iovec { }; #endif -void so_init _P((void)); -struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int)); -struct socket * socreate _P((void)); -void sofree _P((struct socket *)); -int soread _P((struct socket *)); -void sorecvoob _P((struct socket *)); -int sosendoob _P((struct socket *)); -int sowrite _P((struct socket *)); -void sorecvfrom _P((struct socket *)); -int sosendto _P((struct socket *, struct mbuf *)); -struct socket * solisten _P((u_int, u_int32_t, u_int, int)); -void sorwakeup _P((struct socket *)); -void sowwakeup _P((struct socket *)); -void soisfconnecting _P((register struct socket *)); -void soisfconnected _P((register struct socket *)); -void sofcantrcvmore _P((struct socket *)); -void sofcantsendmore _P((struct socket *)); -void soisfdisconnected _P((struct socket *)); -void sofwdrain _P((struct socket *)); +void so_init(void); +struct socket * solookup(struct socket *, struct in_addr, u_int, struct in_addr, u_int); +struct socket * socreate(void); +void sofree(struct socket *); +int soread(struct socket *); +void sorecvoob(struct socket *); +int sosendoob(struct socket *); +int sowrite(struct socket *); +void sorecvfrom(struct socket *); +int sosendto(struct socket *, struct mbuf *); +struct socket * solisten(u_int, u_int32_t, u_int, int); +void sorwakeup(struct socket *); +void sowwakeup(struct socket *); +void soisfconnecting(register struct socket *); +void soisfconnected(register struct socket *); +void sofcantrcvmore(struct socket *); +void sofcantsendmore(struct socket *); +void soisfdisconnected(struct socket *); +void sofwdrain(struct socket *); #endif /* _SOCKET_H_ */ diff --git a/BasiliskII/src/slirp/tcp.h b/BasiliskII/src/slirp/tcp.h index 5f03f9e1..24e7914a 100644 --- a/BasiliskII/src/slirp/tcp.h +++ b/BasiliskII/src/slirp/tcp.h @@ -38,8 +38,8 @@ typedef u_int32_t tcp_seq; #define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */ #define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */ -extern int tcp_rcvspace; -extern int tcp_sndspace; +extern size_t tcp_rcvspace; +extern size_t tcp_sndspace; extern struct socket *tcp_last_so; #define TCP_SNDSPACE 8192 @@ -78,7 +78,7 @@ struct tcphdr { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif #include "tcp_var.h" diff --git a/BasiliskII/src/slirp/tcp_input.c b/BasiliskII/src/slirp/tcp_input.c index 684ed033..032e5378 100644 --- a/BasiliskII/src/slirp/tcp_input.c +++ b/BasiliskII/src/slirp/tcp_input.c @@ -111,10 +111,7 @@ tcp_seq tcp_iss; /* tcp initial send seq # */ #endif int -tcp_reass(tp, ti, m) - register struct tcpcb *tp; - register struct tcpiphdr *ti; - struct mbuf *m; +tcp_reass(register struct tcpcb *tp, register struct tcpiphdr *ti, struct mbuf *m) { register struct tcpiphdr *q; struct socket *so = tp->t_socket; @@ -229,13 +226,9 @@ present: * TCP input routine, follows pages 65-76 of the * protocol specification dated September, 1981 very closely. */ -void -tcp_input(m, iphlen, inso) - register struct mbuf *m; - int iphlen; - struct socket *inso; +void tcp_input(register struct mbuf *m, int iphlen, struct socket *inso) { - struct ip save_ip, *ip; + struct ip save_ip, *ip; register struct tcpiphdr *ti; caddr_t optp = NULL; int optlen = 0; @@ -243,23 +236,25 @@ tcp_input(m, iphlen, inso) register struct tcpcb *tp = 0; register int tiflags; struct socket *so = 0; - int todrop, acked, ourfinisacked, needoutput = 0; -/* int dropsocket = 0; */ + int todrop; + u_int acked; + int ourfinisacked, needoutput = 0; + /* int dropsocket = 0; */ int iss = 0; u_long tiwin; int ret; -/* int ts_present = 0; */ + /* int ts_present = 0; */ DEBUG_CALL("tcp_input"); - DEBUG_ARGS((dfd," m = %8lx iphlen = %2d inso = %lx\n", - (long )m, iphlen, (long )inso )); - + DEBUG_ARGS((dfd, " m = %8lx iphlen = %2d inso = %lx\n", + (long)m, iphlen, (long)inso)); + /* * If called with m == 0, then we're continuing the connect */ if (m == NULL) { so = inso; - + /* Re-set a few variables */ tp = sototcpcb(so); m = so->so_m; @@ -267,31 +262,31 @@ tcp_input(m, iphlen, inso) ti = so->so_ti; tiwin = ti->ti_win; tiflags = ti->ti_flags; - + goto cont_conn; } - - + + tcpstat.tcps_rcvtotal++; /* * Get IP and TCP header together in first mbuf. * Note: IP leaves IP header in first mbuf. */ ti = mtod(m, struct tcpiphdr *); - if (iphlen > sizeof(struct ip )) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen=sizeof(struct ip ); + if (iphlen > sizeof(struct ip)) { + ip_stripoptions(m, (struct mbuf *)0); + iphlen = sizeof(struct ip); } /* XXX Check if too short */ - + /* * Save a copy of the IP header in case we want restore it * for sending an ICMP error message in response. */ - ip=mtod(m, struct ip *); - save_ip = *ip; - save_ip.ip_len+= iphlen; + ip = mtod(m, struct ip *); + save_ip = *ip; + save_ip.ip_len += iphlen; /* * Checksum extended TCP header and data. @@ -300,13 +295,13 @@ tcp_input(m, iphlen, inso) ti->ti_next = ti->ti_prev = 0; ti->ti_x1 = 0; ti->ti_len = htons((u_int16_t)tlen); - len = sizeof(struct ip ) + tlen; + len = sizeof(struct ip) + tlen; /* keep checksum for ICMP reply - * ti->ti_sum = cksum(m, len); + * ti->ti_sum = cksum(m, len); * if (ti->ti_sum) { */ - if(cksum(m, len)) { - tcpstat.tcps_rcvbadsum++; - goto drop; + if (cksum(m, len)) { + tcpstat.tcps_rcvbadsum++; + goto drop; } /* @@ -314,37 +309,37 @@ tcp_input(m, iphlen, inso) * pull out TCP options and adjust length. XXX */ off = ti->ti_off << 2; - if (off < sizeof (struct tcphdr) || off > tlen) { - tcpstat.tcps_rcvbadoff++; - goto drop; + if (off < sizeof(struct tcphdr) || off > tlen) { + tcpstat.tcps_rcvbadoff++; + goto drop; } tlen -= off; ti->ti_len = tlen; - if (off > sizeof (struct tcphdr)) { - optlen = off - sizeof (struct tcphdr); - optp = mtod(m, caddr_t) + sizeof (struct tcpiphdr); + if (off > sizeof(struct tcphdr)) { + optlen = off - sizeof(struct tcphdr); + optp = mtod(m, caddr_t) + sizeof(struct tcpiphdr); - /* + /* * Do quick retrieval of timestamp options ("options * prediction?"). If timestamp is the only option and it's * formatted as recommended in RFC 1323 appendix A, we * quickly get the values now and not bother calling * tcp_dooptions(), etc. */ -/* if ((optlen == TCPOLEN_TSTAMP_APPA || - * (optlen > TCPOLEN_TSTAMP_APPA && - * optp[TCPOLEN_TSTAMP_APPA] == TCPOPT_EOL)) && - * *(u_int32_t *)optp == htonl(TCPOPT_TSTAMP_HDR) && - * (ti->ti_flags & TH_SYN) == 0) { - * ts_present = 1; - * ts_val = ntohl(*(u_int32_t *)(optp + 4)); - * ts_ecr = ntohl(*(u_int32_t *)(optp + 8)); - * optp = NULL; / * we've parsed the options * / - * } - */ + /* if ((optlen == TCPOLEN_TSTAMP_APPA || + * (optlen > TCPOLEN_TSTAMP_APPA && + * optp[TCPOLEN_TSTAMP_APPA] == TCPOPT_EOL)) && + * *(u_int32_t *)optp == htonl(TCPOPT_TSTAMP_HDR) && + * (ti->ti_flags & TH_SYN) == 0) { + * ts_present = 1; + * ts_val = ntohl(*(u_int32_t *)(optp + 4)); + * ts_ecr = ntohl(*(u_int32_t *)(optp + 8)); + * optp = NULL; / * we've parsed the options * / + * } + */ } tiflags = ti->ti_flags; - + /* * Convert TCP protocol specific fields to host format. */ @@ -356,20 +351,20 @@ tcp_input(m, iphlen, inso) /* * Drop TCP, IP headers and TCP options. */ - m->m_data += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); - m->m_len -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); - + m->m_data += sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); + m->m_len -= sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); + /* * Locate pcb for segment. */ findso: so = tcp_last_so; if (so->so_fport != ti->ti_dport || - so->so_lport != ti->ti_sport || - so->so_laddr.s_addr != ti->ti_src.s_addr || - so->so_faddr.s_addr != ti->ti_dst.s_addr) { + so->so_lport != ti->ti_sport || + so->so_laddr.s_addr != ti->ti_src.s_addr || + so->so_faddr.s_addr != ti->ti_dst.s_addr) { so = solookup(&tcb, ti->ti_src, ti->ti_sport, - ti->ti_dst, ti->ti_dport); + ti->ti_dst, ti->ti_dport); if (so) tcp_last_so = so; ++tcpstat.tcps_socachemiss; @@ -382,63 +377,63 @@ findso: * but should either do a listen or a connect soon. * * state == CLOSED means we've done socreate() but haven't - * attached it to a protocol yet... - * + * attached it to a protocol yet... + * * XXX If a TCB does not exist, and the TH_SYN flag is * the only flag set, then create a session, mark it * as if it was LISTENING, and continue... */ if (so == 0) { - if ((tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) != TH_SYN) - goto dropwithreset; - - if ((so = socreate()) == NULL) - goto dropwithreset; - if (tcp_attach(so) < 0) { - free(so); /* Not sofree (if it failed, it's not insqued) */ - goto dropwithreset; - } - - sbreserve(&so->so_snd, tcp_sndspace); - sbreserve(&so->so_rcv, tcp_rcvspace); - - /* tcp_last_so = so; */ /* XXX ? */ - /* tp = sototcpcb(so); */ - - so->so_laddr = ti->ti_src; - so->so_lport = ti->ti_sport; - so->so_faddr = ti->ti_dst; - so->so_fport = ti->ti_dport; - - if ((so->so_iptos = tcp_tos(so)) == 0) - so->so_iptos = ((struct ip *)ti)->ip_tos; - - tp = sototcpcb(so); - tp->t_state = TCPS_LISTEN; + if ((tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) != TH_SYN) + goto dropwithreset; + + if ((so = socreate()) == NULL) + goto dropwithreset; + if (tcp_attach(so) < 0) { + free(so); /* Not sofree (if it failed, it's not insqued) */ + goto dropwithreset; + } + + sbreserve(&so->so_snd, tcp_sndspace); + sbreserve(&so->so_rcv, tcp_rcvspace); + + /* tcp_last_so = so; */ /* XXX ? */ + /* tp = sototcpcb(so); */ + + so->so_laddr = ti->ti_src; + so->so_lport = ti->ti_sport; + so->so_faddr = ti->ti_dst; + so->so_fport = ti->ti_dport; + + if ((so->so_iptos = tcp_tos(so)) == 0) + so->so_iptos = ((struct ip *)ti)->ip_tos; + + tp = sototcpcb(so); + tp->t_state = TCPS_LISTEN; } - - /* - * If this is a still-connecting socket, this probably - * a retransmit of the SYN. Whether it's a retransmit SYN - * or something else, we nuke it. - */ - if (so->so_state & SS_ISFCONNECTING) - goto drop; + + /* + * If this is a still-connecting socket, this probably + * a retransmit of the SYN. Whether it's a retransmit SYN + * or something else, we nuke it. + */ + if (so->so_state & SS_ISFCONNECTING) + goto drop; tp = sototcpcb(so); - + /* XXX Should never fail */ if (tp == 0) goto dropwithreset; if (tp->t_state == TCPS_CLOSED) goto drop; - + /* Unscale the window into a 32-bit value. */ /* if ((tiflags & TH_SYN) == 0) * tiwin = ti->ti_win << tp->snd_scale; * else */ - tiwin = ti->ti_win; + tiwin = ti->ti_win; /* * Segment received on connection. @@ -446,66 +441,66 @@ findso: */ tp->t_idle = 0; if (so_options) - tp->t_timer[TCPT_KEEP] = tcp_keepintvl; + tp->t_timer[TCPT_KEEP] = tcp_keepintvl; else - tp->t_timer[TCPT_KEEP] = tcp_keepidle; + tp->t_timer[TCPT_KEEP] = tcp_keepidle; /* * Process options if not in LISTEN state, * else do it below (after getting remote address). */ if (optp && tp->t_state != TCPS_LISTEN) - tcp_dooptions(tp, (u_char *)optp, optlen, ti); -/* , */ -/* &ts_present, &ts_val, &ts_ecr); */ + tcp_dooptions(tp, (u_char *)optp, optlen, ti); + /* , */ + /* &ts_present, &ts_val, &ts_ecr); */ - /* - * Header prediction: check for the two common cases - * of a uni-directional data xfer. If the packet has - * no control flags, is in-sequence, the window didn't - * change and we're not retransmitting, it's a - * candidate. If the length is zero and the ack moved - * forward, we're the sender side of the xfer. Just - * free the data acked & wake any higher level process - * that was blocked waiting for space. If the length - * is non-zero and the ack didn't move, we're the - * receiver side. If we're getting packets in-order - * (the reassembly queue is empty), add the data to - * the socket buffer and note that we need a delayed ack. - * - * XXX Some of these tests are not needed - * eg: the tiwin == tp->snd_wnd prevents many more - * predictions.. with no *real* advantage.. - */ + /* + * Header prediction: check for the two common cases + * of a uni-directional data xfer. If the packet has + * no control flags, is in-sequence, the window didn't + * change and we're not retransmitting, it's a + * candidate. If the length is zero and the ack moved + * forward, we're the sender side of the xfer. Just + * free the data acked & wake any higher level process + * that was blocked waiting for space. If the length + * is non-zero and the ack didn't move, we're the + * receiver side. If we're getting packets in-order + * (the reassembly queue is empty), add the data to + * the socket buffer and note that we need a delayed ack. + * + * XXX Some of these tests are not needed + * eg: the tiwin == tp->snd_wnd prevents many more + * predictions.. with no *real* advantage.. + */ if (tp->t_state == TCPS_ESTABLISHED && - (tiflags & (TH_SYN|TH_FIN|TH_RST|TH_URG|TH_ACK)) == TH_ACK && -/* (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) && */ - ti->ti_seq == tp->rcv_nxt && - tiwin && tiwin == tp->snd_wnd && - tp->snd_nxt == tp->snd_max) { - /* + (tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) == TH_ACK && + /* (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) && */ + ti->ti_seq == tp->rcv_nxt && + tiwin && tiwin == tp->snd_wnd && + tp->snd_nxt == tp->snd_max) { + /* * If last ACK falls within this segment's sequence numbers, * record the timestamp. */ -/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) && - * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len)) { - * tp->ts_recent_age = tcp_now; - * tp->ts_recent = ts_val; - * } - */ + /* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) && + * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len)) { + * tp->ts_recent_age = tcp_now; + * tp->ts_recent = ts_val; + * } + */ if (ti->ti_len == 0) { if (SEQ_GT(ti->ti_ack, tp->snd_una) && - SEQ_LEQ(ti->ti_ack, tp->snd_max) && - tp->snd_cwnd >= tp->snd_wnd) { + SEQ_LEQ(ti->ti_ack, tp->snd_max) && + tp->snd_cwnd >= tp->snd_wnd) { /* * this is a pure ack for outstanding data. */ ++tcpstat.tcps_predack; -/* if (ts_present) - * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); - * else - */ if (tp->t_rtt && - SEQ_GT(ti->ti_ack, tp->t_rtseq)) + /* if (ts_present) + * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); + * else + */ if (tp->t_rtt && +SEQ_GT(ti->ti_ack, tp->t_rtseq)) tcp_xmit_timer(tp, tp->t_rtt); acked = ti->ti_ack - tp->snd_una; tcpstat.tcps_rcvackpack++; @@ -528,26 +523,27 @@ findso: else if (tp->t_timer[TCPT_PERSIST] == 0) tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - /* + /* * There's room in so_snd, sowwakup will read() * from the socket if we can */ -/* if (so->so_snd.sb_flags & SB_NOTIFY) - * sowwakeup(so); - */ - /* - * This is called because sowwakeup might have - * put data into so_snd. Since we don't so sowwakeup, - * we don't need this.. XXX??? - */ + /* if (so->so_snd.sb_flags & SB_NOTIFY) + * sowwakeup(so); + */ + /* + * This is called because sowwakeup might have + * put data into so_snd. Since we don't so sowwakeup, + * we don't need this.. XXX??? + */ if (so->so_snd.sb_cc) (void) tcp_output(tp); return; } - } else if (ti->ti_ack == tp->snd_una && - tp->seg_next == (tcpiphdrp_32)tp && - ti->ti_len <= sbspace(&so->so_rcv)) { + } + else if (ti->ti_ack == tp->snd_una && + tp->seg_next == (tcpiphdrp_32)tp && + ti->ti_len <= sbspace(&so->so_rcv)) { /* * this is a pure, in-sequence data packet * with nothing on the reassembly queue and @@ -561,25 +557,26 @@ findso: * Add data to socket buffer. */ if (so->so_emu) { - if (tcp_emu(so,m)) sbappend(so, m); - } else + if (tcp_emu(so, m)) sbappend(so, m); + } + else sbappend(so, m); - - /* + + /* * XXX This is called when data arrives. Later, check * if we can actually write() to the socket * XXX Need to check? It's be NON_BLOCKING */ -/* sorwakeup(so); */ - - /* - * If this is a short packet, then ACK now - with Nagel - * congestion avoidance sender won't send more until - * he gets an ACK. - * - * It is better to not delay acks at all to maximize - * TCP throughput. See RFC 2581. - */ + /* sorwakeup(so); */ + + /* + * If this is a short packet, then ACK now - with Nagel + * congestion avoidance sender won't send more until + * he gets an ACK. + * + * It is better to not delay acks at all to maximize + * TCP throughput. See RFC 2581. + */ tp->t_flags |= TF_ACKNOW; tcp_output(tp); return; @@ -592,141 +589,147 @@ findso: * but not less than advertised window. */ { int win; - win = sbspace(&so->so_rcv); - if (win < 0) - win = 0; - tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt)); + win = sbspace(&so->so_rcv); + if (win < 0) + win = 0; + tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt)); } switch (tp->t_state) { - /* - * If the state is LISTEN then ignore segment if it contains an RST. - * If the segment contains an ACK then it is bad and send a RST. - * If it does not contain a SYN then it is not interesting; drop it. - * Don't bother responding if the destination was a broadcast. - * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial - * tp->iss, and send a segment: - * - * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss. - * Fill in remote peer address fields if not previously specified. - * Enter SYN_RECEIVED state, and process any other fields of this - * segment in this state. - */ + /* + * If the state is LISTEN then ignore segment if it contains an RST. + * If the segment contains an ACK then it is bad and send a RST. + * If it does not contain a SYN then it is not interesting; drop it. + * Don't bother responding if the destination was a broadcast. + * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial + * tp->iss, and send a segment: + * + * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss. + * Fill in remote peer address fields if not previously specified. + * Enter SYN_RECEIVED state, and process any other fields of this + * segment in this state. + */ case TCPS_LISTEN: { - if (tiflags & TH_RST) - goto drop; - if (tiflags & TH_ACK) - goto dropwithreset; - if ((tiflags & TH_SYN) == 0) - goto drop; - - /* - * This has way too many gotos... - * But a bit of spaghetti code never hurt anybody :) - */ - - /* - * If this is destined for the control address, then flag to - * tcp_ctl once connected, otherwise connect - */ - if ((so->so_faddr.s_addr&htonl(0xffffff00)) == special_addr.s_addr) { - int lastbyte=ntohl(so->so_faddr.s_addr) & 0xff; - if (lastbyte!=CTL_ALIAS && lastbyte!=CTL_DNS) { -#if 0 - if(lastbyte==CTL_CMD || lastbyte==CTL_EXEC) { - /* Command or exec adress */ - so->so_state |= SS_CTL; - } else -#endif - { - /* May be an add exec */ - struct ex_list *ex_ptr; - for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if(ex_ptr->ex_fport == so->so_fport && - lastbyte == ex_ptr->ex_addr) { - so->so_state |= SS_CTL; - break; - } - } - } - if(so->so_state & SS_CTL) goto cont_input; - } - /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ - } - - if (so->so_emu & EMU_NOCONNECT) { - so->so_emu &= ~EMU_NOCONNECT; - goto cont_input; - } - - if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { - u_char code=ICMP_UNREACH_NET; - DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n", - errno,strerror(errno))); - if(errno == ECONNREFUSED) { - /* ACK the SYN, send RST to refuse the connection */ - tcp_respond(tp, ti, m, ti->ti_seq+1, (tcp_seq)0, - TH_RST|TH_ACK); - } else { - if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST; - HTONL(ti->ti_seq); /* restore tcp header */ - HTONL(ti->ti_ack); - HTONS(ti->ti_win); - HTONS(ti->ti_urp); - m->m_data -= sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); - m->m_len += sizeof(struct tcpiphdr)+off-sizeof(struct tcphdr); - *ip=save_ip; - icmp_error(m, ICMP_UNREACH,code, 0,strerror(errno)); - } - tp = tcp_close(tp); - m_free(m); - } else { - /* - * Haven't connected yet, save the current mbuf - * and ti, and return - * XXX Some OS's don't tell us whether the connect() - * succeeded or not. So we must time it out. - */ - so->so_m = m; - so->so_ti = ti; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tp->t_state = TCPS_SYN_RECEIVED; - } - return; + if (tiflags & TH_RST) + goto drop; + if (tiflags & TH_ACK) + goto dropwithreset; + if ((tiflags & TH_SYN) == 0) + goto drop; - cont_conn: - /* m==NULL - * Check if the connect succeeded - */ - if (so->so_state & SS_NOFDREF) { - tp = tcp_close(tp); - goto dropwithreset; - } - cont_input: - tcp_template(tp); - - if (optp) - tcp_dooptions(tp, (u_char *)optp, optlen, ti); - /* , */ - /* &ts_present, &ts_val, &ts_ecr); */ - - if (iss) - tp->iss = iss; - else - tp->iss = tcp_iss; - tcp_iss += TCP_ISSINCR/2; - tp->irs = ti->ti_seq; - tcp_sendseqinit(tp); - tcp_rcvseqinit(tp); - tp->t_flags |= TF_ACKNOW; - tp->t_state = TCPS_SYN_RECEIVED; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tcpstat.tcps_accepts++; - goto trimthenstep6; + /* + * This has way too many gotos... + * But a bit of spaghetti code never hurt anybody :) + */ + + /* + * If this is destined for the control address, then flag to + * tcp_ctl once connected, otherwise connect + */ + if ((so->so_faddr.s_addr&htonl(0xffffff00)) == special_addr.s_addr) { + int lastbyte = ntohl(so->so_faddr.s_addr) & 0xff; + if (lastbyte != CTL_ALIAS && lastbyte != CTL_DNS) { +#if 0 + if (lastbyte == CTL_CMD || lastbyte == CTL_EXEC) { + /* Command or exec adress */ + so->so_state |= SS_CTL; + } + else +#endif + { + /* May be an add exec */ + struct ex_list *ex_ptr; + for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { + if (ex_ptr->ex_fport == so->so_fport && + lastbyte == ex_ptr->ex_addr) { + so->so_state |= SS_CTL; + break; + } + } + } + if (so->so_state & SS_CTL) goto cont_input; + } + /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ + } + + if (so->so_emu & EMU_NOCONNECT) { + so->so_emu &= ~EMU_NOCONNECT; + goto cont_input; + } + + if (tcp_fconnect(so) == -1) { + int error = WSAGetLastError(); + if ((error != WSAEINPROGRESS) && (error != WSAEWOULDBLOCK)) { + u_char code = ICMP_UNREACH_NET; + DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n", + errno, strerror(errno))); + if (error == WSAECONNREFUSED) { + /* ACK the SYN, send RST to refuse the connection */ + tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq)0, + TH_RST | TH_ACK); + } + else { + if (error == WSAEHOSTUNREACH) code = ICMP_UNREACH_HOST; + HTONL(ti->ti_seq); /* restore tcp header */ + HTONL(ti->ti_ack); + HTONS(ti->ti_win); + HTONS(ti->ti_urp); + m->m_data -= sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); + m->m_len += sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); + *ip = save_ip; + icmp_error(m, ICMP_UNREACH, code, 0, strerror(errno)); + } + tp = tcp_close(tp); + m_free(m); + return; + } + } + + /* + * Haven't connected yet, save the current mbuf + * and ti, and return + * XXX Some OS's don't tell us whether the connect() + * succeeded or not. So we must time it out. + */ + so->so_m = m; + so->so_ti = ti; + tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; + tp->t_state = TCPS_SYN_RECEIVED; + return; + + cont_conn: + /* m==NULL + * Check if the connect succeeded + */ + if (so->so_state & SS_NOFDREF) { + tp = tcp_close(tp); + goto dropwithreset; + } + cont_input: + tcp_template(tp); + + if (optp) + tcp_dooptions(tp, (u_char *)optp, optlen, ti); + /* , */ + /* &ts_present, &ts_val, &ts_ecr); */ + + if (iss) + tp->iss = iss; + else + tp->iss = tcp_iss; + tcp_iss += TCP_ISSINCR / 2; + tp->irs = ti->ti_seq; + tcp_sendseqinit(tp); + tcp_rcvseqinit(tp); + tp->t_flags |= TF_ACKNOW; + tp->t_state = TCPS_SYN_RECEIVED; + tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; + tcpstat.tcps_accepts++; + goto trimthenstep6; } /* case TCPS_LISTEN */ - + /* * If the state is SYN_SENT: * if seg contains an ACK, but not for our SYN, drop the input. @@ -741,13 +744,13 @@ findso: */ case TCPS_SYN_SENT: if ((tiflags & TH_ACK) && - (SEQ_LEQ(ti->ti_ack, tp->iss) || - SEQ_GT(ti->ti_ack, tp->snd_max))) + (SEQ_LEQ(ti->ti_ack, tp->iss) || + SEQ_GT(ti->ti_ack, tp->snd_max))) goto dropwithreset; if (tiflags & TH_RST) { if (tiflags & TH_ACK) - tp = tcp_drop(tp,0); /* XXX Check t_softerror! */ + tp = tcp_drop(tp, 0); /* XXX Check t_softerror! */ goto drop; } @@ -767,7 +770,7 @@ findso: tcpstat.tcps_connects++; soisfconnected(so); tp->t_state = TCPS_ESTABLISHED; - + /* Do window scaling on this connection? */ /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == * (TF_RCVD_SCALE|TF_REQ_SCALE)) { @@ -775,7 +778,7 @@ findso: * tp->rcv_scale = tp->request_r_scale; * } */ - (void) tcp_reass(tp, (struct tcpiphdr *)0, + (void)tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); /* * if we didn't have to retransmit the SYN, @@ -783,10 +786,11 @@ findso: */ if (tp->t_rtt) tcp_xmit_timer(tp, tp->t_rtt); - } else + } + else tp->t_state = TCPS_SYN_RECEIVED; -trimthenstep6: + trimthenstep6: /* * Advance ti->ti_seq to correspond to first data byte. * If data, trim to stay within window, @@ -808,45 +812,45 @@ trimthenstep6: /* * States other than LISTEN or SYN_SENT. * First check timestamp, if present. - * Then check that at least some bytes of segment are within + * Then check that at least some bytes of segment are within * receive window. If segment begins before rcv_nxt, * drop leading data (and SYN); if nothing left, just ack. - * + * * RFC 1323 PAWS: If we have a timestamp reply on this segment * and it's less than ts_recent, drop it. */ -/* if (ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent && - * TSTMP_LT(ts_val, tp->ts_recent)) { - * - */ /* Check to see if ts_recent is over 24 days old. */ -/* if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) { - */ /* - * * Invalidate ts_recent. If this segment updates - * * ts_recent, the age will be reset later and ts_recent - * * will get a valid value. If it does not, setting - * * ts_recent to zero will at least satisfy the - * * requirement that zero be placed in the timestamp - * * echo reply when ts_recent isn't valid. The - * * age isn't reset until we get a valid ts_recent - * * because we don't want out-of-order segments to be - * * dropped when ts_recent is old. - * */ -/* tp->ts_recent = 0; - * } else { - * tcpstat.tcps_rcvduppack++; - * tcpstat.tcps_rcvdupbyte += ti->ti_len; - * tcpstat.tcps_pawsdrop++; - * goto dropafterack; - * } - * } - */ + /* if (ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent && + * TSTMP_LT(ts_val, tp->ts_recent)) { + * + */ /* Check to see if ts_recent is over 24 days old. */ + /* if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) { + */ /* + * * Invalidate ts_recent. If this segment updates + * * ts_recent, the age will be reset later and ts_recent + * * will get a valid value. If it does not, setting + * * ts_recent to zero will at least satisfy the + * * requirement that zero be placed in the timestamp + * * echo reply when ts_recent isn't valid. The + * * age isn't reset until we get a valid ts_recent + * * because we don't want out-of-order segments to be + * * dropped when ts_recent is old. + * */ + /* tp->ts_recent = 0; + * } else { + * tcpstat.tcps_rcvduppack++; + * tcpstat.tcps_rcvdupbyte += ti->ti_len; + * tcpstat.tcps_pawsdrop++; + * goto dropafterack; + * } + * } + */ todrop = tp->rcv_nxt - ti->ti_seq; if (todrop > 0) { if (tiflags & TH_SYN) { tiflags &= ~TH_SYN; ti->ti_seq++; - if (ti->ti_urp > 1) + if (ti->ti_urp > 1) ti->ti_urp--; else tiflags &= ~TH_URG; @@ -856,14 +860,14 @@ trimthenstep6: * Following if statement from Stevens, vol. 2, p. 960. */ if (todrop > ti->ti_len - || (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) { + || (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) { /* * Any valid FIN must be to the left of the window. * At this point the FIN must be a duplicate or out * of sequence; drop it. */ tiflags &= ~TH_FIN; - + /* * Send an ACK to resynchronize and drop any data. * But keep on processing for RST or ACK. @@ -872,7 +876,8 @@ trimthenstep6: todrop = ti->ti_len; tcpstat.tcps_rcvduppack++; tcpstat.tcps_rcvdupbyte += todrop; - } else { + } + else { tcpstat.tcps_rcvpartduppack++; tcpstat.tcps_rcvpartdupbyte += todrop; } @@ -891,7 +896,7 @@ trimthenstep6: * user processes are gone, then RST the other end. */ if ((so->so_state & SS_NOFDREF) && - tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) { + tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) { tp = tcp_close(tp); tcpstat.tcps_rcvafterclose++; goto dropwithreset; @@ -901,7 +906,7 @@ trimthenstep6: * If segment ends after window, drop trailing data * (and PUSH and FIN); if nothing left, just ACK. */ - todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd); + todrop = (ti->ti_seq + ti->ti_len) - (tp->rcv_nxt + tp->rcv_wnd); if (todrop > 0) { tcpstat.tcps_rcvpackafterwin++; if (todrop >= ti->ti_len) { @@ -913,8 +918,8 @@ trimthenstep6: * are above the previous ones. */ if (tiflags & TH_SYN && - tp->t_state == TCPS_TIME_WAIT && - SEQ_GT(ti->ti_seq, tp->rcv_nxt)) { + tp->t_state == TCPS_TIME_WAIT && + SEQ_GT(ti->ti_seq, tp->rcv_nxt)) { iss = tp->rcv_nxt + TCP_ISSINCR; tp = tcp_close(tp); goto findso; @@ -929,53 +934,55 @@ trimthenstep6: if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) { tp->t_flags |= TF_ACKNOW; tcpstat.tcps_rcvwinprobe++; - } else + } + else goto dropafterack; - } else + } + else tcpstat.tcps_rcvbyteafterwin += todrop; m_adj(m, -todrop); ti->ti_len -= todrop; - tiflags &= ~(TH_PUSH|TH_FIN); + tiflags &= ~(TH_PUSH | TH_FIN); } /* * If last ACK falls within this segment's sequence numbers, * record its timestamp. */ -/* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) && - * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len + - * ((tiflags & (TH_SYN|TH_FIN)) != 0))) { - * tp->ts_recent_age = tcp_now; - * tp->ts_recent = ts_val; - * } - */ + /* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) && + * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len + + * ((tiflags & (TH_SYN|TH_FIN)) != 0))) { + * tp->ts_recent_age = tcp_now; + * tp->ts_recent = ts_val; + * } + */ - /* - * If the RST bit is set examine the state: - * SYN_RECEIVED STATE: - * If passive open, return to LISTEN state. - * If active open, inform user that connection was refused. - * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES: - * Inform user that connection was reset, and close tcb. - * CLOSING, LAST_ACK, TIME_WAIT STATES - * Close the tcb. - */ + /* + * If the RST bit is set examine the state: + * SYN_RECEIVED STATE: + * If passive open, return to LISTEN state. + * If active open, inform user that connection was refused. + * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES: + * Inform user that connection was reset, and close tcb. + * CLOSING, LAST_ACK, TIME_WAIT STATES + * Close the tcb. + */ if (tiflags&TH_RST) switch (tp->t_state) { case TCPS_SYN_RECEIVED: -/* so->so_error = ECONNREFUSED; */ + /* so->so_error = ECONNREFUSED; */ goto close; case TCPS_ESTABLISHED: case TCPS_FIN_WAIT_1: case TCPS_FIN_WAIT_2: case TCPS_CLOSE_WAIT: -/* so->so_error = ECONNRESET; */ - close: - tp->t_state = TCPS_CLOSED; - tcpstat.tcps_drops++; - tp = tcp_close(tp); - goto drop; + /* so->so_error = ECONNRESET; */ + close: + tp->t_state = TCPS_CLOSED; + tcpstat.tcps_drops++; + tp = tcp_close(tp); + goto drop; case TCPS_CLOSING: case TCPS_LAST_ACK: @@ -989,7 +996,7 @@ trimthenstep6: * error and we send an RST and drop the connection. */ if (tiflags & TH_SYN) { - tp = tcp_drop(tp,0); + tp = tcp_drop(tp, 0); goto dropwithreset; } @@ -1002,42 +1009,45 @@ trimthenstep6: * Ack processing. */ switch (tp->t_state) { - /* - * In SYN_RECEIVED state if the ack ACKs our SYN then enter - * ESTABLISHED state and continue processing, otherwise - * send an RST. una<=ack<=max - */ + /* + * In SYN_RECEIVED state if the ack ACKs our SYN then enter + * ESTABLISHED state and continue processing, otherwise + * send an RST. una<=ack<=max + */ case TCPS_SYN_RECEIVED: if (SEQ_GT(tp->snd_una, ti->ti_ack) || - SEQ_GT(ti->ti_ack, tp->snd_max)) + SEQ_GT(ti->ti_ack, tp->snd_max)) goto dropwithreset; tcpstat.tcps_connects++; tp->t_state = TCPS_ESTABLISHED; - /* - * The sent SYN is ack'ed with our sequence number +1 - * The first data byte already in the buffer will get + /* + * The sent SYN is ack'ed with our sequence number +1 + * The first data byte already in the buffer will get * lost if no correction is made. This is only needed for * SS_CTL since the buffer is empty otherwise. - * tp->snd_una++; or: + * tp->snd_una++; or: */ - tp->snd_una=ti->ti_ack; + tp->snd_una = ti->ti_ack; if (so->so_state & SS_CTL) { - /* So tcp_ctl reports the right state */ - ret = tcp_ctl(so); - if (ret == 1) { - soisfconnected(so); - so->so_state &= ~SS_CTL; /* success XXX */ - } else if (ret == 2) { - so->so_state = SS_NOFDREF; /* CTL_CMD */ - } else { - needoutput = 1; - tp->t_state = TCPS_FIN_WAIT_1; - } - } else { - soisfconnected(so); + /* So tcp_ctl reports the right state */ + ret = tcp_ctl(so); + if (ret == 1) { + soisfconnected(so); + so->so_state &= ~SS_CTL; /* success XXX */ + } + else if (ret == 2) { + so->so_state = SS_NOFDREF; /* CTL_CMD */ + } + else { + needoutput = 1; + tp->t_state = TCPS_FIN_WAIT_1; + } } - + else { + soisfconnected(so); + } + /* Do window scaling? */ /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == * (TF_RCVD_SCALE|TF_REQ_SCALE)) { @@ -1045,7 +1055,7 @@ trimthenstep6: * tp->rcv_scale = tp->request_r_scale; * } */ - (void) tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); + (void)tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); tp->snd_wl1 = ti->ti_seq - 1; /* Avoid ack processing; snd_una==ti_ack => dup ack */ goto synrx_to_est; @@ -1069,9 +1079,9 @@ trimthenstep6: if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - tcpstat.tcps_rcvdupack++; - DEBUG_MISC((dfd," dup ack m = %lx so = %lx \n", - (long )m, (long )so)); + tcpstat.tcps_rcvdupack++; + DEBUG_MISC((dfd, " dup ack m = %lx so = %lx \n", + (long)m, (long)so)); /* * If we have outstanding data (other than * a window probe), this is a completely @@ -1091,18 +1101,18 @@ trimthenstep6: * the new ssthresh). * * Dup acks mean that packets have left the - * network (they're now cached at the receiver) + * network (they're now cached at the receiver) * so bump cwnd by the amount in the receiver * to keep a constant cwnd packets in the * network. */ if (tp->t_timer[TCPT_REXMT] == 0 || - ti->ti_ack != tp->snd_una) + ti->ti_ack != tp->snd_una) tp->t_dupacks = 0; else if (++tp->t_dupacks == tcprexmtthresh) { tcp_seq onxt = tp->snd_nxt; u_int win = - min(tp->snd_wnd, tp->snd_cwnd) / 2 / + min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; if (win < 2) @@ -1112,18 +1122,20 @@ trimthenstep6: tp->t_rtt = 0; tp->snd_nxt = ti->ti_ack; tp->snd_cwnd = tp->t_maxseg; - (void) tcp_output(tp); + (void)tcp_output(tp); tp->snd_cwnd = tp->snd_ssthresh + - tp->t_maxseg * tp->t_dupacks; + tp->t_maxseg * tp->t_dupacks; if (SEQ_GT(onxt, tp->snd_nxt)) tp->snd_nxt = onxt; goto drop; - } else if (tp->t_dupacks > tcprexmtthresh) { + } + else if (tp->t_dupacks > tcprexmtthresh) { tp->snd_cwnd += tp->t_maxseg; - (void) tcp_output(tp); + (void)tcp_output(tp); goto drop; } - } else + } + else tp->t_dupacks = 0; break; } @@ -1133,7 +1145,7 @@ trimthenstep6: * for the other side's cached packets, retract it. */ if (tp->t_dupacks > tcprexmtthresh && - tp->snd_cwnd > tp->snd_ssthresh) + tp->snd_cwnd > tp->snd_ssthresh) tp->snd_cwnd = tp->snd_ssthresh; tp->t_dupacks = 0; if (SEQ_GT(ti->ti_ack, tp->snd_max)) { @@ -1153,12 +1165,12 @@ trimthenstep6: * timer backoff (cf., Phil Karn's retransmit alg.). * Recompute the initial retransmit timer. */ -/* if (ts_present) - * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); - * else - */ - if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) - tcp_xmit_timer(tp,tp->t_rtt); + /* if (ts_present) + * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); + * else + */ + if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) + tcp_xmit_timer(tp, tp->t_rtt); /* * If all outstanding data is acked, stop retransmit @@ -1169,7 +1181,8 @@ trimthenstep6: if (ti->ti_ack == tp->snd_max) { tp->t_timer[TCPT_REXMT] = 0; needoutput = 1; - } else if (tp->t_timer[TCPT_PERSIST] == 0) + } + else if (tp->t_timer[TCPT_PERSIST] == 0) tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; /* * When new data is acked, open the congestion window. @@ -1179,40 +1192,41 @@ trimthenstep6: * (maxseg^2 / cwnd per packet). */ { - register u_int cw = tp->snd_cwnd; - register u_int incr = tp->t_maxseg; + register u_int cw = tp->snd_cwnd; + register u_int incr = tp->t_maxseg; - if (cw > tp->snd_ssthresh) - incr = incr * incr / cw; - tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<snd_scale); + if (cw > tp->snd_ssthresh) + incr = incr * incr / cw; + tp->snd_cwnd = min(cw + incr, (u_int32_t) (TCP_MAXWIN << tp->snd_scale)); } if (acked > so->so_snd.sb_cc) { tp->snd_wnd -= so->so_snd.sb_cc; - sbdrop(&so->so_snd, (int )so->so_snd.sb_cc); + sbdrop(&so->so_snd, so->so_snd.sb_cc); ourfinisacked = 1; - } else { + } + else { sbdrop(&so->so_snd, acked); tp->snd_wnd -= acked; ourfinisacked = 0; } /* * XXX sowwakup is called when data is acked and there's room for - * for more data... it should read() the socket + * for more data... it should read() the socket */ -/* if (so->so_snd.sb_flags & SB_NOTIFY) - * sowwakeup(so); - */ + /* if (so->so_snd.sb_flags & SB_NOTIFY) + * sowwakeup(so); + */ tp->snd_una = ti->ti_ack; if (SEQ_LT(tp->snd_nxt, tp->snd_una)) tp->snd_nxt = tp->snd_una; switch (tp->t_state) { - /* - * In FIN_WAIT_1 STATE in addition to the processing - * for the ESTABLISHED state if our FIN is now acknowledged - * then enter FIN_WAIT_2. - */ + /* + * In FIN_WAIT_1 STATE in addition to the processing + * for the ESTABLISHED state if our FIN is now acknowledged + * then enter FIN_WAIT_2. + */ case TCPS_FIN_WAIT_1: if (ourfinisacked) { /* @@ -1230,12 +1244,12 @@ trimthenstep6: } break; - /* - * In CLOSING STATE in addition to the processing for - * the ESTABLISHED state if the ACK acknowledges our FIN - * then enter the TIME-WAIT state, otherwise ignore - * the segment. - */ + /* + * In CLOSING STATE in addition to the processing for + * the ESTABLISHED state if the ACK acknowledges our FIN + * then enter the TIME-WAIT state, otherwise ignore + * the segment. + */ case TCPS_CLOSING: if (ourfinisacked) { tp->t_state = TCPS_TIME_WAIT; @@ -1245,12 +1259,12 @@ trimthenstep6: } break; - /* - * In LAST_ACK, we may still be waiting for data to drain - * and/or to be acked, as well as for the ack of our FIN. - * If our FIN is now acknowledged, delete the TCB, - * enter the closed state and return. - */ + /* + * In LAST_ACK, we may still be waiting for data to drain + * and/or to be acked, as well as for the ack of our FIN. + * If our FIN is now acknowledged, delete the TCB, + * enter the closed state and return. + */ case TCPS_LAST_ACK: if (ourfinisacked) { tp = tcp_close(tp); @@ -1258,11 +1272,11 @@ trimthenstep6: } break; - /* - * In TIME_WAIT state the only thing that should arrive - * is a retransmission of the remote FIN. Acknowledge - * it and restart the finack timer. - */ + /* + * In TIME_WAIT state the only thing that should arrive + * is a retransmission of the remote FIN. Acknowledge + * it and restart the finack timer. + */ case TCPS_TIME_WAIT: tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; goto dropafterack; @@ -1275,12 +1289,12 @@ step6: * Don't look at window if no ACK: TAC's send garbage on first SYN. */ if ((tiflags & TH_ACK) && - (SEQ_LT(tp->snd_wl1, ti->ti_seq) || - (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) || - (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) { + (SEQ_LT(tp->snd_wl1, ti->ti_seq) || + (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) || + (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) { /* keep track of pure window updates */ if (ti->ti_len == 0 && - tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd) + tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd) tcpstat.tcps_rcvwinupd++; tp->snd_wnd = tiwin; tp->snd_wl1 = ti->ti_seq; @@ -1294,7 +1308,7 @@ step6: * Process segments with URG. */ if ((tiflags & TH_URG) && ti->ti_urp && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { + TCPS_HAVERCVDFIN(tp->t_state) == 0) { /* * This is a kludge, but if we receive and accept * random urgent pointers, we'll crash in @@ -1310,31 +1324,32 @@ step6: * If this segment advances the known urgent pointer, * then mark the data stream. This should not happen * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since - * a FIN has been received from the remote side. + * a FIN has been received from the remote side. * In these states we ignore the URG. * * According to RFC961 (Assigned Protocols), * the urgent pointer points to the last octet * of urgent data. We continue, however, * to consider it to indicate the first octet - * of data past the urgent section as the original + * of data past the urgent section as the original * spec states (in one of two places). */ - if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) { + if (SEQ_GT(ti->ti_seq + ti->ti_urp, tp->rcv_up)) { tp->rcv_up = ti->ti_seq + ti->ti_urp; - so->so_urgc = so->so_rcv.sb_cc + + so->so_urgc = so->so_rcv.sb_cc + (tp->rcv_up - tp->rcv_nxt); /* -1; */ tp->rcv_up = ti->ti_seq + ti->ti_urp; - + } - } else + } + else /* * If no out of band data is expected, * pull receive urgent pointer along * with the receive window. */ if (SEQ_GT(tp->rcv_nxt, tp->rcv_up)) - tp->rcv_up = tp->rcv_nxt; + tp->rcv_up = tp->rcv_nxt; dodata: /* @@ -1346,7 +1361,7 @@ dodata: * connection then we just ignore the text. */ if ((ti->ti_len || (tiflags&TH_FIN)) && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { + TCPS_HAVERCVDFIN(tp->t_state) == 0) { TCP_REASS(tp, ti, m, so, tiflags); /* * Note the amount of data that peer has sent into @@ -1354,7 +1369,8 @@ dodata: * buffer size. */ len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt); - } else { + } + else { m_free(m); tiflags &= ~TH_FIN; } @@ -1368,45 +1384,45 @@ dodata: /* * If we receive a FIN we can't send more data, * set it SS_FDRAIN - * Shutdown the socket if there is no rx data in the + * Shutdown the socket if there is no rx data in the * buffer. * soread() is called on completion of shutdown() and * will got to TCPS_LAST_ACK, and use tcp_output() * to send the FIN. */ -/* sofcantrcvmore(so); */ + /* sofcantrcvmore(so); */ sofwdrain(so); - + tp->t_flags |= TF_ACKNOW; tp->rcv_nxt++; } switch (tp->t_state) { - /* - * In SYN_RECEIVED and ESTABLISHED STATES - * enter the CLOSE_WAIT state. - */ + /* + * In SYN_RECEIVED and ESTABLISHED STATES + * enter the CLOSE_WAIT state. + */ case TCPS_SYN_RECEIVED: case TCPS_ESTABLISHED: - if(so->so_emu == EMU_CTL) /* no shutdown on socket */ - tp->t_state = TCPS_LAST_ACK; - else - tp->t_state = TCPS_CLOSE_WAIT; - break; + if (so->so_emu == EMU_CTL) /* no shutdown on socket */ + tp->t_state = TCPS_LAST_ACK; + else + tp->t_state = TCPS_CLOSE_WAIT; + break; - /* - * If still in FIN_WAIT_1 STATE FIN has not been acked so - * enter the CLOSING state. - */ + /* + * If still in FIN_WAIT_1 STATE FIN has not been acked so + * enter the CLOSING state. + */ case TCPS_FIN_WAIT_1: tp->t_state = TCPS_CLOSING; break; - /* - * In FIN_WAIT_2 state enter the TIME_WAIT state, - * starting the time-wait timer, turning off the other - * standard timers. - */ + /* + * In FIN_WAIT_2 state enter the TIME_WAIT state, + * starting the time-wait timer, turning off the other + * standard timers. + */ case TCPS_FIN_WAIT_2: tp->t_state = TCPS_TIME_WAIT; tcp_canceltimers(tp); @@ -1414,9 +1430,9 @@ dodata: soisfdisconnected(so); break; - /* - * In TIME_WAIT state restart the 2 MSL time_wait timer. - */ + /* + * In TIME_WAIT state restart the 2 MSL time_wait timer. + */ case TCPS_TIME_WAIT: tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; break; @@ -1427,18 +1443,18 @@ dodata: * If this is a small packet, then ACK now - with Nagel * congestion avoidance sender won't send more until * he gets an ACK. - * + * * See above. */ -/* if (ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg) { - */ -/* if ((ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg && - * (so->so_iptos & IPTOS_LOWDELAY) == 0) || - * ((so->so_iptos & IPTOS_LOWDELAY) && - * ((struct tcpiphdr_2 *)ti)->first_char == (char)27)) { - */ + /* if (ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg) { + */ + /* if ((ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg && + * (so->so_iptos & IPTOS_LOWDELAY) == 0) || + * ((so->so_iptos & IPTOS_LOWDELAY) && + * ((struct tcpiphdr_2 *)ti)->first_char == (char)27)) { + */ if (ti->ti_len && (unsigned)ti->ti_len <= 5 && - ((struct tcpiphdr_2 *)ti)->first_char == (char)27) { + ((struct tcpiphdr_2 *)ti)->first_char == (char)27) { tp->t_flags |= TF_ACKNOW; } @@ -1446,7 +1462,7 @@ dodata: * Return any desired output. */ if (needoutput || (tp->t_flags & TF_ACKNOW)) { - (void) tcp_output(tp); + (void)tcp_output(tp); } return; @@ -1459,7 +1475,7 @@ dropafterack: goto drop; m_freem(m); tp->t_flags |= TF_ACKNOW; - (void) tcp_output(tp); + (void)tcp_output(tp); return; dropwithreset: @@ -1468,8 +1484,8 @@ dropwithreset: tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST); else { if (tiflags & TH_SYN) ti->ti_len++; - tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0, - TH_RST|TH_ACK); + tcp_respond(tp, ti, m, ti->ti_seq + ti->ti_len, (tcp_seq)0, + TH_RST | TH_ACK); } return; @@ -1488,11 +1504,7 @@ drop: * u_int32_t *ts_val, *ts_ecr; */ void -tcp_dooptions(tp, cp, cnt, ti) - struct tcpcb *tp; - u_char *cp; - int cnt; - struct tcpiphdr *ti; +tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti) { u_int16_t mss; int opt, optlen; @@ -1523,7 +1535,7 @@ tcp_dooptions(tp, cp, cnt, ti) continue; memcpy((char *) &mss, (char *) cp + 2, sizeof(mss)); NTOHS(mss); - (void) tcp_mss(tp, mss); /* sets t_maxseg */ + tcp_mss(tp, mss); /* sets t_maxseg */ break; /* case TCPOPT_WINDOW: @@ -1568,11 +1580,7 @@ tcp_dooptions(tp, cp, cnt, ti) #ifdef notdef -void -tcp_pulloutofband(so, ti, m) - struct socket *so; - struct tcpiphdr *ti; - register struct mbuf *m; +void tcp_pulloutofband(struct socket *so, struct tcpiphdr *ti, register struct mbuf *m) { int cnt = ti->ti_urp - 1; @@ -1602,10 +1610,7 @@ tcp_pulloutofband(so, ti, m) * and update averages and current timeout. */ -void -tcp_xmit_timer(tp, rtt) - register struct tcpcb *tp; - int rtt; +void tcp_xmit_timer(register struct tcpcb *tp, int rtt) { register short delta; @@ -1692,13 +1697,10 @@ tcp_xmit_timer(tp, rtt) * parameters from pre-set or cached values in the routing entry. */ -int -tcp_mss(tp, offer) - register struct tcpcb *tp; - u_int offer; +u_int tcp_mss(register struct tcpcb *tp, u_int offer) { struct socket *so = tp->t_socket; - int mss; + u_int mss; DEBUG_CALL("tcp_mss"); DEBUG_ARG("tp = %lx", (long)tp); diff --git a/BasiliskII/src/slirp/tcp_output.c b/BasiliskII/src/slirp/tcp_output.c index 5cb1a61e..0d5c0ce5 100644 --- a/BasiliskII/src/slirp/tcp_output.c +++ b/BasiliskII/src/slirp/tcp_output.c @@ -63,12 +63,10 @@ u_char tcp_outflags[TCP_NSTATES] = { /* * Tcp output routine: figure out what should be sent and send it. */ -int -tcp_output(tp) - register struct tcpcb *tp; +int tcp_output(register struct tcpcb *tp) { register struct socket *so = tp->t_socket; - register long len, win; + register u_long len, win; int off, flags, error; register struct mbuf *m; register struct tcpiphdr *ti; @@ -126,7 +124,7 @@ again: * to send then the probe will be the FIN * itself. */ - if (off < so->so_snd.sb_cc) + if (off < (int)so->so_snd.sb_cc) flags &= ~TH_FIN; win = 1; } else { @@ -201,12 +199,12 @@ again: * taking into account that we are limited by * TCP_MAXWIN << tp->rcv_scale. */ - long adv = min(win, (long)TCP_MAXWIN << tp->rcv_scale) - + u_int adv = min(win, (u_int)TCP_MAXWIN << tp->rcv_scale) - (tp->rcv_adv - tp->rcv_nxt); - if (adv >= (long) (2 * tp->t_maxseg)) + if (adv >= (u_int)(2 * tp->t_maxseg)) goto send; - if (2 * adv >= (long) so->so_rcv.sb_datalen) + if (2 * adv >= so->so_rcv.sb_datalen) goto send; } @@ -359,7 +357,7 @@ send: */ /* if (len <= MHLEN - hdrlen - max_linkhdr) { */ - sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen); + sbcopy(&so->so_snd, off, len, mtod(m, caddr_t) + hdrlen); m->m_len += len; /* } else { @@ -435,12 +433,12 @@ send: * Calculate receive window. Don't shrink window, * but avoid silly window syndrome. */ - if (win < (long)(so->so_rcv.sb_datalen / 4) && win < (long)tp->t_maxseg) + if (win < (so->so_rcv.sb_datalen / 4) && win < tp->t_maxseg) win = 0; - if (win > (long)TCP_MAXWIN << tp->rcv_scale) - win = (long)TCP_MAXWIN << tp->rcv_scale; - if (win < (long)(tp->rcv_adv - tp->rcv_nxt)) - win = (long)(tp->rcv_adv - tp->rcv_nxt); + if (win > (u_long) (TCP_MAXWIN << tp->rcv_scale)) + win = (u_long) (TCP_MAXWIN << tp->rcv_scale); + if (win < (tp->rcv_adv - tp->rcv_nxt)) + win = (tp->rcv_adv - tp->rcv_nxt); ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale)); if (SEQ_GT(tp->snd_up, tp->snd_una)) { @@ -530,7 +528,7 @@ send: { - ((struct ip *)ti)->ip_len = m->m_len; + ((struct ip *)ti)->ip_len = (u_int16_t) m->m_len; ((struct ip *)ti)->ip_ttl = ip_defttl; ((struct ip *)ti)->ip_tos = so->so_iptos; @@ -581,9 +579,7 @@ out: return (0); } -void -tcp_setpersist(tp) - register struct tcpcb *tp; +void tcp_setpersist(register struct tcpcb *tp) { int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1; diff --git a/BasiliskII/src/slirp/tcp_subr.c b/BasiliskII/src/slirp/tcp_subr.c index ae40775d..70e04b5e 100644 --- a/BasiliskII/src/slirp/tcp_subr.c +++ b/BasiliskII/src/slirp/tcp_subr.c @@ -46,14 +46,13 @@ int tcp_mssdflt = TCP_MSS; int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ; int tcp_do_rfc1323 = 0; /* Don't do rfc1323 performance enhancements */ -int tcp_rcvspace; /* You may want to change this */ -int tcp_sndspace; /* Keep small if you have an error prone link */ +size_t tcp_rcvspace; /* You may want to change this */ +size_t tcp_sndspace; /* Keep small if you have an error prone link */ /* * Tcp initialization */ -void -tcp_init() +void tcp_init() { tcp_iss = 1; /* wrong */ tcb.so_next = tcb.so_prev = &tcb; @@ -74,9 +73,7 @@ tcp_init() * necessary when the connection is used. */ /* struct tcpiphdr * */ -void -tcp_template(tp) - struct tcpcb *tp; +void tcp_template(struct tcpcb *tp) { struct socket *so = tp->t_socket; register struct tcpiphdr *n = &tp->t_template; @@ -113,13 +110,8 @@ tcp_template(tp) * In any case the ack and sequence number of the transmitted * segment are as specified by the parameters. */ -void -tcp_respond(tp, ti, m, ack, seq, flags) - struct tcpcb *tp; - register struct tcpiphdr *ti; - register struct mbuf *m; - tcp_seq ack, seq; - int flags; +void tcp_respond(struct tcpcb *tp, register struct tcpiphdr *ti, + register struct mbuf *m, tcp_seq ack, tcp_seq seq, int flags) { register int tlen; int win = 0; @@ -193,9 +185,7 @@ tcp_respond(tp, ti, m, ack, seq, flags) * empty reassembly queue and hooking it to the argument * protocol control block. */ -struct tcpcb * -tcp_newtcpcb(so) - struct socket *so; +struct tcpcb *tcp_newtcpcb(struct socket *so) { register struct tcpcb *tp; @@ -268,9 +258,7 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err) * discard internet protocol block * wake up any sleepers */ -struct tcpcb * -tcp_close(tp) - register struct tcpcb *tp; +struct tcpcb *tcp_close(register struct tcpcb *tp) { register struct tcpiphdr *t; struct socket *so = tp->t_socket; @@ -306,8 +294,7 @@ tcp_close(tp) return ((struct tcpcb *)0); } -void -tcp_drain() +void tcp_drain() { /* XXX */ } @@ -319,10 +306,7 @@ tcp_drain() #ifdef notdef -void -tcp_quench(i, errno) - - int errno; +void tcp_quench(int i, int errno) { struct tcpcb *tp = intotcpcb(inp); @@ -346,9 +330,7 @@ tcp_quench(i, errno) * for peer to send FIN or not respond to keep-alives, etc. * We can let the user exit from the close as soon as the FIN is acked. */ -void -tcp_sockclosed(tp) - struct tcpcb *tp; +void tcp_sockclosed(struct tcpcb *tp) { DEBUG_CALL("tcp_sockclosed"); @@ -389,8 +371,7 @@ tcp_sockclosed(tp) * nonblocking. Connect returns after the SYN is sent, and does * not wait for ACK+SYN. */ -int tcp_fconnect(so) - struct socket *so; +int tcp_fconnect(struct socket *so) { int ret=0; @@ -423,10 +404,12 @@ int tcp_fconnect(so) } else addr.sin_addr = so->so_faddr; addr.sin_port = so->so_fport; - + + char addrstr[INET_ADDRSTRLEN]; DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, " "addr.sin_addr.s_addr=%.16s\n", - ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); + ntohs(addr.sin_port), inet_ntop(AF_INET, &addr.sin_addr, + addrstr, sizeof(addrstr)))); /* We don't care what port we get */ ret = connect(s,(struct sockaddr *)&addr,sizeof (addr)); @@ -452,9 +435,7 @@ int tcp_fconnect(so) * the time it gets to accept(), so... We simply accept * here and SYN the local-host. */ -void -tcp_connect(inso) - struct socket *inso; +void tcp_connect(struct socket *inso) { struct socket *so; struct sockaddr_in addr; @@ -486,7 +467,7 @@ tcp_connect(inso) so->so_lport = inso->so_lport; } - (void) tcp_mss(sototcpcb(so), 0); + tcp_mss(sototcpcb(so), 0); if ((s = accept(inso->s,(struct sockaddr *)&addr,&addrlen)) < 0) { tcp_close(sototcpcb(so)); /* This will sofree() as well */ @@ -539,9 +520,7 @@ tcp_connect(inso) /* * Attach a TCPCB to a socket. */ -int -tcp_attach(so) - struct socket *so; +int tcp_attach(struct socket *so) { if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) return -1; @@ -575,9 +554,7 @@ struct emu_t *tcpemu = 0; /* * Return TOS according to the above table */ -u_int8_t -tcp_tos(so) - struct socket *so; +u_int8_t tcp_tos(struct socket *so) { int i = 0; struct emu_t *emup; @@ -629,10 +606,7 @@ int do_echo = -1; * * NOTE: if you return 0 you MUST m_free() the mbuf! */ -int -tcp_emu(so, m) - struct socket *so; - struct mbuf *m; +int tcp_emu(struct socket *so, struct mbuf *m) { u_int n1, n2, n3, n4, n5, n6; char buff[256]; @@ -833,7 +807,7 @@ tcp_emu(so, m) ns->so_laddr=so->so_laddr; ns->so_lport=htons(port); - (void) tcp_mss(sototcpcb(ns), 0); + tcp_mss(sototcpcb(ns), 0); ns->so_faddr=so->so_faddr; ns->so_fport=htons(IPPORT_RESERVED-1); /* Use a fake port. */ @@ -1060,7 +1034,7 @@ do_prompt: * of the connection as a NUL-terminated decimal ASCII string. */ so->so_emu = 0; - for (lport = 0, i = 0; i < m->m_len-1; ++i) { + for (lport = 0, i = 0; i < (int) (m->m_len-1); ++i) { if (m->m_data[i] < '0' || m->m_data[i] > '9') return 1; /* invalid number */ lport *= 10; @@ -1245,9 +1219,7 @@ do_prompt: * Return 0 if this connections is to be closed, 1 otherwise, * return 2 if this is a command-line connection */ -int -tcp_ctl(so) - struct socket *so; +int tcp_ctl(struct socket *so) { struct sbuf *sb = &so->so_snd; int command; diff --git a/BasiliskII/src/slirp/tcp_timer.h b/BasiliskII/src/slirp/tcp_timer.h index 0bc438c7..73fe2089 100644 --- a/BasiliskII/src/slirp/tcp_timer.h +++ b/BasiliskII/src/slirp/tcp_timer.h @@ -130,9 +130,9 @@ extern int tcp_backoff[]; struct tcpcb; -void tcp_fasttimo _P((void)); -void tcp_slowtimo _P((void)); -void tcp_canceltimers _P((struct tcpcb *)); -struct tcpcb * tcp_timers _P((register struct tcpcb *, int)); +void tcp_fasttimo(void); +void tcp_slowtimo(void); +void tcp_canceltimers(struct tcpcb *); +struct tcpcb * tcp_timers(register struct tcpcb *, int); #endif diff --git a/BasiliskII/src/slirp/tftp.h b/BasiliskII/src/slirp/tftp.h index f89e0393..b150a049 100644 --- a/BasiliskII/src/slirp/tftp.h +++ b/BasiliskII/src/slirp/tftp.h @@ -34,7 +34,7 @@ struct tftp_t { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif void tftp_input(struct mbuf *m); diff --git a/BasiliskII/src/slirp/udp.c b/BasiliskII/src/slirp/udp.c index 10704c35..deedb1e7 100644 --- a/BasiliskII/src/slirp/udp.c +++ b/BasiliskII/src/slirp/udp.c @@ -275,7 +275,7 @@ int udp_output2(struct socket *so, struct mbuf *m, ui->ui_next = ui->ui_prev = 0; ui->ui_x1 = 0; ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons(m->m_len - sizeof(struct ip)); /* + sizeof (struct udphdr)); */ + ui->ui_len = htons((u_short) (m->m_len - sizeof(struct ip))); /* + sizeof (struct udphdr)); */ /* XXXXX Check for from-one-location sockets, or from-any-location sockets */ ui->ui_src = saddr->sin_addr; ui->ui_dst = daddr->sin_addr; @@ -291,7 +291,7 @@ int udp_output2(struct socket *so, struct mbuf *m, if ((ui->ui_sum = cksum(m, /* sizeof (struct udpiphdr) + */ m->m_len)) == 0) ui->ui_sum = 0xffff; } - ((struct ip *)ui)->ip_len = m->m_len; + ((struct ip *)ui)->ip_len = (u_int16_t) m->m_len; ((struct ip *)ui)->ip_ttl = ip_defttl; ((struct ip *)ui)->ip_tos = iptos; @@ -338,14 +338,10 @@ udp_attach(so) addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; if(bind(so->s, (struct sockaddr *)&addr, sizeof(addr))<0) { - int lasterrno=errno; + int error = WSAGetLastError(); closesocket(so->s); so->s=-1; -#ifdef _WIN32 - WSASetLastError(lasterrno); -#else - errno=lasterrno; -#endif + WSASetLastError(error); } else { /* success, insert in queue */ so->so_expire = curtime + SO_EXPIRE; diff --git a/BasiliskII/src/slirp/udp.h b/BasiliskII/src/slirp/udp.h index c16756f6..7d844efe 100644 --- a/BasiliskII/src/slirp/udp.h +++ b/BasiliskII/src/slirp/udp.h @@ -54,7 +54,7 @@ struct udphdr { } PACKED__; #ifdef PRAGMA_PACK_SUPPORTED -#pragma pack(0) +#pragma pack(PACK_RESET) #endif /* @@ -100,14 +100,14 @@ extern struct udpstat udpstat; extern struct socket udb; struct mbuf; -void udp_init _P((void)); -void udp_input _P((register struct mbuf *, int)); -int udp_output _P((struct socket *, struct mbuf *, struct sockaddr_in *)); -int udp_attach _P((struct socket *)); -void udp_detach _P((struct socket *)); -u_int8_t udp_tos _P((struct socket *)); -void udp_emu _P((struct socket *, struct mbuf *)); -struct socket * udp_listen _P((u_int, u_int32_t, u_int, int)); +void udp_init(void); +void udp_input(register struct mbuf *, int); +int udp_output(struct socket *, struct mbuf *, struct sockaddr_in *); +int udp_attach(struct socket *); +void udp_detach(struct socket *); +u_int8_t udp_tos(struct socket *); +void udp_emu(struct socket *, struct mbuf *); +struct socket * udp_listen(u_int, u_int32_t, u_int, int); int udp_output2(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, struct sockaddr_in *daddr, int iptos); From f066f5a4fd5a827c7db3b88b20890b39477e1362 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:12:43 -0700 Subject: [PATCH 04/19] video_sdl compiles cleanly in MSVC. Resolved a bunch of type conversion warnings. --- BasiliskII/src/SDL/video_sdl.cpp | 78 ++++++++++++++++---------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/BasiliskII/src/SDL/video_sdl.cpp b/BasiliskII/src/SDL/video_sdl.cpp index 9f879f4c..4ea28b72 100644 --- a/BasiliskII/src/SDL/video_sdl.cpp +++ b/BasiliskII/src/SDL/video_sdl.cpp @@ -94,7 +94,7 @@ const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; // Global variables -static int32 frame_skip; // Prefs items +static uint32 frame_skip; // Prefs items static int16 mouse_wheel_mode; static int16 mouse_wheel_lines; @@ -475,7 +475,7 @@ static bool has_mode(int type, int width, int height, int depth) // Rely on SDL capabilities return SDL_VideoModeOK(width, height, sdl_depth_of_video_depth(depth), - SDL_HWSURFACE | (type == DISPLAY_SCREEN ? SDL_FULLSCREEN : 0)); + SDL_HWSURFACE | (type == DISPLAY_SCREEN ? SDL_FULLSCREEN : 0)) != 0; } // Add mode to list of supported modes @@ -1840,21 +1840,22 @@ static void handle_events(void) static void update_display_static(driver_base *drv) { // Incremental update code - int wide = 0, high = 0, x1, x2, y1, y2, i, j; + int wide = 0, high = 0; + uint32 x1, x2, y1, y2; const VIDEO_MODE &mode = drv->mode; int bytes_per_row = VIDEO_MODE_ROW_BYTES; uint8 *p, *p2; // Check for first line from top and first line from bottom that have changed y1 = 0; - for (j=0; j=y1; j--) { + for (uint32 j = VIDEO_MODE_Y; j-- > y1; ) { if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { y2 = j; break; @@ -1864,16 +1865,16 @@ static void update_display_static(driver_base *drv) // Check for first column from left and first column from right that have changed if (high) { - if ((int)VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { + if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { const int src_bytes_per_row = bytes_per_row; const int dst_bytes_per_row = drv->s->pitch; const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; x1 = VIDEO_MODE_X / pixels_per_byte; - for (j = y1; j <= y2; j++) { + for (uint32 j = y1; j <= y2; j++) { p = &the_buffer[j * bytes_per_row]; p2 = &the_buffer_copy[j * bytes_per_row]; - for (i = 0; i < x1; i++) { + for (uint32 i = 0; i < x1; i++) { if (*p != *p2) { x1 = i; break; @@ -1882,12 +1883,12 @@ static void update_display_static(driver_base *drv) } } x2 = x1; - for (j = y1; j <= y2; j++) { + for (uint32 j = y1; j <= y2; j++) { p = &the_buffer[j * bytes_per_row]; p2 = &the_buffer_copy[j * bytes_per_row]; p += bytes_per_row; p2 += bytes_per_row; - for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { + for (uint32 i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { p--; p2--; if (*p != *p2) { x2 = i; @@ -1909,7 +1910,7 @@ static void update_display_static(driver_base *drv) // Blit to screen surface int si = y1 * src_bytes_per_row + (x1 / pixels_per_byte); int di = y1 * dst_bytes_per_row + x1; - for (j = y1; j <= y2; j++) { + for (uint32 j = y1; j <= y2; j++) { memcpy(the_buffer_copy + si, the_buffer + si, wide / pixels_per_byte); Screen_blit((uint8 *)drv->s->pixels + di, the_buffer + si, wide / pixels_per_byte); si += src_bytes_per_row; @@ -1929,10 +1930,10 @@ static void update_display_static(driver_base *drv) const int dst_bytes_per_row = drv->s->pitch; x1 = VIDEO_MODE_X; - for (j=y1; j<=y2; j++) { + for (uint32 j = y1; j <= y2; j++) { p = &the_buffer[j * bytes_per_row]; p2 = &the_buffer_copy[j * bytes_per_row]; - for (i=0; ix2*bytes_per_pixel; i--) { + for (uint32 i = VIDEO_MODE_X * bytes_per_pixel; i > x2 * bytes_per_pixel; i--) { p--; p2--; if (*p != *p2) { @@ -1965,8 +1966,8 @@ static void update_display_static(driver_base *drv) SDL_LockSurface(drv->s); // Blit to screen surface - for (j=y1; j<=y2; j++) { - i = j * bytes_per_row + x1 * bytes_per_pixel; + for (uint32 j = y1; j <= y2; j++) { + uint32 i = j * bytes_per_row + x1 * bytes_per_pixel; int dst_i = j * dst_bytes_per_row + x1 * bytes_per_pixel; memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide); Screen_blit((uint8 *)drv->s->pixels + dst_i, the_buffer + i, bytes_per_pixel * wide); @@ -1990,35 +1991,34 @@ static void update_display_static_bbox(driver_base *drv) const VIDEO_MODE &mode = drv->mode; // Allocate bounding boxes for SDL_UpdateRects() - const int N_PIXELS = 64; - const int n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS; - const int n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS; + const uint32 N_PIXELS = 64; + const uint32 n_x_boxes = (VIDEO_MODE_X + N_PIXELS - 1) / N_PIXELS; + const uint32 n_y_boxes = (VIDEO_MODE_Y + N_PIXELS - 1) / N_PIXELS; SDL_Rect *boxes = (SDL_Rect *)alloca(sizeof(SDL_Rect) * n_x_boxes * n_y_boxes); - int nr_boxes = 0; + uint32 nr_boxes = 0; // Lock surface, if required if (SDL_MUSTLOCK(drv->s)) SDL_LockSurface(drv->s); // Update the surface from Mac screen - const int bytes_per_row = VIDEO_MODE_ROW_BYTES; - const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; - const int dst_bytes_per_row = drv->s->pitch; - int x, y; - for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { - int h = N_PIXELS; + const uint32 bytes_per_row = VIDEO_MODE_ROW_BYTES; + const uint32 bytes_per_pixel = bytes_per_row / VIDEO_MODE_X; + const uint32 dst_bytes_per_row = drv->s->pitch; + for (uint32 y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) { + uint32 h = N_PIXELS; if (h > VIDEO_MODE_Y - y) h = VIDEO_MODE_Y - y; - for (x = 0; x < VIDEO_MODE_X; x += N_PIXELS) { - int w = N_PIXELS; + for (uint32 x = 0; x < VIDEO_MODE_X; x += N_PIXELS) { + uint32 w = N_PIXELS; if (w > VIDEO_MODE_X - x) w = VIDEO_MODE_X - x; const int xs = w * bytes_per_pixel; const int xb = x * bytes_per_pixel; bool dirty = false; - for (int j = y; j < (y + h); j++) { - const int yb = j * bytes_per_row; - const int dst_yb = j * dst_bytes_per_row; + for (uint32 j = y; j < (y + h); j++) { + const uint32 yb = j * bytes_per_row; + const uint32 dst_yb = j * dst_bytes_per_row; if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) { memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs); Screen_blit((uint8 *)drv->s->pixels + dst_yb + xb, the_buffer + yb + xb, xs); @@ -2102,7 +2102,7 @@ static void video_refresh_dga_vosf(void) possibly_quit_dga_mode(); // Update display (VOSF variant) - static int tick_counter = 0; + static uint32 tick_counter = 0; if (++tick_counter >= frame_skip) { tick_counter = 0; if (mainBuffer.dirty) { @@ -2120,7 +2120,7 @@ static void video_refresh_window_vosf(void) possibly_ungrab_mouse(); // Update display (VOSF variant) - static int tick_counter = 0; + static uint32 tick_counter = 0; if (++tick_counter >= frame_skip) { tick_counter = 0; if (mainBuffer.dirty) { @@ -2138,7 +2138,7 @@ static void video_refresh_window_static(void) possibly_ungrab_mouse(); // Update display (static variant) - static int tick_counter = 0; + static uint32 tick_counter = 0; if (++tick_counter >= frame_skip) { tick_counter = 0; const VIDEO_MODE &mode = drv->mode; @@ -2214,7 +2214,7 @@ static int redraw_func(void *arg) // Wait next += VIDEO_REFRESH_DELAY; - int64 delay = next - GetTicks_usec(); + int32 delay = int32(next - GetTicks_usec()); if (delay > 0) Delay_usec(delay); else if (delay < -VIDEO_REFRESH_DELAY) @@ -2247,9 +2247,9 @@ void video_set_dirty_area(int x, int y, int w, int h) { #ifdef ENABLE_VOSF const VIDEO_MODE &mode = drv->mode; - const int screen_width = VIDEO_MODE_X; - const int screen_height = VIDEO_MODE_Y; - const int bytes_per_row = VIDEO_MODE_ROW_BYTES; + const unsigned screen_width = VIDEO_MODE_X; + const unsigned screen_height = VIDEO_MODE_Y; + const unsigned bytes_per_row = VIDEO_MODE_ROW_BYTES; if (use_vosf) { vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row); From 2d2e72143733b26e740952aeb838fd7e9c497274 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:17:17 -0700 Subject: [PATCH 05/19] Use ISO C functions for MSVC. --- BasiliskII/src/uae_cpu/fpu/mathlib.h | 38 +++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/BasiliskII/src/uae_cpu/fpu/mathlib.h b/BasiliskII/src/uae_cpu/fpu/mathlib.h index dcf25f73..2363af56 100644 --- a/BasiliskII/src/uae_cpu/fpu/mathlib.h +++ b/BasiliskII/src/uae_cpu/fpu/mathlib.h @@ -51,14 +51,18 @@ // NOTE: this is irrelevant on Win32 platforms since the MS libraries // don't support extended-precision floating-point computations -#ifdef WIN32 +#if defined(WIN32) && USE_LONG_DOUBLE #undef FPU_USE_ISO_C99 #endif // Use faster implementation of math functions, but this could cause // some incorrect results (?) -// TODO: actually implement the slower but safer versions +#ifdef _MSC_VER +// MSVC uses intrinsics for all of the math functions, so it should still be fast +#define FPU_FAST_MATH 0 +#else #define FPU_FAST_MATH 1 +#endif #if FPU_USE_ISO_C99 // NOTE: no prior shall be included at this point @@ -373,7 +377,7 @@ PRIVATE inline bool FFPU fp_do_isnan(fpu_register const & r) hx &= 0x7fffffff; hx |= (uae_u32)(lx | (-lx)) >> 31; hx = 0x7ff00000 - hx; - return (int)(((uae_u32)hx) >> 31); + return (((uae_u32)hx) >> 31) != 0; #elif USE_QUAD_DOUBLE fp_declare_init_shape(sxp, r, extended); uae_s64 hx = sxp->parts64.msw; @@ -381,7 +385,7 @@ PRIVATE inline bool FFPU fp_do_isnan(fpu_register const & r) hx &= 0x7fffffffffffffffLL; hx |= (uae_u64)(lx | (-lx)) >> 63; hx = 0x7fff000000000000LL - hx; - return (int)((uae_u64)hx >> 63); + return ((uae_u64)hx >> 63) != 0; #else fp_declare_init_shape(sxp, r, extended); uae_s32 se = sxp->parts.sign_exponent; @@ -392,7 +396,7 @@ PRIVATE inline bool FFPU fp_do_isnan(fpu_register const & r) se |= (uae_u32)(lx | (-lx)) >> 31; se = 0xfffe - se; // TODO: check whether rshift count is 16 or 31 - return (int)(((uae_u32)(se)) >> 16); + return (((uae_u32)(se)) >> 16) != 0; #endif #else #if USE_LONG_DOUBLE || USE_QUAD_DOUBLE @@ -428,14 +432,14 @@ PRIVATE inline bool FFPU fp_do_isinf(fpu_register const & r) uae_s32 lx = sxp->parts.lsw; lx |= (hx & 0x7fffffff) ^ 0x7ff00000; lx |= -lx; - return ~(lx >> 31) & (hx >> 30); + return (~(lx >> 31) & (hx >> 30)) != 0; #elif USE_QUAD_DOUBLE fp_declare_init_shape(sxp, r, extended); uae_s64 hx = sxp->parts64.msw; uae_s64 lx = sxp->parts64.lsw; lx |= (hx & 0x7fffffffffffffffLL) ^ 0x7fff000000000000LL; lx |= -lx; - return ~(lx >> 63) & (hx >> 62); + return (~(lx >> 63) & (hx >> 62)) != 0; #else fp_declare_init_shape(sxp, r, extended); uae_s32 se = sxp->parts.sign_exponent; @@ -451,7 +455,7 @@ PRIVATE inline bool FFPU fp_do_isinf(fpu_register const & r) #endif lx |= -lx; se &= 0x8000; - return ~(lx >> 31) & (1 - (se >> 14)); + return (~(lx >> 31) & (1 - (se >> 14))) != 0; #endif #else #if USE_LONG_DOUBLE || USE_QUAD_DOUBLE @@ -661,7 +665,8 @@ PRIVATE inline uae_u32 FFPU get_quotient_sign(fpu_register const & ra, fpu_regis /* --- Math functions --- */ /* -------------------------------------------------------------------------- */ -#if FPU_USE_ISO_C99 && (USE_LONG_DOUBLE || USE_QUAD_DOUBLE) +#if FPU_USE_ISO_C99 +#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE # ifdef HAVE_LOGL # define fp_log logl # endif @@ -785,14 +790,13 @@ PRIVATE inline uae_u32 FFPU get_quotient_sign(fpu_register const & ra, fpu_regis # define fp_ceil ceil #endif -#if defined(FPU_IEEE) && defined(USE_X87_ASSEMBLY) +#elif defined(FPU_IEEE) && defined(USE_X87_ASSEMBLY) // Assembly optimized support functions. Taken from glibc 2.2.2 #undef fp_log #define fp_log fp_do_log -#ifndef FPU_FAST_MATH -// FIXME: unimplemented +#if !FPU_FAST_MATH PRIVATE fpu_extended fp_do_log(fpu_extended x); #else PRIVATE inline fpu_extended fp_do_log(fpu_extended x) @@ -806,7 +810,7 @@ PRIVATE inline fpu_extended fp_do_log(fpu_extended x) #undef fp_log10 #define fp_log10 fp_do_log10 -#ifndef FPU_FAST_MATH +#if !FPU_FAST_MATH // FIXME: unimplemented PRIVATE fpu_extended fp_do_log10(fpu_extended x); #else @@ -821,7 +825,7 @@ PRIVATE inline fpu_extended fp_do_log10(fpu_extended x) #undef fp_exp #define fp_exp fp_do_exp -#ifndef FPU_FAST_MATH +#if !FPU_FAST_MATH // FIXME: unimplemented PRIVATE fpu_extended fp_do_exp(fpu_extended x); #else @@ -940,7 +944,7 @@ PRIVATE inline fpu_extended fp_do_sgn1(fpu_extended x) #undef fp_sinh #define fp_sinh fp_do_sinh -#ifndef FPU_FAST_MATH +#if !FPU_FAST_MATH // FIXME: unimplemented PRIVATE fpu_extended fp_do_sinh(fpu_extended x); #else @@ -954,7 +958,7 @@ PRIVATE inline fpu_extended fp_do_sinh(fpu_extended x) #undef fp_cosh #define fp_cosh fp_do_cosh -#ifndef FPU_FAST_MATH +#if !FPU_FAST_MATH // FIXME: unimplemented PRIVATE fpu_extended fp_do_cosh(fpu_extended x); #else @@ -968,7 +972,7 @@ PRIVATE inline fpu_extended fp_do_cosh(fpu_extended x) #undef fp_tanh #define fp_tanh fp_do_tanh -#ifndef FPU_FAST_MATH +#if !FPU_FAST_MATH // FIXME: unimplemented PRIVATE fpu_extended fp_do_tanh(fpu_extended x); #else From 8b4dc6ea812e10f9e4d0d7d46663fb0e550c7036 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:25:15 -0700 Subject: [PATCH 06/19] gencpu builds cleanly on MSVC. Fixed nasty bitfield issue where MSVC enums are signed, so a two-bit bitfield set to 2 is later read as -2. --- BasiliskII/src/uae_cpu/gencpu.c | 32 ++++++++++++++++++++++++------ BasiliskII/src/uae_cpu/m68k.h | 4 ++-- BasiliskII/src/uae_cpu/newcpu.cpp | 10 +++++----- BasiliskII/src/uae_cpu/readcpu.cpp | 6 +++--- BasiliskII/src/uae_cpu/readcpu.h | 6 +++--- BasiliskII/src/uae_cpu/spcflags.h | 2 +- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/BasiliskII/src/uae_cpu/gencpu.c b/BasiliskII/src/uae_cpu/gencpu.c index 43566a04..1653adab 100644 --- a/BasiliskII/src/uae_cpu/gencpu.c +++ b/BasiliskII/src/uae_cpu/gencpu.c @@ -1199,10 +1199,10 @@ static void gen_opcode (unsigned long int opcode) curi->size == sz_word ? sz_word : sz_long, "src"); break; case i_MVMEL: - genmovemel (opcode); + genmovemel ((uae_u16)opcode); break; case i_MVMLE: - genmovemle (opcode); + genmovemle ((uae_u16)opcode); break; case i_TRAP: genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); @@ -1523,7 +1523,7 @@ static void gen_opcode (unsigned long int opcode) printf ("\tcnt &= 63;\n"); printf ("\tCLEAR_CZNV;\n"); printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); - printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size)); + printf ("\t\tval = %s & (uae_u32)-(uae_s32)sign;\n", bit_mask (curi->size)); printf ("\t\tSET_CFLG (sign);\n"); duplicate_carry (); if (source_is_imm1_8 (curi)) @@ -1534,7 +1534,7 @@ static void gen_opcode (unsigned long int opcode) printf ("\t\tSET_CFLG (val & 1);\n"); duplicate_carry (); printf ("\t\tval >>= 1;\n"); - printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n", + printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-(uae_s32)sign;\n", bit_mask (curi->size), bit_size (curi->size)); printf ("\t\tval &= %s;\n", bit_mask (curi->size)); @@ -2286,7 +2286,7 @@ static void generate_one_opcode (int rp) const char *opcode_str; if (table68k[opcode].mnemo == i_ILLG - || table68k[opcode].clev > cpu_level) + || table68k[opcode].clev > (unsigned)cpu_level) return; if (table68k[opcode].handler != -1) @@ -2475,10 +2475,16 @@ static void generate_func (void) postfix = i; fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix); + /* Disable spurious warnings. */ + printf ("\n" + "#ifdef _MSC_VER\n" + "#pragma warning(disable:4102) /* unreferenced label */\n" + "#endif\n"); + /* sam: this is for people with low memory (eg. me :)) */ printf ("\n" "#if !defined(PART_1) && !defined(PART_2) && " - "!defined(PART_3) && !defined(PART_4) && " + "!defined(PART_3) && !defined(PART_4) && " "!defined(PART_5) && !defined(PART_6) && " "!defined(PART_7) && !defined(PART_8)" "\n" @@ -2534,5 +2540,19 @@ int main (int argc, char **argv) fclose (headerfile); fclose (stblfile); fflush (out); + + /* For build systems (IDEs mainly) that don't make it easy to compile the + * same file twice with different settings. */ + stblfile = fopen ("cpustbl_nf.cpp", "w"); + out = freopen ("cpuemu_nf.cpp", "w", stdout); + + fprintf (stblfile, "#define NOFLAGS\n"); + fprintf (stblfile, "#include \"cpustbl.cpp\"\n"); + fclose (stblfile); + + printf ("#define NOFLAGS\n"); + printf ("#include \"cpuemu.cpp\"\n"); + fflush (out); + return 0; } diff --git a/BasiliskII/src/uae_cpu/m68k.h b/BasiliskII/src/uae_cpu/m68k.h index 75063082..f329cb3e 100644 --- a/BasiliskII/src/uae_cpu/m68k.h +++ b/BasiliskII/src/uae_cpu/m68k.h @@ -25,7 +25,7 @@ #ifdef OPTIMIZED_FLAGS -#if (defined(__i386__) && defined(X86_ASSEMBLY)) || (defined(__x86_64__) && defined(X86_64_ASSEMBLY)) +#if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) || defined(MSVC_INTRINSICS) #ifndef SAHF_SETO_PROFITABLE @@ -352,7 +352,7 @@ static __inline__ int cctrue(int cc) #endif -#elif defined(__sparc__) && (defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)) +#elif defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY) struct flag_struct { unsigned char nzvc; diff --git a/BasiliskII/src/uae_cpu/newcpu.cpp b/BasiliskII/src/uae_cpu/newcpu.cpp index 02750879..4e45817b 100644 --- a/BasiliskII/src/uae_cpu/newcpu.cpp +++ b/BasiliskII/src/uae_cpu/newcpu.cpp @@ -211,7 +211,7 @@ static void build_cpufunctbl (void) { int i; unsigned long opcode; - int cpu_level = 0; // 68000 (default) + unsigned int cpu_level = 0; // 68000 (default) if (CPUType == 4) cpu_level = 4; // 68040 with FPU else { @@ -979,8 +979,8 @@ void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc) SET_CFLG (0); SET_ZFLG (((uae_s32)quot) == 0); SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg(regs, extra & 7) = rem; - m68k_dreg(regs, (extra >> 12) & 7) = quot; + m68k_dreg(regs, extra & 7) = (uae_u32)rem; + m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)quot; } } else { /* unsigned */ @@ -1002,8 +1002,8 @@ void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc) SET_CFLG (0); SET_ZFLG (((uae_s32)quot) == 0); SET_NFLG (((uae_s32)quot) < 0); - m68k_dreg(regs, extra & 7) = rem; - m68k_dreg(regs, (extra >> 12) & 7) = quot; + m68k_dreg(regs, extra & 7) = (uae_u32)rem; + m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)quot; } } #else diff --git a/BasiliskII/src/uae_cpu/readcpu.cpp b/BasiliskII/src/uae_cpu/readcpu.cpp index 6b0c64dd..3fccdfb7 100644 --- a/BasiliskII/src/uae_cpu/readcpu.cpp +++ b/BasiliskII/src/uae_cpu/readcpu.cpp @@ -869,7 +869,7 @@ static void handle_merges (long int opcode) } for (srcreg=0; srcreg < sbitdst; srcreg++) { for (dstreg=0; dstreg < dstend; dstreg++) { - uae_u16 code = opcode; + uae_u16 code = uae_u16(opcode); code = (code & ~smsk) | (srcreg << table68k[opcode].spos); code = (code & ~dmsk) | (dstreg << table68k[opcode].dpos); @@ -1023,11 +1023,11 @@ const char *get_instruction_string (unsigned int opcode) strcat (out,".L"); strcat (out," "); if (ins->suse) - strcat (out, get_ea_string (ins->smode, ins->size)); + strcat (out, get_ea_string (amodes(ins->smode), wordsizes(ins->size))); if (ins->duse) { if (ins->suse) strcat (out,","); - strcat (out, get_ea_string (ins->dmode, ins->size)); + strcat (out, get_ea_string (amodes(ins->dmode), wordsizes(ins->size))); } return out; } diff --git a/BasiliskII/src/uae_cpu/readcpu.h b/BasiliskII/src/uae_cpu/readcpu.h index 1e2c30ac..6fba3c39 100644 --- a/BasiliskII/src/uae_cpu/readcpu.h +++ b/BasiliskII/src/uae_cpu/readcpu.h @@ -103,10 +103,10 @@ extern struct instr { unsigned int mnemo:8; unsigned int cc:4; unsigned int plev:2; - wordsizes size:2; - amodes smode:5; + unsigned int size:2; + unsigned int smode:5; unsigned int stype:3; - amodes dmode:5; + unsigned int dmode:5; unsigned int suse:1; unsigned int duse:1; unsigned int unused1:1; diff --git a/BasiliskII/src/uae_cpu/spcflags.h b/BasiliskII/src/uae_cpu/spcflags.h index 9796a8cc..3c3fc032 100644 --- a/BasiliskII/src/uae_cpu/spcflags.h +++ b/BasiliskII/src/uae_cpu/spcflags.h @@ -71,7 +71,7 @@ enum { regs.spcflags &= ~(m); \ } while (0) -#elif (defined(__i386__) || defined(__x86_64__)) && defined(X86_ASSEMBLY) +#elif defined(X86_ASSEMBLY) #define HAVE_HARDWARE_LOCKS From 73f3af6c3b93131bdcc3ca5cb24ab113cf450d7e Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:28:01 -0700 Subject: [PATCH 07/19] gencomp builds cleanly (and produces clean-building code) on MSVC. --- .../src/uae_cpu/compiler/codegen_x86.cpp | 14 ++++--- BasiliskII/src/uae_cpu/compiler/codegen_x86.h | 6 +-- .../src/uae_cpu/compiler/compemu_support.cpp | 25 +++++------ BasiliskII/src/uae_cpu/compiler/gencomp.c | 42 +++++++++---------- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/BasiliskII/src/uae_cpu/compiler/codegen_x86.cpp b/BasiliskII/src/uae_cpu/compiler/codegen_x86.cpp index 4885e083..f03c4f3c 100644 --- a/BasiliskII/src/uae_cpu/compiler/codegen_x86.cpp +++ b/BasiliskII/src/uae_cpu/compiler/codegen_x86.cpp @@ -62,7 +62,7 @@ #define REG_RESULT EAX_INDEX /* The registers subroutines take their first and second argument in */ -#if defined( _MSC_VER ) && !defined( USE_NORMAL_CALLING_CONVENTION ) +#if defined( _MSC_VER ) && !USE_NORMAL_CALLING_CONVENTION /* Handle the _fastcall parameters of ECX and EDX */ #define REG_PAR1 ECX_INDEX #define REG_PAR2 EDX_INDEX @@ -75,7 +75,7 @@ #endif #define REG_PC_PRE EAX_INDEX /* The register we use for preloading regs.pc_p */ -#if defined( _MSC_VER ) && !defined( USE_NORMAL_CALLING_CONVENTION ) +#if defined( _MSC_VER ) && !USE_NORMAL_CALLING_CONVENTION #define REG_PC_TMP EAX_INDEX #else #define REG_PC_TMP ECX_INDEX /* Another register that is not the above */ @@ -3982,7 +3982,7 @@ raw_init_cpu(void) } /* Have CMOV support? */ - have_cmov = c->x86_hwcap & (1 << 15); + have_cmov = (c->x86_hwcap & (1 << 15)) != 0; #if defined(__x86_64__) if (!have_cmov) { write_log("x86-64 implementations are bound to have CMOV!\n"); @@ -4023,8 +4023,14 @@ static bool target_check_bsf(void) for (int value = -1; value <= 1; value++) { unsigned long flags = (g_SF << 7) | (g_OF << 11) | (g_ZF << 6) | g_CF; unsigned long tmp = value; +#ifdef _MSC_VER + __writeeflags(flags); + _BitScanForward(&tmp, value); + flags = __readeflags(); +#else __asm__ __volatile__ ("push %0; popf; bsf %1,%1; pushf; pop %0" : "+r" (flags), "+r" (tmp) : : "cc"); +#endif int OF = (flags >> 11) & 1; int SF = (flags >> 7) & 1; int ZF = (flags >> 6) & 1; @@ -4267,8 +4273,6 @@ LENDFUNC(NONE,WRITE,2,raw_fmov_ext_mr,(MEMW m, FR r)) LOWFUNC(NONE,WRITE,2,raw_fmov_ext_mr_drop,(MEMW m, FR r)) { - int rs; - make_tos(r); raw_fstpt(m); /* store and pop it */ live.onstack[live.tos]=-1; diff --git a/BasiliskII/src/uae_cpu/compiler/codegen_x86.h b/BasiliskII/src/uae_cpu/compiler/codegen_x86.h index febee58b..08538b7a 100644 --- a/BasiliskII/src/uae_cpu/compiler/codegen_x86.h +++ b/BasiliskII/src/uae_cpu/compiler/codegen_x86.h @@ -206,11 +206,11 @@ enum { #define _rC(R) ((R) & 0xf0) #define _rR(R) ((R) & 0x0f) #define _rN(R) ((R) & 0x07) -#define _rXP(R) ((R) > 0 && _rR(R) > 7) +#define _rXP(R) (((R) > 0 && _rR(R) > 7) ? 1 : 0) #else #define _rN(R) ((R) & 0x07) #define _rR(R) (int(R)) -#define _rXP(R) (_rR(R) > 7 && _rR(R) < 16) +#define _rXP(R) ((_rR(R) > 7 && _rR(R) < 16) ? 1 : 0) #endif #if !defined(_ASM_SAFETY) || ! X86_FLAT_REGISTERS @@ -495,7 +495,7 @@ typedef unsigned int _ul; /* --- REX prefixes -------------------------------------------------------- */ #define _VOID() ((void)0) -#define _BIT(X) (!!(X)) +#define _BIT(X) ((X) ? 1 : 0) #define _d64(W,R,X,B) (_B(0x40|(W)<<3|(R)<<2|(X)<<1|(B))) #define __REXwrxb(L,W,R,X,B) ((W|R|X|B) || (L) ? _d64(W,R,X,B) : _VOID()) diff --git a/BasiliskII/src/uae_cpu/compiler/compemu_support.cpp b/BasiliskII/src/uae_cpu/compiler/compemu_support.cpp index 2448d3da..f31febce 100644 --- a/BasiliskII/src/uae_cpu/compiler/compemu_support.cpp +++ b/BasiliskII/src/uae_cpu/compiler/compemu_support.cpp @@ -23,6 +23,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "sysdeps.h" + #if !REAL_ADDRESSING && !DIRECT_ADDRESSING #error "Only Real or Direct Addressing is supported with the JIT Compiler" #endif @@ -43,7 +45,7 @@ #define USE_MATCH 0 /* kludge for Brian, so he can compile under MSVC++ */ -#define USE_NORMAL_CALLING_CONVENTION 0 +#define USE_NORMAL_CALLING_CONVENTION 1 && defined(_MSC_VER) #ifndef WIN32 #include @@ -55,7 +57,6 @@ #include #include -#include "sysdeps.h" #include "cpu_emulation.h" #include "main.h" #include "prefs.h" @@ -192,7 +193,7 @@ static inline bool is_const_jump(uae_u32 opcode) static inline bool may_trap(uae_u32 opcode) { - return (prop[opcode].cflow & fl_trap); + return (prop[opcode].cflow & fl_trap) != 0; } static inline unsigned int cft_map (unsigned int f) @@ -958,7 +959,7 @@ static void ru_fill(regusage *ru, uae_u32 opcode) bool handled = false; /* Handle some instructions specifically */ - uae_u16 reg, ext; + uae_u16 ext; switch (dp->mnemo) { case i_BFCHG: case i_BFCLR: @@ -1565,7 +1566,6 @@ static void mov_nregs(int d, int s) static __inline__ void make_exclusive(int r, int size, int spec) { - int clobber; reg_status oldstate; int rr=live.state[r].realreg; int nr; @@ -1642,7 +1642,6 @@ static __inline__ void add_offset(int r, uae_u32 off) static __inline__ void remove_offset(int r, int spec) { - reg_status oldstate; int rr; if (isconst(r)) @@ -5255,7 +5254,7 @@ void init_comp(void) /* Only do this if you really mean it! The next call should be to init!*/ void flush(int save_regs) { - int fi,i; + int i; log_flush(); flush_flags(); /* low level */ @@ -5308,7 +5307,7 @@ void flush(int save_regs) static void flush_keepflags(void) { - int fi,i; + int i; for (i=0;i= (uintptr)ROMBaseHost) && (addr < (uintptr)ROMBaseHost + ROMSize)); } @@ -5808,7 +5807,7 @@ static void show_checksum(CSI_TYPE* csi) uae_u32 k1=0; uae_u32 k2=0; uae_s32 len=CSI_LENGTH(csi); - uae_u32 tmp=(uintptr)CSI_START_P(csi); + uae_u32 tmp=(uintptr)CSI_STARTcsi uae_u32* pos; len+=(tmp&3); @@ -5902,7 +5901,7 @@ static inline int block_check_checksum(blockinfo* bi) bi->handler_to_use=bi->handler; set_dhtu(bi,bi->direct_handler); bi->status=BI_CHECKING; - isgood=called_check_checksum(bi); + isgood=called_check_checksum(bi) != 0; } if (isgood) { /* write_log("reactivate %p/%p (%x %x/%x %x)\n",bi,bi->pc_p, @@ -6219,7 +6218,7 @@ void build_comp(void) struct comptbl* tbl=op_smalltbl_0_comp_ff; struct comptbl* nftbl=op_smalltbl_0_comp_nf; int count; - int cpu_level = 0; // 68000 (default) + unsigned int cpu_level = 0; // 68000 (default) if (CPUType == 4) cpu_level = 4; // 68040 with FPU else { @@ -6356,7 +6355,6 @@ static void flush_icache_none(int n) static void flush_icache_hard(int n) { - uae_u32 i; blockinfo* bi, *dbi; hard_flush_count++; @@ -6394,7 +6392,6 @@ static void flush_icache_hard(int n) static inline void flush_icache_lazy(int n) { - uae_u32 i; blockinfo* bi; blockinfo* bi2; diff --git a/BasiliskII/src/uae_cpu/compiler/gencomp.c b/BasiliskII/src/uae_cpu/compiler/gencomp.c index 6b47c062..2e16972d 100644 --- a/BasiliskII/src/uae_cpu/compiler/gencomp.c +++ b/BasiliskII/src/uae_cpu/compiler/gencomp.c @@ -30,7 +30,7 @@ #include #include #include "sysdeps.h" -#include "readcpu.h" +#include "../readcpu.h" #define BOOL_TYPE "int" #define failure global_failure=1 @@ -86,7 +86,7 @@ static FILE *stblfile; static int using_prefetch; static int using_exception_3; -static int cpu_level; +static unsigned int cpu_level; static int noflags; /* For the current opcode, the next lower level that will have different code. @@ -508,7 +508,6 @@ genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int move /* We now might have to fix up the register for pre-dec or post-inc * addressing modes. */ if (!movem) { - char x[160]; switch (mode) { case Aipi: @@ -1510,10 +1509,10 @@ gen_opcode (unsigned long int opcode) curi->size == sz_word ? sz_word : sz_long, "src"); break; case i_MVMEL: - genmovemel (opcode); + genmovemel ((uae_u16)opcode); break; case i_MVMLE: - genmovemle (opcode); + genmovemle ((uae_u16)opcode); break; case i_TRAP: isjump; @@ -1636,7 +1635,6 @@ gen_opcode (unsigned long int opcode) comprintf("\tcomp_pc_p=(uae_u8*)get_const(PC_P);\n"); break; case i_Bcc: - comprintf("\tuae_u32 v,v1,v2;\n"); genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); /* That source is an immediate, so we can clobber it with abandon */ switch(curi->size) { @@ -1655,8 +1653,8 @@ gen_opcode (unsigned long int opcode) comprintf("\tm68k_pc_offset=0;\n"); if (curi->cc>=2) { - comprintf("\tv1=get_const(PC_P);\n" - "\tv2=get_const(src);\n" + comprintf("\tuae_u32 v1=get_const(PC_P);\n" + "\tuae_u32 v2=get_const(src);\n" "\tregister_branch(v1,v2,%d);\n", cond_codes_x86[curi->cc]); comprintf("\tmake_flags_live();\n"); /* Load the flags */ @@ -1749,9 +1747,8 @@ gen_opcode (unsigned long int opcode) comprintf("\tsub_w_ri(src,1);\n"); comprintf("\t end_needflags();\n"); start_brace(); - comprintf("\tuae_u32 v2,v;\n" - "\tuae_u32 v1=get_const(PC_P);\n"); - comprintf("\tv2=get_const(offs);\n" + comprintf("\tuae_u32 v1=get_const(PC_P);\n"); + comprintf("\tuae_u32 v2=get_const(offs);\n" "\tregister_branch(v1,v2,3);\n"); break; @@ -1894,7 +1891,6 @@ gen_opcode (unsigned long int opcode) uses_cmov; start_brace(); comprintf("\tint highmask;\n" - "\tint width;\n" "\tint cdata=scratchie++;\n" "\tint sdata=scratchie++;\n" "\tint tmpcnt=scratchie++;\n"); @@ -2991,7 +2987,7 @@ generate_func (int noflags) /* sam: this is for people with low memory (eg. me :)) */ - !printf ("\n" + printf ("\n" "#if !defined(PART_1) && !defined(PART_2) && " "!defined(PART_3) && !defined(PART_4) && " "!defined(PART_5) && !defined(PART_6) && " @@ -3050,10 +3046,10 @@ main (int argc, char **argv) noflags=0; generate_func (noflags); - free(opcode_map); - free(opcode_last_postfix); - free(opcode_next_clev); - free(counts); + free(opcode_map); + free(opcode_last_postfix); + free(opcode_next_clev); + free(counts); opcode_map = (int *) malloc (sizeof (int) * nr_cpuop_funcs); opcode_last_postfix = (int *) malloc (sizeof (int) * nr_cpuop_funcs); @@ -3063,14 +3059,14 @@ main (int argc, char **argv) noflags=1; generate_func (noflags); - free(opcode_map); - free(opcode_last_postfix); - free(opcode_next_clev); - free(counts); + free(opcode_map); + free(opcode_last_postfix); + free(opcode_next_clev); + free(counts); free (table68k); - fclose (stblfile); - fclose (headerfile); + fclose (stblfile); + fclose (headerfile); fflush (stdout); return 0; } From 1d875960dbc21ff8f7ced1ee8e963d7e3eb07caf Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:31:26 -0700 Subject: [PATCH 08/19] Propagate error information from set_gamma_table. --- BasiliskII/src/include/video.h | 2 +- BasiliskII/src/video.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BasiliskII/src/include/video.h b/BasiliskII/src/include/video.h index 4459a09a..78526e67 100644 --- a/BasiliskII/src/include/video.h +++ b/BasiliskII/src/include/video.h @@ -209,7 +209,7 @@ private: bool allocate_gamma_table(int size); // Set gamma table (0 = build linear ramp) - bool set_gamma_table(uint32 user_table); + int16 set_gamma_table(uint32 user_table); // Switch video mode void switch_mode(vector::const_iterator it, uint32 param, uint32 dce); diff --git a/BasiliskII/src/video.cpp b/BasiliskII/src/video.cpp index 8204c40e..8f84f48d 100644 --- a/BasiliskII/src/video.cpp +++ b/BasiliskII/src/video.cpp @@ -290,7 +290,7 @@ bool monitor_desc::allocate_gamma_table(int size) * Set gamma table (0 = build linear ramp) */ -bool monitor_desc::set_gamma_table(uint32 user_table) +int16 monitor_desc::set_gamma_table(uint32 user_table) { if (user_table == 0) { // Build linear ramp, 256 entries @@ -340,7 +340,7 @@ bool monitor_desc::set_gamma_table(uint32 user_table) if (IsDirectMode(*current_mode)) load_ramp_palette(); - return true; + return noErr; } @@ -590,7 +590,7 @@ int16 monitor_desc::driver_control(uint16 code, uint32 param, uint32 dce) case cscSetGamma: { // Set gamma table uint32 user_table = ReadMacInt32(param + csGTable); D(bug(" SetGamma %08x\n", user_table)); - return set_gamma_table(user_table) ? noErr : memFullErr; + return set_gamma_table(user_table); } case cscGrayPage: { // Fill page with dithered gray pattern @@ -627,7 +627,7 @@ int16 monitor_desc::driver_control(uint16 code, uint32 param, uint32 dce) case cscSetGray: // Enable/disable luminance mapping D(bug(" SetGray %02x\n", ReadMacInt8(param + csMode))); - luminance_mapping = ReadMacInt8(param + csMode); + luminance_mapping = ReadMacInt8(param + csMode) != 0; return noErr; case cscSetInterrupt: // Enable/disable VBL From f35cb736c7b85199641ad2100f2abd782bddb2a7 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:34:55 -0700 Subject: [PATCH 09/19] Changed type of audio_channel_counts; fixes type conversion warnings on MSVC. --- BasiliskII/src/audio.cpp | 6 +++--- BasiliskII/src/include/audio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BasiliskII/src/audio.cpp b/BasiliskII/src/audio.cpp index 0a8b8ff3..00a89996 100644 --- a/BasiliskII/src/audio.cpp +++ b/BasiliskII/src/audio.cpp @@ -39,7 +39,7 @@ // Supported sample rates, sizes and channels vector audio_sample_rates; vector audio_sample_sizes; -vector audio_channel_counts; +vector audio_channel_counts; // Global variables struct audio_status AudioStatus; // Current audio status (sample rate etc.) @@ -233,7 +233,7 @@ static int32 AudioSetInfo(uint32 infoPtr, uint32 selector, uint32 sourceID) return badChannel; case siSpeakerMute: - audio_set_speaker_mute((uint16)infoPtr); + audio_set_speaker_mute(uint16(infoPtr) != 0); break; case siSpeakerVolume: @@ -242,7 +242,7 @@ static int32 AudioSetInfo(uint32 infoPtr, uint32 selector, uint32 sourceID) break; case siHardwareMute: - audio_set_main_mute((uint16)infoPtr); + audio_set_main_mute(uint16(infoPtr) != 0); break; case siHardwareVolume: diff --git a/BasiliskII/src/include/audio.h b/BasiliskII/src/include/audio.h index e8ae480e..b875cc15 100644 --- a/BasiliskII/src/include/audio.h +++ b/BasiliskII/src/include/audio.h @@ -76,7 +76,7 @@ extern uint32 audio_component_flags; // Component feature flags extern vector audio_sample_rates; // Vector of supported sample rates (16.16 fixed point) extern vector audio_sample_sizes; // Vector of supported sample sizes -extern vector audio_channel_counts; // Array of supported channels counts +extern vector audio_channel_counts; // Array of supported channels counts // Audio component global data and 68k routines enum { From c92feaf7673b2c921de7e71c0d78d2b621acfdc9 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:37:58 -0700 Subject: [PATCH 10/19] Fixed a bunch of warnings in MSVC. --- BasiliskII/src/adb.cpp | 16 ++++++++-------- BasiliskII/src/cdrom.cpp | 6 +++--- BasiliskII/src/disk.cpp | 4 ++-- BasiliskII/src/emul_op.cpp | 2 +- BasiliskII/src/extfs.cpp | 4 ++-- BasiliskII/src/main.cpp | 2 +- BasiliskII/src/slot_rom.cpp | 16 ++++++++-------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/BasiliskII/src/adb.cpp b/BasiliskII/src/adb.cpp index 04514648..1d656935 100644 --- a/BasiliskII/src/adb.cpp +++ b/BasiliskII/src/adb.cpp @@ -349,7 +349,7 @@ void ADBInterrupt(void) if (relative_mouse) { // Mouse movement (relative) and buttons - if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { + if (mx != 0 || my != 0 || !!mb[0] != old_mouse_button[0] || !!mb[1] != old_mouse_button[1] || !!mb[2] != old_mouse_button[2]) { // Call mouse ADB handler if (mouse_reg_3[1] == 4) { @@ -371,9 +371,9 @@ void ADBInterrupt(void) r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 Execute68k(r.a[1], &r); - old_mouse_button[0] = mb[0]; - old_mouse_button[1] = mb[1]; - old_mouse_button[2] = mb[2]; + old_mouse_button[0] = mb[0] != 0; + old_mouse_button[1] = mb[1] != 0; + old_mouse_button[2] = mb[2] != 0; } } else { @@ -406,7 +406,7 @@ void ADBInterrupt(void) } // Send mouse button events - if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { + if (!!mb[0] != old_mouse_button[0] || !!mb[1] != old_mouse_button[1] || !!mb[2] != old_mouse_button[2]) { uint32 mouse_base = adb_base + 16; // Call mouse ADB handler @@ -429,9 +429,9 @@ void ADBInterrupt(void) r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 Execute68k(r.a[1], &r); - old_mouse_button[0] = mb[0]; - old_mouse_button[1] = mb[1]; - old_mouse_button[2] = mb[2]; + old_mouse_button[0] = mb[0] != 0; + old_mouse_button[1] = mb[1] != 0; + old_mouse_button[2] = mb[2] != 0; } } diff --git a/BasiliskII/src/cdrom.cpp b/BasiliskII/src/cdrom.cpp index 9f9c00ec..370322d1 100644 --- a/BasiliskII/src/cdrom.cpp +++ b/BasiliskII/src/cdrom.cpp @@ -557,7 +557,7 @@ int16 CDROMControl(uint32 pb, uint32 dce) } case 76: // ModifyPostEvent - info->mount_non_hfs = ReadMacInt16(pb + csParam); + info->mount_non_hfs = ReadMacInt16(pb + csParam) != 0; return noErr; case 79: { // Change block size @@ -792,7 +792,7 @@ int16 CDROMControl(uint32 pb, uint32 dce) if (!position2msf(*info, ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), false, start_m, start_s, start_f)) return paramErr; - if (!SysCDScan(info->fh, start_m, start_s, start_f, ReadMacInt16(pb + csParam + 6))) { + if (!SysCDScan(info->fh, start_m, start_s, start_f, ReadMacInt16(pb + csParam + 6) != 0)) { return paramErr; } else { return noErr; @@ -944,7 +944,7 @@ int16 CDROMStatus(uint32 pb, uint32 dce) if (ReadMacInt16(pb + csParam) > 0) { uint32 adr = ReadMacInt32(pb + csParam + 2); WriteMacInt16(pb + csParam, 1); // 1 format - WriteMacInt32(adr, SysGetFileSize(info->fh) / 512); // Number of blocks + WriteMacInt32(adr, uint32(SysGetFileSize(info->fh) / 512)); // Number of blocks WriteMacInt32(adr + 4, 0); // heads/track/sectors return noErr; } else { diff --git a/BasiliskII/src/disk.cpp b/BasiliskII/src/disk.cpp index 48cd5407..6d8d6080 100644 --- a/BasiliskII/src/disk.cpp +++ b/BasiliskII/src/disk.cpp @@ -200,7 +200,7 @@ bool DiskMountVolume(void *fh) WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0xff : 0); find_hfs_partition(*info); if (info->start_byte == 0) - info->num_blocks = SysGetFileSize(info->fh) / 512; + info->num_blocks = uint32(SysGetFileSize(info->fh) / 512); WriteMacInt16(info->status + dsDriveSize, info->num_blocks & 0xffff); WriteMacInt16(info->status + dsDriveS1, info->num_blocks >> 16); info->to_be_mounted = true; @@ -288,7 +288,7 @@ int16 DiskOpen(uint32 pb, uint32 dce) WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0x80 : 0); find_hfs_partition(*info); if (info->start_byte == 0) - info->num_blocks = SysGetFileSize(info->fh) / 512; + info->num_blocks = uint32(SysGetFileSize(info->fh) / 512); info->to_be_mounted = true; } D(bug(" %d blocks\n", info->num_blocks)); diff --git a/BasiliskII/src/emul_op.cpp b/BasiliskII/src/emul_op.cpp index af5bb7dc..0f2b59fc 100644 --- a/BasiliskII/src/emul_op.cpp +++ b/BasiliskII/src/emul_op.cpp @@ -111,7 +111,7 @@ void EmulOp(uint16 opcode, M68kRegisters *r) } case M68K_EMUL_OP_CLKNOMEM: { // Clock/PRAM operations - bool is_read = r->d[1] & 0x80; + bool is_read = (r->d[1] & 0x80) != 0; if ((r->d[1] & 0x78) == 0x38) { // XPRAM uint8 reg = (r->d[1] << 5) & 0xe0 | (r->d[1] >> 10) & 0x1f; diff --git a/BasiliskII/src/extfs.cpp b/BasiliskII/src/extfs.cpp index 90ce8ae2..f6ac09f1 100644 --- a/BasiliskII/src/extfs.cpp +++ b/BasiliskII/src/extfs.cpp @@ -334,7 +334,7 @@ static void pstrcpy(char *dst, const char *src) // Convert C string to pascal string static void cstr2pstr(char *dst, const char *src) { - *dst++ = strlen(src); + *dst++ = char(strlen(src)); char c; while ((c = *src++) != 0) { // Note: we are converting host ':' characters to Mac '/' characters here @@ -2158,7 +2158,7 @@ static int16 fs_get_wd_info(uint32 pb, uint32 vcb) int16 ExtFSHFS(uint32 vcb, uint16 selectCode, uint32 paramBlock, uint32 globalsPtr, int16 fsid) { uint16 trapWord = selectCode & 0xf0ff; - bool hfs = selectCode & kHFSMask; + bool hfs = (selectCode & kHFSMask) != 0; switch (trapWord) { case kFSMOpen: return fs_open(paramBlock, hfs ? ReadMacInt32(paramBlock + ioDirID) : 0, vcb, false); diff --git a/BasiliskII/src/main.cpp b/BasiliskII/src/main.cpp index 9455d387..dcb86e9c 100644 --- a/BasiliskII/src/main.cpp +++ b/BasiliskII/src/main.cpp @@ -177,7 +177,7 @@ bool InitAll(const char *vmdir) XPRAM[0x56] = 0x42; // 'B' XPRAM[0x57] = 0x32; // '2' const monitor_desc &main_monitor = *VideoMonitors[0]; - XPRAM[0x58] = main_monitor.depth_to_apple_mode(main_monitor.get_current_mode().depth); + XPRAM[0x58] = uint8(main_monitor.depth_to_apple_mode(main_monitor.get_current_mode().depth)); XPRAM[0x59] = 0; #if EMULATED_68K diff --git a/BasiliskII/src/slot_rom.cpp b/BasiliskII/src/slot_rom.cpp index 25ea0844..d46d0329 100644 --- a/BasiliskII/src/slot_rom.cpp +++ b/BasiliskII/src/slot_rom.cpp @@ -86,7 +86,7 @@ static void Long(uint32 data) static void Word(uint16 data) { srom[p++] = data >> 8; - srom[p++] = data; + srom[p++] = uint8(data); } static void String(const char *str) @@ -98,7 +98,7 @@ static void String(const char *str) static void PString(const char *str) { - srom[p++] = strlen(str); + srom[p++] = uint8(strlen(str)); while ((srom[p++] = *str++) != 0) ; p--; if (p & 1) @@ -211,17 +211,17 @@ static uint32 VMonitor(const monitor_desc &m, uint32 videoType, uint32 videoName Offs(0x40, gammaDir); // Gamma directory Rsrc(0x7d, 6); // Video attributes: Default to color, built-in if (m.has_depth(VDEPTH_1BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_1BIT), vidMode1); // Video mode parameters for 1 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_1BIT)), vidMode1); // Video mode parameters for 1 bit if (m.has_depth(VDEPTH_2BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_2BIT), vidMode2); // Video mode parameters for 2 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_2BIT)), vidMode2); // Video mode parameters for 2 bit if (m.has_depth(VDEPTH_4BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_4BIT), vidMode4); // Video mode parameters for 4 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_4BIT)), vidMode4); // Video mode parameters for 4 bit if (m.has_depth(VDEPTH_8BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_8BIT), vidMode8); // Video mode parameters for 8 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_8BIT)), vidMode8); // Video mode parameters for 8 bit if (m.has_depth(VDEPTH_16BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_16BIT), vidMode16); // Video mode parameters for 16 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_16BIT)), vidMode16); // Video mode parameters for 16 bit if (m.has_depth(VDEPTH_32BIT)) - Offs(m.depth_to_apple_mode(VDEPTH_32BIT), vidMode32); // Video mode parameters for 32 bit + Offs(uint8(m.depth_to_apple_mode(VDEPTH_32BIT)), vidMode32); // Video mode parameters for 32 bit EndOfList(); return ret; } From 284900f905f480d089d166e9c57c79d29b577790 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:53:29 -0700 Subject: [PATCH 11/19] Moved cross-platform sources into their own directory so that Windows builds don't need to add Unix to the include directory list. --- BasiliskII/src/{Unix => CrossPlatform}/sigsegv.cpp | 0 BasiliskII/src/{Unix => CrossPlatform}/sigsegv.h | 0 .../src/{Unix => CrossPlatform}/video_blit.cpp | 0 BasiliskII/src/{Unix => CrossPlatform}/video_blit.h | 0 BasiliskII/src/{Unix => CrossPlatform}/video_vosf.h | 0 BasiliskII/src/{Unix => CrossPlatform}/vm_alloc.cpp | 0 BasiliskII/src/{Unix => CrossPlatform}/vm_alloc.h | 0 BasiliskII/src/Unix/Makefile.in | 9 +++++---- BasiliskII/src/Windows/Makefile.in | 12 ++++++------ 9 files changed, 11 insertions(+), 10 deletions(-) rename BasiliskII/src/{Unix => CrossPlatform}/sigsegv.cpp (100%) rename BasiliskII/src/{Unix => CrossPlatform}/sigsegv.h (100%) rename BasiliskII/src/{Unix => CrossPlatform}/video_blit.cpp (100%) rename BasiliskII/src/{Unix => CrossPlatform}/video_blit.h (100%) rename BasiliskII/src/{Unix => CrossPlatform}/video_vosf.h (100%) rename BasiliskII/src/{Unix => CrossPlatform}/vm_alloc.cpp (100%) rename BasiliskII/src/{Unix => CrossPlatform}/vm_alloc.h (100%) diff --git a/BasiliskII/src/Unix/sigsegv.cpp b/BasiliskII/src/CrossPlatform/sigsegv.cpp similarity index 100% rename from BasiliskII/src/Unix/sigsegv.cpp rename to BasiliskII/src/CrossPlatform/sigsegv.cpp diff --git a/BasiliskII/src/Unix/sigsegv.h b/BasiliskII/src/CrossPlatform/sigsegv.h similarity index 100% rename from BasiliskII/src/Unix/sigsegv.h rename to BasiliskII/src/CrossPlatform/sigsegv.h diff --git a/BasiliskII/src/Unix/video_blit.cpp b/BasiliskII/src/CrossPlatform/video_blit.cpp similarity index 100% rename from BasiliskII/src/Unix/video_blit.cpp rename to BasiliskII/src/CrossPlatform/video_blit.cpp diff --git a/BasiliskII/src/Unix/video_blit.h b/BasiliskII/src/CrossPlatform/video_blit.h similarity index 100% rename from BasiliskII/src/Unix/video_blit.h rename to BasiliskII/src/CrossPlatform/video_blit.h diff --git a/BasiliskII/src/Unix/video_vosf.h b/BasiliskII/src/CrossPlatform/video_vosf.h similarity index 100% rename from BasiliskII/src/Unix/video_vosf.h rename to BasiliskII/src/CrossPlatform/video_vosf.h diff --git a/BasiliskII/src/Unix/vm_alloc.cpp b/BasiliskII/src/CrossPlatform/vm_alloc.cpp similarity index 100% rename from BasiliskII/src/Unix/vm_alloc.cpp rename to BasiliskII/src/CrossPlatform/vm_alloc.cpp diff --git a/BasiliskII/src/Unix/vm_alloc.h b/BasiliskII/src/CrossPlatform/vm_alloc.h similarity index 100% rename from BasiliskII/src/Unix/vm_alloc.h rename to BasiliskII/src/CrossPlatform/vm_alloc.h diff --git a/BasiliskII/src/Unix/Makefile.in b/BasiliskII/src/Unix/Makefile.in index ac3e258a..8ce51385 100644 --- a/BasiliskII/src/Unix/Makefile.in +++ b/BasiliskII/src/Unix/Makefile.in @@ -21,7 +21,7 @@ CFLAGS = @CFLAGS@ CXXFLAGS = @CXXFLAGS@ CPUINCLUDES_FLAGS=@CPUINCLUDES@ CPUINCLUDES_FLAGS:=$(CPUINCLUDES_FLAGS:-I%=-I@top_srcdir@/%) -CPPFLAGS = @CPPFLAGS@ -I@top_srcdir@/../include -I@top_srcdir@/. -I. $(CPUINCLUDES_FLAGS) -I@top_srcdir@/../slirp +CPPFLAGS = @CPPFLAGS@ -I@top_srcdir@/../include -I@top_srcdir@/. -I. -I@top_srcdir@/../CrossPlatform $(CPUINCLUDES_FLAGS) -I@top_srcdir@/../slirp DEFS = @DEFS@ @DEFINES@ -D_REENTRANT -DDATADIR=\"$(datadir)/$(APP)\" LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ @@ -43,17 +43,18 @@ GUI_LIBS = @GUI_LIBS@ GUI_SRCS = ../prefs.cpp prefs_unix.cpp prefs_editor_gtk.cpp ../prefs_items.cpp \ ../user_strings.cpp user_strings_unix.cpp xpram_unix.cpp sys_unix.cpp rpc_unix.cpp +XPLAT_SRCS = ../CrossPlatform/vm_alloc.cpp ../CrossPlatform/sigsegv.cpp ../CrossPlatform/video_blit.cpp + ## Files SRCS = ../main.cpp ../prefs.cpp ../prefs_items.cpp \ sys_unix.cpp ../rom_patches.cpp ../slot_rom.cpp ../rsrc_patches.cpp \ ../emul_op.cpp ../macos_util.cpp ../xpram.cpp xpram_unix.cpp ../timer.cpp \ timer_unix.cpp ../adb.cpp ../serial.cpp ../ether.cpp \ ../sony.cpp ../disk.cpp ../cdrom.cpp ../scsi.cpp ../video.cpp \ - video_blit.cpp \ - vm_alloc.cpp sigsegv.cpp ../audio.cpp ../extfs.cpp disk_sparsebundle.cpp \ + ../audio.cpp ../extfs.cpp disk_sparsebundle.cpp \ tinyxml2.cpp \ ../user_strings.cpp user_strings_unix.cpp sshpty.c strlcpy.c rpc_unix.cpp \ - $(SYSSRCS) $(CPUSRCS) $(SLIRP_SRCS) + $(XPLAT_SRCS) $(SYSSRCS) $(CPUSRCS) $(SLIRP_SRCS) APP_FLAVOR ?= ifneq ($(APP_FLAVOR),) CURR_APP_FLAVOR := -$(APP_FLAVOR) diff --git a/BasiliskII/src/Windows/Makefile.in b/BasiliskII/src/Windows/Makefile.in index 5bb0acfa..2214d868 100755 --- a/BasiliskII/src/Windows/Makefile.in +++ b/BasiliskII/src/Windows/Makefile.in @@ -37,7 +37,7 @@ CC = @CC@ CXX = @CXX@ CFLAGS = @CFLAGS@ $(SDL_CFLAGS) CXXFLAGS = @CXXFLAGS@ $(SDL_CFLAGS) -CPPFLAGS = @CPPFLAGS@ -I../include -I. @CPUINCLUDES@ -I../slirp +CPPFLAGS = @CPPFLAGS@ -I../include -I. -I../CrossPlatform @CPUINCLUDES@ -I../slirp DEFS = @DEFS@ @DEFINES@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -lwsock32 -liphlpapi @@ -50,7 +50,7 @@ HOST_CXXFLAGS = -O2 HOST_LDFLAGS = ## Files -UNIXSRCS = vm_alloc.cpp vm_alloc.h sigsegv.cpp sigsegv.h video_vosf.h video_blit.cpp video_blit.h +XPLATSRCS = vm_alloc.cpp vm_alloc.h sigsegv.cpp sigsegv.h video_vosf.h video_blit.cpp video_blit.h CDENABLESRCS = cdenable/cache.cpp cdenable/eject_nt.cpp cdenable/ntcd.cpp @@ -91,7 +91,7 @@ endif all: $(PROGS) -$(UNIXSRCS): %: ../Unix/% +$(XPLATSRCS): %: ../CrossPlatform/% $(LN_S) $< $@ OBJ_DIR = obj @@ -114,17 +114,17 @@ SRC_PATHS += $(sort $(foreach file, $(SRCS), $(dir $(file)))) VPATH := VPATH += $(addprefix :, $(subst ,:, $(filter-out $($(subst, :, ,$(VPATH))), $(SRC_PATHS)))) -$(APP): $(UNIXSRCS) $(OBJ_DIR) $(OBJS) +$(APP): $(XPLATSRCS) $(OBJ_DIR) $(OBJS) $(CXX) -o $@ $(LDFLAGS) $(OBJS) $(LIBS) $(SDL_LIBS) -$(UI_APP): $(UNIXSRCS) $(OBJ_DIR) $(UI_OBJS) +$(UI_APP): $(XPLATSRCS) $(OBJ_DIR) $(UI_OBJS) $(CXX) -o $@ $(LDFLAGS) $(UI_OBJS) $(LIBS) $(GTK_LIBS) -mwindows -mno-cygwin mostlyclean: rm -f $(APP) $(UI_APP) $(OBJ_DIR)/* core* *.core *~ *.bak clean: mostlyclean - rm -f $(UNIXSRCS) + rm -f $(XPLATSRCS) rm -f cpuemu.cpp cpudefs.cpp cputmp*.s cpufast*.s cpustbl.cpp cputbl.h compemu.cpp compstbl.cpp comptbl.h distclean: clean From 49f33770ac01d0eab02bc72880059bb4b3d2f444 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 01:57:13 -0700 Subject: [PATCH 12/19] Resolved numerous MSVC warnings. --- BasiliskII/src/CrossPlatform/sigsegv.cpp | 2 +- BasiliskII/src/CrossPlatform/sigsegv.h | 2 +- BasiliskII/src/CrossPlatform/video_vosf.h | 78 ++++++++++++----------- BasiliskII/src/CrossPlatform/vm_alloc.cpp | 2 +- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/BasiliskII/src/CrossPlatform/sigsegv.cpp b/BasiliskII/src/CrossPlatform/sigsegv.cpp index fcc857bf..d83b7536 100644 --- a/BasiliskII/src/CrossPlatform/sigsegv.cpp +++ b/BasiliskII/src/CrossPlatform/sigsegv.cpp @@ -746,7 +746,7 @@ handleExceptions(void *priv) #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION // Decode and skip X86 instruction -#if (defined(i386) || defined(__i386__)) || (defined(__x86_64__) || defined(_M_X64)) +#if (defined(i386) || defined(__i386__) || defined(_M_IX86)) || (defined(__x86_64__) || defined(_M_X64)) #if defined(__linux__) enum { #if (defined(i386) || defined(__i386__)) diff --git a/BasiliskII/src/CrossPlatform/sigsegv.h b/BasiliskII/src/CrossPlatform/sigsegv.h index 4f97668d..d95ca834 100644 --- a/BasiliskII/src/CrossPlatform/sigsegv.h +++ b/BasiliskII/src/CrossPlatform/sigsegv.h @@ -162,6 +162,6 @@ extern sigsegv_address_t sigsegv_get_fault_address(sigsegv_info_t *sip); extern sigsegv_address_t sigsegv_get_fault_instruction_address(sigsegv_info_t *sip); // Define an address that is bound to be invalid for a program counter -const sigsegv_address_t SIGSEGV_INVALID_ADDRESS = (sigsegv_address_t)(-1UL); +const sigsegv_address_t SIGSEGV_INVALID_ADDRESS = sigsegv_address_t(-1); #endif /* SIGSEGV_H */ diff --git a/BasiliskII/src/CrossPlatform/video_vosf.h b/BasiliskII/src/CrossPlatform/video_vosf.h index 0fe0a172..4a5677e1 100644 --- a/BasiliskII/src/CrossPlatform/video_vosf.h +++ b/BasiliskII/src/CrossPlatform/video_vosf.h @@ -73,13 +73,13 @@ // Prototypes static void vosf_do_set_dirty_area(uintptr first, uintptr last); -static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int screen_height, int bytes_per_row); +static void vosf_set_dirty_area(int x, int y, int w, int h, unsigned screen_width, unsigned screen_height, unsigned bytes_per_row); // Variables for Video on SEGV support static uint8 *the_host_buffer; // Host frame buffer in VOSF mode struct ScreenPageInfo { - int top, bottom; // Mapping between this virtual page and Mac scanlines + unsigned top, bottom; // Mapping between this virtual page and Mac scanlines }; struct ScreenInfo { @@ -148,7 +148,7 @@ static ScreenInfo mainBuffer; // provides a really fast strchr() implementation //#define HAVE_FAST_STRCHR 0 -static inline int find_next_page_set(int page) +static inline unsigned find_next_page_set(unsigned page) { #if HAVE_FAST_STRCHR char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE); @@ -162,7 +162,7 @@ static inline int find_next_page_set(int page) #endif } -static inline int find_next_page_clear(int page) +static inline unsigned find_next_page_clear(unsigned page) { #if HAVE_FAST_STRCHR char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE); @@ -235,17 +235,16 @@ static bool video_vosf_profitable(uint32 *duration_p = NULL, uint32 *n_page_faul const bool accel = false; #endif - for (int i = 0; i < n_tries; i++) { + for (uint32 i = 0; i < n_tries; i++) { uint64 start = GetTicks_usec(); - for (int p = 0; p < mainBuffer.pageCount; p++) { + for (uint32 p = 0; p < mainBuffer.pageCount; p++) { uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); if (accel) vosf_do_set_dirty_area((uintptr)addr, (uintptr)addr + mainBuffer.pageSize - 1); else addr[0] = 0; // Trigger Screen_fault_handler() } - uint64 elapsed = GetTicks_usec() - start; - duration += elapsed; + duration += uint32(GetTicks_usec() - start); PFLAG_CLEAR_ALL; mainBuffer.dirty = false; @@ -353,7 +352,7 @@ static void vosf_do_set_dirty_area(uintptr first, uintptr last) { const int first_page = (first - mainBuffer.memStart) >> mainBuffer.pageBits; const int last_page = (last - mainBuffer.memStart) >> mainBuffer.pageBits; - uint8 *addr = (uint8 *)(first & -mainBuffer.pageSize); + uint8 *addr = (uint8 *)(first & ~(mainBuffer.pageSize - 1)); for (int i = first_page; i <= last_page; i++) { if (PFLAG_ISCLEAR(i)) { PFLAG_SET(i); @@ -363,7 +362,7 @@ static void vosf_do_set_dirty_area(uintptr first, uintptr last) } } -static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int screen_height, int bytes_per_row) +static void vosf_set_dirty_area(int x, int y, int w, int h, unsigned screen_width, unsigned screen_height, unsigned bytes_per_row) { if (x < 0) { w -= -x; @@ -375,10 +374,10 @@ static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, in } if (w <= 0 || h <= 0) return; - if (x + w > screen_width) - w -= (x + w) - screen_width; - if (y + h > screen_height) - h -= (y + h) - screen_height; + if (unsigned(x + w) > screen_width) + w -= unsigned(x + w) - screen_width; + if (unsigned(y + h) > screen_height) + h -= unsigned(y + h) - screen_height; LOCK_VOSF; if (bytes_per_row >= screen_width) { const int bytes_per_pixel = bytes_per_row / screen_width; @@ -429,7 +428,7 @@ bool Screen_fault_handler(sigsegv_info_t *sip) LOCK_VOSF; if (PFLAG_ISCLEAR(page)) { PFLAG_SET(page); - vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); + vm_protect((char *)(addr & ~(mainBuffer.pageSize - 1)), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); } mainBuffer.dirty = true; UNLOCK_VOSF; @@ -483,7 +482,7 @@ static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) { VIDEO_MODE_INIT; - int page = 0; + unsigned page = 0; for (;;) { const unsigned first_page = find_next_page_set(page); if (first_page >= mainBuffer.pageCount) @@ -553,7 +552,7 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) memcpy(the_buffer_copy, the_buffer, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); VIDEO_DRV_LOCK_PIXELS; int i1 = 0, i2 = 0; - for (int j = 0; j < VIDEO_MODE_Y; j++) { + for (uint32_t j = 0; j < VIDEO_MODE_Y; j++) { Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); i1 += src_bytes_per_row; i2 += scr_bytes_per_row; @@ -566,15 +565,16 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) } // Setup partial blitter (use 64-pixel wide chunks) - const int n_pixels = 64; - const int n_chunks = VIDEO_MODE_X / n_pixels; - const int n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); - const int src_chunk_size = src_bytes_per_row / n_chunks; - const int dst_chunk_size = dst_bytes_per_row / n_chunks; - const int src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); - const int dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); + const uint32 n_pixels = 64; + const uint32 n_chunks = VIDEO_MODE_X / n_pixels; + const uint32 n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); + const uint32 src_chunk_size = src_bytes_per_row / n_chunks; + const uint32 dst_chunk_size = dst_bytes_per_row / n_chunks; + const uint32 src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); + const uint32 dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); - int page = 0, last_scanline = -1; + unsigned page = 0; + uint32 last_scanline = uint32(-1); for (;;) { const unsigned first_page = find_next_page_set(page); if (first_page >= mainBuffer.pageCount) @@ -589,28 +589,30 @@ static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); // Optimized for scanlines, don't process overlapping lines again - int y1 = mainBuffer.pageInfo[first_page].top; - int y2 = mainBuffer.pageInfo[page - 1].bottom; - if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) - continue; - if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) - continue; + uint32 y1 = mainBuffer.pageInfo[first_page].top; + uint32 y2 = mainBuffer.pageInfo[page - 1].bottom; + if (last_scanline != uint32(-1)) { + if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) + continue; + if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) + continue; + } last_scanline = y2; // Update the_host_buffer and copy of the_buffer, one line at a time - int i1 = y1 * src_bytes_per_row; - int i2 = y1 * scr_bytes_per_row; + uint32 i1 = y1 * src_bytes_per_row; + uint32 i2 = y1 * scr_bytes_per_row; #ifdef USE_SDL_VIDEO int bbi = 0; SDL_Rect bb[3] = { - { VIDEO_MODE_X, y1, 0, 0 }, - { VIDEO_MODE_X, -1, 0, 0 }, - { VIDEO_MODE_X, -1, 0, 0 } + { Sint16(VIDEO_MODE_X), Sint16(y1), 0, 0 }, + { Sint16(VIDEO_MODE_X), -1, 0, 0 }, + { Sint16(VIDEO_MODE_X), -1, 0, 0 } }; #endif VIDEO_DRV_LOCK_PIXELS; - for (int j = y1; j <= y2; j++) { - for (int i = 0; i < n_chunks; i++) { + for (uint32 j = y1; j <= y2; j++) { + for (uint32 i = 0; i < n_chunks; i++) { if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size) != 0) { memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size); Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size); diff --git a/BasiliskII/src/CrossPlatform/vm_alloc.cpp b/BasiliskII/src/CrossPlatform/vm_alloc.cpp index 17280a46..005cb727 100644 --- a/BasiliskII/src/CrossPlatform/vm_alloc.cpp +++ b/BasiliskII/src/CrossPlatform/vm_alloc.cpp @@ -132,7 +132,7 @@ static int translate_map_flags(int vm_flags) #ifdef HAVE_WIN32_VM static inline LPVOID align_addr_segment(LPVOID addr) { - return (LPVOID)(((vm_uintptr_t)addr) & -((vm_uintptr_t)65536)); + return LPVOID(vm_uintptr_t(addr) & ~vm_uintptr_t(0xFFFF)); } static inline DWORD align_size_segment(LPVOID addr, DWORD size) From 4499902ac53c453689e14cb14a6fe97163205241 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:09:10 -0700 Subject: [PATCH 13/19] Removed kernel_windows. Assume a Windows NT-derived operating system. Fixed some calling convention annotations. Fixed some MSVC warnings. --- BasiliskII/src/Windows/Makefile.in | 2 +- BasiliskII/src/Windows/ether_windows.cpp | 55 +++++--------- BasiliskII/src/Windows/kernel_windows.cpp | 88 ----------------------- BasiliskII/src/Windows/kernel_windows.h | 36 ---------- BasiliskII/src/Windows/main_windows.cpp | 33 ++------- 5 files changed, 24 insertions(+), 190 deletions(-) delete mode 100755 BasiliskII/src/Windows/kernel_windows.cpp delete mode 100755 BasiliskII/src/Windows/kernel_windows.h diff --git a/BasiliskII/src/Windows/Makefile.in b/BasiliskII/src/Windows/Makefile.in index 2214d868..dfa59a60 100755 --- a/BasiliskII/src/Windows/Makefile.in +++ b/BasiliskII/src/Windows/Makefile.in @@ -66,7 +66,7 @@ SRCS = ../main.cpp main_windows.cpp ../prefs.cpp ../prefs_items.cpp prefs_window ../scsi.cpp ../dummy/scsi_dummy.cpp ../video.cpp ../SDL/video_sdl.cpp \ video_blit.cpp ../audio.cpp ../SDL/audio_sdl.cpp clip_windows.cpp \ ../extfs.cpp extfs_windows.cpp ../user_strings.cpp user_strings_windows.cpp \ - vm_alloc.cpp sigsegv.cpp posix_emu.cpp util_windows.cpp kernel_windows.cpp \ + vm_alloc.cpp sigsegv.cpp posix_emu.cpp util_windows.cpp \ ../dummy/prefs_editor_dummy.cpp BasiliskII.rc \ $(CDENABLESRCS) $(ROUTERSRCS) $(CPUSRCS) $(SLIRP_OBJS) diff --git a/BasiliskII/src/Windows/ether_windows.cpp b/BasiliskII/src/Windows/ether_windows.cpp index 5182b8a0..b1ddc270 100755 --- a/BasiliskII/src/Windows/ether_windows.cpp +++ b/BasiliskII/src/Windows/ether_windows.cpp @@ -38,7 +38,7 @@ #include "b2ether/inc/b2ether_hl.h" #include "ether_windows.h" #include "router/router.h" -#include "kernel_windows.h" +#include "util_windows.h" #include "libslirp.h" // Define to let the slirp library determine the right timeout for select() @@ -175,10 +175,10 @@ static bool tap_set_status(LPADAPTER fd, ULONG status); static bool tap_get_mac(LPADAPTER fd, LPBYTE addr); static bool tap_receive_packet(LPADAPTER fd, LPPACKET lpPacket, BOOLEAN Sync); static bool tap_send_packet(LPADAPTER fd, LPPACKET lpPacket, BOOLEAN Sync, BOOLEAN recycle); -static WINAPI unsigned int slirp_receive_func(void *arg); -static WINAPI unsigned int ether_thread_feed_int(void *arg); -static WINAPI unsigned int ether_thread_get_packets_nt(void *arg); -static WINAPI unsigned int ether_thread_write_packets(void *arg); +static unsigned int WINAPI slirp_receive_func(void *arg); +static unsigned int WINAPI ether_thread_feed_int(void *arg); +static unsigned int WINAPI ether_thread_get_packets_nt(void *arg); +static unsigned int WINAPI ether_thread_write_packets(void *arg); static void init_queue(void); static void final_queue(void); static bool allocate_read_packets(void); @@ -403,26 +403,10 @@ bool ether_init(void) // No need to enter wait state if we can avoid it. // These all terminate fast. - if(pfnInitializeCriticalSectionAndSpinCount) { - pfnInitializeCriticalSectionAndSpinCount( &fetch_csection, 5000 ); - } else { - InitializeCriticalSection( &fetch_csection ); - } - if(pfnInitializeCriticalSectionAndSpinCount) { - pfnInitializeCriticalSectionAndSpinCount( &queue_csection, 5000 ); - } else { - InitializeCriticalSection( &queue_csection ); - } - if(pfnInitializeCriticalSectionAndSpinCount) { - pfnInitializeCriticalSectionAndSpinCount( &send_csection, 5000 ); - } else { - InitializeCriticalSection( &send_csection ); - } - if(pfnInitializeCriticalSectionAndSpinCount) { - pfnInitializeCriticalSectionAndSpinCount( &wpool_csection, 5000 ); - } else { - InitializeCriticalSection( &wpool_csection ); - } + InitializeCriticalSectionAndSpinCount( &fetch_csection, 5000 ); + InitializeCriticalSectionAndSpinCount( &queue_csection, 5000 ); + InitializeCriticalSectionAndSpinCount( &send_csection, 5000 ); + InitializeCriticalSectionAndSpinCount( &wpool_csection, 5000 ); ether_th = (HANDLE)_beginthreadex( 0, 0, ether_thread_feed_int, 0, 0, ðer_tid ); if (!ether_th) { @@ -497,8 +481,8 @@ void ether_exit(void) if(int_send_now) ReleaseSemaphore(int_send_now,1,NULL); D(bug("CancelIO if needed\n")); - if (fd && fd->hFile && pfnCancelIo) - pfnCancelIo(fd->hFile); + if (fd && fd->hFile) + CancelIo(fd->hFile); // Wait max 2 secs to shut down pending io. After that, kill them. D(bug("Wait delay\n")); @@ -992,7 +976,7 @@ static LPPACKET get_write_packet( UINT len ) return Packet; } -static unsigned int ether_thread_write_packets(void *arg) +unsigned int WINAPI ether_thread_write_packets(void *arg) { LPPACKET Packet; @@ -1246,7 +1230,7 @@ static bool tap_set_status(LPADAPTER fd, ULONG status) DWORD len = 0; return DeviceIoControl(fd->hFile, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof (status), - &status, sizeof (status), &len, NULL); + &status, sizeof (status), &len, NULL) != FALSE; } static bool tap_get_mac(LPADAPTER fd, LPBYTE addr) @@ -1254,8 +1238,7 @@ static bool tap_get_mac(LPADAPTER fd, LPBYTE addr) DWORD len = 0; return DeviceIoControl(fd->hFile, TAP_IOCTL_GET_MAC, addr, 6, - addr, 6, &len, NULL); - + addr, 6, &len, NULL) != FALSE; } static VOID CALLBACK tap_write_completion( @@ -1309,7 +1292,7 @@ static bool tap_send_packet( recycle_write_packet(lpPacket); } - return Result; + return Result != FALSE; } static bool tap_receive_packet(LPADAPTER fd, LPPACKET lpPacket, BOOLEAN Sync) @@ -1348,7 +1331,7 @@ static bool tap_receive_packet(LPADAPTER fd, LPPACKET lpPacket, BOOLEAN Sync) lpPacket->BytesReceived = 0; } - return Result; + return Result != FALSE; } @@ -1366,7 +1349,7 @@ void slirp_output(const uint8 *packet, int len) enqueue_packet(packet, len); } -static unsigned int slirp_receive_func(void *arg) +unsigned int WINAPI slirp_receive_func(void *arg) { D(bug("slirp_receive_func\n")); thread_active_2 = true; @@ -1508,7 +1491,7 @@ static void free_read_packets(void) } } -static unsigned int ether_thread_get_packets_nt(void *arg) +unsigned int WINAPI ether_thread_get_packets_nt(void *arg) { static uint8 packet[1514]; int i, packet_sz = 0; @@ -1565,7 +1548,7 @@ static unsigned int ether_thread_get_packets_nt(void *arg) return 0; } -static unsigned int ether_thread_feed_int(void *arg) +unsigned int WINAPI ether_thread_feed_int(void *arg) { bool looping; diff --git a/BasiliskII/src/Windows/kernel_windows.cpp b/BasiliskII/src/Windows/kernel_windows.cpp deleted file mode 100755 index d32b0712..00000000 --- a/BasiliskII/src/Windows/kernel_windows.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * kernel_windows.cpp - * - * Basilisk II (C) 1997-2008 Christian Bauer - * - * Windows platform specific code copyright (C) Lauri Pesonen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "sysdeps.h" -#include "prefs.h" -#include "kernel_windows.h" - -// From main_windows.cpp -extern DWORD win_os; -extern DWORD win_os_major; - -static HMODULE hKernel32 = 0; -static HMODULE hUser32 = 0; -static HMODULE hB2Win32 = 0; - -UINT (WINAPI *pfnGetWriteWatch) (DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD) = 0; -BOOL (WINAPI *pfnInitializeCriticalSectionAndSpinCount) (LPCRITICAL_SECTION,DWORD) = 0; -BOOL (WINAPI *pfnCancelIo) (HANDLE) = 0; -BOOL (WINAPI *pfnGETCDSECTORS) (BYTE,DWORD,WORD,LPBYTE) = 0; -UINT (WINAPI *pfnSendInput) (UINT,LPVOID,int) = 0; -BOOL (WINAPI *pfnGetDiskFreeSpaceEx) (LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER) = 0; - -void KernelInit( void ) -{ - hKernel32 = LoadLibrary( "kernel32.dll" ); - hUser32 = LoadLibrary( "user32.dll" ); - if(hKernel32) { - if(win_os == VER_PLATFORM_WIN32_WINDOWS) { - // NT5 RC2 Kernel exports GetWriteWatch(), but VirtualAlloc(MEM_WRITE_WATCH) fails - pfnGetWriteWatch = (UINT (WINAPI *)(DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD))GetProcAddress( hKernel32, "GetWriteWatch" ); - } - pfnInitializeCriticalSectionAndSpinCount = (BOOL (WINAPI *)(LPCRITICAL_SECTION,DWORD))GetProcAddress( hKernel32, "InitializeCriticalSectionAndSpinCount" ); - pfnCancelIo = (BOOL (WINAPI *)(HANDLE))GetProcAddress( hKernel32, "CancelIo" ); - pfnGetDiskFreeSpaceEx = (BOOL (WINAPI *)(LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER))GetProcAddress( hKernel32, "GetDiskFreeSpaceExA" ); - } - if(hUser32) { - // Win98 has this one too. - // if(win_os == VER_PLATFORM_WIN32_NT) { - pfnSendInput = (UINT (WINAPI *)(UINT,LPVOID,int))GetProcAddress( hUser32, "SendInput" ); - // } - } - if(win_os == VER_PLATFORM_WIN32_WINDOWS) { - hB2Win32 = LoadLibrary( "B2Win32.dll" ); - if(hB2Win32) { - pfnGETCDSECTORS = (BOOL (WINAPI *)(BYTE,DWORD,WORD,LPBYTE))GetProcAddress( hB2Win32, "GETCDSECTORS" ); - } - } -} - -void KernelExit( void ) -{ - if(hKernel32) { - FreeLibrary( hKernel32 ); - hKernel32 = 0; - } - if(hUser32) { - FreeLibrary( hUser32 ); - hUser32 = 0; - } - if(hB2Win32) { - FreeLibrary( hB2Win32 ); - hB2Win32 = 0; - } - pfnGetWriteWatch = 0; - pfnInitializeCriticalSectionAndSpinCount = 0; - pfnCancelIo = 0; - pfnSendInput = 0; - pfnGETCDSECTORS = 0; -} diff --git a/BasiliskII/src/Windows/kernel_windows.h b/BasiliskII/src/Windows/kernel_windows.h deleted file mode 100755 index efe998f7..00000000 --- a/BasiliskII/src/Windows/kernel_windows.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * kernel_windows.h - * - * Basilisk II (C) 1997-2008 Christian Bauer - * - * Windows platform specific code copyright (C) Lauri Pesonen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _KERNEL_WINDOWS_H_ -#define _KERNEL_WINDOWS_H_ - -extern UINT (WINAPI *pfnGetWriteWatch) (DWORD,PVOID,SIZE_T,PVOID *,LPDWORD,LPDWORD); -extern BOOL (WINAPI *pfnInitializeCriticalSectionAndSpinCount) (LPCRITICAL_SECTION,DWORD); -extern BOOL (WINAPI *pfnCancelIo) (HANDLE); -extern BOOL (WINAPI *pfnGETCDSECTORS) (BYTE,DWORD,WORD,LPBYTE); -extern UINT (WINAPI *pfnSendInput) (UINT,LPVOID,int); -extern BOOL (WINAPI *pfnGetDiskFreeSpaceEx) (LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER); - -void KernelInit( void ); -void KernelExit( void ); - -#endif // _KERNEL_WINDOWS_H_ diff --git a/BasiliskII/src/Windows/main_windows.cpp b/BasiliskII/src/Windows/main_windows.cpp index 38eb80e3..be9b5d94 100755 --- a/BasiliskII/src/Windows/main_windows.cpp +++ b/BasiliskII/src/Windows/main_windows.cpp @@ -49,7 +49,6 @@ using std::string; #include "vm_alloc.h" #include "sigsegv.h" #include "util_windows.h" -#include "kernel_windows.h" #if USE_JIT extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_support.cpp @@ -91,9 +90,6 @@ static SDL_mutex *intflag_lock = NULL; // Mutex to protect InterruptFlags #define LOCK_INTFLAGS SDL_LockMutex(intflag_lock) #define UNLOCK_INTFLAGS SDL_UnlockMutex(intflag_lock) -DWORD win_os; // Windows OS id -DWORD win_os_major; // Windows OS version major - #if USE_SCRATCHMEM_SUBTERFUGE uint8 *ScratchMem = NULL; // Scratch memory for Mac ROM writes #endif @@ -219,7 +215,7 @@ int main(int argc, char **argv) // Initialize variables RAMBaseHost = NULL; ROMBaseHost = NULL; - srand(time(NULL)); + srand(unsigned(time(NULL))); tzset(); // Print some info @@ -239,7 +235,7 @@ int main(int argc, char **argv) } else if (strcmp(argv[i], "--config") == 0) { argv[i++] = NULL; if (i < argc) { - extern string UserPrefsPath; // from prefs_unix.cpp + extern string UserPrefsPath; // from prefs_windows.cpp UserPrefsPath = argv[i]; argv[i] = NULL; } @@ -281,28 +277,10 @@ int main(int argc, char **argv) } } - // Check we are using a Windows NT kernel >= 4.0 - OSVERSIONINFO osvi; - ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!GetVersionEx(&osvi)) { - ErrorAlert("Could not determine OS type"); - QuitEmulator(); - } - win_os = osvi.dwPlatformId; - win_os_major = osvi.dwMajorVersion; - if (win_os != VER_PLATFORM_WIN32_NT || win_os_major < 4) { - ErrorAlert(STR_NO_WIN32_NT_4); - QuitEmulator(); - } - // Check that drivers are installed if (!check_drivers()) QuitEmulator(); - // Load win32 libraries - KernelInit(); - // FIXME: default to DIB driver if (getenv("SDL_VIDEODRIVER") == NULL) putenv("SDL_VIDEODRIVER=windib"); @@ -386,7 +364,7 @@ int main(int argc, char **argv) // Load Mac ROM HANDLE rom_fh = CreateFile(rom_path ? rom_path : ROM_FILE_NAME, GENERIC_READ, - 0, NULL, + FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -495,9 +473,6 @@ void QuitEmulator(void) // Exit preferences PrefsExit(); - // Release win32 libraries - KernelExit(); - exit(0); } @@ -631,7 +606,7 @@ static int tick_func(void *arg) next += 16625; int64 delay = next - GetTicks_usec(); if (delay > 0) - Delay_usec(delay); + Delay_usec(uint32(delay)); else if (delay < -16625) next = GetTicks_usec(); ticks++; From 9b8238ee3e3513afa302fc30387e5099127520fa Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:18:21 -0700 Subject: [PATCH 14/19] Removed spurious #includes of Windows.h. Fixed some more calling convention annotations. Don't mutate the prefs string in init_tcp_listen_ports. --- BasiliskII/src/Windows/cdenable/cache.cpp | 1 - BasiliskII/src/Windows/cdenable/eject_nt.cpp | 1 - BasiliskII/src/Windows/cdenable/ntcd.cpp | 1 - BasiliskII/src/Windows/router/router.cpp | 4 +--- BasiliskII/src/Windows/router/tcp.cpp | 10 ++++------ 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/BasiliskII/src/Windows/cdenable/cache.cpp b/BasiliskII/src/Windows/cdenable/cache.cpp index 4e3375c2..483f3ca1 100755 --- a/BasiliskII/src/Windows/cdenable/cache.cpp +++ b/BasiliskII/src/Windows/cdenable/cache.cpp @@ -27,7 +27,6 @@ */ #include "sysdeps.h" -#include "windows.h" #include "cache.h" #ifdef __cplusplus diff --git a/BasiliskII/src/Windows/cdenable/eject_nt.cpp b/BasiliskII/src/Windows/cdenable/eject_nt.cpp index b7a1357e..414ce4b9 100755 --- a/BasiliskII/src/Windows/cdenable/eject_nt.cpp +++ b/BasiliskII/src/Windows/cdenable/eject_nt.cpp @@ -22,7 +22,6 @@ #include "sysdeps.h" -#include "windows.h" #include // Prototypes diff --git a/BasiliskII/src/Windows/cdenable/ntcd.cpp b/BasiliskII/src/Windows/cdenable/ntcd.cpp index a4af0870..b263d2a8 100755 --- a/BasiliskII/src/Windows/cdenable/ntcd.cpp +++ b/BasiliskII/src/Windows/cdenable/ntcd.cpp @@ -21,7 +21,6 @@ */ #include "sysdeps.h" -#include extern "C" { diff --git a/BasiliskII/src/Windows/router/router.cpp b/BasiliskII/src/Windows/router/router.cpp index 34df59fc..66086381 100755 --- a/BasiliskII/src/Windows/router/router.cpp +++ b/BasiliskII/src/Windows/router/router.cpp @@ -28,8 +28,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include #include #include "cpu_emulation.h" @@ -147,7 +145,7 @@ bool router_read_packet(uint8 *packet, int len) Arguably an ugly hack, but needed since there is no way to listen to all ports w/o writing another ndis filter driver */ -static WINAPI unsigned int router_expire_thread(void *arg) +static unsigned int WINAPI router_expire_thread(void *arg) { while(!is_router_shutting_down) { close_old_sockets(); diff --git a/BasiliskII/src/Windows/router/tcp.cpp b/BasiliskII/src/Windows/router/tcp.cpp index 3a3203e3..72d9a262 100755 --- a/BasiliskII/src/Windows/router/tcp.cpp +++ b/BasiliskII/src/Windows/router/tcp.cpp @@ -67,8 +67,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include #include #include "cpu_emulation.h" @@ -1333,7 +1331,7 @@ void write_tcp( tcp_t *tcp, int len ) - Expire time-waits. - Handle resend timeouts. */ -static WINAPI unsigned int tcp_connect_close_thread(void *arg) +static unsigned int WINAPI tcp_connect_close_thread(void *arg) { WSAEVENT wait_handles[MAX_SOCKETS]; @@ -1429,7 +1427,7 @@ static WINAPI unsigned int tcp_connect_close_thread(void *arg) return 0; } -static WINAPI unsigned int tcp_listen_thread(void *arg) +static unsigned int WINAPI tcp_listen_thread(void *arg) { WSAEVENT wait_handles[MAX_SOCKETS]; @@ -1505,9 +1503,9 @@ static void init_tcp_listen_ports() const char *port_str; while ((port_str = PrefsFindString("tcp_port", index++)) != NULL) { uint32 iface = 0; - char *if_str = strchr(port_str,','); + const char *if_str = strchr(port_str,','); if(if_str) { - *if_str++ = 0; + if_str++; uint32 if_net = _inet_addr( if_str ); if(if_net == INADDR_NONE) if_net = INADDR_ANY; iface = ntohl( if_net ); From 47e95ba2e6afd68c63cc09866aa396d41cc8adae Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:31:42 -0700 Subject: [PATCH 15/19] Removed more spurious Windows.h #includes. MSVC-compatible use of #pragma pack. Fixed potential crash in Sys_open. Use MSVC intrinsics for byte swapping. Ensure use of winsock2 (instead of winsock). Set appropriate architecture #defines. Fixed various other compile warnings/errors. --- BasiliskII/src/Windows/cd_defs.h | 26 +++++----- BasiliskII/src/Windows/clip_windows.cpp | 6 +-- BasiliskII/src/Windows/prefs_windows.cpp | 3 -- BasiliskII/src/Windows/router/router_types.h | 18 +++---- BasiliskII/src/Windows/serial_windows.cpp | 4 +- BasiliskII/src/Windows/sys_windows.cpp | 24 +++++----- BasiliskII/src/Windows/sysdeps.h | 47 ++++++++++++++----- BasiliskII/src/Windows/timer_windows.cpp | 7 +-- .../src/Windows/user_strings_windows.cpp | 3 -- BasiliskII/src/Windows/util_windows.cpp | 8 ++-- BasiliskII/src/Windows/xpram_windows.cpp | 3 -- 11 files changed, 81 insertions(+), 68 deletions(-) diff --git a/BasiliskII/src/Windows/cd_defs.h b/BasiliskII/src/Windows/cd_defs.h index 8aaa595b..f58069e5 100755 --- a/BasiliskII/src/Windows/cd_defs.h +++ b/BasiliskII/src/Windows/cd_defs.h @@ -23,6 +23,8 @@ #define MAXIMUM_NUMBER_TRACKS 100 #define MAXIMUM_CDROM_SIZE 804 +#pragma pack(push, 1) + typedef struct _TRACK_DATA { UCHAR Reserved; UCHAR Control : 4; @@ -30,14 +32,14 @@ typedef struct _TRACK_DATA { UCHAR TrackNumber; UCHAR Reserved1; UCHAR Address[4]; -} ATTRIBUTE_PACKED TRACK_DATA, *PTRACK_DATA; +} TRACK_DATA, *PTRACK_DATA; typedef struct _CDROM_TOC { UCHAR Length[2]; UCHAR FirstTrack; UCHAR LastTrack; TRACK_DATA TrackData[MAXIMUM_NUMBER_TRACKS]; -} ATTRIBUTE_PACKED CDROM_TOC, *PCDROM_TOC; +} CDROM_TOC, *PCDROM_TOC; // #include "ntddcdrm.h" #define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM @@ -61,7 +63,7 @@ typedef struct _CDROM_TOC { typedef struct _VOLUME_CONTROL { UCHAR PortVolume[4]; -} ATTRIBUTE_PACKED VOLUME_CONTROL, *PVOLUME_CONTROL; +} VOLUME_CONTROL, *PVOLUME_CONTROL; typedef struct _CDROM_PLAY_AUDIO_MSF { UCHAR StartingM; @@ -70,13 +72,13 @@ typedef struct _CDROM_PLAY_AUDIO_MSF { UCHAR EndingM; UCHAR EndingS; UCHAR EndingF; -} ATTRIBUTE_PACKED CDROM_PLAY_AUDIO_MSF, *PCDROM_PLAY_AUDIO_MSF; +} CDROM_PLAY_AUDIO_MSF, *PCDROM_PLAY_AUDIO_MSF; typedef struct _CDROM_SEEK_AUDIO_MSF { UCHAR M; UCHAR S; UCHAR F; -} ATTRIBUTE_PACKED CDROM_SEEK_AUDIO_MSF, *PCDROM_SEEK_AUDIO_MSF; +} CDROM_SEEK_AUDIO_MSF, *PCDROM_SEEK_AUDIO_MSF; // @@ -87,7 +89,7 @@ typedef struct _SUB_Q_HEADER { UCHAR Reserved; UCHAR AudioStatus; UCHAR DataLength[2]; -} ATTRIBUTE_PACKED SUB_Q_HEADER, *PSUB_Q_HEADER; +} SUB_Q_HEADER, *PSUB_Q_HEADER; typedef struct _SUB_Q_CURRENT_POSITION { SUB_Q_HEADER Header; @@ -98,7 +100,7 @@ typedef struct _SUB_Q_CURRENT_POSITION { UCHAR IndexNumber; UCHAR AbsoluteAddress[4]; UCHAR TrackRelativeAddress[4]; -} ATTRIBUTE_PACKED SUB_Q_CURRENT_POSITION, *PSUB_Q_CURRENT_POSITION; +} SUB_Q_CURRENT_POSITION, *PSUB_Q_CURRENT_POSITION; typedef struct _SUB_Q_MEDIA_CATALOG_NUMBER { SUB_Q_HEADER Header; @@ -107,7 +109,7 @@ typedef struct _SUB_Q_MEDIA_CATALOG_NUMBER { UCHAR Reserved1 : 7; UCHAR Mcval : 1; UCHAR MediaCatalog[15]; -} ATTRIBUTE_PACKED SUB_Q_MEDIA_CATALOG_NUMBER, *PSUB_Q_MEDIA_CATALOG_NUMBER; +} SUB_Q_MEDIA_CATALOG_NUMBER, *PSUB_Q_MEDIA_CATALOG_NUMBER; typedef struct _SUB_Q_TRACK_ISRC { SUB_Q_HEADER Header; @@ -118,7 +120,7 @@ typedef struct _SUB_Q_TRACK_ISRC { UCHAR Reserved2 : 7; UCHAR Tcval : 1; UCHAR TrackIsrc[15]; -} ATTRIBUTE_PACKED SUB_Q_TRACK_ISRC, *PSUB_Q_TRACK_ISRC; +} SUB_Q_TRACK_ISRC, *PSUB_Q_TRACK_ISRC; typedef union _SUB_Q_CHANNEL_DATA { SUB_Q_CURRENT_POSITION CurrentPosition; @@ -136,16 +138,16 @@ typedef struct __RAW_READ_INFO { LARGE_INTEGER DiskOffset; ULONG SectorCount; TRACK_MODE_TYPE TrackMode; -} ATTRIBUTE_PACKED RAW_READ_INFO, *PRAW_READ_INFO; +} RAW_READ_INFO, *PRAW_READ_INFO; typedef struct _CDROM_SUB_Q_DATA_FORMAT { UCHAR Format; UCHAR Track; -} ATTRIBUTE_PACKED CDROM_SUB_Q_DATA_FORMAT, *PCDROM_SUB_Q_DATA_FORMAT; +} CDROM_SUB_Q_DATA_FORMAT, *PCDROM_SUB_Q_DATA_FORMAT; #define IOCTL_CDROM_SUB_Q_CHANNEL 0x00 #define IOCTL_CDROM_CURRENT_POSITION 0x01 #define IOCTL_CDROM_MEDIA_CATALOG 0x02 #define IOCTL_CDROM_TRACK_ISRC 0x03 -#pragma pack() +#pragma pack(pop) diff --git a/BasiliskII/src/Windows/clip_windows.cpp b/BasiliskII/src/Windows/clip_windows.cpp index 1e6f982b..c4ee65bc 100755 --- a/BasiliskII/src/Windows/clip_windows.cpp +++ b/BasiliskII/src/Windows/clip_windows.cpp @@ -21,8 +21,6 @@ #include "sysdeps.h" #include -#define WIN32_LEAN_AND_MEAN -#include #include "macos_util.h" #include "clip.h" @@ -236,7 +234,7 @@ static void do_getscrap(void **handle, uint32 type, int32 offset) // Convert text from ISO-Latin1 to Mac charset uint8 *p = Mac2HostAddr(scrap_area); - for (int i = 0; i < length; i++) { + for (uint32 i = 0; i < length; i++) { uint8 c = data[i]; if (c < 0x80) { if (c == 0) @@ -262,7 +260,7 @@ static void do_getscrap(void **handle, uint32 type, int32 offset) 0x2f, 0x3c, 0, 0, 0, 0, // move.l #outbuf,-(sp) 0xa9, 0xfe, // PutScrap() 0x58, 0x8f, // addq.l #4,sp - M68K_RTS >> 8, M68K_RTS + uint8(M68K_RTS >> 8), uint8(M68K_RTS) }; uint32 proc_area = Host2MacAddr(proc); WriteMacInt32(proc_area + 6, out_length); diff --git a/BasiliskII/src/Windows/prefs_windows.cpp b/BasiliskII/src/Windows/prefs_windows.cpp index ef3eac10..c7789fbc 100755 --- a/BasiliskII/src/Windows/prefs_windows.cpp +++ b/BasiliskII/src/Windows/prefs_windows.cpp @@ -20,9 +20,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include - #include #include diff --git a/BasiliskII/src/Windows/router/router_types.h b/BasiliskII/src/Windows/router/router_types.h index 1185dccb..9dcc8e63 100755 --- a/BasiliskII/src/Windows/router/router_types.h +++ b/BasiliskII/src/Windows/router/router_types.h @@ -23,7 +23,7 @@ #ifndef _ROUTER_TYPES_H_ #define _ROUTER_TYPES_H_ -#pragma pack(1) +#pragma pack(push, 1) // --------------------------- MAC --------------------------- @@ -31,7 +31,7 @@ typedef struct { uint8 dest[6]; uint8 src[6]; uint16 type; -} ATTRIBUTE_PACKED mac_t; +} mac_t; enum { mac_type_llc_ipx_limit = 0x05DC, // <= mac_type_llc_ipx_limit -->> 802.3 MAC frame @@ -54,7 +54,7 @@ typedef struct { uint8 srcp[4]; // size for ip uint8 dsth[6]; // size for ethernet uint8 dstp[4]; // size for ip -} ATTRIBUTE_PACKED arp_t; +} arp_t; enum { arp_request = 1, @@ -79,7 +79,7 @@ typedef struct { uint32 src; uint32 dest; // ip options, size = 4 * header_len - 20 -} ATTRIBUTE_PACKED ip_t; +} ip_t; // Protocol STD numbers enum { @@ -95,7 +95,7 @@ typedef struct { uint8 code; uint16 checksum; // data -} ATTRIBUTE_PACKED icmp_t; +} icmp_t; enum { icmp_Echo_reply = 0, @@ -140,7 +140,7 @@ typedef struct { uint16 urgent_ptr; // options + padding: size = dataoffset*4-20 // data -} ATTRIBUTE_PACKED tcp_t; +} tcp_t; enum { tcp_flags_URG = 0x20, // The urgent pointer field is significant in this segment. @@ -173,15 +173,15 @@ typedef struct { uint16 msg_len; uint16 checksum; // data -} ATTRIBUTE_PACKED udp_t; +} udp_t; typedef struct { uint16 src_lo, src_hi; uint16 dest_lo, dest_hi; uint16 proto; uint16 msg_len; -} ATTRIBUTE_PACKED pseudo_ip_t; +} pseudo_ip_t; -#pragma pack() +#pragma pack(pop) #endif // _ROUTER_TYPES_H_ diff --git a/BasiliskII/src/Windows/serial_windows.cpp b/BasiliskII/src/Windows/serial_windows.cpp index 4f4639fe..4a1300b2 100755 --- a/BasiliskII/src/Windows/serial_windows.cpp +++ b/BasiliskII/src/Windows/serial_windows.cpp @@ -166,8 +166,8 @@ public: private: bool configure(uint16 config); void set_handshake(uint32 s, bool with_dtr); - static WINAPI unsigned int input_func(void *arg); - static WINAPI unsigned int output_func(void *arg); + static unsigned int WINAPI input_func(void *arg); + static unsigned int WINAPI output_func(void *arg); static int acknowledge_error(HANDLE h, bool is_read); bool set_timeouts(int bauds, int parity_bits, int stop_bits); diff --git a/BasiliskII/src/Windows/sys_windows.cpp b/BasiliskII/src/Windows/sys_windows.cpp index 4a50d658..9e3ed385 100755 --- a/BasiliskII/src/Windows/sys_windows.cpp +++ b/BasiliskII/src/Windows/sys_windows.cpp @@ -20,8 +20,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include #include #include @@ -497,11 +495,11 @@ void *Sys_open(const char *path_name, bool read_only) } } - if (fh->is_floppy && first_floppy == NULL) - first_floppy = fh; - - if (fh) + if (fh) { + if (fh->is_floppy && first_floppy == NULL) + first_floppy = fh; sys_add_file_handle(fh); + } return fh; } @@ -793,7 +791,7 @@ bool SysCDReadTOC(void *arg, uint8 *toc) NULL, 0, toc, min((int)sizeof(CDROM_TOC), 804), &dummy, - NULL); + NULL) != FALSE; } @@ -819,7 +817,7 @@ bool SysCDGetPosition(void *arg, uint8 *pos) &q_format, sizeof(CDROM_SUB_Q_DATA_FORMAT), &q_data, sizeof(SUB_Q_CHANNEL_DATA), &dwBytesReturned, - NULL); + NULL) != FALSE; if (ok) memcpy(pos, &q_data.CurrentPosition, sizeof(SUB_Q_CURRENT_POSITION)); @@ -851,7 +849,7 @@ bool SysCDPlay(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, uint8 end &msf, sizeof(CDROM_PLAY_AUDIO_MSF), NULL, 0, &dwBytesReturned, - NULL); + NULL) != FALSE; } @@ -871,7 +869,7 @@ bool SysCDPause(void *arg) NULL, 0, NULL, 0, &dwBytesReturned, - NULL); + NULL) != FALSE; } @@ -890,7 +888,7 @@ bool SysCDResume(void *arg) IOCTL_CDROM_RESUME_AUDIO, NULL, 0, NULL, 0, - &dwBytesReturned, NULL); + &dwBytesReturned, NULL) != FALSE; } @@ -910,7 +908,7 @@ bool SysCDStop(void *arg, uint8 lead_out_m, uint8 lead_out_s, uint8 lead_out_f) NULL, 0, NULL, 0, &dwBytesReturned, - NULL); + NULL) != FALSE; } @@ -935,7 +933,7 @@ bool SysCDScan(void *arg, uint8 start_m, uint8 start_s, uint8 start_f, bool reve &msf, sizeof(CDROM_SEEK_AUDIO_MSF), NULL, 0, &dwBytesReturned, - NULL); + NULL) != FALSE; } diff --git a/BasiliskII/src/Windows/sysdeps.h b/BasiliskII/src/Windows/sysdeps.h index b64a19fa..8f6fa72b 100755 --- a/BasiliskII/src/Windows/sysdeps.h +++ b/BasiliskII/src/Windows/sysdeps.h @@ -21,7 +21,7 @@ #ifndef SYSDEPS_H #define SYSDEPS_H -#ifndef __STDC__ +#if !defined _MSC_VER && !defined __STDC__ #error "Your compiler is not ANSI. Get a real one." #endif @@ -41,9 +41,9 @@ #include #include #include -#ifdef __WIN32__ +#define WIN32_LEAN_AND_MEAN #include -#endif +#include #include @@ -78,6 +78,10 @@ /* ExtFS is supported */ #define SUPPORTS_EXTFS 1 +/* POSIX data types missing from Microsoft's CRT */ +#ifdef _MSC_VER +typedef ptrdiff_t ssize_t; +#endif /* Data types */ typedef unsigned char uint8; @@ -123,13 +127,21 @@ typedef int64 intptr; #error "Unsupported size of pointer" #endif -#ifdef __WIN32__ +#ifdef _WIN32 typedef int64 loff_t; #endif #ifndef HAVE_CADDR_T typedef char * caddr_t; #endif +#ifdef _MSC_VER +#ifdef _M_IX86 +#define __i386__ +#elif defined _M_AMD64 +#define __x86_64__ +#endif +#endif + /* Time data type for Time Manager emulation */ typedef int64 tm_time_t; @@ -207,31 +219,42 @@ static inline int spin_trylock(spinlock_t *lock) } #endif -/* Intel x86 */ #define X86_PPRO_OPT +#define HAVE_OPTIMIZED_BYTESWAP_32 +#define HAVE_OPTIMIZED_BYTESWAP_16 + +#ifdef _MSC_VER +static inline uae_u32 do_get_mem_long(uae_u32 *a) {return _byteswap_ulong(*a);} +static inline uae_u32 do_get_mem_word(uae_u16 *a) {return _byteswap_ushort(*a);} +static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {*a = _byteswap_ulong(v);} +static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {*a = _byteswap_ushort(v);} +static inline uae_u32 do_byteswap_32_g(uae_u32 v) {return _byteswap_ulong(v);} +static inline uae_u32 do_byteswap_16_g(uae_u32 v) {return _byteswap_ushort(v);} +#else +/* Intel x86 */ static inline uae_u32 do_get_mem_long(uae_u32 *a) {uint32 retval; __asm__ ("bswap %0" : "=r" (retval) : "0" (*a) : "cc"); return retval;} #ifdef X86_PPRO_OPT static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint32 retval; __asm__ ("movzwl %w1,%k0\n\tshll $16,%k0\n\tbswapl %k0\n" : "=&r" (retval) : "m" (*a) : "cc"); return retval;} #else static inline uae_u32 do_get_mem_word(uae_u16 *a) {uint32 retval; __asm__ ("xorl %k0,%k0\n\tmovw %w1,%w0\n\trolw $8,%w0" : "=&r" (retval) : "m" (*a) : "cc"); return retval;} #endif -#define HAVE_GET_WORD_UNSWAPPED -#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) static inline void do_put_mem_long(uae_u32 *a, uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v) : "cc"); *a = v;} #ifdef X86_PPRO_OPT static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); *a = v;} #else static inline void do_put_mem_word(uae_u16 *a, uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); *a = v;} #endif -#define HAVE_OPTIMIZED_BYTESWAP_32 /* bswap doesn't affect condition codes */ static inline uae_u32 do_byteswap_32_g(uae_u32 v) {__asm__ ("bswap %0" : "=r" (v) : "0" (v)); return v;} -#define HAVE_OPTIMIZED_BYTESWAP_16 #ifdef X86_PPRO_OPT static inline uae_u32 do_byteswap_16_g(uae_u32 v) {__asm__ ("bswapl %0" : "=&r" (v) : "0" (v << 16) : "cc"); return v;} #else static inline uae_u32 do_byteswap_16_g(uae_u32 v) {__asm__ ("rolw $8,%0" : "=r" (v) : "0" (v) : "cc"); return v;} #endif +#endif + +#define HAVE_GET_WORD_UNSWAPPED +#define do_get_mem_word_unswapped(a) ((uae_u32)*((uae_u16 *)(a))) #ifndef HAVE_OPTIMIZED_BYTESWAP_32 static inline uae_u32 do_byteswap_32_g(uae_u32 v) @@ -294,8 +317,6 @@ static inline uae_u32 do_byteswap_16_g(uae_u32 v) #define ENUMNAME(name) name #define write_log printf -#define ATTRIBUTE_PACKED __attribute__((packed)) - #if defined(X86_ASSEMBLY) || defined(X86_64_ASSEMBLY) #define ASM_SYM(a) __asm__(a) #else @@ -307,4 +328,8 @@ static inline uae_u32 do_byteswap_16_g(uae_u32 v) #endif #define REGPARAM2 +#ifdef _MSC_VER +#define ATTRIBUTE_PACKED +#endif + #endif diff --git a/BasiliskII/src/Windows/timer_windows.cpp b/BasiliskII/src/Windows/timer_windows.cpp index 5399fdfc..d0aed8ac 100755 --- a/BasiliskII/src/Windows/timer_windows.cpp +++ b/BasiliskII/src/Windows/timer_windows.cpp @@ -20,9 +20,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include - #include "main.h" #include "macos_util.h" #include "timer.h" @@ -169,9 +166,9 @@ int32 timer_host2mac_time(tm_time_t hosttime) else { uint64 t = TICKS2USECS(hosttime); if (t > 0x7fffffff) - return t / 1000; // Time in milliseconds + return int32(t / 1000); // Time in milliseconds else - return -t; // Time in negative microseconds + return -int32(t); // Time in negative microseconds } } diff --git a/BasiliskII/src/Windows/user_strings_windows.cpp b/BasiliskII/src/Windows/user_strings_windows.cpp index 0b9de060..3ca501be 100755 --- a/BasiliskII/src/Windows/user_strings_windows.cpp +++ b/BasiliskII/src/Windows/user_strings_windows.cpp @@ -21,9 +21,6 @@ #include "sysdeps.h" #include "user_strings.h" -#define WIN32_LEAN_AND_MEAN -#include - // Platform-specific string definitions user_string_def platform_strings[] = { diff --git a/BasiliskII/src/Windows/util_windows.cpp b/BasiliskII/src/Windows/util_windows.cpp index 10e586d2..130b8b8c 100755 --- a/BasiliskII/src/Windows/util_windows.cpp +++ b/BasiliskII/src/Windows/util_windows.cpp @@ -23,6 +23,8 @@ #include "sysdeps.h" #include "util_windows.h" #include "main.h" +#include +#include #include using std::list; @@ -35,10 +37,10 @@ BOOL exists( const char *path ) HFILE h; bool ret = false; - h = _lopen( path, OF_READ ); - if(h != HFILE_ERROR) { + h = _open( path, _O_RDONLY | _O_BINARY ); + if(h != -1) { ret = true; - _lclose(h); + _close(h); } return(ret); } diff --git a/BasiliskII/src/Windows/xpram_windows.cpp b/BasiliskII/src/Windows/xpram_windows.cpp index f69c0d0e..c47a9cb7 100755 --- a/BasiliskII/src/Windows/xpram_windows.cpp +++ b/BasiliskII/src/Windows/xpram_windows.cpp @@ -20,9 +20,6 @@ #include "sysdeps.h" -#define WIN32_LEAN_AND_MEAN -#include - #include using std::string; From a6a46a269756023e5d816b2f6597cc22510246da Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:34:24 -0700 Subject: [PATCH 16/19] Unicode friendly! --- .../src/Windows/b2ether/inc/b2ether_hl.h | 7 +- BasiliskII/src/Windows/b2ether/packet32.cpp | 316 ++++++------------ BasiliskII/src/Windows/cdenable/ntcd.cpp | 6 +- BasiliskII/src/Windows/ether_windows.cpp | 50 ++- BasiliskII/src/Windows/extfs_windows.cpp | 18 +- BasiliskII/src/Windows/main_windows.cpp | 36 +- BasiliskII/src/Windows/posix_emu.cpp | 266 ++++++++------- BasiliskII/src/Windows/posix_emu.h | 2 +- BasiliskII/src/Windows/prefs_windows.cpp | 19 +- BasiliskII/src/Windows/router/arp.cpp | 1 + BasiliskII/src/Windows/router/dump.cpp | 1 + BasiliskII/src/Windows/router/dynsockets.cpp | 3 +- BasiliskII/src/Windows/router/ftp.cpp | 1 + BasiliskII/src/Windows/router/icmp.cpp | 1 + BasiliskII/src/Windows/router/iphelp.cpp | 1 + BasiliskII/src/Windows/router/ipsocket.cpp | 1 + .../src/Windows/router/mib/interfaces.cpp | 1 + .../src/Windows/router/mib/mibaccess.cpp | 18 +- BasiliskII/src/Windows/router/mib/mibaccess.h | 2 +- BasiliskII/src/Windows/router/router.cpp | 1 + BasiliskII/src/Windows/router/tcp.cpp | 1 + BasiliskII/src/Windows/router/udp.cpp | 1 + BasiliskII/src/Windows/serial_windows.cpp | 40 +-- BasiliskII/src/Windows/sys_windows.cpp | 50 +-- BasiliskII/src/Windows/sysdeps.h | 1 + .../src/Windows/user_strings_windows.cpp | 26 +- BasiliskII/src/Windows/user_strings_windows.h | 15 +- BasiliskII/src/Windows/util_windows.cpp | 220 +++++++++--- BasiliskII/src/Windows/util_windows.h | 84 ++++- BasiliskII/src/Windows/xpram_windows.cpp | 12 +- BasiliskII/src/dummy/scsi_dummy.cpp | 1 + BasiliskII/src/include/debug.h | 54 ++- 32 files changed, 736 insertions(+), 520 deletions(-) diff --git a/BasiliskII/src/Windows/b2ether/inc/b2ether_hl.h b/BasiliskII/src/Windows/b2ether/inc/b2ether_hl.h index 4d6b2e49..d5e87655 100755 --- a/BasiliskII/src/Windows/b2ether/inc/b2ether_hl.h +++ b/BasiliskII/src/Windows/b2ether/inc/b2ether_hl.h @@ -50,11 +50,11 @@ typedef struct _PACKET { BOOLEAN StartPacketDriver( - LPTSTR ServiceName + LPCTSTR ServiceName ); LPADAPTER PacketOpenAdapter( - LPCSTR AdapterName, + LPCTSTR AdapterName, int16 mode ); @@ -95,8 +95,7 @@ BOOLEAN PacketGetMAC( LPADAPTER AdapterObject, LPBYTE address, BOOL permanent ); BOOLEAN PacketAddMulticast( LPADAPTER AdapterObject, LPBYTE address ); BOOLEAN PacketDelMulticast( LPADAPTER AdapterObject, LPBYTE address ); -ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, PTSTR pStr, PULONG BufferSize ); -ULONG PacketSelectAdapterByName( LPADAPTER AdapterObject, LPCSTR name ); +ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, LPTSTR pStr, PULONG BufferSize ); // callbacks void recycle_write_packet( LPPACKET Packet ); diff --git a/BasiliskII/src/Windows/b2ether/packet32.cpp b/BasiliskII/src/Windows/b2ether/packet32.cpp index be0b134f..72efb1fe 100755 --- a/BasiliskII/src/Windows/b2ether/packet32.cpp +++ b/BasiliskII/src/Windows/b2ether/packet32.cpp @@ -21,7 +21,8 @@ */ #include "sysdeps.h" -#include +#include "main.h" +#include "util_windows.h" #include #include #include "cpu_emulation.h" @@ -73,26 +74,18 @@ extern "C" { #define MAX_MULTICAST 100 #define MAX_MULTICAST_SZ (20*ETH_802_3_ADDRESS_LENGTH) -static int os = VER_PLATFORM_WIN32_WINDOWS; - static ULONG packet_filter = 0; -LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode ) +LPADAPTER PacketOpenAdapter( LPCTSTR AdapterName, int16 mode ) { LPADAPTER lpAdapter; BOOLEAN Result = TRUE; - OSVERSIONINFO osv; D(bug("Packet32: PacketOpenAdapter\n")); - osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if(GetVersionEx( &osv )) os = osv.dwPlatformId; - - if(os == VER_PLATFORM_WIN32_NT) { - // May fail if user is not an Administrator. - StartPacketDriver( "B2ether" ); - } + // May fail if user is not an Administrator. + StartPacketDriver( TEXT("B2ether") ); lpAdapter = (LPADAPTER)GlobalAllocPtr( GMEM_MOVEABLE|GMEM_ZEROINIT, sizeof(ADAPTER) ); if (lpAdapter==NULL) { @@ -100,25 +93,21 @@ LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode ) return NULL; } - if(os == VER_PLATFORM_WIN32_NT) { - char device_name[256]; - wsprintf( lpAdapter->SymbolicLink, "\\\\.\\B2ether_%s", AdapterName ); - wsprintf( device_name, "\\Device\\B2ether_%s", AdapterName ); + TCHAR device_name[256]; + _sntprintf(lpAdapter->SymbolicLink, lengthof(lpAdapter->SymbolicLink), TEXT("\\\\.\\B2ether_%s"), AdapterName ); + _sntprintf(device_name, lengthof(device_name), TEXT("\\Device\\B2ether_%s"), AdapterName ); - // Work around one subtle NT4 bug. - DefineDosDevice( - DDD_REMOVE_DEFINITION, - &lpAdapter->SymbolicLink[4], - NULL - ); - DefineDosDevice( - DDD_RAW_TARGET_PATH, - &lpAdapter->SymbolicLink[4], - device_name - ); - } else { - wsprintf( lpAdapter->SymbolicLink, "\\\\.\\B2ether" ); - } + // Work around one subtle NT4 bug. + DefineDosDevice( + DDD_REMOVE_DEFINITION, + &lpAdapter->SymbolicLink[4], + NULL + ); + DefineDosDevice( + DDD_RAW_TARGET_PATH, + &lpAdapter->SymbolicLink[4], + device_name + ); packet_filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_MULTICAST | @@ -138,10 +127,7 @@ LPADAPTER PacketOpenAdapter( LPCSTR AdapterName, int16 mode ) 0 ); if (lpAdapter->hFile != INVALID_HANDLE_VALUE) { - if(*AdapterName && strcmp(AdapterName,"") != 0) { - if(os == VER_PLATFORM_WIN32_WINDOWS) { - PacketSelectAdapterByName( lpAdapter, AdapterName ); - } + if(*AdapterName && _tcscmp(AdapterName,TEXT("")) != 0) { PacketSetFilter( lpAdapter, packet_filter ); } return lpAdapter; @@ -282,58 +268,48 @@ BOOLEAN PacketSendPacket( D(bug("Packet32: PacketSendPacket bytes=%d, sync=%d\n",lpPacket->Length,Sync)); #endif - if(os == VER_PLATFORM_WIN32_NT) { - lpPacket->OverLapped.Offset = 0; - lpPacket->OverLapped.OffsetHigh = 0; - lpPacket->bIoComplete = FALSE; + lpPacket->OverLapped.Offset = 0; + lpPacket->OverLapped.OffsetHigh = 0; + lpPacket->bIoComplete = FALSE; - if(Sync) { - Result = WriteFile( - AdapterObject->hFile, - lpPacket->Buffer, - lpPacket->Length, - &lpPacket->BytesReceived, - &lpPacket->OverLapped - ); - if(Result) { - Result = GetOverlappedResult( - AdapterObject->hFile, - &lpPacket->OverLapped, - &lpPacket->BytesReceived, - TRUE - ); - } else { - D(bug("Packet32: PacketSendPacket WriteFile failed, err=%d\n",(int)GetLastError())); - } - lpPacket->bIoComplete = TRUE; - if(RecyclingAllowed) PacketFreePacket(lpPacket); -#if DEBUG_PACKETS - D(bug("Packet32: PacketSendPacket result=%d, bytes=%d\n",(int)Result,(int)lpPacket->BytesReceived)); -#endif + if(Sync) { + Result = WriteFile( + AdapterObject->hFile, + lpPacket->Buffer, + lpPacket->Length, + &lpPacket->BytesReceived, + &lpPacket->OverLapped + ); + if(Result) { + Result = GetOverlappedResult( + AdapterObject->hFile, + &lpPacket->OverLapped, + &lpPacket->BytesReceived, + TRUE + ); } else { - // don't care about the result - Result = WriteFileEx( - AdapterObject->hFile, - lpPacket->Buffer, - lpPacket->Length, - &lpPacket->OverLapped, - PacketSendCompletionRoutine - ); -#if DEBUG_PACKETS - D(bug("Packet32: PacketSendPacket result=%d\n",(int)Result)); -#endif - if(!Result && RecyclingAllowed) { - recycle_write_packet(lpPacket); - } + D(bug("Packet32: PacketSendPacket WriteFile failed, err=%d\n",(int)GetLastError())); } + lpPacket->bIoComplete = TRUE; + if(RecyclingAllowed) PacketFreePacket(lpPacket); +#if DEBUG_PACKETS + D(bug("Packet32: PacketSendPacket result=%d, bytes=%d\n",(int)Result,(int)lpPacket->BytesReceived)); +#endif } else { - // Now: make writes always synchronous under Win9x - Sync = TRUE; - Result = PacketDeviceIoControl( AdapterObject, - lpPacket, - IOCTL_PROTOCOL_WRITE, - Sync ); - if(RecyclingAllowed) recycle_write_packet(lpPacket); + // don't care about the result + Result = WriteFileEx( + AdapterObject->hFile, + lpPacket->Buffer, + lpPacket->Length, + &lpPacket->OverLapped, + PacketSendCompletionRoutine + ); +#if DEBUG_PACKETS + D(bug("Packet32: PacketSendPacket result=%d\n",(int)Result)); +#endif + if(!Result && RecyclingAllowed) { + recycle_write_packet(lpPacket); + } } return Result; @@ -347,58 +323,46 @@ BOOLEAN PacketReceivePacket( { BOOLEAN Result; - if(os == VER_PLATFORM_WIN32_NT) { - lpPacket->OverLapped.Offset=0; - lpPacket->OverLapped.OffsetHigh=0; - lpPacket->bIoComplete = FALSE; + lpPacket->OverLapped.Offset=0; + lpPacket->OverLapped.OffsetHigh=0; + lpPacket->bIoComplete = FALSE; #if DEBUG_PACKETS - D(bug("Packet32: PacketReceivePacket\n")); + D(bug("Packet32: PacketReceivePacket\n")); #endif - if (Sync) { - Result = ReadFile( - AdapterObject->hFile, - lpPacket->Buffer, - lpPacket->Length, - &lpPacket->BytesReceived, - &lpPacket->OverLapped - ); - if(Result) { - Result = GetOverlappedResult( - AdapterObject->hFile, - &lpPacket->OverLapped, - &lpPacket->BytesReceived, - TRUE - ); - if(Result) - lpPacket->bIoComplete = TRUE; - else - lpPacket->free = TRUE; - } - } else { - Result = ReadFileEx( - AdapterObject->hFile, - lpPacket->Buffer, - lpPacket->Length, - &lpPacket->OverLapped, - packet_read_completion - ); + if (Sync) { + Result = ReadFile( + AdapterObject->hFile, + lpPacket->Buffer, + lpPacket->Length, + &lpPacket->BytesReceived, + &lpPacket->OverLapped + ); + if(Result) { + Result = GetOverlappedResult( + AdapterObject->hFile, + &lpPacket->OverLapped, + &lpPacket->BytesReceived, + TRUE + ); + if(Result) + lpPacket->bIoComplete = TRUE; + else + lpPacket->free = TRUE; } - - if(!Result) lpPacket->BytesReceived = 0; } else { - Result = PacketDeviceIoControl( AdapterObject, - lpPacket, - IOCTL_PROTOCOL_READ, - Sync ); - if( !Result && !Sync ) { - if (GetLastError() == ERROR_IO_PENDING) { - Result = TRUE; - } - } + Result = ReadFileEx( + AdapterObject->hFile, + lpPacket->Buffer, + lpPacket->Length, + &lpPacket->OverLapped, + packet_read_completion + ); } + if(!Result) lpPacket->BytesReceived = 0; + #if DEBUG_PACKETS D(bug("Packet32: PacketReceivePacket got %d bytes, result=%d\n",lpPacket->BytesReceived,(int)Result)); #endif @@ -641,7 +605,7 @@ BOOLEAN PacketSetFilter( LPADAPTER AdapterObject, ULONG Filter ) return Status; } -BOOLEAN StartPacketDriver( LPTSTR ServiceName ) +BOOLEAN StartPacketDriver( LPCTSTR ServiceName ) { BOOLEAN Status = FALSE; @@ -658,7 +622,7 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName ) } else { SCServiceHandle = OpenService(SCManagerHandle,ServiceName,SERVICE_START); if (SCServiceHandle == NULL) { - D(bug("Could not open service %s\r\n",ServiceName)); + D(bug(TEXT("Could not open service %s\r\n"),ServiceName)); } else { Status = StartService( SCServiceHandle, 0, NULL ); if(!Status) { @@ -686,7 +650,7 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName ) } else { waiting = FALSE; } - } + } CloseServiceHandle(SCServiceHandle); } CloseServiceHandle(SCManagerHandle); @@ -694,91 +658,33 @@ BOOLEAN StartPacketDriver( LPTSTR ServiceName ) return Status; } -ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, PTSTR pStr, PULONG BufferSize ) +ULONG PacketGetAdapterNames( LPADAPTER lpAdapter, LPTSTR pStr, PULONG BufferSize ) { LONG Status; - if(os == VER_PLATFORM_WIN32_NT) { - HKEY hKey; - DWORD RegType; + HKEY hKey; + DWORD RegType; - Status = RegOpenKey( - HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Services\\B2Ether\\Linkage", - &hKey - ); - if( Status == ERROR_SUCCESS ) { - Status = RegQueryValueEx( - hKey, - "Export", - NULL, - &RegType, - (LPBYTE)pStr, - BufferSize - ); - RegCloseKey(hKey); - } - } else { - if (lpAdapter && lpAdapter->hFile != INVALID_HANDLE_VALUE) { - LPPACKET Packet = PacketAllocatePacket( lpAdapter, *BufferSize ); - if(Packet) { - memset( pStr, 0, *BufferSize ); - Packet->Buffer = (PVOID)pStr; - Packet->Length = *BufferSize; - Status = PacketDeviceIoControl( - lpAdapter, - Packet, - (ULONG)IOCTL_PROTOCOL_MACNAME, - TRUE - ); - if(Status) { - while(*pStr) { - if(*pStr == '|' || *pStr == ' ') *pStr = 0; - pStr++; - } - *(++pStr) = 0; - Status = ERROR_SUCCESS; - } else { - Status = ERROR_ACCESS_DENIED; - } - *BufferSize = Packet->BytesReceived; - PacketFreePacket(Packet); - } - } + Status = RegOpenKey( + HKEY_LOCAL_MACHINE, + TEXT("SYSTEM\\CurrentControlSet\\Services\\B2Ether\\Linkage"), + &hKey + ); + if( Status == ERROR_SUCCESS ) { + Status = RegQueryValueEx( + hKey, + TEXT("Export"), + NULL, + &RegType, + (LPBYTE)pStr, + BufferSize + ); + RegCloseKey(hKey); } return Status; } - -ULONG PacketSelectAdapterByName( LPADAPTER lpAdapter, LPCSTR name ) -{ - ULONG Status = 0; - - if(os == VER_PLATFORM_WIN32_WINDOWS) { - int len = strlen(name) + 1; - LPPACKET Packet = PacketAllocatePacket( lpAdapter, len ); - if(Packet) { - Packet->Buffer = (PVOID)name; - Packet->Length = len; - Status = PacketDeviceIoControl( - lpAdapter, - Packet, - (ULONG)IOCTL_PROTOCOL_SELECT_BY_NAME, - TRUE - ); - if(Status) { - Status = ERROR_SUCCESS; - } else { - Status = ERROR_ACCESS_DENIED; - } - PacketFreePacket(Packet); - } - } - return Status; -} - - #ifdef __cplusplus } #endif diff --git a/BasiliskII/src/Windows/cdenable/ntcd.cpp b/BasiliskII/src/Windows/cdenable/ntcd.cpp index b263d2a8..acefb13c 100755 --- a/BasiliskII/src/Windows/cdenable/ntcd.cpp +++ b/BasiliskII/src/Windows/cdenable/ntcd.cpp @@ -29,9 +29,9 @@ extern "C" { #include "ntcd.h" #include "cdenable.h" -static char *sDriverShort = "cdenable"; -static char *sDriverLong = "System32\\Drivers\\cdenable.sys"; -static char *sCompleteName = "\\\\.\\cdenable"; +static LPCTSTR sDriverShort = TEXT("cdenable"); +static LPCTSTR sDriverLong = TEXT("System32\\Drivers\\cdenable.sys"); +static LPCTSTR sCompleteName = TEXT("\\\\.\\cdenable"); #ifdef _DEBUG #define new DEBUG_NEW diff --git a/BasiliskII/src/Windows/ether_windows.cpp b/BasiliskII/src/Windows/ether_windows.cpp index b1ddc270..1f59d830 100755 --- a/BasiliskII/src/Windows/ether_windows.cpp +++ b/BasiliskII/src/Windows/ether_windows.cpp @@ -168,7 +168,7 @@ static HANDLE int_sig2 = 0; static HANDLE int_send_now = 0; // Prototypes -static LPADAPTER tap_open_adapter(const char *dev_name); +static LPADAPTER tap_open_adapter(LPCTSTR dev_name); static void tap_close_adapter(LPADAPTER fd); static bool tap_check_version(LPADAPTER fd); static bool tap_set_status(LPADAPTER fd, ULONG status); @@ -218,7 +218,7 @@ static NetProtocol *find_protocol(uint16 type) bool ether_init(void) { - char str[256]; + TCHAR buf[256]; // Do nothing if no Ethernet device specified const char *name = PrefsFindString("ether"); @@ -248,22 +248,21 @@ bool ether_init(void) // Initialize slirp library if (net_if_type == NET_IF_SLIRP) { if (slirp_init() < 0) { - sprintf(str, GetString(STR_SLIRP_NO_DNS_FOUND_WARN)); - WarningAlert(str); + WarningAlert(GetString(STR_SLIRP_NO_DNS_FOUND_WARN)); return false; } } // Open ethernet device - const char *dev_name; + decltype(tstr(std::declval())) dev_name; switch (net_if_type) { case NET_IF_B2ETHER: - dev_name = PrefsFindString("etherguid"); + dev_name = tstr(PrefsFindString("etherguid")); if (dev_name == NULL || strcmp(name, "b2ether") != 0) - dev_name = name; + dev_name = tstr(name); break; case NET_IF_TAP: - dev_name = PrefsFindString("etherguid"); + dev_name = tstr(PrefsFindString("etherguid")); break; } if (net_if_type == NET_IF_B2ETHER) { @@ -272,17 +271,17 @@ bool ether_init(void) goto open_error; } - fd = PacketOpenAdapter( dev_name, ether_multi_mode ); + fd = PacketOpenAdapter( dev_name.get(), ether_multi_mode ); if (!fd) { - sprintf(str, "Could not open ethernet adapter %s.", dev_name); - WarningAlert(str); + _sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get()); + WarningAlert(buf); goto open_error; } // Get Ethernet address if(!PacketGetMAC(fd,ether_addr,ether_use_permanent)) { - sprintf(str, "Could not get hardware address of device %s. Ethernet is not available.", dev_name); - WarningAlert(str); + _sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get()); + WarningAlert(buf); goto open_error; } D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); @@ -306,28 +305,27 @@ bool ether_init(void) goto open_error; } - fd = tap_open_adapter(dev_name); + fd = tap_open_adapter(dev_name.get()); if (!fd) { - sprintf(str, "Could not open ethernet adapter %s.", dev_name); - WarningAlert(str); + _sntprintf(buf, lengthof(buf), TEXT("Could not open ethernet adapter %s."), dev_name.get()); + WarningAlert(buf); goto open_error; } if (!tap_check_version(fd)) { - sprintf(str, "Minimal TAP-Win32 version supported is %d.%d.", TAP_VERSION_MIN_MAJOR, TAP_VERSION_MIN_MINOR); - WarningAlert(str); + _sntprintf(buf, lengthof(buf), TEXT("Minimal TAP-Win32 version supported is %d.%d."), TAP_VERSION_MIN_MAJOR, TAP_VERSION_MIN_MINOR); + WarningAlert(buf); goto open_error; } if (!tap_set_status(fd, true)) { - sprintf(str, "Could not set media status to connected."); - WarningAlert(str); + WarningAlert("Could not set media status to connected."); goto open_error; } if (!tap_get_mac(fd, ether_addr)) { - sprintf(str, "Could not get hardware address of device %s. Ethernet is not available.", dev_name); - WarningAlert(str); + _sntprintf(buf, lengthof(buf), TEXT("Could not get hardware address of device %s. Ethernet is not available."), dev_name.get()); + WarningAlert(buf); goto open_error; } D(bug("Real ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); @@ -1168,15 +1166,15 @@ static bool set_wait_request(void) * TAP-Win32 glue */ -static LPADAPTER tap_open_adapter(const char *dev_name) +static LPADAPTER tap_open_adapter(LPCTSTR dev_name) { fd = (LPADAPTER)GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(*fd)); if (fd == NULL) return NULL; - char dev_path[MAX_PATH]; - snprintf(dev_path, sizeof(dev_path), - "\\\\.\\Global\\%s.tap", dev_name); + TCHAR dev_path[MAX_PATH]; + _sntprintf(dev_path, lengthof(dev_path), + TEXT("\\\\.\\Global\\%s.tap"), dev_name); HANDLE handle = CreateFile( dev_path, diff --git a/BasiliskII/src/Windows/extfs_windows.cpp b/BasiliskII/src/Windows/extfs_windows.cpp index 9cc171ad..f2b8a372 100755 --- a/BasiliskII/src/Windows/extfs_windows.cpp +++ b/BasiliskII/src/Windows/extfs_windows.cpp @@ -18,17 +18,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "sysdeps.h" +#include "main.h" +#include "extfs.h" +#include "extfs_defs.h" +#include "posix_emu.h" + #include #include #include #include #include -#include "sysdeps.h" -#include "extfs.h" -#include "extfs_defs.h" -#include "posix_emu.h" - #define DEBUG 0 #include "debug.h" @@ -127,8 +128,13 @@ static int open_helper(const char *path, const char *add, int flag) char helper_path[MAX_PATH_LENGTH]; make_helper_path(path, helper_path, add); - if ((flag & O_ACCMODE) == O_RDWR || (flag & O_ACCMODE) == O_WRONLY) + switch (flag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) { + case _O_WRONLY: + case _O_RDWR: flag |= O_CREAT; + break; + } + int fd = open(helper_path, flag, 0666); if (fd < 0) { if (/*errno == ENOENT &&*/ (flag & O_CREAT)) { diff --git a/BasiliskII/src/Windows/main_windows.cpp b/BasiliskII/src/Windows/main_windows.cpp index be9b5d94..7d555c98 100755 --- a/BasiliskII/src/Windows/main_windows.cpp +++ b/BasiliskII/src/Windows/main_windows.cpp @@ -30,7 +30,7 @@ #include #include -using std::string; +typedef std::basic_string tstring; #include "cpu_emulation.h" #include "sys.h" @@ -63,7 +63,7 @@ extern void flush_icache_range(uint8 *start, uint32 size); // from compemu_suppo // Constants -const char ROM_FILE_NAME[] = "ROM"; +const TCHAR ROM_FILE_NAME[] = TEXT("ROM"); const int SCRATCH_MEM_SIZE = 0x10000; // Size of scratch memory area @@ -235,8 +235,8 @@ int main(int argc, char **argv) } else if (strcmp(argv[i], "--config") == 0) { argv[i++] = NULL; if (i < argc) { - extern string UserPrefsPath; // from prefs_windows.cpp - UserPrefsPath = argv[i]; + extern tstring UserPrefsPath; // from prefs_windows.cpp + UserPrefsPath = to_tstring(argv[i]); argv[i] = NULL; } } else if (strcmp(argv[i], "--rominfo") == 0) { @@ -277,9 +277,11 @@ int main(int argc, char **argv) } } +#if 0 // Check that drivers are installed if (!check_drivers()) QuitEmulator(); +#endif // FIXME: default to DIB driver if (getenv("SDL_VIDEODRIVER") == NULL) @@ -359,10 +361,10 @@ int main(int argc, char **argv) D(bug("Mac ROM starts at %p (%08x)\n", ROMBaseHost, ROMBaseMac)); // Get rom file path from preferences - const char *rom_path = PrefsFindString("rom"); + auto rom_path = tstr(PrefsFindString("rom")); // Load Mac ROM - HANDLE rom_fh = CreateFile(rom_path ? rom_path : ROM_FILE_NAME, + HANDLE rom_fh = CreateFile(rom_path ? rom_path.get() : ROM_FILE_NAME, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, @@ -639,7 +641,12 @@ HWND GetMainWindowHandle(void) static void display_alert(int title_id, const char *text, int flags) { HWND hMainWnd = GetMainWindowHandle(); - MessageBox(hMainWnd, text, GetString(title_id), MB_OK | flags); + MessageBoxA(hMainWnd, text, GetString(title_id), MB_OK | flags); +} +static void display_alert(int title_id, const wchar_t *text, int flags) +{ + HWND hMainWnd = GetMainWindowHandle(); + MessageBoxW(hMainWnd, text, GetStringW(title_id).get(), MB_OK | flags); } @@ -655,6 +662,14 @@ void ErrorAlert(const char *text) VideoQuitFullScreen(); display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP); } +void ErrorAlert(const wchar_t *text) +{ + if (PrefsFindBool("nogui")) + return; + + VideoQuitFullScreen(); + display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP); +} /* @@ -668,6 +683,13 @@ void WarningAlert(const char *text) display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONINFORMATION); } +void WarningAlert(const wchar_t *text) +{ + if (PrefsFindBool("nogui")) + return; + + display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONINFORMATION); +} /* diff --git a/BasiliskII/src/Windows/posix_emu.cpp b/BasiliskII/src/Windows/posix_emu.cpp index f494ee51..518a526f 100755 --- a/BasiliskII/src/Windows/posix_emu.cpp +++ b/BasiliskII/src/Windows/posix_emu.cpp @@ -114,21 +114,21 @@ int my_errno = 0; #define VIRTUAL_ROOT_ID ((HANDLE)0xFFFFFFFE) -static const char *desktop_name = "Virtual Desktop"; +static LPCTSTR desktop_name = TEXT("Virtual Desktop"); static const char *custom_icon_name = "Icon\r"; #define my_computer GetString(STR_EXTFS_VOLUME_NAME) -static char lb1[MAX_PATH_LENGTH]; -static char lb2[MAX_PATH_LENGTH]; +static TCHAR lb1[MAX_PATH_LENGTH]; +static TCHAR lb2[MAX_PATH_LENGTH]; -#define MRP(path) translate(path,lb1) +#define MRP(path) translate(path,lb1) #define MRP2(path) translate(path,lb2) #define DISABLE_ERRORS UINT prevmode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS) #define RESTORE_ERRORS SetErrorMode(prevmode); -static char host_drive_list[512]; -static char virtual_root[248]; // Not _MAX_PATH +static TCHAR host_drive_list[512]; +static TCHAR virtual_root[248]; // Not _MAX_PATH const uint8 my_comp_icon[2670] = { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0xD8, 0x00, 0x00, 0x08, 0xD8, 0x00, 0x00, 0x00, 0x96, @@ -302,12 +302,12 @@ const uint8 my_comp_icon[2670] = { static bool use_streams[ 'Z'-'A'+1 ]; -static bool is_ntfs_volume( char *rootdir ) +static bool is_ntfs_volume(LPCTSTR rootdir) { bool ret = false; - char tst_file[_MAX_PATH], tst_stream[_MAX_PATH]; - sprintf( tst_file, "%sb2query.tmp", rootdir ); - sprintf( tst_stream, "%s:AFP_AfpInfo", tst_file ); + TCHAR tst_file[_MAX_PATH], tst_stream[_MAX_PATH]; + _sntprintf( tst_file, lengthof(tst_file), TEXT("%sb2query.tmp"), rootdir ); + _sntprintf( tst_stream, lengthof(tst_stream), TEXT("%s:AFP_AfpInfo"), tst_file ); if(!exists(tst_file)) { if(create_file( tst_file, 0 )) { if(create_file( tst_stream, 0 )) { @@ -353,12 +353,11 @@ void init_posix_emu(void) const char *extdrives = PrefsFindString("extdrives"); // Set up drive list. - int outinx = 0; - for( char letter = 'A'; letter <= 'Z'; letter++ ) { + size_t outinx = 0; + for( TCHAR letter = TEXT('A'); letter <= TEXT('Z'); letter++ ) { if(extdrives && !strchr(extdrives,letter)) continue; - int i = (int)( letter - 'A' ); - char rootdir[20]; - wsprintf( rootdir, "%c:\\", letter ); + TCHAR rootdir[20]; + _sntprintf( rootdir, lengthof(rootdir), TEXT("%c:\\"), letter ); use_streams[ letter - 'A' ] = false; switch(GetDriveType(rootdir)) { case DRIVE_FIXED: @@ -368,7 +367,7 @@ void init_posix_emu(void) // fall case DRIVE_REMOVABLE: case DRIVE_CDROM: - if(outinx < sizeof(host_drive_list)) { + if(outinx < lengthof(host_drive_list)) { host_drive_list[outinx] = letter; outinx += 2; } @@ -377,14 +376,13 @@ void init_posix_emu(void) // Set up virtual desktop root. // TODO: this should be customizable. - GetModuleFileName( NULL, virtual_root, sizeof(virtual_root) ); - char *p = strrchr( virtual_root, '\\' ); + GetModuleFileName( NULL, virtual_root, lengthof(virtual_root) ); + TCHAR *p = _tcsrchr( virtual_root, TEXT('\\') ); if(p) { - *(++p) = 0; - strcat( virtual_root, desktop_name ); + _tcscpy( ++p, desktop_name ); } else { // should never happen - sprintf( virtual_root, "C:\\%s", desktop_name ); + _sntprintf( virtual_root, lengthof(virtual_root), TEXT("C:\\%s"), desktop_name ); } CreateDirectory( virtual_root, 0 ); @@ -433,14 +431,14 @@ static void charset_host2mac( char *s ) } } -static void charset_mac2host( char *s ) +static void charset_mac2host( LPTSTR s ) { - int i, convert, len = strlen(s); + size_t len = _tcslen(s); - D(bug("charset_mac2host(%s)...\n", s)); + D(bug(TEXT("charset_mac2host(%s)...\n"), s)); - for( i=len-1; i>=0; i-- ) { - convert = 0; + for( size_t i=len; i-->0; ) { + bool convert = false; switch( (unsigned char)s[i] ) { // case '\r': // handled by "default" // case '\n': @@ -455,61 +453,61 @@ static void charset_mac2host( char *s ) case '>': case '|': case '%': - convert = 1; + convert = true; break; default: - if((unsigned char)s[i] < ' ') convert = 1; + if((unsigned char)s[i] < ' ') convert = true; break; } if(convert) { - char sml[10]; - sprintf( sml, "%%%02X", s[i] ); - memmove( &s[i+2], &s[i], strlen(&s[i])+1 ); - memmove( &s[i], sml, 3 ); + TCHAR sml[10]; + _sntprintf( sml, lengthof(sml), TEXT("%%%02X"), s[i] ); + memmove( &s[i+2], &s[i], (_tcslen(&s[i])+1) * sizeof(TCHAR) ); + memmove( &s[i], sml, 3 * sizeof(TCHAR) ); } } - D(bug("charset_mac2host = %s\n", s)); + D(bug(TEXT("charset_mac2host = %s\n"), s)); } static void make_mask( - char *mask, - const char *dir, - const char *a1, - const char *a2 + TCHAR *mask, + LPCTSTR dir, + LPCTSTR a1, + LPCTSTR a2 ) { - strcpy( mask, dir ); + _tcscpy( mask, dir ); - int len = strlen(mask); - if( len && mask[len-1] != '\\' ) strcat( mask, "\\" ); + size_t len = _tcslen(mask); + if( len && mask[len-1] != '\\' ) _tcscat( mask, TEXT("\\") ); - if( a1 ) strcat( mask, a1 ); - if( a2 ) strcat( mask, a2 ); + if( a1 ) _tcscat( mask, a1 ); + if( a2 ) _tcscat( mask, a2 ); } // !!UNC -static char *translate( const char *path, char *buffer ) +static LPTSTR translate( LPCTSTR path, TCHAR *buffer ) { - char *l = host_drive_list; - char *p = (char *)path; + TCHAR *l = host_drive_list; + const TCHAR *p = path; while(*l) { - if(toupper(p[1]) == toupper(*l)) break; - l += strlen(l) + 1; + if(_totupper(p[1]) == _totupper(*l)) break; + l += _tcslen(l) + 1; } - if(p[0] == '\\' && *l && (p[2] == 0 || p[2] == ':' || p[2] == '\\')) { + if(p[0] == TEXT('\\') && *l && (p[2] == 0 || p[2] == TEXT(':') || p[2] == TEXT('\\'))) { p += 2; - if(*p == ':') p++; - if(*p == '\\') p++; - sprintf( buffer, "%c:\\%s", *l, p ); + if(*p == TEXT(':')) p++; + if(*p == TEXT('\\')) p++; + _sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%c:\\%s"), *l, p ); } else { - if(*path == '\\') { - sprintf( buffer, "%s%s", virtual_root, path ); + if(*path == TEXT('\\')) { + _sntprintf( buffer, MAX_PATH_LENGTH, TEXT("%s%s"), virtual_root, path ); } else { - int len = strlen(path); - if(len == 0 || path[len-1] == '\\') { - make_mask( buffer, virtual_root, path, my_computer ); + int len = _tcslen(path); + if(len == 0 || path[len-1] == TEXT('\\')) { + make_mask( buffer, virtual_root, path, tstr(my_computer).get() ); } else { make_mask( buffer, virtual_root, path, 0 ); } @@ -521,10 +519,10 @@ static char *translate( const char *path, char *buffer ) } // helpers -static void strip_trailing_bs( char *path ) +static void strip_trailing_bs( LPTSTR path ) { - int len = strlen(path); - if(len > 0 && path[len-1] == '\\') path[len-1] = 0; + size_t len = _tcslen(path); + if(len > 0 && path[len-1] == TEXT('\\')) path[len-1] = 0; } #if 0 /* defined is util_windows.cpp */ @@ -546,7 +544,7 @@ static int exists( const char *p ) } #endif -static int is_dir( char *p ) +static int is_dir( LPCTSTR p ) { WIN32_FIND_DATA fdata; @@ -560,31 +558,31 @@ static int is_dir( char *p ) return result; } -static int myRemoveDirectory( const char *source ) +static int myRemoveDirectory( LPCTSTR source ) { HANDLE fh; WIN32_FIND_DATA FindFileData; int ok, result = 1; - char mask[_MAX_PATH]; + TCHAR mask[_MAX_PATH]; - D(bug("removing folder %s\n", source)); + D(bug(TEXT("removing folder %s\n"), source)); - make_mask( mask, source, "*.*", 0 ); + make_mask( mask, source, TEXT("*.*"), 0 ); fh = FindFirstFile( mask, &FindFileData ); ok = fh != INVALID_HANDLE_VALUE; while(ok) { make_mask( mask, source, FindFileData.cFileName, 0 ); - D(bug("removing item %s\n", mask)); + D(bug(TEXT("removing item %s\n"), mask)); int isdir = (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; if(isdir) { // must delete ".finf", ".rsrc" but not ".", ".." - if(strcmp(FindFileData.cFileName,".") && strcmp(FindFileData.cFileName,"..")) { + if(_tcscmp(FindFileData.cFileName,TEXT(".")) && _tcscmp(FindFileData.cFileName,TEXT(".."))) { result = myRemoveDirectory( mask ); if(!result) break; } } else { - D(bug("DeleteFile %s\n", mask)); + D(bug(TEXT("DeleteFile %s\n"), mask)); result = DeleteFile( mask ); if(!result) break; } @@ -592,41 +590,41 @@ static int myRemoveDirectory( const char *source ) } if(fh != INVALID_HANDLE_VALUE) FindClose( fh ); if(result) { - D(bug("RemoveDirectory %s\n", source)); + D(bug(TEXT("RemoveDirectory %s\n"), source)); result = RemoveDirectory( source ); } return result; } -static void make_folders( char *path ) +static void make_folders( LPCTSTR path ) { - char local_path[_MAX_PATH], *p; - strcpy( local_path, path ); - p = strrchr( local_path, '\\' ); + TCHAR local_path[_MAX_PATH], *p; + _tcscpy( local_path, path ); + p = _tcsrchr( local_path, TEXT('\\') ); if(p) { *p = 0; - if(strlen(local_path) > 3) { + if(_tcslen(local_path) > 3) { make_folders(local_path); - mkdir(local_path); + _tmkdir(local_path); } } } // !!UNC -static bool is_same_drive( char *p1, char *p2 ) +static bool is_same_drive( LPCTSTR p1, LPCTSTR p2 ) { - return toupper(*p1) == toupper(*p2); + return _totupper(*p1) == _totupper(*p2); } // Used when the drives are known to be different. // Can't use MoveFileEx() etc because of the Win9x limitations. // It would simulate CopyFile*() -- DeleteFile*() anyway -int file_move_copy( char *src, char *dst, bool delete_old ) +static int file_move_copy( LPCTSTR src, LPCTSTR dst, bool delete_old ) { int result = 0; my_errno = 0; - D(bug("file_copy %s -> %s\n", src, dst)); + D(bug(TEXT("file_copy %s -> %s\n"), src, dst)); // Fail if exists -- it's up to MacOS to move things to Trash if(CopyFile(src,dst,TRUE)) { @@ -644,24 +642,24 @@ int file_move_copy( char *src, char *dst, bool delete_old ) return result; } -int file_move( char *src, char *dst ) +static int file_move( LPCTSTR src, LPCTSTR dst ) { return file_move_copy( src, dst, true ); } -int file_copy( char *src, char *dst ) +static int file_copy( LPCTSTR src, LPCTSTR dst ) { return file_move_copy( src, dst, false ); } -int folder_copy( char *folder_src, char *folder_dst ) +static int folder_copy( LPCTSTR folder_src, LPCTSTR folder_dst ) { HANDLE fh; WIN32_FIND_DATA FindFileData; int ok, result = 0; - char mask[_MAX_PATH]; + TCHAR mask[_MAX_PATH]; - D(bug("copying folder %s -> \n", folder_src, folder_dst)); + D(bug(TEXT("copying folder %s -> \n"), folder_src, folder_dst)); my_errno = 0; @@ -670,18 +668,18 @@ int folder_copy( char *folder_src, char *folder_dst ) return -1; } - make_mask( mask, folder_src, "*.*", 0 ); + make_mask( mask, folder_src, TEXT("*.*"), 0 ); fh = FindFirstFile( mask, &FindFileData ); ok = fh != INVALID_HANDLE_VALUE; while(ok) { make_mask( mask, folder_src, FindFileData.cFileName, 0 ); int isdir = (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - char target[_MAX_PATH]; + TCHAR target[_MAX_PATH]; make_mask( target, folder_dst, FindFileData.cFileName, 0 ); - D(bug("copying item %s -> %s\n", mask, target)); + D(bug(TEXT("copying item %s -> %s\n"), mask, target)); if(isdir) { - if(strcmp(FindFileData.cFileName,".") && strcmp(FindFileData.cFileName,"..")) { + if(_tcscmp(FindFileData.cFileName,TEXT(".")) && _tcscmp(FindFileData.cFileName,TEXT(".."))) { result = folder_copy( mask, target ); if(result < 0) break; } @@ -715,12 +713,11 @@ static int make_dentry( struct DIR *d ) memset( &d->de, 0, sizeof(d->de) ); if(d->h != INVALID_HANDLE_VALUE) { if( (d->FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && - *d->FindFileData.cFileName == '.') + *d->FindFileData.cFileName == TEXT('.')) { ok = 0; } else { - strncpy( d->de.d_name, d->FindFileData.cFileName, sizeof(d->de.d_name)-1 ); - d->de.d_name[sizeof(d->de.d_name)-1] = 0; + strlcpy( d->de.d_name, d->FindFileData.cFileName, lengthof(d->de.d_name) ); charset_host2mac( d->de.d_name ); ok = 1; } @@ -739,14 +736,14 @@ struct dirent *readdir( struct DIR *d ) if(d->h == VIRTUAL_ROOT_ID) { make_dentry(d); de = &d->de; - d->vname_list += strlen(d->vname_list) + 1; + d->vname_list += _tcslen(d->vname_list) + 1; if(*d->vname_list) { - strcpy( d->FindFileData.cFileName, d->vname_list ); + _tcscpy( d->FindFileData.cFileName, d->vname_list ); d->FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; } else { // Out of static drive entries. Continue with other stuff. - char mask[MAX_PATH_LENGTH]; - make_mask( mask, virtual_root, "*.*", 0 ); + TCHAR mask[MAX_PATH_LENGTH]; + make_mask( mask, virtual_root, TEXT("*.*"), 0 ); d->h = FindFirstFile( mask, &d->FindFileData ); } } else { @@ -778,23 +775,24 @@ struct dirent *readdir( struct DIR *d ) struct DIR *opendir( const char *path ) { DISABLE_ERRORS; + auto tpath = tstr(path); DIR *d = new DIR; if(d) { memset( d, 0, sizeof(DIR) ); - if(*path == 0) { + if(*tpath.get() == 0) { d->vname_list = host_drive_list; if(d->vname_list) { d->h = VIRTUAL_ROOT_ID; - strcpy( d->FindFileData.cFileName, d->vname_list ); + _tcscpy( d->FindFileData.cFileName, d->vname_list ); d->FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; } else { d->h = INVALID_HANDLE_VALUE; } } else { - char mask[MAX_PATH_LENGTH]; - make_mask( mask, MRP(path), "*.*", 0 ); + TCHAR mask[MAX_PATH_LENGTH]; + make_mask( mask, MRP(tpath.get()), TEXT("*.*"), 0 ); - D(bug("opendir path=%s, mask=%s\n", path, mask)); + D(bug(TEXT("opendir path=%s, mask=%s\n"), tpath.get(), mask)); d->h = FindFirstFile( mask, &d->FindFileData ); if(d->h == INVALID_HANDLE_VALUE) { @@ -804,7 +802,7 @@ struct DIR *opendir( const char *path ) } } - D(bug("opendir(%s,%s) = %08x\n", path, MRP(path), d)); + D(bug(TEXT("opendir(%s,%s) = %08x\n"), tpath.get(), MRP(tpath.get()), d)); RESTORE_ERRORS; @@ -823,16 +821,17 @@ int my_stat( const char *path, struct my_stat *st ) { DISABLE_ERRORS; + auto tpath = tstr(path); int result; - if(*path == 0) { + if(*tpath.get() == 0) { /// virtual root memset( st, 0, sizeof(struct my_stat) ); st->st_mode = _S_IFDIR; result = 0; my_errno = 0; } else { - result = stat( MRP(path), (struct stat *)st ); + result = _tstat( MRP(tpath.get()), (struct _stat *)st ); if(result < 0) { my_errno = errno; } else { @@ -840,7 +839,7 @@ int my_stat( const char *path, struct my_stat *st ) } } - D(bug("stat(%s,%s) = %d\n", path, MRP(path), result)); + D(bug(TEXT("stat(%s,%s) = %d\n"), tpath.get(), MRP(tpath.get()), result)); if(result >= 0) dump_stat( st ); RESTORE_ERRORS; return result; @@ -849,7 +848,7 @@ int my_stat( const char *path, struct my_stat *st ) int my_fstat( int fd, struct my_stat *st ) { DISABLE_ERRORS; - int result = fstat( fd, (struct stat *)st ); + int result = _fstat( fd, (struct _stat *)st ); if(result < 0) { my_errno = errno; } else { @@ -865,24 +864,25 @@ int my_open( const char *path, int mode, ... ) { DISABLE_ERRORS; int result; - char *p = MRP(path); + auto tpath = tstr(path); + LPCTSTR p = MRP(tpath.get()); // Windows "open" does not handle _O_CREAT and _O_BINARY as it should if(mode & _O_CREAT) { if(exists(p)) { - result = open( p, mode & ~_O_CREAT ); - D(bug("open-nocreat(%s,%s,%d) = %d\n", path, p, mode, result)); + result = _topen( p, mode & ~_O_CREAT ); + D(bug(TEXT("open-nocreat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } else { - result = creat( p, _S_IWRITE|_S_IREAD ); + result = _tcreat( p, _S_IWRITE|_S_IREAD ); if(result < 0) { make_folders(p); - result = creat( p, _S_IWRITE|_S_IREAD ); + result = _tcreat( p, _S_IWRITE|_S_IREAD ); } - D(bug("open-creat(%s,%s,%d) = %d\n", path, p, mode, result)); + D(bug(TEXT("open-creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } } else { - result = open( p, mode ); - D(bug("open(%s,%s,%d) = %d\n", path, p, mode, result)); + result = _topen( p, mode ); + D(bug(TEXT("open(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); } if(result < 0) { my_errno = errno; @@ -898,15 +898,17 @@ int my_rename( const char *old_path, const char *new_path ) { DISABLE_ERRORS; int result = -1; - char *p_old = MRP(old_path); - char *p_new = MRP2(new_path); + auto told_path = tstr(old_path); + auto tnew_path = tstr(new_path); + LPCTSTR p_old = MRP(told_path.get()); + LPCTSTR p_new = MRP2(tnew_path.get()); result = my_access(old_path,0); if(result < 0) { // my_errno already set } else { if(is_same_drive(p_old,p_new)) { - result = rename( p_old, p_new ); + result = _trename( p_old, p_new ); if(result != 0) { // by definition, rename may also return a positive value to indicate an error my_errno = errno; } else { @@ -932,7 +934,7 @@ int my_rename( const char *old_path, const char *new_path ) } } } - D(bug("rename(%s,%s,%s,%s) = %d\n", old_path, p_old, new_path, p_new, result)); + D(bug(TEXT("rename(%s,%s,%s,%s) = %d\n"), told_path.get(), p_old, tnew_path.get(), p_new, result)); RESTORE_ERRORS; return result; } @@ -940,7 +942,8 @@ int my_rename( const char *old_path, const char *new_path ) int my_access( const char *path, int mode ) { DISABLE_ERRORS; - char *p = MRP(path); + auto tpath = tstr(path); + LPCTSTR p = MRP(tpath.get()); WIN32_FIND_DATA fdata; int result; @@ -968,7 +971,7 @@ int my_access( const char *path, int mode ) } } else { // W_OK, F_OK are ok. - result = access(p,mode); + result = _taccess(p,mode); if(result < 0) { my_errno = errno; } else { @@ -976,7 +979,7 @@ int my_access( const char *path, int mode ) } } - D(bug("access(%s,%s,%d) = %d\n", path, MRP(path), mode, result)); + D(bug(TEXT("access(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); RESTORE_ERRORS; return result; } @@ -984,19 +987,20 @@ int my_access( const char *path, int mode ) int my_mkdir( const char *path, int mode ) { DISABLE_ERRORS; - char *p = MRP(path); + auto tpath = tstr(path); + LPTSTR p = MRP(tpath.get()); strip_trailing_bs(p); - int result = mkdir( p ); + int result = _tmkdir( p ); if(result < 0) { make_folders(p); - result = mkdir( p ); + result = _tmkdir( p ); } if(result < 0) { my_errno = errno; } else { my_errno = 0; } - D(bug("mkdir(%s,%s,%d) = %d\n", path, p, mode, result)); + D(bug(TEXT("mkdir(%s,%s,%d) = %d\n"), tpath.get(), p, mode, result)); RESTORE_ERRORS; return result; } @@ -1004,13 +1008,14 @@ int my_mkdir( const char *path, int mode ) int my_remove( const char *path ) { DISABLE_ERRORS; - char *p = MRP(path); + auto tpath = tstr(path); + LPTSTR p = MRP(tpath.get()); strip_trailing_bs(p); int result; if(is_dir(p)) { result = myRemoveDirectory( p ); } else { - D(bug("DeleteFile %s\n", p)); + D(bug(TEXT("DeleteFile %s\n"), p)); result = DeleteFile( p ); } if(result) { @@ -1024,7 +1029,7 @@ int my_remove( const char *path ) my_errno = ENOENT; } } - D(bug("remove(%s,%s) = %d\n", path, p, result)); + D(bug(TEXT("remove(%s,%s) = %d\n"), tpath.get(), p, result)); RESTORE_ERRORS; return result; } @@ -1032,11 +1037,12 @@ int my_remove( const char *path ) int my_creat( const char *path, int mode ) { DISABLE_ERRORS; - char *p = MRP(path); - int result = creat( p, _S_IWRITE|_S_IREAD ); // note mode + auto tpath = tstr(path); + LPCTSTR p = MRP(tpath.get()); + int result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode if(result < 0) { make_folders(p); - result = creat( p, _S_IWRITE|_S_IREAD ); // note mode + result = _tcreat( p, _S_IWRITE|_S_IREAD ); // note mode } if(result < 0) { my_errno = errno; @@ -1044,7 +1050,7 @@ int my_creat( const char *path, int mode ) setmode(result, _O_BINARY); my_errno = 0; } - D(bug("creat(%s,%s,%d) = %d\n", path, p, mode,result)); + D(bug(TEXT("creat(%s,%s,%d) = %d\n"), tpath.get(), p, mode,result)); RESTORE_ERRORS; return result; } diff --git a/BasiliskII/src/Windows/posix_emu.h b/BasiliskII/src/Windows/posix_emu.h index 36de7f28..f5077558 100755 --- a/BasiliskII/src/Windows/posix_emu.h +++ b/BasiliskII/src/Windows/posix_emu.h @@ -39,7 +39,7 @@ typedef struct DIR { HANDLE h; WIN32_FIND_DATA FindFileData; dirent de; - char *vname_list; + TCHAR *vname_list; } DIR; // emulated diff --git a/BasiliskII/src/Windows/prefs_windows.cpp b/BasiliskII/src/Windows/prefs_windows.cpp index c7789fbc..ed837b86 100755 --- a/BasiliskII/src/Windows/prefs_windows.cpp +++ b/BasiliskII/src/Windows/prefs_windows.cpp @@ -24,7 +24,7 @@ #include #include -using std::string; +typedef std::basic_string tstring; #include "prefs.h" @@ -58,9 +58,9 @@ prefs_desc platform_prefs_items[] = { // Prefs file name and path -const char PREFS_FILE_NAME[] = "BasiliskII_prefs"; -string UserPrefsPath; -static string prefs_path; +const TCHAR PREFS_FILE_NAME[] = TEXT("BasiliskII_prefs"); +tstring UserPrefsPath; +static tstring prefs_path; /* @@ -72,16 +72,15 @@ void LoadPrefs(const char *vmdir) // Construct prefs path if (UserPrefsPath.empty()) { int pwd_len = GetCurrentDirectory(0, NULL); - char *pwd = new char[pwd_len]; - if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1) - prefs_path = string(pwd) + '\\'; - delete[] pwd; + prefs_path.resize(pwd_len); + pwd_len = GetCurrentDirectory(pwd_len, &prefs_path.front()); + prefs_path[pwd_len] = TEXT('\\'); prefs_path += PREFS_FILE_NAME; } else prefs_path = UserPrefsPath; // Read preferences from settings file - FILE *f = fopen(prefs_path.c_str(), "r"); + FILE *f = _tfopen(prefs_path.c_str(), TEXT("r")); if (f != NULL) { // Prefs file found, load settings @@ -103,7 +102,7 @@ void LoadPrefs(const char *vmdir) void SavePrefs(void) { FILE *f; - if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { + if ((f = _tfopen(prefs_path.c_str(), TEXT("w"))) != NULL) { SavePrefsToStream(f); fclose(f); } diff --git a/BasiliskII/src/Windows/router/arp.cpp b/BasiliskII/src/Windows/router/arp.cpp index ae60b40f..69a11879 100755 --- a/BasiliskII/src/Windows/router/arp.cpp +++ b/BasiliskII/src/Windows/router/arp.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "cpu_emulation.h" #include "prefs.h" #include "ether_windows.h" diff --git a/BasiliskII/src/Windows/router/dump.cpp b/BasiliskII/src/Windows/router/dump.cpp index 1944f224..4d3fe731 100755 --- a/BasiliskII/src/Windows/router/dump.cpp +++ b/BasiliskII/src/Windows/router/dump.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "dump.h" #if DEBUG diff --git a/BasiliskII/src/Windows/router/dynsockets.cpp b/BasiliskII/src/Windows/router/dynsockets.cpp index 89e1b975..77e9e0d1 100755 --- a/BasiliskII/src/Windows/router/dynsockets.cpp +++ b/BasiliskII/src/Windows/router/dynsockets.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "dynsockets.h" #include "dump.h" #include "main.h" @@ -40,7 +41,7 @@ Win95 b2 users who can't (or won't) upgrade. */ -static const char *wslib = "WS2_32.DLL"; +static LPCTSTR wslib = TEXT("WS2_32.DLL"); static HMODULE hWinsock32 = 0; static WSADATA WSAData; diff --git a/BasiliskII/src/Windows/router/ftp.cpp b/BasiliskII/src/Windows/router/ftp.cpp index 417e5d30..c25f57e0 100755 --- a/BasiliskII/src/Windows/router/ftp.cpp +++ b/BasiliskII/src/Windows/router/ftp.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include #include "dump.h" #include "prefs.h" diff --git a/BasiliskII/src/Windows/router/icmp.cpp b/BasiliskII/src/Windows/router/icmp.cpp index 969cff10..d6cb0e0e 100755 --- a/BasiliskII/src/Windows/router/icmp.cpp +++ b/BasiliskII/src/Windows/router/icmp.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "cpu_emulation.h" #include "ws2tcpip.h" #include "prefs.h" diff --git a/BasiliskII/src/Windows/router/iphelp.cpp b/BasiliskII/src/Windows/router/iphelp.cpp index 4dce669f..e77466e1 100755 --- a/BasiliskII/src/Windows/router/iphelp.cpp +++ b/BasiliskII/src/Windows/router/iphelp.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "cpu_emulation.h" #include "ether_windows.h" #include "ether.h" diff --git a/BasiliskII/src/Windows/router/ipsocket.cpp b/BasiliskII/src/Windows/router/ipsocket.cpp index 329621cb..21fef9a9 100755 --- a/BasiliskII/src/Windows/router/ipsocket.cpp +++ b/BasiliskII/src/Windows/router/ipsocket.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "cpu_emulation.h" #include "ws2tcpip.h" #include "prefs.h" diff --git a/BasiliskII/src/Windows/router/mib/interfaces.cpp b/BasiliskII/src/Windows/router/mib/interfaces.cpp index d2f2f35f..d89d407d 100755 --- a/BasiliskII/src/Windows/router/mib/interfaces.cpp +++ b/BasiliskII/src/Windows/router/mib/interfaces.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "interfaces.h" #include "../dump.h" #include "mibaccess.h" diff --git a/BasiliskII/src/Windows/router/mib/mibaccess.cpp b/BasiliskII/src/Windows/router/mib/mibaccess.cpp index d55e06ef..f877db9d 100755 --- a/BasiliskII/src/Windows/router/mib/mibaccess.cpp +++ b/BasiliskII/src/Windows/router/mib/mibaccess.cpp @@ -61,6 +61,7 @@ #include "sysdeps.h" +#include "main.h" #include "mibaccess.h" #include "../dynsockets.h" #include "../dump.h" @@ -71,9 +72,8 @@ #include "debug.h" -MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName ) +MibExtLoad::MibExtLoad( LPCTSTR MibDllName, LPCTSTR SnmpDllName ) { - m_Init = NULL; m_InitEx = NULL; @@ -88,10 +88,10 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName ) m_hInst = LoadLibrary( MibDllName ); if(!m_hInst) { - D(bug("MIB: library %s could not be loaded.\r\n", MibDllName)); + D(bug(TEXT("MIB: library %s could not be loaded.\r\n"), MibDllName)); return; } - D(bug("MIB: library %s loaded ok.\r\n", MibDllName)); + D(bug(TEXT("MIB: library %s loaded ok.\r\n"), MibDllName)); m_Init = (pSnmpExtensionInit)GetProcAddress(m_hInst ,"SnmpExtensionInit"); m_InitEx= (pSnmpExtensionInitEx)GetProcAddress(m_hInst ,"SnmpExtensionInitEx"); @@ -100,19 +100,19 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName ) if( !m_Init || !m_InitEx || !m_Query || !m_Trap ) { - D(bug("MIB: required entry points not found in library %s.\r\n", MibDllName)); + D(bug(TEXT("MIB: required entry points not found in library %s.\r\n"), MibDllName)); FreeLibrary( m_hInst ); m_hInst = NULL; } m_hInst_snmputil = LoadLibrary( SnmpDllName ); if(!m_hInst_snmputil){ - D(bug("MIB: library %s could not be loaded.\r\n", SnmpDllName)); + D(bug(TEXT("MIB: library %s could not be loaded.\r\n"), SnmpDllName)); FreeLibrary( m_hInst ); m_hInst = NULL; return; } - D(bug("MIB: library %s loaded ok.\r\n", SnmpDllName)); + D(bug(TEXT("MIB: library %s loaded ok.\r\n"), SnmpDllName)); m_SnmpUtilVarBindFree = (VOID (SNMP_FUNC_TYPE *)(SnmpVarBind *))GetProcAddress( m_hInst_snmputil, "SnmpUtilVarBindFree" ); m_SnmpUtilOidNCmp = (SNMPAPI (SNMP_FUNC_TYPE *)(AsnObjectIdentifier *, AsnObjectIdentifier *, UINT))GetProcAddress( m_hInst_snmputil, "SnmpUtilOidNCmp" ); @@ -120,7 +120,7 @@ MibExtLoad::MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName ) if( !m_SnmpUtilVarBindFree || !m_SnmpUtilOidNCmp || !m_SnmpUtilOidCpy ) { - D(bug("MIB: required entry points not found in library %s.\r\n", SnmpDllName)); + D(bug(TEXT("MIB: required entry points not found in library %s.\r\n"), SnmpDllName)); FreeLibrary( m_hInst ); FreeLibrary( m_hInst_snmputil ); m_hInst = NULL; @@ -181,7 +181,7 @@ BOOL MibExtLoad::Trap(AsnObjectIdentifier *enterprise, AsnInteger *genericTrap, return FALSE; } -MibII::MibII( bool load_winsock ):MibExtLoad("inetmib1.dll","snmpapi.dll") +MibII::MibII(bool load_winsock) : MibExtLoad(TEXT("inetmib1.dll"), TEXT("snmpapi.dll")) { WSADATA wsa; m_load_winsock = load_winsock; diff --git a/BasiliskII/src/Windows/router/mib/mibaccess.h b/BasiliskII/src/Windows/router/mib/mibaccess.h index 2511bfdd..385f5b85 100755 --- a/BasiliskII/src/Windows/router/mib/mibaccess.h +++ b/BasiliskII/src/Windows/router/mib/mibaccess.h @@ -38,7 +38,7 @@ typedef BOOL (WINAPI *pSnmpExtensionInitEx)(OUT AsnObjectIdentifier *supportedVi class MibExtLoad { public: - MibExtLoad( LPSTR MibDllName, LPSTR SnmpDllName ); + MibExtLoad( LPCTSTR MibDllName, LPCTSTR SnmpDllName ); ~MibExtLoad(); BOOL Init(DWORD dwTimeZeroReference,HANDLE *hPollForTrapEvent,AsnObjectIdentifier *supportedView); BOOL InitEx(AsnObjectIdentifier *supportedView); diff --git a/BasiliskII/src/Windows/router/router.cpp b/BasiliskII/src/Windows/router/router.cpp index 66086381..10fe2fd7 100755 --- a/BasiliskII/src/Windows/router/router.cpp +++ b/BasiliskII/src/Windows/router/router.cpp @@ -27,6 +27,7 @@ */ #include "sysdeps.h" +#include "main.h" #include diff --git a/BasiliskII/src/Windows/router/tcp.cpp b/BasiliskII/src/Windows/router/tcp.cpp index 72d9a262..4b0800dd 100755 --- a/BasiliskII/src/Windows/router/tcp.cpp +++ b/BasiliskII/src/Windows/router/tcp.cpp @@ -66,6 +66,7 @@ */ #include "sysdeps.h" +#include "main.h" #include diff --git a/BasiliskII/src/Windows/router/udp.cpp b/BasiliskII/src/Windows/router/udp.cpp index 21a94599..a76fc4ad 100755 --- a/BasiliskII/src/Windows/router/udp.cpp +++ b/BasiliskII/src/Windows/router/udp.cpp @@ -21,6 +21,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "cpu_emulation.h" #include "prefs.h" #include "ether_windows.h" diff --git a/BasiliskII/src/Windows/serial_windows.cpp b/BasiliskII/src/Windows/serial_windows.cpp index 4a1300b2..5a062b32 100755 --- a/BasiliskII/src/Windows/serial_windows.cpp +++ b/BasiliskII/src/Windows/serial_windows.cpp @@ -27,6 +27,7 @@ #include #include "main.h" +#include "util_windows.h" #include "macos_util.h" #include "prefs.h" #include "serial.h" @@ -38,7 +39,7 @@ #undef OutputDebugString #define OutputDebugString serial_log_write static void serial_log_write( char *s ); -#define SERIAL_LOG_FILE_NAME "serial.log" +#define SERIAL_LOG_FILE_NAME TEXT("serial.log") #include "debug.h" #undef D #define D(x) if(debug_serial != DB_SERIAL_NONE) (x); @@ -54,7 +55,7 @@ static int16 debug_serial = DB_SERIAL_NONE; static HANDLE serial_log_file = INVALID_HANDLE_VALUE; -static void serial_log_open( char *path ) +static void serial_log_open( LPCTSTR path ) { if(debug_serial == DB_SERIAL_NONE) return; @@ -108,28 +109,27 @@ static void serial_log_write( char *s ) // Driver private variables class XSERDPort : public SERDPort { public: - XSERDPort(const char *dev, const char *suffix) + XSERDPort(LPCTSTR dev, LPCTSTR suffix) { - D(bug("XSERDPort constructor %s\r\n", dev)); - // device_name = (char *)dev; + D(bug(TEXT("XSERDPort constructor %s\r\n"), dev)); read_pending = write_pending = false; if(dev) - strcpy( device_name, (char *)dev ); + _tcscpy( device_name, dev ); else *device_name = 0; - strupr(device_name); - is_parallel = (strncmp(device_name,"LPT",3) == 0); - is_file = (strncmp(device_name,"FILE",4) == 0); + _tcsupr(device_name); + is_parallel = (_tcsncmp(device_name, TEXT("LPT"), 3) == 0); + is_file = (_tcsncmp(device_name, TEXT("FILE"), 4) == 0); if(is_file) { char entry_name[20]; - wsprintf( entry_name, "portfile%s", suffix ); + _snprintf( entry_name, lengthof(entry_name), "portfile%s", str(suffix).get() ); const char *path = PrefsFindString(entry_name); if(path) { - strcpy( output_file_name, path ); + _tcscpy( output_file_name, tstr(path).get() ); } else { - strcpy( output_file_name, "C:\\B2TEMP.OUT" ); + _tcscpy( output_file_name, TEXT("C:\\B2TEMP.OUT") ); } } @@ -171,7 +171,7 @@ private: static int acknowledge_error(HANDLE h, bool is_read); bool set_timeouts(int bauds, int parity_bits, int stop_bits); - char device_name[256]; + TCHAR device_name[256]; HANDLE fd; bool io_killed; // Flag: KillIO called, I/O threads must not call deferred tasks @@ -193,7 +193,7 @@ private: bool is_parallel; // true if LPTx bool is_file; // true if FILE - char output_file_name[256]; + TCHAR output_file_name[256]; }; /* @@ -214,13 +214,13 @@ void SerialInit(void) if(port) { D(bug("SerialInit seriala=%s\r\n",port)); } - the_serd_port[0] = new XSERDPort(port,"0"); + the_serd_port[0] = new XSERDPort(tstr(port).get(), TEXT("0")); port = PrefsFindString("serialb"); if(port) { D(bug("SerialInit serialb=%s\r\n",port)); } - the_serd_port[1] = new XSERDPort(port,"1"); + the_serd_port[1] = new XSERDPort(tstr(port).get(), TEXT("1")); } @@ -249,7 +249,7 @@ int16 XSERDPort::open(uint16 config) if (!device_name || !*device_name) return openErr; - D(bug("XSERDPort::open device=%s,config=0x%X\r\n",device_name,(int)config)); + D(bug(TEXT("XSERDPort::open device=%s,config=0x%X\r\n"),device_name,(int)config)); // Init variables io_killed = false; @@ -268,7 +268,7 @@ int16 XSERDPort::open(uint16 config) } if(fd == INVALID_HANDLE_VALUE) { goto open_error; - D(bug("XSERDPort::open failed to open port %s\r\n",device_name)); + D(bug(TEXT("XSERDPort::open failed to open port %s\r\n"),device_name)); } if(is_serial) { @@ -1046,7 +1046,7 @@ unsigned int XSERDPort::input_func(void *arg) set_desktop(); #endif - D(bug("XSERDPort::input_func started for device %s\r\n",s->device_name)); + D(bug(TEXT("XSERDPort::input_func started for device %s\r\n"),s->device_name)); for (;;) { @@ -1131,7 +1131,7 @@ unsigned int XSERDPort::output_func(void *arg) set_desktop(); #endif - D(bug("XSERDPort::output_func started for device %s\r\n",s->device_name)); + D(bug(TEXT("XSERDPort::output_func started for device %s\r\n"),s->device_name)); for (;;) { diff --git a/BasiliskII/src/Windows/sys_windows.cpp b/BasiliskII/src/Windows/sys_windows.cpp index 9e3ed385..21e2df0e 100755 --- a/BasiliskII/src/Windows/sys_windows.cpp +++ b/BasiliskII/src/Windows/sys_windows.cpp @@ -23,12 +23,13 @@ #include #include -using std::string; +typedef std::basic_string tstring; #include using std::min; #include "main.h" +#include "util_windows.h" #include "macos_util.h" #include "prefs.h" #include "user_strings.h" @@ -45,7 +46,7 @@ using std::min; // File handles are pointers to these structures struct file_handle { - char *name; // Copy of device/file name + TCHAR *name; // Copy of device/file name HANDLE fh; bool is_file; // Flag: plain file or physical device? bool is_floppy; // Flag: floppy device @@ -149,8 +150,8 @@ void mount_removable_media(int media) CloseHandle(fh->fh); // Re-open device - char device_name[MAX_PATH]; - sprintf(device_name, "\\\\.\\%c:", fh->name[0]); + TCHAR device_name[MAX_PATH]; + _sntprintf(device_name, lengthof(device_name), TEXT("\\\\.\\%c:"), fh->name[0]); fh->fh = CreateFile( device_name, GENERIC_READ, @@ -230,11 +231,10 @@ void SysAddCDROMPrefs(void) if (PrefsFindBool("nocdrom")) return; - for (char letter = 'C'; letter <= 'Z'; letter++) { - int i = (int)(letter - 'A'); - string rootdir = letter + ":\\"; - if (GetDriveType(rootdir.c_str()) == DRIVE_CDROM) - PrefsAddString("cdrom", rootdir.c_str()); + char rootdir[] = "C:\\"; + for (; rootdir[0] <= 'Z'; rootdir[0]++) { + if (GetDriveTypeA(rootdir) == DRIVE_CDROM) + PrefsAddString("cdrom", rootdir); } } @@ -395,9 +395,9 @@ static bool is_cdrom_readable(file_handle *fh) * Check if NAME represents a read-only file */ -static bool is_read_only_path(const char *name) +static bool is_read_only_path(const TCHAR *name) { - DWORD attrib = GetFileAttributes((char *)name); + DWORD attrib = GetFileAttributes(name); return (attrib != INVALID_FILE_ATTRIBUTES && ((attrib & FILE_ATTRIBUTE_READONLY) != 0)); } @@ -411,25 +411,25 @@ void *Sys_open(const char *path_name, bool read_only) file_handle * fh = NULL; // Parse path name and options - char name[MAX_PATH]; - strcpy(name, path_name); + TCHAR name[MAX_PATH]; + tcslcpy(name, path_name, lengthof(name)); // Normalize floppy / cd path - int name_len = strlen(name); - if (name_len == 1 && isalpha(name[0])) - strcat(name, ":\\"); - if (name_len > 0 && name[name_len - 1] == ':') - strcat(name, "\\"); - name_len = strlen(name); + int name_len = _tcslen(name); + if (name_len == 1 && _istalpha(name[0])) + _tcscat(name, TEXT(":\\")); + if (name_len > 0 && name[name_len - 1] == TEXT(':')) + _tcscat(name, TEXT("\\")); + name_len = _tcslen(name); - D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write")); - if (name_len > 0 && name[name_len - 1] == '\\') { + D(bug(TEXT("Sys_open(%s, %s)\n"), name, read_only ? TEXT("read-only") : TEXT("read/write"))); + if (name_len > 0 && name[name_len - 1] == TEXT('\\')) { int type = GetDriveType(name); if (type == DRIVE_CDROM) { read_only = true; - char device_name[MAX_PATH]; - sprintf(device_name, "\\\\.\\%c:", name[0]); + TCHAR device_name[MAX_PATH]; + _sntprintf(device_name, lengthof(device_name), TEXT("\\\\.\\%c:"), name[0]); // Open device HANDLE h = CreateFile( @@ -439,7 +439,7 @@ void *Sys_open(const char *path_name, bool read_only) if (h != INVALID_HANDLE_VALUE) { fh = new file_handle; - fh->name = strdup(name); + fh->name = _tcsdup(name); fh->fh = h; fh->is_file = false; fh->read_only = read_only; @@ -478,7 +478,7 @@ void *Sys_open(const char *path_name, bool read_only) if (h != INVALID_HANDLE_VALUE) { fh = new file_handle; - fh->name = strdup(name); + fh->name = _tcsdup(name); fh->fh = h; fh->is_file = true; fh->read_only = read_only; diff --git a/BasiliskII/src/Windows/sysdeps.h b/BasiliskII/src/Windows/sysdeps.h index 8f6fa72b..c1d7898f 100755 --- a/BasiliskII/src/Windows/sysdeps.h +++ b/BasiliskII/src/Windows/sysdeps.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #define WIN32_LEAN_AND_MEAN #include diff --git a/BasiliskII/src/Windows/user_strings_windows.cpp b/BasiliskII/src/Windows/user_strings_windows.cpp index 3ca501be..c2241250 100755 --- a/BasiliskII/src/Windows/user_strings_windows.cpp +++ b/BasiliskII/src/Windows/user_strings_windows.cpp @@ -88,7 +88,7 @@ static const char *get_volume_name(void) // Try Windows 2000 key first if (ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", + TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), &hHelpKey)) { cbData = sizeof(volume); @@ -99,7 +99,7 @@ static const char *get_volume_name(void) if (volume[0] == 0 && ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, - "Software\\Classes\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", + TEXT("Software\\Classes\\CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), &hHelpKey)) { cbData = sizeof(volume); @@ -110,7 +110,7 @@ static const char *get_volume_name(void) if (volume[0] == 0 && ERROR_SUCCESS == RegOpenKey( HKEY_CLASSES_ROOT, - "CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", + TEXT("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), &hHelpKey)) { cbData = sizeof(volume); @@ -119,7 +119,7 @@ static const char *get_volume_name(void) } // Fix the error that some "tweak" apps do. - if (stricmp(volume, "%USERNAME% on %COMPUTER%") == 0) + if (_stricmp(volume, "%USERNAME% on %COMPUTER%") == 0) volume[0] = '\0'; // No volume name found, default to "My Computer" @@ -159,3 +159,21 @@ const char *GetString(int num) } return NULL; } + +/* + * Convert text to wide string, given the string number + */ +std::unique_ptr GetStringW(int num) +{ + auto str = GetString(num); + if (str == nullptr) + return nullptr; + + auto length = MultiByteToWideChar(CP_ACP, 0, str, -1, nullptr, 0); + if (length == 0) + return nullptr; + + auto p = std::unique_ptr(new wchar_t[length]); + MultiByteToWideChar(CP_ACP, 0, str, -1, p.get(), length); + return p; +} diff --git a/BasiliskII/src/Windows/user_strings_windows.h b/BasiliskII/src/Windows/user_strings_windows.h index 30bd3c72..ccf5ff54 100755 --- a/BasiliskII/src/Windows/user_strings_windows.h +++ b/BasiliskII/src/Windows/user_strings_windows.h @@ -1,5 +1,5 @@ /* - * user_strings_unix.h - Unix-specific localizable strings + * user_strings_windows.h - Windows-specific localizable strings * * Basilisk II (C) 1997-2008 Christian Bauer * @@ -18,8 +18,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef USER_STRINGS_UNIX_H -#define USER_STRINGS_UNIX_H +#ifndef USER_STRINGS_WINDOWS_H +#define USER_STRINGS_WINDOWS_H + +#ifdef __cplusplus +#if __cplusplus >= 201103L || _MSC_VER >= 1600 +#include + + // Convert text to wide string, given the string number +extern std::unique_ptr GetStringW(int num); +#endif +#endif enum { STR_NO_XVISUAL_ERR = 10000, diff --git a/BasiliskII/src/Windows/util_windows.cpp b/BasiliskII/src/Windows/util_windows.cpp index 130b8b8c..ef29a06b 100755 --- a/BasiliskII/src/Windows/util_windows.cpp +++ b/BasiliskII/src/Windows/util_windows.cpp @@ -31,13 +31,143 @@ using std::list; #include using std::string; +using std::wstring; +typedef std::basic_string tstring; -BOOL exists( const char *path ) +std::unique_ptr str(const wchar_t* s) +{ + auto length = WideCharToMultiByte(CP_ACP, 0, s, -1, nullptr, 0, nullptr, nullptr); + if (length == -1) + return nullptr; + + std::unique_ptr p(new char[length]); + WideCharToMultiByte(CP_ACP, 0, s, -1, p.get(), length, nullptr, nullptr); + return p; +} + +std::unique_ptr wstr(const char* s) +{ + auto length = MultiByteToWideChar(CP_ACP, 0, s, -1, nullptr, 0); + if (length == -1) + return nullptr; + + std::unique_ptr p(new wchar_t[length]); + MultiByteToWideChar(CP_ACP, 0, s, -1, p.get(), length); + return p; +} + +string to_string(const wchar_t* s) +{ + auto wlen = wcslen(s); // length without null terminator + auto len = WideCharToMultiByte(CP_ACP, 0, s, wlen, nullptr, 0, nullptr, nullptr); + if (len == -1) + return string(); + + string str(len, '\0'); + WideCharToMultiByte(CP_ACP, 0, s, wlen, &str.front(), len, nullptr, nullptr); + return str; +} + +wstring to_wstring(const char* s) +{ + auto len = strlen(s); // length without null terminator + auto wlen = MultiByteToWideChar(CP_ACP, 0, s, len, nullptr, 0); + if (len == -1) + return wstring(); + + wstring str(wlen, L'\0'); + MultiByteToWideChar(CP_ACP, 0, s, len, &str.front(), wlen); + return str; +} + +size_t strlcpy(char* dst, const char* src, size_t size) +{ + size_t length = strlen(src); + if (size-- > 0) { + if (length < size) + size = length; + memcpy(dst, src, size); + dst[size] = '\0'; + } + return length; +} + +size_t strlcpy(char* dst, const wchar_t* src, size_t size) +{ + size_t length = WideCharToMultiByte(CP_ACP, 0, src, -1, dst, size, nullptr, nullptr); + if (size > 0) { + if (length == 0) + return strlcpy(dst, str(src).get(), size); + --length; + } + return length; +} + +size_t strlcat(char* dst, const char* src, size_t size) +{ + char* end = static_cast(memchr(dst, '\0', size)); + if (end == nullptr) + return size; + size_t length = end - dst; + return length + strlcpy(end, src, size - length); +} + +size_t strlcat(char* dst, const wchar_t* src, size_t size) +{ + char* end = static_cast(memchr(dst, '\0', size)); + if (end == nullptr) + return size; + size_t length = end - dst; + return length + strlcpy(end, src, size - length); +} + +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t size) +{ + size_t length = wcslen(src); + if (size-- > 0) { + if (length < size) + size = length; + wmemcpy(dst, src, size); + dst[size] = '\0'; + } + return length; +} + +size_t wcslcpy(wchar_t* dst, const char* src, size_t size) +{ + size_t length = MultiByteToWideChar(CP_ACP, 0, src, -1, dst, size); + if (size > 0) { + if (length == 0) + return wcslcpy(dst, wstr(src).get(), size); + --length; + } + return length; +} + +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t size) +{ + wchar_t* end = wmemchr(dst, L'\0', size); + if (end == nullptr) + return size; + size_t length = end - dst; + return length + wcslcpy(end, src, size - length); +} + +size_t wcslcat(wchar_t* dst, const char* src, size_t size) +{ + wchar_t* end = wmemchr(dst, L'\0', size); + if (end == nullptr) + return size; + size_t length = end - dst; + return length + wcslcpy(end, src, size - length); +} + +BOOL exists( const TCHAR *path ) { HFILE h; bool ret = false; - h = _open( path, _O_RDONLY | _O_BINARY ); + h = _topen( path, _O_RDONLY | _O_BINARY ); if(h != -1) { ret = true; _close(h); @@ -45,7 +175,7 @@ BOOL exists( const char *path ) return(ret); } -BOOL create_file( const char *path, DWORD size ) +BOOL create_file( const TCHAR *path, DWORD size ) { HANDLE h; bool ok = false; @@ -80,7 +210,7 @@ BOOL create_file( const char *path, DWORD size ) return(ok); } -int32 get_file_size( const char *path ) +int32 get_file_size( const TCHAR *path ) { HANDLE h; DWORD size = 0; @@ -125,22 +255,22 @@ void kill_thread(HANDLE thread) bool check_drivers(void) { - char path[_MAX_PATH]; - GetSystemDirectory(path, sizeof(path)); - strcat(path, "\\drivers\\cdenable.sys"); + TCHAR path[_MAX_PATH]; + GetSystemDirectory(path, lengthof(path)); + _tcscat(path, TEXT("\\drivers\\cdenable.sys")); if (exists(path)) { int32 size = get_file_size(path); if (size != 6112) { - char str[256]; - sprintf(str, "The CD-ROM driver file \"%s\" is too old or corrupted.", path); + TCHAR str[256]; + _sntprintf(str, lengthof(str), TEXT("The CD-ROM driver file \"%s\" is too old or corrupted."), path); ErrorAlert(str); return false; } } else { - char str[256]; - sprintf(str, "The CD-ROM driver file \"%s\" is missing.", path); + TCHAR str[256]; + _sntprintf(str, lengthof(str), TEXT("The CD-ROM driver file \"%s\" is missing."), path); WarningAlert(str); } @@ -153,15 +283,15 @@ bool check_drivers(void) */ struct panel_reg { - string name; - string guid; + tstring name; + tstring guid; }; static list network_registry; typedef list::const_iterator network_registry_iterator; #define NETWORK_CONNECTIONS_KEY \ - "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" + TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}") static void get_network_registry(void) { @@ -184,14 +314,14 @@ static void get_network_registry(void) return; while (true) { - char enum_name[256]; - char connection_string[256]; + TCHAR enum_name[256]; + TCHAR connection_string[256]; HKEY connection_key; - char name_data[256]; + TCHAR name_data[256]; DWORD name_type; - const char name_string[] = "Name"; + const TCHAR name_string[] = TEXT("Name"); - len = sizeof (enum_name); + len = lengthof(enum_name); status = RegEnumKeyEx( network_connections_key, i, @@ -204,8 +334,8 @@ static void get_network_registry(void) if (status != ERROR_SUCCESS) break; - snprintf (connection_string, sizeof(connection_string), - "%s\\%s\\Connection", + _sntprintf (connection_string, lengthof(connection_string), + TEXT("%s\\%s\\Connection"), NETWORK_CONNECTIONS_KEY, enum_name); status = RegOpenKeyEx( @@ -216,7 +346,7 @@ static void get_network_registry(void) &connection_key); if (status == ERROR_SUCCESS) { - len = sizeof (name_data); + len = lengthof(name_data); status = RegQueryValueEx( connection_key, name_string, @@ -239,24 +369,24 @@ static void get_network_registry(void) RegCloseKey (network_connections_key); } -const char *ether_name_to_guid(const char *name) +const TCHAR *ether_name_to_guid(const TCHAR *name) { get_network_registry(); for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) { - if (strcmp((*it).name.c_str(), name) == 0) + if (_tcscmp((*it).name.c_str(), name) == 0) return (*it).guid.c_str(); } return NULL; } -const char *ether_guid_to_name(const char *guid) +const TCHAR *ether_guid_to_name(const TCHAR *guid) { get_network_registry(); for (network_registry_iterator it = network_registry.begin(); it != network_registry.end(); it++) { - if (strcmp((*it).guid.c_str(), guid) == 0) + if (_tcscmp((*it).guid.c_str(), guid) == 0) return (*it).name.c_str(); } @@ -268,11 +398,11 @@ const char *ether_guid_to_name(const char *guid) * Get TAP-Win32 adapters */ -#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}" +#define ADAPTER_KEY TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}") -#define TAP_COMPONENT_ID "tap0801" +#define TAP_COMPONENT_ID TEXT("tap0801") -const char *ether_tap_devices(void) +const TCHAR *ether_tap_devices(void) { HKEY adapter_key; LONG status; @@ -289,19 +419,19 @@ const char *ether_tap_devices(void) if (status != ERROR_SUCCESS) return NULL; - list devices; + list devices; while (true) { - char enum_name[256]; - char unit_string[256]; + TCHAR enum_name[256]; + TCHAR unit_string[256]; HKEY unit_key; - char component_id_string[] = "ComponentId"; - char component_id[256]; - char net_cfg_instance_id_string[] = "NetCfgInstanceId"; - char net_cfg_instance_id[256]; + TCHAR component_id_string[] = TEXT("ComponentId"); + TCHAR component_id[256]; + TCHAR net_cfg_instance_id_string[] = TEXT("NetCfgInstanceId"); + TCHAR net_cfg_instance_id[256]; DWORD data_type; - len = sizeof (enum_name); + len = lengthof(enum_name); status = RegEnumKeyEx( adapter_key, i, @@ -314,7 +444,7 @@ const char *ether_tap_devices(void) if (status != ERROR_SUCCESS) break; - snprintf (unit_string, sizeof(unit_string), "%s\\%s", + _sntprintf (unit_string, lengthof(unit_string), TEXT("%s\\%s"), ADAPTER_KEY, enum_name); status = RegOpenKeyEx( @@ -325,7 +455,7 @@ const char *ether_tap_devices(void) &unit_key); if (status == ERROR_SUCCESS) { - len = sizeof (component_id); + len = lengthof(component_id); status = RegQueryValueEx( unit_key, component_id_string, @@ -335,7 +465,7 @@ const char *ether_tap_devices(void) &len); if (status == ERROR_SUCCESS && data_type == REG_SZ) { - len = sizeof (net_cfg_instance_id); + len = lengthof(net_cfg_instance_id); status = RegQueryValueEx( unit_key, net_cfg_instance_id_string, @@ -345,7 +475,7 @@ const char *ether_tap_devices(void) &len); if (status == ERROR_SUCCESS && data_type == REG_SZ) { - if (!strcmp (component_id, TAP_COMPONENT_ID)) + if (!_tcscmp (component_id, TAP_COMPONENT_ID)) devices.push_back(net_cfg_instance_id); } } @@ -360,17 +490,17 @@ const char *ether_tap_devices(void) return NULL; // The result is a '\0' separated list of strings - list::const_iterator it; + list::const_iterator it; len = 0; for (it = devices.begin(); it != devices.end(); it++) len += (*it).length() + 1; - char *names = (char *)malloc(len); + TCHAR *names = (TCHAR *)malloc(len * sizeof(TCHAR)); if (names) { - char *p = names; + TCHAR *p = names; for (it = devices.begin(); it != devices.end(); it++) { len = (*it).length(); - strcpy(p, (*it).c_str()); + _tcscpy(p, (*it).c_str()); p[len] = '\0'; p += len + 1; } diff --git a/BasiliskII/src/Windows/util_windows.h b/BasiliskII/src/Windows/util_windows.h index b43a0074..26435558 100755 --- a/BasiliskII/src/Windows/util_windows.h +++ b/BasiliskII/src/Windows/util_windows.h @@ -23,9 +23,12 @@ #ifndef _UTIL_WINDOWS_H #define _UTIL_WINDOWS_H -BOOL exists( const char *path ); -int32 get_file_size( const char *path ); -BOOL create_file( const char *path, DWORD size ); +#include +#include + +BOOL exists( const TCHAR *path ); +int32 get_file_size( const TCHAR *path ); +BOOL create_file( const TCHAR *path, DWORD size ); bool check_drivers(void); // Thread wrappers @@ -44,10 +47,79 @@ class mutex_t { }; // Network control panel helpers -extern const char *ether_name_to_guid(const char *name); -extern const char *ether_guid_to_name(const char *guid); +extern const TCHAR *ether_name_to_guid(const TCHAR *name); +extern const TCHAR *ether_guid_to_name(const TCHAR *guid); // Get TAP-Win32 devices (caller free()s returned buffer) -extern const char *ether_tap_devices(void); +extern const TCHAR *ether_tap_devices(void); + +// Wide string versions of commonly used functions +extern void ErrorAlert(const wchar_t *text); +extern void WarningAlert(const wchar_t *text); + +// ----------------- String conversion functions ----------------- + +// Null deleter -- does nothing. Allows returning a non-owning +// unique_ptr. This should go away if observer_ptr makes it into +// the standard. +template struct null_delete { + constexpr null_delete() noexcept = default; + template null_delete(const null_delete&) noexcept { } + void operator ()(T*) const noexcept { } +}; +template struct null_delete { + constexpr null_delete() noexcept = default; + void operator ()(T*) const noexcept { } + template void operator ()(U*) const = delete; +}; + +// Functions returning null-terminated C strings +std::unique_ptr str(const wchar_t* s); +std::unique_ptr wstr(const char* s); + +inline std::unique_ptr> str(const char* s) +{ + return std::unique_ptr>(s); +} +inline std::unique_ptr> wstr(const wchar_t* s) +{ + return std::unique_ptr>(s); +} + +#ifdef _UNICODE +#define tstr wstr +#else +#define tstr str +#endif + +// Functions returning std::strings +std::string to_string(const wchar_t* s); +std::wstring to_wstring(const char* s); +inline std::string to_string(const char* s) { return std::string(s); } +inline std::wstring to_wstring(const wchar_t* s) { return std::wstring(s); } + +#ifdef _UNICODE +#define to_tstring to_wstring +#else +#define to_tstring to_string +#endif + +// BSD strlcpy/strlcat with overloads for converting between wide and narrow strings +size_t strlcpy(char* dst, const char* src, size_t size); +size_t strlcpy(char* dst, const wchar_t* src, size_t size); +size_t strlcat(char* dst, const char* src, size_t size); +size_t strlcat(char* dst, const wchar_t* src, size_t size); +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t size); +size_t wcslcpy(wchar_t* dst, const char* src, size_t size); +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t size); +size_t wcslcat(wchar_t* dst, const char* src, size_t size); + +#ifdef _UNICODE +#define tcslcpy wcslcpy +#define tcslcat wcslcat +#else +#define tcslcpy strlcpy +#define tcslcat strlcat +#endif #endif // _UTIL_WINDOWS_H diff --git a/BasiliskII/src/Windows/xpram_windows.cpp b/BasiliskII/src/Windows/xpram_windows.cpp index c47a9cb7..46c45040 100755 --- a/BasiliskII/src/Windows/xpram_windows.cpp +++ b/BasiliskII/src/Windows/xpram_windows.cpp @@ -21,18 +21,18 @@ #include "sysdeps.h" #include -using std::string; +typedef std::basic_string tstring; #include "xpram.h" // XPRAM file name and path #if POWERPC_ROM -const char XPRAM_FILE_NAME[] = "SheepShaver_nvram.dat"; +const TCHAR XPRAM_FILE_NAME[] = TEXT("SheepShaver_nvram.dat"); #else -const char XPRAM_FILE_NAME[] = "BasiliskII_xpram.dat"; +const TCHAR XPRAM_FILE_NAME[] = TEXT("BasiliskII_xpram.dat"); #endif -static string xpram_path; +static tstring xpram_path; /* @@ -43,9 +43,9 @@ static void build_xpram_path(void) { xpram_path.clear(); int pwd_len = GetCurrentDirectory(0, NULL); - char *pwd = new char[pwd_len]; + TCHAR *pwd = new TCHAR[pwd_len]; if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1) - xpram_path = string(pwd) + '\\'; + xpram_path = tstring(pwd) + TEXT('\\'); delete[] pwd; xpram_path += XPRAM_FILE_NAME; } diff --git a/BasiliskII/src/dummy/scsi_dummy.cpp b/BasiliskII/src/dummy/scsi_dummy.cpp index bed1055d..f46b85f0 100644 --- a/BasiliskII/src/dummy/scsi_dummy.cpp +++ b/BasiliskII/src/dummy/scsi_dummy.cpp @@ -19,6 +19,7 @@ */ #include "sysdeps.h" +#include "main.h" #include "scsi.h" #define DEBUG 0 diff --git a/BasiliskII/src/include/debug.h b/BasiliskII/src/include/debug.h index 47726e97..414ad324 100644 --- a/BasiliskII/src/include/debug.h +++ b/BasiliskII/src/include/debug.h @@ -30,24 +30,62 @@ #include #include -static void _cdecl inline winbug( char *s, ...) +static inline void _cdecl vwinbug(const char *s, va_list vargs) { - va_list vargs; char msg[1024], date[50], hours[50]; struct _timeb tstruct; _ftime( &tstruct ); _strtime( hours ); _strdate( date ); - sprintf( msg, "B2: %s %s:%03u ", date, hours, tstruct.millitm ); - - va_start( vargs, s ); - vsprintf( &msg[strlen(msg)], s, vargs ); - va_end( vargs ); + _snprintf( msg, lengthof(msg), "B2: %s %s:%03u ", date, hours, tstruct.millitm ); - OutputDebugString(msg); + char *rest = &msg[strlen(msg)]; + _vsnprintf( rest, lengthof(msg) - (rest - msg), s, vargs ); + + OutputDebugStringA(msg); } +static inline void _cdecl vwwinbug( const wchar_t *s, va_list vargs) +{ + wchar_t msg[1024], date[50], hours[50]; + struct _timeb tstruct; + + _ftime( &tstruct ); + _wstrtime( hours ); + _wstrdate( date ); + _snwprintf( msg, lengthof(msg), L"B2: %s %s:%03u ", date, hours, tstruct.millitm ); + + wchar_t *rest = &msg[wcslen(msg)]; + _vsnwprintf( rest, lengthof(msg) - (rest - msg), s, vargs ); + + OutputDebugStringW(msg); +} +static inline void _cdecl winbug( const char *s, ...) +{ + va_list vargs; + va_start(vargs, s); + vwinbug(s, vargs); + va_end(vargs); +} +static inline void _cdecl wwinbug(const wchar_t *s, ...) +{ + va_list vargs; + va_start(vargs, s); + vwwinbug(s, vargs); + va_end(vargs); +} + +#ifdef __cplusplus +static inline void _cdecl winbug(wchar_t *s, ...) +{ + va_list vargs; + va_start(vargs, s); + vwwinbug(s, vargs); + va_end(vargs); +} +#endif #define bug winbug +#define wbug wwinbug #elif defined(AMIGA) From 1c9b9ba7a81bab20365d730db47142c196de4c95 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:35:51 -0700 Subject: [PATCH 17/19] Added MSVC-friendly config.h. --- BasiliskII/src/Windows/config.h | 260 ++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 BasiliskII/src/Windows/config.h diff --git a/BasiliskII/src/Windows/config.h b/BasiliskII/src/Windows/config.h new file mode 100644 index 00000000..88bd0904 --- /dev/null +++ b/BasiliskII/src/Windows/config.h @@ -0,0 +1,260 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Define if using video enabled on SEGV signals. */ +#ifndef _DEBUG +#define ENABLE_VOSF 1 +#endif + +/* Define to 1 if you have the `acoshl' function. */ +#define HAVE_ACOSHL 1 + +/* Define to 1 if you have the `acosl' function. */ +#define HAVE_ACOSL 1 + +/* Define to 1 if you have the `asinhl' function. */ +#define HAVE_ASINHL 1 + +/* Define to 1 if you have the `asinl' function. */ +#define HAVE_ASINL 1 + +/* Define to 1 if you have the `atanh' function. */ +#define HAVE_ATANH 1 + +/* Define to 1 if you have the `atanhl' function. */ +#define HAVE_ATANHL 1 + +/* Define to 1 if you have the `atanl' function. */ +#define HAVE_ATANL 1 + +/* Define to 1 if the system has the type `caddr_t'. */ +/* #undef HAVE_CADDR_T */ + +/* Define to 1 if you have the `ceill' function. */ +#define HAVE_CEILL 1 + +/* Define to 1 if you have the `coshl' function. */ +#define HAVE_COSHL 1 + +/* Define to 1 if you have the `cosl' function. */ +#define HAVE_COSL 1 + +/* Define to 1 if you have the `expl' function. */ +/* #undef HAVE_EXPL */ + +/* Define to 1 if you have the `fabsl' function. */ +/* #undef HAVE_FABSL */ + +/* Define to 1 if you have the `finite' function. */ +#define HAVE_FINITE 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FLOATINGPOINT_H */ + +/* Define to 1 if you have the `floorl' function. */ +#define HAVE_FLOORL 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEE754_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEEFP_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `isinf' function. */ +/* #undef HAVE_ISINF */ + +/* Define to 1 if you have the `isinfl' function. */ +/* #undef HAVE_ISINFL */ + +/* Define to 1 if you have the `isnan' function. */ +#define HAVE_ISNAN 1 + +/* Define to 1 if you have the `isnanl' function. */ +/* #undef HAVE_ISNANL */ + +/* Define to 1 if you have the `isnormal' function. */ +/* #undef HAVE_ISNORMAL */ + +/* Define to 1 if the system has the type `loff_t'. */ +/* #undef HAVE_LOFF_T */ + +/* Define to 1 if you have the `log10l' function. */ +/* #undef HAVE_LOG10L */ + +/* Define to 1 if you have the `logl' function. */ +/* #undef HAVE_LOGL */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NAN_H */ + +/* Define to 1 if you have the `powl' function. */ +#define HAVE_POWL 1 + +/* Define to 1 if you have the `signbit' function. */ +/* #undef HAVE_SIGNBIT */ + +/* Define if we can ignore the fault (instruction skipping in SIGSEGV + handler). */ +#define HAVE_SIGSEGV_SKIP_INSTRUCTION 1 + +/* Define to 1 if you have the `sinhl' function. */ +#define HAVE_SINHL 1 + +/* Define to 1 if you have the `sinl' function. */ +#define HAVE_SINL 1 + +/* Define to 1 if you have the `sqrtl' function. */ +#define HAVE_SQRTL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STRINGS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the `tanhl' function. */ +#define HAVE_TANHL 1 + +/* Define to 1 if you have the `tanl' function. */ +#define HAVE_TANL 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UNISTD_H */ + +/* Define if your system supports Windows exceptions. */ +#define HAVE_WIN32_EXCEPTIONS 1 + +/* Define if your system has a working Win32-based memory allocator. */ +#define HAVE_WIN32_VM 1 + +/* Define to the floating point format of the host machine. */ +#define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT + +/* Define to 1 if the host machine stores floating point numbers in memory + with the word containing the sign bit at the lowest address, or to 0 if it + does it the other way around. This macro should not be defined if the + ordering is the same as for multi-word integers. */ +/* #undef HOST_FLOAT_WORDS_BIG_ENDIAN */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Define this program name. */ +#define PACKAGE "Basilisk II" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "Christian.Bauer@uni-mainz.de" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Basilisk II" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Basilisk II 1.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "BasiliskII" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.0" + +/* The size of `double', as computed by sizeof. */ +#define SIZEOF_DOUBLE 8 + +/* The size of `float', as computed by sizeof. */ +#define SIZEOF_FLOAT 4 + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `long double', as computed by sizeof. */ +#define SIZEOF_LONG_DOUBLE 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 4 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to enble SDL support */ +#define USE_SDL 1 + +/* Define to enable SDL audio support */ +#define USE_SDL_AUDIO 1 + +/* Define to enable SDL video graphics support */ +#define USE_SDL_VIDEO 1 + +/* Define this program version. */ +#define VERSION "1.0" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ From 6cd37656b48c1688ddf65695224468ad59ecd654 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 02:37:05 -0700 Subject: [PATCH 18/19] Added Visual Studio 2015 project files. --- .../src/Windows/BasiliskII.DebugJIT.props | 14 + .../src/Windows/BasiliskII.ReleaseJIT.props | 14 + BasiliskII/src/Windows/BasiliskII.props | 14 + BasiliskII/src/Windows/BasiliskII.sln | 140 ++++ BasiliskII/src/Windows/BasiliskII.vcxproj | 685 ++++++++++++++++++ .../src/Windows/BasiliskII.vcxproj.filters | 589 +++++++++++++++ BasiliskII/src/Windows/build68k.vcxproj | 156 ++++ .../src/Windows/build68k.vcxproj.filters | 22 + BasiliskII/src/Windows/gencomp.vcxproj | 182 +++++ .../src/Windows/gencomp.vcxproj.filters | 36 + BasiliskII/src/Windows/gencpu.vcxproj | 182 +++++ BasiliskII/src/Windows/gencpu.vcxproj.filters | 36 + 12 files changed, 2070 insertions(+) create mode 100644 BasiliskII/src/Windows/BasiliskII.DebugJIT.props create mode 100644 BasiliskII/src/Windows/BasiliskII.ReleaseJIT.props create mode 100644 BasiliskII/src/Windows/BasiliskII.props create mode 100644 BasiliskII/src/Windows/BasiliskII.sln create mode 100644 BasiliskII/src/Windows/BasiliskII.vcxproj create mode 100644 BasiliskII/src/Windows/BasiliskII.vcxproj.filters create mode 100644 BasiliskII/src/Windows/build68k.vcxproj create mode 100644 BasiliskII/src/Windows/build68k.vcxproj.filters create mode 100644 BasiliskII/src/Windows/gencomp.vcxproj create mode 100644 BasiliskII/src/Windows/gencomp.vcxproj.filters create mode 100644 BasiliskII/src/Windows/gencpu.vcxproj create mode 100644 BasiliskII/src/Windows/gencpu.vcxproj.filters diff --git a/BasiliskII/src/Windows/BasiliskII.DebugJIT.props b/BasiliskII/src/Windows/BasiliskII.DebugJIT.props new file mode 100644 index 00000000..124285ea --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.DebugJIT.props @@ -0,0 +1,14 @@ + + + + + $(ProjectDir)Debug\ + + + + + + $(ToolsDir) + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/BasiliskII.ReleaseJIT.props b/BasiliskII/src/Windows/BasiliskII.ReleaseJIT.props new file mode 100644 index 00000000..c67b5361 --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.ReleaseJIT.props @@ -0,0 +1,14 @@ + + + + + $(ProjectDir)Release\ + + + + + + $(ToolsDir) + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/BasiliskII.props b/BasiliskII/src/Windows/BasiliskII.props new file mode 100644 index 00000000..345f9f06 --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.props @@ -0,0 +1,14 @@ + + + + + $(OutDir) + + + + + + $(ToolsDir) + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/BasiliskII.sln b/BasiliskII/src/Windows/BasiliskII.sln new file mode 100644 index 00000000..1c4b7a1f --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.sln @@ -0,0 +1,140 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasiliskII", "BasiliskII.vcxproj", "{1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}" + ProjectSection(ProjectDependencies) = postProject + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48} = {1A9EA738-8DA7-422F-9E0D-BE92893C0E48} + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04} = {95933FE9-C27C-41F0-B4AF-EAAADE94FD04} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "build68k", "build68k.vcxproj", "{7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gencpu", "gencpu.vcxproj", "{1A9EA738-8DA7-422F-9E0D-BE92893C0E48}" + ProjectSection(ProjectDependencies) = postProject + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0} = {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gencomp", "gencomp.vcxproj", "{95933FE9-C27C-41F0-B4AF-EAAADE94FD04}" + ProjectSection(ProjectDependencies) = postProject + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0} = {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDLmain", "..\..\..\..\SDL-1.2.15\VisualC\SDLmain\SDLmain.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL", "..\..\..\..\SDL-1.2.15\VisualC\SDL\SDL.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug JIT|x64 = Debug JIT|x64 + Debug JIT|x86 = Debug JIT|x86 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release JIT|x64 = Release JIT|x64 + Release JIT|x86 = Release JIT|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug JIT|x64.ActiveCfg = Debug JIT|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug JIT|x64.Build.0 = Debug JIT|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug JIT|x86.ActiveCfg = Debug JIT|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug JIT|x86.Build.0 = Debug JIT|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug|x64.ActiveCfg = Debug|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug|x64.Build.0 = Debug|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug|x86.ActiveCfg = Debug|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Debug|x86.Build.0 = Debug|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release JIT|x64.ActiveCfg = Release JIT|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release JIT|x64.Build.0 = Release JIT|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release JIT|x86.ActiveCfg = Release JIT|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release JIT|x86.Build.0 = Release JIT|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release|x64.ActiveCfg = Release|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release|x64.Build.0 = Release|x64 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release|x86.ActiveCfg = Release|Win32 + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0}.Release|x86.Build.0 = Release|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug JIT|x64.ActiveCfg = Debug|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug JIT|x64.Build.0 = Debug|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug JIT|x86.ActiveCfg = Debug|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug JIT|x86.Build.0 = Debug|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug|x64.ActiveCfg = Debug|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug|x64.Build.0 = Debug|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug|x86.ActiveCfg = Debug|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Debug|x86.Build.0 = Debug|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release JIT|x64.ActiveCfg = Release|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release JIT|x64.Build.0 = Release|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release JIT|x86.ActiveCfg = Release|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release JIT|x86.Build.0 = Release|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release|x64.ActiveCfg = Release|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release|x64.Build.0 = Release|x64 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release|x86.ActiveCfg = Release|Win32 + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0}.Release|x86.Build.0 = Release|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug JIT|x64.ActiveCfg = Debug|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug JIT|x64.Build.0 = Debug|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug JIT|x86.ActiveCfg = Debug|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug JIT|x86.Build.0 = Debug|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug|x64.ActiveCfg = Debug|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug|x64.Build.0 = Debug|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug|x86.ActiveCfg = Debug|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Debug|x86.Build.0 = Debug|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release JIT|x64.ActiveCfg = Release|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release JIT|x64.Build.0 = Release|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release JIT|x86.ActiveCfg = Release|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release JIT|x86.Build.0 = Release|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release|x64.ActiveCfg = Release|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release|x64.Build.0 = Release|x64 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release|x86.ActiveCfg = Release|Win32 + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48}.Release|x86.Build.0 = Release|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug JIT|x64.ActiveCfg = Debug|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug JIT|x64.Build.0 = Debug|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug JIT|x86.ActiveCfg = Debug|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug JIT|x86.Build.0 = Debug|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug|x64.ActiveCfg = Debug|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug|x64.Build.0 = Debug|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug|x86.ActiveCfg = Debug|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Debug|x86.Build.0 = Debug|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release JIT|x64.ActiveCfg = Release|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release JIT|x64.Build.0 = Release|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release JIT|x86.ActiveCfg = Release|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release JIT|x86.Build.0 = Release|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release|x64.ActiveCfg = Release|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release|x64.Build.0 = Release|x64 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release|x86.ActiveCfg = Release|Win32 + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04}.Release|x86.Build.0 = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug JIT|x64.ActiveCfg = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug JIT|x64.Build.0 = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug JIT|x86.ActiveCfg = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug JIT|x86.Build.0 = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.ActiveCfg = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x64.Build.0 = Debug|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x86.ActiveCfg = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Debug|x86.Build.0 = Debug|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release JIT|x64.ActiveCfg = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release JIT|x64.Build.0 = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release JIT|x86.ActiveCfg = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release JIT|x86.Build.0 = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.ActiveCfg = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x86.ActiveCfg = Release|Win32 + {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x86.Build.0 = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug JIT|x64.ActiveCfg = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug JIT|x64.Build.0 = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug JIT|x86.ActiveCfg = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug JIT|x86.Build.0 = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x86.ActiveCfg = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x86.Build.0 = Debug|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release JIT|x64.ActiveCfg = Release|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release JIT|x64.Build.0 = Release|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release JIT|x86.ActiveCfg = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release JIT|x86.Build.0 = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x86.ActiveCfg = Release|Win32 + {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BasiliskII/src/Windows/BasiliskII.vcxproj b/BasiliskII/src/Windows/BasiliskII.vcxproj new file mode 100644 index 00000000..cd05c309 --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.vcxproj @@ -0,0 +1,685 @@ + + + + + Debug JIT + Win32 + + + Debug JIT + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release JIT + Win32 + + + Release JIT + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + + + true + true + true + true + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {81ce8daf-ebb2-4761-8e45-b71abcca8c68} + + + {da956fd3-e142-46f2-9dd5-c78bebb56b7a} + + + + {1AAA5D96-9498-4EB5-A436-0143E2B7A0B0} + Win32Proj + BasiliskII + 8.1 + + + + Application + true + v140_xp + Unicode + + + Application + true + v140_xp + Unicode + + + Application + true + v140_xp + Unicode + + + Application + true + v140_xp + Unicode + + + Application + false + v140_xp + true + Unicode + + + Application + false + v140_xp + true + Unicode + + + Application + false + v140_xp + true + Unicode + + + Application + false + v140_xp + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + ClCompile + + + ClCompile + true + + + true + $(Configuration)\$(ProjectName)\ + ClCompile + + + ClCompile + true + + + false + $(Configuration)\$(ProjectName)\ + ClCompile + + + ClCompile + false + + + false + $(Configuration)\$(ProjectName)\ + ClCompile + + + ClCompile + false + + + + + + Level3 + Disabled + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + + + Level3 + Disabled + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + + + Level3 + Disabled + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;USE_JIT;USE_JIT_FPU;JIT_DEBUG;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + + + Level3 + Disabled + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;USE_JIT;USE_JIT_FPU;JIT_DEBUG;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;OPTIMIZED_FLAGS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + true + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;OPTIMIZED_FLAGS;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + true + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;OPTIMIZED_FLAGS;USE_JIT;USE_JIT_FPU;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + true + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H;DIRECT_ADDRESSING;UNALIGNED_PROFITABLE;MSVC_INTRINSICS;OPTIMIZED_FLAGS;SAHF_SETO_PROFITABLE;FPU_IEEE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;OPTIMIZED_FLAGS;USE_JIT;USE_JIT_FPU;%(PreprocessorDefinitions) + ..\include;..\uae_cpu;.;..\CrossPlatform;..\slirp;..\..\..\..\SDL-1.2.15\include + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + $(IntDir)%(RelativeDir) + + + Windows + true + true + true + WS2_32.lib;IPHlpApi.lib;%(AdditionalDependencies) + + + cd ..\uae_cpu +"$(ToolsDir)gencpu" +"$(ToolsDir)gencomp" + + + + Generating CPU emulation sources... + + + ..\uae_cpu\cpustbl.cpp;..\uae_cpu\cpustbl_nf.cpp;..\uae_cpu\cputbl.h;..\uae_cpu\cpuemu.cpp;..\uae_cpu\cpuemu_nf.cpp;..\uae_cpu\compstbl.cpp;..\uae_cpu\comptbl.h;..\uae_cpu\compemu.cpp;%(Outputs) + + + $(ToolsDir)gencpu.exe;$(ToolsDir)gencomp.exe + + + + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/BasiliskII.vcxproj.filters b/BasiliskII/src/Windows/BasiliskII.vcxproj.filters new file mode 100644 index 00000000..50eae3d1 --- /dev/null +++ b/BasiliskII/src/Windows/BasiliskII.vcxproj.filters @@ -0,0 +1,589 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/build68k.vcxproj b/BasiliskII/src/Windows/build68k.vcxproj new file mode 100644 index 00000000..b29e072d --- /dev/null +++ b/BasiliskII/src/Windows/build68k.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {7BCEAB0D-0C62-46E1-BA1E-AF42798B67D0} + Win32Proj + build68k + 8.1 + + + + Application + true + v140 + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + + + true + + + false + $(Configuration)\$(ProjectName)\ + + + false + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/build68k.vcxproj.filters b/BasiliskII/src/Windows/build68k.vcxproj.filters new file mode 100644 index 00000000..65e38167 --- /dev/null +++ b/BasiliskII/src/Windows/build68k.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/gencomp.vcxproj b/BasiliskII/src/Windows/gencomp.vcxproj new file mode 100644 index 00000000..b2c92701 --- /dev/null +++ b/BasiliskII/src/Windows/gencomp.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {95933FE9-C27C-41F0-B4AF-EAAADE94FD04} + Win32Proj + gencomp + 8.1 + + + + Application + true + v140 + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + + + true + + + false + $(Configuration)\$(ProjectName)\ + + + false + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + + + + + + + + + Document + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + Generating cpudefs.cpp... + Generating cpudefs.cpp... + Generating cpudefs.cpp... + Generating cpudefs.cpp... + ..\uae_cpu\cpudefs.cpp + ..\uae_cpu\cpudefs.cpp + ..\uae_cpu\cpudefs.cpp + ..\uae_cpu\cpudefs.cpp + $(OutDir)build68k.exe + $(OutDir)build68k.exe + $(OutDir)build68k.exe + $(OutDir)build68k.exe + + + + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/gencomp.vcxproj.filters b/BasiliskII/src/Windows/gencomp.vcxproj.filters new file mode 100644 index 00000000..861ff2a3 --- /dev/null +++ b/BasiliskII/src/Windows/gencomp.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/gencpu.vcxproj b/BasiliskII/src/Windows/gencpu.vcxproj new file mode 100644 index 00000000..c688794b --- /dev/null +++ b/BasiliskII/src/Windows/gencpu.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {1A9EA738-8DA7-422F-9E0D-BE92893C0E48} + Win32Proj + gencpu + 8.1 + + + + Application + true + v140 + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + + + true + + + false + $(Configuration)\$(ProjectName)\ + + + false + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + . + + + Console + true + true + true + + + + + + + + + + + + + Document + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + Generating cpudefs.cpp... + Generating cpudefs.cpp... + ..\uae_cpu\cpudefs.cpp + ..\uae_cpu\cpudefs.cpp + $(OutDir)build68k.exe + $(OutDir)build68k.exe + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + "$(OutDir)build68k" "%(Identity)" > ..\uae_cpu\cpudefs.cpp + Generating cpudefs.cpp... + Generating cpudefs.cpp... + ..\uae_cpu\cpudefs.cpp + ..\uae_cpu\cpudefs.cpp + $(OutDir)build68k.exe + $(OutDir)build68k.exe + + + + + + \ No newline at end of file diff --git a/BasiliskII/src/Windows/gencpu.vcxproj.filters b/BasiliskII/src/Windows/gencpu.vcxproj.filters new file mode 100644 index 00000000..d8db474e --- /dev/null +++ b/BasiliskII/src/Windows/gencpu.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + + + + \ No newline at end of file From 0a9a4d03673eb14a2bfed20d175067e2bc3a6e37 Mon Sep 17 00:00:00 2001 From: James Touton Date: Thu, 6 Aug 2015 22:26:23 -0700 Subject: [PATCH 19/19] Changed mb type from int to bool. --- BasiliskII/src/adb.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/BasiliskII/src/adb.cpp b/BasiliskII/src/adb.cpp index 1d656935..27d1de73 100644 --- a/BasiliskII/src/adb.cpp +++ b/BasiliskII/src/adb.cpp @@ -340,7 +340,7 @@ void ADBInterrupt(void) int my = mouse_y; if (relative_mouse) mouse_x = mouse_y = 0; - int mb[3] = {mouse_button[0], mouse_button[1], mouse_button[2]}; + bool mb[3] = {mouse_button[0], mouse_button[1], mouse_button[2]}; B2_unlock_mutex(mouse_lock); uint32 key_base = adb_base + 4; @@ -349,7 +349,7 @@ void ADBInterrupt(void) if (relative_mouse) { // Mouse movement (relative) and buttons - if (mx != 0 || my != 0 || !!mb[0] != old_mouse_button[0] || !!mb[1] != old_mouse_button[1] || !!mb[2] != old_mouse_button[2]) { + if (mx != 0 || my != 0 || mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { // Call mouse ADB handler if (mouse_reg_3[1] == 4) { @@ -371,9 +371,9 @@ void ADBInterrupt(void) r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 Execute68k(r.a[1], &r); - old_mouse_button[0] = mb[0] != 0; - old_mouse_button[1] = mb[1] != 0; - old_mouse_button[2] = mb[2] != 0; + old_mouse_button[0] = mb[0]; + old_mouse_button[1] = mb[1]; + old_mouse_button[2] = mb[2]; } } else { @@ -406,7 +406,7 @@ void ADBInterrupt(void) } // Send mouse button events - if (!!mb[0] != old_mouse_button[0] || !!mb[1] != old_mouse_button[1] || !!mb[2] != old_mouse_button[2]) { + if (mb[0] != old_mouse_button[0] || mb[1] != old_mouse_button[1] || mb[2] != old_mouse_button[2]) { uint32 mouse_base = adb_base + 16; // Call mouse ADB handler @@ -429,9 +429,9 @@ void ADBInterrupt(void) r.d[0] = (mouse_reg_3[0] << 4) | 0x0c; // Talk 0 Execute68k(r.a[1], &r); - old_mouse_button[0] = mb[0] != 0; - old_mouse_button[1] = mb[1] != 0; - old_mouse_button[2] = mb[2] != 0; + old_mouse_button[0] = mb[0]; + old_mouse_button[1] = mb[1]; + old_mouse_button[2] = mb[2]; } }