libbgi: выделить графику BGI в отдельную библиотеку + тест спрайтов

Графика вынесена из libc/ в новую библиотеку libbgi/:
  - common/  — mode-agnostic математика и состояние (один исходник,
    .rel попадает в оба driver-архива);
  - bgi256/ + bgi16/ — mode-specific leaf'ы (raw-плот/чтение/спаны);
  - include/ — graphics.h + gfx.h; _bgi.h — внутренний заголовок.
Собираются lib/bgi256.lib (и bgi16.lib в Фазе 2); выбор режима
линковкой через sprinter-cc --gfx 256|16.  libc/ теперь без графики.

tests/bgi_img — тест спрайтов getimage/putimage/imagesize (5 операций
COPY/XOR/OR/AND/NOT + XOR-round-trip + self-check imagesize).
Проверен автотестом в MAME.

Примечание: make size-check пока красный (gfx_dbuf/gfx_demo выросли
после реорга) — закрыть по завершении миграции libbgi.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 14:18:33 +03:00
parent 3bf50f7ff7
commit 52636a5d6e
164 changed files with 1072 additions and 1440 deletions
+62 -49
View File
@@ -1,15 +1,23 @@
/*
* gfx_demo — exercises the libc/gfx primitives. Shows:
* 1. accelerator-backed gfx_clear256 / gfx_hline256 / gfx_vline256 / gfx_fill_rect256
* 2. gfx_rect256 outline, gfx_line256 diagonals (Bresenham via putpixel)
* 3. a grey-ramp palette
* gfx_demo — exercises the BGI primitives (bgi256.lib). Shows:
* 1. cleardevice / line (orthogonal frame via horizontal/vertical lines)
* 2. rectangle outlines, line diagonals (Bresenham)
* 3. bar filled-rect colour bars (accelerator-backed)
* 4. a grey-ramp palette
*
* Migrated с низкоуровневого gfx.h drawing-API на BGI (graphics.h).
* Режим 0x81 (320×256×256) выбирается линковкой: EXTRA_FLAGS=--gfx 256
* (см. Makefile). Палитура грузится через gfx_pal_load (mode-agnostic,
* остался в gfx.h) — BGI initgraph уже загрузил EGA-палитру, мы её
* подменяем серым клином.
*
* Press a key to advance through each stage.
*/
#include <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <graphics.h>
#include <gfx.h> /* GFX_WIDTH/HEIGHT, gfx_pal_load (mode-agnostic) */
#include <stdint.h>
static uint8_t palette_data[256 * 4];
@@ -32,69 +40,74 @@ int main(void)
palette_data[i * 4 + 3] = 0;
}
uint8_t prev = gfx_init(GFX_MODE_320x256x256, 0);
initgraph();
gfx_pal_load(0, 0, 0, palette_data);
/* --- Stage 1: orthogonal frame via hline / vline ----------------- */
gfx_clear256(0x40);
gfx_hline256(1, 1, GFX_WIDTH - 2, 0xFF);
gfx_hline256(1, GFX_HEIGHT - 2, GFX_WIDTH - 2, 0xFF);
gfx_vline256(1, 2, GFX_HEIGHT - 4, 0xFF);
gfx_vline256(GFX_WIDTH - 2, 2, GFX_HEIGHT - 4, 0xFF);
/* --- Stage 1: orthogonal frame via horizontal/vertical lines ------ */
setbkcolor(0x40); cleardevice();
setcolor(0xFF);
line(1, 1, GFX_WIDTH - 2, 1); /* top */
line(1, GFX_HEIGHT - 2, GFX_WIDTH - 2, GFX_HEIGHT - 2); /* bottom */
line(1, 2, 1, GFX_HEIGHT - 4); /* left */
line(GFX_WIDTH - 2, 2, GFX_WIDTH - 2, GFX_HEIGHT - 4); /* right */
wait_key();
/* --- Stage 2: nested rectangles -------------------------------- */
gfx_clear256(0x20);
for (int i = 0; i < 16; i++)
gfx_rect256(i * 10, i * 8,
GFX_WIDTH - i * 20,
GFX_HEIGHT - i * 16,
(uint8_t)(0x40 + i * 8));
wait_key();
/* --- Stage 3: filled-rect colour bars --------------------------- */
gfx_clear256(0);
/* Tall-narrow rects (w=20, h=128) — heuristic picks vertical orient. */
/* --- Stage 2: nested rectangles --------------------------------- */
setbkcolor(0x20); cleardevice();
for (int i = 0; i < 16; i++) {
gfx_fill_rect256(i * 20, 0, 20, 128, (uint8_t)(i * 16));
gfx_fill_rect256(i * 20 + 0, 128, 20, 128, (uint8_t)(255 - i * 16));
setcolor((uint8_t)(0x40 + i * 8));
rectangle(i * 10, i * 8,
GFX_WIDTH - i * 20,
GFX_HEIGHT - i * 16);
}
wait_key();
/* --- Stage 3b: wide-short rects + a grid of small squares -------- */
gfx_clear256(0x08);
/* Wide-short stripes (w=320, h=16) — heuristic picks horizontal. */
for (int i = 0; i < 8; i++)
gfx_fill_rect256(0, i * 32, GFX_WIDTH, 16, (uint8_t)(0x40 + i * 24));
/* 8×8 small squares grid (w=h, heuristic picks either — same cost). */
for (int row = 0; row < 4; row++)
for (int col = 0; col < 16; col++)
gfx_fill_rect256(col * 20 + 4, 256 - 80 + row * 20, 12, 12,
(uint8_t)((row * 16 + col) * 4));
/* --- Stage 3: filled-rect colour bars (bar = залитый прямоугольник) */
setbkcolor(0); cleardevice();
for (int i = 0; i < 16; i++) {
setfillstyle(SOLID_FILL, (uint8_t)(i * 16));
bar(i * 20, 0, i * 20 + 19, 127);
setfillstyle(SOLID_FILL, (uint8_t)(255 - i * 16));
bar(i * 20, 128, i * 20 + 19, 255);
}
wait_key();
/* --- Stage 4: diagonal lines via Bresenham ---------------------- */
gfx_clear256(0x18);
/* "Star" of lines from centre to a circle of endpoints. */
/* --- Stage 3b: wide-short stripes + a grid of small squares ------ */
setbkcolor(0x08); cleardevice();
for (int i = 0; i < 8; i++) {
setfillstyle(SOLID_FILL, (uint8_t)(0x40 + i * 24));
bar(0, i * 32, GFX_WIDTH - 1, i * 32 + 15);
}
for (int row = 0; row < 4; row++)
for (int col = 0; col < 16; col++) {
setfillstyle(SOLID_FILL, (uint8_t)((row * 16 + col) * 4));
bar(col * 20 + 4, 256 - 80 + row * 20,
col * 20 + 4 + 11, 256 - 80 + row * 20 + 11);
}
wait_key();
/* --- Stage 4: diagonal lines via Bresenham ----------------------- */
setbkcolor(0x18); cleardevice();
int cx = GFX_WIDTH / 2, cy = GFX_HEIGHT / 2;
for (int i = 0; i < 16; i++) {
int ex = i * (GFX_WIDTH - 1) / 15;
gfx_line256(cx, cy, ex, 0, 0xFF);
gfx_line256(cx, cy, ex, GFX_HEIGHT - 1, 0xC0);
setcolor(0xFF); line(cx, cy, ex, 0);
setcolor(0xC0); line(cx, cy, ex, GFX_HEIGHT - 1);
}
for (int i = 0; i < 16; i++) {
int ey = i * (GFX_HEIGHT - 1) / 15;
gfx_line256(cx, cy, 0, ey, 0x80);
gfx_line256(cx, cy, GFX_WIDTH - 1, ey, 0x40);
setcolor(0x80); line(cx, cy, 0, ey);
setcolor(0x40); line(cx, cy, GFX_WIDTH - 1, ey);
}
/* Box outline using gfx_line256. */
gfx_line256(0, 0, GFX_WIDTH - 1, 0, 0xFF);
gfx_line256(0, GFX_HEIGHT - 1, GFX_WIDTH - 1, GFX_HEIGHT - 1, 0xFF);
gfx_line256(0, 0, 0, GFX_HEIGHT - 1, 0xFF);
gfx_line256(GFX_WIDTH - 1, 0, GFX_WIDTH - 1, GFX_HEIGHT - 1, 0xFF);
/* Box outline. */
setcolor(0xFF);
line(0, 0, GFX_WIDTH - 1, 0);
line(0, GFX_HEIGHT - 1, GFX_WIDTH - 1, GFX_HEIGHT - 1);
line(0, 0, 0, GFX_HEIGHT - 1);
line(GFX_WIDTH - 1, 0, GFX_WIDTH - 1, GFX_HEIGHT - 1);
wait_key();
gfx_done(prev);
closegraph();
puts("done");
return 0;
}