Files
DoubleTroubleRecomp/runtime/host_headless.c
T
linkatplugandClaude Opus 5.5 dd2a7efd8d Premier commit : recompilation statique de Bud Tucker in Double Trouble
- tools/ : lecteur LE (DOS/4GW) et traducteur x86 -> C (Capstone)
- runtime/ : CPU, FPU x87, DOS, VGA/PIT, mixeur et emulation AIL,
  remplacements de fonctions, hotes SDL2 et headless
- build.bat : generation et compilation MSVC 2022
- README, feuille de route (docs/ROADMAP.md), .gitignore excluant
  tout fichier du jeu et tout code genere

Etat du code au moment du commit : travail en cours sur le son
des cinematiques (runtime/ail.c).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 02:18:30 +01:00

109 lines
4.2 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.
/* Hôte sans fenêtre, pour les essais : temps virtuel déterministe, images écrites en BMP.
* --images N arrêt après N images (70 par seconde de jeu), défaut 700
* --tous K écrit une image sur K, défaut 70
* --dossier D dossier des images, défaut frames
* --wav F enregistre le son mixé dans F (WAV 44,1 kHz stéréo)
* --clic I,X,Y clic gauche à l'image I en (X, Y) (coordonnées 320×200), répétable
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cpu.h"
#include "rt.h"
int host_quit;
static uint64_t vtime;
static unsigned frame, max_frames = 700, every = 70;
static const char *outdir = "frames";
static int mx = 160, my = 100, mb;
static struct { unsigned at; int x, y; } clicks[64];
static int nclicks;
static FILE *wav_out;
static uint32_t wav_bytes;
int host_init(int argc, char **argv) {
int i;
for (i = 1; i + 1 < argc; i++) {
if (!strcmp(argv[i], "--images")) max_frames = (unsigned)atoi(argv[i + 1]);
else if (!strcmp(argv[i], "--tous")) every = (unsigned)atoi(argv[i + 1]);
else if (!strcmp(argv[i], "--dossier")) outdir = argv[i + 1];
else if (!strcmp(argv[i], "--wav")) {
static const uint8_t hdr[44] = {0};
wav_out = fopen(argv[i + 1], "wb");
if (wav_out) fwrite(hdr, 1, 44, wav_out);
}
else if (!strcmp(argv[i], "--clic") && nclicks < 64) {
sscanf(argv[i + 1], "%u,%d,%d", &clicks[nclicks].at, &clicks[nclicks].x, &clicks[nclicks].y);
nclicks++;
}
}
return 1;
}
static void put32(uint8_t *p, uint32_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); p[2] = (uint8_t)(v >> 16); p[3] = (uint8_t)(v >> 24); }
void host_shutdown(void) {
uint8_t h[44];
if (!wav_out) return;
memcpy(h, "RIFF", 4); put32(h + 4, 36 + wav_bytes); memcpy(h + 8, "WAVEfmt ", 8);
put32(h + 16, 16); h[20] = 1; h[21] = 0; h[22] = 2; h[23] = 0;
put32(h + 24, AUDIO_RATE); put32(h + 28, AUDIO_RATE * 4); h[32] = 4; h[33] = 0; h[34] = 16; h[35] = 0;
memcpy(h + 36, "data", 4); put32(h + 40, wav_bytes);
fseek(wav_out, 0, SEEK_SET); fwrite(h, 1, 44, wav_out); fclose(wav_out);
}
uint64_t host_time_us(void) {
vtime += 20; /* chaque appel avance le temps virtuel */
return vtime;
}
static void write_bmp(const char *path) {
FILE *f = fopen(path, "wb");
uint8_t hdr[54 + 1024];
int y, i;
if (!f) return;
memset(hdr, 0, sizeof hdr);
hdr[0] = 'B'; hdr[1] = 'M';
*(uint32_t *)(hdr + 2) = 54 + 1024 + 64000;
*(uint32_t *)(hdr + 10) = 54 + 1024;
*(uint32_t *)(hdr + 14) = 40;
*(int32_t *)(hdr + 18) = 320; *(int32_t *)(hdr + 22) = 200;
*(uint16_t *)(hdr + 26) = 1; *(uint16_t *)(hdr + 28) = 8;
*(uint32_t *)(hdr + 34) = 64000; *(uint32_t *)(hdr + 46) = 256;
for (i = 0; i < 256; i++) {
hdr[54 + i * 4 + 0] = (uint8_t)(vga_dac[i * 3 + 2] * 255 / 63);
hdr[54 + i * 4 + 1] = (uint8_t)(vga_dac[i * 3 + 1] * 255 / 63);
hdr[54 + i * 4 + 2] = (uint8_t)(vga_dac[i * 3 + 0] * 255 / 63);
}
fwrite(hdr, 1, sizeof hdr, f);
for (y = 199; y >= 0; y--) fwrite(M + VGA_BASE + (uint32_t)y * 320, 1, 320, f);
fclose(f);
}
void host_frame(void) {
int i;
static int16_t snd[2 * (AUDIO_RATE / 70 + 1)];
frame++;
audio_mix(snd, AUDIO_RATE / 70); /* fait avancer les sons au rythme du jeu */
if (wav_out) { fwrite(snd, 4, AUDIO_RATE / 70, wav_out); wav_bytes += 4 * (AUDIO_RATE / 70); }
mb = 0;
for (i = 0; i < nclicks; i++) {
if (frame >= clicks[i].at && frame <= clicks[i].at + 8) { mx = clicks[i].x; my = clicks[i].y; }
if (frame > clicks[i].at && frame <= clicks[i].at + 8) mb = 1; /* bouton tenu 8 images */
}
if (every && frame % every == 0) {
char p[512];
snprintf(p, sizeof p, "%s/img_%05u.bmp", outdir, frame);
write_bmp(p);
}
if (frame >= max_frames) host_quit = 1;
}
void host_pump(void) {}
void host_idle(void) {}
void host_audio_lock(void) {}
void host_audio_unlock(void) {}
int host_key_pop(uint8_t *sc) { (void)sc; return 0; }
int host_key_peek(uint8_t *sc) { (void)sc; return 0; }
void host_mouse(int *x, int *y, int *b) { *x = mx; *y = my; *b = mb; }