dos is dead, really. This has never worked, and would need a full rewrite

from scratch before it would anyway.  That's not likely, so say goodbye!
This commit is contained in:
Joseph Carter 2001-06-29 07:56:36 +00:00
parent c350bb2b1b
commit 11257134c0
9 changed files with 0 additions and 4560 deletions

View file

@ -1,105 +0,0 @@
/*
dosisms.h
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef _DOSISMS_H_
#define _DOSISMS_H_
int dos_lockmem(void *addr, int size);
int dos_unlockmem(void *addr, int size);
typedef union {
struct {
unsigned long edi;
unsigned long esi;
unsigned long ebp;
unsigned long res;
unsigned long ebx;
unsigned long edx;
unsigned long ecx;
unsigned long eax;
} d;
struct {
unsigned short di, di_hi;
unsigned short si, si_hi;
unsigned short bp, bp_hi;
unsigned short res, res_hi;
unsigned short bx, bx_hi;
unsigned short dx, dx_hi;
unsigned short cx, cx_hi;
unsigned short ax, ax_hi;
unsigned short flags;
unsigned short es;
unsigned short ds;
unsigned short fs;
unsigned short gs;
unsigned short ip;
unsigned short cs;
unsigned short sp;
unsigned short ss;
} x;
struct {
unsigned char edi[4];
unsigned char esi[4];
unsigned char ebp[4];
unsigned char res[4];
unsigned char bl, bh, ebx_b2, ebx_b3;
unsigned char dl, dh, edx_b2, edx_b3;
unsigned char cl, ch, ecx_b2, ecx_b3;
unsigned char al, ah, eax_b2, eax_b3;
} h;
} regs_t;
unsigned int ptr2real(void *ptr);
void *real2ptr(unsigned int real);
void *far2ptr(unsigned int farptr);
unsigned int ptr2far(void *ptr);
int dos_inportb(int port);
int dos_inportw(int port);
void dos_outportb(int port, int val);
void dos_outportw(int port, int val);
void dos_irqenable(void);
void dos_irqdisable(void);
void dos_registerintr(int intr, void (*handler)(void));
void dos_restoreintr(int intr);
int dos_int86(int vec);
void *dos_getmemory(int size);
void dos_freememory(void *ptr);
void dos_usleep(int usecs);
int dos_getheapsize(void);
extern regs_t regs;
#endif // _DOSISMS_H_

View file

@ -1,797 +0,0 @@
/* WINSOCK.H--definitions to be used with the WINSOCK.DLL
* Copyright (c) 1993-1995, Microsoft Corp. All rights reserved.
*
* This header file corresponds to version 1.1 of the Windows Sockets specification.
*
* This file includes parts which are Copyright (c) 1982-1986 Regents
* of the University of California. All rights reserved. The
* Berkeley Software License Agreement specifies the terms and
* conditions for redistribution.
*
*/
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#define FAR
#define PASCAL
/*
* Basic system type definitions, taken from the BSD file sys/types.h.
*/
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
/*
* The new type to be used in all
* instances which refer to sockets.
*/
typedef u_int SOCKET;
// FIXME
#if 0
/*
* Select uses arrays of SOCKETs. These macros manipulate such
* arrays. FD_SETSIZE may be defined by the user before including
* this file, but the default here should be >= 64.
*
* CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
* INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
*/
#ifndef FD_SETSIZE
#define FD_SETSIZE 64
#endif /* FD_SETSIZE */
typedef struct fd_set {
u_int fd_count; /* how many are SET? */
SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
} fd_set;
#ifdef __cplusplus
extern "C" {
#endif
extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
#ifdef __cplusplus
}
#endif
#define FD_CLR(fd, set) do { \
u_int __i; \
for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
((fd_set FAR *)(set))->fd_array[__i] = \
((fd_set FAR *)(set))->fd_array[__i+1]; \
__i++; \
} \
((fd_set FAR *)(set))->fd_count--; \
break; \
} \
} \
} while(0)
#define FD_SET(fd, set) do { \
if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
} while(0)
#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
/*
* Structure used in select() call, taken from the BSD file sys/time.h.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
/*
* Operations on timevals.
*
* NB: timercmp does not work for >= or <=.
*/
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
#define timercmp(tvp, uvp, cmp) \
((tvp)->tv_sec cmp (uvp)->tv_sec || \
(tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
#endif
/*
* Commands for ioctlsocket(), taken from the BSD file fcntl.h.
*
*
* Ioctl's have the command encoded in the lower word,
* and the size of any in or out parameters in the upper
* word. The high 2 bits of the upper word are used
* to encode the in/out status of the parameter; for now
* we restrict parameters to at most 128 bytes.
*/
#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
#define IOC_VOID 0x20000000 /* no parameters */
#define IOC_OUT 0x40000000 /* copy out parameters */
#define IOC_IN 0x80000000 /* copy in parameters */
#define IOC_INOUT (IOC_IN|IOC_OUT)
/* 0x20000000 distinguishes new &
old ioctl's */
#define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */
#define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
#define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
/* Socket I/O Controls */
#define SIOCSHIWAT _IOW('s', 0, u_long) /* set high watermark */
#define SIOCGHIWAT _IOR('s', 1, u_long) /* get high watermark */
#define SIOCSLOWAT _IOW('s', 2, u_long) /* set low watermark */
#define SIOCGLOWAT _IOR('s', 3, u_long) /* get low watermark */
#define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */
/*
* Structures returned by network data base library, taken from the
* BSD file netdb.h. All addresses are supplied in host order, and
* returned in network order (suitable for use in system calls).
*/
struct hostent {
char FAR * h_name; /* official name of host */
char FAR * FAR * h_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */
char FAR * FAR * h_addr_list; /* list of addresses */
#define h_addr h_addr_list[0] /* address, for backward compat */
};
/*
* It is assumed here that a network number
* fits in 32 bits.
*/
struct netent {
char FAR * n_name; /* official name of net */
char FAR * FAR * n_aliases; /* alias list */
short n_addrtype; /* net address type */
u_long n_net; /* network # */
};
struct servent {
char FAR * s_name; /* official service name */
char FAR * FAR * s_aliases; /* alias list */
short s_port; /* port # */
char FAR * s_proto; /* protocol to use */
};
struct protoent {
char FAR * p_name; /* official protocol name */
char FAR * FAR * p_aliases; /* alias list */
short p_proto; /* protocol # */
};
/*
* Constants and structures defined by the internet system,
* Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
*/
/*
* Protocols
*/
#define IPPROTO_IP 0 /* dummy for IP */
#define IPPROTO_ICMP 1 /* control message protocol */
#define IPPROTO_GGP 2 /* gateway^2 (deprecated) */
#define IPPROTO_TCP 6 /* tcp */
#define IPPROTO_PUP 12 /* pup */
#define IPPROTO_UDP 17 /* user datagram protocol */
#define IPPROTO_IDP 22 /* xns idp */
#define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */
#define IPPROTO_RAW 255 /* raw IP packet */
#define IPPROTO_MAX 256
/*
* Port/socket numbers: network standard functions
*/
#define IPPORT_ECHO 7
#define IPPORT_DISCARD 9
#define IPPORT_SYSTAT 11
#define IPPORT_DAYTIME 13
#define IPPORT_NETSTAT 15
#define IPPORT_FTP 21
#define IPPORT_TELNET 23
#define IPPORT_SMTP 25
#define IPPORT_TIMESERVER 37
#define IPPORT_NAMESERVER 42
#define IPPORT_WHOIS 43
#define IPPORT_MTP 57
/*
* Port/socket numbers: host specific functions
*/
#define IPPORT_TFTP 69
#define IPPORT_RJE 77
#define IPPORT_FINGER 79
#define IPPORT_TTYLINK 87
#define IPPORT_SUPDUP 95
/*
* UNIX TCP sockets
*/
#define IPPORT_EXECSERVER 512
#define IPPORT_LOGINSERVER 513
#define IPPORT_CMDSERVER 514
#define IPPORT_EFSSERVER 520
/*
* UNIX UDP sockets
*/
#define IPPORT_BIFFUDP 512
#define IPPORT_WHOSERVER 513
#define IPPORT_ROUTESERVER 520
/* 520+1 also used */
/*
* Ports < IPPORT_RESERVED are reserved for
* privileged processes (e.g. root).
*/
#define IPPORT_RESERVED 1024
/*
* Link numbers
*/
#define IMPLINK_IP 155
#define IMPLINK_LOWEXPER 156
#define IMPLINK_HIGHEXPER 158
/*
* Internet address (old style... should be updated)
*/
struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
#define s_addr S_un.S_addr
/* can be used for most tcp & ip code */
#define s_host S_un.S_un_b.s_b2
/* host on imp */
#define s_net S_un.S_un_b.s_b1
/* network */
#define s_imp S_un.S_un_w.s_w2
/* imp */
#define s_impno S_un.S_un_b.s_b4
/* imp # */
#define s_lh S_un.S_un_b.s_b3
/* logical host */
};
/*
* Definitions of bits in internet address integers.
* On subnets, the decomposition of addresses to host and net parts
* is done according to subnet mask, not the masks here.
*/
#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
#define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST 0x00ffffff
#define IN_CLASSA_MAX 128
#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST 0x0000ffff
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST 0x000000ff
#define INADDR_ANY (u_long)0x00000000
#define INADDR_LOOPBACK 0x7f000001
#define INADDR_BROADCAST (u_long)0xffffffff
#define INADDR_NONE 0xffffffff
/*
* Socket address, internet style.
*/
struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
/*
* Options for use with [gs]etsockopt at the IP level.
*/
#define IP_OPTIONS 1 /* set/get IP per-packet options */
#define IP_MULTICAST_IF 2 /* set/get IP multicast interface */
#define IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */
#define IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */
#define IP_ADD_MEMBERSHIP 5 /* add an IP group membership */
#define IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */
#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
#define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */
/*
* Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
*/
struct ip_mreq {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
/*
* Definitions related to sockets: types, address families, options,
* taken from the BSD file sys/socket.h.
*/
/*
* This is used instead of -1, since the
* SOCKET type is unsigned.
*/
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
/*
* Types
*/
#define SOCK_STREAM 1 /* stream socket */
#define SOCK_DGRAM 2 /* datagram socket */
#define SOCK_RAW 3 /* raw-protocol interface */
#define SOCK_RDM 4 /* reliably-delivered message */
#define SOCK_SEQPACKET 5 /* sequenced packet stream */
/*
* Option flags per-socket.
*/
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
#define SO_LINGER 0x0080 /* linger on close if data present */
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
#define SO_DONTLINGER (u_int)(~SO_LINGER)
/*
* Additional options.
*/
#define SO_SNDBUF 0x1001 /* send buffer size */
#define SO_RCVBUF 0x1002 /* receive buffer size */
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
#define SO_SNDTIMEO 0x1005 /* send timeout */
#define SO_RCVTIMEO 0x1006 /* receive timeout */
#define SO_ERROR 0x1007 /* get error status and clear */
#define SO_TYPE 0x1008 /* get socket type */
/*
* Options for connect and disconnect data and options. Used only by
* non-TCP/IP transports such as DECNet, OSI TP4, etc.
*/
#define SO_CONNDATA 0x7000
#define SO_CONNOPT 0x7001
#define SO_DISCDATA 0x7002
#define SO_DISCOPT 0x7003
#define SO_CONNDATALEN 0x7004
#define SO_CONNOPTLEN 0x7005
#define SO_DISCDATALEN 0x7006
#define SO_DISCOPTLEN 0x7007
/*
* Option for opening sockets for synchronous access.
*/
#define SO_OPENTYPE 0x7008
#define SO_SYNCHRONOUS_ALERT 0x10
#define SO_SYNCHRONOUS_NONALERT 0x20
/*
* Other NT-specific options.
*/
#define SO_MAXDG 0x7009
#define SO_MAXPATHDG 0x700A
/*
* TCP options.
*/
#define TCP_NODELAY 0x0001
#define TCP_BSDURGENT 0x7000
/*
* Address families.
*/
#define AF_UNSPEC 0 /* unspecified */
#define AF_UNIX 1 /* local to host (pipes, portals) */
#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
#define AF_IMPLINK 3 /* arpanet imp addresses */
#define AF_PUP 4 /* pup protocols: e.g. BSP */
#define AF_CHAOS 5 /* mit CHAOS protocols */
#define AF_IPX 6 /* IPX and SPX */
#define AF_NS 6 /* XEROX NS protocols */
#define AF_ISO 7 /* ISO protocols */
#define AF_OSI AF_ISO /* OSI is ISO */
#define AF_ECMA 8 /* european computer manufacturers */
#define AF_DATAKIT 9 /* datakit protocols */
#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
#define AF_SNA 11 /* IBM SNA */
#define AF_DECnet 12 /* DECnet */
#define AF_DLI 13 /* Direct data link interface */
#define AF_LAT 14 /* LAT */
#define AF_HYLINK 15 /* NSC Hyperchannel */
#define AF_APPLETALK 16 /* AppleTalk */
#define AF_NETBIOS 17 /* NetBios-style addresses */
#define AF_VOICEVIEW 18 /* VoiceView */
#define AF_MAX 19
/*
* Structure used by kernel to store most
* addresses.
*/
struct sockaddr {
u_short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
};
/*
* Structure used by kernel to pass protocol
* information in raw sockets.
*/
struct sockproto {
u_short sp_family; /* address family */
u_short sp_protocol; /* protocol */
};
/*
* Protocol families, same as address families for now.
*/
#define PF_UNSPEC AF_UNSPEC
#define PF_UNIX AF_UNIX
#define PF_INET AF_INET
#define PF_IMPLINK AF_IMPLINK
#define PF_PUP AF_PUP
#define PF_CHAOS AF_CHAOS
#define PF_NS AF_NS
#define PF_IPX AF_IPX
#define PF_ISO AF_ISO
#define PF_OSI AF_OSI
#define PF_ECMA AF_ECMA
#define PF_DATAKIT AF_DATAKIT
#define PF_CCITT AF_CCITT
#define PF_SNA AF_SNA
#define PF_DECnet AF_DECnet
#define PF_DLI AF_DLI
#define PF_LAT AF_LAT
#define PF_HYLINK AF_HYLINK
#define PF_APPLETALK AF_APPLETALK
#define PF_VOICEVIEW AF_VOICEVIEW
#define PF_MAX AF_MAX
/*
* Structure used for manipulating linger option.
*/
struct linger {
u_short l_onoff; /* option on/off */
u_short l_linger; /* linger time */
};
/*
* Level number for (get/set)sockopt() to apply to socket itself.
*/
#define SOL_SOCKET 0xffff /* options for socket level */
/*
* Maximum queue length specifiable by listen.
*/
#define SOMAXCONN 5
#define MSG_OOB 0x1 /* process out-of-band data */
#define MSG_PEEK 0x2 /* peek at incoming message */
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
#define MSG_MAXIOVLEN 16
#define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */
/*
* Define constant based on rfc883, used by gethostbyxxxx() calls.
*/
#define MAXGETHOSTSTRUCT 1024
/*
* Define flags to be used with the WSAAsyncSelect() call.
*/
#define FD_READ 0x01
#define FD_WRITE 0x02
#define FD_OOB 0x04
#define FD_ACCEPT 0x08
#define FD_CONNECT 0x10
#define FD_CLOSE 0x20
/*
* All Windows Sockets error constants are biased by WSABASEERR from
* the "normal"
*/
#define WSABASEERR 10000
/*
* Windows Sockets definitions of regular Microsoft C error constants
*/
#define WSAEINTR (WSABASEERR+4)
#define WSAEBADF (WSABASEERR+9)
#define WSAEACCES (WSABASEERR+13)
#define WSAEFAULT (WSABASEERR+14)
#define WSAEINVAL (WSABASEERR+22)
#define WSAEMFILE (WSABASEERR+24)
/*
* Windows Sockets definitions of regular Berkeley error constants
*/
#define WSAEWOULDBLOCK (WSABASEERR+35)
#define WSAEINPROGRESS (WSABASEERR+36)
#define WSAEALREADY (WSABASEERR+37)
#define WSAENOTSOCK (WSABASEERR+38)
#define WSAEDESTADDRREQ (WSABASEERR+39)
#define WSAEMSGSIZE (WSABASEERR+40)
#define WSAEPROTOTYPE (WSABASEERR+41)
#define WSAENOPROTOOPT (WSABASEERR+42)
#define WSAEPROTONOSUPPORT (WSABASEERR+43)
#define WSAESOCKTNOSUPPORT (WSABASEERR+44)
#define WSAEOPNOTSUPP (WSABASEERR+45)
#define WSAEPFNOSUPPORT (WSABASEERR+46)
#define WSAEAFNOSUPPORT (WSABASEERR+47)
#define WSAEADDRINUSE (WSABASEERR+48)
#define WSAEADDRNOTAVAIL (WSABASEERR+49)
#define WSAENETDOWN (WSABASEERR+50)
#define WSAENETUNREACH (WSABASEERR+51)
#define WSAENETRESET (WSABASEERR+52)
#define WSAECONNABORTED (WSABASEERR+53)
#define WSAECONNRESET (WSABASEERR+54)
#define WSAENOBUFS (WSABASEERR+55)
#define WSAEISCONN (WSABASEERR+56)
#define WSAENOTCONN (WSABASEERR+57)
#define WSAESHUTDOWN (WSABASEERR+58)
#define WSAETOOMANYREFS (WSABASEERR+59)
#define WSAETIMEDOUT (WSABASEERR+60)
#define WSAECONNREFUSED (WSABASEERR+61)
#define WSAELOOP (WSABASEERR+62)
#define WSAENAMETOOLONG (WSABASEERR+63)
#define WSAEHOSTDOWN (WSABASEERR+64)
#define WSAEHOSTUNREACH (WSABASEERR+65)
#define WSAENOTEMPTY (WSABASEERR+66)
#define WSAEPROCLIM (WSABASEERR+67)
#define WSAEUSERS (WSABASEERR+68)
#define WSAEDQUOT (WSABASEERR+69)
#define WSAESTALE (WSABASEERR+70)
#define WSAEREMOTE (WSABASEERR+71)
#define WSAEDISCON (WSABASEERR+101)
/*
* Extended Windows Sockets error constant definitions
*/
#define WSASYSNOTREADY (WSABASEERR+91)
#define WSAVERNOTSUPPORTED (WSABASEERR+92)
#define WSANOTINITIALISED (WSABASEERR+93)
/*
* Error return codes from gethostbyname() and gethostbyaddr()
* (when using the resolver). Note that these errors are
* retrieved via WSAGetLastError() and must therefore follow
* the rules for avoiding clashes with error numbers from
* specific implementations or language run-time systems.
* For this reason the codes are based at WSABASEERR+1001.
* Note also that [WSA]NO_ADDRESS is defined only for
* compatibility purposes.
*/
#define h_errno WSAGetLastError()
/* Authoritative Answer: Host not found */
#define WSAHOST_NOT_FOUND (WSABASEERR+1001)
#define HOST_NOT_FOUND WSAHOST_NOT_FOUND
/* Non-Authoritative: Host not found, or SERVERFAIL */
#define WSATRY_AGAIN (WSABASEERR+1002)
#define TRY_AGAIN WSATRY_AGAIN
/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
#define WSANO_RECOVERY (WSABASEERR+1003)
#define NO_RECOVERY WSANO_RECOVERY
/* Valid name, no data record of requested type */
#define WSANO_DATA (WSABASEERR+1004)
#define NO_DATA WSANO_DATA
/* no address, look for MX record */
#define WSANO_ADDRESS WSANO_DATA
#define NO_ADDRESS WSANO_ADDRESS
/*
* Windows Sockets errors redefined as regular Berkeley error constants.
* These are commented out in Windows NT to avoid conflicts with errno.h.
* Use the WSA constants instead.
*/
#if 0
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ESHUTDOWN WSAESHUTDOWN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define ENAMETOOLONG WSAENAMETOOLONG
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define ENOTEMPTY WSAENOTEMPTY
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
#endif
/* Socket function prototypes */
#ifdef __cplusplus
extern "C" {
#endif
SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
int FAR *addrlen);
int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
int PASCAL FAR closesocket (SOCKET s);
int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
int FAR * namelen);
int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
int FAR * namelen);
int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
char FAR * optval, int FAR *optlen);
u_long PASCAL FAR htonl (u_long hostlong);
u_short PASCAL FAR htons (u_short hostshort);
unsigned long PASCAL FAR inet_addr (const char FAR * cp);
char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
int PASCAL FAR listen (SOCKET s, int backlog);
u_long PASCAL FAR ntohl (u_long netlong);
u_short PASCAL FAR ntohs (u_short netshort);
int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
struct sockaddr FAR *from, int FAR * fromlen);
#if 0
int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
fd_set FAR *exceptfds, const struct timeval FAR *timeout);
#endif
int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
const struct sockaddr FAR *to, int tolen);
int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
const char FAR * optval, int optlen);
int PASCAL FAR shutdown (SOCKET s, int how);
SOCKET PASCAL FAR socket (int af, int type, int protocol);
/* Database function prototypes */
struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
int len, int type);
struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
int PASCAL FAR gethostname (char FAR * name, int namelen);
struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
const char FAR * proto);
struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
#ifdef __cplusplus
}
#endif
/* Microsoft Windows Extended data types */
typedef struct sockaddr SOCKADDR;
typedef struct sockaddr *PSOCKADDR;
typedef struct sockaddr FAR *LPSOCKADDR;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr_in *PSOCKADDR_IN;
typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
typedef struct linger LINGER;
typedef struct linger *PLINGER;
typedef struct linger FAR *LPLINGER;
typedef struct in_addr IN_ADDR;
typedef struct in_addr *PIN_ADDR;
typedef struct in_addr FAR *LPIN_ADDR;
typedef struct fd_set FD_SET;
typedef struct fd_set *PFD_SET;
typedef struct fd_set FAR *LPFD_SET;
typedef struct hostent HOSTENT;
typedef struct hostent *PHOSTENT;
typedef struct hostent FAR *LPHOSTENT;
typedef struct servent SERVENT;
typedef struct servent *PSERVENT;
typedef struct servent FAR *LPSERVENT;
typedef struct protoent PROTOENT;
typedef struct protoent *PPROTOENT;
typedef struct protoent FAR *LPPROTOENT;
typedef struct timeval TIMEVAL;
typedef struct timeval *PTIMEVAL;
typedef struct timeval FAR *LPTIMEVAL;
#endif /* _WINSOCKAPI_ */

