diff --git a/misc/macclassic/Makefile_68k b/misc/macclassic/Makefile_68k index 9a838a54f..17aa6ef20 100644 --- a/misc/macclassic/Makefile_68k +++ b/misc/macclassic/Makefile_68k @@ -8,7 +8,7 @@ CFLAGS=-O1 -fno-math-errno REZ=$(RETRO68)/bin/Rez -LDFLAGS=-lRetroConsole +LDFLAGS=-lm RINCLUDES=$(PREFIX)/RIncludes REZFLAGS=-I$(RINCLUDES) @@ -27,7 +27,7 @@ $(TARGET).bin $(TARGET).APPL $(TARGET).dsk: $(BUILD_DIR) $(TARGET).code.bin $(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): mkdir -p $(BUILD_DIR) diff --git a/misc/macclassic/Makefile_ppc b/misc/macclassic/Makefile_ppc index 1870b6af3..1f330635d 100644 --- a/misc/macclassic/Makefile_ppc +++ b/misc/macclassic/Makefile_ppc @@ -9,7 +9,7 @@ CFLAGS=-O1 -fno-math-errno REZ=$(RETRO68)/bin/Rez MakePEF=$(RETRO68)/bin/MakePEF -LDFLAGS=-lRetroConsole +LDFLAGS=-lm RINCLUDES=$(PREFIX)/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 $(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 $(MakePEF) $(TARGET).elf -o $(TARGET).pef diff --git a/src/Platform_MacClassic.c b/src/Platform_MacClassic.c index 23148176e..75065bdb2 100644 --- a/src/Platform_MacClassic.c +++ b/src/Platform_MacClassic.c @@ -102,11 +102,10 @@ void Mem_Free(void* mem) { /*########################################################################################################################* *------------------------------------------------------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) { - _consolewrite(0, msg, len); - _consolewrite(0, "\n", 1); + Console_Write(msg, len); } // classic macOS uses an epoch of 1904 diff --git a/src/Window_MacClassic.c b/src/Window_MacClassic.c index d98546f8c..6b6f81007 100644 --- a/src/Window_MacClassic.c +++ b/src/Window_MacClassic.c @@ -23,6 +23,78 @@ static WindowPtr win; 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------------------------------------------------------* *#########################################################################################################################*/ @@ -182,7 +254,7 @@ void Window_RequestClose(void) { static void HandleMouseDown(EventRecord* event) { MAC_WindowPartCode part; - WindowPtr window; + WindowPtr window; Point localPoint; int x, y;