Found at 80012360
Summary
Function that adds cd commands to the command queue for later execution. It handles all commands accepted by CdControl along with their arguments as well as a custom command used to setup the callback and execute a read. After a command is added it increments the enqueue index to point to the next free slot in the queue.
Behavior
When entering the function increment the enqueue index incremented by 1 locally. This points to where the next command will go in the buffer. Then normalize the incremented index meaning we make sure it stays between 0 and 15. Check if adding a command would make it look like the queue is empty, if it will, make space by executing a command in a loop which will only exit when execution is successful.
Start filling out the command queue entry first by populating the command member. Then if no arguments were passed to the function because the command takes no args, set the args_ptr member to NULL. Otherwise copy the address of where the arg is in this queue entry into the args_ptr member and following this copy the first four bytes of the CdArg union into the args member. This covers mode, filter or location cd command arguments.
Check if the command is a CdLdReadN, if it is this means that the union is taking the shape of a CdLdFile which means there are two other members that need to be copied, these members are used for setting up the callback. Finish copying the remaining members which are the load address and size of file in sector count.
Finish copying the remaining parameters in to the queue entry which are the result buffer ptr and and command executed ptr which I believe is a pointer for variable that tracks if the command was executed.
Increment the enqueue index locally again, normalize the value and assign that value to be the global enqueue index. Continue by doing a NULL check on the last parameter and if it wasnt null dereference that pointer to assign it a value of 0. Finally if the CD is idle set it to ready.
Notes
- The queue is empty when exec and enqueue index are equal in value.
- To see how the CdLdFile is used as arguments for a command see cdlib_execute_cmd and cdlib_ready_callback
Unknowns
- That last parameter which is assigned to the command executed member is always NULL in all the calls to this function hence i believe the command executed member is a leftover member for debugging.
Function Signature
Parameters: 4
cmd: the op code that corresponds to a cd command args: pointer to the arguments that a command requires returnValueBufferPtr: pointer to the return value buffer cmdExecutedPtr: pointer to a command executed flag
Returns
Always 1