clean up and format code

This commit is contained in:
SwareJonge
2025-06-17 23:46:35 +02:00
parent c5e5f47880
commit c545a42c15
93 changed files with 7033 additions and 7909 deletions
+44 -70
View File
@@ -3,15 +3,13 @@
#include "MSL_C/printf.h"
#include "JSystem/JUtility/JUTDirectPrint.h"
JUTDirectPrint *JUTDirectPrint::sDirectPrint;
JUTDirectPrint* JUTDirectPrint::sDirectPrint;
JUTDirectPrint::JUTDirectPrint()
{
JUTDirectPrint::JUTDirectPrint() {
changeFrameBuffer(nullptr, 0, 0);
}
JUTDirectPrint *JUTDirectPrint::start()
{
JUTDirectPrint* JUTDirectPrint::start() {
if (!sDirectPrint) {
sDirectPrint = new JUTDirectPrint();
}
@@ -19,29 +17,24 @@ JUTDirectPrint *JUTDirectPrint::start()
return sDirectPrint;
}
void JUTDirectPrint::erase(int x, int y, int width, int height)
{
void JUTDirectPrint::erase(int x, int y, int width, int height) {
if (!mFramebuffer) {
return;
}
if (400 < mFbWidth)
{
if (400 < mFbWidth) {
x = x << 1;
width = width << 1;
}
if (300 < mFbHeight)
{
if (300 < mFbHeight) {
y = y << 1;
height = height << 1;
}
u16 *pixel = mFrameMemory + mStride * y + x;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
u16* pixel = mFrameMemory + mStride * y + x;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
*pixel = 0x1080;
pixel = pixel + 1;
}
@@ -51,14 +44,13 @@ void JUTDirectPrint::erase(int x, int y, int width, int height)
}
u8 JUTDirectPrint::sAsciiTable[128] = {
0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0xFD, 0xFE, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x29, 0x64, 0x65, 0x66, 0x2B, 0x67, 0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E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D,
0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x76, 0x77, 0x78, 0x79, 0x7A,
};
u32 JUTDirectPrint::sFontData[64] = {
@@ -73,15 +65,14 @@ u32 JUTDirectPrint::sFontData[64] = {
};
u32 JUTDirectPrint::sFontData2[77] = {
0x51421820, 0x53E7A420, 0x014A2C40, 0x01471000, 0x0142AA00, 0x03EAA400, 0x01471A78, 0x00000000,
0x50008010, 0x20010820, 0xF8020040, 0x20420820, 0x50441010, 0x00880000, 0x00070E00, 0x01088840,
0x78898820, 0x004A8810, 0x788A8810, 0x01098808, 0x00040E04, 0x70800620, 0x11400820, 0x12200820,
0x10001020, 0x10000820, 0x100F8820, 0x70000620, 0x60070000, 0x110F82A0, 0x12AA8AE0, 0x084F92A0,
0x100FBE1C, 0x10089008, 0x60070808, 0x00000000, 0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8,
0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000, 0x422F1830, 0xFBE88810, 0x40288890,
0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288, 0xA10AA288, 0x98CAA270,
0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38, 0x00000000,
0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000,
0x51421820, 0x53E7A420, 0x014A2C40, 0x01471000, 0x0142AA00, 0x03EAA400, 0x01471A78, 0x00000000, 0x50008010,
0x20010820, 0xF8020040, 0x20420820, 0x50441010, 0x00880000, 0x00070E00, 0x01088840, 0x78898820, 0x004A8810,
0x788A8810, 0x01098808, 0x00040E04, 0x70800620, 0x11400820, 0x12200820, 0x10001020, 0x10000820, 0x100F8820,
0x70000620, 0x60070000, 0x110F82A0, 0x12AA8AE0, 0x084F92A0, 0x100FBE1C, 0x10089008, 0x60070808, 0x00000000,
0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8, 0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000,
0x422F1830, 0xFBE88810, 0x40288890, 0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288,
0xA10AA288, 0x98CAA270, 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38,
0x00000000, 0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000,
0xF8000000, 0x10000000, 0x20000000, 0x40000000, 0xF8000000,
};
@@ -90,12 +81,12 @@ void JUTDirectPrint::drawChar(int position_x, int position_y, int ch) {
int col_index = (codepoint % 5) * 6;
int row_index = (codepoint / 5) * 7;
const u32 *font_data = (100 > ch) ? sFontData + row_index : sFontData2 + row_index;
const u32* font_data = (100 > ch) ? sFontData + row_index : sFontData2 + row_index;
int scale_x = (mFbWidth < 400) ? 1 : 2;
int scale_y = (mFbHeight < 300) ? 1 : 2;
u16 *pixel = mFrameMemory + mStride * position_y * scale_y + position_x * scale_x;
u16* pixel = mFrameMemory + mStride * position_y * scale_y + position_x * scale_x;
for (int y = 0; y < 7; y++) {
u32 data = *font_data << col_index;
font_data += 1;
@@ -119,52 +110,40 @@ void JUTDirectPrint::drawChar(int position_x, int position_y, int ch) {
}
}
void JUTDirectPrint::changeFrameBuffer(void *fb, u16 width, u16 height)
{
void JUTDirectPrint::changeFrameBuffer(void* fb, u16 width, u16 height) {
mFramebuffer = fb;
mFrameMemory = (u16 *)fb;
mFrameMemory = (u16*)fb;
mFbWidth = width;
mFbHeight = height;
mStride = ALIGN_NEXT((u16)width, 16);
mFbSize = (u32)mStride * (u32)mFbHeight * 2;
}
void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char *format, va_list args, bool clear)
{
void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char* format, va_list args, bool clear) {
char buffer[256];
if (!mFrameMemory)
{
if (!mFrameMemory) {
return;
}
int buffer_length = vsnprintf(buffer, sizeof(buffer), format, args);
u16 x = position_x;
if (buffer_length > 0)
{
if (clear)
{
if (buffer_length > 0) {
if (clear) {
erase(position_x - 6, position_y - 3, (buffer_length + 2) * 6, 0xd);
}
char *ptr = buffer;
for (; 0 < buffer_length; buffer_length--, ptr++)
{
char* ptr = buffer;
for (; 0 < buffer_length; buffer_length--, ptr++) {
int codepoint = sAsciiTable[*ptr & 0x7f];
if (codepoint == 0xfe)
{
if (codepoint == 0xfe) {
position_x = x;
position_y += 7;
}
else if (codepoint == 0xfd)
{
} else if (codepoint == 0xfd) {
s32 current_position = (int)position_x;
s32 tab = (current_position - x + 0x2f) % 0x30;
position_x = current_position + 0x30 - tab;
}
else
{
if (codepoint != 0xff)
{
} else {
if (codepoint != 0xff) {
drawChar(position_x, position_y, codepoint);
}
position_x += 6;
@@ -175,10 +154,8 @@ void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char *format
DCFlushRange(mFrameMemory, mFbSize);
}
void JUTDirectPrint::print(u16 position_x, u16 position_y, char const *format, ...)
{
if (mFrameMemory)
{
void JUTDirectPrint::print(u16 position_x, u16 position_y, char const* format, ...) {
if (mFrameMemory) {
va_list args;
va_start(args, format);
printSub(position_x, position_y, format, args, true);
@@ -186,18 +163,15 @@ void JUTDirectPrint::print(u16 position_x, u16 position_y, char const *format, .
}
}
void JUTDirectPrint::drawString(u16 position_x, u16 position_y, char *text)
{
void JUTDirectPrint::drawString(u16 position_x, u16 position_y, char* text) {
drawString_f(position_x, position_y, "%s", text);
}
void JUTDirectPrint::drawString_f(u16 position_x, u16 position_y, char const *format, ...)
{
if (mFrameMemory)
{
void JUTDirectPrint::drawString_f(u16 position_x, u16 position_y, char const* format, ...) {
if (mFrameMemory) {
va_list args;
va_start(args, format);
printSub(position_x, position_y, format, args, false);
va_end(args);
}
}
}