32typedef enum : int32_t {
91 for (
int index = 2; index < argc; ++index) {
92 if ((
strcmp(argv[index],
"--page") == 0) && ((index + 1) < argc)) {
94 }
else if ((
strcmp(argv[index],
"--dump-ppm") == 0) && ((index + 1) < argc)) {
96 }
else if ((
strcmp(argv[index],
"--dump-tile") == 0) && ((index + 1) < argc)) {
98 }
else if (
strcmp(argv[index],
"--headless") == 0) {
127 return (page >= count) ? (count - 1U) : page;
148 const size_t mask = alignment - 1U;
149 if ((alignment == 0U) || ((alignment & mask) != 0U) || (offset > (SIZE_MAX - mask))) {
152 *out = (offset + mask) & ~mask;
204 if ((options->
dump_ppm !=
nullptr) &&
239 size_t workspace_bytes,
243 uint32_t height = 0U;
244 uint16_t* pixels =
nullptr;
290 size_t workspace_bytes,
296 "no window (headless host?); use --headless --dump-ppm PATH\n");
313 "no window (headless host?); use --headless --dump-ppm PATH\n");
318 (void)nanosleep(&frame,
nullptr);
361 struct sigaction action = {.sa_handler = SIG_IGN};
362 if ((sigemptyset(&action.sa_mask) != 0) || (sigaction(SIGPIPE, &action,
nullptr) != 0)) {
393 size_t scratch_offset = 0U;
401 const char* output = (options->
dump_ppm !=
nullptr) ? options->
dump_ppm :
"/tmp/ra8_tile.ppm";
457 const int status =
internal_execute(reader, &requirements, &options, page, &diagnostic);
void main(void)
Secure fallback main entry point.
static void internal_log_sink(void *ctx, uint8_t byte)
ra8_log byte sink: forward every log byte to the SCI8 console.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_comm_error
Generic communication error (use a more specific code when possible).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
ra8_io targetable byte-stream facade – one writer, many destinations.
ra8_err_t ra8_io_stream_putc(ra8_io_stream_t *s, char c)
Write a single byte to the bound sink.
Borrowed raw-descriptor backend for the portable byte-stream facade.
ra8_err_t ra8_io_stream_posix_init(ra8_io_stream_t *stream, ra8_io_stream_posix_state_t *state, int fd)
Bind a borrowed writable descriptor as a byte-stream sink.
Lightweight Logging Interface for ra8-firmware.
void ra8_log_set_byte_sink(ra8_log_byte_sink_fn_t fn, void *ctx)
Install (or clear) an optional byte sink for log output.
Private typed diagnostic writers for the host viewer.
ra8_err_t priv_viewer_output_error(ra8_io_stream_t *output, const char *operation, ra8_err_t error)
Write an unnumbered operation failure and hexadecimal status.
ra8_err_t priv_viewer_output_open_error(ra8_io_stream_t *output, const char *path, ra8_err_t error)
Write a document-open failure with its path and status.
ra8_err_t priv_viewer_output_index_error(ra8_io_stream_t *output, const char *operation, uint32_t index, ra8_err_t error)
Write a numbered operation failure and hexadecimal status.
ra8_err_t priv_viewer_output_text(ra8_io_stream_t *output, const char *text)
Write one fixed diagnostic without a terminating byte.
ra8_err_t priv_viewer_output_wrote(ra8_io_stream_t *output, const char *path)
Write a successful path-publication diagnostic.
ra8_err_t priv_viewer_output_usage(ra8_io_stream_t *output, const char *executable)
Write the complete command-line usage message.
ra8_err_t priv_viewer_output_opened(ra8_io_stream_t *output, const char *path, uint32_t page_count)
Write a successful document-open diagnostic.
ra8_err_t priv_viewer_output_tile(ra8_io_stream_t *output, uint32_t tile, uint32_t width, uint32_t height, const char *path)
Write a successful tile-publication diagnostic.
ra8_err_t priv_viewer_output_capacity(ra8_io_stream_t *output, const char *subject, size_t required, size_t supplied)
Write an exact workspace requirement diagnostic.
Caller-owned host JOF/comic reader and RGB565 render surface.
ra8_err_t ra8_viewer_write_ppm565(const uint16_t *px, uint32_t w, uint32_t h, const char *path)
Write arbitrary caller-owned RGB565 pixels as binary PPM.
uint32_t ra8_viewer_page_count(const ra8_viewer_reader_t *reader)
Number of viewport pages in reader, or zero for NULL/closed.
void ra8_viewer_close(ra8_viewer_reader_t *reader)
Close the descriptor and reset reader state without freeing workspace.
ra8_err_t ra8_viewer_open(ra8_viewer_reader_t *reader, const char *path)
Open the document class used to size and bind reader.
ra8_err_t ra8_viewer_render_tile565(ra8_viewer_reader_t *reader, uint32_t index, void *workspace, size_t workspace_bytes, uint32_t *width, uint32_t *height, uint16_t **out_pixels, ra8_viewer_workspace_report_t *report)
Render tile index into caller-owned RGB565 storage.
ra8_err_t ra8_viewer_render_page(ra8_viewer_reader_t *reader, uint32_t page)
Render one page into the reader's fixed RGB565 framebuffer.
ra8_err_t ra8_viewer_dump_ppm(const ra8_viewer_reader_t *reader, const char *path)
Write the current fixed framebuffer as binary PPM.
ra8_err_t ra8_viewer_reader_bind(ra8_viewer_reader_t **out, void *workspace, size_t workspace_bytes, const ra8_viewer_reader_requirements_t *requirements, ra8_viewer_workspace_report_t *report)
Bind one reader state to caller-owned bytes.
ra8_err_t ra8_viewer_reader_requirements(const char *path, ra8_viewer_reader_requirements_t *out)
Inspect path and calculate its exact reader workspace.
struct ra8_viewer_reader ra8_viewer_reader_t
Opaque state bound inside caller-owned workspace.
Caller-owned C ABI for the Cocoa scrolling JOF view.
struct ra8_viewer_view ra8_viewer_view_t
Opaque view state bound inside caller workspace.
ra8_err_t ra8_viewer_view_open(ra8_viewer_view_t **out, ra8_viewer_reader_t *reader, const char *title, void *workspace, size_t workspace_bytes, const ra8_viewer_view_requirements_t *requirements, ra8_viewer_workspace_report_t *report)
Open a scrolling window into caller-owned first-party workspace.
void ra8_viewer_view_close(ra8_viewer_view_t *view)
Close the window and reset borrowed view state without freeing it.
ra8_err_t ra8_viewer_view_requirements(const ra8_viewer_reader_t *reader, ra8_viewer_view_requirements_t *out)
Calculate the exact view workspace for reader.
bool ra8_viewer_view_pump(ra8_viewer_view_t *view)
Drain pending events; true after the window closes.
static void internal_usage(void)
Print CLI usage and the explicit compiled cache ceiling.
Caller-owned state retained by one POSIX stream binding.
Caller-allocated byte-stream handle binding a sink to its context.
Exact immutable layout returned for one document.
size_t required_bytes
Complete workspace extent.
Exact first-party workspace required by one platform view.
Required-versus-supplied evidence from a bind attempt.
Parsed command-line options.
int64_t dump_tile
Tile index, or -1.
bool headless
Do not create a window.
const char * dump_ppm
Output path, or NULL.
uint32_t page
Headless page index.
const char * path
Input document path.
static uint32_t internal_clamp_page(uint32_t page, uint32_t count)
Clamp a requested page into the document.
static void internal_report_capacity(ra8_io_stream_t *output, const char *subject, const ra8_viewer_workspace_report_t *report)
Report exact capacity evidence.
static bool internal_render_page(ra8_viewer_reader_t *reader, const viewer_options_t *options, uint32_t page, ra8_io_stream_t *diagnostic)
Render and optionally write one fixed-framebuffer page.
static ra8_err_t internal_bind_diagnostic(ra8_io_stream_t *output, ra8_io_stream_posix_state_t *state)
Bind standard error through the raw POSIX stream adapter.
viewer_main_config_t
Composition limits and CLI constants.
@ k_viewer_composition_bytes
Entire first-party byte budget.
@ k_viewer_min_args
argv count with an input path.
@ k_viewer_frame_ns
Cooperative pump period.
@ k_viewer_radix_dec
Decimal option radix.
static uint8_t s_viewer_composition[k_viewer_composition_bytes]
Explicit host composition storage; another target may replace it.
static int internal_execute(ra8_viewer_reader_t *reader, const ra8_viewer_reader_requirements_t *requirements, const viewer_options_t *options, uint32_t page, ra8_io_stream_t *diagnostic)
Execute the selected viewer mode over the composition remainder.
static bool internal_dump_tile(ra8_viewer_reader_t *reader, uint32_t tile, const char *path, void *workspace, size_t workspace_bytes, ra8_io_stream_t *diagnostic)
Render and publish one caller-buffered scroll tile.
static int internal_run_window(ra8_viewer_reader_t *reader, void *workspace, size_t workspace_bytes, ra8_io_stream_t *diagnostic)
Open and cooperatively pump the caller-workspace Cocoa view.
static bool internal_align_offset(size_t offset, size_t alignment, size_t *out)
Align a composition offset upward.
static bool internal_parse_arguments(int argc, char **argv, viewer_options_t *options)
Parse the bounded viewer command line.