joeylib2/examples/hello/hello.c
2026-10-19 15:46:47 -05:00

59 lines
2.1 KiB
C

// Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
// See LICENSE.md for license information.
// SPDX-License-Identifier: MIT
//
// JoeyLib hello-world example: the smallest program that shows something. It
// starts the library, writes a greeting, the library's version, and the
// machine it runs on on the stage in the default palette (no jlPaletteSet:
// every surface starts with the 16 EGA colors), presents it, says the same on
// the console where there is one, and waits for a key.
#include <stdio.h>
#include <joey/joey.h>
#include "exampleFont.h"
// No sprites, so the smallest compiled-sprite cache.
#define CODEGEN_BYTES ((uint32_t)8 * 1024)
// The lines, each a label and its value, and where they go: the greeting
// in yellow, the version and the platform in white below it, the prompt in
// light gray.
#define TEXT_X 64
#define GREETING_Y 72
#define VERSION_Y 96
#define PLATFORM_Y 108
#define PROMPT_Y 132
#define VALUE_X (TEXT_X + 10 * EXAMPLE_FONT_ADVANCE)
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
#define COLOR_GRAY 7
int main(void) {
jlConfigT config;
jlSurfaceT *stage;
config.codegenBytes = CODEGEN_BYTES;
config.noAudio = true;
if (!jlInit(&config)) {
fprintf(stderr, "jlInit failed: %s\n", jlLastError());
return 1;
}
stage = jlStageGet();
exampleFontDraw(stage, TEXT_X, GREETING_Y, "Hello from JoeyLib!", COLOR_YELLOW);
exampleFontDraw(stage, TEXT_X, VERSION_Y, "Version:", COLOR_WHITE);
exampleFontDraw(stage, VALUE_X, VERSION_Y, jlVersionString(), COLOR_WHITE);
exampleFontDraw(stage, TEXT_X, PLATFORM_Y, "Platform:", COLOR_WHITE);
exampleFontDraw(stage, VALUE_X, PLATFORM_Y, jlPlatformName(), COLOR_WHITE);
exampleFontDraw(stage, TEXT_X, PROMPT_Y, "Press any key.", COLOR_GRAY);
jlStagePresent();
// The same on the console, where there is one (scripts/verify-ste-machine.sh
// reads it through Hatari).
printf("JoeyLib %s\nPlatform: %s\n", jlVersionString(), jlPlatformName());
jlWaitForAnyKey();
jlShutdown();
return 0;
}