From c7df0bd4f2479c98e3b843c06954ceba593a88c7 Mon Sep 17 00:00:00 2001 From: manuelaidos123 Date: Sun, 2 Feb 2025 20:12:58 +0000 Subject: [PATCH 1/2] changes to getsfx --- linuxdoom-1.10/i_sound.c | 118 ++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/linuxdoom-1.10/i_sound.c b/linuxdoom-1.10/i_sound.c index a327bfa29..307465945 100644 --- a/linuxdoom-1.10/i_sound.c +++ b/linuxdoom-1.10/i_sound.c @@ -182,78 +182,82 @@ myioctl // This function loads the sound data from the WAD lump, // for single sound. // -void* -getsfx -( char* sfxname, - int* len ) -{ - unsigned char* sfx; - unsigned char* paddedsfx; - int i; - int size; - int paddedsize; - char name[20]; - int sfxlump; +void* getsfx(const char* sfxname, int* len) { + unsigned char *sfx, *paddedsfx; + int i, size, paddedsize; + char name[64]; // Increased size for safety. + int sfxlump; + + // Build the lump name safely. + if (snprintf(name, sizeof(name), "ds%s", sfxname) >= sizeof(name)) { + fprintf(stderr, "Error: sfxname too long for buffer\n"); + exit(EXIT_FAILURE); + } - - // Get the sound data from the WAD, allocate lump - // in zone memory. - sprintf(name, "ds%s", sfxname); - - // Now, there is a severe problem with the - // sound handling, in it is not (yet/anymore) - // gamemode aware. That means, sounds from - // DOOM II will be requested even with DOOM - // shareware. - // The sound list is wired into sounds.c, - // which sets the external variable. - // I do not do runtime patches to that - // variable. Instead, we will use a - // default sound for replacement. - if ( W_CheckNumForName(name) == -1 ) - sfxlump = W_GetNumForName("dspistol"); - else - sfxlump = W_GetNumForName(name); - - size = W_LumpLength( sfxlump ); + // Check if the lump exists. + if (W_CheckNumForName(name) == -1) { + fprintf(stderr, "Warning: Lump '%s' not found. Using default sound 'dspistol'.\n", name); + sfxlump = W_GetNumForName("dspistol"); + if (sfxlump == -1) { + fprintf(stderr, "Critical error: Default sound 'dspistol' not found in WAD.\n"); + exit(EXIT_FAILURE); + } + } else { + sfxlump = W_GetNumForName(name); + } - // Debug. - // fprintf( stderr, "." ); - //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n", - // sfxname, sfxlump, size ); - //fflush( stderr ); - - sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC ); + // Get the lump length. + size = W_LumpLength(sfxlump); + if (size < 8) { + fprintf(stderr, "Error: Lump '%s' is too small (size=%d)\n", name, size); + exit(EXIT_FAILURE); + } - // Pads the sound effect out to the mixing buffer size. - // The original realloc would interfere with zone memory. - paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT; + // Cache the lump data. + sfx = (unsigned char*)W_CacheLumpNum(sfxlump, PU_STATIC); + if (!sfx) { + fprintf(stderr, "Error: Failed to cache lump '%s'\n", name); + exit(EXIT_FAILURE); + } - // Allocate from zone memory. - paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 ); - // ddt: (unsigned char *) realloc(sfx, paddedsize+8); - // This should interfere with zone memory handling, - // which does not kick in in the soundserver. + /* + * The original code seems to assume the first 8 bytes are a header, + * and the actual sound data starts at offset 8. + * Verify that this is the intended behavior. + */ + int dataSize = size - 8; + // Calculate the padded size to be a multiple of SAMPLECOUNT. + paddedsize = ((dataSize + SAMPLECOUNT - 1) / SAMPLECOUNT) * SAMPLECOUNT; + + // Allocate memory for padded data. We allocate 8 extra bytes at the beginning. + paddedsfx = (unsigned char*)Z_Malloc(paddedsize + 8, PU_STATIC, 0); + if (!paddedsfx) { + fprintf(stderr, "Error: Memory allocation failed for padded sfx data.\n"); + exit(EXIT_FAILURE); + } - // Now copy and pad. - memcpy( paddedsfx, sfx, size ); - for (i=size ; i Date: Mon, 3 Feb 2025 23:52:19 +0000 Subject: [PATCH 2/2] SVGA support --- linuxdoom-1.10/i_svga.c | 47 ++++++++++++++++++++++++++++++++++++++++ linuxdoom-1.10/i_video.c | 13 ++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 linuxdoom-1.10/i_svga.c diff --git a/linuxdoom-1.10/i_svga.c b/linuxdoom-1.10/i_svga.c new file mode 100644 index 000000000..304017097 --- /dev/null +++ b/linuxdoom-1.10/i_svga.c @@ -0,0 +1,47 @@ +#include +#include +#include "doomdef.h" +#include "i_system.h" +#include "v_video.h" +#include "d_main.h" + +static int current_mode; +static byte* screen_buffer; + +boolean I_InitSVGA(void) +{ + // Initialize SVGA library + vga_init(); + + // Try to set highest supported mode + // Common SVGA modes: 640x480, 800x600, 1024x768 + if (vga_hasmode(G1024x768x256)) { + current_mode = G1024x768x256; + SCREENWIDTH = 1024; + SCREENHEIGHT = 768; + } else if (vga_hasmode(G800x600x256)) { + current_mode = G800x600x256; + SCREENWIDTH = 800; + SCREENHEIGHT = 600; + } else { + current_mode = G640x480x256; + SCREENWIDTH = 640; + SCREENHEIGHT = 480; + } + + if (vga_setmode(current_mode) == -1) + I_Error("Could not set SVGA mode"); + + // Allocate screen buffer + screen_buffer = Z_Malloc(SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); + screens[0] = screen_buffer; + + return true; +} + +void I_UpdateSVGAScreen(void) +{ + // Copy buffer to SVGA memory + vga_setpage(0); + memcpy(vga_getgraphmem(), screen_buffer, SCREENWIDTH * SCREENHEIGHT); +} \ No newline at end of file diff --git a/linuxdoom-1.10/i_video.c b/linuxdoom-1.10/i_video.c index 9b311b39a..03149becd 100644 --- a/linuxdoom-1.10/i_video.c +++ b/linuxdoom-1.10/i_video.c @@ -691,7 +691,18 @@ void grabsharedmemory(int size) void I_InitGraphics(void) { - +#ifdef USE_SVGA + if (M_CheckParm("-svga")) + { + if (I_InitSVGA()) + { + // Override default update function + I_FinishUpdate = I_UpdateSVGAScreen; + return; + } + } +#endif + // Fallback to existing X11 initialization... char* displayname; char* d; int n;