Skip to content

Commit

Permalink
fbdoom first version with more generic framebuffer support
Browse files Browse the repository at this point in the history
  • Loading branch information
maximevince committed Dec 2, 2017
1 parent f167242 commit 72b0675
Show file tree
Hide file tree
Showing 186 changed files with 110 additions and 74 deletions.
15 changes: 11 additions & 4 deletions README.TXT
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
================
= FROSTED DOOM =
= fbDOOM =
================

Port of original DOOM to Frosted operating system.
Frosted does not yet have a framebuffer nor sound driver,
so for the moment, it just compiles and links...
Adaptation of the original DOOM
to be easily portable to framebuffer devices with minimal depenencies.
Runs on:
* Plain desktop Linux framebuffer,
* Siglent SSA 3021X Spectrum Analyzer,
* Frosted OS

To build (example):
* cd fbdoom
* make CROSS_COMPILE=arm-linux-gnueabihf-


Original readme
Expand Down
31 changes: 7 additions & 24 deletions frosted-doom/Makefile → fbdoom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,28 @@
# $Log:$
#

ARM?=1
CROSS_COMPILE ?= #arm-linux-gnueabihf-

ifeq ($(V),1)
VB=''
else
VB=@
endif

ifeq ($(ARM),1)
CROSS_COMPILE = arm-frosted-eabi-
OBJS+=$(OBJDIR)/i_video_fbdev.o
CFLAGS+=-mthumb -mlittle-endian -mthumb-interwork -ffunction-sections -fdata-sections -mcpu=cortex-m3
CFLAGS+=-DCORE_M3 -D__frosted__
# COMPILER FLAGS -- No gcc libraries
CFLAGS+=-nostartfiles
# COMPILER FLAGS -- GOT/PIC
CFLAGS+=-fPIC -mlong-calls -fno-common -msingle-pic-base -mno-pic-data-is-text-relative -Wstack-usage=1024
# LINKER FLAGS
LDFLAGS+=-fPIC -mlong-calls -fno-common -Wl,-elf2flt -lgloss
else
CFLAGS+=-m32 -fsanitize=address -Wunused-const-variable=0
LIBS+=-lXext -lX11 -lnsl -lm -lSDL
OBJS+=$(OBJDIR)/i_video.o
endif
#LIBS+=-lXext -lX11 -lnsl -lm -lSDL
#CFLAGS+=-Wunused-const-variable=0
#CFLAGS+=-fsanitize=address
OBJS+=$(OBJDIR)/i_video_fbdev.o

CC= $(CROSS_COMPILE)gcc # gcc or g++
CC=$(CROSS_COMPILE)gcc # gcc or g++
CFLAGS+=-ggdb3 -Os
LDFLAGS+=-Wl,--gc-sections
CFLAGS+=-ggdb3 -Wall -DNORMALUNIX -DLINUX -DSNDSERV # -DUSEASM
LIBS+=-lm -lc

# subdirectory for objects
OBJDIR=build
OUTPUT=fdoom
OUTPUT=fbdoom

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_file_stdc_unbuffered.o w_main.o w_wad.o z_zone.o
OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))
Expand All @@ -57,7 +45,6 @@ $(OUTPUT): $(OBJS)
-o $(OUTPUT) $(LIBS) -Wl,-Map,$(OUTPUT).map
@echo [Size]
-$(CROSS_COMPILE)size $(OUTPUT)
-$(CROSS_COMPILE)flthdr $(OUTPUT)

$(OBJS): | $(OBJDIR)

Expand All @@ -71,7 +58,3 @@ $(OBJDIR)/%.o: %.c
print:
@echo OBJS: $(OBJS)

#############################################################
#
#############################################################

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
138 changes: 92 additions & 46 deletions frosted-doom/i_video_fbdev.c → fbdoom/i_video_fbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/fb.h>
#include <sys/ioctl.h>

//#define CMAP256

#define FB_WIDTH (480)
#define FB_HEIGHT (272)
#define FB_BPP_RGB565 (16)
struct fb_var_screeninfo fb = {};
int fb_scaling = 1;

