Use the QVM build toolchain from ioq3

This commit is contained in:
Izuru Yakumo
2025-07-15 15:09:05 -03:00
parent 733fac10f2
commit e8a6db7830
32 changed files with 1982 additions and 1955 deletions

View File

@@ -63,9 +63,9 @@ char *ex_argv[MAX_EX_ARGC];
void ExpandWildcards( int *argc, char ***argv )
{
struct _finddata_t fileinfo;
int handle;
intptr_t handle;
int i;
char filename[1024];
char filename[2048];
char filebase[1024];
char *path;
@@ -88,7 +88,7 @@ void ExpandWildcards( int *argc, char ***argv )
do
{
sprintf (filename, "%s%s", filebase, fileinfo.name);
snprintf (filename, sizeof(filename), "%s%s", filebase, fileinfo.name);
ex_argv[ex_argc++] = copystring (filename);
} while (_findnext( handle, &fileinfo ) != -1);
@@ -126,7 +126,7 @@ void Error( const char *error, ... )
vsprintf (text, error,argptr);
va_end (argptr);
sprintf (text2, "%s\nGetLastError() = %i", text, err);
snprintf (text2, sizeof(text2), "%s\nGetLastError() = %i", text, err);
MessageBox(NULL, text2, "Error", 0 /* MB_OK */ );
exit (1);
@@ -185,7 +185,7 @@ void _printf( const char *format, ... ) {
vsprintf (text, format, argptr);
va_end (argptr);
printf(text);
printf("%s", text);
#ifdef WIN32
if (!lookedForServer) {
@@ -318,7 +318,7 @@ char *ExpandPath (const char *path)
strcpy( full, path );
return full;
}
sprintf (full, "%s%s", qdir, path);
snprintf (full, sizeof(full), "%s%s", qdir, path);
return full;
}
@@ -331,20 +331,20 @@ char *ExpandGamePath (const char *path)
strcpy( full, path );
return full;
}
sprintf (full, "%s%s", gamedir, path);
snprintf (full, sizeof(full), "%s%s", gamedir, path);
return full;
}
char *ExpandPathAndArchive (const char *path)
{
char *expanded;
char archivename[1024];
char archivename[2048];
expanded = ExpandPath (path);
if (archive)
{
sprintf (archivename, "%s/%s", archivedir, path);
snprintf (archivename, sizeof(archivename), "%s/%s", archivedir, path);
QCopyFile (expanded, archivename);
}
return expanded;
@@ -396,10 +396,12 @@ void Q_getwd (char *out)
int i = 0;
#ifdef WIN32
_getcwd (out, 256);
if (_getcwd (out, 256) == NULL)
strcpy(out, "."); /* shrug */
strcat (out, "\\");
#else
getcwd (out, 256);
if (getcwd (out, 256) == NULL)
strcpy(out, "."); /* shrug */
strcat (out, "/");
#endif
@@ -732,7 +734,7 @@ int LoadFile( const char *filename, void **bufferptr )
==============
LoadFileBlock
-
rounds up memory allocation to 4K boundry
rounds up memory allocation to 4K boundary
-
==============
*/
@@ -808,7 +810,7 @@ void DefaultExtension (char *path, const char *extension)
{
char *src;
//
// if path doesnt have a .EXT, append extension
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src = path + strlen(path) - 1;

View File

@@ -59,7 +59,7 @@ typedef unsigned char byte;
#define MAX_OS_PATH 1024
#define MEM_BLOCKSIZE 4096
// the dec offsetof macro doesnt work very well...
// the dec offsetof macro doesn't work very well...
#define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier)
@@ -71,7 +71,6 @@ char *strupr (char *in);
char *strlower (char *in);
int Q_strncasecmp( const char *s1, const char *s2, int n );
int Q_stricmp( const char *s1, const char *s2 );
#define Q_strequal(s1,s2) (Q_stricmp(s1,s2)==0)
void Q_getwd( char *out );
int Q_filelength (FILE *f);

View File

@@ -1,5 +1,5 @@
don't do any paramter conversion (double to float, etc)
don't do any parameter conversion (double to float, etc)

View File

@@ -250,7 +250,6 @@ static void hashtable_init (hashtable_t *H, int buckets)
{
H->buckets = buckets;
H->table = calloc(H->buckets, sizeof(*(H->table)));
return;
}
static hashtable_t *hashtable_new (int buckets)
@@ -285,7 +284,6 @@ static void hashtable_add (hashtable_t *H, int hashvalue, void *datum)
}
hc->data = datum;
hc->next = 0;
return;
}
static hashchain_t *hashtable_get (hashtable_t *H, int hashvalue)
@@ -386,8 +384,12 @@ static void sort_symbols ()
symbol_t *s;
symbol_t **symlist;
if(!symbols)
return;
//crumb("sort_symbols: Constructing symlist array\n");
for (elems = 0, s = symbols; s; s = s->next, elems++) /* nop */ ;
symlist = malloc(elems * sizeof(symbol_t*));
for (i = 0, s = symbols; s; s = s->next, i++)
{
@@ -475,7 +477,7 @@ static unsigned int HashString (const char *key)
acc = (acc << 2) | (acc >> 30);
acc &= 0xffffffffU;
}
return abs(acc);
return acc;
}
@@ -489,10 +491,10 @@ static void CodeError( char *fmt, ... ) {
errorCount++;
report( "%s:%i ", currentFileName, currentFileLine );
fprintf( stderr, "%s:%i ", currentFileName, currentFileLine );
va_start( argptr,fmt );
vprintf( fmt,argptr );
vfprintf( stderr, fmt, argptr );
va_end( argptr );
}
@@ -544,7 +546,7 @@ static void DefineSymbol( char *sym, int value ) {
// add the file prefix to local symbols to guarantee unique
if ( sym[0] == '$' ) {
sprintf( expanded, "%s_%i", sym, currentFileIndex );
snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex );
sym = expanded;
}
@@ -600,7 +602,7 @@ static int LookupSymbol( char *sym ) {
// add the file prefix to local symbols to guarantee unique
if ( sym[0] == '$' ) {
sprintf( expanded, "%s_%i", sym, currentFileIndex );
snprintf( expanded, sizeof(expanded), "%s_%i", sym, currentFileIndex );
sym = expanded;
}
@@ -786,7 +788,7 @@ HackToSegment
BIG HACK: I want to put all 32 bit values in the data
segment so they can be byte swapped, and all char data in the lit
segment, but switch jump tables are emited in the lit segment and
segment, but switch jump tables are emitted in the lit segment and
initialized strng variables are put in the data segment.
I can change segments here, but I also need to fixup the
@@ -946,12 +948,11 @@ STAT("PROC");
ASM(ENDPROC)
{
int v, v2;
if ( !strcmp( token, "endproc" ) ) {
STAT("ENDPROC");
Parse(); // skip the function name
v = ParseValue(); // locals
v2 = ParseValue(); // arg marshalling
ParseValue(); // locals
ParseValue(); // arg marshalling
// all functions must leave something on the opstack
instructionCount++;
@@ -1128,7 +1129,7 @@ STAT("BYTE");
return 0;
}
// code labels are emited as instruction counts, not byte offsets,
// code labels are emitted as instruction counts, not byte offsets,
// because the physical size of the code will change with
// different run time compilers and we want to minimize the
// size of the required translation table
@@ -1520,12 +1521,13 @@ static void ShowHelp( char *argv0 ) {
Error("Usage: %s [OPTION]... [FILES]...\n\
Assemble LCC bytecode assembly to Q3VM bytecode.\n\
\n\
-o OUTPUT Write assembled output to file OUTPUT.qvm\n\
-f LISTFILE Read options and list of files to assemble from LISTFILE.q3asm\n\
-b BUCKETS Set symbol hash table to BUCKETS buckets\n\
-v Verbose compilation report\n\
-vq3 Produce a qvm file compatible with Q3 1.32b\n\
-h --help -? Show this help\n\
-o OUTPUT Write assembled output to file OUTPUT.qvm\n\
-f LISTFILE Read options and list of files to assemble from LISTFILE.q3asm\n\
-b BUCKETS Set symbol hash table to BUCKETS buckets\n\
-m Generate a mapfile for each OUTPUT.qvm\n\
-v Verbose compilation report\n\
-vq3 Produce a qvm file compatible with Q3 1.32b\n\
-h --help -? Show this help\n\
", argv0);
}
@@ -1562,7 +1564,7 @@ int main( int argc, char **argv ) {
if ( !strcmp( argv[i], "-o" ) ) {
if ( i == argc - 1 ) {
Error( "-o must preceed a filename" );
Error( "-o must precede a filename" );
}
/* Timbo of Tremulous pointed out -o not working; stock ID q3asm folded in the change. Yay. */
strcpy( outputFilename, argv[ i+1 ] );
@@ -1572,7 +1574,7 @@ int main( int argc, char **argv ) {
if ( !strcmp( argv[i], "-f" ) ) {
if ( i == argc - 1 ) {
Error( "-f must preceed a filename" );
Error( "-f must precede a filename" );
}
ParseOptionFile( argv[ i+1 ] );
i++;
@@ -1618,7 +1620,7 @@ Motivation: not wanting to scrollback for pages to find asm error.
}
// In some case it Segfault without this check
if ( numAsmFiles == 0 ) {
Error( "No file to assemble\n" );
Error( "No file to assemble" );
}
InitTables();