shithub: duke3d

Download patch

ref: 19bf783384014d10101e97fe81d2c83a9b30f408
parent: 6826682f43d94f27117a8570c4fc058ede9c236a
author: Jacob Moody <[email protected]>
date: Sun Feb 5 19:25:22 EST 2023

First set of Engine port work

--- a/Engine/src/cache.h
+++ b/Engine/src/cache.h
@@ -32,4 +32,4 @@
 
 
 
-#endif
\ No newline at end of file
+#endif
--- a/Engine/src/display.c
+++ b/Engine/src/display.c
@@ -99,7 +99,7 @@
  * !!!  titlebar caption.   --ryan.
  */
 static uint8_t  screenalloctype = 255;
-static void init_new_res_vars()
+static void init_new_res_vars(void)
 {
 	int i = 0;
 	int j = 0;
@@ -200,7 +200,8 @@
 	SDL_CHECK_NOT_NULL(window, "create window");
 
 	// don't override higher-res app icon on OS X or Windows
-#if !PLATFORM_MACOSX && !WIN32
+        // plan9 has no window icons
+#if !PLATFORM_MACOSX && !WIN32 && !defined(__plan9__)
 	SDL_Surface* image = SDL_LoadBMP_RW(SDL_RWFromMem(iconBMP, sizeof(iconBMP)), 1);
 	Uint32 colorkey = 0; // index in this image to be transparent
 	SDL_SetColorKey(image, SDL_TRUE, colorkey);
@@ -214,9 +215,11 @@
 	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
 	SDL_CHECK_NOT_NULL(renderer, "create renderer");
 
+#ifndef __plan9__
 	SDL_RendererInfo rendererInfo;
 	SDL_CHECK_SUCCESS(SDL_GetRendererInfo(renderer, &rendererInfo));
 	printf("SDL Renderer: '%s'.\n", rendererInfo.name);
+#endif
 
 	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
 	//SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
@@ -249,7 +252,7 @@
 	SDL_RenderPresent(renderer);
 }
 
-static inline int sdl_mouse_button_filter(SDL_MouseButtonEvent const *event)
+static int sdl_mouse_button_filter(SDL_MouseButtonEvent *event)
 {
 		/*
 		 * What bits BUILD expects:
@@ -326,7 +329,7 @@
 	 *  which we check for explicitly, and give the engine a keypad enter
 	 *  enter event.
 	 */
-static inline int handle_keypad_enter_hack(const SDL_Event *event)
+static int handle_keypad_enter_hack(const SDL_Event *event)
 {
 	static int kp_enter_hack = 0;
 	int retval = 0;
@@ -634,6 +637,8 @@
 
 static void output_sdl_versions(void)
 {
+/* FIXME plan9 */
+#ifndef __plan9__
 	SDL_version linked_ver;
 	SDL_GetVersion(&linked_ver);
 
@@ -643,6 +648,7 @@
 	printf("SDL Display driver for the BUILD engine initializing.\n");
 	printf("SDL Compiled %s against SDL version %d.%d.%d ...\n", __DATE__, compiled_ver.major, compiled_ver.minor, compiled_ver.patch);
 	printf("SDL Linked against SDL version %d.%d.%d ...\n", linked_ver.major, linked_ver.minor, linked_ver.patch);
+#endif
 }
 
 /* lousy -ansi flag.  :) */
--- a/Engine/src/display.h
+++ b/Engine/src/display.h
@@ -95,7 +95,7 @@
 /* resolution inits. sdl_driver.c ... */
 int32_t _setgamemode(int32_t daxdim, int32_t daydim);
 
-uint32_t getticks();
+uint32_t getticks(void);
 
 void drawline16(int32_t XStart, int32_t YStart, int32_t XEnd, int32_t YEnd, uint8_t  Color);
 void setcolor16(uint8_t color);
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -1373,7 +1373,7 @@
         if (d4 >= u4) 
             vlineasm4(d4-u4+1,ylookup[u4]+x+frameoffset);
 
-        i = x+frameoffset+ylookup[d4+1];
+        i = (intptr_t)(x+frameoffset+ylookup[d4+1]);
         
         if (y2ve[0] > d4)
             prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],(uint8_t*) bufplce[0],(uint8_t*) i+0);
@@ -1505,7 +1505,7 @@
             else
                 i <<= tileHeight;
             
-            bufplce[z] = tiles[globalpicnum].data+i;
+            bufplce[z] = (intptr_t)(tiles[globalpicnum].data+i);
 
             vince[z] = swal[dax]*globalyscale;
             vplce[z] = globalzd + vince[z]*(y1ve[z]-globalhoriz+1);
@@ -1545,7 +1545,7 @@
 
         if (d4 >= u4) mvlineasm4(d4-u4+1,ylookup[u4]+p);
 
