Commit Graph

12339 Commits

Author SHA1 Message Date
Bill Currie 7c6ef06dfb [gamecode] Make PF_VarString v6p-only
It's not enforced a this stage, and it would be easy enough to handle,
but it turns out all the standard quake and quakeworld progs never used
... for the print functions: the behavior of PF_VarString was
undocumented and so... tough :P.
2022-02-06 21:20:00 +09:00
Bill Currie 95c4cdd1b0 [vulkan] Set frame buffer before calling draw functions
This lets them set up their subpass inherit info correctly. QF now
renders correctly, albeit painfully slowly, on my VersaPro.
2022-02-06 13:12:16 +09:00
Bill Currie e1ecda9221 [gamecode] Add unsigned divide and remainder instructions
I had forgotten that unsigned division was different from signed
division (rather silly of me). However, with some testing and analysis,
unsigned true modulo is not needed as it's not possible to have
negative inputs and thus it's the same as remainder.
2022-02-06 12:20:17 +09:00
Bill Currie 5f2fd3cac0 [qfcc] Skip over zero stack adjustment
This is a very tiny optimization, but there's no point in adjust the
stack if there's no actual adjustment. I didn't bother with it initially
because I thought it wouldn't happen (and I was more interested in
getting things working first), but it turns out that simple getters that
result in a zero adjustment are quite common (70/535 in qwaq-app.dat).
2022-02-05 20:36:38 +09:00
Bill Currie fbb67419f2 [qwaq] Use RUA_Sprintf for non-va_list printers
This fixes the runtime error when the debugger gets to the end of the
gcd test program.
2022-02-05 20:26:06 +09:00
Bill Currie c10b09d41b [ruamoko] Make RUA_Sprintf more generally useful
It now takes the function name to print in error message (passed on to
PR_Sprintf) and the argument number of the format string. The variable
arguments (in ...) are assumed to be immediately after the format
argument.
2022-02-05 20:24:17 +09:00
Bill Currie f4b81d30b0 [qwaq] Pass the correct selector when listeners respond
This is actually an old bug in qwaq that was masked by v6p progs
parameter passing: it was just luck that event got put in the correct
parameter and not trampled until the responder saw it. Ruamoko progs,
however, simply lost the event entirely because it never got explicitly
passed by the listener implementation.
2022-02-05 19:30:08 +09:00
Bill Currie ab8692bd96 [qwaq] Allow return values through forwarded messages
This was easy to achieve in v6p progs because all return values passed
through .return and thus could not be lost. However, Ruamoko progs use a
return pointer which can wind up pointed into the void (the return
buffer) and thus cause the return value to be lost. Using @return on
obj_msg_sendv bounces the return pointer through to the called function.
In addition, nil is returned when the forwarding target is nil.
2022-02-05 19:30:08 +09:00
Bill Currie 6f4bb0df2c [qfcc] Update sendv test to use @return
The return value can't be checked in the test, but it was useful for
getting everything actually working.
2022-02-05 19:30:08 +09:00
Bill Currie 1fa3acf2d7 [ruamoko] Support return values in message forwarding
This is the libr side of the return pointer bouncing.
2022-02-05 19:30:08 +09:00
Bill Currie 1ce026d168 [qfcc] Implement bounced return pointer calls
This is achieved by marking a void function with the void_return
attribute and then calling that function in an @return expression.
@return can be used only inside a void function and only with void
functions marked with the void_return attribute. As this is intended for
Objective-QC message forwarding, it is deliberately "difficult" to use
as returning a larger than expected value is unlikely to end well for
the calling function.