View file

@ -1,91 +0,0 @@
/*
vid_dos.h
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
typedef struct vmode_s {
struct vmode_s *pnext;
char *name;
char *header;
unsigned width;
unsigned height;
float aspect;
unsigned rowbytes;
int planar;
int numpages;
void *pextradata;
int (*setmode)(viddef_t *vid, struct vmode_s *pcurrentmode);
void (*swapbuffers)(viddef_t *vid, struct vmode_s *pcurrentmode,
vrect_t *rects);
void (*setpalette)(viddef_t *vid, struct vmode_s *pcurrentmode,
unsigned char *palette);
void (*begindirectrect)(viddef_t *vid, struct vmode_s *pcurrentmode,
int x, int y, byte *pbitmap, int width,
int height);
void (*enddirectrect)(viddef_t *vid, struct vmode_s *pcurrentmode,
int x, int y, int width, int height);
} vmode_t;
// vid_wait settings
#define VID_WAIT_NONE 0
#define VID_WAIT_VSYNC 1
#define VID_WAIT_DISPLAY_ENABLE 2
extern int numvidmodes;
extern vmode_t *pvidmodes;
extern int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes;
extern byte *VGA_pagebase;
extern vmode_t *VGA_pcurmode;
extern cvar_t *vid_wait;
extern cvar_t *vid_nopageflip;
extern cvar_t *_vid_wait_override;
extern unsigned char colormap256[32][256];
extern void *vid_surfcache;
extern int vid_surfcachesize;
void VGA_Init (void);
void VID_InitVESA (void);
void VID_InitExtra (void);
void VGA_WaitVsync (void);
void VGA_ClearVideoMem (int planar);
void VGA_SetPalette(viddef_t *vid, vmode_t *pcurrentmode, unsigned char *pal);
void VGA_SwapBuffersCopy (viddef_t *vid, vmode_t *pcurrentmode,
vrect_t *rects);
qboolean VGA_FreeAndAllocVidbuffer (viddef_t *vid, int allocnewbuffer);
qboolean VGA_CheckAdequateMem (int width, int height, int rowbytes,
int allocnewbuffer);
void VGA_BeginDirectRect (viddef_t *vid, struct vmode_s *pcurrentmode, int x,
int y, byte *pbitmap, int width, int height);
void VGA_EndDirectRect (viddef_t *vid, struct vmode_s *pcurrentmode, int x,
int y, int width, int height);
void VGA_UpdateLinearScreen (void *srcptr, void *destptr, int width,
int height, int srcrowbytes, int destrowbytes);

View file

@ -1,872 +0,0 @@
/*
cd_dos.c
support for cd music in dos.
FIXME: Update for plugin API
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <dpmi.h>
#include "dosisms.h"
extern cvar_t *bgmvolume;
#define ADDRESS_MODE_HSG 0
#define ADDRESS_MODE_RED_BOOK 1
#define STATUS_ERROR_BIT 0x8000
#define STATUS_BUSY_BIT 0x0200
#define STATUS_DONE_BIT 0x0100
#define STATUS_ERROR_MASK 0x00ff
#define ERROR_WRITE_PROTECT 0
#define ERROR_UNKNOWN_UNIT 1
#define ERROR_DRIVE_NOT_READY 2
#define ERROR_UNKNOWN_COMMAND 3
#define ERROR_CRC_ERROR 4
#define ERROR_BAD_REQUEST_LEN 5
#define ERROR_SEEK_ERROR 6
#define ERROR_UNKNOWN_MEDIA 7
#define ERROR_SECTOR_NOT_FOUND 8
#define ERROR_OUT_OF_PAPER 9
#define ERROR_WRITE_FAULT 10
#define ERROR_READ_FAULT 11
#define ERROR_GENERAL_FAILURE 12
#define ERROR_RESERVED_13 13
#define ERROR_RESERVED_14 14
#define ERROR_BAD_DISK_CHANGE 15
#define COMMAND_READ 3
#define COMMAND_WRITE 12
#define COMMAND_PLAY_AUDIO 132
#define COMMAND_STOP_AUDIO 133
#define COMMAND_RESUME_AUDIO 136
#define READ_REQUEST_AUDIO_CHANNEL_INFO 4
#define READ_REQUEST_DEVICE_STATUS 6
#define READ_REQUEST_MEDIA_CHANGE 9
#define READ_REQUEST_AUDIO_DISK_INFO 10
#define READ_REQUEST_AUDIO_TRACK_INFO 11
#define READ_REQUEST_AUDIO_STATUS 15
#define WRITE_REQUEST_EJECT 0
#define WRITE_REQUEST_RESET 2
#define WRITE_REQUEST_AUDIO_CHANNEL_INFO 3
#define STATUS_DOOR_OPEN 0x00000001
#define STATUS_DOOR_UNLOCKED 0x00000002
#define STATUS_RAW_SUPPORT 0x00000004
#define STATUS_READ_WRITE 0x00000008
#define STATUS_AUDIO_SUPPORT 0x00000010
#define STATUS_INTERLEAVE_SUPPORT 0x00000020
#define STATUS_BIT_6_RESERVED 0x00000040
#define STATUS_PREFETCH_SUPPORT 0x00000080
#define STATUS_AUDIO_MANIPLUATION_SUPPORT 0x00000100
#define STATUS_RED_BOOK_ADDRESS_SUPPORT 0x00000200
#define MEDIA_NOT_CHANGED 1
#define MEDIA_STATUS_UNKNOWN 0
#define MEDIA_CHANGED -1
#define AUDIO_CONTROL_MASK 0xd0
#define AUDIO_CONTROL_DATA_TRACK 0x40
#define AUDIO_CONTROL_AUDIO_2_TRACK 0x00
#define AUDIO_CONTROL_AUDIO_2P_TRACK 0x10
#define AUDIO_CONTROL_AUDIO_4_TRACK 0x80
#define AUDIO_CONTROL_AUDIO_4P_TRACK 0x90
#define AUDIO_STATUS_PAUSED 0x0001
#pragma pack(1)
struct playAudioRequest {
char addressingMode;
int startLocation;
int sectors;
};
struct readRequest {
char mediaDescriptor;
short bufferOffset;
short bufferSegment;
short length;
short startSector;
int volumeID;
};
struct writeRequest {
char mediaDescriptor;
short bufferOffset;
short bufferSegment;
short length;
short startSector;
int volumeID;
};
struct cd_request {
char headerLength;
char unit;
char command;
short status;
char reserved[8];
union {
struct playAudioRequest playAudio;
struct readRequest read;
struct writeRequest write;
} x;
};
struct audioChannelInfo_s {
char code;
char channel0input;
char channel0volume;
char channel1input;
char channel1volume;
char channel2input;
char channel2volume;
char channel3input;
char channel3volume;
};
struct deviceStatus_s {
char code;
int status;
};
struct mediaChange_s {
char code;
char status;
};
struct audioDiskInfo_s {
char code;
char lowTrack;
char highTrack;
int leadOutStart;
};
struct audioTrackInfo_s {
char code;
char track;
int start;
char control;
};
struct audioStatus_s {
char code;
short status;
int PRstartLocation;
int PRendLocation;
};
struct reset_s {
char code;
};
union readInfo_u {
struct audioChannelInfo_s audioChannelInfo;
struct deviceStatus_s deviceStatus;
struct mediaChange_s mediaChange;
struct audioDiskInfo_s audioDiskInfo;
struct audioTrackInfo_s audioTrackInfo;
struct audioStatus_s audioStatus;
struct reset_s reset;
};
#pragma pack()
#define MAXIMUM_TRACKS 32
typedef struct {
int start;
int length;
qboolean isData;
} track_info;
typedef struct {
qboolean valid;
int leadOutAddress;
track_info track[MAXIMUM_TRACKS];
byte lowTrack;
byte highTrack;
} cd_info;
static struct cd_request *cdRequest;
static union readInfo_u *readInfo;
static cd_info cd;
static qboolean playing = false;
static qboolean wasPlaying = false;
static qboolean mediaCheck = false;
static qboolean initialized = false;
static qboolean enabled = true;
static qboolean playLooping = false;
static short cdRequestSegment;
static short cdRequestOffset;
static short readInfoSegment;
static short readInfoOffset;
static byte remap[256];
static byte cdrom;
static byte playTrack;
static byte cdvolume;
static int
RedBookToSector (int rb)
{
byte minute;
byte second;
byte frame;
minute = (rb >> 16) & 0xff;
second = (rb >> 8) & 0xff;
frame = rb & 0xff;
return minute * 60 * 75 + second * 75 + frame;
}
static void
CDAudio_Reset (void)
{
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_WRITE;
cdRequest->status = 0;
cdRequest->x.write.mediaDescriptor = 0;
cdRequest->x.write.bufferOffset = readInfoOffset;
cdRequest->x.write.bufferSegment = readInfoSegment;
cdRequest->x.write.length = sizeof (struct reset_s);
cdRequest->x.write.startSector = 0;
cdRequest->x.write.volumeID = 0;
readInfo->reset.code = WRITE_REQUEST_RESET;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
}
static void
CDAudio_Eject (void)
{
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_WRITE;
cdRequest->status = 0;
cdRequest->x.write.mediaDescriptor = 0;
cdRequest->x.write.bufferOffset = readInfoOffset;
cdRequest->x.write.bufferSegment = readInfoSegment;
cdRequest->x.write.length = sizeof (struct reset_s);
cdRequest->x.write.startSector = 0;
cdRequest->x.write.volumeID = 0;
readInfo->reset.code = WRITE_REQUEST_EJECT;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
}
static int
CDAudio_GetAudioTrackInfo (byte track, int *start)
{
byte control;
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_READ;
cdRequest->status = 0;
cdRequest->x.read.mediaDescriptor = 0;
cdRequest->x.read.bufferOffset = readInfoOffset;
cdRequest->x.read.bufferSegment = readInfoSegment;
cdRequest->x.read.length = sizeof (struct audioTrackInfo_s);
cdRequest->x.read.startSector = 0;
cdRequest->x.read.volumeID = 0;
readInfo->audioTrackInfo.code = READ_REQUEST_AUDIO_TRACK_INFO;
readInfo->audioTrackInfo.track = track;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
if (cdRequest->status & STATUS_ERROR_BIT) {
Con_DPrintf ("CDAudio_GetAudioTrackInfo %04x\n",
cdRequest->status & 0xffff);
return -1;
}
*start = readInfo->audioTrackInfo.start;
control = readInfo->audioTrackInfo.control & AUDIO_CONTROL_MASK;
return (control & AUDIO_CONTROL_DATA_TRACK);
}
static int
CDAudio_GetAudioDiskInfo (void)
{
int n;
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_READ;
cdRequest->status = 0;
cdRequest->x.read.mediaDescriptor = 0;
cdRequest->x.read.bufferOffset = readInfoOffset;
cdRequest->x.read.bufferSegment = readInfoSegment;
cdRequest->x.read.length = sizeof (struct audioDiskInfo_s);
cdRequest->x.read.startSector = 0;
cdRequest->x.read.volumeID = 0;
readInfo->audioDiskInfo.code = READ_REQUEST_AUDIO_DISK_INFO;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
if (cdRequest->status & STATUS_ERROR_BIT) {
Con_DPrintf ("CDAudio_GetAudioDiskInfo %04x\n",
cdRequest->status & 0xffff);
return -1;
}
cd.valid = true;
cd.lowTrack = readInfo->audioDiskInfo.lowTrack;
cd.highTrack = readInfo->audioDiskInfo.highTrack;
cd.leadOutAddress = readInfo->audioDiskInfo.leadOutStart;
for (n = cd.lowTrack; n <= cd.highTrack; n++) {
cd.track[n].isData = CDAudio_GetAudioTrackInfo (n, &cd.track[n].start);
if (n > cd.lowTrack) {
cd.track[n - 1].length =
RedBookToSector (cd.track[n].start) -
RedBookToSector (cd.track[n - 1].start);
if (n == cd.highTrack)
cd.track[n].length =
RedBookToSector (cd.leadOutAddress) -
RedBookToSector (cd.track[n].start);
}
}
return 0;
}
static int
CDAudio_GetAudioStatus (void)
{
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_READ;
cdRequest->status = 0;
cdRequest->x.read.mediaDescriptor = 0;
cdRequest->x.read.bufferOffset = readInfoOffset;
cdRequest->x.read.bufferSegment = readInfoSegment;
cdRequest->x.read.length = sizeof (struct audioStatus_s);
cdRequest->x.read.startSector = 0;
cdRequest->x.read.volumeID = 0;
readInfo->audioDiskInfo.code = READ_REQUEST_AUDIO_STATUS;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
if (cdRequest->status & STATUS_ERROR_BIT)
return -1;
return 0;
}
static int
CDAudio_MediaChange (void)
{
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_READ;
cdRequest->status = 0;
cdRequest->x.read.mediaDescriptor = 0;
cdRequest->x.read.bufferOffset = readInfoOffset;
cdRequest->x.read.bufferSegment = readInfoSegment;
cdRequest->x.read.length = sizeof (struct mediaChange_s);
cdRequest->x.read.startSector = 0;
cdRequest->x.read.volumeID = 0;
readInfo->mediaChange.code = READ_REQUEST_MEDIA_CHANGE;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
return readInfo->mediaChange.status;
}
byte
CDAudio_GetVolume (void)
{
return cdvolume;
}
// we set the volume to 0 first and then to the desired volume
// some cd-rom drivers seem to need it done this way
void
CDAudio_SetVolume (byte volume)
{
if (!initialized || !enabled)
return;
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_WRITE;
cdRequest->status = 0;
cdRequest->x.read.mediaDescriptor = 0;
cdRequest->x.read.bufferOffset = readInfoOffset;
cdRequest->x.read.bufferSegment = readInfoSegment;
cdRequest->x.read.length = sizeof (struct audioChannelInfo_s);
cdRequest->x.read.startSector = 0;
cdRequest->x.read.volumeID = 0;
readInfo->audioChannelInfo.code = WRITE_REQUEST_AUDIO_CHANNEL_INFO;
readInfo->audioChannelInfo.channel0input = 0;
readInfo->audioChannelInfo.channel0volume = 0;
readInfo->audioChannelInfo.channel1input = 1;
readInfo->audioChannelInfo.channel1volume = 0;
readInfo->audioChannelInfo.channel2input = 2;
readInfo->audioChannelInfo.channel2volume = 0;
readInfo->audioChannelInfo.channel3input = 3;
readInfo->audioChannelInfo.channel3volume = 0;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
readInfo->audioChannelInfo.channel0volume = volume;
readInfo->audioChannelInfo.channel1volume = volume;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
cdvolume = volume;
}
void
CDAudio_Play (byte track, qboolean looping)
{
if (!initialized || !enabled)
return;
if (!cd.valid)
return;
track = remap[track];
if (playing) {
if (playTrack == track)
return;
CDAudio_Stop ();
}
playLooping = looping;
if (track < cd.lowTrack || track > cd.highTrack) {
Con_DPrintf ("CDAudio_Play: Bad track number %u.\n", track);
return;
}
playTrack = track;
if (cd.track[track].isData) {
Con_DPrintf ("CDAudio_Play: Can not play data.\n");
return;
}
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_PLAY_AUDIO;
cdRequest->status = 0;
cdRequest->x.playAudio.addressingMode = ADDRESS_MODE_RED_BOOK;
cdRequest->x.playAudio.startLocation = cd.track[track].start;
cdRequest->x.playAudio.sectors = cd.track[track].length;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
if (cdRequest->status & STATUS_ERROR_BIT) {
Con_DPrintf ("CDAudio_Play: track %u failed\n", track);
cd.valid = false;
playing = false;
return;
}
playing = true;
}
void
CDAudio_Stop (void)
{
if (!initialized || !enabled)
return;
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_STOP_AUDIO;
cdRequest->status = 0;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
wasPlaying = playing;
playing = false;
}
void
CDAudio_Resume (void)
{
if (!initialized || !enabled)
return;
if (!cd.valid)
return;
if (!wasPlaying)
return;
cdRequest->headerLength = 13;
cdRequest->unit = 0;
cdRequest->command = COMMAND_RESUME_AUDIO;
cdRequest->status = 0;
regs.x.ax = 0x1510;
regs.x.cx = cdrom;
regs.x.es = cdRequestSegment;
regs.x.bx = cdRequestOffset;
dos_int86 (0x2f);
playing = true;
}
static void
CD_f (void)
{
char *command;
int ret;
int n;
int startAddress;
if (Cmd_Argc () < 2)
return;
command = Cmd_Argv (1);
if (Q_strcasecmp (command, "on") == 0) {
enabled = true;
return;
}
if (Q_strcasecmp (command, "off") == 0) {
if (playing)
CDAudio_Stop ();
enabled = false;
return;
}
if (Q_strcasecmp (command, "reset") == 0) {
enabled = true;
if (playing)
CDAudio_Stop ();
for (n = 0; n < 256; n++)
remap[n] = n;
CDAudio_Reset ();
CDAudio_GetAudioDiskInfo ();
return;
}
if (Q_strcasecmp (command, "remap") == 0) {
ret = Cmd_Argc () - 2;
if (ret <= 0) {
for (n = 1; n < 256; n++)
if (remap[n] != n)
Con_Printf (" %u -> %u\n", n, remap[n]);
return;
}
for (n = 1; n <= ret; n++)
remap[n] = Q_atoi (Cmd_Argv (n + 1));
return;
}
if (!cd.valid) {
Con_Printf ("No CD in player.\n");
return;
}
if (Q_strcasecmp (command, "play") == 0) {
CDAudio_Play (Q_atoi (Cmd_Argv (2)), false);
return;
}
if (Q_strcasecmp (command, "loop") == 0) {
CDAudio_Play (Q_atoi (Cmd_Argv (2)), true);
return;
}
if (Q_strcasecmp (command, "stop") == 0) {
CDAudio_Stop ();
return;
}
if (Q_strcasecmp (command, "resume") == 0) {
CDAudio_Resume ();
return;
}
if (Q_strcasecmp (command, "eject") == 0) {
if (playing)
CDAudio_Stop ();
CDAudio_Eject ();
cd.valid = false;
return;
}
if (Q_strcasecmp (command, "info") == 0) {
Con_Printf ("%u tracks\n", cd.highTrack - cd.lowTrack + 1);
for (n = cd.lowTrack; n <= cd.highTrack; n++) {
ret = CDAudio_GetAudioTrackInfo (n, &startAddress);
Con_Printf ("Track %2u: %s at %2u:%02u\n", n,
ret ? "data " : "music", (startAddress >> 16) & 0xff,
(startAddress >> 8) & 0xff);
}
if (playing)
Con_Printf ("Currently %s track %u\n",
playLooping ? "looping" : "playing", playTrack);
Con_Printf ("Volume is %u\n", cdvolume);
CDAudio_MediaChange ();
Con_Printf ("Status %04x\n", cdRequest->status & 0xffff);
return;
}
}
void
CDAudio_Update (void)
{
int ret;
int newVolume;
static double lastUpdate;
if (!initialized || !enabled)
return;
if ((realtime - lastUpdate) < 0.25)
return;
lastUpdate = realtime;
if (mediaCheck) {
static double lastCheck;
if ((realtime - lastCheck) < 5.0)
return;
lastCheck = realtime;
ret = CDAudio_MediaChange ();
if (ret == MEDIA_CHANGED) {
Con_DPrintf ("CDAudio: media changed\n");
playing = false;
wasPlaying = false;
cd.valid = false;
CDAudio_GetAudioDiskInfo ();
return;
}
}
newVolume = (int) (bgmvolume->value * 255.0);
if (newVolume < 0) {
Cvar_SetValue (bgmvolume, 0.0);
newVolume = 0;
} else if (newVolume > 255) {
Cvar_SetValue (bgmvolume, 1.0);
newVolume = 255;
}
if (cdvolume != newVolume)
CDAudio_SetVolume (newVolume);
if (playing) {
CDAudio_GetAudioStatus ();
if ((cdRequest->status & STATUS_BUSY_BIT) == 0) {
playing = false;
if (playLooping)
CDAudio_Play (playTrack, true);
}
}
}
qboolean
CDAudio_Playing (void)
{
return playing;
}
int
CDAudio_Init (void)
{
char *memory;
int n;
if (cls.state == ca_dedicated)
return -1;
if (COM_CheckParm ("-nocdaudio"))
return -1;
if (COM_CheckParm ("-cdmediacheck"))
mediaCheck = true;
regs.x.ax = 0x1500;
regs.x.bx = 0;
dos_int86 (0x2f);
if (regs.x.bx == 0) {
Con_Printf
("MSCDEX not loaded, music is disabled. Use \"-nocdaudio\" if you wish to avoid this message in the future. See README.TXT for help.\n");
return -1;
}
if (regs.x.bx > 1)
Con_DPrintf ("CDAudio_Init: First CD-ROM drive will be used\n");
cdrom = regs.x.cx;
regs.x.ax = 0x150c;
regs.x.bx = 0;
dos_int86 (0x2f);
if (regs.x.bx == 0) {
Con_Printf
("MSCDEX version 2.00 or later required for music. See README.TXT for help.\n");
return -1;
}
memory =
dos_getmemory (sizeof (struct cd_request) + sizeof (union readInfo_u));
if (memory == NULL) {
Con_DPrintf ("CDAudio_Init: Unable to allocate low memory.\n");
return -1;
}
cdRequest = (struct cd_request *) memory;
cdRequestSegment = ptr2real (cdRequest) >> 4;
cdRequestOffset = ptr2real (cdRequest) & 0xf;
readInfo = (union readInfo_u *) (memory + sizeof (struct cd_request));
readInfoSegment = ptr2real (readInfo) >> 4;
readInfoOffset = ptr2real (readInfo) & 0xf;
for (n = 0; n < 256; n++)
remap[n] = n;
initialized = true;
CDAudio_SetVolume (255);
if (CDAudio_GetAudioDiskInfo ()) {
Con_Printf ("CDAudio_Init: No CD in player.\n");
enabled = false;
}
Cmd_AddCommand ("cd", CD_f, "Control the CD player.\n"
"Commands:\n"
"eject - Eject the CD.\n"
"info - Reports information on the CD.\n"
"loop (track number) - Loops the specified track.\n"
"remap (track1) (track2) ... - Remap the current track order.\n"
"reset - Causes the CD audio to re-initialize.\n"
"resume - Will resume playback after pause.\n"
"off - Shuts down the CD audio system..\n"
"on - Re-enables the CD audio system after a cd off command.\n"
"pause - Pause the CD playback.\n"
"play (track number) - Plays the specified track one time.\n"
"stop - Stops the currently playing track.");
Con_Printf ("CD Audio Initialized\n");
return 0;
}
void
CDAudio_Shutdown (void)
{
if (!initialized)
return;
CDAudio_Stop ();
}

View file

@ -1,619 +0,0 @@
/*
in_dos.c
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "dosisms.h"
#define AUX_FLAG_FREELOOK 0x00000001
typedef struct {
long interruptVector;
char deviceName[16];
long numAxes;
long numButtons;
long flags;
vec3_t viewangles;
// intended velocities
float forwardmove;
float sidemove;
float upmove;
long buttons;
} externControl_t;
/*
#define AUX_FLAG_FORCEFREELOOK 0x00000001 // r/o
#define AUX_FLAG_EXTENDED 0x00000002 // r/o
#define AUX_FLAG_RUN 0x00000004 // w/o
#define AUX_FLAG_STRAFE 0x00000008 // w/o
#define AUX_FLAG_FREELOOK 0x00000010 // w/o
#define AUX_MAP_UNDEFINED 0
#define AUX_MAP_PITCH 1
#define AUX_MAP_YAW 2
#define AUX_MAP_ROLL 3
#define AUX_MAP_FORWARD 4
#define AUX_MAP_SIDE 5
#define AUX_MAP_UP 6
typedef struct
{
long interruptVector;
// r/o
char deviceName[16];
// r/o
long numAxes;
// r/o 1-6
long numButtons; // r/o 0-32
long flags; // see above
byte axisMapping[6]; // w/o default = p,y,r,f,s,u
float axisValue[6]; // r/w
float sensitivity[6]; // w/o default = 1.0
long buttons; // r/o
float last_frame_time; // w/o
} externControl_t;
*/
cvar_t *m_filter;
qboolean mouse_avail;
int mouse_buttons;
int mouse_oldbuttonstate;
int mouse_buttonstate;
float mouse_x, mouse_y;
float old_mouse_x, old_mouse_y;
cvar_t *in_joystick;
cvar_t *joy_numbuttons;
qboolean joy_avail;
int joy_oldbuttonstate;
int joy_buttonstate;
int joyxl, joyxh, joyyl, joyyh;
int joystickx, joysticky;
qboolean need_center;
qboolean extern_avail;
int extern_buttons;
int extern_oldbuttonstate;
int extern_buttonstate;
cvar_t *aux_look;
externControl_t *extern_control;
void IN_StartupExternal (void);
void IN_ExternalMove (usercmd_t *cmd);
void IN_StartupJoystick (void);
qboolean IN_ReadJoystick (void);
void
Toggle_AuxLook_f (void)
{
if (aux_look->int_val)
Cvar_Set ("auxlook", "0");
else
Cvar_Set ("auxlook", "1");
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
/*
===========
IN_StartupMouse
===========
*/
void
IN_StartupMouse (void)
{
if (COM_CheckParm ("-nomouse"))
return;
// check for mouse
regs.x.ax = 0;
dos_int86 (0x33);
mouse_avail = regs.x.ax;
if (!mouse_avail) {
Con_Printf ("No mouse found\n");
return;
}
mouse_buttons = regs.x.bx;
if (mouse_buttons > 3)
mouse_buttons = 3;
Con_Printf ("%d-button mouse available\n", mouse_buttons);
}
/*
===========
IN_Init
===========
*/
void
IN_Init (void)
{
int i;
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL, "None");
in_joystick = Cvar_Get ("joystick", "0", CVAR_ARCHIVE, NULL, "None");
joy_numbuttons = Cvar_Get ("joybuttons", "4", CVAR_ARCHIVE, NULL, "None");
aux_look = Cvar_Get ("auxlook", "1", CVAR_ARCHIVE, NULL, "None");
Cmd_AddCommand ("toggle_auxlook", Toggle_AuxLook_f, "No Description");
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "No Description");
IN_StartupMouse ();
IN_StartupJoystick ();
i = COM_CheckParm ("-control");
if (i) {
extern_control = real2ptr (Q_atoi (com_argv[i + 1]));
IN_StartupExternal ();
}
}
/*
===========
IN_Shutdown
===========
*/
void
IN_Shutdown (void)
{
}
/*
===========
IN_Commands
===========
*/
void
IN_Commands (void)
{
int i;
if (mouse_avail) {
regs.x.ax = 3; // read buttons
dos_int86 (0x33);
mouse_buttonstate = regs.x.bx;
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mouse_buttonstate & (1 << i)) &&
!(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, true);
}
if (!(mouse_buttonstate & (1 << i)) &&
(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, false);
}
}
mouse_oldbuttonstate = mouse_buttonstate;
}
if (joy_avail) {
joy_buttonstate = ((dos_inportb (0x201) >> 4) & 15) ^ 15;
// perform button actions
for (i = 0; i < joy_numbuttons->int_val; i++) {
if ((joy_buttonstate & (1 << i)) &&
!(joy_oldbuttonstate & (1 << i))) {
Key_Event (K_JOY1 + i, true);
}
if (!(joy_buttonstate & (1 << i)) &&
(joy_oldbuttonstate & (1 << i))) {
Key_Event (K_JOY1 + i, false);
}
}
joy_oldbuttonstate = joy_buttonstate;
}
if (extern_avail) {
extern_buttonstate = extern_control->buttons;
// perform button actions
for (i = 0; i < extern_buttons; i++) {
if ((extern_buttonstate & (1 << i)) &&
!(extern_oldbuttonstate & (1 << i))) {
Key_Event (K_AUX1 + i, true);
}
if (!(extern_buttonstate & (1 << i)) &&
(extern_oldbuttonstate & (1 << i))) {
Key_Event (K_AUX1 + i, false);
}
}
extern_oldbuttonstate = extern_buttonstate;
}
}
/*
===========
IN_Move
===========
*/
void
IN_MouseMove (void)
{
int mx, my;
if (!mouse_avail)
return;
regs.x.ax = 11; // read move
dos_int86 (0x33);
mx = (short) regs.x.cx;
my = (short) regs.x.dx;
if (m_filter->int_val) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ((in_strafe.state & 1) || (lookstrafe->int_val && (in_mlook.state & 1)))
cmd->sidemove += m_side->value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw->value * mouse_x;
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if (in_strafe.state & 1)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
}
/*
===========
IN_JoyMove
===========
*/
void
IN_JoyMove (void)
{
float speed, aspeed;
if (!joy_avail || !in_joystick->int_val)
return;
IN_ReadJoystick ();
if (joysticky > joyyh * 2 || joystickx > joyxh * 2)
return; // assume something jumped in and
// messed up the joystick
// reading time (win 95)
if (in_speed.state & 1)
speed = cl_movespeedkey->value;
else
speed = 1;
aspeed = speed * host_frametime;
if (in_strafe.state & 1) {
if (joystickx < joyxl)
cmd->sidemove -= speed * cl_sidespeed->value;
else if (joystickx > joyxh)
cmd->sidemove += speed * cl_sidespeed->value;
} else {
if (joystickx < joyxl)
cl.viewangles[YAW] += aspeed * cl_yawspeed->value;
else if (joystickx > joyxh)
cl.viewangles[YAW] -= aspeed * cl_yawspeed->value;
cl.viewangles[YAW] = anglemod (cl.viewangles[YAW]);
}
if (in_mlook.state & 1) {
if (m_pitch->value < 0)
speed *= -1;
if (joysticky < joyyl)
cl.viewangles[PITCH] += aspeed * cl_pitchspeed->value;
else if (joysticky > joyyh)
cl.viewangles[PITCH] -= aspeed * cl_pitchspeed->value;
} else {
if (joysticky < joyyl)
cmd->forwardmove += speed * cl_forwardspeed->value;
else if (joysticky > joyyh)
cmd->forwardmove -= speed * cl_backspeed->value;
}
}
/*
===========
IN_Move
===========
*/
void
IN_Move (void)
{
IN_MouseMove ();
IN_JoyMove ();
IN_ExternalMove (cmd);
}
/*
============================================================================
JOYSTICK
============================================================================
*/
qboolean
IN_ReadJoystick (void)
{
int b;
int count;
joystickx = 0;
joysticky = 0;
count = 0;
b = dos_inportb (0x201);
dos_outportb (0x201, b);
// clear counters
while (++count < 10000) {
b = dos_inportb (0x201);
joystickx += b & 1;
joysticky += (b & 2) >> 1;
if (!(b & 3))
return true;
}
Con_Printf ("IN_ReadJoystick: no response\n");
joy_avail = false;
return false;
}
/*
=============
WaitJoyButton
=============
*/
qboolean
WaitJoyButton (void)
{
int oldbuttons, buttons;
oldbuttons = 0;
do {
key_count = -1;
IN_SendKeyEvents ();
key_count = 0;
if (key_lastpress == K_ESCAPE) {
Con_Printf ("aborted.\n");
return false;
}
key_lastpress = 0;
SCR_UpdateScreen ();
buttons = ((dos_inportb (0x201) >> 4) & 1) ^ 1;
if (buttons != oldbuttons) {
oldbuttons = buttons;
continue;
}
} while (!buttons);
do {
key_count = -1;
IN_SendKeyEvents ();
key_count = 0;
if (key_lastpress == K_ESCAPE) {
Con_Printf ("aborted.\n");
return false;
}
key_lastpress = 0;
SCR_UpdateScreen ();
buttons = ((dos_inportb (0x201) >> 4) & 1) ^ 1;
if (buttons != oldbuttons) {
oldbuttons = buttons;
continue;
}
} while (buttons);
return true;
}
/*
===============
IN_StartupJoystick
===============
*/
void
IN_StartupJoystick (void)
{
int centerx, centery;
Con_Printf ("\n");
joy_avail = false;
if (COM_CheckParm ("-nojoy"))
return;
if (!IN_ReadJoystick ()) {
joy_avail = false;
Con_Printf ("joystick not found\n");
return;
}
Con_Printf ("joystick found\n");
Con_Printf ("CENTER the joystick\nand press button 1 (ESC to skip):\n");
if (!WaitJoyButton ())
return;
IN_ReadJoystick ();
centerx = joystickx;
centery = joysticky;
Con_Printf
("Push the joystick to the UPPER LEFT\nand press button 1 (ESC to skip):\n");
if (!WaitJoyButton ())
return;
IN_ReadJoystick ();
joyxl = (centerx + joystickx) / 2;
joyyl = (centerx + joysticky) / 2;
Con_Printf
("Push the joystick to the LOWER RIGHT\nand press button 1 (ESC to skip):\n");
if (!WaitJoyButton ())
return;
IN_ReadJoystick ();
joyxh = (centerx + joystickx) / 2;
joyyh = (centery + joysticky) / 2;
joy_avail = true;
Con_Printf ("joystick configured.\n");
Con_Printf ("\n");
}
/*
============================================================================
EXTERNAL
============================================================================
*/
/*
===============
IN_StartupExternal
===============
*/
void
IN_StartupExternal (void)
{
if (extern_control->numButtons > 32)
extern_control->numButtons = 32;
Con_Printf ("%s Initialized\n", extern_control->deviceName);
Con_Printf (" %u axes %u buttons\n", extern_control->numAxes,
extern_control->numButtons);
extern_avail = true;
extern_buttons = extern_control->numButtons;
}
/*
===========
IN_ExternalMove
===========
*/
void
IN_ExternalMove (usercmd_t *cmd)
{
qboolean freelook;
if (!extern_avail)
return;
extern_control->viewangles[YAW] = cl.viewangles[YAW];
extern_control->viewangles[PITCH] = cl.viewangles[PITCH];
extern_control->viewangles[ROLL] = cl.viewangles[ROLL];
extern_control->forwardmove = cmd->forwardmove;
extern_control->sidemove = cmd->sidemove;
extern_control->upmove = cmd->upmove;
Con_DPrintf ("IN: y:%f p:%f r:%f f:%f s:%f u:%f\n",
extern_control->viewangles[YAW],
extern_control->viewangles[PITCH],
extern_control->viewangles[ROLL], extern_control->forwardmove,
extern_control->sidemove, extern_control->upmove);
dos_int86 (extern_control->interruptVector);
Con_DPrintf ("OUT: y:%f p:%f r:%f f:%f s:%f u:%f\n",
extern_control->viewangles[YAW],
extern_control->viewangles[PITCH],
extern_control->viewangles[ROLL], extern_control->forwardmove,
extern_control->sidemove, extern_control->upmove);
cl.viewangles[YAW] = extern_control->viewangles[YAW];
cl.viewangles[PITCH] = extern_control->viewangles[PITCH];
cl.viewangles[ROLL] = extern_control->viewangles[ROLL];
cmd->forwardmove = extern_control->forwardmove;
cmd->sidemove = extern_control->sidemove;
cmd->upmove = extern_control->upmove;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
freelook = (extern_control->flags & AUX_FLAG_FREELOOK || aux_look->int_val
|| in_mlook.state & 1);
if (freelook)
V_StopPitchDrift ();
}
void
IN_HandlePause (qboolean pause)
{
}
void
IN_LL_ClearStates (void)
{
}

