rk86 2.0.30 → 2.0.32
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/package.json +2 -2
- package/rk86.js +218 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rk86",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.32",
|
|
4
4
|
"description": "Эмулятор Радио-86РК (Intel 8080) для терминала",
|
|
5
5
|
"bin": {
|
|
6
6
|
"rk86": "rk86.js"
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/begoon/rk86-js
|
|
21
|
+
"url": "https://github.com/begoon/rk86-js"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/rk86.js
CHANGED
|
@@ -165,6 +165,7 @@ function preprocess(source) {
|
|
|
165
165
|
const out = [];
|
|
166
166
|
const stack = [];
|
|
167
167
|
let counter = 0;
|
|
168
|
+
let procCounter = 0;
|
|
168
169
|
let proc = null;
|
|
169
170
|
for (let i = 0;i < lines.length; i++) {
|
|
170
171
|
const line = lines[i];
|
|
@@ -223,7 +224,14 @@ function preprocess(source) {
|
|
|
223
224
|
regs.push(up);
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
+
const id = procCounter++;
|
|
228
|
+
proc = {
|
|
229
|
+
regs,
|
|
230
|
+
line: orig,
|
|
231
|
+
source: line,
|
|
232
|
+
exitLabel: `__proc_${id}_exit`,
|
|
233
|
+
returnUsed: false
|
|
234
|
+
};
|
|
227
235
|
out.push({ text: `${name}:`, orig });
|
|
228
236
|
for (const r of regs) {
|
|
229
237
|
out.push({ text: ` PUSH ${r}`, orig });
|
|
@@ -237,6 +245,9 @@ function preprocess(source) {
|
|
|
237
245
|
if (!proc) {
|
|
238
246
|
throw new AsmError(".endp without .proc", orig, line, firstNonSpaceCol(line));
|
|
239
247
|
}
|
|
248
|
+
if (proc.returnUsed) {
|
|
249
|
+
out.push({ text: `${proc.exitLabel}:`, orig });
|
|
250
|
+
}
|
|
240
251
|
out.push(...popsAndRet(proc.regs, orig));
|
|
241
252
|
proc = null;
|
|
242
253
|
continue;
|
|
@@ -245,7 +256,12 @@ function preprocess(source) {
|
|
|
245
256
|
if (!proc) {
|
|
246
257
|
throw new AsmError(".return outside .proc", orig, line, firstNonSpaceCol(line));
|
|
247
258
|
}
|
|
248
|
-
|
|
259
|
+
if (proc.regs.length === 0) {
|
|
260
|
+
out.push({ text: ` RET`, orig });
|
|
261
|
+
} else {
|
|
262
|
+
proc.returnUsed = true;
|
|
263
|
+
out.push({ text: ` JMP ${proc.exitLabel}`, orig });
|
|
264
|
+
}
|
|
249
265
|
continue;
|
|
250
266
|
}
|
|
251
267
|
out.push({ text: line, orig });
|
|
@@ -742,6 +758,7 @@ function countDb(operands) {
|
|
|
742
758
|
function asm(source) {
|
|
743
759
|
const pp = preprocess(source);
|
|
744
760
|
const symbols = new Map;
|
|
761
|
+
const pending = [];
|
|
745
762
|
let pc = 0;
|
|
746
763
|
let lastLabel = "";
|
|
747
764
|
let ended = false;
|
|
@@ -760,7 +777,7 @@ function asm(source) {
|
|
|
760
777
|
lastLabel = parts.label;
|
|
761
778
|
}
|
|
762
779
|
if (parts.isEqu) {
|
|
763
|
-
symbols
|
|
780
|
+
tryDefineEqu(symbols, pending, labelName, parts.operands[0], pc, lastLabel, orig, line);
|
|
764
781
|
continue;
|
|
765
782
|
}
|
|
766
783
|
symbols.set(labelName.toUpperCase(), pc);
|
|
@@ -800,6 +817,7 @@ function asm(source) {
|
|
|
800
817
|
throw new AsmError(e.message, orig, line, firstNonSpaceCol(line));
|
|
801
818
|
}
|
|
802
819
|
}
|
|
820
|
+
resolvePendingEqus(symbols, pending);
|
|
803
821
|
const sections = [];
|
|
804
822
|
let current = null;
|
|
805
823
|
const sectionNames = new Set;
|
|
@@ -861,6 +879,50 @@ function asm(source) {
|
|
|
861
879
|
}
|
|
862
880
|
return sections;
|
|
863
881
|
}
|
|
882
|
+
function isUnknownSymbolErr(e) {
|
|
883
|
+
return e instanceof Error && /^unknown symbol:/.test(e.message);
|
|
884
|
+
}
|
|
885
|
+
function tryDefineEqu(symbols, pending, name, expr, pc, lastLabel, orig, line) {
|
|
886
|
+
try {
|
|
887
|
+
symbols.set(name.toUpperCase(), evalExpr(expr, symbols, pc, lastLabel));
|
|
888
|
+
} catch (e) {
|
|
889
|
+
if (isUnknownSymbolErr(e)) {
|
|
890
|
+
pending.push({ name, expr, pc, lastLabel, orig, line });
|
|
891
|
+
} else {
|
|
892
|
+
throw e;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function resolvePendingEqus(symbols, pending) {
|
|
897
|
+
while (pending.length > 0) {
|
|
898
|
+
let progress = false;
|
|
899
|
+
const next = [];
|
|
900
|
+
for (const p of pending) {
|
|
901
|
+
try {
|
|
902
|
+
symbols.set(p.name.toUpperCase(), evalExpr(p.expr, symbols, p.pc, p.lastLabel));
|
|
903
|
+
progress = true;
|
|
904
|
+
} catch (e) {
|
|
905
|
+
if (isUnknownSymbolErr(e)) {
|
|
906
|
+
next.push(p);
|
|
907
|
+
} else {
|
|
908
|
+
throw new AsmError(e.message, p.orig, p.line, firstNonSpaceCol(p.line));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
if (!progress) {
|
|
913
|
+
const p = next[0];
|
|
914
|
+
try {
|
|
915
|
+
evalExpr(p.expr, symbols, p.pc, p.lastLabel);
|
|
916
|
+
} catch (e) {
|
|
917
|
+
throw new AsmError(e.message, p.orig, p.line, firstNonSpaceCol(p.line));
|
|
918
|
+
}
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
pending.length = 0;
|
|
922
|
+
pending.push(...next);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
var DATA_DIRECTIVES = new Set(["DB", "DW", "DS"]);
|
|
864
926
|
if (false) {}
|
|
865
927
|
|
|
866
928
|
// src/lib/terminal/rk86_terminal.ts
|
|
@@ -871,7 +933,7 @@ import { basename } from "path";
|
|
|
871
933
|
// packages/rk86/package.json
|
|
872
934
|
var package_default = {
|
|
873
935
|
name: "rk86",
|
|
874
|
-
version: "2.0.
|
|
936
|
+
version: "2.0.31",
|
|
875
937
|
description: "\u042D\u043C\u0443\u043B\u044F\u0442\u043E\u0440 \u0420\u0430\u0434\u0438\u043E-86\u0420\u041A (Intel 8080) \u0434\u043B\u044F \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0430",
|
|
876
938
|
bin: {
|
|
877
939
|
rk86: "rk86.js"
|
|
@@ -889,7 +951,7 @@ var package_default = {
|
|
|
889
951
|
license: "MIT",
|
|
890
952
|
repository: {
|
|
891
953
|
type: "git",
|
|
892
|
-
url: "https://github.com/begoon/rk86-js
|
|
954
|
+
url: "https://github.com/begoon/rk86-js"
|
|
893
955
|
}
|
|
894
956
|
};
|
|
895
957
|
|
|
@@ -1836,7 +1898,10 @@ var parse = (binary) => {
|
|
|
1836
1898
|
};
|
|
1837
1899
|
var convert_hex_to_binary = function(text) {
|
|
1838
1900
|
const lines = text.split(`
|
|
1839
|
-
`).filter((line) => line.trim().length).filter((line) =>
|
|
1901
|
+
`).filter((line) => line.trim().length).filter((line) => {
|
|
1902
|
+
const c = line.trim()[0];
|
|
1903
|
+
return c !== ";" && c !== "#" && c !== "!";
|
|
1904
|
+
});
|
|
1840
1905
|
const image = [];
|
|
1841
1906
|
for (const line of lines) {
|
|
1842
1907
|
const hex_line = line.slice(5).trim();
|
|
@@ -2206,7 +2271,7 @@ class Memory {
|
|
|
2206
2271
|
this.last_access_address = addr;
|
|
2207
2272
|
this.last_access_operation = "write";
|
|
2208
2273
|
this.tracer?.("write", addr);
|
|
2209
|
-
if (addr <
|
|
2274
|
+
if (addr < 57344)
|
|
2210
2275
|
this.buf[addr] = byte;
|
|
2211
2276
|
const ppi_reg = addr & 57347;
|
|
2212
2277
|
const vg75_reg = addr & 57345;
|
|
@@ -2257,10 +2322,13 @@ class Memory {
|
|
|
2257
2322
|
}
|
|
2258
2323
|
if (vg75_reg === 49152 && this.vg75_c001_00_cmd === 2) {
|
|
2259
2324
|
this.video_screen_size_y_buf = (byte & 63) + 1;
|
|
2325
|
+
this.machine.screen.vrtc_rows = (byte >> 6 & 3) + 1;
|
|
2260
2326
|
this.vg75_c001_00_cmd += 1;
|
|
2261
2327
|
return;
|
|
2262
2328
|
}
|
|
2263
2329
|
if (vg75_reg === 49152 && this.vg75_c001_00_cmd === 3) {
|
|
2330
|
+
this.machine.screen.set_char_height((byte & 15) + 1);
|
|
2331
|
+
this.machine.screen.underline_scanline = byte >> 4 & 15;
|
|
2264
2332
|
this.vg75_c001_00_cmd += 1;
|
|
2265
2333
|
return;
|
|
2266
2334
|
}
|
|
@@ -2272,6 +2340,7 @@ class Memory {
|
|
|
2272
2340
|
this.machine.screen.set_geometry(this.video_screen_size_x, this.video_screen_size_y);
|
|
2273
2341
|
}
|
|
2274
2342
|
this.machine.screen.transparent_attr = (byte & 64) === 0;
|
|
2343
|
+
this.machine.screen.hrtc_chars = ((byte & 15) + 1) * 2;
|
|
2275
2344
|
return;
|
|
2276
2345
|
}
|
|
2277
2346
|
if (vt57_reg === 57352 && byte === 128) {
|
|
@@ -2354,74 +2423,103 @@ class Memory {
|
|
|
2354
2423
|
// src/lib/core/rk86_runner.ts
|
|
2355
2424
|
class Runner {
|
|
2356
2425
|
paused = false;
|
|
2426
|
+
turbo = false;
|
|
2427
|
+
hardware_id_enabled = false;
|
|
2428
|
+
stc_streak = 0;
|
|
2357
2429
|
tracer = null;
|
|
2358
2430
|
last_instructions = [];
|
|
2359
|
-
previous_batch_time = 0;
|
|
2360
2431
|
total_ticks = 0;
|
|
2361
|
-
|
|
2432
|
+
total_instructions = 0;
|
|
2362
2433
|
last_iff = 0;
|
|
2363
2434
|
sound = null;
|
|
2364
2435
|
sound_factory;
|
|
2365
2436
|
instructions_per_millisecond = 0;
|
|
2366
2437
|
ticks_per_millisecond = 0;
|
|
2367
2438
|
FREQ = 1780000;
|
|
2368
|
-
TICK_PER_MS;
|
|
2369
2439
|
execute_timer;
|
|
2370
2440
|
machine;
|
|
2441
|
+
BATCH_TICKS;
|
|
2442
|
+
TICKS_PER_WALL_MS;
|
|
2371
2443
|
constructor(machine) {
|
|
2372
2444
|
this.machine = machine;
|
|
2373
|
-
this.
|
|
2445
|
+
this.BATCH_TICKS = this.FREQ / 100;
|
|
2446
|
+
this.TICKS_PER_WALL_MS = this.FREQ / 1000;
|
|
2374
2447
|
this.machine.io.interrupt = (iff) => this.interrupt(iff);
|
|
2375
2448
|
this.machine.cpu.jump(63488);
|
|
2376
2449
|
}
|
|
2377
2450
|
interrupt(iff) {
|
|
2378
|
-
if (!this.sound)
|
|
2451
|
+
if (!this.sound || this.turbo)
|
|
2379
2452
|
return;
|
|
2380
2453
|
if (this.last_iff == iff)
|
|
2381
2454
|
return;
|
|
2382
|
-
if (this.last_iff == 0 && iff == 1) {
|
|
2383
|
-
this.last_iff_raise_ticks = this.total_ticks;
|
|
2384
|
-
}
|
|
2385
|
-
if (this.last_iff == 1 && iff == 0) {
|
|
2386
|
-
const tone_ticks = this.total_ticks - this.last_iff_raise_ticks;
|
|
2387
|
-
const tone = this.FREQ / (tone_ticks * 2);
|
|
2388
|
-
const duration = 1 / tone;
|
|
2389
|
-
this.sound.play(tone, duration);
|
|
2390
|
-
}
|
|
2391
2455
|
this.last_iff = iff;
|
|
2456
|
+
this.sound.out(iff, this.total_ticks);
|
|
2392
2457
|
}
|
|
2393
2458
|
init_sound(enabled) {
|
|
2394
2459
|
if (enabled && this.sound == null && this.sound_factory) {
|
|
2395
2460
|
this.sound = this.sound_factory();
|
|
2396
2461
|
this.machine.log("\u0437\u0432\u0443\u043A \u0432\u043A\u043B\u044E\u0447\u0435\u043D");
|
|
2397
2462
|
} else if (!enabled) {
|
|
2463
|
+
this.sound?.done?.();
|
|
2398
2464
|
this.sound = null;
|
|
2399
2465
|
this.machine.log("\u0437\u0432\u0443\u043A \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D");
|
|
2400
2466
|
}
|
|
2401
2467
|
}
|
|
2402
2468
|
execute(options = {}) {
|
|
2403
|
-
const { terminate_address, on_terminate, exit_on_halt, on_halt, on_batch_complete
|
|
2469
|
+
const { terminate_address, on_terminate, exit_on_halt, on_halt, on_batch_complete } = options;
|
|
2470
|
+
if (options.turbo !== undefined)
|
|
2471
|
+
this.turbo = options.turbo;
|
|
2404
2472
|
clearTimeout(this.execute_timer);
|
|
2405
|
-
const
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2473
|
+
const QUANTUM_BUDGET_MS = 5;
|
|
2474
|
+
const TURBO_BUDGET_MS = 50;
|
|
2475
|
+
const MAX_DT_MS = 100;
|
|
2476
|
+
const PAUSED_TICK_MS = 50;
|
|
2477
|
+
const PERF_WINDOW_MS = 500;
|
|
2478
|
+
let next_batch_boundary = this.total_ticks + this.BATCH_TICKS;
|
|
2479
|
+
let last_call_time = performance.now();
|
|
2480
|
+
let perf_window_start_wall = last_call_time;
|
|
2481
|
+
let perf_window_start_instructions = this.total_instructions;
|
|
2482
|
+
let perf_window_start_ticks = this.total_ticks;
|
|
2483
|
+
const tick = () => {
|
|
2484
|
+
if (this.paused) {
|
|
2485
|
+
last_call_time = performance.now();
|
|
2486
|
+
perf_window_start_wall = last_call_time;
|
|
2487
|
+
perf_window_start_instructions = this.total_instructions;
|
|
2488
|
+
perf_window_start_ticks = this.total_ticks;
|
|
2489
|
+
next_batch_boundary = this.total_ticks + this.BATCH_TICKS;
|
|
2490
|
+
this.execute_timer = setTimeout(tick, PAUSED_TICK_MS);
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
const call_start = performance.now();
|
|
2494
|
+
const dt_ms = Math.min(call_start - last_call_time, MAX_DT_MS);
|
|
2495
|
+
last_call_time = call_start;
|
|
2496
|
+
const target_total = this.turbo ? Number.POSITIVE_INFINITY : this.total_ticks + dt_ms * this.TICKS_PER_WALL_MS;
|
|
2497
|
+
const deadline = call_start + (this.turbo ? TURBO_BUDGET_MS : QUANTUM_BUDGET_MS);
|
|
2498
|
+
let terminated = false;
|
|
2499
|
+
while (!this.paused && !terminated && this.total_ticks < target_total && performance.now() < deadline) {
|
|
2412
2500
|
if (this.tracer) {
|
|
2413
2501
|
this.tracer("before");
|
|
2414
2502
|
if (this.paused)
|
|
2415
2503
|
break;
|
|
2416
2504
|
}
|
|
2417
2505
|
this.last_instructions.push(this.machine.cpu.pc);
|
|
2418
|
-
if (this.last_instructions.length > 5)
|
|
2506
|
+
if (this.last_instructions.length > 5)
|
|
2419
2507
|
this.last_instructions.shift();
|
|
2420
|
-
|
|
2508
|
+
const opcode_pc = this.machine.cpu.pc;
|
|
2421
2509
|
this.machine.memory.invalidate_access_variables();
|
|
2422
2510
|
const instruction_ticks = this.machine.cpu.instruction();
|
|
2423
|
-
batch_ticks += instruction_ticks;
|
|
2424
2511
|
this.total_ticks += instruction_ticks;
|
|
2512
|
+
this.total_instructions += 1;
|
|
2513
|
+
if (this.hardware_id_enabled) {
|
|
2514
|
+
if (this.machine.memory.read_raw(opcode_pc) === 55) {
|
|
2515
|
+
if (++this.stc_streak >= 4) {
|
|
2516
|
+
this.stc_streak = 0;
|
|
2517
|
+
this.fire_hardware_id();
|
|
2518
|
+
}
|
|
2519
|
+
} else {
|
|
2520
|
+
this.stc_streak = 0;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2425
2523
|
if (this.tracer) {
|
|
2426
2524
|
this.tracer("after");
|
|
2427
2525
|
if (this.paused)
|
|
@@ -2430,7 +2528,6 @@ class Runner {
|
|
|
2430
2528
|
if (this.machine.ui.visualizer_visible && this.machine.ui.on_visualizer_hit) {
|
|
2431
2529
|
this.machine.ui.on_visualizer_hit(this.machine.memory.read_raw(this.machine.cpu.pc));
|
|
2432
2530
|
}
|
|
2433
|
-
batch_instructions += 1;
|
|
2434
2531
|
if (terminate_address !== undefined && this.machine.cpu.pc === terminate_address) {
|
|
2435
2532
|
on_terminate?.();
|
|
2436
2533
|
return;
|
|
@@ -2440,19 +2537,28 @@ class Runner {
|
|
|
2440
2537
|
on_terminate?.();
|
|
2441
2538
|
return;
|
|
2442
2539
|
}
|
|
2443
|
-
if (on_halt && on_halt())
|
|
2444
|
-
|
|
2540
|
+
if (on_halt && on_halt()) {
|
|
2541
|
+
terminated = true;
|
|
2542
|
+
break;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
if (this.total_ticks >= next_batch_boundary) {
|
|
2546
|
+
this.machine.screen.tick_cursor(this.total_ticks, this.FREQ * (this.machine.screen.cursor_rate / 1000));
|
|
2547
|
+
on_batch_complete?.();
|
|
2548
|
+
next_batch_boundary += this.BATCH_TICKS;
|
|
2445
2549
|
}
|
|
2446
2550
|
}
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2551
|
+
const window_elapsed = performance.now() - perf_window_start_wall;
|
|
2552
|
+
if (window_elapsed >= PERF_WINDOW_MS) {
|
|
2553
|
+
this.instructions_per_millisecond = (this.total_instructions - perf_window_start_instructions) / window_elapsed;
|
|
2554
|
+
this.ticks_per_millisecond = (this.total_ticks - perf_window_start_ticks) / window_elapsed;
|
|
2555
|
+
perf_window_start_wall = performance.now();
|
|
2556
|
+
perf_window_start_instructions = this.total_instructions;
|
|
2557
|
+
perf_window_start_ticks = this.total_ticks;
|
|
2558
|
+
}
|
|
2559
|
+
this.execute_timer = setTimeout(tick, 0);
|
|
2560
|
+
};
|
|
2561
|
+
tick();
|
|
2456
2562
|
}
|
|
2457
2563
|
pause() {
|
|
2458
2564
|
this.paused = true;
|
|
@@ -2464,11 +2570,19 @@ class Runner {
|
|
|
2464
2570
|
this.machine.cpu.jump(63488);
|
|
2465
2571
|
this.machine.keyboard.reset();
|
|
2466
2572
|
}
|
|
2573
|
+
fire_hardware_id() {
|
|
2574
|
+
const colorIdx = COLOR_MODES.indexOf(this.machine.screen.color_mode);
|
|
2575
|
+
this.machine.cpu.set_a(1);
|
|
2576
|
+
this.machine.cpu.set_b(colorIdx < 0 ? 0 : colorIdx);
|
|
2577
|
+
this.machine.cpu.set_c(this.turbo ? 1 : 0);
|
|
2578
|
+
this.machine.cpu.cf = 0;
|
|
2579
|
+
}
|
|
2467
2580
|
}
|
|
2468
2581
|
|
|
2469
2582
|
// src/lib/core/rk86_screen.ts
|
|
2470
2583
|
class Screen {
|
|
2471
|
-
static
|
|
2584
|
+
static CHAR_CLOCK_HZ = 8000000 / 6;
|
|
2585
|
+
static #IDLE_RENDER_MS = 40;
|
|
2472
2586
|
machine;
|
|
2473
2587
|
cursor_rate;
|
|
2474
2588
|
scale_x;
|
|
@@ -2484,8 +2598,13 @@ class Screen {
|
|
|
2484
2598
|
video_memory_base = 0;
|
|
2485
2599
|
video_memory_size = 0;
|
|
2486
2600
|
transparent_attr = false;
|
|
2601
|
+
char_height = 10;
|
|
2602
|
+
underline_scanline = 7;
|
|
2487
2603
|
color_mode = DEFAULT_COLOR_MODE;
|
|
2488
2604
|
ready = false;
|
|
2605
|
+
hrtc_chars = 8;
|
|
2606
|
+
vrtc_rows = 1;
|
|
2607
|
+
render_mode = "vg75";
|
|
2489
2608
|
renderer;
|
|
2490
2609
|
constructor(machine) {
|
|
2491
2610
|
this.machine = machine;
|
|
@@ -2540,19 +2659,44 @@ class Screen {
|
|
|
2540
2659
|
start(renderer) {
|
|
2541
2660
|
this.renderer = renderer;
|
|
2542
2661
|
this.renderer.connect(this.machine);
|
|
2543
|
-
this.
|
|
2662
|
+
this.schedule_next_render();
|
|
2663
|
+
}
|
|
2664
|
+
set_render_mode(mode) {
|
|
2665
|
+
if (this.render_mode === mode)
|
|
2666
|
+
return;
|
|
2667
|
+
this.render_mode = mode;
|
|
2668
|
+
}
|
|
2669
|
+
frame_period_ms() {
|
|
2670
|
+
const chars = (this.width + this.hrtc_chars) * (this.height + this.vrtc_rows) * this.char_height;
|
|
2671
|
+
return 1000 * chars / Screen.CHAR_CLOCK_HZ;
|
|
2544
2672
|
}
|
|
2545
2673
|
last_flip_ticks = 0;
|
|
2546
2674
|
tick_cursor(total_ticks, ticks_per_flip) {
|
|
2675
|
+
if (this.machine.runner.turbo) {
|
|
2676
|
+
this.cursor_state = true;
|
|
2677
|
+
this.last_flip_ticks = total_ticks;
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2547
2680
|
while (total_ticks - this.last_flip_ticks >= ticks_per_flip) {
|
|
2548
2681
|
this.cursor_state = !this.cursor_state;
|
|
2549
2682
|
this.last_flip_ticks += ticks_per_flip;
|
|
2550
2683
|
}
|
|
2551
2684
|
}
|
|
2552
|
-
render_loop() {
|
|
2685
|
+
render_loop = () => {
|
|
2553
2686
|
if (this.ready)
|
|
2554
2687
|
this.renderer.update();
|
|
2555
|
-
|
|
2688
|
+
this.schedule_next_render();
|
|
2689
|
+
};
|
|
2690
|
+
schedule_next_render() {
|
|
2691
|
+
if (!this.ready) {
|
|
2692
|
+
setTimeout(this.render_loop, Screen.#IDLE_RENDER_MS);
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
if (this.render_mode === "monitor" && typeof requestAnimationFrame !== "undefined") {
|
|
2696
|
+
requestAnimationFrame(this.render_loop);
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2699
|
+
setTimeout(this.render_loop, this.frame_period_ms());
|
|
2556
2700
|
}
|
|
2557
2701
|
last_width = -1;
|
|
2558
2702
|
last_height = -1;
|
|
@@ -2560,7 +2704,7 @@ class Screen {
|
|
|
2560
2704
|
this.width = width;
|
|
2561
2705
|
this.height = height;
|
|
2562
2706
|
this.video_memory_size = width * height;
|
|
2563
|
-
this.machine.ui.update_screen_geometry(this.width, this.height);
|
|
2707
|
+
this.machine.ui.update_screen_geometry(this.width, this.height, this.char_height);
|
|
2564
2708
|
if (this.last_width === this.width && this.last_height === this.height)
|
|
2565
2709
|
return;
|
|
2566
2710
|
this.machine.log(`\u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D \u0440\u0430\u0437\u043C\u0435\u0440 \u044D\u043A\u0440\u0430\u043D\u0430: ${width} x ${height}`);
|
|
@@ -2569,6 +2713,12 @@ class Screen {
|
|
|
2569
2713
|
if (this.last_video_memory_base !== -1)
|
|
2570
2714
|
this.ready = true;
|
|
2571
2715
|
}
|
|
2716
|
+
set_char_height(char_height) {
|
|
2717
|
+
if (this.char_height === char_height)
|
|
2718
|
+
return;
|
|
2719
|
+
this.char_height = char_height;
|
|
2720
|
+
this.machine.ui.update_screen_geometry(this.width, this.height, this.char_height);
|
|
2721
|
+
}
|
|
2572
2722
|
last_video_memory_base = -1;
|
|
2573
2723
|
set_video_memory(base) {
|
|
2574
2724
|
this.video_memory_base = base;
|
|
@@ -2992,21 +3142,34 @@ class TerminalRenderer {
|
|
|
2992
3142
|
addr += w;
|
|
2993
3143
|
}
|
|
2994
3144
|
let prevAnsi = -1;
|
|
3145
|
+
let prevReverse = false;
|
|
3146
|
+
let prevUnderline = false;
|
|
2995
3147
|
for (let x = 0;x < w; x++) {
|
|
2996
3148
|
const cell = cells[x];
|
|
2997
3149
|
const ch = cell.blink && blinkOff ? 0 : cell.ch;
|
|
2998
3150
|
const glyph = rk86char(ch);
|
|
2999
|
-
let
|
|
3151
|
+
let colorAttrs = cell.attrs;
|
|
3000
3152
|
if (offset && x + 1 < w && cells[x + 1].isFA) {
|
|
3001
|
-
|
|
3153
|
+
colorAttrs = cells[x + 1].attrs;
|
|
3002
3154
|
}
|
|
3003
|
-
const ansi = rgbToAnsiBaseFg(attrToRgb(mode,
|
|
3155
|
+
const ansi = rgbToAnsiBaseFg(attrToRgb(mode, colorAttrs));
|
|
3156
|
+
const reverse = !cell.isFA && (cell.attrs & 16) !== 0;
|
|
3157
|
+
const underline = !cell.isFA && (cell.attrs & 32) !== 0;
|
|
3004
3158
|
if (ansi !== prevAnsi) {
|
|
3005
3159
|
line += `\x1B[${ansi}m`;
|
|
3006
3160
|
prevAnsi = ansi;
|
|
3007
3161
|
}
|
|
3162
|
+
if (reverse !== prevReverse) {
|
|
3163
|
+
line += reverse ? `\x1B[7m` : `\x1B[27m`;
|
|
3164
|
+
prevReverse = reverse;
|
|
3165
|
+
}
|
|
3166
|
+
if (underline !== prevUnderline) {
|
|
3167
|
+
line += underline ? `\x1B[4m` : `\x1B[24m`;
|
|
3168
|
+
prevUnderline = underline;
|
|
3169
|
+
}
|
|
3008
3170
|
if (x === screen.cursor_x && y === screen.cursor_y) {
|
|
3009
3171
|
line += `\x1B[4m${glyph}\x1B[24m`;
|
|
3172
|
+
prevUnderline = false;
|
|
3010
3173
|
} else {
|
|
3011
3174
|
line += glyph;
|
|
3012
3175
|
}
|
|
@@ -3299,6 +3462,8 @@ async function main() {
|
|
|
3299
3462
|
const machine = machineBuilder;
|
|
3300
3463
|
machine.ui = new TerminalUI;
|
|
3301
3464
|
machine.memory = new Memory(machine);
|
|
3465
|
+
io.input = (port) => machine.memory.read(port | port << 8);
|
|
3466
|
+
io.output = (port, w8) => machine.memory.write(port | port << 8, w8);
|
|
3302
3467
|
machine.cpu = new I8080(machine);
|
|
3303
3468
|
machine.screen = new Screen(machine);
|
|
3304
3469
|
machine.screen.color_mode = colorMode;
|
|
@@ -3323,7 +3488,7 @@ async function main() {
|
|
|
3323
3488
|
for (const section of sections) {
|
|
3324
3489
|
const data = section.data;
|
|
3325
3490
|
for (let i = 0;i < data.length; i++) {
|
|
3326
|
-
machine.memory.
|
|
3491
|
+
machine.memory.write_raw(section.start + i, data[i]);
|
|
3327
3492
|
}
|
|
3328
3493
|
const name = section.name ? ` [${section.name}]` : "";
|
|
3329
3494
|
lines.push(`${hex16(section.start)}-${hex16(section.end)}${name} (${data.length} \u0431\u0430\u0439\u0442)`);
|