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
+2 -1
View File
@@ -1,3 +1,4 @@
PROJ_ROOT := $(abspath $(CURDIR)/../..)
EXAMPLE := gfx_dbuf
EXAMPLE := gfx_dbuf
EXTRA_FLAGS := --gfx 256
include $(PROJ_ROOT)/app.mk
+40 -42
View File
@@ -1,29 +1,26 @@
/*
* gfx_dbuf — double-buffering demo.
* gfx_dbuf — double-buffering demo (BGI, bgi256.lib).
*
* Renders a moving rectangle by alternating between page 0 and page 1:
* - Each frame: draw to the HIDDEN page, then flip visible to it.
* - The page currently being displayed is never written to, so the
* user only sees fully-rendered frames (no half-drawn artefacts,
* no flicker from the per-frame clear).
* Рендерит движущийся прямоугольник, чередуя страницу 0 и 1:
* - Каждый кадр: рисуем на СКРЫТОЙ странице, затем делаем её видимой.
* - Видимая страница никогда не пишется → пользователь видит только
* целые кадры (без артефактов, без мерцания от per-frame clear).
*
* Indicators help verify the swap is actually happening:
* - A small colour swatch in the top-right alternates each frame:
* one shade when page 0 is shown, another when page 1. If the
* box motion looks smooth and the swatch flickers between the two
* shades at the animation rate, the swap is working.
* Переключение страниц и vsync — через mode-agnostic gfx_* (gfx.h,
* остались в BGI_GFX): gfx_set_draw_page / gfx_set_visible_page /
* gfx_get_visible_page / gfx_wait_vsync. Рисование — через BGI
* (graphics.h): cleardevice / bar / rectangle / outtextxy. Режим
* 0x81 выбирается линковкой: EXTRA_FLAGS=--gfx 256.
*
* NOTE: each graphics screen has its OWN palette page (screen 0 →
* palette 0, screen 1 → palette 1). We load the same palette into
* both so the colours look identical regardless of which page is
* currently visible. See memory/sprinter_graphics.md.
*
* Press any key to exit.
* Индикатор страницы (маленький swatch сверху-справа) меняет оттенок
* каждый кадр — если бокс движется плавно, а swatch мигает между двумя
* оттенками, своп работает. Press any key to exit.
*/
#include <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <graphics.h>
#include <gfx.h> /* double-buffering + vsync (mode-agnostic) */
#include <stdint.h>
static uint8_t palette[256 * 4];
@@ -48,42 +45,44 @@ static void make_palette(void)
static void draw_frame(int box_x, int box_y, uint8_t page_indicator)
{
gfx_clear256(COL_BG);
setbkcolor(COL_BG); cleardevice();
/* Static decoration — identical on both pages so the swap doesn't
* flicker the chrome. */
gfx_fill_rect256(0, 0, GFX_WIDTH, 8, COL_STRIPE);
gfx_fill_rect256(0, GFX_HEIGHT - 8, GFX_WIDTH, 8, COL_STRIPE);
setfillstyle(SOLID_FILL, COL_STRIPE);
bar(0, 0, GFX_WIDTH - 1, 7);
bar(0, GFX_HEIGHT - 8, GFX_WIDTH - 1, GFX_HEIGHT - 1);
gfx_text256(8, 16, "double-buffering demo", COL_TEXT, COL_BG);
gfx_text256(8, GFX_HEIGHT - 24,
"press a key to exit", COL_TEXT, COL_BG);
setcolor(COL_TEXT);
outtextxy(8, 16, "double-buffering demo");
outtextxy(8, GFX_HEIGHT - 24, "press a key to exit");
/* Page indicator — different shade for each page so a flickering
* box here proves the swap is happening. */
gfx_fill_rect256(GFX_WIDTH - 24, 16, 12, 12,
page_indicator ? COL_PAGE1 : COL_PAGE0);
/* Page indicator — different shade per page: flicker here proves
* the swap is happening. */
setfillstyle(SOLID_FILL, page_indicator ? COL_PAGE1 : COL_PAGE0);
bar(GFX_WIDTH - 24, 16, GFX_WIDTH - 24 + 11, 16 + 11);
/* The animated box. */
gfx_fill_rect256(box_x, box_y, 40, 30, COL_BOX);
gfx_rect256 (box_x, box_y, 40, 30, COL_BLACK);
setfillstyle(SOLID_FILL, COL_BOX);
bar(box_x, box_y, box_x + 39, box_y + 29);
setcolor(COL_BLACK);
rectangle(box_x, box_y, box_x + 39, box_y + 29);
}
int main(void)
{
make_palette();
uint8_t prev = gfx_init(GFX_MODE_320x256x256, 0);
initgraph();
/* Each graphics screen has its own palette page (0→pal 0, 1→pal 1).
* Load the same data into both so the visual swap is seamless. */
/* Каждая графическая страница имеет свою палитру (0→pal 0, 1→pal 1).
* Грузим одну и ту же в обе — визуальный своп бесшовный. */
gfx_pal_load(0, 0, 0, palette);
gfx_pal_load(1, 0, 0, palette);
/* Clear both pages so the very first flip doesn't reveal garbage. */
gfx_set_draw_page(0);
gfx_clear256(COL_BG);
gfx_set_draw_page(1);
gfx_clear256(COL_BG);
/* Очистить обе страницы, чтобы первый флип не вскрыл мусор. */
setbkcolor(COL_BG);
gfx_set_draw_page(0); cleardevice();
gfx_set_draw_page(1); cleardevice();
/* Bouncing rect state. */
int box_x = 10;
@@ -98,9 +97,8 @@ int main(void)
draw_frame(box_x, box_y, hidden);
/* Wait for the next frame interrupt before flipping, so the
* page swap lands during vertical retrace and the user never
* sees a half-drawn frame. */
/* Ждать следующий кадр перед флипом — своп падает в vblank,
* пользователь не видит полунарисованный кадр. */
gfx_wait_vsync();
gfx_set_visible_page(hidden);
@@ -114,7 +112,7 @@ int main(void)
}
(void)getch();
gfx_done(prev);
closegraph();
puts("done");
return 0;
}