-        i = p+ylookup[d4+1];
+        i = (intptr_t)(p+ylookup[d4+1]);
         if (y2ve[0] > d4) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],(const uint8_t*)bufplce[0],(uint8_t*)i+0);
         if (y2ve[1] > d4) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],(const uint8_t*)bufplce[1],(uint8_t*)i+1);
         if (y2ve[2] > d4) mvlineasm1(vince[2],palookupoffse[2],y2ve[2]-d4-1,vplce[2],(const uint8_t*)bufplce[2],(uint8_t*)i+2);
@@ -1869,7 +1869,7 @@
     globvis = mulscale16(globvis,xdimscale);
     j = (intptr_t) palookup[globalpal];
 
-    setupslopevlin(((int32_t)(picsiz[globalpicnum]&15))+(((int32_t)(picsiz[globalpicnum]>>4))<<8),tiles[globalpicnum].data,-ylookup[1]);
+    setupslopevlin(((int32_t)(picsiz[globalpicnum]&15))+(((int32_t)(picsiz[globalpicnum]>>4))<<8),(intptr_t)(tiles[globalpicnum].data),-ylookup[1]);
 
     l = (globalzd>>16);
 
@@ -1916,7 +1916,7 @@
             globalx3 = (globalx2>>10);
             globaly3 = (globaly2>>10);
             asm3 = mulscale16(y2,globalzd) + (globalzx>>6);
-            slopevlin(ylookup[y2]+x+frameoffset,krecipasm(asm3>>3),slopalookup,y2+(shoffs>>15),y2-y1+1,globalx1,globaly1);
+            slopevlin((intptr_t)(ylookup[y2]+x+frameoffset),krecipasm(asm3>>3),slopalookup,y2+(shoffs>>15),y2-y1+1,globalx1,globaly1);
 
             if ((x&15) == 0) faketimerhandler();
         }
@@ -3121,18 +3121,18 @@
     i = lwall[x] + globalxpanning;
     if (i >= tiles[globalpicnum].dim.width)
         i %= tiles[globalpicnum].dim.width;
-    bufplce[0] = tiles[globalpicnum].data+i*tiles[globalpicnum].dim.height;
+    bufplce[0] = (intptr_t)(tiles[globalpicnum].data+i*tiles[globalpicnum].dim.height);
 
     i = lwall[x2] + globalxpanning;
     if (i >= tiles[globalpicnum].dim.width)
         i %= tiles[globalpicnum].dim.width;
-    bufplce[1] = tiles[globalpicnum].data+i*tiles[globalpicnum].dim.height;
+    bufplce[1] = (intptr_t)(tiles[globalpicnum].data+i*tiles[globalpicnum].dim.height);
 
     
     y1 = max(y1ve[0],y1ve[1]);
     y2 = min(y2ve[0],y2ve[1]);
 
-    i = x+frameoffset;
+    i = (intptr_t)(x+frameoffset);
 
     if (y1ve[0] != y1ve[1])
     {
@@ -3360,8 +3360,7 @@
 #endif
 
     if ((fil = open(filename,
-                    O_BINARY|O_TRUNC|O_CREAT|O_WRONLY,
-                    permissions)) == -1)
+                    O_BINARY|O_TRUNC|O_CREAT|O_WRONLY)) == -1)
     {
         return(-1);
     }
@@ -4021,7 +4020,7 @@
                     by += yv*(y1-oy);
                     oy = y1;
 
-                    bufplce[xx] = (bx>>16)*tileHeight+bufplc;
+                    bufplce[xx] = (intptr_t)((bx>>16)*tileHeight+bufplc);
                     vplce[xx] = by;
                     y1ve[xx] = y1;
                     y2ve[xx] = y2-1;
@@ -4059,7 +4058,7 @@
 
                     if (d4 >= u4) vlineasm4(d4-u4+1,ylookup[u4]+p);
 
-                    i = p+ylookup[d4+1];
+                    i = (intptr_t)(p+ylookup[d4+1]);
                     if (y2ve[0] > d4) 
                         prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],(const uint8_t*)bufplce[0],(uint8_t*)i+0);
                     if (y2ve[1] > d4) 
@@ -4087,7 +4086,7 @@
 
                     if (d4 >= u4) mvlineasm4(d4-u4+1,ylookup[u4]+p);
 
-                    i = p+ylookup[d4+1];
+                    i = (intptr_t)(p+ylookup[d4+1]);
                     if (y2ve[0] > d4) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],(const uint8_t*)bufplce[0],(uint8_t*)i+0);
                     if (y2ve[1] > d4) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],(const uint8_t*)bufplce[1],(uint8_t*)i+1);
                     if (y2ve[2] > d4) mvlineasm1(vince[2],palookupoffse[2],y2ve[2]-d4-1,vplce[2],(const uint8_t*)bufplce[2],(uint8_t*)i+2);
@@ -4736,9 +4735,9 @@
     int32_t x1, v, bx, by;
 
     /*
-     * x = x1 + (x2-x1)t + (y1-y2)u  �  x = 160v
-     * y = y1 + (y2-y1)t + (x2-x1)u  �  y = (scrx-160)v
-     * z = z1 = z2                   �  z = posz + (scry-horiz)v
+     * x = x1 + (x2-x1)t + (y1-y2)u  �  x = 160v
+     * y = y1 + (y2-y1)t + (x2-x1)u  �  y = (scrx-160)v
+     * z = z1 = z2                   �  z = posz + (scry-horiz)v
      */
 
     x1 = lastx[y];
