Mac classic: Save 90kb from 68k and 120kb PPC builds by using own cut down console log

This commit is contained in:
UnknownShadow200 2024-06-08 10:22:02 +10:00
parent e2a4fc1205
commit 93c18b6177
4 changed files with 79 additions and 8 deletions

View file

@ -8,7 +8,7 @@ CFLAGS=-O1 -fno-math-errno
REZ=$(RETRO68)/bin/Rez REZ=$(RETRO68)/bin/Rez
LDFLAGS=-lRetroConsole LDFLAGS=-lm
RINCLUDES=$(PREFIX)/RIncludes RINCLUDES=$(PREFIX)/RIncludes
REZFLAGS=-I$(RINCLUDES) REZFLAGS=-I$(RINCLUDES)
@ -27,7 +27,7 @@ $(TARGET).bin $(TARGET).APPL $(TARGET).dsk: $(BUILD_DIR) $(TARGET).code.bin
$(TARGET).code.bin: $(C_OBJECTS) $(TARGET).code.bin: $(C_OBJECTS)
$(CXX) $(C_OBJECTS) -o $@ $(LDFLAGS) # C++ used for linking because RetroConsole needs it $(CC) $(C_OBJECTS) -o $@ $(LDFLAGS)
$(BUILD_DIR): $(BUILD_DIR):
mkdir -p $(BUILD_DIR) mkdir -p $(BUILD_DIR)

View file

@ -9,7 +9,7 @@ CFLAGS=-O1 -fno-math-errno
REZ=$(RETRO68)/bin/Rez REZ=$(RETRO68)/bin/Rez
MakePEF=$(RETRO68)/bin/MakePEF MakePEF=$(RETRO68)/bin/MakePEF
LDFLAGS=-lRetroConsole LDFLAGS=-lm
RINCLUDES=$(PREFIX)/RIncludes RINCLUDES=$(PREFIX)/RIncludes
REZFLAGS=-I$(RINCLUDES) REZFLAGS=-I$(RINCLUDES)
@ -27,7 +27,7 @@ $(TARGET).bin $(TARGET).APPL $(TARGET).dsk: $(BUILD_DIR) $(TARGET).pef
-o $(TARGET).bin --cc $(TARGET).APPL --cc $(TARGET).dsk -o $(TARGET).bin --cc $(TARGET).APPL --cc $(TARGET).dsk
$(TARGET).elf: $(C_OBJECTS) $(TARGET).elf: $(C_OBJECTS)
$(CXX) $(C_OBJECTS) -o $@ $(LDFLAGS) # C++ used for linking because RetroConsole needs it $(CC) $(C_OBJECTS) -o $@ $(LDFLAGS)
$(TARGET).pef: $(TARGET).elf $(TARGET).pef: $(TARGET).elf
$(MakePEF) $(TARGET).elf -o $(TARGET).pef $(MakePEF) $(TARGET).elf -o $(TARGET).pef

View file

@ -102,11 +102,10 @@ void Mem_Free(void* mem) {
/*########################################################################################################################* /*########################################################################################################################*
*------------------------------------------------------Logging/Time-------------------------------------------------------* *------------------------------------------------------Logging/Time-------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
ssize_t _consolewrite(int fd, const void *buf, size_t count); void Console_Write(const char* msg, int len);
void Platform_Log(const char* msg, int len) { void Platform_Log(const char* msg, int len) {
_consolewrite(0, msg, len); Console_Write(msg, len);
_consolewrite(0, "\n", 1);
} }
// classic macOS uses an epoch of 1904 // classic macOS uses an epoch of 1904

View file

@ -23,6 +23,78 @@ static WindowPtr win;
static cc_bool hasColorQD, useGWorld; static cc_bool hasColorQD, useGWorld;
/*########################################################################################################################*
*--------------------------------------------------Console log window-----------------------------------------------------*
*#########################################################################################################################*/
static int con_cellSizeX, con_cellSizeY;
static int con_rows, con_cols;
static int cursorX, cursorY;
static WindowPtr con_win;
static Rect con_bounds;
static void Console_EraseLine(int y) {
Rect r = con_bounds;
r.top += y * con_cellSizeY;
r.bottom = r.top + con_cellSizeY;
MoveTo(r.left, r.bottom - 2);
EraseRect(&r);
}
static void Console_Init(void) {
Rect r = qd.screenBits.bounds;
r.top += 40;
InsetRect(&r, 5, 5);
con_win = NewWindow(NULL, &r, "\pConsole log", true, 0, (WindowPtr)-1, true, 0);
GrafPtr savedPort;
GetPort(&savedPort);
SetPort(con_win);
con_bounds = con_win->portRect;
EraseRect(&con_bounds);
TextFont(kFontIDMonaco);
TextSize(9);
InsetRect(&con_bounds, 2, 2);
con_cellSizeX = CharWidth('M');
con_cellSizeY = 12;
con_rows = (con_bounds.bottom - con_bounds.top) / con_cellSizeY;
con_cols = (con_bounds.right - con_bounds.left) / con_cellSizeX;
Console_EraseLine(0);
cursorX = cursorY = 0;
SetPort(savedPort);
}
static void Console_NewLine(void) {
Console_EraseLine(cursorY);
cursorY++;
cursorX = 0;
if (cursorY >= con_rows) cursorY = 0;
}
void Console_Write(const char* msg, int len) {
if (!con_win) Console_Init();
GrafPtr savedPort;
GetPort(&savedPort);
SetPort(con_win);
for (int i = 0; i < len; i++)
{
DrawChar(msg[i]);
cursorX++;
if (cursorX >= con_cols) Console_NewLine();
}
Console_NewLine();
SetPort(savedPort);
}
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------Imported headers------------------------------------------------------* *---------------------------------------------------Imported headers------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
@ -182,7 +254,7 @@ void Window_RequestClose(void) {
static void HandleMouseDown(EventRecord* event) { static void HandleMouseDown(EventRecord* event) {
MAC_WindowPartCode part; MAC_WindowPartCode part;
WindowPtr window; WindowPtr window;
Point localPoint; Point localPoint;
int x, y; int x, y;