View file

@ -1,760 +0,0 @@
/*
vid_dos.c
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include "d_local.h"
#include "dosisms.h"
#include "vid_dos.h"
int vid_modenum;
vmode_t *pcurrentmode = NULL;
int vid_testingmode, vid_realmode;
double vid_testendtime;
cvar_t *vid_mode;
cvar_t *vid_wait;
cvar_t *vid_nopageflip;
cvar_t *_vid_wait_override;
cvar_t *_vid_default_mode;
cvar_t *_vid_default_mode_win;
cvar_t *vid_config_x;
cvar_t *vid_config_y;
cvar_t *vid_stretch_by_2;
cvar_t *_windowed_mouse;
cvar_t *vid_fullscreen_mode;
cvar_t *vid_windowed_mode;
cvar_t *block_switch;
cvar_t *vid_window_x;
cvar_t *vid_window_y;
int d_con_indirect = 0;
int numvidmodes;
vmode_t *pvidmodes;
static int firstupdate = 1;
extern regs_t regs;
void VID_TestMode_f (void);
void VID_NumModes_f (void);
void VID_DescribeCurrentMode_f (void);
void VID_DescribeMode_f (void);
void VID_DescribeModes_f (void);
byte vid_current_palette[768]; // save for mode changes
static qboolean nomodecheck = false;
unsigned d_8to24table[256]; // not used in 8 bpp mode
void VID_MenuDraw (void);
void VID_MenuKey (int key);
void
VID_InitCvars (void)
{
}
/*
================
VID_Init
================
*/
void
VID_Init (unsigned char *palette)
{
vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, NULL, "None");
vid_wait = Cvar_Get ("vid_wait", "0", CVAR_NONE, NULL, "None");
vid_nopageflip = Cvar_Get ("vid_nopageflip", "0", CVAR_ARCHIVE, NULL,
"None");
_vid_wait_override =
Cvar_Get ("_vid_wait_override", "0", CVAR_ARCHIVE, NULL, "None");
_vid_default_mode =
Cvar_Get ("_vid_default_mode", "0", CVAR_ARCHIVE, NULL, "None");
_vid_default_mode_win =
Cvar_Get ("_vid_default_mode_win", "3", CVAR_ARCHIVE, NULL, "None");
vid_config_x = Cvar_Get ("vid_config_x", "800", CVAR_ARCHIVE, NULL, "None");
vid_config_y = Cvar_Get ("vid_config_y", "600", CVAR_ARCHIVE, NULL, "None");
vid_stretch_by_2 = Cvar_Get ("vid_stretch_by_2", "1", CVAR_ARCHIVE, NULL,
"None");
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"None");
vid_fullscreen_mode =
Cvar_Get ("vid_fullscreen_mode", "3", CVAR_ARCHIVE, NULL, "None");
vid_windowed_mode =
Cvar_Get ("vid_windowed_mode", "0", CVAR_ARCHIVE, NULL, "None");
block_switch = Cvar_Get ("block_switch", "0", CVAR_ARCHIVE, NULL, "None");
Cmd_AddCommand ("vid_testmode", VID_TestMode_f, "No Description");
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f,
"No Description");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "No Description");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "No Description");
// set up the mode list; note that later inits link in their modes ahead of
// earlier ones, so the standard VGA modes are always first in the list. This
// is important because mode 0 must always be VGA mode 0x13
if (!COM_CheckParm ("-stdvid"))
VID_InitExtra ();
VGA_Init ();
vid_testingmode = 0;
vid_modenum = vid_mode->int_val;
VID_SetMode (vid_modenum, palette);
vid_realmode = vid_modenum;
vid_menudrawfn = VID_MenuDraw;
vid_menukeyfn = VID_MenuKey;
vid.initialized = true;
}
/*
=================
VID_GetModePtr
=================
*/
vmode_t *
VID_GetModePtr (int modenum)
{
vmode_t *pv;
pv = pvidmodes;
if (!pv)
Sys_Error ("VID_GetModePtr: empty vid mode list");
while (modenum--) {
pv = pv->pnext;
if (!pv)
Sys_Error ("VID_GetModePtr: corrupt vid mode list");
}
return pv;
}
/*
================
VID_NumModes
================
*/
int
VID_NumModes ()
{
return (numvidmodes);
}
/*
================
VID_ModeInfo
================
*/
char *
VID_ModeInfo (int modenum, char **ppheader)
{
static char *badmodestr = "Bad mode number";
vmode_t *pv;
pv = VID_GetModePtr (modenum);
if (!pv) {
if (ppheader)
*ppheader = NULL;
return badmodestr;
} else {
if (ppheader)
*ppheader = pv->header;
return pv->name;
}
}
/*
================
VID_SetMode
================
*/
int
VID_SetMode (int modenum, unsigned char *palette)
{
int stat;
vmode_t *pnewmode, *poldmode;
if ((modenum >= numvidmodes) || (modenum < 0)) {
Cvar_SetValue (vid_mode, (float) vid_modenum);
nomodecheck = true;
Con_Printf ("No such video mode: %d\n", modenum);
nomodecheck = false;
if (pcurrentmode == NULL) {
modenum = 0; // mode hasn't been set yet, so
// initialize to base
// mode since they gave us an invalid initial mode
} else {
return 0;
}
}
pnewmode = VID_GetModePtr (modenum);
if (pnewmode == pcurrentmode)
return 1; // already in the desired mode
// initialize the new mode
poldmode = pcurrentmode;
pcurrentmode = pnewmode;
vid.width = pcurrentmode->width;
vid.height = pcurrentmode->height;
vid.aspect = pcurrentmode->aspect;
vid.rowbytes = pcurrentmode->rowbytes;
stat = (*pcurrentmode->setmode) (&vid, pcurrentmode);
if (stat < 1) {
if (stat == 0) {
// real, hard failure that requires resetting the mode
if (!VID_SetMode (vid_modenum, palette)) // restore prior mode
Sys_Error ("VID_SetMode: Unable to set any mode, probably "
"because there's not enough memory available");
Con_Printf ("Failed to set mode %d\n", modenum);
return 0;
} else if (stat == -1) {
// not enough memory; just put things back the way they were
pcurrentmode = poldmode;
vid.width = pcurrentmode->width;
vid.height = pcurrentmode->height;
vid.aspect = pcurrentmode->aspect;
vid.rowbytes = pcurrentmode->rowbytes;
return 0;
} else {
Sys_Error ("VID_SetMode: invalid setmode return code %d");
}
}
(*pcurrentmode->setpalette) (&vid, pcurrentmode, palette);
vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float) vid_modenum);
nomodecheck = true;
Con_Printf ("%s\n", VID_ModeInfo (vid_modenum, NULL));
nomodecheck = false;
vid.recalc_refdef = 1;
return 1;
}
/*
================
VID_SetPalette
================
*/
void
VID_SetPalette (unsigned char *palette)
{
if (palette != vid_current_palette)
Q_memcpy (vid_current_palette, palette, 768);
(*pcurrentmode->setpalette) (&vid, pcurrentmode, vid_current_palette);
}
/*
================
VID_Shutdown
================
*/
void
VID_Shutdown (void)
{
regs.h.ah = 0;
regs.h.al = 0x3;
dos_int86 (0x10);
vid_testingmode = 0;
}
/*
================
VID_Update
================
*/
void
VID_Update (vrect_t *rects)
{
if (firstupdate && _vid_default_mode->int_val) {
if (_vid_default_mode->int_val >= numvidmodes)
Cvar_SetValue (_vid_default_mode, 0);
firstupdate = 0;
Cvar_SetValue (vid_mode, _vid_default_mode->int_val);
}
(*pcurrentmode->swapbuffers) (&vid, pcurrentmode, rects);
if (!nomodecheck) {
if (vid_testingmode) {
if (realtime >= vid_testendtime) {
VID_SetMode (vid_realmode, vid_current_palette);
vid_testingmode = 0;
}
} else {
if (vid_mode->int_val != vid_realmode) {
VID_SetMode (vid_mode->int_val, vid_current_palette);
Cvar_SetValue (vid_mode, (float) vid_modenum);
// so if mode set fails, we don't keep on
// trying to set that mode
vid_realmode = vid_modenum;
}
}
}
}
/*
=================
VID_NumModes_f
=================
*/
void
VID_NumModes_f (void)
{
int nummodes;
nummodes = VID_NumModes ();
if (nummodes == 1)
Con_Printf ("%d video mode is available\n", VID_NumModes ());
else
Con_Printf ("%d video modes are available\n", VID_NumModes ());
}
/*
=================
VID_DescribeCurrentMode_f
=================
*/
void
VID_DescribeCurrentMode_f (void)
{
Con_Printf ("%s\n", VID_ModeInfo (vid_modenum, NULL));
}
/*
=================
VID_DescribeMode_f
=================
*/
void
VID_DescribeMode_f (void)
{
int modenum;
modenum = Q_atoi (Cmd_Argv (1));
Con_Printf ("%s\n", VID_ModeInfo (modenum, NULL));
}
/*
=================
VID_DescribeModes_f
=================
*/
void
VID_DescribeModes_f (void)
{
int i, nummodes;
char *pinfo, *pheader;
vmode_t *pv;
qboolean na;
na = false;
nummodes = VID_NumModes ();
for (i = 0; i < nummodes; i++) {
pv = VID_GetModePtr (i);
pinfo = VID_ModeInfo (i, &pheader);
if (pheader)
Con_Printf ("\n%s\n", pheader);
if (VGA_CheckAdequateMem (pv->width, pv->height, pv->rowbytes,
(pv->numpages == 1)
|| vid_nopageflip->int_val)) {
Con_Printf ("%2d: %s\n", i, pinfo);
} else {
Con_Printf ("**: %s\n", pinfo);
na = true;
}
}
if (na) {
Con_Printf ("\n[**: not enough system RAM for mode]\n");
}
}
/*
=================
VID_GetModeDescription
=================
*/
char *
VID_GetModeDescription (int mode)
{
char *pinfo, *pheader;
vmode_t *pv;
pv = VID_GetModePtr (mode);
pinfo = VID_ModeInfo (mode, &pheader);
if (VGA_CheckAdequateMem (pv->width, pv->height, pv->rowbytes,
(pv->numpages == 1) || vid_nopageflip->int_val)) {
return pinfo;
} else {
return NULL;
}
}
/*
=================
VID_TestMode_f
=================
*/
void
VID_TestMode_f (void)
{
int modenum;
double testduration;
if (!vid_testingmode) {
modenum = Q_atoi (Cmd_Argv (1));
if (VID_SetMode (modenum, vid_current_palette)) {
vid_testingmode = 1;
testduration = Q_atof (Cmd_Argv (2));
if (testduration == 0)
testduration = 5.0;
vid_testendtime = realtime + testduration;
}
}
}
/*
================
D_BeginDirectRect
================
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
if (!vid.direct || !pcurrentmode)
return;
if ((width > 24) || (height > 24) || (width < 1) || (height < 1))
return;
if (width & 0x03)
return;
(*pcurrentmode->begindirectrect) (&vid, pcurrentmode, x, y, pbitmap, width,
height);
}
/*
================
D_EndDirectRect
================
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
if (!vid.direct || !pcurrentmode)
return;
if ((width > 24) || (height > 24) || (width < 1) || (height < 1))
return;
if ((width & 0x03) || (height & 0x03))
return;
(*pcurrentmode->enddirectrect) (&vid, pcurrentmode, x, y, width, height);
}
//===========================================================================
extern void M_Menu_Options_f (void);
extern void M_Print (int cx, int cy, char *str);
extern void M_PrintWhite (int cx, int cy, char *str);
extern void M_DrawCharacter (int cx, int line, int num);
extern void M_DrawTransPic (int x, int y, qpic_t *pic);
extern void M_DrawPic (int x, int y, qpic_t *pic);
static int vid_line, vid_wmodes, vid_column_size;
typedef struct {
int modenum;
char *desc;
int iscur;
} modedesc_t;
#define MAX_COLUMN_SIZE 11
#define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
static modedesc_t modedescs[MAX_MODEDESCS];
/*
================
VID_MenuDraw
================
*/
void
VID_MenuDraw (void)
{
qpic_t *p;
char *ptr;
int nummodes, i, j, column, row, dup;
char temp[100];
vid_wmodes = 0;
nummodes = VID_NumModes ();
p = Draw_CachePic ("gfx/vidmodes.lmp");
M_DrawPic ((320 - p->width) / 2, 4, p);
for (i = 0; i < nummodes; i++) {
if (vid_wmodes < MAX_MODEDESCS) {
if (i != 1) {
ptr = VID_GetModeDescription (i);
if (ptr) {
dup = 0;
for (j = 0; j < vid_wmodes; j++) {
if (!strcmp (modedescs[j].desc, ptr)) {
if (modedescs[j].modenum != 0) {
modedescs[j].modenum = i;
dup = 1;
if (i == vid_modenum)
modedescs[j].iscur = 1;
} else {
dup = 1;
}
break;
}
}
if (!dup) {
modedescs[vid_wmodes].modenum = i;
modedescs[vid_wmodes].desc = ptr;
modedescs[vid_wmodes].iscur = 0;
if (i == vid_modenum)
modedescs[vid_wmodes].iscur = 1;
vid_wmodes++;
}
}
}
}
}
vid_column_size = (vid_wmodes + 2) / 3;
column = 16;
row = 36;
for (i = 0; i < vid_wmodes; i++) {
if (modedescs[i].iscur)
M_PrintWhite (column, row, modedescs[i].desc);
else
M_Print (column, row, modedescs[i].desc);
row += 8;
if ((i % vid_column_size) == (vid_column_size - 1)) {
column += 13 * 8;
row = 36;
}
}
// line cursor
if (vid_testingmode) {
snprintf (temp, sizeof (temp), "TESTING %s", modedescs[vid_line].desc);
M_Print (13 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 4, temp);
M_Print (9 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 6,
"Please wait 5 seconds...");
} else {
M_Print (9 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8,
"Press Enter to set mode");
M_Print (6 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 3,
"T to test mode for 5 seconds");
ptr = VID_GetModeDescription (vid_modenum);
snprintf (temp, sizeof (temp), "D to make %s the default", ptr);
M_Print (6 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 5, temp);
ptr = VID_GetModeDescription (_vid_default_mode->int_val);
if (ptr) {
snprintf (temp, sizeof (temp), "Current default is %s", ptr);
M_Print (7 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 6, temp);
}
M_Print (15 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 8, "Esc to exit");
row = 36 + (vid_line % vid_column_size) * 8;
column = 8 + (vid_line / vid_column_size) * 13 * 8;
M_DrawCharacter (column, row, 12 + ((int) (realtime * 4) & 1));
}
}
/*
================
VID_MenuKey
================
*/
void
VID_MenuKey (int key)
{
if (vid_testingmode)
return;
switch (key) {
case K_ESCAPE:
S_LocalSound ("misc/menu1.wav");
M_Menu_Options_f ();
break;
case K_UPARROW:
S_LocalSound ("misc/menu1.wav");
vid_line--;
if (vid_line < 0)
vid_line = vid_wmodes - 1;
break;
case K_DOWNARROW:
S_LocalSound ("misc/menu1.wav");
vid_line++;
if (vid_line >= vid_wmodes)
vid_line = 0;
break;
case K_LEFTARROW:
S_LocalSound ("misc/menu1.wav");
vid_line -= vid_column_size;
if (vid_line < 0) {
vid_line += ((vid_wmodes + (vid_column_size - 1)) /
vid_column_size) * vid_column_size;
while (vid_line >= vid_wmodes)
vid_line -= vid_column_size;
}
break;
case K_RIGHTARROW:
S_LocalSound ("misc/menu1.wav");
vid_line += vid_column_size;
if (vid_line >= vid_wmodes) {
vid_line -= ((vid_wmodes + (vid_column_size - 1)) /
vid_column_size) * vid_column_size;
while (vid_line < 0)
vid_line += vid_column_size;
}
break;
case K_ENTER:
S_LocalSound ("misc/menu1.wav");
VID_SetMode (modedescs[vid_line].modenum, vid_current_palette);
break;
case 'T':
case 't':
S_LocalSound ("misc/menu1.wav");
if (VID_SetMode (modedescs[vid_line].modenum, vid_current_palette)) {
vid_testingmode = 1;
vid_testendtime = realtime + 5.0;
}
break;
case 'D':
case 'd':
S_LocalSound ("misc/menu1.wav");
firstupdate = 0;
Cvar_SetValue (_vid_default_mode, vid_modenum);
break;
default:
break;
}
}
void
VID_HandlePause (qboolean pause)
{
}

