libc: graphics.h — Turbo-C BGI-слой, Фаза 1 (режим 256)
Функционально-совместимый с Turbo-C <graphics.h> поверх gfx.h. Архитектура: mode-agnostic математика (libc/bgi/*.c → sprinter.lib) + driver-leaf'ы per-режим (libc/bgi/drv256/*.c → sprinter_gfx256.lib). Режим выбирается линковкой: sprinter-cc --gfx 256 (16 — позже, тем же leaf-split'ом). Один код работает в любом режиме без правок. API: initgraph/closegraph/graphresult/cleardevice, set/get color+bkcolor, getmaxx/y/color, put/getpixel, moveto/moverel/getx/gety, line/lineto/ linerel, rectangle, bar, circle, outtext/outtextxy. initgraph грузит EGA-палитру 0..15. Пакетные примитивы (circle) — одна W3-скобка на примитив (иначе на порядок медленнее). Проверено в MAME (tests/bgitest). Попутно: gfx_getpixel256 в libc/gfx. size-check без регресса, baseline обновлён. Детали: memory/bgi_two_lib_design, docs/TODO.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/* _bgi_begin (drv256) — открыть W3-сессию для пакетного рисования. */
|
||||
#include "../_bgi.h"
|
||||
#include "../../gfx/_gfx.h"
|
||||
|
||||
void _bgi_begin(void)
|
||||
{
|
||||
_gfx_w3_video_begin();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_clearall (drv256) — залить весь экран цветом. */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_clearall(uint8_t color)
|
||||
{
|
||||
gfx_clear256(color);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_drawtext (drv256) — строка шрифтом 8×8 цветами fg/bg в (x,y). */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_drawtext(int x, int y, const char *s, uint8_t fg, uint8_t bg)
|
||||
{
|
||||
gfx_text256(x, y, s, fg, bg);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_end (drv256) — закрыть W3-сессию пакетного рисования. */
|
||||
#include "../_bgi.h"
|
||||
#include "../../gfx/_gfx.h"
|
||||
|
||||
void _bgi_end(void)
|
||||
{
|
||||
_gfx_w3_video_end();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_fillrect (drv256) — залитый прямоугольник w×h из (x,y). */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_fillrect(int x, int y, int w, int h, uint8_t color)
|
||||
{
|
||||
gfx_fill_rect256(x, y, w, h, color);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_hspan (drv256) — горизонтальный отрезок len пикселей. */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_hspan(int x, int y, int len, uint8_t color)
|
||||
{
|
||||
gfx_hline256(x, y, len, color);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_lineseg (drv256) — отрезок (x0,y0)->(x1,y1) (использует accel-line). */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_lineseg(int x0, int y0, int x1, int y1, uint8_t color)
|
||||
{
|
||||
gfx_line256(x0, y0, x1, y1, color);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_mode_done (drv256) — вернуть видеорежим, бывший до initgraph. */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_mode_done(uint8_t prev_mode)
|
||||
{
|
||||
gfx_done(prev_mode);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* _bgi_mode_set (drv256) — вход в графический режим 320×256×256.
|
||||
*
|
||||
* Загружает EGA-совместимые цвета 0..15 в палитру 0, чтобы setcolor(RED)
|
||||
* и прочие BGI-константы давали ожидаемый цвет. Заполняет границы
|
||||
* экрана в состоянии BGI. Возвращает предыдущий видеорежим.
|
||||
*/
|
||||
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
/* 16 EGA-цветов, формат записи палитры (B, G, R, pad). */
|
||||
static const uint8_t _bgi_ega_pal[16 * 4] = {
|
||||
0, 0, 0, 0, /* 0 BLACK */
|
||||
168, 0, 0, 0, /* 1 BLUE */
|
||||
0, 168, 0, 0, /* 2 GREEN */
|
||||
168, 168, 0, 0, /* 3 CYAN */
|
||||
0, 0, 168, 0, /* 4 RED */
|
||||
168, 0, 168, 0, /* 5 MAGENTA */
|
||||
0, 84, 168, 0, /* 6 BROWN */
|
||||
168, 168, 168, 0, /* 7 LIGHTGRAY */
|
||||
84, 84, 84, 0, /* 8 DARKGRAY */
|
||||
255, 84, 84, 0, /* 9 LIGHTBLUE */
|
||||
84, 255, 84, 0, /* 10 LIGHTGREEN */
|
||||
255, 255, 84, 0, /* 11 LIGHTCYAN */
|
||||
84, 84, 255, 0, /* 12 LIGHTRED */
|
||||
255, 84, 255, 0, /* 13 LIGHTMAGENTA */
|
||||
84, 255, 255, 0, /* 14 YELLOW */
|
||||
255, 255, 255, 0, /* 15 WHITE */
|
||||
};
|
||||
|
||||
uint8_t _bgi_mode_set(void)
|
||||
{
|
||||
uint8_t prev = gfx_init(GFX_MODE_320x256x256, 0);
|
||||
gfx_pal_load(0, 0, 16, _bgi_ega_pal);
|
||||
_bgi_maxx = GFX_WIDTH - 1;
|
||||
_bgi_maxy = GFX_HEIGHT - 1;
|
||||
_bgi_maxcolor = 255;
|
||||
return prev;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_plot (drv256) — одиночный пиксель текущим цветом. */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
void _bgi_plot(int x, int y, uint8_t color)
|
||||
{
|
||||
gfx_putpixel256(x, y, color);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* _bgi_plot_raw (drv256) — пиксель без своей W3-скобки (вызывать между
|
||||
* _bgi_begin/_bgi_end). Клип по краю экрана делает сам raw-примитив.
|
||||
*/
|
||||
#include "../_bgi.h"
|
||||
#include "../../gfx/_gfx.h"
|
||||
|
||||
void _bgi_plot_raw(int x, int y, uint8_t color)
|
||||
{
|
||||
_gfx_putpixel256_raw(x, y, color);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* _bgi_read (drv256) — цвет пикселя (x,y). */
|
||||
#include "../_bgi.h"
|
||||
#include <gfx.h>
|
||||
|
||||
unsigned _bgi_read(int x, int y)
|
||||
{
|
||||
return gfx_getpixel256(x, y);
|
||||
}
|
||||
Reference in New Issue
Block a user