fs2port/port/include/chunk5Transform.h
2026-05-13 21:32:05 -05:00

33 lines
1.5 KiB
C

// Cycle-by-cycle port of chunk5 TransformVertex7EBC (L7EBC..L80B0)
// and TransformVertex80C5 (L80C5). These are the polygon vertex
// transform routines that read 4 stream bytes (xLo, xHi, zLo, zHi),
// subtract camera-section deltas at $66/$67/$6A/$6B, run the
// auto-scale loop (L7F1A), apply the 2x3 rotation matrix at $79/$7B/
// $7D + $85/$87/$89, and write the 6-byte result (16-bit X/Y/Z) into
// the caller's vertex slot.
//
// Faithful to the original 6502 -- 8-bit byte arithmetic, carry/V/N
// flag handling, exact algorithm order. Reads from and writes to a
// 64K RAM buffer that mirrors the Apple II zero page and chunk5's
// scratch slots.
#ifndef CHUNK5_TRANSFORM_H
#define CHUNK5_TRANSFORM_H
#include <stdint.h>
// Run TransformVertex7EBC on the 4 vertex bytes at `stream+1..stream+4`.
// `ram` is the 64K RAM image (zero page reads at $4A..$52, $66..$6B,
// $79/$7B/$7D, $85/$87/$89). `destSlot` is the caller-supplied X
// register equivalent ($CB for v1 = vertex 1, $D4 for v2 = vertex 2)
// -- the 6-byte result is written to ram[destSlot..destSlot+5].
//
// Returns the byte advance for $8B (always 5: opcode + 4 vertex bytes).
int chunk5TransformVertex7EBC(uint8_t *ram, const uint8_t *stream, uint8_t destSlot);
// Same as above but uses the transform-A work-counter bias (#$C7)
// instead of transform-B's (#$51). The actual matrix multiply and
// vertex math is identical.
int chunk5TransformVertex80C5(uint8_t *ram, const uint8_t *stream, uint8_t destSlot);
#endif