However, as a convenience, "@return nil" is allowed (in a void
function). It always returns an integer (which, of course,can be
interpreted as a pointer). This is safe because if the return value is
ignored, it will go into the progs return buffer, and if it is not
ignored, it is the smallest value that can be returned.
2022-02-05 19:30:08 +09:00
Bill Currie 084c2ccb1f [qfcc] Make is_function_call a little more useful
It can (and must) be used one level higher as it checks that the
expression is a block and that its result expression is call branch
expression.
2022-02-05 19:30:08 +09:00
Bill Currie eee6744656 [qfcc] Use a function to apply function attributes
There are too may places where they need to be applied, so making them
all use a function will keep things manageable in the future.
2022-02-05 19:30:08 +09:00
Bill Currie 8cc6cbc157 [qfcc] Use a union to manage function attributes
Same idea as the specifiers, but makes checking function types are the
same much easier.
2022-02-05 19:30:08 +09:00
Bill Currie f153e87daa [qfcc] Use a union to manage specifier bits
Having to remember to copy yet another specifier bit was getting
tedious, so use a union of a struct with the bitfields and an unsigned
int to access them in parallel. Makes for a tidier spec_merge, and one
less headache.
2022-02-05 18:45:54 +09:00
Bill Currie 078f36a871 [gamecode] Add "return pointer" mode to with instruction
This loads the current return pointer into the specified register. No
offset is used (should make that an error, but for now any offset is
simply ignored). This is part of the fix for getting obj_msg_sendv to
work with return values.
2022-02-05 18:42:54 +09:00
Bill Currie 208cba85eb [gamecode] Move return buffer to end of progs memory map
With the return buffer in progs_t, it could not be addressed by the
progs on 64-bit machines (this was intentional, actually), but in order
to get obj_msg_sendv working properly, I needed a way to "bounce" the
return address of a calling function to the called function. The
cleanest solution I could think of was to add a mode to the with
instruction allowing the return pointer to be loaded into a register and
then calling the function with a 0 offset for the return value but using
the relevant register (next few commits). Testing promptly segfaulted
due to the 64-bit offset not fitting into a 32-bit value.
2022-02-05 18:37:23 +09:00
Bill Currie b0810958e7 [ruamoko] Use encoded selector param count when forwarding
This gets message forwarding apparently working, though something isn't
quite right as qwaq-app doesn't update properly when I try to step
through the program, but that could be an error elsewhere.
2022-02-05 14:24:12 +09:00
Bill Currie 9cf2740cb4 [gamecode] Create a globally accessible hash of type encodings
The plan is to use the types to extract the number of parameters for a
selector when it is necessary to know the count. However, it'll probably
become useful for something else alter (these things seem to always do
so).
2022-02-05 14:07:45 +09:00
Bill Currie 2c0969f988 [ruamoko] Rework method call hand-off to preserve the stack
This takes care of the problems with PR_RESET_PARAMS (which has recently
become just a wrapper for PR_SetupParams) changing the stack and causing
PR_CallFunction to save the wrong stack pointer. Message forwarding is
currently broken for Ruamoko ISA progs, but that is due to not having a
valid pr_argc. However, I do have a plan involving extracting the
parameter count from the selector, but that's something for a later
commit. Everything else seems to be ok (my little game is working
nicely).
2022-02-05 13:01:44 +09:00
Bill Currie 5500d835fe [qw] Fix a mangled builtin number
When doing the builtin params data change, I had somehow switch
multicast's number from 82 to 81. Fortunately, another builtin is also
81, so the VM told me off when I tried to run qw-server :)
2022-02-05 10:29:20 +09:00
Bill Currie 01345ba675 [gamecode] Wrap most uses of PR_RESET_PARAMS with push/pop frame
rua_obj was skipped because that looks to be a bit more work and should
be a separate commit.

