Skip to content

Commit 25cff59

Browse files
committed
games/NXDoom: support RGB565 and loadable modules
Add RGB565 framebuffer output and module builds. Harden configuration parsing and renderer bounds, support supervised SIGTERM shutdown, and notify framebuffer drivers after drawing. Assisted-by: Codex:gpt-5 Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
1 parent 2aebae7 commit 25cff59

11 files changed

Lines changed: 186 additions & 22 deletions

File tree

games/NXDoom/Kconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
config GAMES_NXDOOM
7-
bool "NXDoom"
7+
tristate "NXDoom"
88
default n
99
depends on ALLOW_GPL_COMPONENTS
1010
depends on VIDEO_FB
@@ -252,6 +252,13 @@ config GAMES_NXDOOM_MAXDRAWSEGS
252252
memory, so you may reduce the number. However, too few will cause
253253
rendering issues (overflow is checked to avoid crashes).
254254

255+
config GAMES_NXDOOM_STATDUMP_MAX_CAPTURES
256+
int "Maximum statdump capture buffer entries"
257+
default 32
258+
range 1 1024
259+
---help---
260+
Number of diagnostic playtime-statistics capture slots.
261+
255262
config GAMES_NXDOOM_RANGECHECK
256263
bool "Perform range checks"
257264
default y

games/NXDoom/src/d_iwad.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ static void buld_iwad_dir_list(void)
271271

272272
add_iwad_dir(m_dir_name(myargv[0]));
273273

274+
/* Add the configured DOOM data directory */
275+
276+
add_iwad_dir(CONFIG_GAMES_NXDOOM_PREFDIR);
277+
274278
/* Add DOOMWADDIR if it is in the environment */
275279

276280
env = getenv("DOOMWADDIR");

games/NXDoom/src/doom/d_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ void d_doomloop(void)
12941294

12951295
while (1)
12961296
{
1297+
i_poll_quit_signal();
12971298
d_run_frame();
12981299
}
12991300
}

games/NXDoom/src/doom/r_draw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ void r_draw_span(void)
597597

598598
#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
599599
if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH ||
600-
(unsigned)ds_y > SCREENHEIGHT)
600+
ds_y < 0 || ds_y >= viewheight)
601601
{
602602
i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y);
603603
}
@@ -724,7 +724,7 @@ void r_draw_span_low(void)
724724

725725
#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
726726
if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH ||
727-
(unsigned)ds_y > SCREENHEIGHT)
727+
ds_y < 0 || ds_y >= viewheight)
728728
{
729729
i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y);
730730
}

games/NXDoom/src/doom/r_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "d_loop.h"
3333
#include "doomdef.h"
34+
#include "i_system.h"
3435

3536
#include "m_bbox.h"
3637
#include "m_menu.h"
@@ -685,6 +686,13 @@ fixed_t r_scale_from_global_angle(angle_t visangle)
685686

686687
void r_set_view_size(int blocks, int detail)
687688
{
689+
/* Reject invalid screen sizes before calculating view geometry. */
690+
691+
if (blocks < 3 || blocks > 11)
692+
{
693+
i_error("r_set_view_size: screenblocks=%d out of range", blocks);
694+
}
695+
688696
setsizeneeded = true;
689697
setblocks = blocks;
690698
setdetail = detail;

games/NXDoom/src/doom/r_plane.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ planefunction_t ceilingfunc;
5858
/* Here comes the obnoxious "visplane". */
5959

6060
visplane_t visplanes[CONFIG_GAMES_NXDOOM_MAXVISPLANES];
61+
short openings[MAXOPENINGS];
6162
visplane_t *lastvisplane;
6263
visplane_t *floorplane;
6364
visplane_t *ceilingplane;
6465

65-
short openings[MAXOPENINGS];
6666
short *lastopening;
6767

6868
/* Clip values are the solid pixel bounding the range. floorclip starts out
@@ -114,12 +114,21 @@ static void r_map_plane(int y, int x1, int x2)
114114
fixed_t length;
115115
unsigned index;
116116

117-
#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
118-
if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight)
117+
/* Ensure array indices are in range before access. */
118+
119+
if (x2 < x1 || x1 < 0 || x2 >= viewwidth)
119120
{
120-
i_error("R_MapPlane: %i, %i at %i", x1, x2, y);
121+
return;
122+
}
123+
124+
if (y < 0)
125+
{
126+
y = 0;
127+
}
128+
else if (y >= viewheight)
129+
{
130+
y = viewheight - 1;
121131
}
122-
#endif
123132

124133
if (planeheight != cachedheight[y])
125134
{
@@ -160,27 +169,42 @@ static void r_map_plane(int y, int x1, int x2)
160169
spanfunc();
161170
}
162171

172+
static inline boolean r_row_in_range(int row)
173+
{
174+
return row >= 0 && row < SCREENHEIGHT;
175+
}
176+
163177
static void r_make_spans(int x, int t1, int b1, int t2, int b2)
164178
{
179+
/* Check that row is in range before indexing arrays. */
180+
165181
while (t1 < t2 && t1 <= b1)
166182
{
167-
r_map_plane(t1, spanstart[t1], x - 1);
183+
r_map_plane(t1, r_row_in_range(t1) ? spanstart[t1] : 0, x - 1);
168184
t1++;
169185
}
170186
while (b1 > b2 && b1 >= t1)
171187
{
172-
r_map_plane(b1, spanstart[b1], x - 1);
188+
r_map_plane(b1, r_row_in_range(b1) ? spanstart[b1] : 0, x - 1);
173189
b1--;
174190
}
175191

176192
while (t2 < t1 && t2 <= b2)
177193
{
178-
spanstart[t2] = x;
194+
if (r_row_in_range(t2))
195+
{
196+
spanstart[t2] = x;
197+
}
198+
179199
t2++;
180200
}
181201
while (b2 > b1 && b2 >= t2)
182202
{
183-
spanstart[b2] = x;
203+
if (r_row_in_range(b2))
204+
{
205+
spanstart[b2] = x;
206+
}
207+
184208
b2--;
185209
}
186210
}
@@ -314,13 +338,15 @@ visplane_t *r_check_plane(visplane_t *pl, int start, int stop)
314338

315339
/* make a new visplane */
316340

341+
if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES)
342+
{
343+
i_error("r_check_plane: no more visplanes");
344+
}
345+
317346
lastvisplane->height = pl->height;
318347
lastvisplane->picnum = pl->picnum;
319348
lastvisplane->lightlevel = pl->lightlevel;
320349

