dart/bgi/demo_bgi.dart · 3344 字节 · 下载原文
// demo_bgi.dart —— **第 3 层:传统 BGI 图形接口**(Dart)
// demo_bgi.dart — **Layer 3: the classic BGI graphics interface** (Dart)
//
// BGI(Borland Graphics Interface)是固定分辨率 + 16 个索引色的一层:
// `initgraph` 开一块 640×480 的固定画布,`setcolor(4)` 说的是"红"而不是 RGB 0x000004,
// `closegraph` 收尾。落笔由 `Lib/shared/bgi.vml` 转成平台的 `ui_*` 图元。
// BGI (Borland Graphics Interface) is the fixed-resolution + 16 indexed colors layer:
// `initgraph` opens a fixed 640x480 canvas, `setcolor(4)` means "red" (not RGB 0x000004),
// and `closegraph` wraps up. `Lib/shared/bgi.vml` turns every call into the platform's `ui_*`.
//
// ## 前两个参数是 int 指针
// ## The first two parameters are int pointers
//
// Dart 没有取地址运算符,所以先 `vml_alloc(8)` 拿两个字的可写内存,把 `gd` / `gd + 4`
// 当指针传给库(再 `poke(0, …)` 清零 ⇒ 库按 DETECT 自己挑 VGA + VGAHI)。
// Dart has no address-of operator, so `vml_alloc(8)` gives two writable words and we pass
// `gd` / `gd + 4` as the pointers (zeroed with `poke(0, …)` so the library sees DETECT).
//
// ## 声明 / 链接
// ## Declarations / linking
//
// `Lib/dart/shared.dart` 里 BGI 那一段是**文档表**(注释行);本前端的惯例是直接调用。
// 链接走文件顶部那行 `#param lib(bgi)`(Dart 的 `import` 是**真的读声明文件**,
// 而 BGI 没有 `.dart` 声明文件,所以这里用 `#param` 把 `Lib/shared/bgi.vml` 链进来)。
// The BGI section of `Lib/dart/shared.dart` is a **doc table** (comment lines); this frontend's
// convention is a direct call. Linking goes through the `#param lib(bgi)` line at the top
// (Dart's `import` really reads a declaration file, and BGI has no `.dart` one, so `#param`
// links `Lib/shared/bgi.vml`).
//
// 跑法:手机 `vml run examples/dart/bgi/demo_bgi.dart`;
// 桌面 `dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/dart/bgi/demo_bgi.dart --frames /tmp/fr`
// How to run: on the phone `vml run examples/dart/bgi/demo_bgi.dart`;
// on the desktop `dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/dart/bgi/demo_bgi.dart --frames /tmp/fr`
#param lib(bgi)
void main() {
// ── 1. 开场三行:分配 gd/gm 两个字并清零,再 initgraph ──
// ── 1. Opening three lines: allocate two words for gd/gm, zero them, then initgraph ──
var gd = vml_alloc(8);
poke(0, gd);
poke(0, gd + 4);
initgraph(gd, gd + 4, "");
// ── 2. 铺底:索引色 0 = BLACK;cleardevice 用当前背景色刷满 ──
// ── 2. Background: index 0 = BLACK; cleardevice floods with the current background color ──
setbkcolor(0);
cleardevice();
// ── 3. 画两三个图元:索引色 4 = RED,14 = YELLOW ──
// ── 3. Draw a few primitives: index 4 = RED, 14 = YELLOW ──
setcolor(4);
line(80, 60, 560, 360);
circle(320, 240, 90);
setcolor(14);
rectangle(40, 40, 600, 440);
outtextxy(200, 80, "BGI demo (Dart)");
// ── 4. 收尾:不调 getch()(本平台图形窗口里按不了键),直接 closegraph ──
// ── 4. Wrap-up: no getch() (a graphics window cannot take keys here), just closegraph ──
ui_2d_present()
closegraph();
}