Files
Sprinter-SDCC/tests/bgitest/bgitest.c
T
snark13 5a48f7fafb libc: BGI Фаза 2a — arc/ellipse/drawpoly
Дуги/эллипсы через целочисленную тригонометрию Q7 (_bgi_trig.c, ×128) +
общий рисователь полилинией (_bgi_arc_draw.c). arc(x,y,st,end,r),
ellipse(x,y,st,end,xr,yr), drawpoly(n,pts). Проверено в MAME (tests/
bgitest): окружность/эллипс/дуга/полигон рисуются корректно.

ВАЖНО: тригонометрию считаем в int (Q7), НЕ через (long)…>>8 — первая
версия на 32-бит арифметике рисовала эллипс прямоугольником (SDCC/z80
криво собирает 32-бит; см. memory/avoid_32bit_arith_z80). Q7 даёт
радиус×значение ≤ 255×128 < 32767 — всё влезает в 16 бит.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 15:50:00 +03:00

64 lines
1.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* bgitest — демонстрация BGI-слоя graphics.h (режим 320×256×256).
*
* Собирается с `--gfx 256` (см. Makefile). Показывает примитивы
* Фазы 1 (рамка/бары/линии/окружность/текст) и Фазы 2a
* (эллипс/дуга/полигон) — визуальная проверка в MAME.
*/
#include <graphics.h>
int main(void)
{
int i, mx, my;
/* треугольник для drawpoly (замкнут повтором первой точки). */
static const int tri[] = { 120, 244, 210, 244, 165, 210, 120, 244 };
initgraph();
mx = getmaxx(); /* 319 */
my = getmaxy(); /* 255 */
cleardevice();
setcolor(WHITE);
rectangle(0, 0, mx, my);
setcolor(YELLOW);
outtextxy(96, 6, "SPRINTER BGI P2");
/* Палитровая полоса: 15 залитых баров цветами 1..15. */
for (i = 1; i <= 15; i++) {
int x0 = 8 + (i - 1) * 20;
setcolor(i);
bar(x0, 22, x0 + 16, 40);
}
/* Окружность (Фаза 1). */
setcolor(LIGHTRED);
circle(60, 120, 40);
/* Полный эллипс (Фаза 2a). */
setcolor(LIGHTGREEN);
ellipse(165, 120, 0, 360, 70, 40);
/* Верхняя половина дуги (Фаза 2a). */
setcolor(LIGHTCYAN);
arc(270, 140, 0, 180, 35);
/* Треугольник через drawpoly (Фаза 2a). */
setcolor(LIGHTMAGENTA);
drawpoly(4, tri);
/* Веер линий слева. */
for (i = 150; i <= my - 6; i += 8) {
setcolor(1 + ((i - 150) / 8) % 15);
line(6, 175, 110, i);
}
setcolor(YELLOW);
outtextxy(120, 190, "circle ellipse arc poly");
for (;;) { } /* держим картинку на экране */
}