ticbuild 1.0.16 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/tic80Controller/remotingClient.d.ts +7 -0
- package/dist/backend/tic80Controller/remotingClient.d.ts.map +1 -1
- package/dist/backend/tic80Controller/remotingClient.js +30 -12
- package/dist/backend/tic80Controller/remotingClient.js.map +1 -1
- package/dist/backend/tic80Controller/remotingClient.test.d.ts +2 -0
- package/dist/backend/tic80Controller/remotingClient.test.d.ts.map +1 -0
- package/dist/backend/tic80Controller/remotingClient.test.js +94 -0
- package/dist/backend/tic80Controller/remotingClient.test.js.map +1 -0
- package/dist/backend/tic80Controller/remotingProtocol.d.ts +15 -0
- package/dist/backend/tic80Controller/remotingProtocol.d.ts.map +1 -0
- package/dist/backend/tic80Controller/remotingProtocol.js +30 -0
- package/dist/backend/tic80Controller/remotingProtocol.js.map +1 -0
- package/dist/backend/tic80Controller/remotingProtocol.test.d.ts +2 -0
- package/dist/backend/tic80Controller/remotingProtocol.test.d.ts.map +1 -0
- package/dist/backend/tic80Controller/remotingProtocol.test.js +26 -0
- package/dist/backend/tic80Controller/remotingProtocol.test.js.map +1 -0
- package/dist/buildInfo.d.ts +5 -5
- package/dist/buildInfo.js +5 -5
- package/dist/buildInfo.js.map +1 -1
- package/dist/frontend/terminal.d.ts.map +1 -1
- package/dist/frontend/terminal.js +14 -34
- package/dist/frontend/terminal.js.map +1 -1
- package/package.json +1 -1
- package/templates/TIC-80-ticbuild/remoting_README.md +470 -0
- package/templates/TIC-80-ticbuild/tic80.exe +0 -0
|
@@ -3,6 +3,11 @@ export interface RemotingResponse {
|
|
|
3
3
|
status: "OK" | "ERR";
|
|
4
4
|
data: string;
|
|
5
5
|
}
|
|
6
|
+
export interface RemotingEvent {
|
|
7
|
+
id: number;
|
|
8
|
+
eventType: string;
|
|
9
|
+
data: string;
|
|
10
|
+
}
|
|
6
11
|
export declare class Tic80RemotingClient {
|
|
7
12
|
private host;
|
|
8
13
|
private port;
|
|
@@ -10,9 +15,11 @@ export declare class Tic80RemotingClient {
|
|
|
10
15
|
private socket;
|
|
11
16
|
private buffer;
|
|
12
17
|
private nextId;
|
|
18
|
+
private eventHandlers;
|
|
13
19
|
private pending;
|
|
14
20
|
constructor(host: string, port: number, verbose: boolean);
|
|
15
21
|
isConnected(): boolean;
|
|
22
|
+
onEvent(handler: (event: RemotingEvent) => void): () => void;
|
|
16
23
|
connect(timeoutMs?: number): Promise<void>;
|
|
17
24
|
hello(): Promise<string>;
|
|
18
25
|
loadCart(cartPath: string, runAfterLoad?: boolean): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remotingClient.d.ts","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remotingClient.d.ts","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingClient.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,mBAAmB;IAW5B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IAZjB,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,OAAO,CAGX;gBAGM,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO;IAG1B,WAAW,IAAI,OAAO;IAItB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAOtD,OAAO,CAAC,SAAS,GAAE,MAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BhD,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAKxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAMvE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,KAAK,IAAI,IAAI;IAOb,OAAO,CAAC,YAAY;YAKN,WAAW;IAsBzB,OAAO,CAAC,MAAM;IAad,OAAO,CAAC,UAAU;IAiDlB,OAAO,CAAC,cAAc;CAOvB"}
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.Tic80RemotingClient = void 0;
|
|
40
40
|
const node_net_1 = __importDefault(require("node:net"));
|
|
41
41
|
const cons = __importStar(require("../../utils/console"));
|
|
42
|
+
const remotingProtocol_1 = require("./remotingProtocol");
|
|
42
43
|
class Tic80RemotingClient {
|
|
43
44
|
constructor(host, port, verbose) {
|
|
44
45
|
this.host = host;
|
|
@@ -46,11 +47,18 @@ class Tic80RemotingClient {
|
|
|
46
47
|
this.verbose = verbose;
|
|
47
48
|
this.buffer = "";
|
|
48
49
|
this.nextId = 1;
|
|
50
|
+
this.eventHandlers = new Set();
|
|
49
51
|
this.pending = new Map();
|
|
50
52
|
}
|
|
51
53
|
isConnected() {
|
|
52
54
|
return !!this.socket && !this.socket.destroyed;
|
|
53
55
|
}
|
|
56
|
+
onEvent(handler) {
|
|
57
|
+
this.eventHandlers.add(handler);
|
|
58
|
+
return () => {
|
|
59
|
+
this.eventHandlers.delete(handler);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
54
62
|
async connect(timeoutMs = 5000) {
|
|
55
63
|
if (this.isConnected()) {
|
|
56
64
|
return;
|
|
@@ -132,23 +140,33 @@ class Tic80RemotingClient {
|
|
|
132
140
|
if (this.verbose) {
|
|
133
141
|
cons.dim(`[remoting] << ${line}`);
|
|
134
142
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const match = /^([^\s]+)\s+([^\s]+)\s*(.*)$/.exec(line);
|
|
140
|
-
if (!match) {
|
|
143
|
+
const parsed = (0, remotingProtocol_1.parseRemotingLine)(line);
|
|
144
|
+
if (!parsed) {
|
|
141
145
|
cons.warning(`[remoting] Unparseable response: ${line}`);
|
|
142
146
|
return;
|
|
143
147
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
if (parsed.kind === "event") {
|
|
149
|
+
const event = {
|
|
150
|
+
id: parsed.id,
|
|
151
|
+
eventType: parsed.eventType,
|
|
152
|
+
data: parsed.data,
|
|
153
|
+
};
|
|
154
|
+
if (this.verbose) {
|
|
155
|
+
cons.dim(`[remoting] event ${event.id} ${event.eventType}${event.data ? ` ${event.data}` : ""}`);
|
|
156
|
+
}
|
|
157
|
+
for (const handler of this.eventHandlers) {
|
|
158
|
+
try {
|
|
159
|
+
handler(event);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
163
|
+
cons.warning(`[remoting] Event handler failed: ${message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
150
166
|
return;
|
|
151
167
|
}
|
|
168
|
+
const { id, data } = parsed;
|
|
169
|
+
const status = parsed.status;
|
|
152
170
|
const pending = this.pending.get(id);
|
|
153
171
|
if (!pending) {
|
|
154
172
|
cons.warning(`[remoting] No pending request for id ${id}: ${line}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remotingClient.js","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA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;QAED,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAsB,CAAC;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,OAAO,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACpE,OAAO;QACT,CAAC;QAED,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAExB,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,kCAAkC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,KAAY;QACjC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC5C,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AA/KD,kDA+KC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingClient.test.d.ts","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingClient.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
40
|
+
const cons = __importStar(require("../../utils/console"));
|
|
41
|
+
const remotingClient_1 = require("./remotingClient");
|
|
42
|
+
function listen(server) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
server.once("error", reject);
|
|
45
|
+
server.listen(0, "127.0.0.1", () => {
|
|
46
|
+
const address = server.address();
|
|
47
|
+
if (!address || typeof address === "string") {
|
|
48
|
+
reject(new Error("Server did not bind to an IPv4 port"));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
resolve(address.port);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function closeServer(server) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
server.close((err) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
reject(err);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
describe("Tic80RemotingClient", () => {
|
|
67
|
+
it("dispatches pushed events without consuming the matching command response", async () => {
|
|
68
|
+
const server = node_net_1.default.createServer((socket) => {
|
|
69
|
+
socket.once("data", (chunk) => {
|
|
70
|
+
const line = chunk.toString("utf8").trim();
|
|
71
|
+
const id = Number(line.split(/\s+/, 1)[0]);
|
|
72
|
+
socket.write('-1 trace "hello from tic80"\n');
|
|
73
|
+
socket.write(`${id} OK "TIC-80 remoting v1"\n`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const port = await listen(server);
|
|
77
|
+
const client = new remotingClient_1.Tic80RemotingClient("127.0.0.1", port, false);
|
|
78
|
+
const warnings = jest.spyOn(cons, "warning").mockImplementation(() => undefined);
|
|
79
|
+
const events = [];
|
|
80
|
+
client.onEvent((event) => events.push(event));
|
|
81
|
+
try {
|
|
82
|
+
await client.connect();
|
|
83
|
+
await expect(client.hello()).resolves.toBe('"TIC-80 remoting v1"');
|
|
84
|
+
expect(events).toEqual([{ id: -1, eventType: "trace", data: '"hello from tic80"' }]);
|
|
85
|
+
expect(warnings).not.toHaveBeenCalledWith(expect.stringContaining("No pending request"));
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
warnings.mockRestore();
|
|
89
|
+
client.close();
|
|
90
|
+
await closeServer(server);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=remotingClient.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingClient.test.js","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingClient.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAC3B,0DAA4C;AAC5C,qDAAuD;AAEvD,SAAS,MAAM,CAAC,MAAkB;IAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE;YACjC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC5C,MAAM,CAAC,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC,CAAC;gBACzD,OAAO;YACT,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,MAAkB;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;gBACZ,OAAO;YACT,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAA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C,CAAC;YACnE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC;YACrF,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC3F,CAAC;gBAAS,CAAC;YACT,QAAQ,CAAC,WAAW,EAAE,CAAC;YACvB,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ParsedRemotingResponseLine {
|
|
2
|
+
kind: "response";
|
|
3
|
+
id: number;
|
|
4
|
+
status: string;
|
|
5
|
+
data: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ParsedRemotingEventLine {
|
|
8
|
+
kind: "event";
|
|
9
|
+
id: number;
|
|
10
|
+
eventType: string;
|
|
11
|
+
data: string;
|
|
12
|
+
}
|
|
13
|
+
export type ParsedRemotingLine = ParsedRemotingResponseLine | ParsedRemotingEventLine;
|
|
14
|
+
export declare function parseRemotingLine(line: string): ParsedRemotingLine | undefined;
|
|
15
|
+
//# sourceMappingURL=remotingProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingProtocol.d.ts","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingProtocol.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,kBAAkB,GAAG,0BAA0B,GAAG,uBAAuB,CAAC;AAEtF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CA4B9E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRemotingLine = parseRemotingLine;
|
|
4
|
+
function parseRemotingLine(line) {
|
|
5
|
+
const match = /^([^\s]+)\s+([^\s]+)\s*(.*)$/.exec(line);
|
|
6
|
+
if (!match) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const id = Number(match[1]);
|
|
10
|
+
if (!Number.isInteger(id)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const token = match[2];
|
|
14
|
+
const data = match[3] ?? "";
|
|
15
|
+
if (id < 0) {
|
|
16
|
+
return {
|
|
17
|
+
kind: "event",
|
|
18
|
+
id,
|
|
19
|
+
eventType: token,
|
|
20
|
+
data,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
kind: "response",
|
|
25
|
+
id,
|
|
26
|
+
status: token.toUpperCase(),
|
|
27
|
+
data,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=remotingProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingProtocol.js","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingProtocol.ts"],"names":[],"mappings":";;AAgBA,8CA4BC;AA5BD,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,MAAM,KAAK,GAAG,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5B,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QACX,OAAO;YACL,IAAI,EAAE,OAAO;YACb,EAAE;YACF,SAAS,EAAE,KAAK;YAChB,IAAI;SACL,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,EAAE;QACF,MAAM,EAAE,KAAK,CAAC,WAAW,EAAE;QAC3B,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingProtocol.test.d.ts","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingProtocol.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const remotingProtocol_1 = require("./remotingProtocol");
|
|
4
|
+
describe("parseRemotingLine", () => {
|
|
5
|
+
it("parses response lines", () => {
|
|
6
|
+
expect((0, remotingProtocol_1.parseRemotingLine)('12 OK "hello"')).toEqual({
|
|
7
|
+
kind: "response",
|
|
8
|
+
id: 12,
|
|
9
|
+
status: "OK",
|
|
10
|
+
data: '"hello"',
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
it("parses pushed event lines", () => {
|
|
14
|
+
expect((0, remotingProtocol_1.parseRemotingLine)('-1 trace "hello from tic80"')).toEqual({
|
|
15
|
+
kind: "event",
|
|
16
|
+
id: -1,
|
|
17
|
+
eventType: "trace",
|
|
18
|
+
data: '"hello from tic80"',
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it("rejects lines without an integer id", () => {
|
|
22
|
+
expect((0, remotingProtocol_1.parseRemotingLine)('abc OK "nope"')).toBeUndefined();
|
|
23
|
+
expect((0, remotingProtocol_1.parseRemotingLine)('1.5 OK "nope"')).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=remotingProtocol.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remotingProtocol.test.js","sourceRoot":"","sources":["../../../src/backend/tic80Controller/remotingProtocol.test.ts"],"names":[],"mappings":";;AAAA,yDAAuD;AAEvD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,IAAA,oCAAiB,EAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;YACjD,IAAI,EAAE,UAAU;YAChB,EAAE,EAAE,EAAE;YACN,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,IAAA,oCAAiB,EAAC,6BAA6B,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/D,IAAI,EAAE,OAAO;YACb,EAAE,EAAE,CAAC,CAAC;YACN,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,oBAAoB;SAC3B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,IAAA,oCAAiB,EAAC,eAAe,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QAC3D,MAAM,CAAC,IAAA,oCAAiB,EAAC,eAAe,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/buildInfo.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const buildInfo: {
|
|
2
|
-
readonly version: "1.0.
|
|
3
|
-
readonly dirty:
|
|
4
|
-
readonly buildDate: "2026-04-
|
|
5
|
-
readonly lastCommitDate: "2026-04-
|
|
6
|
-
readonly commitHash: "
|
|
2
|
+
readonly version: "1.0.17";
|
|
3
|
+
readonly dirty: true;
|
|
4
|
+
readonly buildDate: "2026-04-30T10:59:54.765Z";
|
|
5
|
+
readonly lastCommitDate: "2026-04-30T12:58:56+02:00";
|
|
6
|
+
readonly commitHash: "f78a4af";
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=buildInfo.d.ts.map
|
package/dist/buildInfo.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildInfo = void 0;
|
|
4
4
|
// Auto-generated by scripts/gen-build-info.js. Do not edit.
|
|
5
5
|
exports.buildInfo = {
|
|
6
|
-
"version": "1.0.
|
|
7
|
-
"dirty":
|
|
8
|
-
"buildDate": "2026-04-
|
|
9
|
-
"lastCommitDate": "2026-04-
|
|
10
|
-
"commitHash": "
|
|
6
|
+
"version": "1.0.17",
|
|
7
|
+
"dirty": true,
|
|
8
|
+
"buildDate": "2026-04-30T10:59:54.765Z",
|
|
9
|
+
"lastCommitDate": "2026-04-30T12:58:56+02:00",
|
|
10
|
+
"commitHash": "f78a4af"
|
|
11
11
|
};
|
|
12
12
|
//# sourceMappingURL=buildInfo.js.map
|
package/dist/buildInfo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildInfo.js","sourceRoot":"","sources":["../src/buildInfo.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC/C,QAAA,SAAS,GAAG;IACvB,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"buildInfo.js","sourceRoot":"","sources":["../src/buildInfo.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC/C,QAAA,SAAS,GAAG;IACvB,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,0BAA0B;IACvC,gBAAgB,EAAE,2BAA2B;IAC7C,YAAY,EAAE,SAAS;CACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/frontend/terminal.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/frontend/terminal.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AA2ED,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,cAAc,CAuBnE;AAsGD,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAmD7E;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAWlD;AAED,wBAAsB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMtE;AAED,wBAAsB,6BAA6B,CAC/C,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,EACjC,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,GAAE,MAAc,GAC1B,OAAO,CAAC,IAAI,CAAC,CAoBf"}
|
|
@@ -72,28 +72,15 @@ function formatSessionSummary(session, index) {
|
|
|
72
72
|
const prefix = index === undefined ? "" : `${index + 1}. `;
|
|
73
73
|
return `${prefix}${session.host}:${session.port} pid=${session.pid} started=${started} version=${session.remotingVersion} source=${session.source}`;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function createSocketLinePump(socket, onLine, onClosed) {
|
|
76
76
|
let buffer = "";
|
|
77
77
|
let closed = false;
|
|
78
|
-
const pending = [];
|
|
79
|
-
const queued = [];
|
|
80
|
-
const flushLine = (value) => {
|
|
81
|
-
if (pending.length > 0) {
|
|
82
|
-
const resolver = pending.shift();
|
|
83
|
-
resolver(value);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
queued.push(value);
|
|
87
|
-
};
|
|
88
78
|
const resolveClosed = () => {
|
|
89
79
|
if (closed) {
|
|
90
80
|
return;
|
|
91
81
|
}
|
|
92
82
|
closed = true;
|
|
93
|
-
|
|
94
|
-
const resolver = pending.shift();
|
|
95
|
-
resolver(null);
|
|
96
|
-
}
|
|
83
|
+
onClosed();
|
|
97
84
|
};
|
|
98
85
|
const onData = (chunk) => {
|
|
99
86
|
buffer += chunk.toString("ascii");
|
|
@@ -101,13 +88,13 @@ function createSocketLineReader(socket) {
|
|
|
101
88
|
while (lineBreak !== -1) {
|
|
102
89
|
const line = buffer.slice(0, lineBreak).replace(/\r$/, "");
|
|
103
90
|
buffer = buffer.slice(lineBreak + 1);
|
|
104
|
-
|
|
91
|
+
onLine(line);
|
|
105
92
|
lineBreak = buffer.indexOf("\n");
|
|
106
93
|
}
|
|
107
94
|
};
|
|
108
95
|
const onClose = () => {
|
|
109
96
|
if (buffer.length > 0) {
|
|
110
|
-
|
|
97
|
+
onLine(buffer);
|
|
111
98
|
buffer = "";
|
|
112
99
|
}
|
|
113
100
|
resolveClosed();
|
|
@@ -116,17 +103,6 @@ function createSocketLineReader(socket) {
|
|
|
116
103
|
socket.once("close", onClose);
|
|
117
104
|
socket.once("error", onClose);
|
|
118
105
|
return {
|
|
119
|
-
readNextLine: async () => {
|
|
120
|
-
if (queued.length > 0) {
|
|
121
|
-
return queued.shift();
|
|
122
|
-
}
|
|
123
|
-
if (closed) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
return new Promise((resolve) => {
|
|
127
|
-
pending.push(resolve);
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
106
|
close: () => {
|
|
131
107
|
socket.removeListener("data", onData);
|
|
132
108
|
socket.removeListener("close", onClose);
|
|
@@ -245,13 +221,19 @@ function connectSocket(host, port, timeoutMs) {
|
|
|
245
221
|
async function runTerminalClient(target) {
|
|
246
222
|
const { host, port } = target;
|
|
247
223
|
const socket = await connectSocket(host, port, 5000);
|
|
248
|
-
const socketReader = createSocketLineReader(socket);
|
|
249
224
|
cons.info(`Connected to ${host}:${port}. Type lines like: 1 ping (Ctrl+C to quit)`);
|
|
250
225
|
const rl = readline.createInterface({
|
|
251
226
|
input: process.stdin,
|
|
252
227
|
output: process.stdout,
|
|
253
228
|
terminal: true,
|
|
254
229
|
});
|
|
230
|
+
let disconnected = false;
|
|
231
|
+
const socketPump = createSocketLinePump(socket, (line) => {
|
|
232
|
+
process.stdout.write(`${line}\n`);
|
|
233
|
+
}, () => {
|
|
234
|
+
disconnected = true;
|
|
235
|
+
rl.close();
|
|
236
|
+
});
|
|
255
237
|
rl.on("SIGINT", () => {
|
|
256
238
|
rl.close();
|
|
257
239
|
});
|
|
@@ -264,17 +246,15 @@ async function runTerminalClient(target) {
|
|
|
264
246
|
if (line.trim().length === 0) {
|
|
265
247
|
continue;
|
|
266
248
|
}
|
|
267
|
-
|
|
268
|
-
const response = await socketReader.readNextLine();
|
|
269
|
-
if (response === null) {
|
|
249
|
+
if (disconnected) {
|
|
270
250
|
throw new Error("Disconnected from TIC-80 remoting server");
|
|
271
251
|
}
|
|
272
|
-
|
|
252
|
+
socket.write(`${line}\n`, "ascii");
|
|
273
253
|
}
|
|
274
254
|
}
|
|
275
255
|
finally {
|
|
276
256
|
rl.close();
|
|
277
|
-
|
|
257
|
+
socketPump.close();
|
|
278
258
|
if (!socket.destroyed) {
|
|
279
259
|
socket.end();
|
|
280
260
|
socket.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.js","sourceRoot":"","sources":["../../src/frontend/terminal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"terminal.js","sourceRoot":"","sources":["../../src/frontend/terminal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,sCAuBC;AAsGD,8CAmDC;AAED,oCAWC;AAED,0CAMC;AAED,sEAwBC;AApTD,wDAA2B;AAC3B,wDAA0C;AAC1C,oEAA6G;AAC7G,uDAAyC;AACzC,8CAAsD;AACtD,0CAAuC;AAOvC,SAAS,QAAQ,CAAC,EAAsB,EAAE,MAAc;IACpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;YAC7B,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,GAAG,EAAE;YACjB,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,GAAG,EAAE;YACjB,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAClC,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC,CAAC;QAEF,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1B,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACrB,EAAE,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,oBAAoB,CAAC,OAA+B,EAAE,KAAc;IACzE,MAAM,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AC,CAAC;AACxF,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
# Features in this fork
|
|
2
|
+
|
|
3
|
+
- Remoting server
|
|
4
|
+
- Frame timing and remoting display in window title and HUD (access via <kbd>ALT+0</kbd>)
|
|
5
|
+
|
|
6
|
+
# Perf HUD color scheme and thresholds
|
|
7
|
+
|
|
8
|
+
HUD colors are configured with these optional command line args:
|
|
9
|
+
|
|
10
|
+
- `--hud-palette-outline`
|
|
11
|
+
- `--hud-palette-text`
|
|
12
|
+
- `--hud-palette-ok`
|
|
13
|
+
- `--hud-palette-warning`
|
|
14
|
+
- `--hud-palette-alert`
|
|
15
|
+
|
|
16
|
+
Each value can be:
|
|
17
|
+
|
|
18
|
+
- `auto` (use built-in target color matching against current frame palette)
|
|
19
|
+
- a palette index (`0` to `15`)
|
|
20
|
+
- a hex color token without `#`, in either `rgb` or `rrggbb` form (`f80`, `ff8800`)
|
|
21
|
+
|
|
22
|
+
`auto` default targets are:
|
|
23
|
+
|
|
24
|
+
- outline: black
|
|
25
|
+
- text: white
|
|
26
|
+
- ok: green
|
|
27
|
+
- warning: orange/yellow
|
|
28
|
+
- alert: red
|
|
29
|
+
|
|
30
|
+
Threshold command line args:
|
|
31
|
+
|
|
32
|
+
- `--thresh-fps-warn` (fps)
|
|
33
|
+
- `--thresh-fps-alert` (fps)
|
|
34
|
+
- `--thresh-mem-warn` (kb)
|
|
35
|
+
- `--thresh-mem-alert` (kb)
|
|
36
|
+
- `--thresh-cycles-warn` (kcycles)
|
|
37
|
+
- `--thresh-cycles-alert` (kcycles)
|
|
38
|
+
|
|
39
|
+
Default thresholds:
|
|
40
|
+
|
|
41
|
+
- FPS: warning `<57`, alert `<53`
|
|
42
|
+
- MEM: warning `>102400` kb, alert `>256000` kb
|
|
43
|
+
- cycles (TIC/SCN+BDR): warning `>1800` kcycles, alert `>2400` kcycles
|
|
44
|
+
|
|
45
|
+
Threshold state is checked as alert first, then warning, then OK. For FPS (lower is
|
|
46
|
+
worse), comparisons are inverted.
|
|
47
|
+
|
|
48
|
+
Graph coloring is evaluated per rendered x-column and value text is colored by the
|
|
49
|
+
same severity. Custom perf metrics always use OK color.
|
|
50
|
+
|
|
51
|
+
# remoting support for ticbuild
|
|
52
|
+
|
|
53
|
+
[ticbuild](https://github.com/thenfour/ticbuild) is a build system for TIC-80 which
|
|
54
|
+
supports watching cart dependencies for live updates.
|
|
55
|
+
|
|
56
|
+
In order to make that work, we need to add some functionality to TIC-80 for remote control.
|
|
57
|
+
|
|
58
|
+
We add a command line arg:
|
|
59
|
+
|
|
60
|
+
`tic80.exe --remoting-port=9977`
|
|
61
|
+
|
|
62
|
+
While TIC-80 is running, it will listen on this port for remote commands. Always
|
|
63
|
+
binds to `127.0.0.1`. Up to 10 clients supported.
|
|
64
|
+
|
|
65
|
+
# Protocol
|
|
66
|
+
|
|
67
|
+
- Line-based human readable (terminal-friendly)
|
|
68
|
+
- dead-simple, no optional args or multiple datatypes if possible.
|
|
69
|
+
- requests
|
|
70
|
+
- each line in the form `<id> <command> <args...>`
|
|
71
|
+
- `id` is an id used to pair responses with requests. `id` must be integral number, and non-negative (>=0).
|
|
72
|
+
Invalid/negative IDs won't echo back to clients; id will be `0` in that case. (`-1 hello` will give response `0 ERR "invalid id"`)
|
|
73
|
+
- example: `1 sync 24`
|
|
74
|
+
- example: `1 poke 0x8fff <24 ff c0>`
|
|
75
|
+
- this `<xx ...>` syntax allows representing binary data in hex byte form
|
|
76
|
+
- multiple args are separated by whitespace.
|
|
77
|
+
- example: `1 eval "trace(\"hello from remote\")"`
|
|
78
|
+
- quotes wrap an arg that contains whitespace. Escape char is `\`
|
|
79
|
+
- `\\` = `\`
|
|
80
|
+
- `\"` = `"`
|
|
81
|
+
- commands are not case-sensitive. `sync` and `SYNC` and `SyNc` are equivalent.
|
|
82
|
+
- whitespace is forgiving. `1 sync 24` (or tabs) is the same as `1 sync 24`.
|
|
83
|
+
- trailing whitespace is trimmed/ignored
|
|
84
|
+
- non-ASCII chars are considered an error.
|
|
85
|
+
- named args not supported (yet)
|
|
86
|
+
- commands supported:
|
|
87
|
+
- `hello` - returns a description of the system (TIC-80 remoting v1)
|
|
88
|
+
- `load <cart_path.tic> <run:1|0>`, e.g. `load "c:\\xyz.tic" 1`.
|
|
89
|
+
If the run flag is `0`, the cart is just loaded. If `1`, the cart is
|
|
90
|
+
launched after successful load.
|
|
91
|
+
- `ping` - returns data `PONG`
|
|
92
|
+
- `sync <flags>` - returns nothing (syncs cart & runtime memory; see tic80 docs)
|
|
93
|
+
- `poke <addr> <data>` - returns nothing
|
|
94
|
+
- `peek <addr> <size>`
|
|
95
|
+
- returns the binary result, e.g., `<c0 a7 ff 00>`.
|
|
96
|
+
- size is required even if it's only 1.
|
|
97
|
+
- `restart`
|
|
98
|
+
- `quit`
|
|
99
|
+
- `eval <code>` - no return possible (`tic_script.eval` has `void` return type).
|
|
100
|
+
you could just make the script do something visible, like `poke()`.
|
|
101
|
+
- TODO: enable trace output to remote? or support return data?
|
|
102
|
+
- `evalexpr <expression>` - returns the result of the given single expression.
|
|
103
|
+
It's effectively your expression with `return` prepended, allowing syntax like `1+3`
|
|
104
|
+
or `width * size`
|
|
105
|
+
without having to type `return width * size`. That can cause issues if you need
|
|
106
|
+
to execute a lot of code, but always workaroundable with something like,
|
|
107
|
+
`evelexpr "(function() ... end)()"`.
|
|
108
|
+
- `status` - return runtime & loaded cart status. see below.
|
|
109
|
+
- `listglobals` - returns a single-line, comma-separated list of eval-able
|
|
110
|
+
global symbols (identifier keys from the Lua global environment).
|
|
111
|
+
- `typeschema <symbol>` - returns a type schema of the specified global symbol. see below.
|
|
112
|
+
- `getfps` - gets current FPS
|
|
113
|
+
- `cartpath` - returns the full path to the currently open cartridge.
|
|
114
|
+
empty string if there's no open cart.
|
|
115
|
+
- `fs` - returns the current filesystem local path (the one you can control via command line `--fs=...`)
|
|
116
|
+
- `perf` - returns current live performance metrics. see below for response
|
|
117
|
+
- `metadata <key>` - returns the value for the metadata value in code.
|
|
118
|
+
See: https://github.com/nesbox/TIC-80/wiki/Cartridge-Metadata.
|
|
119
|
+
- `lua_profiler_start <mode> <instructionInterval> <wallClockPeriodMicros> <seconds?> <output_path?>` - Starts a
|
|
120
|
+
Lua performance profiling session. See below for performance profiler instructions.
|
|
121
|
+
- `lua_profiler_stop <output_path>`. Stops the profiler and writes the output to the optional
|
|
122
|
+
specified path (otherwise one is auto-generated)
|
|
123
|
+
See below for performance profiler instructions.
|
|
124
|
+
- `lua_profiler_status` - returns the status of the lua profiler
|
|
125
|
+
- `event_subscribe <event_type|event_type> <enabled:1|0>` - set client subscription status for event types.
|
|
126
|
+
Specify the event types to affect; they can be combined with pipe char `|`. Enable subscription to the
|
|
127
|
+
types with `1`; `0` will unsubscribe. Event types that aren't specified here are unaffected.
|
|
128
|
+
Example: `0 event_subscribe "trace|cart_run" 1` enables
|
|
129
|
+
receiving `trace()` and cart run events pushed from server to client (and other event types remain unaffected)
|
|
130
|
+
- datatypes
|
|
131
|
+
- numbers (integral, negative, decimal)
|
|
132
|
+
- No fancy `1e3` forms
|
|
133
|
+
- integral: `1` `0` `24` `-1000`
|
|
134
|
+
- decimal: `1.011` `.1` `-123.456` `.1`
|
|
135
|
+
- leading `0` not necessary (`.1` is valid; `0.1` is also valid)
|
|
136
|
+
- trailing decimal supported (`1.` is valid)
|
|
137
|
+
- decimal on its own (no leading 0 + trailing decimal) is an error (`.`)
|
|
138
|
+
- hex `0xff` `-0x1` (always integral, prefix with `0x`).
|
|
139
|
+
- strings
|
|
140
|
+
- always require double quotes, ASCII-only, escape char is `\`.
|
|
141
|
+
- binary, enclosed in `<` and `>`.
|
|
142
|
+
- example: `<ff 22 00>`
|
|
143
|
+
- string syntax: always hexadecimal.
|
|
144
|
+
- whitespace is ignored so `<ff2200>` or `<f f220 0>` are equivalent to `<ff 22 00>`
|
|
145
|
+
- response
|
|
146
|
+
- datatypes follow same convention as requests
|
|
147
|
+
- `<id> <status> <data...>`
|
|
148
|
+
- `id` is the same ID as the request. no checking is done on this, you can
|
|
149
|
+
send the same id always and the server doesn't care.
|
|
150
|
+
- `status` is either `OK` or `ERR`
|
|
151
|
+
- data is defined by the command, but is similar to the request args.
|
|
152
|
+
- `1 ping` => `1 OK PONG`
|
|
153
|
+
- `44 sync 24` => `44 OK`
|
|
154
|
+
- `xx` => `0 ERR "error description here"`
|
|
155
|
+
- events (pushed from server to client): `<-id> <eventtype> <data...>`
|
|
156
|
+
- server can send event messages to the client using similar message format. The
|
|
157
|
+
message id is a negative integer (e.g. `-243`). Datatype syntax remains.
|
|
158
|
+
Note that clients will only receive event types they subscribe to via `event_subscribe`
|
|
159
|
+
explicitly; by default clients do not receive any events. Event subscription is
|
|
160
|
+
per-client; if client A subscribes, then only it receives the event; it doesn't
|
|
161
|
+
affect other clients. No guarantees are made about ids being in a particular order,
|
|
162
|
+
having gaps, or duplicates (though reasonably speaking there won't be duplicates due to int64 numeric range).
|
|
163
|
+
Examples of received events:
|
|
164
|
+
- `-1 trace "hello from tic80"` sent for all `trace()` Lua calls.
|
|
165
|
+
- `-2 cart_run` sent when cart is launched / game is run (ctrl+R)
|
|
166
|
+
- `-3 lua_profiler_stopped` sent when the lua profiler finishes
|
|
167
|
+
- (this is the only one supported so far)
|
|
168
|
+
- Commands to be queued and executed at a deterministic safe point in the
|
|
169
|
+
TIC-80 system loop (e.g., between frames if the cart is running)
|
|
170
|
+
|
|
171
|
+
# `perf` command
|
|
172
|
+
|
|
173
|
+
returns a single-line, comma-separated, `key=value` pairs.
|
|
174
|
+
|
|
175
|
+
## keys
|
|
176
|
+
|
|
177
|
+
- `client_count` integer; number of clients connected to remoting
|
|
178
|
+
- `fps` current capped FPS from the rolling window tracker, floating-point (e.g. `59.95`, `60`)
|
|
179
|
+
- `fps_uncapped` estimated uncapped FPS derived from `total_ms`, integral.
|
|
180
|
+
- `tic_ms` time spent in TIC, in milliseconds quantized to `0.1ms`.
|
|
181
|
+
- `scn_ms`
|
|
182
|
+
- `bdr_ms`
|
|
183
|
+
- `total_ms` total time spent in TIC+SCN+BDR, in milliseconds quantized to `0.1ms`.
|
|
184
|
+
- `tic_cycles` number of Lua VM cycles spent in TIC. integral.
|
|
185
|
+
- `scn_cycles`
|
|
186
|
+
- `bdr_cycles`
|
|
187
|
+
- `total_cycles`
|
|
188
|
+
- `lua_gc_mem` - lua's gc memory usage, in bytes (integral)
|
|
189
|
+
|
|
190
|
+
Timing values are measured as fixed-point `ms10` internally, so all `*_ms` values
|
|
191
|
+
are rounded to the nearest `0.1ms` before being exposed. `fps_uncapped` is
|
|
192
|
+
derived from that quantized `total_ms` value, so it is approximate and becomes
|
|
193
|
+
coarser at very high frame rates.
|
|
194
|
+
|
|
195
|
+
# Discovery Protocol
|
|
196
|
+
|
|
197
|
+
When the remoting server is listening, we will make the server discoverable by
|
|
198
|
+
placing a json file on the filesystem.
|
|
199
|
+
|
|
200
|
+
If the file already exists, it shall be overwritten.
|
|
201
|
+
|
|
202
|
+
The file is to be deleted when the server stops listening.
|
|
203
|
+
|
|
204
|
+
The global file will be placed in `%LOCALAPPDATA%\TIC-80\remoting\sessions\` and
|
|
205
|
+
the file is to be named `tic80-remote.<pid>.json`. Its contents will look like,
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"pid": 1234,
|
|
210
|
+
"host": "127.0.0.1",
|
|
211
|
+
"port": 51000,
|
|
212
|
+
"startedAt": "2026-01-31T19:50:26.859Z",
|
|
213
|
+
"remotingVersion": "v1"
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
- `remotingVersion` is the same as in the `hello` command.
|
|
218
|
+
|
|
219
|
+
We also must support a new command line arg, for specifying where to output the
|
|
220
|
+
remote session file.
|
|
221
|
+
|
|
222
|
+
`tic80.exe --remote-session-location=c:\my\folder`
|
|
223
|
+
|
|
224
|
+
will write the discovery file as `c:\my\folder\tic80-remote.<pid>.json`
|
|
225
|
+
|
|
226
|
+
The global discovery location (under `%LOCALAPPDATA%`) is written unless disabled
|
|
227
|
+
with the `--global-disco=OFF|ON` command line arg. It is `ON` by default. The
|
|
228
|
+
user-specified `--remote-session-location` file is always written regardless of
|
|
229
|
+
the global flag.
|
|
230
|
+
|
|
231
|
+
example:
|
|
232
|
+
|
|
233
|
+
`tic80.exe --remote-session-location=c:\my\folder --global-disco=OFF`
|
|
234
|
+
|
|
235
|
+
writes the remote session file to `c:\my\folder`
|
|
236
|
+
|
|
237
|
+
# `typeschema <symbol>`
|
|
238
|
+
|
|
239
|
+
Returns the type schema of the specified global symbol. For simple values it's
|
|
240
|
+
the same as Lua's keyword `type(x)`. So it can return:
|
|
241
|
+
|
|
242
|
+
- `string`
|
|
243
|
+
- `number`
|
|
244
|
+
- `function`
|
|
245
|
+
- `boolean`
|
|
246
|
+
- `nil`
|
|
247
|
+
|
|
248
|
+
However for tables
|
|
249
|
+
|
|
250
|
+
- `table`
|
|
251
|
+
|
|
252
|
+
# code structure
|
|
253
|
+
|
|
254
|
+
changes to existing "official" TIC-80 code to be surgical and minimal. put our own
|
|
255
|
+
sources under `/src/ticbuild_remoting`.
|
|
256
|
+
|
|
257
|
+
# performance profiler
|
|
258
|
+
|
|
259
|
+
Want to see which Lua functions or lines are causing performance issues? The
|
|
260
|
+
following remoting commands can be used to record stack trace samples to eventually
|
|
261
|
+
view in as a flame graph.
|
|
262
|
+
|
|
263
|
+
`lua_profiler_start <mode> <instructionInterval> <wallClockPeriodMicros> <seconds?> <output_path?>`
|
|
264
|
+
|
|
265
|
+
Starts a Lua performance profiling session.
|
|
266
|
+
|
|
267
|
+
- `mode` can be:
|
|
268
|
+
- `instructions`: samples are collected every `<instructionInterval>` Lua instructions.
|
|
269
|
+
- `wallclock`: samples are collected every `<wallClockPeriodMicros>` microseconds
|
|
270
|
+
(1000 micros = 1 millisecond). Because of the way we sample the Lua runtime,
|
|
271
|
+
`<instructionInterval>` is still used here.
|
|
272
|
+
- `seconds` is optional and specifies the # of seconds to profile for. After this # of
|
|
273
|
+
seconds has elapsed, profiling stops automatically on the next regular update/frame poll.
|
|
274
|
+
- `output_path` has the same semantics as `lua_profiler_stop`. Optional; and only
|
|
275
|
+
used when `seconds` is specified. If not specified, auto-stop will choose an auto
|
|
276
|
+
temp file path.
|
|
277
|
+
|
|
278
|
+
When `seconds` is specified, the `lua_profiler_start` response includes the reserved
|
|
279
|
+
save path immediately, for example:
|
|
280
|
+
|
|
281
|
+
`auto_stop=1,duration=12,output_path="C:\\Users\\you\\AppData\\Local\\Temp\\tic80-lua-profiler-1234.txt"`
|
|
282
|
+
|
|
283
|
+
When `seconds` is omitted, the response is:
|
|
284
|
+
|
|
285
|
+
`auto_stop=0`
|
|
286
|
+
|
|
287
|
+
Notes:
|
|
288
|
+
|
|
289
|
+
- It is an error to start a session when one is already running
|
|
290
|
+
- It is an error to stop a session when one is not running.
|
|
291
|
+
- It is not defined how the profiler acts when reloading/stopping/pausing etc. Don't bother handling these scenarios explicitly; that's on the user.
|
|
292
|
+
|
|
293
|
+
Once profiling is started, the title bar will indicate that profiling is active.
|
|
294
|
+
|
|
295
|
+
`TIC-80 | 60/60 fps | 55 + 3 = 58 kcyc | 1.2 ms | 100 kb | listening on 127.0.0.1:55555 (1 client) | PROFILING... 12s`
|
|
296
|
+
|
|
297
|
+
To stop profiling and collect the data, call
|
|
298
|
+
|
|
299
|
+
`lua_profiler_stop <output_path>`.
|
|
300
|
+
|
|
301
|
+
Stops the profiler and writes the output to the specified path. If no path is specified,
|
|
302
|
+
a temp path is chosen. The response will indicate the saved file path.
|
|
303
|
+
|
|
304
|
+
`lua_profiler_status`
|
|
305
|
+
|
|
306
|
+
returns the status of the lua profiler. single-line, comma-separated, `key=value` pairs.
|
|
307
|
+
|
|
308
|
+
examples:
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
running=0,auto_stop=0
|
|
312
|
+
running=1,auto_stop=0,mode=instructions,instruction_interval=1000,elapsed_seconds=12
|
|
313
|
+
running=1,auto_stop=1,mode=wallclock,instruction_interval=1000,wall_clock_period_micros=10,elapsed_seconds=12,duration=30,remaining_seconds=18,output_path="C:\\Users\\you\\AppData\\Local\\Temp\\tic80-lua-profiler-1234.txt"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## `instructions` vs. `wallclock` mode
|
|
317
|
+
|
|
318
|
+
Lua instructions are a host-agnostic way to measure performance. If you're working on a team
|
|
319
|
+
of people with different computer specs, you cannot for example compare FPS values.
|
|
320
|
+
In this case Lua instructions (or kcycles as in the title bar) is an objective cross-host
|
|
321
|
+
metric.
|
|
322
|
+
|
|
323
|
+
Just be aware that not all instructions are made equal, so there are cases where
|
|
324
|
+
you optimize for kcycles but actual Windows host performance is worse.
|
|
325
|
+
|
|
326
|
+
For profiling on your own machine against your own metrics during development,
|
|
327
|
+
`wallclock` can be more useful. It measures the actual host time spent. So while
|
|
328
|
+
it is the actual metric that says "this is running faster", it's not consistent because
|
|
329
|
+
it depends on the environment: if another process is hogging CPU, or if you run
|
|
330
|
+
in a VM etc, you cannot compare the values anymore.
|
|
331
|
+
|
|
332
|
+
Further note about difficulties in measuring `wallclock`: we use `lua_getstack` and `lua_getinfo`,
|
|
333
|
+
which cannot be run at arbitrary times. We therefore use `lua_sethook`, but this
|
|
334
|
+
operates on a lua instruction count basis, not host clock. So in order to sample
|
|
335
|
+
at host clock intervals, we use `lua_sethook` but on a tight-ish interval,
|
|
336
|
+
and check if a sample is due. If not, return. If it's due, collect the sample.
|
|
337
|
+
|
|
338
|
+
This means some kind of jitter can cause slight noise, but that's not expected
|
|
339
|
+
to be an issue over thousands of collections.
|
|
340
|
+
|
|
341
|
+
Jitter can even be a good thing in profiling because some natural code loops/cadences
|
|
342
|
+
can accidentally line up with the sampling cadence. Apparently most profilers
|
|
343
|
+
introduce some strategic jitter to ensure this is accounted for. Not sure our kind
|
|
344
|
+
of jitter would be the good kind or not.
|
|
345
|
+
|
|
346
|
+
## Stats collection
|
|
347
|
+
|
|
348
|
+
We're going to collect stats in the least intrusive way possible. We are expecting
|
|
349
|
+
a lot of hits for certain paths, so a map-like structure is expected here. Better
|
|
350
|
+
to defer any processing (like mapping stack trace to symbols/source file:line etc)
|
|
351
|
+
until when the session is ended, to avoid affecting runtime.
|
|
352
|
+
|
|
353
|
+
As tempting as it is to introduce C++, let's stay in C for consistency.
|
|
354
|
+
|
|
355
|
+
## Output format
|
|
356
|
+
|
|
357
|
+
The output is a plain text file that can be imported to [speedscope](https://github.com/jlfwong/speedscope/).
|
|
358
|
+
|
|
359
|
+
In particular the "Brendan Gregg" format is fine for us. Just line-based plain text,
|
|
360
|
+
each line has a semi-colon delimited stack frames and integral sample count at the end.
|
|
361
|
+
|
|
362
|
+
```
|
|
363
|
+
main;a;b;c 1
|
|
364
|
+
main;a;b;c 1
|
|
365
|
+
main;a;b;d 4
|
|
366
|
+
main;a;b;c 3
|
|
367
|
+
main;a;b 5
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Integration with existing system
|
|
371
|
+
|
|
372
|
+
`lua_sethook` I believe just handles one hook at a time. It's not some kind of hook chain;
|
|
373
|
+
the interval needs to be chosen for the hook and the profiling hook will want
|
|
374
|
+
a different cadence than the default hook.
|
|
375
|
+
|
|
376
|
+
It means either we disable the exsiting perf hook during profiling, or we find a
|
|
377
|
+
way to synergize. Disabling existing hook is impossible because it's important information
|
|
378
|
+
even during profiling.
|
|
379
|
+
|
|
380
|
+
The existing hook interval is `TB_LUA_HOOK_STEP = 1000`.
|
|
381
|
+
|
|
382
|
+
## Example
|
|
383
|
+
|
|
384
|
+
**First, be running this fork of TIC-80 with a cart**
|
|
385
|
+
|
|
386
|
+
**Launch remote terminal**
|
|
387
|
+
|
|
388
|
+
easiest way is
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
> ticbuild terminal
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
which will automatically connect, via the discovery protocol
|
|
395
|
+
|
|
396
|
+
**Begin profiling**
|
|
397
|
+
|
|
398
|
+
Let's do a timed 10-second profile...
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
0 lua_profiler_start "wallclock" 1000 50 4
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Which returns:
|
|
405
|
+
|
|
406
|
+
```
|
|
407
|
+
0 OK auto_stop=1,duration=4,output_path="C:\\Users\\carl\\AppData\\Local\\Temp\\tic80-lua-profiler-34672.txt"
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
This samples on a host time cadence, checking every 1000 lua instructions if the
|
|
411
|
+
50 microsecond sample is due.
|
|
412
|
+
|
|
413
|
+
Sample collection happens over 4 seconds, and then stops automatically, placing the
|
|
414
|
+
file. This is done silently; remoting clients don't get a notification that profiling has
|
|
415
|
+
stopped.
|
|
416
|
+
|
|
417
|
+
**Checking on status**
|
|
418
|
+
|
|
419
|
+
```
|
|
420
|
+
0 lua_profiler_status
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
While the auto-stopping profile session is capturing, the response can be like,
|
|
424
|
+
|
|
425
|
+
```
|
|
426
|
+
0 OK running=1,auto_stop=1,mode=wallclock,instruction_interval=1000,
|
|
427
|
+
wall_clock_period_micros=50,elapsed_seconds=1,duration=4,remaining_seconds=3,
|
|
428
|
+
output_path="C:\\Users\\carl\\AppData\\Local\\Temp\\tic80-lua-profiler-34672.txt"
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Notably, `remaining_seconds` can be used by clients to know how much time
|
|
432
|
+
is left in the capture session.
|
|
433
|
+
|
|
434
|
+
Also note: output_path is not sticky; after the file is written, this status goes back
|
|
435
|
+
to:
|
|
436
|
+
|
|
437
|
+
```
|
|
438
|
+
> 0 lua_profiler_status
|
|
439
|
+
0 OK running=0,auto_stop=0
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
# `status` command
|
|
443
|
+
|
|
444
|
+
Similar to `perf`, returns a single-line, comma-separated, `key=value` pairs.
|
|
445
|
+
|
|
446
|
+
## keys
|
|
447
|
+
|
|
448
|
+
- `cart_loaded_at` timestamp when the current cartridge was loaded. `0` if there's no cart.
|
|
449
|
+
- `cart_last_launch_at` timestamp when the cart was last launched (ignores pausing/resuming).
|
|
450
|
+
if never launched, `0`. Also this resets when cart changes.
|
|
451
|
+
- `now` current wall clock timestamp; for reference / sanity check against the other fields
|
|
452
|
+
- `process_started_at` timestamp when this process was started.
|
|
453
|
+
- `pid` the pid of the this process
|
|
454
|
+
|
|
455
|
+
Timestamps are unix epoch.
|
|
456
|
+
|
|
457
|
+
Hosts can use `cart_loaded_at` and `cart_last_launch_at` to guarantee if the
|
|
458
|
+
cart has changed (note that changing Lua code requires a relaunch).
|
|
459
|
+
|
|
460
|
+
```
|
|
461
|
+
> 0 status
|
|
462
|
+
0 OK cart_loaded_at=1767225600123,cart_last_launch_at=1767225600456,now=1767225610000,process_started_at=1767225600123,pid=1773
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
While serial generation counters would be theoretically more precise, timestamps
|
|
466
|
+
are just simpler in code (`ts = time()` instead of `gen = existing_gen + 1`).
|
|
467
|
+
|
|
468
|
+
Generation is also problematic if you ever compare across sessions. We want that
|
|
469
|
+
`cart_loaded_at` is _always_ different on a different cart load, no matter which
|
|
470
|
+
tic-80 instance did it. Simplifies client logic.
|
|
Binary file
|