@@ -9100,7 +9099,7 @@
 
     transarea += (mirrorsx2-mirrorsx1)*(windowy2-windowy1);
 
-    p = frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1;
+    p = (intptr_t)(frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1);
     i = windowx2-windowx1-mirrorsx2-mirrorsx1;
     mirrorsx2 -= mirrorsx1;
     // FIX_00085: Optimized Video driver. FPS increases by +20%.
--- a/Engine/src/filesystem.c
+++ b/Engine/src/filesystem.c
@@ -83,7 +83,7 @@
 	//groupfil_memory[numgroupfiles] = NULL; // addresses of raw GRP files in memory
 	//groupefil_crc32[numgroupfiles] = 0;
     
-	archive->fileDescriptor = open(filename,O_BINARY|O_RDONLY,S_IREAD);
+	archive->fileDescriptor = open(filename,O_BINARY|O_RDONLY);
     
     if (archive->fileDescriptor < 0){
         printf("Error: Unable to open file %s.\n",filename);
@@ -422,6 +422,18 @@
     struct stat stats;
     fstat(fd, &stats);
     return (int32_t )stats.st_size;
+}
+#endif
+
+#if defined(__plan9__)
+int32_t filelength(int32_t fd){
+    Dir *d;
+    int32_t len;
+
+    d = dirfstat(fd);
+    len = d->length;
+    free(d);
+    return len;
 }
 #endif
 
--- a/Engine/src/icon.h
+++ b/Engine/src/icon.h
@@ -162,4 +162,4 @@
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
-  };
\ No newline at end of file
+  };
--- /dev/null
+++ b/Engine/src/mkfile
@@ -1,0 +1,33 @@
+</$objtype/mkfile
+
+CFLAGS=-Fpw -I/sys/include/npe -I/sys/include/npe/SDL2 -D__plan9__ -D__${objtype}__
+LIB=libbuild.a
+
+OFILES=\
+	cache.$O \
+	display.$O \
+	draw.$O \
+	engine.$O \
+	filesystem.$O \
+	fixedPoint_math.$O \
+#TODO	mmulti.$O \
+	tiles.$O \
+	
+HFILES=\
+	build.h \
+	cache.h \
+	draw.h \
+	display.h \
+	engine.h \
+	filesystem.h \
+	fixedPoint_math.h \
+	icon.h \
+	macos_compat.h \
+	mmulti.h \
+	platform.h \
+	sdl_util.h \
+	tiles.h \
+	unix_compat.h \
+	win32_compat.h
+
+</sys/src/cmd/mksyslib
--- a/Engine/src/mmulti.h
+++ b/Engine/src/mmulti.h
@@ -14,4 +14,4 @@
 void flushpackets(void);
 void genericmultifunction(int32_t other, const uint8_t* bufptr, int32_t messleng, int32_t command);
 
-#endif
\ No newline at end of file
+#endif
--- /dev/null
+++ b/Engine/src/plan9_compat.h
@@ -1,0 +1,51 @@
+//
+//  unix_compat.h
+//  Duke3D
+//
+//  Based on macos_compat.h
+//  Copyright Wed, Jul 31, 2013, Juan Manuel Borges Caño (GPLv3+)
+//
+
+#ifndef Duke3D_plan9_compat_h
+#define Duke3D_plan9_compat_h
+
+//MOODY
+#define BYTE_ORDER LITTLE_ENDIAN
+
+#include <stdlib.h>
+
+#ifndef max
+#define max(x, y)  (((x) > (y)) ? (x) : (y))
+#endif
+
+#ifndef min
+#define min(x, y)  (((x) < (y)) ? (x) : (y))
+#endif
+
+#include <inttypes.h>
+
+#define O_BINARY 0
+
+
+/*
+#define SOL_IP SOL_SOCKET
+#define IP_RECVERR  SO_BROADCAST
+*/
+
+#define stricmp strcasecmp
+#define strcmpi strcasecmp
+
+#define S_IREAD S_IRUSR
+#define O_CREAT OTRUNC
+#define O_WRONLY OWRITE
+#define O_RDONLY OREAD
+
+#define lseek seek
+
+#include <assert.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <string.h>
+
+#endif
--- a/Engine/src/platform.h
+++ b/Engine/src/platform.h
@@ -9,6 +9,8 @@
     #include "unix_compat.h"
 #elif (defined __APPLE__)
     #include "macos_compat.h"
+#elif (defined __plan9__)
+    #include "plan9_compat.h"
 #else
 #error Define your platform!
 #endif
--- a/Engine/src/tiles.c
+++ b/Engine/src/tiles.c
@@ -386,4 +386,4 @@
     }
     
     return(offs);
-}
\ No newline at end of file
+}