This is to avoid the stack getting mangled when calling progs functions
with parameters.
2022-02-05 10:26:47 +09:00
Bill Currie 529253e6d9 [gamecode] Make edict macros more robust to null
A null edict pointer should product a null entity, not a segfault.
2022-02-05 10:17:57 +09:00
Bill Currie f94d5e9fdb [ruamoko] Correct decls for functions using PF_VarString
Need to ensure va_list gets into the arguments so PF_VarString can work
with Ruamoko progs.
2022-02-04 22:31:36 +09:00
Bill Currie 2fc35b39b0 [ruamoko] Use a shared implementation for set functions
I suppose having one builtin call another was a neat idea at the time,
and really could have been fixed by simply wrapping the calls with
push/pop frame, but this is probably faster.
2022-02-04 22:19:05 +09:00
Bill Currie 5f684b2f81 [ruamoko] Rework PF_VarString to work with Ruamoko progs
It's a rather core function used by the game code, though it is rather
horrid.
2022-02-04 22:15:24 +09:00
Bill Currie cdc3c9822d [ruamoko] Preserve the stack in obj_msg_sendv
obj_msg_sendv needs to push the parameters onto the stack for Ruamoko
progs, but this causes problems because PR_CallFunction winds up
recording the wrong stack pointer for progs functions, and nothing
restores the stack for builtins. The handling is basically the same as
for the return pointer.
2022-02-04 22:09:38 +09:00
Bill Currie b6a8a93cc3 [qfcc] Treat vectors and quaternions as non-scalars
Fixes a segfault when initializing vectors thai was caused by the
earlier block init fix.
2022-02-04 22:03:26 +09:00
Bill Currie 6988752dea [qfcc] Clean up line numbers in varargs setup
It's never nice getting the end-of-function line in the middle of some
code.
2022-02-04 22:02:05 +09:00
Bill Currie 24a42dc064 [qfcc] Emit args for ... functions with no other parameters
I missed that the block was < -1, ie at least one real parameters.
2022-02-04 22:00:18 +09:00
Bill Currie 1b40cdbab6 [qfcc] Handle vector scaling by ints
I missed a change when implementing support for the scale instructions.
2022-02-04 21:57:41 +09:00
Bill Currie 2a8fca80a0 [nq,qw] Give the menu and server progs stacks
They're going to need them :P
2022-02-04 21:53:37 +09:00
Bill Currie 7731c469e2 [gamecode] Count calls to builtins in profile
It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
2022-02-04 21:49:59 +09:00
Bill Currie 974af36d13 [gamecode] Move profile out of the union
It happens to sit over the builtin data pointer and thus messes up
PR_Profile (any attempt to count calls to builtins).
2022-02-04 21:46:40 +09:00
Bill Currie b425f449b6 [ruamoko] Separate the two str_mid builtins
pr_argc cannot be used in Ruamoko progs because nothing sets it. This
fixes the parse errors and resulting segfault when trying to parse the
Vulkan pipeline config.
2022-02-04 11:38:36 +09:00
Bill Currie 26fca581fc [qfcc] Make ruamoko the default and update the docs
It's time to do the dog-food.
2022-02-04 10:46:31 +09:00
Bill Currie f3770cc647 [qfcc] Add --ruamoko command line option and pragma
The command line option works the same way as
--advanced/traditional/extended, as does the pragma. As well, raumoko
(alternative spelling) can be used because both are legitimate and some
people may prefer one spelling over the other.

As always, use of the pragma is at one's own risk: its intended use is
forcing the target in the unit tests.
2022-02-04 09:27:07 +09:00
Bill Currie 52a399daeb [qfcc] Update sizes and alignments for dvec4 and friends
dvec4, lvec4 and ulvec4 need to be aligned to 8 words (32 bytes) in
order to avoid hardware exceptions. Rather than dealing with possibly
mixed alignment when a function has 8-word aligned locals but only
4-word aligned parameters, simply keep the stack frame 8-word aligned at
all times.

As for sizes, the temp def recycler was written before the Ruamoko ISA
was even a pipe dream and thus never expected temp def sizes over 4. At
least now any future adjustments can be done in one place.

My quick and dirty test program works :)

    dvec4 xy = {1d, 2d, 0d, 0.5};
    void printf(string fmt, ...) = #0;
    int main()
    {
	dvec4 u = {3, 4, 3.14};
	dvec4 v = {3, 4, 0, 1};
	dvec4 w = v * xy + u;
	printf ("[%g, %g, %g, %g]\n", w[0], w[1], w[2], w[3]);
	return 0;
    }
