Sprites HD : capture des sprites dessinés par le jeu (étape 1)

Interception des trois routines de dessin RLE (0x10f18, 0x11038, 0x11168), de la
découpe des planches PCX (0x10df0) et de la copie vers l'écran (0x10d88). Pour chaque
image affichée, sprites.c sait quel sprite est dessiné, d'où il vient (image d'un
fichier SPR, ou rectangle d'une planche PCX) et où il est à l'écran. Vérifié au pixel
près sur la chambre (SCROBJ10/11, POINTER, BUD_1/2). Pas encore de rendu HD : aucun
changement visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
linkatplugandClaude Opus 5.5 committed 2026-12-05 06:36:04 +01:00
1 parent 48d2f9e058
commit a1c8ad7b11
8 files changed
+381 -9

No files matched your search

+2 -2
View File
@@ -21,11 +21,11 @@ if /i not "%ARG1%"=="nogen" (
if not exist build\obj mkdir build\obj
set CFLAGS=/nologo /O2 /GS- /W3 /wd4146 /wd4244 /wd4018 /wd4102 /wd4101 /wd4189 /MP /utf-8 /Iruntime /Ibuild\gen_tucker /Ibuild\gen_intro /I%SDL%\include /D_CRT_SECURE_NO_WARNINGS /Fobuild\obj\
cl %CFLAGS% /c runtime\cpu.c runtime\fpu.c runtime\loader.c runtime\dos.c runtime\machine.c runtime\audio.c runtime\ail.c runtime\menu.c runtime\mods.c runtime\hd.c runtime\png.c runtime\overrides.c runtime\main.c build\gen_tucker\*.c build\gen_intro\*.c || exit /b 1
cl %CFLAGS% /c runtime\cpu.c runtime\fpu.c runtime\loader.c runtime\dos.c runtime\machine.c runtime\audio.c runtime\ail.c runtime\menu.c runtime\mods.c runtime\hd.c runtime\png.c runtime\sprites.c runtime\overrides.c runtime\main.c build\gen_tucker\*.c build\gen_intro\*.c || exit /b 1
cl %CFLAGS% /c runtime\host_headless.c runtime\host_sdl.c runtime\gfx_gl.c || exit /b 1
if not exist build\lib mkdir build\lib
lib /nologo /OUT:build\lib\jeu.lib build\obj\cpu.obj build\obj\fpu.obj build\obj\loader.obj build\obj\dos.obj build\obj\machine.obj build\obj\audio.obj build\obj\ail.obj build\obj\menu.obj build\obj\mods.obj build\obj\hd.obj build\obj\png.obj build\obj\overrides.obj build\obj\main.obj build\obj\tucker_*.obj build\obj\intro_*.obj || exit /b 1
lib /nologo /OUT:build\lib\jeu.lib build\obj\cpu.obj build\obj\fpu.obj build\obj\loader.obj build\obj\dos.obj build\obj\machine.obj build\obj\audio.obj build\obj\ail.obj build\obj\menu.obj build\obj\mods.obj build\obj\hd.obj build\obj\png.obj build\obj\sprites.obj build\obj\overrides.obj build\obj\main.obj build\obj\tucker_*.obj build\obj\intro_*.obj || exit /b 1
link /nologo /STACK:67108864 /OUT:build\tucker_headless.exe build\obj\host_headless.obj build\lib\jeu.lib || exit /b 1
link /nologo /STACK:67108864 /SUBSYSTEM:CONSOLE /OUT:build\tucker.exe build\obj\host_sdl.obj build\obj\gfx_gl.obj build\lib\jeu.lib %SDL%\lib\x64\SDL2.lib opengl32.lib || exit /b 1
+10 -5
View File
@@ -13,6 +13,7 @@
#include "rt.h"
#include "mods.h"
#include "hd.h"
#include "sprites.h"
RtConfig rt_cfg;
@@ -46,6 +47,8 @@ void set_seg(int s, uint16_t sel) { cpu.seg[s] = sel; cpu.sb[s] = sel_base(sel);
/* ------------------------------------------------------------------ fichiers */
#define NFILES 40
static FILE *files[NFILES];
static char file_rel[NFILES][64]; /* chemin relatif dans le jeu (sprites HD) */
static char file_host[NFILES][300]; /* chemin réel */
static int file_writable[NFILES];
static uint32_t dta = 0;
@@ -111,7 +114,7 @@ static int alloc_handle(FILE *f, int w) {
}
static void dos_open(int create) {
char name[260], path[300];
char name[260], path[300], rel[260] = "";
FILE *f;
int h, mode = BL_(0) & 3;
read_str(LIN(S_DS, R(2)), name, sizeof name);
@@ -128,14 +131,13 @@ static void dos_open(int create) {
dos_error(2); return;
}
f = fopen(path, "rb");
if (f) {
char rel[260];
hd_file_opened(game_rel(name, rel, sizeof rel), path);
}
if (f) hd_file_opened(game_rel(name, rel, sizeof rel), path);
}
if (!f) { dos_error(2); return; }
h = alloc_handle(f, create || mode != 0);
if (h < 0) { dos_error(4); return; }
snprintf(file_rel[h], sizeof file_rel[h], "%s", rel);
snprintf(file_host[h], sizeof file_host[h], "%s", path);
if (rt_cfg.verbose) fprintf(stderr, "[dos] ouvre %s -> %d\n", name, h);
R(0) = (uint32_t)h;
set_cf(0);
@@ -226,7 +228,9 @@ void dos_int21(void) {
size_t got;
f = handle(W(3));
if (!f) { if (W(3) == 0) { R(0) = 0; set_cf(0); } else dos_error(6); return; }
long at = ftell(f);
got = fread(M + (LIN(S_DS, R(2)) & MEM_MASK), 1, R(1), f);
if (file_rel[W(3)][0]) spr_file_read(file_rel[W(3)], file_host[W(3)], at, LIN(S_DS, R(2)) & MEM_MASK, (uint32_t)got);
R(0) = (uint32_t)got; set_cf(0); return;
}
case 0x40: {
@@ -494,6 +498,7 @@ void dos_reset(void) {
for (i = 5; i < NFILES; i++) if (files[i]) { fclose(files[i]); files[i] = NULL; }
memset(file_writable, 0, sizeof file_writable);
hd_reset();
spr_reset();
memset(sel_tab_base, 0, sizeof sel_tab_base);
memset(sel_used, 0, sizeof sel_used);
memset(pm_vec_off, 0, sizeof pm_vec_off);
+2 -2
View File
@@ -38,7 +38,7 @@ void hd_reset(void) {
}
/* PCX 320×200 8 bits → indices + palette ; 0 si format inattendu */
static int read_pcx(const char *path, uint8_t *pix, uint8_t *pal) {
int hd_read_pcx(const char *path, uint8_t *pix, uint8_t *pal) {
FILE *f = fopen(path, "rb");
uint8_t *d;
long len;
@@ -107,7 +107,7 @@ void hd_file_opened(const char *rel, const char *host_path) {
if (!part) return;
{
static uint8_t other_pal[768]; /* les morceaux suivants partagent la palette du premier */
if (!read_pcx(host_path, part, s->parts ? other_pal : s->pal)) { free(part); return; }
if (!hd_read_pcx(host_path, part, s->parts ? other_pal : s->pal)) { free(part); return; }
}
{
int n = s->parts + 1, y;
+1
View File
@@ -22,6 +22,7 @@ typedef struct {
void hd_set_enabled(int on);
int hd_enabled(void);
void hd_reset(void);
int hd_read_pcx(const char *path, uint8_t *pix, uint8_t *pal); /* PCX 320×200 8 bits : 1 si lu */
void hd_file_opened(const char *rel, const char *host_path); /* appelé par dos.c à chaque ouverture */
/* fb : écran 320×200 en indices ; dac : palette VGA 6 bits ; mask : 320×200, 0 = HD, 255 = pixel du jeu */
int hd_compose(const uint8_t *fb, const uint8_t *dac, uint8_t *mask, HdFrame *out);
+22
View File
@@ -5,6 +5,7 @@
#include "rt.h"
#include "recomp_tucker.h"
#include "recomp_intro.h"
#include "sprites.h"
/* int386x(eax = n° d'interruption, edx = REGS entrée, ebx = REGS sortie, ecx = SREGS) -> eax = sortie.eax
* REGS : eax ebx ecx edx esi edi cflag (dwords) ; SREGS : es cs ss ds fs gs (mots).
@@ -162,3 +163,24 @@ void I_00016ab8(void) { ail_sample_status(); }
void I_00017036(void) { ail_minimum_sample_buffer_size(); }
void I_0001712f(void) { ail_sample_buffer_ready(); }
void I_00017214(void) { ail_load_sample_buffer(); }
/* ------------------------------------------------------------------ sprites HD (sprites.c) */
void F_00010f18_orig(void);
void F_00011038_orig(void);
void F_00011168_orig(void);
void F_00010d88_orig(void);
void F_00010df0_orig(void);
/* les trois routines de dessin des .SPR : on note le sprite, puis l'original dessine */
void F_00010f18(void) { spr_blit(R(0), R(2), (int)R(3), (int)R(1)); F_00010f18_orig(); }
void F_00011038(void) { spr_blit(R(0), R(2), (int)R(3), (int)R(1)); F_00011038_orig(); }
void F_00011168(void) { spr_blit(R(0), R(2), (int)R(3), (int)R(1)); F_00011168_orig(); }
/* découpe d'un rectangle de planche PCX (eax = source dans [0x46858], edx = destination, ebx = largeur,
* ecx = hauteur) en RLE ; renvoie la longueur : on note d'où vient ce sprite */
void F_00010df0(void) {
uint32_t src = R(0), dest = R(2);
int w = (int)R(3), h = (int)R(1);
F_00010df0_orig();
spr_encode(src, dest, w, h, R(0));
}
/* copie vers l'écran : l'image est complète */
void F_00010d88(void) { spr_present(R(0)); F_00010d88_orig(); }
+5
View File
@@ -14,3 +14,8 @@
11f64 # voix_joue (speech\samNNNN.wav)
11eb4 # voix_suite (lecture en flux de l'original)
11f24 # voix_arrete
10f18 # sprite SPR : décodage dans le tampon de la pièce (eax = dest, edx = pixels, ebx = largeur, ecx = hauteur) -> sprites HD
11038 # idem, derrière le premier plan (indices >= 0xE0)
11168 # idem, avec profondeur (2 paramètres sur la pile)
10d88 # copie du tampon de la pièce vers l'écran (eax = première ligne, défilement compris) -> fin d'image
10df0 # découpe un rectangle d'une planche PCX en RLE (sprites HD : origine de chaque sprite)
+298
View File
@@ -0,0 +1,298 @@
/* Sprites HD : voir sprites.h. */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cpu.h"
#include "rt.h"
#include "sprites.h"
#define SHEET_BUF 0x46858u /* [ds:0x46858] : tampon 320 de large où le jeu décode les planches PCX */
#define ROW 640 /* largeur du tampon de la pièce */
#define NREG 96 /* fichiers SPR suivis */
#define NENC 4096 /* sprites découpés dans des planches PCX */
#define NDRAW 160 /* sprites par image */
#define POOL (1 << 20) /* pixels décodés par image */
/* ------------------------------------------------------------------ palettes de référence */
typedef struct { char name[16]; uint8_t pal[768]; int ok; } Pal;
static Pal pals[24];
static int npals;
static int read_pcx_palette(const char *path, uint8_t *pal) {
FILE *f = fopen(path, "rb");
long len;
int ok = 0;
if (!f) return 0;
fseek(f, 0, SEEK_END);
len = ftell(f);
if (len > 769 && fseek(f, len - 769, SEEK_SET) == 0 && fgetc(f) == 12) ok = fread(pal, 1, 768, f) == 768;
fclose(f);
return ok;
}
/* palette du PCX « name » (sans extension) ; host : chemin réel s'il est connu, sinon recherche dans le jeu */
static const uint8_t *pcx_palette(const char *name, const char *host) {
int i;
char path[600];
for (i = 0; i < npals; i++) if (!strcmp(pals[i].name, name)) return pals[i].ok ? pals[i].pal : NULL;
if (npals == 24) npals = 0;
i = npals++;
snprintf(pals[i].name, sizeof pals[i].name, "%s", name);
pals[i].ok = 0;
if (host) pals[i].ok = read_pcx_palette(host, pals[i].pal);
else {
char dosname[32];
snprintf(dosname, sizeof dosname, "%s.PCX", name);
if (dos_map_path(dosname, path, sizeof path, 0)) pals[i].ok = read_pcx_palette(path, pals[i].pal);
}
return pals[i].ok ? pals[i].pal : NULL;
}
/* Palette d'export d'un fichier SPR : celle du décor de la pièce indiquée par le nom (A01_02 -> LOC01,
* C50_02 -> LOC50, LOC03A si LOC03 n'existe pas), PARTONE/PARTTWO/PARTTHR -> PT1BAK/PT2BAK/PT3BAK.
* Même règle que palette_for() de tools/hd_export.py. */
static const uint8_t *spr_palette(const char *name) {
char room[16];
const char *p = name;
const uint8_t *pal;
if (!strcmp(name, "PARTONE")) return pcx_palette("PT1BAK", NULL);
if (!strcmp(name, "PARTTWO")) return pcx_palette("PT2BAK", NULL);
if (!strcmp(name, "PARTTHR")) return pcx_palette("PT3BAK", NULL);
while (*p && !isdigit((unsigned char)*p)) p++;
if (!(isdigit((unsigned char)p[0]) && isdigit((unsigned char)p[1]))) return pcx_palette("LOC01", NULL);
snprintf(room, sizeof room, "LOC%c%c", p[0], p[1]);
if ((pal = pcx_palette(room, NULL))) return pal;
snprintf(room, sizeof room, "LOC%c%cA", p[0], p[1]);
return pcx_palette(room, NULL);
}
/* ------------------------------------------------------------------ fichiers SPR en mémoire */
typedef struct {
char name[16];
uint32_t addr, len; /* zone mémoire (linéaire) occupée par le fichier */
int nframes; /* 0 tant que la mise en page n'est pas calculée */
int *lay; /* par image : page, x, y */
int *page_wh; /* par page : largeur, hauteur */
} Region;
static Region reg[NREG];
static int nreg;
/* ------------------------------------------------------------------ sprites découpés dans des planches PCX */
typedef struct { uint32_t addr, len; int w, h, sx, sy; char sheet[16]; } Enc;
static Enc enc[NENC];
static int nenc;
static char cur_pcx[16], cur_pcx_host[600]; /* dernière planche PCX lue (celle que le jeu vient de décoder) */
/* ------------------------------------------------------------------ image en cours / affichée */
typedef struct { SprDraw d; uint32_t dest; } Pending;
static Pending cur[NDRAW];
static int ncur;
static SprDraw shown[NDRAW];
static int nshown;
static uint32_t serial;
static uint8_t *pool[2]; /* pool[0] : image en cours ; pool[1] : image affichée */
static int pool_used;
static void free_region(Region *r) { free(r->lay); free(r->page_wh); memset(r, 0, sizeof *r); }
void spr_reset(void) {
int i;
for (i = 0; i < nreg; i++) free_region(&reg[i]);
nreg = ncur = nshown = nenc = 0;
cur_pcx[0] = 0;
}
static void base_name(const char *rel, char *out, size_t n) {
const char *b = strrchr(rel, '\\'), *s = strrchr(rel, '/');
size_t i = 0;
if (s > b) b = s;
b = b ? b + 1 : rel;
while (b[i] && b[i] != '.' && i + 1 < n) { out[i] = (char)toupper((unsigned char)b[i]); i++; }
out[i] = 0;
}
static int ends_with(const char *s, const char *ext) {
size_t l = strlen(s), e = strlen(ext), i;
if (l < e) return 0;
for (i = 0; i < e; i++) if (toupper((unsigned char)s[l - e + i]) != ext[i]) return 0;
return 1;
}
static void drop_overlapping(uint32_t addr, uint32_t len) {
int i;
for (i = 0; i < nreg;)
if (reg[i].addr < addr + len && addr < reg[i].addr + reg[i].len) { free_region(&reg[i]); reg[i] = reg[--nreg]; memset(&reg[nreg], 0, sizeof reg[nreg]); }
else i++;
for (i = 0; i < nenc;)
if (enc[i].addr < addr + len && addr < enc[i].addr + enc[i].len) enc[i] = enc[--nenc];
else i++;
}
void spr_file_read(const char *rel, const char *host, long fileoff, uint32_t addr, uint32_t len) {
char name[16];
int i;
if (!len) return;
base_name(rel, name, sizeof name);
if (ends_with(rel, ".PCX")) { /* le jeu va décoder cette planche */
snprintf(cur_pcx, sizeof cur_pcx, "%s", name);
snprintf(cur_pcx_host, sizeof cur_pcx_host, "%s", host ? host : "");
return;
}
if (!ends_with(rel, ".SPR")) return;
if (fileoff > 0) { /* suite d'une lecture en plusieurs fois */
for (i = 0; i < nreg; i++)
if (!strcmp(reg[i].name, name) && reg[i].addr + reg[i].len == addr) { reg[i].len += len; return; }
return;
}
drop_overlapping(addr, len); /* mémoire réutilisée */
if (nreg == NREG) { free_region(&reg[0]); reg[0] = reg[--nreg]; memset(&reg[nreg], 0, sizeof reg[nreg]); }
memset(&reg[nreg], 0, sizeof reg[nreg]);
snprintf(reg[nreg].name, sizeof reg[nreg].name, "%s", name);
reg[nreg].addr = addr;
reg[nreg].len = len;
nreg++;
}
void spr_encode(uint32_t src, uint32_t dest, int w, int h, uint32_t len) {
uint32_t base = RD32(SB(S_DS) + SHEET_BUF), off = src - base, lin = (SB(S_DS) + dest) & MEM_MASK;
if (!cur_pcx[0] || off >= 320u * 200u || w <= 0 || h <= 0 || !len || len > 1u << 20) return;
drop_overlapping(lin, len);
if (nenc == NENC) nenc = 0;
enc[nenc].addr = lin;
enc[nenc].len = len;
enc[nenc].w = w;
enc[nenc].h = h;
enc[nenc].sx = (int)(off % 320);
enc[nenc].sy = (int)(off / 320);
snprintf(enc[nenc].sheet, sizeof enc[nenc].sheet, "%s", cur_pcx);
pcx_palette(cur_pcx, cur_pcx_host[0] ? cur_pcx_host : NULL); /* palette mise en cache tant que le chemin est connu */
nenc++;
}
/* Mise en page des images d'un SPR dans ses planches HD : rangées de gauche à droite, page suivante quand
* c'est plein. Doit rester identique à layout() de tools/hd_export.py. */
static int make_layout(Region *r) {
uint32_t n = RD32(r->addr), k;
int page = 0, x = SPR_PAD, y = SPR_PAD, rowh = 0, total_w = SPR_PAD, pw;
if (n == 0 || n > 4096 || 4 + 4 * n > r->len) return 0;
for (k = 0; k < n; k++) {
uint32_t o = RD32(r->addr + 4 + 4 * k);
if (o + 12 > r->len) return 0;
total_w += RD16(r->addr + o) + SPR_PAD;
}
r->lay = (int *)calloc(n * 3, sizeof(int));
r->page_wh = (int *)calloc(n * 2, sizeof(int));
if (!r->lay || !r->page_wh) return 0;
pw = total_w < SPR_PAGE_W ? total_w : SPR_PAGE_W;
for (k = 0; k < n; k++) {
uint32_t o = RD32(r->addr + 4 + 4 * k);
int w = RD16(r->addr + o), h = RD16(r->addr + o + 2);
if (x + w + SPR_PAD > pw && x > SPR_PAD) { x = SPR_PAD; y += rowh + SPR_PAD; rowh = 0; }
if (y + h + SPR_PAD > SPR_PAGE_H && y > SPR_PAD) {
r->page_wh[2 * page] = pw; r->page_wh[2 * page + 1] = y + rowh + SPR_PAD;
page++; x = SPR_PAD; y = SPR_PAD; rowh = 0;
}
r->lay[3 * k] = page; r->lay[3 * k + 1] = x; r->lay[3 * k + 2] = y;
x += w + SPR_PAD;
if (h > rowh) rowh = h;
}
r->page_wh[2 * page] = pw; r->page_wh[2 * page + 1] = y + rowh + SPR_PAD;
r->nframes = (int)n;
return 1;
}
/* RLE : octet non nul = pixel, 00 n = n pixels transparents (même lecture que la routine 0x10f18) */
static void decode(uint32_t src, int w, int h, uint8_t *out) {
int i = 0, total = w * h;
while (i < total) {
uint8_t b = RD8(src++);
if (b) out[i++] = b;
else {
int n = RD8(src++);
if (n > total - i) n = total - i;
memset(out + i, 0, (size_t)n);
i += n;
}
}
}
void spr_blit(uint32_t dest, uint32_t src, int w, int h) {
uint32_t lin = (SB(S_DS) + src) & MEM_MASK;
Pending *p;
int i;
if (w <= 0 || h <= 0 || w > 640 || h > 400 || ncur == NDRAW) return;
if (!pool[0]) { pool[0] = (uint8_t *)malloc(POOL); pool[1] = (uint8_t *)malloc(POOL); if (!pool[0] || !pool[1]) return; }
if (pool_used + w * h > POOL) return;
p = &cur[ncur];
memset(p, 0, sizeof *p);
/* sprite découpé dans une planche PCX ? */
for (i = nenc - 1; i >= 0; i--)
if (enc[i].addr == lin && enc[i].w == w && enc[i].h == h) {
snprintf(p->d.key, sizeof p->d.key, "SHEETS\\%s", enc[i].sheet);
p->d.sx = enc[i].sx; p->d.sy = enc[i].sy;
p->d.img_w = 320; p->d.img_h = 200;
p->d.ref_pal = pcx_palette(enc[i].sheet, NULL);
break;
}
/* image d'un fichier SPR ? */
if (i < 0) {
Region *r = NULL;
int lo, hi, k = -1;
for (i = 0; i < nreg; i++) if (lin - reg[i].addr < reg[i].len) { r = &reg[i]; break; }
if (!r || (!r->nframes && !make_layout(r))) return;
lo = 0; hi = r->nframes - 1; /* table d'offsets croissante en tête de fichier */
while (lo <= hi) {
int m = (lo + hi) / 2;
uint32_t a = r->addr + RD32(r->addr + 4 + 4 * (uint32_t)m) + 12;
if (a == lin) { k = m; break; }
if (a < lin) lo = m + 1; else hi = m - 1;
}
if (k < 0) return;
if (r->lay[3 * k]) snprintf(p->d.key, sizeof p->d.key, "SPRITES\\%s_P%d", r->name, r->lay[3 * k]);
else snprintf(p->d.key, sizeof p->d.key, "SPRITES\\%s", r->name);
p->d.sx = r->lay[3 * k + 1]; p->d.sy = r->lay[3 * k + 2];
p->d.img_w = r->page_wh[2 * r->lay[3 * k]]; p->d.img_h = r->page_wh[2 * r->lay[3 * k] + 1];
p->d.ref_pal = spr_palette(r->name);
}
p->d.w = w; p->d.h = h;
p->d.pix = pool[0] + pool_used;
pool_used += w * h;
decode(lin, w, h, (uint8_t *)p->d.pix);
p->dest = dest;
ncur++;
}
/* fin d'image : src = première ligne copiée à l'écran (tampon de la pièce + défilement) */
void spr_present(uint32_t src) {
int i;
uint8_t *t;
nshown = 0;
for (i = 0; i < ncur; i++) {
long d = (long)(int32_t)(cur[i].dest - src);
long x = ((d % ROW) + ROW) % ROW, y = (d - x) / ROW;
if (x >= 480) { x -= ROW; y++; } /* sprite qui commence à gauche de l'écran */
cur[i].d.x = (int)x;
cur[i].d.y = (int)y;
if (x >= 320 || y >= 200 || x + cur[i].d.w <= 0 || y + cur[i].d.h <= 0) continue;
shown[nshown++] = cur[i].d;
}
if (rt_cfg.verbose && serial % 140 == 0) {
fprintf(stderr, "[sprites] image %u : %d sprite(s)", serial, nshown);
for (i = 0; i < nshown && i < 8; i++)
fprintf(stderr, " %s(%d,%d)@%d,%d", shown[i].key, shown[i].sx, shown[i].sy, shown[i].x, shown[i].y);
fprintf(stderr, "\n");
}
t = pool[0]; pool[0] = pool[1]; pool[1] = t; /* les pixels affichés restent valides */
ncur = 0;
pool_used = 0;
serial++;
}
int spr_frame(const SprDraw **list, uint32_t *ser) {
*list = shown;
if (ser) *ser = serial;
return nshown;
}
+41
View File
@@ -0,0 +1,41 @@
/* Sprites HD : savoir exactement quels sprites le jeu dessine, d'où ils viennent, et où, à chaque image.
*
* Le jeu compose chaque image dans un tampon de 640 pixels de large (la pièce entière) : décor propre,
* puis sprites par trois routines de décodage RLE (0x10f18, 0x11038, 0x11168 : normal et « derrière le
* premier plan »), puis copie d'une fenêtre 320×200 vers l'écran (0x10d88, défilement compris).
* Les sprites viennent de deux sources :
* - fichiers SPRITES\*.SPR, chargés tels quels en mémoire (animations, personnages, scènes) ;
* - planches PCX (BUD_1.PCX, SCROBJ10.PCX, POINTER.PCX…) : le jeu décode la planche dans le tampon
* [0x46858] (320 de large) puis découpe et encode chaque rectangle en RLE (0x10df0).
* Ces routines sont interceptées (overrides.c) ; dos.c signale chaque lecture de fichier. On sait donc,
* pour l'image affichée : l'image d'origine de chaque sprite, sa position à l'écran et ses pixels.
*
* Images HD (dans mods/<nom>/hd/) :
* SPRITES/<NOM>.png une planche par fichier SPR (puis <NOM>_P1.png… si plusieurs pages), images
* rangées par spr_layout (même algorithme que tools/hd_export.py --sprites)
* SHEETS/<NOM>.png la planche PCX entière agrandie (320×200 d'origine), transparente là où l'indice vaut 0 */
#pragma once
#include <stdint.h>
#define SPR_PAGE_W 1024 /* largeur maximale d'une page de planche SPR, en pixels d'origine */
#define SPR_PAGE_H 1024
#define SPR_PAD 4 /* marge transparente autour de chaque image dans une planche SPR */
typedef struct {
char key[40]; /* image HD sans extension, relative à hd/ (SPRITES\A01_01, SHEETS\BUD_1) */
int x, y, w, h; /* rectangle à l'écran 320×200 (peut déborder) */
const uint8_t *pix; /* w × h indices de palette, 0 = transparent */
int sx, sy; /* coin du sprite dans l'image HD, en pixels d'origine */
int img_w, img_h; /* taille de l'image HD en pixels d'origine (échelle = largeur PNG / img_w) */
const uint8_t *ref_pal; /* palette 8 bits de l'image HD exportée (fondus), ou NULL */
} SprDraw;
void spr_reset(void);
/* dos.c : lecture de len octets du fichier rel (décalage fileoff) à l'adresse linéaire addr ; host = chemin réel */
void spr_file_read(const char *rel, const char *host, long fileoff, uint32_t addr, uint32_t len);
/* overrides.c */
void spr_blit(uint32_t dest, uint32_t src, int w, int h);
void spr_encode(uint32_t src, uint32_t dest, int w, int h, uint32_t len);
void spr_present(uint32_t src);
/* hôte : sprites de la dernière image copiée à l'écran ; serial change à chaque image */
int spr_frame(const SprDraw **list, uint32_t *serial);