mirror of
https://github.com/SwareJonge/mkdd.git
synced 2025-03-02 01:58:42 +00:00
JUTConsole WIP
This commit is contained in:
parent
6863fc60ce
commit
fc68b0bbbc
@ -141,7 +141,7 @@ namespace JGadget
|
||||
void Push_back(T *element)
|
||||
{
|
||||
TLinkList::iterator iter(TLinkList::end());
|
||||
this->Insert(iter, element);
|
||||
Insert(iter, element);
|
||||
}
|
||||
|
||||
// _00-_08 = TNodeLinkList
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _JUTCONSOLE_H
|
||||
#define _JUTCONSOLE_H
|
||||
|
||||
#include <dolphin/stl.h>
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
#include "JSystem/JUtility/JUTFont.h"
|
||||
#include "JSystem/JGadget/linklist.h"
|
||||
@ -24,29 +25,30 @@ public:
|
||||
{
|
||||
/* 0x0 */ OUTPUT_NONE,
|
||||
/* 0x1 */ OUTPUT_OSREPORT,
|
||||
/* 0x2 */ OUTPUT_CONSOLE
|
||||
/* 0x2 */ OUTPUT_CONSOLE,
|
||||
/* 0x3 */ OUTPUT_OSR_AND_CONSOLE,
|
||||
};
|
||||
|
||||
virtual ~JUTConsole(); // _08
|
||||
|
||||
// _00 VTBL
|
||||
|
||||
static JUTConsole *create(unsigned int, unsigned int, JKRHeap *);
|
||||
static JUTConsole *create(unsigned int, void *, u32);
|
||||
static JUTConsole *create(uint, uint, JKRHeap *);
|
||||
static JUTConsole *create(uint, void *, u32);
|
||||
static void destroy(JUTConsole *); // UNUSED
|
||||
JUTConsole(unsigned int, unsigned int, bool);
|
||||
JUTConsole(uint, uint, bool);
|
||||
static size_t getObjectSizeFromBufferSize(uint, uint);
|
||||
static size_t getLineFromObjectSize(u32, uint);
|
||||
void clear();
|
||||
void doDraw(JUTConsole::EConsoleType) const;
|
||||
void print_f(char const *, ...);
|
||||
void print(char const *);
|
||||
void dumpToTerminal(unsigned int);
|
||||
void dumpToTerminal(uint);
|
||||
void scroll(int);
|
||||
int getUsedLine() const;
|
||||
int getLineOffset() const;
|
||||
|
||||
void setOutput(unsigned int output) { mOutput = output; }
|
||||
void setOutput(uint output) { mOutput = output; }
|
||||
void setPosition(int x, int y)
|
||||
{
|
||||
mPositionX = x;
|
||||
@ -60,9 +62,9 @@ public:
|
||||
void setHeight(u32 height)
|
||||
{
|
||||
mHeight = height;
|
||||
if (mHeight > field_0x24)
|
||||
if (mHeight > mMaxLines)
|
||||
{
|
||||
mHeight = field_0x24;
|
||||
mHeight = mMaxLines;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,8 +79,8 @@ public:
|
||||
int getPositionX() const { return mPositionX; }
|
||||
u32 getHeight() const { return mHeight; }
|
||||
|
||||
bool isVisible() const { return mVisible; }
|
||||
void setVisible(bool visible) { mVisible = visible; }
|
||||
bool isVisible() const { return mIsVisible; }
|
||||
void setVisible(bool visible) { mIsVisible = visible; }
|
||||
|
||||
void setLineAttr(int param_0, u8 param_1) { mBuf[(field_0x20 + 2) * param_0] = param_1; }
|
||||
u8 *getLinePtr(int param_0) const { return &mBuf[(field_0x20 + 2) * param_0] + 1; }
|
||||
@ -89,18 +91,18 @@ public:
|
||||
{
|
||||
return diff;
|
||||
}
|
||||
return diff += field_0x24;
|
||||
return diff += mMaxLines;
|
||||
}
|
||||
|
||||
void scrollToLastLine() { scroll(field_0x24); }
|
||||
void scrollToFirstLine() { scroll(-field_0x24); }
|
||||
void scrollToLastLine() { scroll(mMaxLines); }
|
||||
void scrollToFirstLine() { scroll(-mMaxLines); }
|
||||
|
||||
private:
|
||||
JGadget::TLinkListNode mListNode; // _18
|
||||
|
||||
private:
|
||||
/* 0x20 */ u32 field_0x20;
|
||||
/* 0x24 */ u32 field_0x24;
|
||||
/* 0x24 */ u32 mMaxLines;
|
||||
/* 0x28 */ u8 *mBuf;
|
||||
/* 0x2C */ bool field_0x2c;
|
||||
/* 0x30 */ int field_0x30;
|
||||
@ -113,11 +115,11 @@ private:
|
||||
/* 0x4C */ JUTFont *mFont;
|
||||
/* 0x50 */ f32 mFontSizeX;
|
||||
/* 0x54 */ f32 mFontSizeY;
|
||||
/* 0x58 */ int mOutput;
|
||||
/* 0x58 */ uint mOutput;
|
||||
/* 0x5C */ JUtility::TColor field_0x5c;
|
||||
/* 0x60 */ JUtility::TColor field_0x60;
|
||||
/* 0x64 */ int field_0x64;
|
||||
/* 0x68 */ bool mVisible;
|
||||
/* 0x68 */ bool mIsVisible;
|
||||
/* 0x69 */ bool field_0x69;
|
||||
/* 0x6A */ bool field_0x6a;
|
||||
/* 0x6B */ bool field_0x6b;
|
||||
@ -128,8 +130,8 @@ class JUTConsoleManager
|
||||
public:
|
||||
JUTConsoleManager();
|
||||
static JUTConsoleManager *createManager(JKRHeap *);
|
||||
void appendConsole(JUTConsole *);
|
||||
void removeConsole(JUTConsole *);
|
||||
void appendConsole(JUTConsole *console);
|
||||
void removeConsole(JUTConsole *console);
|
||||
void draw() const;
|
||||
void drawDirect(bool) const;
|
||||
void setDirectConsole(JUTConsole *);
|
||||
@ -139,21 +141,27 @@ public:
|
||||
static JUTConsoleManager *sManager;
|
||||
|
||||
private:
|
||||
JGadget::TLinkList<JUTConsole, 4> mLinkList; // _00
|
||||
JGadget::TLinkList<JUTConsole, 4> soLink_; // _00
|
||||
JUTConsole *mActiveConsole; // _0C
|
||||
JUTConsole *mDirectConsole; // _10
|
||||
}; // Size: 0x14
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JUTConsole *JUTGetReportConsole();
|
||||
void JUTSetReportConsole(JUTConsole *);
|
||||
JUTConsole *JUTGetWarningConsole();
|
||||
void JUTSetWarningConsole(JUTConsole *);
|
||||
void JUTReportConsole(char const *);
|
||||
void JUTReportConsole_f(char const *, ...);
|
||||
void JUTWarningConsole(const char*);
|
||||
void JUTWarningConsole_f(const char *, ...);
|
||||
}
|
||||
#ifdef __cplusplus // not sure if this is needed, if it is, maybe recast JUTConsole to void * or forward declaration
|
||||
extern "C" {
|
||||
#endif
|
||||
void JUTConsole_print_f_va_(JUTConsole *, const char *, va_list);
|
||||
|
||||
JUTConsole *JUTGetReportConsole();
|
||||
void JUTSetReportConsole(JUTConsole *);
|
||||
JUTConsole *JUTGetWarningConsole();
|
||||
void JUTSetWarningConsole(JUTConsole *);
|
||||
void JUTReportConsole(const char *);
|
||||
void JUTReportConsole_f(const char *, ...);
|
||||
void JUTReportConsole_f_va(const char *, va_list);
|
||||
void JUTWarningConsole(const char*);
|
||||
void JUTWarningConsole_f(const char *, ...);
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif // ifdef __cplusplus
|
||||
|
||||
#endif
|
233
src/JSystem/JUtility/JUTConsole.cpp
Normal file
233
src/JSystem/JUtility/JUTConsole.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
#include <dolphin/os.h>
|
||||
#include <dolphin/vi.h>
|
||||
#include <JSystem/JUtility/JUTConsole.h>
|
||||
#include <JSystem/JUtility/JUTDbg.h>
|
||||
|
||||
// WIP
|
||||
|
||||
#define OUTPUT_NONE 0
|
||||
#define OUTPUT_OSREPORT 1
|
||||
#define OUTPUT_CONSOLE 2
|
||||
#define OUTPUT_ALL OUTPUT_OSREPORT | OUTPUT_CONSOLE
|
||||
|
||||
JUTConsoleManager *JUTConsoleManager::sManager;
|
||||
|
||||
JUTConsole *JUTConsole::create(uint param_0, uint maxLines, JKRHeap *pHeap)
|
||||
{
|
||||
JUTConsoleManager *pManager = JUTConsoleManager::sManager;
|
||||
|
||||
u8 *buffer = (u8 *)JKRHeap::alloc(getObjectSizeFromBufferSize(param_0, maxLines), 0, pHeap);
|
||||
|
||||
JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, true);
|
||||
newConsole->mBuf = buffer + sizeof(JUTConsole);
|
||||
newConsole->clear();
|
||||
|
||||
pManager->appendConsole(newConsole);
|
||||
return newConsole;
|
||||
}
|
||||
|
||||
JUTConsole *JUTConsole::create(uint param_0, void *buffer, u32 bufferSize)
|
||||
{
|
||||
JUTConsoleManager *pManager = JUTConsoleManager::sManager;
|
||||
u32 maxLines = getLineFromObjectSize(bufferSize, param_0);
|
||||
|
||||
JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, false);
|
||||
newConsole->mBuf = (u8 *)buffer + sizeof(JUTConsole);
|
||||
newConsole->clear();
|
||||
|
||||
pManager->appendConsole(newConsole);
|
||||
return newConsole;
|
||||
}
|
||||
|
||||
void JUTConsole::print_f(char const *text, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
JUTConsole_print_f_va_(this, text, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void JUTConsole_print_f_va_(JUTConsole *console, const char *text, va_list args)
|
||||
{
|
||||
char buf[1024];
|
||||
JUT_ASSERT(563, console!=0);
|
||||
vsnprintf(buf, sizeof(buf), text, args);
|
||||
console->print(buf);
|
||||
}
|
||||
|
||||
void JUTConsole::scroll(int scrollAmnt)
|
||||
{
|
||||
if (scrollAmnt < 0)
|
||||
{
|
||||
int diff = diffIndex(field_0x34, field_0x30);
|
||||
if (scrollAmnt < -diff)
|
||||
{
|
||||
scrollAmnt = -diff;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scrollAmnt > 0)
|
||||
{
|
||||
int diff = diffIndex(field_0x34, field_0x38);
|
||||
if (diff + 1 <= mHeight)
|
||||
{
|
||||
scrollAmnt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = diffIndex(field_0x30, field_0x38);
|
||||
if (scrollAmnt > (int)(diff - mHeight) + 1)
|
||||
{
|
||||
scrollAmnt = (int)(diff - mHeight) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
field_0x30 += scrollAmnt;
|
||||
if (field_0x30 < 0)
|
||||
{
|
||||
field_0x30 += mMaxLines;
|
||||
}
|
||||
|
||||
if (field_0x30 >= mMaxLines)
|
||||
{
|
||||
field_0x30 -= mMaxLines;
|
||||
}
|
||||
}
|
||||
|
||||
int JUTConsole::getUsedLine() const
|
||||
{
|
||||
return diffIndex(field_0x34, field_0x38);
|
||||
}
|
||||
|
||||
int JUTConsole::getLineOffset() const
|
||||
{
|
||||
return diffIndex(field_0x34, field_0x30);
|
||||
}
|
||||
|
||||
JUTConsoleManager::JUTConsoleManager()
|
||||
{
|
||||
mActiveConsole = nullptr;
|
||||
mDirectConsole = nullptr;
|
||||
}
|
||||
|
||||
JUTConsoleManager *JUTConsoleManager::createManager(JKRHeap *pHeap)
|
||||
{
|
||||
JUT_ASSERT(924, sManager == 0);
|
||||
if (pHeap == nullptr)
|
||||
{
|
||||
pHeap = JKRGetCurrentHeap();
|
||||
}
|
||||
return sManager = new (pHeap, 0) JUTConsoleManager();
|
||||
}
|
||||
|
||||
void JUTConsoleManager::appendConsole(JUTConsole *console)
|
||||
{
|
||||
JUT_ASSERT(961, sManager != 0 && console != 0);
|
||||
// maybe local soLink_
|
||||
JUT_ASSERT(964, soLink_.Find( console ) == soLink_.end());
|
||||
soLink_.Push_back(console);
|
||||
if (mActiveConsole == nullptr)
|
||||
{
|
||||
mActiveConsole = console;
|
||||
}
|
||||
}
|
||||
|
||||
void JUTConsoleManager::drawDirect(bool waitRetrace) const {
|
||||
if(mDirectConsole != nullptr) {
|
||||
if(waitRetrace) {
|
||||
BOOL interrupt = OSEnableInterrupts();
|
||||
u32 retrace_count = VIGetRetraceCount();
|
||||
u32 new_count;
|
||||
do
|
||||
{
|
||||
new_count = VIGetRetraceCount();
|
||||
} while (retrace_count == new_count);
|
||||
OSRestoreInterrupts(interrupt);
|
||||
}
|
||||
mDirectConsole->doDraw(JUTConsole::UNK_TYPE2);
|
||||
}
|
||||
}
|
||||
|
||||
void JUTConsoleManager::setDirectConsole(JUTConsole *console) {
|
||||
if (mDirectConsole != nullptr) {
|
||||
appendConsole(mDirectConsole);
|
||||
}
|
||||
if(console != nullptr) {
|
||||
removeConsole(console);
|
||||
}
|
||||
mDirectConsole = console;
|
||||
}
|
||||
|
||||
static JUTConsole *sReportConsole;
|
||||
static JUTConsole *sWarningConsole;
|
||||
|
||||
// C Functions
|
||||
void JUTSetReportConsole(JUTConsole *console) {
|
||||
sReportConsole = console;
|
||||
}
|
||||
|
||||
JUTConsole *JUTGetReportConsole() {
|
||||
return sReportConsole;
|
||||
}
|
||||
|
||||
void JUTSetWarningConsole(JUTConsole *console) {
|
||||
sWarningConsole = console;
|
||||
}
|
||||
|
||||
JUTConsole *JUTGetWarningConsole() {
|
||||
return sWarningConsole;
|
||||
}
|
||||
|
||||
void JUTReportConsole_f_va(const char *text, va_list args) {
|
||||
char buf[256];
|
||||
if(JUTGetReportConsole() == NULL) {
|
||||
vsnprintf(buf, sizeof(buf), text, args);
|
||||
OSReport("%s", buf);
|
||||
}
|
||||
else if (JUTGetReportConsole()->getOutput() & OUTPUT_ALL) {
|
||||
vsnprintf(buf, sizeof(buf), text, args);
|
||||
JUTGetReportConsole()->print(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void JUTReportConsole_f(const char *text, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, text);
|
||||
JUTReportConsole_f_va(text, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void JUTReportConsole(const char *text) {
|
||||
JUTReportConsole_f("%s", text);
|
||||
}
|
||||
|
||||
void JUTWarningConsole_f_va(const char *text, va_list args)
|
||||
{
|
||||
char buf[256];
|
||||
if (JUTGetWarningConsole() == NULL)
|
||||
{
|
||||
vsnprintf(buf, sizeof(buf), text, args);
|
||||
OSReport("%s", buf);
|
||||
}
|
||||
else if (JUTGetWarningConsole()->getOutput() & OUTPUT_ALL)
|
||||
{
|
||||
vsnprintf(buf, sizeof(buf), text, args);
|
||||
JUTGetWarningConsole()->print(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void JUTWarningConsole_f(const char *text, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, text);
|
||||
JUTWarningConsole_f_va(text, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void JUTWarningConsole(const char *text) {
|
||||
JUTWarningConsole_f("%s", text);
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
#include "types.h"
|
||||
#include "dolphin/os.h"
|
||||
#include "dolphin/PPCArch.h"
|
||||
#include <dolphin/os.h>
|
||||
#include <dolphin/PPCArch.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
Loading…
x
Reference in New Issue
Block a user