running ok

This commit is contained in:
Frater 2026-05-10 11:49:01 +02:00
commit 8e30b7692f
8 changed files with 371 additions and 356 deletions

View file

@ -1,31 +1,13 @@
#include "defines.h"
/* Prototypes pour les fonctions assembleur externes */
extern void scanline_zonly_asm(int width, uint16_t *zbuf, int z, int dz_step);
#pragma aux scanline_zonly_asm = \
"test ecx, ecx" \
"jz done_z" \
"loop_z:" \
"mov eax, edx" \
"shr eax, 16" \
"cmp ax, [esi]" \
"jae skip_z" \
"mov [esi], ax" \
"skip_z:" \
"add edx, ebx" \
"add esi, 2" \
"dec ecx" \
"jnz loop_z" \
"done_z:" \
parm [ecx] [esi] [edx] [ebx] \
modify [eax ecx esi edx];
/* Rendu d'une ligne avec interpolation Gouraud 16.16 */
void scanline_gouraud_c(int width, uint8_t *dest, uint16_t *zbuf, int z, int dz_step, int intensity, int di_step, uint8_t base_color) {
/* Rendu d'une scanline avec interpolation Gouraud 16.16 */
void scanline_gouraud_c(int width, uint8_t *dest, uint16_t *zbuf,
fixed z, fixed dz_step, fixed intensity, fixed di_step,
uint8_t base_color) {
int i;
uint8_t color_offset;
int s;
uint8_t shade;
uint8_t color_offset;
uint16_t zv;
color_offset = (uint8_t)(base_color << 4);
@ -34,9 +16,10 @@ void scanline_gouraud_c(int width, uint8_t *dest, uint16_t *zbuf, int z, int dz_
zv = (uint16_t)(z >> 16);
if (zv < zbuf[i]) {
zbuf[i] = zv;
/* Extraction de l'intensité 0-15 depuis le format fixed 16.16 */
shade = (uint8_t)(intensity >> 16);
if (shade > 15) shade = 15;
s = intensity >> 16;
if (s < 0) shade = 0;
else if (s > 15) shade = 15;
else shade = (uint8_t)s;
dest[i] = color_offset + shade;
}
z += dz_step;
@ -50,9 +33,10 @@ void swap_pt(Point2D **a, Point2D **b) {
void fill_triangle_gouraud(Point2D *p1, Point2D *p2, Point2D *p3, uint8_t base_color) {
/* TOUTES les variables déclarées ici pour le C89 */
int y, width, start_x, end_x, dz_step, di_step, clip_x, w, start_z, start_i, second_half, total_height;
int y, width, start_x, end_x, clip_x, w, second_half, total_height;
fixed dx13, dz13, di13, xA, zA, iA, xB, zB, iB, dx12, dz12, di12, dx23, dz23, di23;
fixed cx1, cz1, ci1, cx2, cz2, ci2, tx, tz, ti;
fixed dz_step, di_step, start_z, start_i;
uint8_t *dest;
uint16_t *zbuf;
@ -70,7 +54,12 @@ void fill_triangle_gouraud(Point2D *p1, Point2D *p2, Point2D *p3, uint8_t base_c
di13 = (p3->intensity - p1->intensity) / total_height;
xA = int_to_f(p1->x); zA = p1->z; iA = p1->intensity;
xB = xA; zB = zA; iB = iA;
/* Sommet plat en haut : xB part de p2, pas de p1 */
if (p1->y == p2->y) {
xB = int_to_f(p2->x); zB = p2->z; iB = p2->intensity;
} else {
xB = xA; zB = zA; iB = iA;
}
/* Gradients pour les côtés courts (p1-p2 puis p2-p3) */
dx12 = (p2->y > p1->y) ? ((p2->x - p1->x) << 16) / (p2->y - p1->y) : 0;
@ -94,22 +83,22 @@ void fill_triangle_gouraud(Point2D *p1, Point2D *p2, Point2D *p3, uint8_t base_c
}
start_x = f_to_int(cx1);
end_x = f_to_int(cx2);
width = end_x - start_x;
end_x = f_to_int(cx2) + 1; /* ceil : couvre le pixel de bord droit fractionnaire */
width = end_x - start_x;
if (y >= 0 && y < 200 && width > 0) {
if (y >= 0 && y < SCREEN_H && width > 0) {
dz_step = (cz2 - cz1) / width;
di_step = (ci2 - ci1) / width;
clip_x = (start_x < 0) ? 0 : start_x;
w = width - (clip_x - start_x);
if (clip_x + w > 320) w = 320 - clip_x;
if (clip_x + w > SCREEN_W) w = SCREEN_W - clip_x;
if (w > 0) {
start_z = cz1 + (clip_x - start_x) * dz_step;
start_i = ci1 + (clip_x - start_x) * di_step;
dest = backbuffer + (y * 320) + clip_x;
zbuf = zbuffer + (y * 320) + clip_x;
dest = backbuffer + (y * SCREEN_W) + clip_x;
zbuf = zbuffer + (y * SCREEN_W) + clip_x;
scanline_gouraud_c(w, dest, zbuf, start_z, dz_step, start_i, di_step, base_color);
}
@ -142,11 +131,11 @@ void draw_line_z(Point2D *p1, Point2D *p2, uint8_t col, int z_test) {
x = p1->x; y = p1->y;
while (1) {
if (x >= 0 && x < 320 && y >= 0 && y < 200) {
if (x >= 0 && x < SCREEN_W && y >= 0 && y < SCREEN_H) {
zv = (uint16_t)f_to_int(cz);
if (!z_test || zv <= zbuffer[y * 320 + x]) {
backbuffer[y * 320 + x] = col;
if (z_test) zbuffer[y * 320 + x] = zv;
if (!z_test || zv < zbuffer[y * SCREEN_W + x]) {
backbuffer[y * SCREEN_W + x] = col;
if (z_test) zbuffer[y * SCREEN_W + x] = zv;
}
}
if (x == p2->x && y == p2->y) break;
@ -156,37 +145,3 @@ void draw_line_z(Point2D *p1, Point2D *p2, uint8_t col, int z_test) {
cz += z_step;
}
}