View file

@ -1,302 +0,0 @@
/*
dos_v2.c
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <sys/segments.h>
#include <go32.h>
#include <unistd.h>
#include <sys/nearptr.h>
#include <dos.h>
#include <dpmi.h>
// #include <osfcn.h>
#include <bios.h>
#include "dosisms.h"
_go32_dpmi_registers hmm;
// globals
regs_t regs;
void (*dos_error_func) (char *msg, ...);
static unsigned conventional_memory = -1;
__dpmi_regs callback_regs;
void
map_in_conventional_memory (void)
{
if (conventional_memory == -1) {
if (__djgpp_nearptr_enable ()) {
conventional_memory = __djgpp_conventional_base;
}
}
}
unsigned int
ptr2real (void *ptr)
{
map_in_conventional_memory ();
return (int) ptr - conventional_memory;
}
void *
real2ptr (unsigned int real)
{
map_in_conventional_memory ();
return (void *) (real + conventional_memory);
}
void *
far2ptr (unsigned int farptr)
{
return real2ptr (((farptr & ~0xffff) >> 12) + (farptr & 0xffff));
}
unsigned int
ptr2far (void *ptr)
{
return ((ptr2real (ptr) & ~0xf) << 12) + (ptr2real (ptr) & 0xf);
}
int
dos_inportb (int port)
{
return inportb (port);
}
int
dos_inportw (int port)
{
return inportw (port);
}
void
dos_outportb (int port, int val)
{
outportb (port, val);
}
void
dos_outportw (int port, int val)
{
outportw (port, val);
}
void
dos_irqenable (void)
{
enable ();
}
void
dos_irqdisable (void)
{
disable ();
}
// Returns 0 on success
int
dos_int86 (int vec)
{
int rc;
regs.x.ss = regs.x.sp = 0;
rc = _go32_dpmi_simulate_int (vec, (_go32_dpmi_registers *) & regs);
return rc || (regs.x.flags & 1);
}
int
dos_int386 (int vec, regs_t * inregs, regs_t * outregs)
{
int rc;
memcpy (outregs, inregs, sizeof (regs_t));
outregs->x.ss = outregs->x.sp = 0;
rc = _go32_dpmi_simulate_int (vec, (_go32_dpmi_registers *) outregs);
return rc || (outregs->x.flags & 1);
}
// Because of a quirk in dj's alloc-dos-memory wrapper, you need to keep
// the seginfo structure around for when you free the mem.
static _go32_dpmi_seginfo seginfo[10];
void *
dos_getmemory (int size)
{
int rc;
_go32_dpmi_seginfo info;
static int firsttime = 1;
int i;
if (firsttime) {
memset (seginfo, 0, sizeof (seginfo));
firsttime = 0;
}
info.size = (size + 15) / 16;
rc = _go32_dpmi_allocate_dos_memory (&info);
if (rc)
return 0;
for (i = 0; i < 10; i++)
if (!seginfo[i].rm_segment)
break;
seginfo[i] = info;
return real2ptr ((int) info.rm_segment << 4);
}
void
dos_freememory (void *ptr)
{
int i;
int segment;
segment = ptr2real (ptr) >> 4;
for (i = 0; i < 10; i++)
if (seginfo[i].rm_segment == segment) {
_go32_dpmi_free_dos_memory (&seginfo[i]);
seginfo[i].rm_segment = 0;
break;
}
}
static struct handlerhistory_s {
int intr;
_go32_dpmi_seginfo pm_oldvec;
} handlerhistory[4];
static int handlercount = 0;
void
dos_registerintr (int intr, void (*handler) (void))
{
_go32_dpmi_seginfo info;
struct handlerhistory_s *oldstuff;
oldstuff = &handlerhistory[handlercount];
// remember old handler
_go32_dpmi_get_protected_mode_interrupt_vector (intr, &oldstuff->pm_oldvec);
oldstuff->intr = intr;
info.pm_offset = (int) handler;
_go32_dpmi_allocate_iret_wrapper (&info);
// set new protected mode handler
_go32_dpmi_set_protected_mode_interrupt_vector (intr, &info);
handlercount++;
}
void
dos_restoreintr (int intr)
{
int i;
struct handlerhistory_s *oldstuff;
// find and reinstall previous interrupt
for (i = 0; i < handlercount; i++) {
oldstuff = &handlerhistory[i];
if (oldstuff->intr == intr) {
_go32_dpmi_set_protected_mode_interrupt_vector (intr,
&oldstuff->
pm_oldvec);
oldstuff->intr = -1;
break;
}
}
}
void
dos_usleep (int usecs)
{
usleep (usecs);
}
int
dos_getheapsize (void)
{
return _go32_dpmi_remaining_physical_memory ();
}
int
dos_lockmem (void *addr, int size)
{
__dpmi_meminfo info;
info.address = (long) addr + __djgpp_base_address;
info.size = size;
if (__dpmi_lock_linear_region (&info))
return __dpmi_error;
else
return 0;
}
int
dos_unlockmem (void *addr, int size)
{
__dpmi_meminfo info;
info.address = (long) addr + __djgpp_base_address;
info.size = size;
if (__dpmi_unlock_linear_region (&info))
return __dpmi_error;
else
return 0;
}

View file

@ -1,77 +0,0 @@
#include "asm_i386.h"
.data
fpenv: .long 0, 0, 0, 0, 0, 0, 0, 0
.text
.globl C(StartMSRInterval)
C(StartMSRInterval):
movl $0x11,%ecx // read the CESR
.byte 0x0F
.byte 0x32 // RDMSR
andl $0xFE3FFE3F,%eax // stop both counters
.byte 0x0F
.byte 0x30 // WRMSR
movl 4(%esp),%eax // point counter 0 to desired event, with counters
andl $0x3F,%eax // still stopped
movl $0x11,%ecx
.byte 0x0F
.byte 0x30 // WRMSR
movl $0x12,%ecx // set counter 0 to the value 0
subl %eax,%eax
subl %edx,%edx
.byte 0x0F
.byte 0x30 // WRMSR
movl 4(%esp),%eax // restart counter 0 with selected event
andl $0x3F,%eax
subl %edx,%edx
orl $0xC0,%eax
movl $0x11,%ecx // control and event select
.byte 0x0F
.byte 0x30 // WRMSR
ret
.globl C(EndMSRInterval)
C(EndMSRInterval):
movl $0x12,%ecx // counter 0
.byte 0x0F
.byte 0x32 // RDMSR
ret // lower 32 bits of count in %eax
#if 0
.data
Lxxx: .long 0
.text
.globl C(setstackcheck)
C(setstackcheck):
movl %esp,%eax
subl $0x38000,%eax
movl $0x5A5A5A5A,(%eax)
movl %eax,Lxxx
ret
.globl C(dostackcheck)
C(dostackcheck):
movl Lxxx,%edx
movl $0,%eax
cmpl $0x5A5A5A5A,(%edx)
jz qqq
incl %eax
qqq:
ret
#endif

View file

@ -1,937 +0,0 @@
/*
sys_dos.c
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <dir.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/stat.h>
#include <dpmi.h>
#include <sys/nearptr.h>
#include <conio.h>
#include "dosisms.h"
#define MINIMUM_WIN_MEMORY 0x800000
#define MINIMUM_WIN_MEMORY_LEVELPAK (MINIMUM_WIN_MEMORY + 0x100000)
int end_of_memory;
qboolean lockmem, lockunlockmem, unlockmem;
static int win95;
#define STDOUT 1
#define KEYBUF_SIZE 256
static unsigned char keybuf[KEYBUF_SIZE];
static int keybuf_head = 0;
static int keybuf_tail = 0;
static quakeparms_t quakeparms;
int sys_checksum;
static double curtime = 0.0;
static double lastcurtime = 0.0;
static double oldtime = 0.0;
static qboolean isDedicated;
static int minmem;
float fptest_temp;
extern char start_of_memory __asm__ ("start");
//=============================================================================
// this is totally dependent on cwsdpmi putting the stack right after tge
// global data
// This does evil things in a Win95 DOS box!!!
#if 0
extern byte end;
#define CHECKBYTE 0xed
void
Sys_InitStackCheck (void)
{
int i;
for (i = 0; i < 128 * 1024; i++)
(&end)[i] = CHECKBYTE;
}
void
Sys_StackCheck (void)
{
int i;
for (i = 0; i < 128 * 1024; i++)
if ((&end)[i] != CHECKBYTE)
break;
Con_Printf ("%i undisturbed stack bytes\n", i);
if (end != CHECKBYTE)
Sys_Error ("System stack overflow!");
}
#endif
//=============================================================================
byte scantokey[128] = {
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0, 27, '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', 13, K_CTRL, 'a', 's', // 1
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', K_SHIFT, '\\', 'z', 'x', 'c', 'v', // 2
'b', 'n', 'm', ',', '.', '/', K_SHIFT, '*',
K_ALT, ' ', 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
K_F6, K_F7, K_F8, K_F9, K_F10, 0, 0, K_HOME,
K_UPARROW, K_PGUP, '-', K_LEFTARROW, '5', K_RIGHTARROW, '+', K_END, // 4
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // 6
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 // 7
};
byte shiftscantokey[128] = {
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0, 27, '!', '@', '#', '$', '%', '^',
'&', '*', '(', ')', '_', '+', K_BACKSPACE, 9, // 0
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', '{', '}', 13, K_CTRL, 'A', 'S', // 1
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
'"', '~', K_SHIFT, '|', 'Z', 'X', 'C', 'V', // 2
'B', 'N', 'M', '<', '>', '?', K_SHIFT, '*',
K_ALT, ' ', 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
K_F6, K_F7, K_F8, K_F9, K_F10, 0, 0, K_HOME,
K_UPARROW, K_PGUP, '_', K_LEFTARROW, '%', K_RIGHTARROW, '+', K_END, // 4
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // 6
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 // 7
};
void
TrapKey (void)
{
// static int ctrl=0;
keybuf[keybuf_head] = dos_inportb (0x60);
dos_outportb (0x20, 0x20);
/*
if (scantokey[keybuf[keybuf_head]&0x7f] == K_CTRL)
ctrl=keybuf[keybuf_head]&0x80; if (ctrl &&
scantokey[keybuf[keybuf_head]&0x7f] == 'c') Sys_Error("ctrl-c hit\n");
*/
keybuf_head = (keybuf_head + 1) & (KEYBUF_SIZE - 1);
}
#define SC_UPARROW 0x48
#define SC_DOWNARROW 0x50
#define SC_LEFTARROW 0x4b
#define SC_RIGHTARROW 0x4d
#define SC_LEFTSHIFT 0x2a
#define SC_RIGHTSHIFT 0x36
#define SC_RIGHTARROW 0x4d
void MaskExceptions (void);
void Sys_InitFloatTime (void);
void Sys_PushFPCW_SetHigh (void);
void Sys_PopFPCW (void);
#define LEAVE_FOR_CACHE (512*1024) // FIXME: tune
#define LOCKED_FOR_MALLOC (128*1024) // FIXME: tune
void
Sys_DetectWin95 (void)
{
__dpmi_regs r;
r.x.ax = 0x160a; /* Get Windows Version */
__dpmi_int (0x2f, &r);
if (r.x.ax || r.h.bh < 4) { /* Not windows or earlier than Win95 */
win95 = 0;
lockmem = true;
lockunlockmem = false;
unlockmem = true;
} else {
win95 = 1;
lockunlockmem = COM_CheckParm ("-winlockunlock");
if (lockunlockmem)
lockmem = true;
else
lockmem = COM_CheckParm ("-winlock");
unlockmem = lockmem && !lockunlockmem;
}
}
void *
dos_getmaxlockedmem (int *size)
{
__dpmi_free_mem_info meminfo;
__dpmi_meminfo info;
int working_size;
void *working_memory;
int last_locked;
int extra, i, j, allocsize;
static char *msg = "Locking data...";
int m, n;
byte *x;
// first lock all the current executing image so the locked count will
// be accurate. It doesn't hurt to lock the memory multiple times
last_locked = __djgpp_selector_limit + 1;
info.size = last_locked - 4096;
info.address = __djgpp_base_address + 4096;
if (lockmem) {
if (__dpmi_lock_linear_region (&info)) {
Sys_Error ("Lock of current memory at 0x%lx for %ldKb failed!\n",
info.address, info.size / 1024);
}
}
__dpmi_get_free_memory_information (&meminfo);
if (!win95) { /* Not windows or earlier than Win95 */
working_size = meminfo.maximum_locked_page_allocation_in_pages * 4096;
} else {
working_size = meminfo.largest_available_free_block_in_bytes -
LEAVE_FOR_CACHE;
}
working_size &= ~0xffff; /* Round down to 64K */
working_size += 0x10000;
do {
working_size -= 0x10000; /* Decrease 64K and try again */
working_memory = sbrk (working_size);
} while (working_memory == (void *) -1);
extra = 0xfffc - ((unsigned) sbrk (0) & 0xffff);
if (extra > 0) {
sbrk (extra);
working_size += extra;
}
// now grab the memory
info.address = last_locked + __djgpp_base_address;
if (!win95) {
info.size = __djgpp_selector_limit + 1 - last_locked;
while (info.size > 0 && __dpmi_lock_linear_region (&info)) {
info.size -= 0x1000;
working_size -= 0x1000;
sbrk (-0x1000);
}
} else { /* Win95 section */
j = COM_CheckParm ("-winmem");
if (standard_quake)
minmem = MINIMUM_WIN_MEMORY;
else
minmem = MINIMUM_WIN_MEMORY_LEVELPAK;
if (j) {
allocsize = ((int) (Q_atoi (com_argv[j + 1]))) * 0x100000 +
LOCKED_FOR_MALLOC;
if (allocsize < (minmem + LOCKED_FOR_MALLOC))
allocsize = minmem + LOCKED_FOR_MALLOC;
} else {
allocsize = minmem + LOCKED_FOR_MALLOC;
}
if (!lockmem) {
// we won't lock, just sbrk the memory
info.size = allocsize;
goto UpdateSbrk;
}
// lock the memory down
write (STDOUT, msg, strlen (msg));
for (j = allocsize; j > (minmem + LOCKED_FOR_MALLOC); j -= 0x100000) {
info.size = j;
if (!__dpmi_lock_linear_region (&info))
goto Locked;
write (STDOUT, ".", 1);
}
// finally, try with the absolute minimum amount
for (i = 0; i < 10; i++) {
info.size = minmem + LOCKED_FOR_MALLOC;
if (!__dpmi_lock_linear_region (&info))
goto Locked;
}
Sys_Error ("Can't lock memory; %d Mb lockable RAM required. "
"Try shrinking smartdrv.", info.size / 0x100000);
Locked:
UpdateSbrk:
info.address += info.size;
info.address -= __djgpp_base_address + 4; // ending point, malloc
// align
working_size = info.address - (int) working_memory;
sbrk (info.address - (int) sbrk (0)); // negative adjustment
}
if (lockunlockmem) {
__dpmi_unlock_linear_region (&info);
printf ("Locked and unlocked %d Mb data\n", working_size / 0x100000);
} else if (lockmem) {
printf ("Locked %d Mb data\n", working_size / 0x100000);
} else {
printf ("Allocated %d Mb data\n", working_size / 0x100000);
}
// touch all the memory to make sure it's there. The 16-page skip is to
// keep Win 95 from thinking we're trying to page ourselves in (we are
// doing that, of course, but there's no reason we shouldn't)
x = (byte *) working_memory;
for (n = 0; n < 4; n++) {
for (m = 0; m < (working_size - 16 * 0x1000); m += 4) {
sys_checksum += *(int *) &x[m];
sys_checksum += *(int *) &x[m + 16 * 0x1000];
}
}
// give some of what we locked back for malloc before returning. Done
// by cheating and passing a negative value to sbrk
working_size -= LOCKED_FOR_MALLOC;
sbrk (-(LOCKED_FOR_MALLOC));
*size = working_size;
return working_memory;
}
/*
============
Sys_FileTime
returns -1 if not present
============
*/
int
Sys_FileTime (char *path)
{
struct stat buf;
if (stat (path, &buf) == -1)
return -1;
return buf.st_mtime;
}
void
Sys_mkdir (char *path)
{
mkdir (path, 0777);
}
void
Sys_Sleep (void)
{
}
char *
Sys_ConsoleInput (void)
{
static char text[256];
static int len = 0;
char ch;
if (!isDedicated)
return NULL;
if (!kbhit ())
return NULL;
ch = getche ();
switch (ch) {
case '\r':
putch ('\n');
if (len) {
text[len] = 0;
len = 0;
return text;
}
break;
case '\b':
putch (' ');
if (len) {
len--;
putch ('\b');
}
break;
default:
text[len] = ch;
len = (len + 1) & 0xff;
break;
}
return NULL;
}
void
Sys_Init (void)
{
MaskExceptions ();
Sys_SetFPCW ();
dos_outportb (0x43, 0x34); // set system timer to mode 2
dos_outportb (0x40, 0); // for the Sys_DoubleTime() function
dos_outportb (0x40, 0);
Sys_InitFloatTime ();
_go32_interrupt_stack_size = 4 * 1024;;
_go32_rmcb_stack_size = 4 * 1024;
}
void
Sys_Shutdown (void)
{
if (!isDedicated)
dos_restoreintr (9);
if (unlockmem) {
dos_unlockmem (&start_of_memory,
end_of_memory - (int) &start_of_memory);
dos_unlockmem (quakeparms.membase, quakeparms.memsize);
}
}
#define SC_RSHIFT 0x36
#define SC_LSHIFT 0x2a
void
IN_SendKeyEvents (void)
{
int k, next;
int outkey;
// get key events
while (keybuf_head != keybuf_tail) {
k = keybuf[keybuf_tail++];
keybuf_tail &= (KEYBUF_SIZE - 1);
if (k == 0xe0)
continue; // special / pause keys
next = keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)];
if (next == 0xe1)
continue; // pause key bullshit
if (k == 0xc5 && next == 0x9d) {
Key_Event (K_PAUSE, true);
continue;
}
// extended keyboard shift key bullshit
if ((k & 0x7f) == SC_LSHIFT || (k & 0x7f) == SC_RSHIFT) {
if (keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)] == 0xe0)
continue;
k &= 0x80;
k |= SC_RSHIFT;
}
if (k == 0xc5 && keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)] == 0x9d)
continue; // more pause bullshit
outkey = scantokey[k & 0x7f];
if (k & 0x80)
Key_Event (outkey, false);
else
Key_Event (outkey, true);
}
}
// =======================================================================
// General routines
// =======================================================================
/*
================
Sys_Printf
================
*/
void
Sys_Printf (char *fmt, ...)
{
va_list argptr;
char text[1024];
va_start (argptr, fmt);
vsnprintf (text, sizeof (text), fmt, argptr);
va_end (argptr);
if (cls.state == ca_dedicated)
fprintf (stderr, "%s", text);
}
void
Sys_AtExit (void)
{
// shutdown only once (so Sys_Error can call this function to shutdown, then
// print the error message, then call exit without exit calling this function
// again)
Sys_Shutdown ();
}
void
Sys_Quit (void)
{
byte screen[80 * 25 * 2];
byte *d;
char ver[6];
int i;
// load the sell screen before shuting everything down
if (registered->int_val)
d = COM_LoadHunkFile ("end2.bin");
else
d = COM_LoadHunkFile ("end1.bin");
if (d)
memcpy (screen, d, sizeof (screen));
// write the version number directly to the end screen
snprintf (ver, sizeof (ver), " v%4.2f", VERSION);
for (i = 0; i < 6; i++)
screen[0 * 80 * 2 + 72 * 2 + i * 2] = ver[i];
Host_Shutdown ();
// do the text mode sell screen
if (d) {
memcpy ((void *) real2ptr (0xb8000), screen, 80 * 25 * 2);
// set text pos
regs.x.ax = 0x0200;
regs.h.bh = 0;
regs.h.dl = 0;
regs.h.dh = 22;
dos_int86 (0x10);
} else
printf ("couldn't load endscreen.\n");
exit (0);
}
void
Sys_Error (char *error, ...)
{
va_list argptr;
char string[1024];
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
va_end (argptr);
Host_Shutdown ();
fprintf (stderr, "Error: %s\n", string);
// Sys_AtExit is called by exit to shutdown the system
exit (0);
}
int
Sys_FileOpenRead (char *path, int *handle)
{
int h;
struct stat fileinfo;
h = open (path, O_RDONLY | O_BINARY, 0666);
*handle = h;
if (h == -1)
return -1;
if (fstat (h, &fileinfo) == -1)
Sys_Error ("Error fstating %s", path);
return fileinfo.st_size;
}
int
Sys_FileOpenWrite (char *path)
{
int handle;
umask (0);
handle = open (path, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0666);
if (handle == -1)
Sys_Error ("Error opening %s: %s", path, strerror (errno));
return handle;
}
void
Sys_FileClose (int handle)
{
close (handle);
}
void
Sys_FileSeek (int handle, int position)
{
lseek (handle, position, SEEK_SET);
}
int
Sys_FileRead (int handle, void *dest, int count)
{
return read (handle, dest, count);
}
int
Sys_FileWrite (int handle, void *data, int count)
{
return write (handle, data, count);
}
/*
================
Sys_MakeCodeWriteable
================
*/
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
// it's always writeable
}
/*
================
Sys_DoubleTime
================
*/
double
Sys_DoubleTime (void)
{
int r;
unsigned t, tick;
double ft, time;
static int sametimecount;
Sys_PushFPCW_SetHigh ();
//{static float t = 0; t=t+0.05; return t;} // DEBUG
t = *(unsigned short *) real2ptr (0x46c) * 65536;
dos_outportb (0x43, 0); // latch time
r = dos_inportb (0x40);
r |= dos_inportb (0x40) << 8;
r = (r - 1) & 0xffff;
tick = *(unsigned short *) real2ptr (0x46c) * 65536;
if ((tick != t) && (r & 0x8000))
t = tick;
ft = (double) (t + (65536 - r)) / 1193200.0;
time = ft - oldtime;
oldtime = ft;
if (time < 0) {
if (time > -3000.0)
time = 0.0;
else
time += 3600.0;
}
curtime += time;
if (curtime == lastcurtime) {
sametimecount++;
if (sametimecount > 100000) {
curtime += 1.0;
sametimecount = 0;
}
} else {
sametimecount = 0;
}
lastcurtime = curtime;
Sys_PopFPCW ();
return curtime;
}
/*
================
Sys_InitFloatTime
================
*/
void
Sys_InitFloatTime (void)
{
int j;
Sys_DoubleTime ();
oldtime = curtime;
j = COM_CheckParm ("-starttime");
if (j) {
curtime = (double) (Q_atof (com_argv[j + 1]));
} else {
curtime = 0.0;
}
lastcurtime = curtime;
}
/*
================
Sys_GetMemory
================
*/
void
Sys_GetMemory (void)
{
int j, tsize;
j = COM_CheckParm ("-mem");
if (j) {
quakeparms.memsize = (int) (Q_atof (com_argv[j + 1]) * 1024 * 1024);
quakeparms.membase = malloc (quakeparms.memsize);
} else {
quakeparms.membase = dos_getmaxlockedmem (&quakeparms.memsize);
}
fprintf (stderr, "malloc'd: %d\n", quakeparms.memsize);
if (COM_CheckParm ("-heapsize")) {
tsize = Q_atoi (com_argv[COM_CheckParm ("-heapsize") + 1]) * 1024;
if (tsize < quakeparms.memsize)
quakeparms.memsize = tsize;
}
}
/*
================
Sys_PageInProgram
walks the text, data, and bss to make sure it's all paged in so that the
actual physical memory detected by Sys_GetMemory is correct.
================
*/
void
Sys_PageInProgram (void)
{
int i, j;
end_of_memory = (int) sbrk (0);
if (lockmem) {
if (dos_lockmem ((void *) &start_of_memory,
end_of_memory - (int) &start_of_memory))
Sys_Error ("Couldn't lock text and data");
}
if (lockunlockmem) {
dos_unlockmem ((void *) &start_of_memory,
end_of_memory - (int) &start_of_memory);
printf ("Locked and unlocked %d Mb image\n",
(end_of_memory - (int) &start_of_memory) / 0x100000);
} else if (lockmem) {
printf ("Locked %d Mb image\n",
(end_of_memory - (int) &start_of_memory) / 0x100000);
} else {
printf ("Loaded %d Mb image\n",
(end_of_memory - (int) &start_of_memory) / 0x100000);
}
// touch the entire image, doing the 16-page skip so Win95 doesn't think we're
// trying to page ourselves in
for (j = 0; j < 4; j++) {
for (i = (int) &start_of_memory; i < (end_of_memory - 16 * 0x1000);
i += 4) {
sys_checksum += *(int *) i;
sys_checksum += *(int *) (i + 16 * 0x1000);
}
}
}
/*
================
Sys_NoFPUExceptionHandler
================
*/
void
Sys_NoFPUExceptionHandler (int whatever)
{
printf ("\nError: Quake requires a floating-point processor\n");
exit (0);
}
/*
================
Sys_DefaultExceptionHandler
================
*/
void
Sys_DefaultExceptionHandler (int whatever)
{
}
/*
================
main
================
*/
int
main (int c, char **v)
{
double time, oldtime, newtime;
extern void (*dos_error_func) (char *, ...);
static char cwd[1024];
printf ("Quake v%4.2f\n", VERSION);
// make sure there's an FPU
signal (SIGNOFP, Sys_NoFPUExceptionHandler);
signal (SIGABRT, Sys_DefaultExceptionHandler);
signal (SIGALRM, Sys_DefaultExceptionHandler);
signal (SIGKILL, Sys_DefaultExceptionHandler);
signal (SIGQUIT, Sys_DefaultExceptionHandler);
signal (SIGINT, Sys_DefaultExceptionHandler);
if (fptest_temp >= 0.0)
fptest_temp += 0.1;
COM_InitArgv (c, v);
quakeparms.argc = com_argc;
quakeparms.argv = com_argv;
dos_error_func = Sys_Error;
Sys_DetectWin95 ();
Sys_PageInProgram ();
Sys_GetMemory ();
atexit (Sys_AtExit); // in case we crash
getwd (cwd);
if (cwd[Q_strlen (cwd) - 1] == '/')
cwd[Q_strlen (cwd) - 1] = 0;
quakeparms.basedir = cwd; // "f:/quake";
isDedicated = (COM_CheckParm ("-dedicated") != 0);
Sys_Init ();
if (!isDedicated)
dos_registerintr (9, TrapKey);
//Sys_InitStackCheck ();
Host_Init (&quakeparms);
//Sys_StackCheck ();
//Con_Printf ("Top of stack: 0x%x\n", &time);
oldtime = Sys_DoubleTime ();
while (1) {
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
if (cls.state == ca_dedicated && (time < sys_ticrate->value))
continue;
Host_Frame (time);
//Sys_StackCheck ();
oldtime = newtime;
}
}