Skip to content

Commit 0cedaca

Browse files
committed
Merge pull request #64 from carrdylan52/pr/game-text-20261006
2 parents 2927543 + 2f6515a commit 0cedaca

5 files changed

Lines changed: 661 additions & 1 deletion

File tree

‎docs/PC.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,46 @@ retail's 0x136A7-byte image. `sce/sifdev.cpp` implements `sceOpen`,
819819
device prefix stripped (the debug dump `edit.cpp` writes to `host0:`), and
820820
`WriteFile` writes there too.
821821

822+
## Game text
823+
824+
`port/src/gametext.cpp` writes the port's own text in the game's message
825+
font, so menus the port adds can match the game's. A message is an s16 code
826+
per character ending in `MES_CODE_END` (-0xFF); a space is
827+
`MES_CODE_SPACE` (-0xFE) and a line break `MES_CODE_NEWLINE` (-0x100). The
828+
PAL font draws only the external characters from -0x300: -0x300 to -0x2E0
829+
are the pad buttons and icons; -0x2DF to -0x288 are the 88 cells of
830+
`gaiji.img`'s letter grid in order (`A`-`Z`, `a`-`z`,
831+
`'="!?#&+-*/%()@|<>{}[]:,.$` and `0`-`9`); -0x287 to -0x254 are `œ ¡ ¿ ß Œ
832+
Ç ç` and the letters `DrawGaijiFont` draws an accent over (`ÀÁÂÄÈÉÊËÌÍÎÏÑ
833+
ÒÓÔÖÙÚÛÜàáâäèéêëìíîïñòóôöùúûü`). -0x263 to -0x261, -0x253 and -0x252
834+
draw a bare `?`. There is no `;`, `_`, `~`, `^`, backquote or backslash.
835+
The table was read off the `gaiji.img` of every `meswin/mes_tex_N.pak` (all
836+
seven draw these characters in the same cells; only the pixels differ) and
837+
checked by decoding every `.mes` on the disc: each language uses only
838+
characters in it, and its own accents only.
839+
840+
`GameTextEncode` turns UTF-8 into codes. Curly quotes and dashes become the
841+
font's own; any other character the font lacks, and any byte that is not
842+
UTF-8, becomes `?` and is counted. `{N}` writes code N as it is, for control
843+
codes and icons, and `{{` a `{`; `GameTextDecode` writes the same form, so
844+
any message reads back and encodes to the same codes. `GameTextFile` lays
845+
texts out as a message file for `ClsMes::SetBuff`. `GameText` is one piece of
846+
text drawn as the menus draw their help line (`InitMenuMesSet`'s
847+
`CommonMenuMes2`: the menu font, white with a black edge, shown whole): `Set`
848+
the text, `SetColour` a `FontColor`, then `Draw(x, y, alpha)` from a menu's
849+
draw function; `Width` gives its width for aligning a value.
850+
851+
Both have retail's fixed sizes. A window lays out at most `MES_WIN_LINE_MAX`
852+
(720) characters, counting the end and what a `{N}` name, value or system
853+
message code expands to; retail's `SetMesWinTbl` writes on past the table, so
854+
the port's (`port/src/clsmes.cpp`) takes no more, and `GameText::Set` gives back
855+
-1, draws nothing and has a width of 0 for a text that did not fit. A line past
856+
the window's ten `line_pos` entries draws in the block layout, as a line
857+
without one does. A message file is s16 throughout: an id is -0x8000 to
858+
0x7FFF. Every message must start within 0x7FFF codes of `&buff[1 + count]`;
859+
the last message by id may extend beyond that range. `GameTextFile::Set`
860+
gives back -1 and leaves the file as it was where either would not hold.
861+
822862
## Arenas
823863

824864
`CDataAlloc2<1>::Alloc/Alloc64/Align64` and the carving in

‎port/src/clsmes.cpp‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <array>
55
#include <cmath>
6+
#include <iterator>
67
#include <vector>
78

89
#include "draw2d_port.hpp"
@@ -457,6 +458,54 @@ PC_OVERRIDE void ClsMes::MakeFukidashi(sceVif1Packet *packet) {
457458
services.set_alpha(nullptr);
458459
}
459460

461+
// Keep the message layout within the fixed character table.
462+
PC_OVERRIDE int ClsMes::SetMesWinTbl(int code, int mode, short x, short y) {
463+
if (code >= -0x200 && code <= -0x101) {
464+
if (this->win_line_num > 0) {
465+
this->win_line[this->win_line_num - 1].space += code + 0x200;
466+
}
467+
468+
return 0;
469+
}
470+
471+
if (code >= -0x400 && code <= -0x301) {
472+
if (code + 0x400 == 0) {
473+
this->clut_now = this->clut_default;
474+
} else if (code == -0x301) {
475+
this->clut_now = 0xFF;
476+
} else {
477+
this->clut_now = code + 0x401;
478+
}
479+
480+
return 0;
481+
}
482+
483+
if (code >= -0xA00 && code <= -0x901) {
484+
this->fukidashi_shape = code + 0xA00;
485+
return 0;
486+
}
487+
488+
if (this->win_line_num >= MES_WIN_LINE_MAX) {
489+
return 0;
490+
}
491+
492+
if (mode == 1) {
493+
this->win_line[this->win_line_num].code = code + 0x1000;
494+
this->win_line[this->win_line_num].x = x;
495+
this->win_line[this->win_line_num].y = y;
496+
this->win_line[this->win_line_num].clut = this->clut_now;
497+
this->win_line_num++;
498+
} else {
499+
this->win_line[this->win_line_num].code = code;
500+
this->win_line[this->win_line_num].x = x;
501+
this->win_line[this->win_line_num].y = y;
502+
this->win_line[this->win_line_num].clut = this->clut_now;
503+
this->win_line_num++;
504+
}
505+
506+
return 1;
507+
}
508+
460509
PC_OVERRIDE void ClsMes::DrawMesWin() {
461510
CTexture *texture;
462511
int offset_x;
@@ -599,7 +648,8 @@ PC_OVERRIDE void ClsMes::DrawMesWin() {
599648

600649
int row = this->win_line[index].y / this->char_height;
601650

602-
if (this->line_pos[row].x < 0 || this->line_pos[row].y < 0) {
651+
if (row >= static_cast<int>(std::size(this->line_pos)) || this->line_pos[row].x < 0 ||
652+
this->line_pos[row].y < 0) {
603653
int line_x = this->win_line[index].x + this->text_x;
604654
int line_y = this->win_line[index].y + this->text_y;
605655
int screen_x = offset_x + (line_x + dx);

0 commit comments

Comments
 (0)