Skip to content

Commit b964f78

Browse files
committed
better framebuffer handling for soso
1 parent c579afc commit b964f78

File tree

2 files changed

+93
-13
lines changed

2 files changed

+93
-13
lines changed

doomgeneric/Makefile.soso

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
################################################################
2+
#
3+
# $Id:$
4+
#
5+
# $Log:$
6+
#
7+
8+
ifeq ($(V),1)
9+
VB=''
10+
else
11+
VB=@
12+
endif
13+
14+
15+
CC=soso-clang # gcc or g++
16+
CFLAGS+=-O3
17+
LDFLAGS+=$(SOSO_ROOT)/lib/crt1.o $(SOSO_ROOT)/lib/crti.o $(SOSO_ROOT)/lib/crtn.o
18+
CFLAGS+=-Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
19+
LIBS+=-lsosousdk -lm -lc /usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/libclang_rt.builtins-i386.a
20+
21+
# subdirectory for objects
22+
OBJDIR=build
23+
OUTPUT=doom-soso
24+
25+
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
26+
OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))
27+
28+
all: $(OUTPUT)
29+
30+
clean:
31+
rm -rf $(OBJDIR)
32+
rm -f $(OUTPUT)
33+
rm -f $(OUTPUT).gdb
34+
rm -f $(OUTPUT).map
35+
36+
$(OUTPUT): $(OBJS)
37+
@echo [Linking $@]
38+
i386-soso-ld -v $(LDFLAGS) $(OBJS) -o $(OUTPUT) $(LIBS)
39+
@echo [Size]
40+
-$(CROSS_COMPILE)size $(OUTPUT)
41+
cp $(OUTPUT) ~/git/soso/userspace/bin/
42+
43+
$(OBJS): | $(OBJDIR)
44+
45+
$(OBJDIR):
46+
mkdir -p $(OBJDIR)
47+
48+
$(OBJDIR)/%.o: %.c
49+
@echo [Compiling $<]
50+
$(VB)$(CC) $(CFLAGS) -c $< -o $@
51+
52+
print:
53+
@echo OBJS: $(OBJS)
54+

doomgeneric/doomgeneric_soso.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#include <stdio.h>
88
#include <fcntl.h>
99
#include <unistd.h>
10+
#include <string.h>
11+
12+
#include <sys/ioctl.h>
13+
#include <sys/mman.h>
1014

1115
#include <sosousdk.h>
12-
#include "../kernel/termios.h"
16+
#include <termios.h>
1317

1418
static int FrameBufferFd = -1;
1519
static int* FrameBuffer = 0;
@@ -25,6 +29,16 @@ static unsigned int s_KeyQueueReadIndex = 0;
2529
static unsigned int s_PositionX = 0;
2630
static unsigned int s_PositionY = 0;
2731

32+
static unsigned int s_ScreenWidth = 0;
33+
static unsigned int s_ScreenHeight = 0;
34+
35+
enum EnFrameBuferIoctl
36+
{
37+
FB_GET_WIDTH,
38+
FB_GET_HEIGHT,
39+
FB_GET_BITSPERPIXEL
40+
};
41+
2842
static unsigned char convertToDoomKey(unsigned char scancode)
2943
{
3044
unsigned char key = 0;
@@ -90,12 +104,14 @@ static void addKeyToQueue(int pressed, unsigned char keyCode)
90104

91105
struct termios orig_termios;
92106

93-
void disableRawMode() {
107+
void disableRawMode()
108+
{
94109
//printf("returning original termios\n");
95110
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
96111
}
97112

98-
void enableRawMode() {
113+
void enableRawMode()
114+
{
99115
tcgetattr(STDIN_FILENO, &orig_termios);
100116
atexit(disableRawMode);
101117
struct termios raw = orig_termios;
@@ -111,20 +127,34 @@ void DG_Init()
111127

112128
if (FrameBufferFd >= 0)
113129
{
114-
FrameBuffer = mmap(NULL, DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4, 0, FrameBufferFd, 0);
130+
printf("Getting screen width...");
131+
s_ScreenWidth = ioctl(FrameBufferFd, FB_GET_WIDTH);
132+
printf("%d\n", s_ScreenWidth);
133+
134+
printf("Getting screen height...");
135+
s_ScreenHeight = ioctl(FrameBufferFd, FB_GET_HEIGHT);
136+
printf("%d\n", s_ScreenHeight);
137+
138+
if (0 == s_ScreenWidth || 0 == s_ScreenHeight)
139+
{
140+
printf("Unable to obtain screen info!");
141+
exit(1);
142+
}
143+
144+
FrameBuffer = mmap(NULL, s_ScreenWidth * s_ScreenHeight * 4, PROT_READ | PROT_WRITE, 0, FrameBufferFd, 0);
115145

116146
if (FrameBuffer != (int*)-1)
117147
{
118-
printf("mmap success\n");
148+
printf("FrameBuffer mmap success\n");
119149
}
120150
else
121151
{
122-
printf("mmap failed\n");
152+
printf("FrameBuffermmap failed\n");
123153
}
124154
}
125155
else
126156
{
127-
printf("opening device failed!\n");
157+
printf("Opening FrameBuffer device failed!\n");
128158
}
129159

130160
enableRawMode();
@@ -134,7 +164,7 @@ void DG_Init()
134164
if (KeyboardFd >= 0)
135165
{
136166
//enter non-blocking mode
137-
syscall_ioctl(KeyboardFd, 1, (void*)1);
167+
ioctl(KeyboardFd, 1, (void*)1);
138168
}
139169

140170
int argPosX = 0;
@@ -185,13 +215,9 @@ void DG_DrawFrame()
185215
{
186216
if (FrameBuffer)
187217
{
188-
//memcpy(FrameBuffer, DG_ScreenBuffer, DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);
189-
190-
const int screenWidth = 1024;
191-
192218
for (int i = 0; i < DOOMGENERIC_RESY; ++i)
193219
{
194-
memcpy(FrameBuffer + s_PositionX + (i + s_PositionY) * screenWidth, DG_ScreenBuffer + i * DOOMGENERIC_RESX, DOOMGENERIC_RESX * 4);
220+
memcpy(FrameBuffer + s_PositionX + (i + s_PositionY) * s_ScreenWidth, DG_ScreenBuffer + i * DOOMGENERIC_RESX, DOOMGENERIC_RESX * 4);
195221
}
196222
}
197223

0 commit comments

Comments
 (0)