]> git.0x19.co - doomgeneric-snom360/commitdiff
better framebuffer handling for soso
authorozkl <ozkl@users.noreply.github.com>
Sun, 6 Dec 2020 15:45:44 +0000 (18:45 +0300)
committerozkl <ozkl@users.noreply.github.com>
Sun, 6 Dec 2020 15:48:59 +0000 (18:48 +0300)
doomgeneric/Makefile.soso [new file with mode: 0644]
doomgeneric/doomgeneric_soso.c

diff --git a/doomgeneric/Makefile.soso b/doomgeneric/Makefile.soso
new file mode 100644 (file)
index 0000000..86b0e24
--- /dev/null
@@ -0,0 +1,54 @@
+################################################################
+#
+# $Id:$
+#
+# $Log:$
+#
+
+ifeq ($(V),1)
+       VB=''
+else
+       VB=@
+endif
+
+
+CC=soso-clang  # gcc or g++
+CFLAGS+=-O3
+LDFLAGS+=$(SOSO_ROOT)/lib/crt1.o $(SOSO_ROOT)/lib/crti.o $(SOSO_ROOT)/lib/crtn.o
+CFLAGS+=-Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
+LIBS+=-lsosousdk -lm -lc /usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/libclang_rt.builtins-i386.a
+
+# subdirectory for objects
+OBJDIR=build
+OUTPUT=doom-soso
+
+SRC_DOOM = i_main.o dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric.o doomgeneric_soso.o
+OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))
+
+all:    $(OUTPUT)
+
+clean:
+       rm -rf $(OBJDIR)
+       rm -f $(OUTPUT)
+       rm -f $(OUTPUT).gdb
+       rm -f $(OUTPUT).map
+
+$(OUTPUT):     $(OBJS)
+       @echo [Linking $@]
+       i386-soso-ld -v $(LDFLAGS) $(OBJS) -o $(OUTPUT) $(LIBS)
+       @echo [Size]
+       -$(CROSS_COMPILE)size $(OUTPUT)
+       cp $(OUTPUT) ~/git/soso/userspace/bin/
+
+$(OBJS): | $(OBJDIR)
+
+$(OBJDIR):
+       mkdir -p $(OBJDIR)
+
+$(OBJDIR)/%.o: %.c
+       @echo [Compiling $<]
+       $(VB)$(CC) $(CFLAGS) -c $< -o $@
+
+print:
+       @echo OBJS: $(OBJS)
+
index 3912964756a033cd1a6927934d4e2df40bf1867f..d5c3e87c43a67afc580093c55feaffbe822e0507 100644 (file)
@@ -7,9 +7,13 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <string.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
 
 #include <sosousdk.h>
-#include "../kernel/termios.h"
+#include <termios.h>
 
 static int FrameBufferFd = -1;
 static int* FrameBuffer = 0;
@@ -25,6 +29,16 @@ static unsigned int s_KeyQueueReadIndex = 0;
 static unsigned int s_PositionX = 0;
 static unsigned int s_PositionY = 0;
 
+static unsigned int s_ScreenWidth = 0;
+static unsigned int s_ScreenHeight = 0;
+
+enum EnFrameBuferIoctl
+{
+    FB_GET_WIDTH,
+    FB_GET_HEIGHT,
+    FB_GET_BITSPERPIXEL
+};
+
 static unsigned char convertToDoomKey(unsigned char scancode)
 {
     unsigned char key = 0;
@@ -90,12 +104,14 @@ static void addKeyToQueue(int pressed, unsigned char keyCode)
 
 struct termios orig_termios;
 
-void disableRawMode() {
+void disableRawMode()
+{
   //printf("returning original termios\n");
   tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
 }
 
-void enableRawMode() {
+void enableRawMode()
+{
   tcgetattr(STDIN_FILENO, &orig_termios);
   atexit(disableRawMode);
   struct termios raw = orig_termios;
@@ -111,20 +127,34 @@ void DG_Init()
 
     if (FrameBufferFd >= 0)
     {
-        FrameBuffer = mmap(NULL, DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4, 0, FrameBufferFd, 0);
+        printf("Getting screen width...");
+        s_ScreenWidth = ioctl(FrameBufferFd, FB_GET_WIDTH);
+        printf("%d\n", s_ScreenWidth);
+
+        printf("Getting screen height...");
+        s_ScreenHeight = ioctl(FrameBufferFd, FB_GET_HEIGHT);
+        printf("%d\n", s_ScreenHeight);
+
+        if (0 == s_ScreenWidth || 0 == s_ScreenHeight)
+        {
+            printf("Unable to obtain screen info!");
+            exit(1);
+        }
+
+        FrameBuffer = mmap(NULL, s_ScreenWidth * s_ScreenHeight * 4, PROT_READ | PROT_WRITE, 0, FrameBufferFd, 0);
 
         if (FrameBuffer != (int*)-1)
         {
-            printf("mmap success\n");
+            printf("FrameBuffer mmap success\n");
         }
         else
         {
-            printf("mmap failed\n");
+            printf("FrameBuffermmap failed\n");
         }
     }
     else
     {
-        printf("opening device failed!\n");
+        printf("Opening FrameBuffer device failed!\n");
     }
 
     enableRawMode();
@@ -134,7 +164,7 @@ void DG_Init()
     if (KeyboardFd >= 0)
     {
         //enter non-blocking mode
-        syscall_ioctl(KeyboardFd, 1, (void*)1);
+        ioctl(KeyboardFd, 1, (void*)1);
     }
 
     int argPosX = 0;
@@ -185,13 +215,9 @@ void DG_DrawFrame()
 {
     if (FrameBuffer)
     {
-        //memcpy(FrameBuffer, DG_ScreenBuffer, DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);
-
-        const int screenWidth = 1024;
-
         for (int i = 0; i < DOOMGENERIC_RESY; ++i)
         {
-            memcpy(FrameBuffer + s_PositionX + (i + s_PositionY) * screenWidth, DG_ScreenBuffer + i * DOOMGENERIC_RESX, DOOMGENERIC_RESX * 4);
+            memcpy(FrameBuffer + s_PositionX + (i + s_PositionY) * s_ScreenWidth, DG_ScreenBuffer + i * DOOMGENERIC_RESX, DOOMGENERIC_RESX * 4);
         }
     }