struct color {
uint32_t b:8;
Expand Down Expand Up @@ -105,7 +106,6 @@ int usemouse = 0;

int vanilla_keyboard_mapping = true;


typedef struct
{
byte r;
Expand All @@ -117,38 +117,56 @@ typedef struct

static uint16_t rgb565_palette[256];

// Last touch state

//static touch_state_t last_touch_state;

// Last button state
void cmap_to_rgb565(uint16_t * out, uint8_t * in, int in_pixels)
{
int i, j;
struct color c;
uint16_t r, g, b;

//static bool last_button_state;
for (i = 0; i < in_pixels; i++)
{
c = colors[*in];
r = ((uint16_t)(c.r >> 3)) << 11;
g = ((uint16_t)(c.g >> 2)) << 5;
b = ((uint16_t)(c.b >> 3)) << 0;
*out = (r | g | b);

in++;
for (j = 0; j < fb_scaling; j++) {
out++;
}
}
}

// run state
void cmap_to_fb(uint8_t * out, uint8_t * in, int in_pixels)
{
int i, j, k;
struct color c;
uint32_t pix;
uint16_t r, g, b;

//static bool run;
for (i = 0; i < in_pixels; i++)
{
c = colors[*in]; /* R:8 G:8 B:8 format! */
r = (uint16_t)(c.r >> (8 - fb.red.length));
g = (uint16_t)(c.g >> (8 - fb.green.length));
b = (uint16_t)(c.b >> (8 - fb.blue.length));
pix = r << fb.red.offset;
pix |= g << fb.green.offset;
pix |= b << fb.blue.offset;

for (k = 0; k < fb_scaling; k++) {
for (j = 0; j < fb.bits_per_pixel/8; j++) {
*out = (pix >> (j*8));
out++;
}
}
in++;
}
}

void I_InitGraphics (void)
{
// gfx_image_t keys_img;
// gfx_coord_t coords;
//
// gfx_init_img (&keys_img, 40, 320, GFX_PIXEL_FORMAT_RGB565, RGB565_BLACK);
// keys_img.pixel_data = (uint8_t*)img_keys;
// gfx_init_img_coord (&coords, &keys_img);
//
// gfx_draw_img (&keys_img, &coords);
// lcd_refresh ();
//
// gfx_draw_img (&keys_img, &coords);
// lcd_refresh ();

X_width = SCREENWIDTH;
X_height = SCREENHEIGHT;

printf("I_InitGraphics: w x h: %d x %d\n", X_width, X_height);

/* Open fbdev file descriptor */
fd_fb = open("/dev/fb0", O_RDWR);
if (fd_fb < 0)
Expand All @@ -157,19 +175,33 @@ void I_InitGraphics (void)
exit(-1);
}

/* fetch framebuffer info */
ioctl(fd_fb, FBIOGET_VSCREENINFO, &fb);
/* change params if needed */
//ioctl(fd_fb, FBIOPUT_VSCREENINFO, &fb);
printf("I_InitGraphics: framebuffer: x_res: %d, y_res: %d, x_virtual: %d, y_virtual: %d, bpp: %d, grayscale: %d\n",
fb.xres, fb.yres, fb.xres_virtual, fb.yres_virtual, fb.bits_per_pixel, fb.grayscale);

printf("I_InitGraphics: framebuffer: RGBA: %d%d%d%d, red_off: %d, green_off: %d, blue_off: %d, transp_off: %d\n",
fb.red.length, fb.green.length, fb.blue.length, fb.transp.length, fb.red.offset, fb.green.offset, fb.blue.offset, fb.transp.offset);

printf("I_InitGraphics: DOOM screen size: w x h: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
fb_scaling = fb.xres / SCREENWIDTH;
if (fb.yres / SCREENHEIGHT < fb_scaling)
fb_scaling = fb.yres / SCREENHEIGHT;
printf("I_InitGraphics: Auto-scaling factor: %d\n", fb_scaling);

/* Allocate screen to draw to */
//screen_pixels = malloc(X_width * X_height);
//
I_VideoBuffer = (byte*)Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); // For DOOM to draw on
I_VideoBuffer_FB = (byte*)Z_Malloc (FB_WIDTH * FB_HEIGHT, PU_STATIC, NULL); // For a single write() syscall to fbdev
I_VideoBuffer_FB = (byte*)malloc(fb.xres * fb.yres * (fb.bits_per_pixel/8)); // For a single write() syscall to fbdev

screenvisible = true;
}

void I_ShutdownGraphics (void)
{
Z_Free (I_VideoBuffer);
Z_Free (I_VideoBuffer_FB);
free(I_VideoBuffer_FB);
}

void I_StartFrame (void)
Expand Down Expand Up @@ -362,15 +394,18 @@ void I_UpdateNoBlit (void)

void I_FinishUpdate (void)
{
#define CMAP256
int y;
int x_offset, y_offset, x_offset_end;
unsigned char *line_in, *line_out;

/* Offsets in case FB is bigger than DOOM */
y_offset = (FB_HEIGHT - SCREENHEIGHT + 1) / 2;
x_offset = (FB_WIDTH - SCREENWIDTH + 1) / 2;
x_offset_end = (FB_WIDTH - SCREENWIDTH - x_offset);
/* 600 = fb heigt, 200 screenheight */
/* 600 = fb heigt, 200 screenheight */
/* 2048 =fb width, 320 screenwidth */
y_offset = (((fb.yres - (SCREENHEIGHT * fb_scaling)) * fb.bits_per_pixel/8)) / 2;
x_offset = (((fb.xres - (SCREENWIDTH * fb_scaling)) * fb.bits_per_pixel/8)) / 2; // XXX: siglent FB hack: /4 instead of /2, since it seems to handle the resolution in a funny way
//x_offset = 0;
x_offset_end = ((fb.xres - (SCREENWIDTH * fb_scaling)) * fb.bits_per_pixel/8) - x_offset;

/* DRAW SCREEN */
line_in = (unsigned char *) I_VideoBuffer;
Expand All @@ -380,20 +415,27 @@ void I_FinishUpdate (void)

while (y--)
{
line_out += x_offset;
int i;
for (i = 0; i < fb_scaling; i++) {
line_out += x_offset;
#ifdef CMAP256
memcpy(line_out, line_in, SCREENWIDTH); /* FB_WIDTH is bigger than Doom SCREENWIDTH... */
for (fb_scaling == 1) {
memcpy(line_out, line_in, SCREENWIDTH); /* fb_width is bigger than Doom SCREENWIDTH... */
} else {
//XXX FIXME fb_scaling support!
}
#else
cmap_to_rgb565(line_out, line_in, SCREENWIDTH);
//cmap_to_rgb565((void*)line_out, (void*)line_in, SCREENWIDTH);
cmap_to_fb((void*)line_out, (void*)line_in, SCREENWIDTH);
#endif
line_out += (SCREENWIDTH * fb_scaling * (fb.bits_per_pixel/8)) + x_offset_end;
}
line_in += SCREENWIDTH;
line_out += SCREENWIDTH + x_offset_end;
}

/* Start drawing from y-offset */
lseek(fd_fb, y_offset * FB_WIDTH, SEEK_SET);
write(fd_fb, I_VideoBuffer_FB, SCREENHEIGHT * FB_WIDTH); /* draw only portion used by doom + x-offsets */

lseek(fd_fb, y_offset * fb.xres, SEEK_SET);
write(fd_fb, I_VideoBuffer_FB, (SCREENHEIGHT * fb_scaling * (fb.bits_per_pixel/8)) * fb.xres); /* draw only portion used by doom + x-offsets */
}

//
Expand Down Expand Up @@ -428,6 +470,10 @@ void I_SetPalette (byte* palette)
// palette += 3;
//}


/* performance boost:
* map to the right pixel format over here! */

for (i=0; i<256; ++i ) {
colors[i].a = 0;
colors[i].r = gammatable[usegamma][*palette++];
Expand All @@ -436,7 +482,7 @@ void I_SetPalette (byte* palette)
}

/* Set new color map in kernel framebuffer driver */
ioctl(fd_fb, IOCTL_FB_PUTCMAP, colors);
//XXX FIXME ioctl(fd_fb, IOCTL_FB_PUTCMAP, colors);
}

// Given an RGB value, find the closest matching palette index.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 72b0675

Please sign in to comment.