fs2port/port/include/sceneryData.h
2026-05-14 10:03:23 -05:00

74 lines
3.7 KiB
C

// Scenery loader. Reads one of the FS2 region .dsk-equivalent files
// (extracted from the san-inc-pack ProDOS image, see
// downloads/scenery/extracted/) into memory and exposes the raw
// bytestream so `sceneryVm` can interpret it.
#ifndef SCENERY_DATA_H
#define SCENERY_DATA_H
#include <stdbool.h>
#include <stdint.h>
typedef enum SceneryRegionE {
SCENERY_NONE = 0,
SCENERY_FS2_1, // Built-in WW1 Ace training field (FS2 base disk default)
SCENERY_FS2_1_CHICAGO, // FS2 base disk - Chicago / Meigs Field (LoadSceneryFile1)
SCENERY_FS2_1_LA, // FS2 base disk - Los Angeles (LoadSceneryFile2)
SCENERY_FS2_1_SEATTLE, // FS2 base disk - Seattle (LoadSceneryFile3)
SCENERY_FS2_1_NY, // FS2 base disk - New York / Kennedy (LoadSceneryFile4)
SCENERY_SD1, // Dallas-Ft.Worth, Houston, San Antonio, Brownsville
SCENERY_SD2, // Phoenix, Albuquerque, El Paso
SCENERY_SD3, // San Francisco, Los Angeles, Las Vegas
SCENERY_SD4, // Klamath Falls, Seattle, Great Falls
SCENERY_SD5, // Salt Lake City, Cheyenne, Denver
SCENERY_SD6, // Omaha, Wichita, Kansas City
SCENERY_SD7A, // Washington, Charlotte
SCENERY_SD7B, // Jacksonville, Miami
SCENERY_SD11, // Lake Huron, Detroit
SCENERY_SD13, // Japan - Tokyo, Osaka
SCENERY_SD14A, // Western European Tour - S. UK, N. France
SCENERY_SD14B, // Western European Tour - N. France, S. West Germany
SCENERY_SDS1, // STAR San Francisco & The Bay Area
SCENERY_REGION_COUNT
} SceneryRegionE;
typedef struct SceneryDataT {
SceneryRegionE region;
const uint8_t *bytes; // points into a 64K RAM image (the result of running fs2trace's boot mode); whole image is memory-addressable
uint32_t length; // 65536 for RAM images; smaller for the legacy .SD payload path
uint16_t entryOffset; // bytecode entry pointer for ProcessScenery; for RAM images this is `bytes[0xA7E0] | (bytes[0xA7E1] << 8)` (LA7E0); falls back to the legacy 0x7000 for raw .SD loads
const char *name; // human-readable region label
// Raw .SD scenery file (143KB-ish). Used by sceneryVm's HEADER
// demand-load to copy section-specific bytecode over the $79
// padding at $A848+. Indexed in 256-byte sectors per the chunk5
// descriptor format: sector N = file offset N*256.
const uint8_t *sceneryFile;
uint32_t sceneryFileSize;
} SceneryDataT;
// Load the named region's bytes into memory. Returns true on success
// and populates `*out`. The first scenery payload byte starts at the
// returned `bytes` pointer; the caller should call `sceneryDataFree`
// when done. Searches for the .dsk file in:
// - downloads/scenery/extracted/A2.SD<region>
// - ../downloads/scenery/extracted/A2.SD<region>
// - ../../downloads/scenery/extracted/A2.SD<region>
// - /home/scott/claude/flight/downloads/scenery/extracted/A2.SD<region>
bool sceneryDataLoad(SceneryRegionE region, SceneryDataT *out);
// Release the buffer allocated by `sceneryDataLoad`.
void sceneryDataFree(SceneryDataT *out);
// Human-readable name for a region. Always returns a non-NULL string.
const char *sceneryDataRegionName(SceneryRegionE region);
// Reverse-lookup: map the basename string used by SCENERY_REGION
// (e.g. "FS2.1", "FS2.1_chicago", "SD3", "SD14B") back to its enum.
// Accepts the bare SD form ("SD3") as well as the "A2.SD3" full form.
// Returns SCENERY_NONE if unrecognised.
SceneryRegionE sceneryDataRegionFromName(const char *name);
#endif