mirror of
https://github.com/clang-retro/mac-sdk.git
synced 2026-11-28 13:19:22 -08:00
- tools/simppc.py runs a PowerPC application on unicorn: it loads the PEF container, applies its relocations, and fakes the InterfaceLib functions the tests import with sim68k.py's fakes. tests/run.sh runs the runtime, glue and C library tests in it. - peflink.py puts clang's AIX-style __sinit and __sterm functions in the constructor and destructor tables, by priority. - Fixes found by running PowerPC code for the first time: a pointer to a symbol from another object got that object's address subtracted from it, and a relocation at the TOC anchor's address went to the empty anchor csect. - codelink.py dropped .init_array and .fini_array (section types 14 to 16), so 68k static constructors never ran; the test passed because clang folded its constructor away. It is volatile now. - rename moves files between folders with PBCatMove. - stdin reads "App Input" (input.c, which a program can replace). - sim68k.py --os fakes PBGetCatInfo and PBCatMove, and --input fills stdin's file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRSuLMRWD4gxrktBpac Signed-off-by: Claude <noreply@anthropic.com>
50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
/* Console input: stdin reads the text file named after the program with
|
|
* " Input" ("Hello Input" for Hello) in the program's folder, with each
|
|
* Mac "\r" read as "\n". Without that file, stdin is at end of file.
|
|
*
|
|
* A program that reads its input elsewhere (a dialog, the serial port)
|
|
* defines __mac_console_read itself; then this file is not linked.
|
|
*
|
|
* Copyright (C) clang-retro contributors.
|
|
* SPDX-License-Identifier: AGPL-3.0-only */
|
|
#include <SegLoad.h>
|
|
#include "macos.h"
|
|
|
|
static short ref;
|
|
static int state; /* 0 not open yet, 1 open, -1 none */
|
|
|
|
static void open_input(void) {
|
|
Str255 name;
|
|
const unsigned char *app = LMGetCurApName();
|
|
static const char suffix[] = " Input";
|
|
unsigned n = app[0], i;
|
|
|
|
state = -1;
|
|
if (n > 31 - (sizeof suffix - 1))
|
|
n = 31 - (sizeof suffix - 1);
|
|
for (i = 0; i < n; i++)
|
|
name[1 + i] = app[1 + i];
|
|
for (i = 0; i < sizeof suffix - 1; i++)
|
|
name[1 + n + i] = (unsigned char)suffix[i];
|
|
name[0] = (unsigned char)(n + sizeof suffix - 1);
|
|
if (FSOpen(name, 0, &ref) == noErr)
|
|
state = 1;
|
|
}
|
|
|
|
long __mac_console_read(void *buf, size_t n) {
|
|
char *p = buf;
|
|
long count = (long)n, i;
|
|
OSErr err;
|
|
if (state == 0)
|
|
open_input();
|
|
if (state < 0)
|
|
return 0;
|
|
err = FSRead(ref, &count, buf);
|
|
if (err != noErr && err != eofErr)
|
|
return -1;
|
|
for (i = 0; i < count; i++)
|
|
if (p[i] == '\r')
|
|
p[i] = '\n';
|
|
return count;
|
|
}
|