BitPatty / gct-generator

A gecko code practice file generator for everyone's favorite game: Super Mario Sunshine

Home Page:https://gct.zint.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

drawText parameters as struct

QbeRoot opened this issue · comments

Is your request related to a problem? Please describe

drawText currently takes 5 "visual" parameters, then a format string, then varargs to be inserted into the text. Per the PowerPC ABI, only registers r3-r10 can be used for non-float function arguments, and with the fixed arguments taking up r3-r8, that only leaves r9 and r10 for varargs. QFT only needs 3 varargs (minutes, seconds and milliseconds) but already has to set up a stack frame for the last one.

Describe the solution you'd like

Since the first 5 parameters are configured on the site then constant in the downloaded file, I think it would make sense to store them in RAM and have the caller simply pass a pointer to its settings struct. It would also make it easy to tweak those settings live in a RAM editor or an eventual built-in settings screen. The format string is much more related to the varargs so it would make sense to keep it as a separate argument imo

Describe alternatives you've considered

No response

Additional context

No response

Yeah, that makes sense. I implemented one with the following definition:

typedef struct {
  int16_t x;
  int16_t y;
  uint32_t fontSize;
  uint32_t colorTop;
  uint32_t colorBot;
} DrawTextOpt;

void drawText(DrawTextOpt *opt, const char *fmt, ...);

With the new definition, we can print at most 6 integers (r5~r10) and 8 floats (f1~f8) without setting up a stack.
The C source code can be found here, and the size-optimized assembly code based on GCC's output can be found here.

The reason I choose int16_t instead of int32_t for x and y is that we can use paired single instructions to load int8 and int16 from RAM to FPRs directly, which reduces the code size a lot. With the paired single instructions, I managed to implement the new version without increasing the code size.