321-
if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES)
322-
i_error("r_check_plane: no more visplanes");
323-
324350
pl = lastvisplane++;
325351
pl->minx = start;
326352
pl->maxx = stop;

games/NXDoom/src/doom/statdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Pre-processor Definitions
4040
****************************************************************************/
4141

42-
#define MAX_CAPTURES 32
42+
#define MAX_CAPTURES CONFIG_GAMES_NXDOOM_STATDUMP_MAX_CAPTURES
4343

4444
/****************************************************************************
4545
* Private Data

games/NXDoom/src/i_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ void d_doom_main(void);
5757

5858
int main(int argc, char **argv)
5959
{
60+
i_install_quit_signal();
61+
6062
/* save arguments */
6163

6264
myargc = argc;

games/NXDoom/src/i_system.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* Included Files
2323
****************************************************************************/
2424

25+
#include <errno.h>
26+
#include <signal.h>
2527
#include <stdarg.h>
2628
#include <stdio.h>
2729
#include <stdlib.h>
@@ -75,6 +77,10 @@ static atexit_listentry_t *exit_funcs = NULL;
7577

7678
static boolean already_quitting = false;
7779

80+
/* Set by the signal handler and polled from the main loop. */
81+
82+
static volatile sig_atomic_t quit_requested = 0;
83+
7884
/* Read Access Violation emulation.
7985
*
8086
* From PrBoom+, by entryway.
@@ -320,6 +326,69 @@ void i_quit(void)
320326
exit(0);
321327
}
322328

329+
/****************************************************************************
330+
* Name: i_quit_signal_handler
331+
*
332+
* Description:
333+
* Records that a quit was requested. The work is deferred to
334+
* i_poll_quit_signal() so that no cleanup runs from signal context.
335+
*
336+
****************************************************************************/
337+
338+
static void i_quit_signal_handler(int signo)
339+
{
340+
(void)signo;
341+
quit_requested = 1;
342+
}
343+
344+
/****************************************************************************
345+
* Name: i_install_quit_signal
346+
*
347+
* Description:
348+
* Installs the SIGTERM handler used to request a clean exit.
349+
*
350+
****************************************************************************/
351+
352+
void i_install_quit_signal(void)
353+
{
354+
struct sigaction sa;
355+
356+
/* Reset state left by an earlier built-in run. */
357+
358+
quit_requested = 0;
359+
exit_funcs = NULL;
360+
361+
memset(&sa, 0, sizeof(sa));
362+
sa.sa_handler = i_quit_signal_handler;
363+
sigemptyset(&sa.sa_mask);
364+
365+
if (sigaction(SIGTERM, &sa, NULL) < 0)
366+
{
367+
/* Not fatal: the game runs, it just cannot be asked to exit. */
368+
369+
printf("nxdoom: failed to install SIGTERM handler: %d\n",
370+
errno);
371+
}
372+
}
373+
374+
/****************************************************************************
375+
* Name: i_poll_quit_signal
376+
*
377+
* Description:
378+
* Exits if a quit was requested. Called from the main loop, where the
379+
* cleanup i_quit() performs is safe to run.
380+
*
381+
****************************************************************************/
382+
383+
void i_poll_quit_signal(void)
384+
{
385+
if (quit_requested)
386+
{
387+
printf("nxdoom: quit signal seen, calling i_quit\n");
388+
i_quit();
389+
}
390+
}
391+
323392
void i_error(const char *error, ...)
324393
{
325394
char msgbuf[512];

games/NXDoom/src/i_system.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ ticcmd_t *i_base_ticcmd(void);
7373

7474
void i_quit(void) NORETURN;
7575

76+
/****************************************************************************
77+
* Name: i_install_quit_signal
78+
*
79+
* Description:
80+
* Install the SIGTERM handler used to request a clean exit.
81+
*
82+
****************************************************************************/
83+
84+
void i_install_quit_signal(void);
85+
86+
/****************************************************************************
87+
* Name: i_poll_quit_signal
88+
*
89+
* Description:
90+
* Exit if SIGTERM requested a clean shutdown.
91+
*
92+
****************************************************************************/
93+
94+
void i_poll_quit_signal(void);
95+
7696
void i_error(const char *error, ...) NORETURN PRINTF_ATTR(1, 2);
7797

7898
void i_tactile(int on, int off, int total);

0 commit comments

Comments
 (0)