2022-02-04 08:46:58 +09:00
Bill Currie 1487fa6b50 [qfcc] Implement some basics for the vector types
They're now properly part of the type system and can be used for
declaring variables, initialized (using {} block initializers), operated
on (=, *, + tested) though much work needs to be done on binary
expressions, and indexed. So far, only ivec2 has been tested.
2022-02-04 00:25:31 +09:00
Bill Currie ca818eaff8 [qfcc] Ensure ops on globals occur before return
This fixes the return-postop test, and covers calls, too.
2022-02-03 16:40:53 +09:00
Bill Currie bbac02de24 [qfcc] Add failing test for return of postop
Commit 76b3bedb72 broke more than just the
swap test, but at least I know I need to get an edge in the dag.
Currently, the following code is generated: return and add are reversed.

    ../tools/qfcc/test/return-postop.r:8:   return counter++;
    0001 store.i counter, .tmp0
    0002 return .tmp0
    0003 add.i .tmp0, (1), counter

However, I don't want to deal with it right now, so it's marked XFAIL.
2022-02-03 16:40:53 +09:00
Bill Currie 3d8ee5df43 [qfcc] Ensure ops on globals occur before return
This fixes the return-postop test, and covers calls, too.
2022-02-03 16:33:42 +09:00
Bill Currie a3c37201b2 [qfcc] Emit constant pointers as direct def references
When possible, of course. However, this tightens up struct and constant
index array accesses, and avoids issues with flow analysis losing track
of the def (such trucking is something I want to do, but haven't decided
out to get the information out to the right statements).
2022-02-03 14:41:46 +09:00
Bill Currie 008359862b [qfcc] Avoid pointer alias of address expressions
Since address expressions always product a pointer type, aliasing one to
another pointer type is redundant. Instead, simply return an address
expression with the desired type.
2022-02-03 14:38:26 +09:00
Bill Currie 80c6431544 [qfcc] Clear up a FIXME
The FIXME was there because I couldn't remember why the test was
type_compatible but the internal error complains about the types being
the same size. The compatibility check is to see if the op can be used
directly or whether a temp is required. The offset check is because
types that are the same size (which they must be if they are
compatible) is because it is not possible to create an offset alias def
that escapes the bounds of the real def, which any non-zero offset will
do if the types are the same size.
2022-02-03 14:15:20 +09:00
Bill Currie 6f49b919ec [qfcc] Move constant pointer offset into address expr
This is the intended purpose of the offset field in address expressions,
and will make struct and array accesses more efficient when I sort out
the code generation side.
2022-02-03 10:55:37 +09:00
Bill Currie b668759b7d [qfcc] Add a very basic attribute system
Ruamoko passes va_list (@args) through the ... parameter (as such), but
IMP uses ... to defeat parameter type and count checking and doesn't
want va_list. While possibly not the best solution, adding a no_va_list
flag to function types and skipping ex_args entirely does take care of
the problem without hard-coding anything specific to IMP.

The system currently just sets some bits in the type specifier (the
attribute list should probably be carried around with the specifier),
but it gets the job done for now, and at least gets things started.
2022-02-02 23:51:37 +09:00
Bill Currie 6fe72b0420 [qfcc] Check load/store operand type before mangling
This fixes the incorrect use of assign64 for quaternions. All tests
except return-postop pass \o/.
2022-02-02 19:14:22 +09:00
Bill Currie 0fa9d0d256 [qfcc] Tweak the printf to make more sense
Though I'm sure I had a good reason at the time, seeing 6.98487e-315
when expecting pi is a bit disconcerting.
2022-02-02 19:04:43 +09:00
Bill Currie a64f91129f [qfcc] Give lea its own statement type
This makes it much easier to check (and more robust to name changes),
allowing for effectively killing the node to which the variable being
addressed is attached. This fixes the incorrect address being used for
va_list, which is what caused double-alias to fail.
2022-02-02 18:55:01 +09:00