From 6740fb6c86387246f00434f0096c80030af055d6 Mon Sep 17 00:00:00 2001 From: IoIxD Date: Sun, 17 May 2026 21:06:39 -0700 Subject: [PATCH] dc --- CMakeLists.txt | 84 ++++++---- compile_flags.txt | 3 + src/common.c | 225 +++++++++++++------------- src/net_udp.c | 29 ++-- src/port.c | 403 ++++++++++++++++++++++++++-------------------- src/snd_dc.c | 38 +++++ 6 files changed, 452 insertions(+), 330 deletions(-) create mode 100644 compile_flags.txt create mode 100644 src/snd_dc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2be5739..e1b6ba3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,19 +4,27 @@ project(gquake) file(GLOB SOURCES src/*.c) if(PS2) - set(GL ps2gl) + set(GL ps2gl) - set(CMAKE_EXECUTABLE_SUFFIX .elf) + set(CMAKE_EXECUTABLE_SUFFIX .elf) elseif(VITA) - set(GL vitaGL) + set(GL vitaGL) +elseif(PLATFORM_DREAMCAST) + include(kallistios) + add_compile_definitions(USE_KALLISTIOS) + add_compile_definitions(NO_FCNTL) + set(GL GL) else() - find_package(OpenGL REQUIRED) + find_package(OpenGL REQUIRED) - set(GL OpenGL::GL) + set(GL OpenGL::GL) endif() set(MILSKO "/usr/local") -option(TRY_SDL2 "Try SDL2" ON) +if(NOT PLATFORM_DREAMCAST) + option(TRY_SDL2 "Try SDL2" ON) + option(TRY_MILSKO "Try SDL2" OFF) +endif() add_executable(gquake ${SOURCES}) target_include_directories(gquake PRIVATE include) @@ -24,49 +32,55 @@ target_compile_definitions(gquake PRIVATE GL_EXT_SHARED GLQUAKE) target_link_libraries(gquake PRIVATE ${GL}) if(PSP) - target_link_libraries(gquake PRIVATE SDL2main pspsdk pspnet cglue) + target_link_libraries(gquake PRIVATE SDL2main pspsdk pspnet cglue) - create_pbp_file(TARGET gquake - TITLE "GQuake") + create_pbp_file(TARGET gquake + TITLE "GQuake") elseif(PS2) - target_link_libraries(gquake PRIVATE SDL2main stdc++ ps2stuff dma -ldebug) + target_link_libraries(gquake PRIVATE SDL2main stdc++ ps2stuff dma -ldebug) - add_custom_command(TARGET gquake POST_BUILD - COMMAND rm -rf gquake - COMMAND mkdir -p gquake - COMMAND cp gquake.elf gquake/GQUAKE.ELF - COMMAND cp -rf ${CMAKE_SOURCE_DIR}/id1 gquake/ - COMMAND echo "BOOT2 = cdrom0:\\\\GQUAKE.ELF" > gquake/SYSTEM.CNF - COMMAND genisoimage -udf -o gquake.iso gquake - ) + add_custom_command(TARGET gquake POST_BUILD + COMMAND rm -rf gquake + COMMAND mkdir -p gquake + COMMAND cp gquake.elf gquake/GQUAKE.ELF + COMMAND cp -rf ${CMAKE_SOURCE_DIR}/id1 gquake/ + COMMAND echo "BOOT2 = cdrom0:\\\\GQUAKE.ELF" > gquake/SYSTEM.CNF + COMMAND genisoimage -udf -o gquake.iso gquake + ) elseif(VITA) - include(${VITASDK}/share/vita.cmake) + include(${VITASDK}/share/vita.cmake) - target_link_libraries(gquake PRIVATE SDL2main stdc++ vitashark SceShaccCg_stub SceKernelDmacMgr_stub mathneon) + target_link_libraries(gquake PRIVATE SDL2main stdc++ vitashark SceShaccCg_stub SceKernelDmacMgr_stub mathneon) - vita_create_self(gquake.self gquake) - vita_create_vpk(gquake.vpk PYRT10000 gquake.self - FILE ${CMAKE_SOURCE_DIR}/id1 sce_sys/id1 - ) + vita_create_self(gquake.self gquake) + vita_create_vpk(gquake.vpk PYRT10000 gquake.self + FILE ${CMAKE_SOURCE_DIR}/id1 sce_sys/id1 + ) elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") - target_link_libraries(gquake PRIVATE wsock32) + target_link_libraries(gquake PRIVATE wsock32) else() - target_link_libraries(gquake PRIVATE m) + target_link_libraries(gquake PRIVATE m) endif() set(FOUND FALSE) if(NOT FOUND AND TRY_SDL2) - find_package(SDL2) - target_compile_definitions(gquake PRIVATE USE_SDL2) - target_link_libraries(gquake PRIVATE SDL2::SDL2) + find_package(SDL2) + target_compile_definitions(gquake PRIVATE USE_SDL2) + target_link_libraries(gquake PRIVATE SDL2::SDL2) - set(FOUND ON) + set(FOUND ON) endif() -if(NOT FOUND) - target_compile_definitions(gquake PRIVATE USE_MILSKO USE_MINIAUDIO) - target_include_directories(gquake PRIVATE ${MILSKO}/include) - target_link_directories(gquake PRIVATE ${MILSKO}/src ${MILSKO}/lib) - target_link_libraries(gquake PRIVATE Mw) +if(NOT FOUND AND TRY_MILSKO) + target_compile_definitions(gquake PRIVATE USE_MILSKO USE_MINIAUDIO) + target_include_directories(gquake PRIVATE ${MILSKO}/include) + target_link_directories(gquake PRIVATE ${MILSKO}/src ${MILSKO}/lib) + target_link_libraries(gquake PRIVATE Mw) +endif() + +if(PLATFORM_DREAMCAST) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/romdisk/) +file(COPY ${CMAKE_BINARY_DIR}/../id1 DESTINATION ${CMAKE_BINARY_DIR}/romdisk/) +kos_add_romdisk(${PROJECT_NAME} ${CMAKE_BINARY_DIR}/romdisk/) endif() diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..709da2f --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,3 @@ +-DUSE_KALLISTIOS +-I/opt/toolchains/dc/kos-ports/include/ +-I/opt/toolchains/dc/kos/include/ diff --git a/src/common.c b/src/common.c index d7396ac..b7bbe0c 100644 --- a/src/common.c +++ b/src/common.c @@ -8,7 +8,7 @@ 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. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -94,7 +94,7 @@ into the cache directory, then opened there. FIXME: The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently. This could be used to add a "-sspeed 22050" for the high quality sound edition. Because they are added at the end, they will not override an explicit setting on the original command line. - + */ //============================================================================ @@ -138,7 +138,7 @@ void InsertLinkAfter (link_t *l, link_t *after) void Q_memset (void *dest, int fill, int count) { int i; - + if ( (((long)dest | count) & 3) == 0) { count >>= 2; @@ -154,7 +154,7 @@ void Q_memset (void *dest, int fill, int count) void Q_memcpy (void *dest, void *src, int count) { int i; - + if (( ( (long)dest | (long)src | count) & 3) == 0 ) { count>>=2; @@ -199,7 +199,7 @@ void Q_strncpy (char *dest, char *src, int count) int Q_strlen (char *str) { int count; - + count = 0; while (str[count]) count++; @@ -227,13 +227,13 @@ int Q_strcmp (char *s1, char *s2) while (1) { if (*s1 != *s2) - return -1; // strings not equal + return -1; // strings not equal if (!*s1) return 0; // strings are equal s1++; s2++; } - + return -1; } @@ -244,20 +244,20 @@ int Q_strncmp (char *s1, char *s2, int count) if (!count--) return 0; if (*s1 != *s2) - return -1; // strings not equal + return -1; // strings not equal if (!*s1) return 0; // strings are equal s1++; s2++; } - + return -1; } int Q_strncasecmp (char *s1, char *s2, int n) { int c1, c2; - + while (1) { c1 = *s1++; @@ -265,7 +265,7 @@ int Q_strncasecmp (char *s1, char *s2, int n) if (!n--) return 0; // strings are equal until end point - + if (c1 != c2) { if (c1 >= 'a' && c1 <= 'z') @@ -280,7 +280,7 @@ int Q_strncasecmp (char *s1, char *s2, int n) // s1++; // s2++; } - + return -1; } @@ -294,7 +294,7 @@ int Q_atoi (char *str) int val; int sign; int c; - + if (*str == '-') { sign = -1; @@ -302,7 +302,7 @@ int Q_atoi (char *str) } else sign = 1; - + val = 0; // @@ -324,7 +324,7 @@ int Q_atoi (char *str) return val*sign; } } - + // // check for character // @@ -332,7 +332,7 @@ int Q_atoi (char *str) { return sign * str[1]; } - + // // assume decimal // @@ -343,7 +343,7 @@ int Q_atoi (char *str) return val*sign; val = val*10 + c - '0'; } - + return 0; } @@ -354,7 +354,7 @@ float Q_atof (char *str) int sign; int c; int decimal, total; - + if (*str == '-') { sign = -1; @@ -362,7 +362,7 @@ float Q_atof (char *str) } else sign = 1; - + val = 0; // @@ -384,7 +384,7 @@ float Q_atof (char *str) return val*sign; } } - + // // check for character // @@ -392,7 +392,7 @@ float Q_atof (char *str) { return sign * str[1]; } - + // // assume decimal // @@ -419,7 +419,7 @@ float Q_atof (char *str) val /= 10; total--; } - + return val*sign; } @@ -479,8 +479,8 @@ float FloatSwap (float f) float f; byte b[4]; } dat1, dat2; - - + + dat1.f = f; dat2.b[0] = dat1.b[3]; dat2.b[1] = dat1.b[2]; @@ -510,7 +510,7 @@ Handles byte ordering and avoids alignment errors void MSG_WriteChar (sizebuf_t *sb, int c) { byte *buf; - + #ifdef PARANOID if (c < -128 || c > 127) Sys_Error ("MSG_WriteChar: range error"); @@ -523,7 +523,7 @@ void MSG_WriteChar (sizebuf_t *sb, int c) void MSG_WriteByte (sizebuf_t *sb, int c) { byte *buf; - + #ifdef PARANOID if (c < 0 || c > 255) Sys_Error ("MSG_WriteByte: range error"); @@ -536,7 +536,7 @@ void MSG_WriteByte (sizebuf_t *sb, int c) void MSG_WriteShort (sizebuf_t *sb, int c) { byte *buf; - + #ifdef PARANOID if (c < ((short)0x8000) || c > (short)0x7fff) Sys_Error ("MSG_WriteShort: range error"); @@ -550,7 +550,7 @@ void MSG_WriteShort (sizebuf_t *sb, int c) void MSG_WriteLong (sizebuf_t *sb, int c) { byte *buf; - + buf = SZ_GetSpace (sb, 4); buf[0] = c&0xff; buf[1] = (c>>8)&0xff; @@ -565,11 +565,11 @@ void MSG_WriteFloat (sizebuf_t *sb, float f) float f; int l; } dat; - - + + dat.f = f; dat.l = LittleLong (dat.l); - + SZ_Write (sb, &dat.l, 4); } @@ -607,70 +607,70 @@ void MSG_BeginReading (void) int MSG_ReadChar (void) { int c; - + if (msg_readcount+1 > net_message.cursize) { msg_badread = qtrue; return -1; } - + c = (signed char)net_message.data[msg_readcount]; msg_readcount++; - + return c; } int MSG_ReadByte (void) { int c; - + if (msg_readcount+1 > net_message.cursize) { msg_badread = qtrue; return -1; } - + c = (unsigned char)net_message.data[msg_readcount]; msg_readcount++; - + return c; } int MSG_ReadShort (void) { int c; - + if (msg_readcount+2 > net_message.cursize) { msg_badread = qtrue; return -1; } - + c = (short)(net_message.data[msg_readcount] + (net_message.data[msg_readcount+1]<<8)); - + msg_readcount += 2; - + return c; } int MSG_ReadLong (void) { int c; - + if (msg_readcount+4 > net_message.cursize) { msg_badread = qtrue; return -1; } - + c = net_message.data[msg_readcount] + (net_message.data[msg_readcount+1]<<8) + (net_message.data[msg_readcount+2]<<16) + (net_message.data[msg_readcount+3]<<24); - + msg_readcount += 4; - + return c; } @@ -682,23 +682,23 @@ float MSG_ReadFloat (void) float f; int l; } dat; - + dat.b[0] = net_message.data[msg_readcount]; dat.b[1] = net_message.data[msg_readcount+1]; dat.b[2] = net_message.data[msg_readcount+2]; dat.b[3] = net_message.data[msg_readcount+3]; msg_readcount += 4; - + dat.l = LittleLong (dat.l); - return dat.f; + return dat.f; } char *MSG_ReadString (void) { static char string[2048]; int l,c; - + l = 0; do { @@ -708,9 +708,9 @@ char *MSG_ReadString (void) string[l] = c; l++; } while (l < sizeof(string)-1); - + string[l] = 0; - + return string; } @@ -754,35 +754,35 @@ void SZ_Clear (sizebuf_t *buf) void *SZ_GetSpace (sizebuf_t *buf, int length) { void *data; - + if (buf->cursize + length > buf->maxsize) { if (!buf->allowoverflow) Sys_Error ("SZ_GetSpace: overflow without allowoverflow set"); - + if (length > buf->maxsize) Sys_Error ("SZ_GetSpace: %i is > full buffer size", length); - + buf->overflowed = qtrue; Con_Printf ("SZ_GetSpace: overflow"); - SZ_Clear (buf); + SZ_Clear (buf); } data = buf->data + buf->cursize; buf->cursize += length; - + return data; } void SZ_Write (sizebuf_t *buf, void *data, int length) { - Q_memcpy (SZ_GetSpace(buf,length),data,length); + Q_memcpy (SZ_GetSpace(buf,length),data,length); } void SZ_Print (sizebuf_t *buf, char *data) { int len; - + len = Q_strlen(data)+1; // byte * cast to keep VC++ happy @@ -804,7 +804,7 @@ COM_SkipPath char *COM_SkipPath (char *pathname) { char *last; - + last = pathname; while (*pathname) { @@ -856,15 +856,15 @@ COM_FileBase void COM_FileBase (char *in, char *out) { char *s, *s2; - + s = in + strlen(in) - 1; - + while (s != in && *s != '.') s--; - + for (s2 = s ; *s2 && *s2 != '/' ; s2--) ; - + if (s-s2 < 2) strcpy (out,"?model?"); else @@ -912,13 +912,13 @@ char *COM_Parse (char *data) { int c; int len; - + len = 0; com_token[0] = 0; - + if (!data) return NULL; - + // skip whitespace skipwhite: while ( (c = *data) <= ' ') @@ -927,7 +927,7 @@ skipwhite: return NULL; // end of file; data++; } - + // skip // comments if (c=='/' && data[1] == '/') { @@ -935,7 +935,7 @@ skipwhite: data++; goto skipwhite; } - + // handle quoted strings specially if (c == '\"') @@ -973,7 +973,7 @@ skipwhite: if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') break; } while (c>32); - + com_token[len] = 0; return data; } @@ -990,7 +990,7 @@ where the given parameter apears, or 0 if not present int COM_CheckParm (char *parm) { int i; - + for (i=1 ; inext) { @@ -1282,7 +1282,7 @@ void COM_WriteFile (char *filename, void *data, int len) { int handle; char name[MAX_OSPATH + 1]; - + sprintf (name, "%s/%s", com_gamedir, filename); handle = Sys_FileOpenWrite (name); @@ -1291,7 +1291,7 @@ void COM_WriteFile (char *filename, void *data, int len) Sys_Printf ("COM_WriteFile: failed on %s\n", name); return; } - + Sys_Printf ("COM_WriteFile: %s\n", name); Sys_FileWrite (handle, data, len); Sys_FileClose (handle); @@ -1308,7 +1308,7 @@ Only used for CopyFile void COM_CreatePath (char *path) { char *ofs; - + for (ofs = path+1 ; *ofs ; ofs++) { if (*ofs == '/') @@ -1334,11 +1334,11 @@ void COM_CopyFile (char *netpath, char *cachepath) int in, out; int remaining, count; char buf[4096]; - - remaining = Sys_FileOpenRead (netpath, &in); + + remaining = Sys_FileOpenRead (netpath, &in); COM_CreatePath (cachepath); // create directories up to the cache file out = Sys_FileOpenWrite (cachepath); - + while (remaining) { if (remaining < sizeof(buf)) @@ -1351,7 +1351,7 @@ void COM_CopyFile (char *netpath, char *cachepath) } Sys_FileClose (in); - Sys_FileClose (out); + Sys_FileClose (out); } /* @@ -1375,7 +1375,7 @@ int COM_FindFile (char *filename, int *handle, FILE **file) Sys_Error ("COM_FindFile: both handle and file set"); if (!file && !handle) Sys_Error ("COM_FindFile: neither handle or file set"); - + // // search through the path, one element at a time // @@ -1413,25 +1413,25 @@ int COM_FindFile (char *filename, int *handle, FILE **file) } } else - { + { // check a file in the directory tree if (!static_registered) { // if not a registered version, don't ever go beyond base if ( strchr (filename, '/') || strchr (filename,'\\')) continue; } - + sprintf (netpath, "%s/%s",search->filename, filename); - + findtime = Sys_FileTime (netpath); if (findtime == -1) continue; - + // see if the file needs to be updated in the cache if (!com_cachedir[0]) strcpy (cachepath, netpath); else - { + { #if defined(_WIN32) if ((strlen(netpath) < 2) || (netpath[1] != ':')) sprintf (cachepath,"%s%s", com_cachedir, netpath); @@ -1442,11 +1442,11 @@ int COM_FindFile (char *filename, int *handle, FILE **file) #endif cachetime = Sys_FileTime (cachepath); - + if (cachetime < findtime) COM_CopyFile (netpath, cachepath); strcpy (netpath, cachepath); - } + } Sys_Printf ("FindFile: %s\n",netpath); com_filesize = Sys_FileOpenRead (netpath, &i); @@ -1459,11 +1459,11 @@ int COM_FindFile (char *filename, int *handle, FILE **file) } return com_filesize; } - + } - + Sys_Printf ("FindFile: can't find %s\n", filename); - + if (handle) *handle = -1; else @@ -1510,11 +1510,11 @@ If it is a pak file handle, don't really close it void COM_CloseFile (int h) { searchpath_t *s; - + for (s = com_searchpaths ; s ; s=s->next) if (s->pack && s->pack->handle == h) return; - + Sys_FileClose (h); } @@ -1543,10 +1543,10 @@ byte *COM_LoadFile (char *path, int usehunk) len = COM_OpenFile (path, &h); if (h == -1) return NULL; - + // extract the filename base name for hunk tag COM_FileBase (path, base); - + if (usehunk == 1) buf = Hunk_AllocName (len+1, base); else if (usehunk == 2) @@ -1567,11 +1567,11 @@ byte *COM_LoadFile (char *path, int usehunk) if (!buf) Sys_Error ("COM_LoadFile: not enough space for %s", path); - + ((byte *)buf)[len] = 0; Draw_BeginDisc (); - Sys_FileRead (h, buf, len); + Sys_FileRead (h, buf, len); COM_CloseFile (h); Draw_EndDisc (); @@ -1598,11 +1598,11 @@ void COM_LoadCacheFile (char *path, struct cache_user_s *cu) byte *COM_LoadStackFile (char *path, void *buffer, int bufsize) { byte *buf; - + loadbuf = (byte *)buffer; loadsize = bufsize; buf = COM_LoadFile (path, 4); - + return buf; } @@ -1672,7 +1672,7 @@ pack_t *COM_LoadPackFile (char *packfile) pack->handle = packhandle; pack->numfiles = numpackfiles; pack->files = newfiles; - + Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); return pack; } @@ -1683,7 +1683,7 @@ pack_t *COM_LoadPackFile (char *packfile) COM_AddGameDirectory Sets com_gamedir, adds the directory to the head of the path, -then loads and adds pak1.pak pak2.pak ... +then loads and adds pak1.pak pak2.pak ... ================ */ void COM_AddGameDirectory (char *dir) @@ -1715,7 +1715,7 @@ void COM_AddGameDirectory (char *dir) search = Hunk_Alloc (sizeof(searchpath_t)); search->pack = pak; search->next = com_searchpaths; - com_searchpaths = search; + com_searchpaths = search; } // @@ -1774,8 +1774,11 @@ void COM_InitFilesystem (void) // // start up with GAMENAME by default (id1) // - COM_AddGameDirectory (va("%s/"GAMENAME, basedir) ); - +#ifdef USE_KALLISTIOS + COM_AddGameDirectory ("/rd/"); +#else + COM_AddGameDirectory (va("%s/"GAMENAME, basedir) ); +#endif if (COM_CheckParm ("-rogue")) COM_AddGameDirectory (va("%s/rogue", basedir) ); if (COM_CheckParm ("-hipnotic")) @@ -1805,7 +1808,7 @@ void COM_InitFilesystem (void) { if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-') break; - + search = Hunk_Alloc (sizeof(searchpath_t)); if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") ) { @@ -1823,5 +1826,3 @@ void COM_InitFilesystem (void) if (COM_CheckParm ("-proghack")) proghack = qtrue; } - - diff --git a/src/net_udp.c b/src/net_udp.c index 00022eb..34a7e9b 100644 --- a/src/net_udp.c +++ b/src/net_udp.c @@ -8,7 +8,7 @@ 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. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -74,13 +74,15 @@ int UDP_Init (void) WSADATA wsa; WSAStartup(MAKEWORD(1, 1), &wsa); #endif - + if (COM_CheckParm ("-noudp")) return -1; // determine my name & address #ifdef _EE - strcpy(buff, "PS2"); + strcpy(buff, "PS2"); +#elif USE_KALLISTIOS + strcpy(buff, "DC"); #else gethostname(buff, MAXHOSTNAMELEN); #endif @@ -157,7 +159,7 @@ int UDP_OpenSocket (int port) if (ioctl (newsocket, FIONBIO, (u_long*)&_qtrue) == -1) #elif defined(_PSP) || defined(__vita__) if(setsockopt(newsocket, SOL_SOCKET, SO_NONBLOCK, (char*)_qtrue, sizeof(_qtrue)) == -1) -#elif defined(_EE) +#elif defined(_EE) || defined(USE_KALLISTIOS) #else if (ioctl (newsocket, FIONBIO, (char *)&_qtrue) == -1) #endif @@ -204,7 +206,7 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr) int mask; int run; int port; - + buff[0] = '.'; b = buff; strcpy(buff+1, in); @@ -231,16 +233,16 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr) mask<<=8; addr = (addr<<8) + num; } - + if (*b++ == ':') port = Q_atoi(b); else port = net_hostport; hostaddr->sa_family = AF_INET; - ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port); + ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port); ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr = (myAddr & htonl(mask)) | htonl(addr); - + return 0; } //============================================================================= @@ -259,7 +261,7 @@ int UDP_CheckNewConnections (void) if (net_acceptsocket == -1) return -1; -#if defined(_PSP) || defined(_EE) || defined(__vita__) +#if defined(_PSP) || defined(_EE) || defined(__vita__) || defined(USE_KALLISTIOS) #else if (ioctl (net_acceptsocket, FIONREAD, &available) == -1) Sys_Error ("UDP: ioctlsocket (FIONREAD) failed\n"); @@ -379,6 +381,10 @@ int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name) { struct hostent *hostentry; +#ifdef USE_KALLISTIOS + printf("UDP_GetNameFromAddr STUB"); +#else + hostentry = gethostbyaddr ((char *)&((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr), AF_INET); if (hostentry) { @@ -387,6 +393,7 @@ int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name) } Q_strcpy (name, UDP_AddrToString (addr)); +#endif return 0; } @@ -398,13 +405,13 @@ int UDP_GetAddrFromName(char *name, struct qsockaddr *addr) if (name[0] >= '0' && name[0] <= '9') return PartialIPAddress (name, addr); - + hostentry = gethostbyname (name); if (!hostentry) return -1; addr->sa_family = AF_INET; - ((struct sockaddr_in *)addr)->sin_port = htons(net_hostport); + ((struct sockaddr_in *)addr)->sin_port = htons(net_hostport); ((struct sockaddr_in *)addr)->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; return 0; diff --git a/src/port.c b/src/port.c index 3040996..dbd746c 100644 --- a/src/port.c +++ b/src/port.c @@ -4,236 +4,295 @@ static MwWidget win = NULL; static MwWidget opengl; -static int MilskoToQuakeKey(int key){ - if(key == MwKEY_ENTER) key = K_ENTER; - if(key == MwKEY_ESCAPE) key = K_ESCAPE; - if(key == MwKEY_BACKSPACE) key = K_BACKSPACE; - if(key == MwKEY_LEFT) key = K_LEFTARROW; - if(key == MwKEY_RIGHT) key = K_RIGHTARROW; - if(key == MwKEY_UP) key = K_UPARROW; - if(key == MwKEY_DOWN) key = K_DOWNARROW; - if(key == MwKEY_LEFTSHIFT) key = K_SHIFT; - if(key == MwKEY_RIGHTSHIFT) key = K_SHIFT; - if(key == MwKEY_ALT) key = K_ALT; - if(key == MwKEY_CONTROL) key = K_CTRL; +static int MilskoToQuakeKey(int key) { + if (key == MwKEY_ENTER) + key = K_ENTER; + if (key == MwKEY_ESCAPE) + key = K_ESCAPE; + if (key == MwKEY_BACKSPACE) + key = K_BACKSPACE; + if (key == MwKEY_LEFT) + key = K_LEFTARROW; + if (key == MwKEY_RIGHT) + key = K_RIGHTARROW; + if (key == MwKEY_UP) + key = K_UPARROW; + if (key == MwKEY_DOWN) + key = K_DOWNARROW; + if (key == MwKEY_LEFTSHIFT) + key = K_SHIFT; + if (key == MwKEY_RIGHTSHIFT) + key = K_SHIFT; + if (key == MwKEY_ALT) + key = K_ALT; + if (key == MwKEY_CONTROL) + key = K_CTRL; - if('A' <= key && key <= 'Z') return tolower(key); + if ('A' <= key && key <= 'Z') + return tolower(key); - return key; + return key; } -static int MilskoToQuakeMouse(int btn){ - int b = 0; - if(btn == MwMOUSE_LEFT) b = 0; - if(btn == MwMOUSE_MIDDLE) b = 2; - if(btn == MwMOUSE_RIGHT) b = 1; - if(btn == MwMOUSE_WHEELUP) return K_MWHEELUP; - if(btn == MwMOUSE_WHEELDOWN) return K_MWHEELDOWN; +static int MilskoToQuakeMouse(int btn) { + int b = 0; + if (btn == MwMOUSE_LEFT) + b = 0; + if (btn == MwMOUSE_MIDDLE) + b = 2; + if (btn == MwMOUSE_RIGHT) + b = 1; + if (btn == MwMOUSE_WHEELUP) + return K_MWHEELUP; + if (btn == MwMOUSE_WHEELDOWN) + return K_MWHEELDOWN; - return K_MOUSE1 + b; + return K_MOUSE1 + b; } -static void MWAPI mousemove(MwWidget handle, void* user, void* call) { - MwPoint* p = call; - int vecX = p->x; - int vecY = p->y; +static void MWAPI mousemove(MwWidget handle, void *user, void *call) { + MwPoint *p = call; + int vecX = p->x; + int vecY = p->y; - if (mouse_active) { - mx += vecX * 2; - my += vecY * 2; - } + if (mouse_active) { + mx += vecX * 2; + my += vecY * 2; + } } -static void MWAPI key(MwWidget handle, void* user, void* call){ - int k = *(int*)call; - k = MilskoToQuakeKey(k); - if(k == -0xdead) return; - if(k & MwKEY_FLAG) return; - Key_Event(k, 1); +static void MWAPI key(MwWidget handle, void *user, void *call) { + int k = *(int *)call; + k = MilskoToQuakeKey(k); + if (k == -0xdead) + return; + if (k & MwKEY_FLAG) + return; + Key_Event(k, 1); } -static void MWAPI keyrelease(MwWidget handle, void* user, void* call){ - int k = *(int*)call; - k = MilskoToQuakeKey(k); - if(k == -0xdead) return; - if(k & MwKEY_FLAG) return; - Key_Event(k, 0); +static void MWAPI keyrelease(MwWidget handle, void *user, void *call) { + int k = *(int *)call; + k = MilskoToQuakeKey(k); + if (k == -0xdead) + return; + if (k & MwKEY_FLAG) + return; + Key_Event(k, 0); } -static void MWAPI mousedown(MwWidget handle, void* user, void* call){ - MwMouse* m = call; - Key_Event(MilskoToQuakeMouse(m->button), 1); +static void MWAPI mousedown(MwWidget handle, void *user, void *call) { + MwMouse *m = call; + Key_Event(MilskoToQuakeMouse(m->button), 1); } -static void MWAPI mouseup(MwWidget handle, void* user, void* call){ - MwMouse* m = call; - Key_Event(MilskoToQuakeMouse(m->button), 0); +static void MWAPI mouseup(MwWidget handle, void *user, void *call) { + MwMouse *m = call; + Key_Event(MilskoToQuakeMouse(m->button), 0); } -static void MWAPI focusin(MwWidget handle, void* user, void* call){ - if(mouse_active){ - MwGrabPointer(opengl, 0); - MwGrabPointer(opengl, 1); - } +static void MWAPI focusin(MwWidget handle, void *user, void *call) { + if (mouse_active) { + MwGrabPointer(opengl, 0); + MwGrabPointer(opengl, 1); + } } -static void MWAPI focusout(MwWidget handle, void* user, void* call){ - MwGrabPointer(opengl, 0); +static void MWAPI focusout(MwWidget handle, void *user, void *call) { + MwGrabPointer(opengl, 0); } +void Port_Init(int width, int height) { + MwSizeHints sh; + MwWidget label; -void Port_Init(int width, int height){ - MwSizeHints sh; - MwWidget label; + MwLibraryInit(); - MwLibraryInit(); + win = MwVaCreateWidget(MwWindowClass, "Quake", NULL, MwDEFAULT, MwDEFAULT, + width, height + 24, MwNtitle, "Quake", NULL); + label = MwVaCreateWidget(MwLabelClass, "Label", win, 0, height, width, 24, + MwNtext, "Milsko Quake!", NULL); + opengl = MwCreateWidget(MwOpenGLClass, "OpenGL", win, 0, 0, width, height); - win = MwVaCreateWidget(MwWindowClass, "Quake", NULL, MwDEFAULT, MwDEFAULT, width, height + 24, - MwNtitle, "Quake", - NULL); - label = MwVaCreateWidget(MwLabelClass, "Label", win, 0, height, width, 24, - MwNtext, "Milsko Quake!", - NULL); - opengl = MwCreateWidget(MwOpenGLClass, "OpenGL", win, 0, 0, width, height); + sh.min_width = sh.max_width = width; + sh.min_height = sh.max_height = height + 24; + MwVaApply(win, MwNsizeHints, &sh, NULL); - sh.min_width = sh.max_width = width; - sh.min_height = sh.max_height = height + 24; - MwVaApply(win, - MwNsizeHints, &sh, - NULL); + MwOpenGLMakeCurrent(opengl); - MwOpenGLMakeCurrent(opengl); + MwAddUserHandler(opengl, MwNmouseMoveHandler, mousemove, NULL); + MwAddUserHandler(opengl, MwNkeyHandler, key, NULL); + MwAddUserHandler(opengl, MwNkeyReleaseHandler, keyrelease, NULL); + MwAddUserHandler(opengl, MwNmouseDownHandler, mousedown, NULL); + MwAddUserHandler(opengl, MwNmouseUpHandler, mouseup, NULL); + MwAddUserHandler(opengl, MwNfocusInHandler, focusin, NULL); + MwAddUserHandler(opengl, MwNfocusOutHandler, focusout, NULL); - MwAddUserHandler(opengl, MwNmouseMoveHandler, mousemove, NULL); - MwAddUserHandler(opengl, MwNkeyHandler, key, NULL); - MwAddUserHandler(opengl, MwNkeyReleaseHandler, keyrelease, NULL); - MwAddUserHandler(opengl, MwNmouseDownHandler, mousedown, NULL); - MwAddUserHandler(opengl, MwNmouseUpHandler, mouseup, NULL); - MwAddUserHandler(opengl, MwNfocusInHandler, focusin, NULL); - MwAddUserHandler(opengl, MwNfocusOutHandler, focusout, NULL); - - if(fullscreen){ - /* todo */ - } + if (fullscreen) { + /* todo */ + } } -void Port_Step(void){ - if(!win) return; +void Port_Step(void) { + if (!win) + return; - if(MwPending(win)) MwStep(win); + if (MwPending(win)) + MwStep(win); } -void Port_GrabPointer(int toggle){ - if(!win) return; +void Port_GrabPointer(int toggle) { + if (!win) + return; - if(toggle){ - MwHideCursor(opengl); - MwGrabPointer(opengl, 1); - }else{ - MwGrabPointer(opengl, 0); - } + if (toggle) { + MwHideCursor(opengl); + MwGrabPointer(opengl, 1); + } else { + MwGrabPointer(opengl, 0); + } } -void Port_Shutdown(void){ - if (win) { - MwDestroyWidget(win); - } - win = NULL; +void Port_Shutdown(void) { + if (win) { + MwDestroyWidget(win); + } + win = NULL; } -void Port_SwapBuffer(void){ - MwOpenGLSwapBuffer(opengl); -} +void Port_SwapBuffer(void) { MwOpenGLSwapBuffer(opengl); } #endif #ifdef USE_SDL2 -static SDL_Window* win; +static SDL_Window *win; static SDL_GLContext context; -void Port_Init(int width, int height){ - SDL_Init(SDL_INIT_VIDEO); +void Port_Init(int width, int height) { + SDL_Init(SDL_INIT_VIDEO); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - win = SDL_CreateWindow("Quake", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); - context = SDL_GL_CreateContext(win); + win = + SDL_CreateWindow("Quake", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width, height, SDL_WINDOW_OPENGL); + context = SDL_GL_CreateContext(win); } -void Port_Step(void){ - if(!win) return; +void Port_Step(void) { + if (!win) + return; - SDL_Event ev; + SDL_Event ev; - while(SDL_PollEvent(&ev)){ - if(ev.type == SDL_MOUSEMOTION){ - if (mouse_active) { - mx += ev.motion.xrel * 2; - my += ev.motion.yrel * 2; - } - }else if(ev.type == SDL_MOUSEBUTTONDOWN || ev.type == SDL_MOUSEBUTTONUP){ - int b = 0; - int btn = ev.button.button; + while (SDL_PollEvent(&ev)) { + if (ev.type == SDL_MOUSEMOTION) { + if (mouse_active) { + mx += ev.motion.xrel * 2; + my += ev.motion.yrel * 2; + } + } else if (ev.type == SDL_MOUSEBUTTONDOWN || ev.type == SDL_MOUSEBUTTONUP) { + int b = 0; + int btn = ev.button.button; - if(btn == SDL_BUTTON_LEFT) b = 0; - if(btn == SDL_BUTTON_MIDDLE) b = 2; - if(btn == SDL_BUTTON_RIGHT) b = 1; + if (btn == SDL_BUTTON_LEFT) + b = 0; + if (btn == SDL_BUTTON_MIDDLE) + b = 2; + if (btn == SDL_BUTTON_RIGHT) + b = 1; - Key_Event(K_MOUSE1 + b, ev.type == SDL_MOUSEBUTTONDOWN); - }else if(ev.type == SDL_MOUSEWHEEL){ - int k; + Key_Event(K_MOUSE1 + b, ev.type == SDL_MOUSEBUTTONDOWN); + } else if (ev.type == SDL_MOUSEWHEEL) { + int k; - if(ev.wheel.y > 0){ - k = K_MWHEELUP; - }else if(ev.wheel.y < 0){ - k = K_MWHEELDOWN; - } - Key_Event(k, 1); - Key_Event(k, 0); - }else if(ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP){ - int key = ev.key.keysym.sym; + if (ev.wheel.y > 0) { + k = K_MWHEELUP; + } else if (ev.wheel.y < 0) { + k = K_MWHEELDOWN; + } + Key_Event(k, 1); + Key_Event(k, 0); + } else if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { + int key = ev.key.keysym.sym; - if(key == SDLK_RETURN) key = K_ENTER; - if(key == SDLK_ESCAPE) key = K_ESCAPE; - if(key == SDLK_BACKSPACE) key = K_BACKSPACE; - if(key == SDLK_LEFT) key = K_LEFTARROW; - if(key == SDLK_RIGHT) key = K_RIGHTARROW; - if(key == SDLK_UP) key = K_UPARROW; - if(key == SDLK_DOWN) key = K_DOWNARROW; - if(key == SDLK_LSHIFT) key = K_SHIFT; - if(key == SDLK_RSHIFT) key = K_SHIFT; - if(key == SDLK_LALT) key = K_ALT; - if(key == SDLK_RALT) key = K_ALT; - if(key == SDLK_LCTRL) key = K_CTRL; - if(key == SDLK_RCTRL) key = K_CTRL; - if(key == SDLK_LGUI) key = K_SUPER; - if(key == SDLK_RGUI) key = K_SUPER; - if(SDLK_a <= key && key <= SDLK_z) key = key - SDLK_a + 'a'; - if(SDLK_0 <= key && key <= SDLK_9) key = key - SDLK_0 + '0'; + if (key == SDLK_RETURN) + key = K_ENTER; + if (key == SDLK_ESCAPE) + key = K_ESCAPE; + if (key == SDLK_BACKSPACE) + key = K_BACKSPACE; + if (key == SDLK_LEFT) + key = K_LEFTARROW; + if (key == SDLK_RIGHT) + key = K_RIGHTARROW; + if (key == SDLK_UP) + key = K_UPARROW; + if (key == SDLK_DOWN) + key = K_DOWNARROW; + if (key == SDLK_LSHIFT) + key = K_SHIFT; + if (key == SDLK_RSHIFT) + key = K_SHIFT; + if (key == SDLK_LALT) + key = K_ALT; + if (key == SDLK_RALT) + key = K_ALT; + if (key == SDLK_LCTRL) + key = K_CTRL; + if (key == SDLK_RCTRL) + key = K_CTRL; + if (key == SDLK_LGUI) + key = K_SUPER; + if (key == SDLK_RGUI) + key = K_SUPER; + if (SDLK_a <= key && key <= SDLK_z) + key = key - SDLK_a + 'a'; + if (SDLK_0 <= key && key <= SDLK_9) + key = key - SDLK_0 + '0'; - Key_Event(key, ev.type == SDL_KEYDOWN); - } - } + Key_Event(key, ev.type == SDL_KEYDOWN); + } + } } -void Port_GrabPointer(int toggle){ - if(toggle){ - SDL_ShowCursor(0); - } - SDL_SetWindowMouseGrab(win, toggle); - SDL_SetWindowKeyboardGrab(win, toggle); +void Port_GrabPointer(int toggle) { + if (toggle) { + SDL_ShowCursor(0); + } + SDL_SetWindowMouseGrab(win, toggle); + SDL_SetWindowKeyboardGrab(win, toggle); - if(toggle){ - SDL_SetRelativeMouseMode(SDL_TRUE); - SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0"); - } + if (toggle) { + SDL_SetRelativeMouseMode(SDL_TRUE); + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0"); + } } +void Port_Shutdown(void) { SDL_Quit(); } + +void Port_SwapBuffer(void) { SDL_GL_SwapWindow(win); } +#endif + +#ifdef USE_KALLISTIOS +#include +KOS_INIT_FLAGS(INIT_DEFAULT); + +#include +#include + +void Port_Init(int width, int height) { + glKosInit(); +} + +void Port_Step(void) { +} + +void Port_GrabPointer(int toggle) {} + +void Port_Shutdown(void) {} + +void Port_SwapBuffer(void) { + glKosSwapBuffers(); +} -void Port_Shutdown(void){ - SDL_Quit(); -} - -void Port_SwapBuffer(void){ - SDL_GL_SwapWindow(win); -} #endif diff --git a/src/snd_dc.c b/src/snd_dc.c new file mode 100644 index 0000000..20f7fbe --- /dev/null +++ b/src/snd_dc.c @@ -0,0 +1,38 @@ +/* +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 the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +#ifdef USE_KALLISTIOS +#include "quakedef.h" + +int snd_inited; + +int total = 0; +#define BUFFER_SIZE 4096 * 4 +unsigned char dma_buffer[BUFFER_SIZE]; + +qboolean SNDDMA_Init(void) { return 1; } + +int SNDDMA_GetDMAPos(void) { return 0; } + +int SNDDMA_GetSamples(void) { return total; } + +void SNDDMA_Shutdown(void) {} + +void SNDDMA_Submit(void) {} +#endif