rk86 2.0.31 → 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 +1 -1
- package/rk86.js +93 -44
package/package.json
CHANGED
package/rk86.js
CHANGED
|
@@ -933,7 +933,7 @@ import { basename } from "path";
|
|
|
933
933
|
// packages/rk86/package.json
|
|
934
934
|
var package_default = {
|
|
935
935
|
name: "rk86",
|
|
936
|
-
version: "2.0.
|
|
936
|
+
version: "2.0.31",
|
|
937
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",
|
|
938
938
|
bin: {
|
|
939
939
|
rk86: "rk86.js"
|
|
@@ -1898,7 +1898,10 @@ var parse = (binary) => {
|
|
|
1898
1898
|
};
|
|
1899
1899
|
var convert_hex_to_binary = function(text) {
|
|
1900
1900
|
const lines = text.split(`
|
|
1901
|
-
`).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
|
+
});
|
|
1902
1905
|
const image = [];
|
|
1903
1906
|
for (const line of lines) {
|
|
1904
1907
|
const hex_line = line.slice(5).trim();
|
|
@@ -2268,7 +2271,7 @@ class Memory {
|
|
|
2268
2271
|
this.last_access_address = addr;
|
|
2269
2272
|
this.last_access_operation = "write";
|
|
2270
2273
|
this.tracer?.("write", addr);
|
|
2271
|
-
if (addr <
|
|
2274
|
+
if (addr < 57344)
|
|
2272
2275
|
this.buf[addr] = byte;
|
|
2273
2276
|
const ppi_reg = addr & 57347;
|
|
2274
2277
|
const vg75_reg = addr & 57345;
|
|
@@ -2319,6 +2322,7 @@ class Memory {
|
|
|
2319
2322
|
}
|
|
2320
2323
|
if (vg75_reg === 49152 && this.vg75_c001_00_cmd === 2) {
|
|
2321
2324
|
this.video_screen_size_y_buf = (byte & 63) + 1;
|
|
2325
|
+
this.machine.screen.vrtc_rows = (byte >> 6 & 3) + 1;
|
|
2322
2326
|
this.vg75_c001_00_cmd += 1;
|
|
2323
2327
|
return;
|
|
2324
2328
|
}
|
|
@@ -2336,6 +2340,7 @@ class Memory {
|
|
|
2336
2340
|
this.machine.screen.set_geometry(this.video_screen_size_x, this.video_screen_size_y);
|
|
2337
2341
|
}
|
|
2338
2342
|
this.machine.screen.transparent_attr = (byte & 64) === 0;
|
|
2343
|
+
this.machine.screen.hrtc_chars = ((byte & 15) + 1) * 2;
|
|
2339
2344
|
return;
|
|
2340
2345
|
}
|
|
2341
2346
|
if (vt57_reg === 57352 && byte === 128) {
|
|
@@ -2423,21 +2428,22 @@ class Runner {
|
|
|
2423
2428
|
stc_streak = 0;
|
|
2424
2429
|
tracer = null;
|
|
2425
2430
|
last_instructions = [];
|
|
2426
|
-
previous_batch_time = 0;
|
|
2427
2431
|
total_ticks = 0;
|
|
2428
|
-
|
|
2432
|
+
total_instructions = 0;
|
|
2429
2433
|
last_iff = 0;
|
|
2430
2434
|
sound = null;
|
|
2431
2435
|
sound_factory;
|
|
2432
2436
|
instructions_per_millisecond = 0;
|
|
2433
2437
|
ticks_per_millisecond = 0;
|
|
2434
2438
|
FREQ = 1780000;
|
|
2435
|
-
TICK_PER_MS;
|
|
2436
2439
|
execute_timer;
|
|
2437
2440
|
machine;
|
|
2441
|
+
BATCH_TICKS;
|
|
2442
|
+
TICKS_PER_WALL_MS;
|
|
2438
2443
|
constructor(machine) {
|
|
2439
2444
|
this.machine = machine;
|
|
2440
|
-
this.
|
|
2445
|
+
this.BATCH_TICKS = this.FREQ / 100;
|
|
2446
|
+
this.TICKS_PER_WALL_MS = this.FREQ / 1000;
|
|
2441
2447
|
this.machine.io.interrupt = (iff) => this.interrupt(iff);
|
|
2442
2448
|
this.machine.cpu.jump(63488);
|
|
2443
2449
|
}
|
|
@@ -2446,22 +2452,15 @@ class Runner {
|
|
|
2446
2452
|
return;
|
|
2447
2453
|
if (this.last_iff == iff)
|
|
2448
2454
|
return;
|
|
2449
|
-
if (this.last_iff == 0 && iff == 1) {
|
|
2450
|
-
this.last_iff_raise_ticks = this.total_ticks;
|
|
2451
|
-
}
|
|
2452
|
-
if (this.last_iff == 1 && iff == 0) {
|
|
2453
|
-
const tone_ticks = this.total_ticks - this.last_iff_raise_ticks;
|
|
2454
|
-
const tone = this.FREQ / (tone_ticks * 2);
|
|
2455
|
-
const duration = 1 / tone;
|
|
2456
|
-
this.sound.play(tone, duration);
|
|
2457
|
-
}
|
|
2458
2455
|
this.last_iff = iff;
|
|
2456
|
+
this.sound.out(iff, this.total_ticks);
|
|
2459
2457
|
}
|
|
2460
2458
|
init_sound(enabled) {
|
|
2461
2459
|
if (enabled && this.sound == null && this.sound_factory) {
|
|
2462
2460
|
this.sound = this.sound_factory();
|
|
2463
2461
|
this.machine.log("\u0437\u0432\u0443\u043A \u0432\u043A\u043B\u044E\u0447\u0435\u043D");
|
|
2464
2462
|
} else if (!enabled) {
|
|
2463
|
+
this.sound?.done?.();
|
|
2465
2464
|
this.sound = null;
|
|
2466
2465
|
this.machine.log("\u0437\u0432\u0443\u043A \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D");
|
|
2467
2466
|
}
|
|
@@ -2471,28 +2470,46 @@ class Runner {
|
|
|
2471
2470
|
if (options.turbo !== undefined)
|
|
2472
2471
|
this.turbo = options.turbo;
|
|
2473
2472
|
clearTimeout(this.execute_timer);
|
|
2474
|
-
const
|
|
2475
|
-
const
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
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) {
|
|
2482
2500
|
if (this.tracer) {
|
|
2483
2501
|
this.tracer("before");
|
|
2484
2502
|
if (this.paused)
|
|
2485
2503
|
break;
|
|
2486
2504
|
}
|
|
2487
2505
|
this.last_instructions.push(this.machine.cpu.pc);
|
|
2488
|
-
if (this.last_instructions.length > 5)
|
|
2506
|
+
if (this.last_instructions.length > 5)
|
|
2489
2507
|
this.last_instructions.shift();
|
|
2490
|
-
}
|
|
2491
2508
|
const opcode_pc = this.machine.cpu.pc;
|
|
2492
2509
|
this.machine.memory.invalidate_access_variables();
|
|
2493
2510
|
const instruction_ticks = this.machine.cpu.instruction();
|
|
2494
|
-
batch_ticks += instruction_ticks;
|
|
2495
2511
|
this.total_ticks += instruction_ticks;
|
|
2512
|
+
this.total_instructions += 1;
|
|
2496
2513
|
if (this.hardware_id_enabled) {
|
|
2497
2514
|
if (this.machine.memory.read_raw(opcode_pc) === 55) {
|
|
2498
2515
|
if (++this.stc_streak >= 4) {
|
|
@@ -2511,7 +2528,6 @@ class Runner {
|
|
|
2511
2528
|
if (this.machine.ui.visualizer_visible && this.machine.ui.on_visualizer_hit) {
|
|
2512
2529
|
this.machine.ui.on_visualizer_hit(this.machine.memory.read_raw(this.machine.cpu.pc));
|
|
2513
2530
|
}
|
|
2514
|
-
batch_instructions += 1;
|
|
2515
2531
|
if (terminate_address !== undefined && this.machine.cpu.pc === terminate_address) {
|
|
2516
2532
|
on_terminate?.();
|
|
2517
2533
|
return;
|
|
@@ -2521,19 +2537,28 @@ class Runner {
|
|
|
2521
2537
|
on_terminate?.();
|
|
2522
2538
|
return;
|
|
2523
2539
|
}
|
|
2524
|
-
if (on_halt && on_halt())
|
|
2525
|
-
|
|
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;
|
|
2526
2549
|
}
|
|
2527
2550
|
}
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
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();
|
|
2537
2562
|
}
|
|
2538
2563
|
pause() {
|
|
2539
2564
|
this.paused = true;
|
|
@@ -2556,7 +2581,8 @@ class Runner {
|
|
|
2556
2581
|
|
|
2557
2582
|
// src/lib/core/rk86_screen.ts
|
|
2558
2583
|
class Screen {
|
|
2559
|
-
static
|
|
2584
|
+
static CHAR_CLOCK_HZ = 8000000 / 6;
|
|
2585
|
+
static #IDLE_RENDER_MS = 40;
|
|
2560
2586
|
machine;
|
|
2561
2587
|
cursor_rate;
|
|
2562
2588
|
scale_x;
|
|
@@ -2576,6 +2602,9 @@ class Screen {
|
|
|
2576
2602
|
underline_scanline = 7;
|
|
2577
2603
|
color_mode = DEFAULT_COLOR_MODE;
|
|
2578
2604
|
ready = false;
|
|
2605
|
+
hrtc_chars = 8;
|
|
2606
|
+
vrtc_rows = 1;
|
|
2607
|
+
render_mode = "vg75";
|
|
2579
2608
|
renderer;
|
|
2580
2609
|
constructor(machine) {
|
|
2581
2610
|
this.machine = machine;
|
|
@@ -2630,7 +2659,16 @@ class Screen {
|
|
|
2630
2659
|
start(renderer) {
|
|
2631
2660
|
this.renderer = renderer;
|
|
2632
2661
|
this.renderer.connect(this.machine);
|
|
2633
|
-
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;
|
|
2634
2672
|
}
|
|
2635
2673
|
last_flip_ticks = 0;
|
|
2636
2674
|
tick_cursor(total_ticks, ticks_per_flip) {
|
|
@@ -2644,10 +2682,21 @@ class Screen {
|
|
|
2644
2682
|
this.last_flip_ticks += ticks_per_flip;
|
|
2645
2683
|
}
|
|
2646
2684
|
}
|
|
2647
|
-
render_loop() {
|
|
2685
|
+
render_loop = () => {
|
|
2648
2686
|
if (this.ready)
|
|
2649
2687
|
this.renderer.update();
|
|
2650
|
-
|
|
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());
|
|
2651
2700
|
}
|
|
2652
2701
|
last_width = -1;
|
|
2653
2702
|
last_height = -1;
|
|
@@ -3439,7 +3488,7 @@ async function main() {
|
|
|
3439
3488
|
for (const section of sections) {
|
|
3440
3489
|
const data = section.data;
|
|
3441
3490
|
for (let i = 0;i < data.length; i++) {
|
|
3442
|
-
machine.memory.
|
|
3491
|
+
machine.memory.write_raw(section.start + i, data[i]);
|
|
3443
3492
|
}
|
|
3444
3493
|
const name = section.name ? ` [${section.name}]` : "";
|
|
3445
3494
|
lines.push(`${hex16(section.start)}-${hex16(section.end)}${name} (${data.length} \u0431\u0430\u0439\u0442)`);
|